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


001:        package org.andromda.maven.plugin.initialize;
002:
003:        import java.io.File;
004:
005:        import java.util.ArrayList;
006:        import java.util.Collection;
007:        import java.util.Iterator;
008:        import java.util.List;
009:        import java.util.ListIterator;
010:
011:        import org.apache.commons.io.FilenameUtils;
012:        import org.apache.commons.lang.StringUtils;
013:        import org.apache.maven.artifact.repository.ArtifactRepository;
014:        import org.apache.maven.plugin.AbstractMojo;
015:        import org.apache.maven.plugin.MojoExecutionException;
016:        import org.apache.maven.plugin.MojoFailureException;
017:        import org.apache.maven.project.MavenProject;
018:        import org.codehaus.plexus.util.FileUtils;
019:
020:        /**
021:         * Provides any initialization required by the AndroMDA build.
022:         *
023:         * @author Chad Brandon
024:         * @goal initialize
025:         * @phase generate-resources
026:         */
027:        public class InitializeMojo extends AbstractMojo {
028:            /**
029:             * The maven project.
030:             *
031:             * @parameter expression="${project}"
032:             * @required
033:             * @readonly
034:             * @description "the maven project to use"
035:             */
036:            protected MavenProject project;
037:
038:            /**
039:             * @parameter expression="${localRepository}"
040:             * @required
041:             * @readonly
042:             */
043:            protected ArtifactRepository localRepository;
044:
045:            /**
046:             * @parameter
047:             * @required
048:             * @description the directory where any local (those not kept in a remote repository) artifacts are kept.
049:             */
050:            protected String localArtifactDirectory;
051:
052:            /**
053:             * @parameter expression="${bootstrap.artifacts}"
054:             * @description Whether or not bootstrap artifacts should be installed, by default they are not.  If this is
055:             *              set to true this means the andromda bootstrap plugin will be updating the bootstaps, therefore
056:             *              this plugin will not deploy any of the current bootstraps (since that would create an inconsistent state).
057:             */
058:            protected boolean installBootstraps;
059:
060:            /**
061:             * @parameter expression="org/andromda/bootstrap"
062:             * @required
063:             * @readonly
064:             * @description the name root directory of the bootstrap artifacts.
065:             */
066:            protected String bootstrapDirectoryName;
067:
068:            /**
069:             * @see org.apache.maven.plugin.Mojo#execute()
070:             */
071:            public void execute() throws MojoExecutionException,
072:                    MojoFailureException {
073:                if (!this .installBootstraps) {
074:                    try {
075:                        final File bootstrapDirectory = new File(
076:                                this .localArtifactDirectory);
077:                        final Collection contents = this 
078:                                .getDirectoryContents(bootstrapDirectory);
079:                        for (final Iterator iterator = contents.iterator(); iterator
080:                                .hasNext();) {
081:                            String path = (String) iterator.next();
082:                            final String extension = FileUtils
083:                                    .getExtension(path);
084:                            String fileName = this .getFileName(path);
085:                            final String version = this .project.getVersion();
086:                            final String versionedFileName = StringUtils
087:                                    .replace(fileName, '.' + extension, '-'
088:                                            + version + '.' + extension);
089:                            final String artifactId = this .getArtifactId(path);
090:                            final String newPath = StringUtils.replace(path,
091:                                    fileName, artifactId + '/' + version + '/'
092:                                            + versionedFileName);
093:                            final File bootstrapFile = new File(
094:                                    this .localArtifactDirectory, path);
095:                            final File repositoryFile = new File(
096:                                    this .localRepository.getBasedir(), newPath);
097:
098:                            if (bootstrapFile.lastModified() > repositoryFile
099:                                    .lastModified()) {
100:                                this .getLog().info(
101:                                        "Installing bootstrap artifact "
102:                                                + bootstrapFile + " to "
103:                                                + repositoryFile);
104:                                FileUtils.copyFile(bootstrapFile,
105:                                        repositoryFile);
106:                            }
107:                        }
108:                    } catch (final Throwable throwable) {
109:                        throw new MojoExecutionException(
110:                                "Error installing bootstrap artifact(s)",
111:                                throwable);
112:                    }
113:                }
114:            }
115:
116:            /**
117:             * Retrieves the artifact id from the given <code>path</code>.
118:             * @param path the path from which to retrieve the artifactId.
119:             * @return the artifactId.
120:             */
121:            private String getArtifactId(final String path) {
122:                return this .getFileName(path).replaceAll("\\..*", "");
123:            }
124:
125:            /**
126:             * Retrieves the file name from the given <code>path</code>.
127:             * @param path the path from which to retrieve the file name
128:             * @return the path.
129:             */
130:            private String getFileName(final String path) {
131:                return path.replaceAll(".*(\\\\|/)", "");
132:            }
133:
134:            /**
135:             * Retrieves the contents of this directory as a list of relative
136:             * paths.
137:             * @param the directory from which to retrieve the contents.
138:             * @return the contents of the directory as a list of relative paths.
139:             */
140:            private List getDirectoryContents(final File directory) {
141:                final List files = new ArrayList();
142:                this .loadFiles(directory, files);
143:                for (final ListIterator iterator = files.listIterator(); iterator
144:                        .hasNext();) {
145:                    final File file = (File) iterator.next();
146:                    final String filePath = file.toString().replace('\\', '/');
147:                    final String directoryPath = directory.toString().replace(
148:                            '\\', '/');
149:                    final String relativePath = StringUtils.replace(filePath,
150:                            directoryPath + '/', "");
151:                    if (!FilenameUtils.wildcardMatch(relativePath,
152:                            this .bootstrapDirectoryName + "**/*")) {
153:                        iterator.remove();
154:                    } else {
155:                        iterator.set(relativePath);
156:                    }
157:                }
158:                return files;
159:            }
160:
161:            /**
162:             * Loads all files find in the <code>directory</code> and adds them to the <code>fileList</code>.
163:             *
164:             * @param directory the directory from which to load all files.
165:             * @param fileList  the List of files to which we'll add the found files.
166:             * @param includeSubdirectories whether or not to include sub directories when loading the files.
167:             */
168:            private void loadFiles(final File directory, final List fileList) {
169:                if (directory != null) {
170:                    final File[] files = directory.listFiles();
171:                    if (files != null) {
172:                        for (int ctr = 0; ctr < files.length; ctr++) {
173:                            File file = files[ctr];
174:                            if (!file.isDirectory()) {
175:                                fileList.add(file);
176:                            } else {
177:                                loadFiles(file, fileList);
178:                            }
179:                        }
180:                    }
181:                }
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.