Source Code Cross Referenced for ArchiveCarMojo.java in  » EJB-Server-geronimo » car-maven-plugin » org » apache » geronimo » mavenplugins » car » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » car maven plugin » org.apache.geronimo.mavenplugins.car 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one
003:         *  or more contributor license agreements.  See the NOTICE file
004:         *  distributed with this work for additional information
005:         *  regarding copyright ownership.  The ASF licenses this file
006:         *  to you under the Apache License, Version 2.0 (the
007:         *  "License"); you may not use this file except in compliance
008:         *  with the License.  You may obtain a copy of the License at
009:         *
010:         *    http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing,
013:         *  software distributed under the License is distributed on an
014:         *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         *  KIND, either express or implied.  See the License for the
016:         *  specific language governing permissions and limitations
017:         *  under the License.
018:         */package org.apache.geronimo.mavenplugins.car;
019:
020:        import java.io.File;
021:        import java.net.URI;
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.HashMap;
025:        import java.util.HashSet;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Set;
029:
030:        import org.apache.geronimo.deployment.PluginBootstrap2;
031:        import org.apache.geronimo.gbean.AbstractName;
032:        import org.apache.geronimo.gbean.AbstractNameQuery;
033:        import org.apache.geronimo.gbean.GBeanData;
034:        import org.apache.geronimo.gbean.GBeanInfo;
035:        import org.apache.geronimo.gbean.ReferencePatterns;
036:        import org.apache.geronimo.kernel.Kernel;
037:        import org.apache.geronimo.kernel.KernelFactory;
038:        import org.apache.geronimo.kernel.KernelRegistry;
039:        import org.apache.geronimo.kernel.Naming;
040:        import org.apache.geronimo.kernel.config.ConfigurationData;
041:        import org.apache.geronimo.kernel.config.ConfigurationManager;
042:        import org.apache.geronimo.kernel.config.ConfigurationUtil;
043:        import org.apache.geronimo.kernel.config.KernelConfigurationManager;
044:        import org.apache.geronimo.kernel.config.LifecycleException;
045:        import org.apache.geronimo.kernel.config.RecordingLifecycleMonitor;
046:        import org.apache.geronimo.kernel.log.GeronimoLogging;
047:        import org.apache.geronimo.kernel.management.State;
048:        import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
049:        import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
050:        import org.apache.geronimo.system.repository.Maven2Repository;
051:        import org.apache.geronimo.system.resolver.ExplicitDefaultArtifactResolver;
052:        import org.apache.maven.archiver.MavenArchiveConfiguration;
053:        import org.apache.maven.archiver.MavenArchiver;
054:        import org.apache.maven.artifact.Artifact;
055:        import org.apache.maven.artifact.factory.ArtifactFactory;
056:        import org.apache.maven.plugin.MojoExecutionException;
057:        import org.apache.maven.project.MavenProject;
058:        import org.codehaus.mojo.pluginsupport.dependency.DependencyTree;
059:        import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
060:        import org.codehaus.plexus.archiver.jar.JarArchiver;
061:        import org.codehaus.plexus.util.FileUtils;
062:
063:        /**
064:         * Jar up a packaged plugin
065:         *
066:         * @goal archive-car
067:         * @requiresDependencyResolution runtime
068:         *
069:         * @version $Rev: 617364 $ $Date: 2008-01-31 23:44:42 -0800 (Thu, 31 Jan 2008) $
070:         */
071:        public class ArchiveCarMojo extends AbstractCarMojo {
072:
073:            /**
074:             * The maven archive configuration to use.
075:             *
076:             * See <a href="http://maven.apache.org/ref/current/maven-archiver/apidocs/org/apache/maven/archiver/MavenArchiveConfiguration.html">the Javadocs for MavenArchiveConfiguration</a>.
077:             *
078:             * @parameter
079:             */
080:            private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
081:
082:            /**
083:             * The Jar archiver.
084:             *
085:             * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
086:             * @required
087:             * @readonly
088:             */
089:            private JarArchiver jarArchiver = null;
090:
091:            /**
092:             * The module base directory.
093:             *
094:             * @parameter expression="${project.basedir}"
095:             * @required
096:             * @readonly
097:             */
098:            private File baseDirectory = null;
099:
100:            /**
101:             * Directory containing the generated archive.
102:             *
103:             * @parameter expression="${project.build.directory}"
104:             * @required
105:             */
106:            private File outputDirectory = null;
107:
108:            /**
109:             * Directory containing the classes/resources.
110:             *
111:             * @parameter expression="${project.build.outputDirectory}"
112:             * @required
113:             */
114:            private File classesDirectory = null;
115:
116:            /**
117:             * Name of the generated archive.
118:             *
119:             * @parameter expression="${project.build.finalName}"
120:             * @required
121:             */
122:            private String finalName = null;
123:
124:            /**
125:             * The Geronimo repository where modules will be packaged up from.
126:             *
127:             * @parameter expression="${project.build.directory}/repository"
128:             * @required
129:             */
130:            private File targetRepository = null;
131:
132:            /**
133:             * The location where the properties mapping will be generated.
134:             *
135:             * <p>
136:             * Probably don't want to change this.
137:             * </p>
138:             *
139:             * @parameter expression="${project.build.directory}/explicit-versions.properties"
140:             */
141:            private File explicitResolutionProperties = null;
142:
143:            /**
144:             * An array of {@link org.apache.geronimo.mavenplugins.car.ClasspathElement} objects which will be used to construct the
145:             * Class-Path entry of the manifest.
146:             *
147:             * This is needed to allow per-element prefixes to be added, which the standard Maven archiver
148:             * does not provide.
149:             *
150:             * @parameter
151:             */
152:            private ClasspathElement[] classpath = null;
153:
154:            /**
155:             * The default prefix to be applied to all elements of the <tt>classpath</tt> which
156:             * do not provide a prefix.
157:             *
158:             * @parameter
159:             */
160:            private String classpathPrefix = null;
161:
162:            /**
163:             * Location of resources directory for additional content to include in the car.
164:             *
165:             * @parameter expression="${project.build.directory}/resources"
166:             */
167:            private File resourcesDir;
168:
169:            //
170:            // Mojo
171:            //
172:
173:            protected void doExecute() throws Exception {
174:
175:                // Build the archive
176:                File archive = createArchive();
177:
178:                // Attach the generated archive for install/deploy
179:                project.getArtifact().setFile(archive);
180:            }
181:
182:            private File getArtifactInRepositoryDir() {
183:                //
184:                // HACK: Generate the filename in the repo... really should delegate this to the repo impl
185:                //
186:
187:                File dir = new File(targetRepository, project.getGroupId()
188:                        .replace('.', '/'));
189:                dir = new File(dir, project.getArtifactId());
190:                dir = new File(dir, project.getVersion());
191:                dir = new File(dir, project.getArtifactId() + "-"
192:                        + project.getVersion() + ".car");
193:
194:                return dir;
195:            }
196:
197:            /**
198:             * Generates the configuration archive.
199:             */
200:            private File createArchive() throws MojoExecutionException {
201:                File archiveFile = getArchiveFile(outputDirectory, finalName,
202:                        null);
203:
204:                MavenArchiver archiver = new MavenArchiver();
205:                archiver.setArchiver(jarArchiver);
206:                archiver.setOutputFile(archiveFile);
207:
208:                try {
209:                    // Incldue the generated artifact contents
210:                    archiver.getArchiver().addDirectory(
211:                            getArtifactInRepositoryDir());
212:
213:                    // Include the optional classes.resources
214:                    if (classesDirectory.isDirectory()) {
215:                        archiver.getArchiver().addDirectory(classesDirectory);
216:                    }
217:
218:                    if (resourcesDir.isDirectory()) {
219:                        archiver.getArchiver().addDirectory(resourcesDir);
220:                    }
221:
222:                    //
223:                    // HACK: Include legal files here for sanity
224:                    //
225:
226:                    //
227:                    // NOTE: Would be nice to share this with the copy-legal-files mojo
228:                    //
229:                    String[] includes = { "LICENSE.txt", "LICENSE",
230:                            "NOTICE.txt", "NOTICE", "DISCLAIMER.txt",
231:                            "DISCLAIMER" };
232:
233:                    archiver.getArchiver().addDirectory(baseDirectory,
234:                            "META-INF/", includes, new String[0]);
235:
236:                    if (classpath != null) {
237:                        archive.addManifestEntry("Class-Path", getClassPath());
238:                    }
239:
240:                    archiver.createArchive(project, archive);
241:
242:                    return archiveFile;
243:                } catch (Exception e) {
244:                    throw new MojoExecutionException(
245:                            "Failed to create archive", e);
246:                }
247:            }
248:
249:            private String getClassPath() throws MojoExecutionException {
250:                StringBuffer buff = new StringBuffer();
251:
252:                for (int i = 0; i < classpath.length; i++) {
253:                    String entry = classpath[i].getEntry();
254:                    if (entry != null) {
255:                        buff.append(entry);
256:                    } else {
257:                        Artifact artifact = getArtifact(classpath[i]);
258:
259:                        //
260:                        // TODO: Need to optionally get all transitive dependencies... but dunno how to get that intel from m2
261:                        //
262:
263:                        String prefix = classpath[i].getClasspathPrefix();
264:                        if (prefix == null) {
265:                            prefix = classpathPrefix;
266:                        }
267:
268:                        if (prefix != null) {
269:                            buff.append(prefix);
270:
271:                            if (!prefix.endsWith("/")) {
272:                                buff.append("/");
273:                            }
274:                        }
275:
276:                        File file = artifact.getFile();
277:                        buff.append(file.getName());
278:                    }
279:
280:                    if (i + 1 < classpath.length) {
281:                        buff.append(" ");
282:                    }
283:                }
284:
285:                log.debug("Using classpath: " + buff);
286:
287:                return buff.toString();
288:            }
289:
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.