Source Code Cross Referenced for CartridgeArchiverMojo.java in  » UML » AndroMDA-3.2 » org » andromda » maven » plugin » cartridge » 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 » UML » AndroMDA 3.2 » org.andromda.maven.plugin.cartridge 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.maven.plugin.cartridge;
002:
003:        import java.io.File;
004:        import java.util.Collection;
005:        import java.util.Iterator;
006:
007:        import org.apache.commons.lang.StringUtils;
008:        import org.apache.maven.archiver.MavenArchiveConfiguration;
009:        import org.apache.maven.archiver.MavenArchiver;
010:        import org.apache.maven.artifact.Artifact;
011:        import org.apache.maven.plugin.AbstractMojo;
012:        import org.apache.maven.plugin.MojoExecutionException;
013:        import org.apache.maven.plugin.MojoFailureException;
014:        import org.apache.maven.project.MavenProject;
015:        import org.codehaus.plexus.archiver.jar.JarArchiver;
016:        import org.codehaus.plexus.util.FileUtils;
017:
018:        /**
019:         * Provides the archiving of AndroMDA cartridges.
020:         *
021:         * @author Chad Brandon
022:         * @goal andromda-cartridge
023:         * @phase package
024:         * @requiresProject
025:         * @description builds an AndroMDA cartridge.
026:         */
027:        public class CartridgeArchiverMojo extends AbstractMojo {
028:            /**
029:             * Directory that resources are copied to during the build.
030:             *
031:             * @parameter expression="${project.build.directory}"
032:             * @required
033:             */
034:            private String workDirectory;
035:
036:            /**
037:             * The directory for the generated cartridge.
038:             *
039:             * @parameter expression="${project.build.outputDirectory}"
040:             * @required
041:             */
042:            private String outputDirectory;
043:
044:            /**
045:             * The name of the cartridge file to generate.
046:             *
047:             * @parameter alias="modelName" expression="${project.build.finalName}"
048:             * @required
049:             * @readonly
050:             */
051:            private String finalName;
052:
053:            /**
054:             * The maven project.
055:             *
056:             * @parameter expression="${project}"
057:             * @required
058:             * @readonly
059:             * @description "the maven project to use"
060:             */
061:            private MavenProject project;
062:
063:            /**
064:             * The Jar archiver.
065:             *
066:             * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
067:             * @required
068:             */
069:            private JarArchiver jarArchiver;
070:
071:            /**
072:             * The maven archiver to use.
073:             *
074:             * @parameter
075:             */
076:            private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
077:
078:            /**
079:             * The libraries to include in the cartridge.
080:             *
081:             * @parameter
082:             */
083:            private CartridgeArtifact[] artifacts;
084:
085:            /**
086:             *  The patterns indicating what will be included in the cartridge.
087:             */
088:            private static final String[] OUTPUT_INCLUDES = new String[] { "**/*" };
089:
090:            /**
091:             * @see org.apache.maven.plugin.Mojo#execute()
092:             */
093:            public void execute() throws MojoExecutionException,
094:                    MojoFailureException {
095:                getLog().debug(
096:                        " ======= CartridgeArchiverMojo settings =======");
097:                getLog().debug("workDirectory[" + this .workDirectory + "]");
098:                getLog().debug("outputDirectory[" + this .outputDirectory + "]");
099:                getLog().debug("finalName[" + finalName + "]");
100:                final File buildDirectory = this .getBuildDirectory();
101:                final File outputDirectory = new File(this .outputDirectory);
102:                try {
103:                    if (artifacts != null) {
104:                        for (int ctr = 0; ctr < artifacts.length; ctr++) {
105:                            final CartridgeArtifact cartridgeArtifact = artifacts[ctr];
106:                            final Artifact artifact = this 
107:                                    .resolveArtifact(cartridgeArtifact);
108:                            if (artifact != null) {
109:                                final String path = cartridgeArtifact.getPath();
110:                                if (path == null || path.trim().length() == 0) {
111:                                    throw new MojoFailureException(
112:                                            "Please specify the 'path' for the cartridge artifact ["
113:                                                    + cartridgeArtifact
114:                                                            .getGroupId()
115:                                                    + ":"
116:                                                    + cartridgeArtifact
117:                                                            .getArtifactId()
118:                                                    + ":"
119:                                                    + cartridgeArtifact
120:                                                            .getType() + "]");
121:                                }
122:
123:                                final File destinationDirectory = new File(
124:                                        outputDirectory, cartridgeArtifact
125:                                                .getPath());
126:                                final File artifactFile = artifact.getFile();
127:                                final String artifactPath = artifactFile != null ? StringUtils
128:                                        .replace(artifact.getFile().toString()
129:                                                .replaceAll(".*(\\\\|/)", ""),
130:                                                '-' + artifact.getVersion(), "")
131:                                        : null;
132:                                if (artifactPath != null) {
133:                                    FileUtils
134:                                            .copyFile(artifactFile, new File(
135:                                                    destinationDirectory,
136:                                                    artifactPath));
137:                                }
138:                            }
139:                        }
140:                    }
141:                    final File cartridgeFile = new File(buildDirectory,
142:                            this .finalName + ".jar");
143:                    final Artifact artifact = this .project.getArtifact();
144:                    final MavenArchiver archiver = new MavenArchiver();
145:                    archiver.setArchiver(this .jarArchiver);
146:                    archiver.setOutputFile(cartridgeFile);
147:                    archiver.getArchiver().addDirectory(outputDirectory,
148:                            OUTPUT_INCLUDES, null);
149:                    archiver.createArchive(this .project, this .archive);
150:                    artifact.setFile(cartridgeFile);
151:                } catch (final Throwable throwable) {
152:                    throw new MojoExecutionException(
153:                            "An error occured while packaging this cartridge",
154:                            throwable);
155:                }
156:            }
157:
158:            /**
159:             * Resolves the actual Maven artifact for the given cartridge artifact.
160:             * @param cartridgeArtifact the cartridge artifact.
161:             * @return
162:             * @throws MojoFailureException
163:             */
164:            public Artifact resolveArtifact(
165:                    final CartridgeArtifact cartridgeArtifact)
166:                    throws MojoFailureException {
167:                Artifact resolvedArtifact = null;
168:                if (cartridgeArtifact != null) {
169:                    final Collection artifacts = this .project.getArtifacts();
170:                    final String groupId = cartridgeArtifact.getGroupId();
171:                    final String artifactId = cartridgeArtifact.getArtifactId();
172:                    final String type = cartridgeArtifact.getType();
173:                    if (groupId == null || artifactId == null) {
174:                        throw new MojoFailureException(
175:                                "Could not resolve cartridge artifact ["
176:                                        + groupId + ":" + artifactId + ":"
177:                                        + type + "]");
178:                    }
179:
180:                    for (final Iterator iterator = artifacts.iterator(); iterator
181:                            .hasNext();) {
182:                        final Artifact artifact = (Artifact) iterator.next();
183:                        if (artifact.getGroupId().equals(groupId)
184:                                && artifact.getArtifactId().equals(artifactId)
185:                                && (type == null || artifact.getType().equals(
186:                                        type))) {
187:                            resolvedArtifact = artifact;
188:                            break;
189:                        }
190:                    }
191:
192:                    if (resolvedArtifact == null) {
193:                        // Artifact has not been found
194:                        throw new MojoFailureException("Artifact[" + groupId
195:                                + ":" + artifactId + ":" + type + "] "
196:                                + "is not a dependency of the project.");
197:                    }
198:                    return resolvedArtifact;
199:                }
200:                return resolvedArtifact;
201:            }
202:
203:            /**
204:             * The build directory.
205:             */
206:            private File buildDirectory;
207:
208:            /**
209:             * Gets the current build directory as a file instance.
210:             *
211:             * @return the build directory as a file.
212:             */
213:            protected File getBuildDirectory() {
214:                if (this .buildDirectory == null) {
215:                    this .buildDirectory = new File(workDirectory);
216:                }
217:                return this.buildDirectory;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.