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


001:        package org.andromda.maven.plugin.bootstrap.install;
002:
003:        import java.io.File;
004:        import java.io.FileWriter;
005:        import java.io.IOException;
006:
007:        import java.util.ArrayList;
008:        import java.util.Collections;
009:        import java.util.List;
010:
011:        import org.apache.commons.lang.StringUtils;
012:        import org.apache.maven.artifact.Artifact;
013:        import org.apache.maven.artifact.repository.ArtifactRepository;
014:        import org.apache.maven.model.Build;
015:        import org.apache.maven.model.Model;
016:        import org.apache.maven.model.Parent;
017:        import org.apache.maven.plugin.AbstractMojo;
018:        import org.apache.maven.plugin.MojoExecutionException;
019:        import org.apache.maven.plugin.MojoFailureException;
020:        import org.apache.maven.project.MavenProject;
021:        import org.codehaus.plexus.util.FileUtils;
022:
023:        /**
024:         * Provides the installation of bootstrap artifacts.
025:         *
026:         * @author Chad Brandon
027:         *
028:         * @goal install
029:         * @phase install
030:         */
031:        public class BootstrapInstallMojo extends AbstractMojo {
032:            /**
033:             * The maven project.
034:             *
035:             * @parameter expression="${project}"
036:             * @required
037:             * @readonly
038:             * @description "the maven project to use"
039:             */
040:            protected MavenProject project;
041:
042:            /**
043:             * @parameter expression="${localRepository}"
044:             * @required
045:             * @readonly
046:             */
047:            protected ArtifactRepository localRepository;
048:
049:            /**
050:             * @parameter expression="${bootstrap.artifacts}"
051:             * @description whether or not bootstrap artifacts should be installed, by default they are not.
052:             */
053:            protected boolean installBootstraps;
054:
055:            /**
056:             * @parameter
057:             * @required
058:             * @description the directory to which the bootstrap artifact should be installed.
059:             */
060:            protected String installDirectory;
061:
062:            /**
063:             * @parameter expression="org.andromda"
064:             * @required
065:             * @readonly
066:             * @description the name of the project groupId.
067:             */
068:            protected String projectGroupId;
069:
070:            /**
071:             * @parameter expression="org.andromda.bootstrap"
072:             * @required
073:             * @readonly
074:             * @description the name of the project bootstrap groupId.
075:             */
076:            protected String projectBootstrapGroupId;
077:
078:            /**
079:             * The extension for "JAR" files.
080:             */
081:            private static final String JAR_EXTENSION = "jar";
082:
083:            /**
084:             * The extension for "POM" files.
085:             */
086:            private static final String POM_EXTENSION = "pom";
087:
088:            /**
089:             * @see org.apache.maven.plugin.Mojo#execute()
090:             */
091:            public void execute() throws MojoExecutionException,
092:                    MojoFailureException {
093:                if (this .installBootstraps) {
094:                    try {
095:                        final File installDirectory = new File(
096:                                this .installDirectory);
097:                        if (!installDirectory.exists()
098:                                || !installDirectory.isDirectory()) {
099:                            throw new MojoExecutionException("'"
100:                                    + installDirectory
101:                                    + "' is not a valid install directory");
102:                        }
103:                        Artifact artifact = this .project.getArtifact();
104:
105:                        final String path = this .replaceExtension(artifact,
106:                                JAR_EXTENSION);
107:                        final String localRepositoryDirectory = this .localRepository
108:                                .getBasedir();
109:                        final File existingFile = new File(
110:                                localRepositoryDirectory, path);
111:                        final String bootstrapGroupId = this 
112:                                .getBootstrapGroupId(artifact);
113:                        final String bootstrapPath = bootstrapGroupId.replace(
114:                                '.', '/')
115:                                + '/' + artifact.getArtifactId();
116:                        final File bootstrapFile = new File(installDirectory,
117:                                bootstrapPath + '.' + JAR_EXTENSION);
118:                        this .getLog().info(
119:                                "Installing bootstrap artifact: "
120:                                        + bootstrapFile);
121:                        FileUtils.copyFile(existingFile, bootstrapFile);
122:                        final File bootstrapPomFile = new File(
123:                                installDirectory, bootstrapPath + '.'
124:                                        + POM_EXTENSION);
125:                        this .writeMinimalPom(bootstrapPomFile);
126:                    } catch (final Throwable throwable) {
127:                        throw new MojoExecutionException(
128:                                "Error creating bootstrap artifact", throwable);
129:                    }
130:                }
131:            }
132:
133:            /**
134:             * Clears the POM's model of its parent or any dependencies
135:             * it may have so that we can write a POM that isn't dependant on anything
136:             * (which we need for bootstrap artifacts).
137:             *
138:             * @param bootstrapPomFile the bootstrap POM file to write.
139:             */
140:            private void writeMinimalPom(final File bootstrapPomFile)
141:                    throws MojoExecutionException, IOException {
142:                if (this .project != null) {
143:                    Model model = this .project.getModel();
144:                    if (model == null) {
145:                        throw new MojoExecutionException(
146:                                "Model could not be retrieved from current project");
147:                    }
148:
149:                    // - remove the parent
150:                    final Parent parent = model.getParent();
151:                    final List dependencies = new ArrayList(model
152:                            .getDependencies());
153:                    final String groupId = model.getGroupId();
154:                    final Artifact artifact = this .project.getArtifact();
155:                    final Build build = this .project.getBuild();
156:                    final List developers = new ArrayList(model.getDevelopers());
157:                    final List contributors = new ArrayList(model
158:                            .getContributors());
159:                    model.setGroupId(this .getBootstrapGroupId(artifact));
160:                    model.setParent(null);
161:                    model.setBuild(null);
162:                    model.setDependencies(Collections.EMPTY_LIST);
163:                    model.setDevelopers(Collections.EMPTY_LIST);
164:                    model.setContributors(Collections.EMPTY_LIST);
165:                    final FileWriter fileWriter = new FileWriter(
166:                            bootstrapPomFile);
167:                    this .project.writeModel(fileWriter);
168:                    fileWriter.flush();
169:
170:                    // - set any removed items back to the way it was since we've written the POM
171:                    model.setParent(parent);
172:                    model.setGroupId(groupId);
173:                    model.setDependencies(dependencies);
174:                    model.setBuild(build);
175:                    model.setDevelopers(developers);
176:                    model.setContributors(contributors);
177:                }
178:            }
179:
180:            /**
181:             * Retrieves the project's bootstrap groupId from the given <code>artifact</code>.
182:             *
183:             * @param artifact the artfact from which to retrieve the group Id.
184:             * @return the bootstrap groupId.
185:             */
186:            private String getBootstrapGroupId(final Artifact artifact) {
187:                return StringUtils.replaceOnce(artifact.getGroupId(),
188:                        this .projectGroupId, this .projectBootstrapGroupId);
189:            }
190:
191:            /**
192:             * Retrieves the extension from the given path.
193:             * @param artifact the artifact from which to retrieve the version information.
194:             * @param path the path of the file
195:             * @return the extension.
196:             */
197:            private String replaceExtension(final Artifact artifact,
198:                    final String newExtension) {
199:                String path = this .localRepository.pathOf(artifact);
200:                final String version = artifact.getVersion() != null ? artifact
201:                        .getVersion().trim() : "";
202:                int versionIndex = path.lastIndexOf(artifact.getVersion());
203:                final String extension = path.substring(versionIndex
204:                        + version.length() + 1, path.length());
205:                if (!newExtension.equals(extension)) {
206:                    int extensionIndex = path.lastIndexOf(extension);
207:                    path = path.substring(0, extensionIndex) + newExtension;
208:                }
209:                return path;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.