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


001:        package org.andromda.maven.plugin.modelarchiver;
002:
003:        import java.io.File;
004:        import java.io.FileReader;
005:        import java.io.FileWriter;
006:
007:        import org.apache.commons.io.IOUtils;
008:        import org.apache.commons.lang.StringUtils;
009:        import org.apache.maven.artifact.Artifact;
010:        import org.apache.maven.artifact.repository.ArtifactRepository;
011:        import org.apache.maven.plugin.AbstractMojo;
012:        import org.apache.maven.plugin.MojoExecutionException;
013:        import org.apache.maven.project.MavenProject;
014:        import org.codehaus.plexus.archiver.manager.ArchiverManager;
015:        import org.codehaus.plexus.util.FileUtils;
016:
017:        /**
018:         * Builds archived model uml2 files.
019:         *
020:         * @author Chad Brandon
021:         * @goal uml2
022:         * @phase package
023:         * @requiresProject
024:         * @description builds a versioned uml2
025:         */
026:        public class Uml2ArchiverMojo extends AbstractMojo {
027:            /**
028:             * Single directory that contains the model
029:             *
030:             * @parameter expression="${basedir}/src/main/uml"
031:             * @required
032:             */
033:            private File modelSourceDirectory;
034:
035:            /**
036:             * Directory that resources are copied to during the build.
037:             *
038:             * @parameter expression="${project.build.directory}"
039:             * @required
040:             */
041:            private String workDirectory;
042:
043:            /**
044:             * The directory for the generated uml2.
045:             *
046:             * @parameter expression="${project.build.outputDirectory}"
047:             * @required
048:             */
049:            private String outputDirectory;
050:
051:            /**
052:             * The name of the uml2 file to generate.
053:             *
054:             * @parameter alias="modelName" expression="${project.build.finalName}"
055:             * @required
056:             * @readonly
057:             */
058:            private String finalName;
059:
060:            /**
061:             * The maven project.
062:             *
063:             * @parameter expression="${project}"
064:             * @required
065:             * @readonly
066:             * @description "the maven project to use"
067:             */
068:            private MavenProject project;
069:
070:            /**
071:             * To look up Archiver/UnArchiver implementations
072:             *
073:             * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
074:             * @required
075:             */
076:            protected ArchiverManager archiverManager;
077:
078:            /**
079:             * The extensions to search for when doing replacement of embedded model HREF references
080:             * within the archived model file from non-versioned to versioned references.
081:             *
082:             * @parameter expression=".uml2"
083:             * @required
084:             */
085:            protected String replacementExtensions;
086:
087:            /**
088:             * Whether or not to do replacement of embedded model HREF reference extensions.
089:             *
090:             * @parameter expression=false
091:             * @required
092:             */
093:            protected boolean replaceExtensions;
094:
095:            /**
096:             * The pattern of the model file(s) that should be versioned.
097:             *
098:             * @parameter expression=".*(\\.uml2)"
099:             * @required
100:             * @readonly
101:             */
102:            private String modelFilePattern;
103:
104:            /**
105:             * @parameter expression="${localRepository}"
106:             * @required
107:             * @readonly
108:             */
109:            protected ArtifactRepository localRepository;
110:
111:            public void execute() throws MojoExecutionException {
112:                getLog().debug(" ======= Uml2ArchiverMojo settings =======");
113:                getLog().debug(
114:                        "modelSourceDirectory[" + modelSourceDirectory + "]");
115:                getLog().debug("workDirectory[" + workDirectory + "]");
116:                getLog().debug("outputDirectory[" + outputDirectory + "]");
117:                getLog().debug("finalName[" + finalName + "]");
118:                getLog().debug("replaceExtensions[" + replaceExtensions + "]");
119:
120:                try {
121:                    // - the directory which to extract the model file
122:                    final File modelExtractDirectory = new File(
123:                            this .workDirectory, "models/xmi");
124:                    modelExtractDirectory.mkdirs();
125:                    final File buildDirectory = new File(this .workDirectory);
126:
127:                    final File modelSourceDir = modelSourceDirectory;
128:                    final String[] replacementExtensions = this .replacementExtensions != null ? this .replacementExtensions
129:                            .split(",\\s*")
130:                            : new String[0];
131:                    if (modelSourceDir.exists()) {
132:                        getLog().info(
133:                                "Copy uml2 resources to "
134:                                        + buildDirectory.getAbsolutePath());
135:                        final File[] modelFiles = modelSourceDir.listFiles();
136:                        for (int ctr = 0; ctr < modelFiles.length; ctr++) {
137:                            final File file = modelFiles[ctr];
138:                            if (file.isFile()
139:                                    && file.toString().matches(
140:                                            this .modelFilePattern)) {
141:                                FileUtils.copyFileToDirectory(file,
142:                                        modelExtractDirectory);
143:
144:                                // - copy the model to the extract directory
145:                                final File[] extractedModelFiles = modelExtractDirectory
146:                                        .listFiles();
147:                                for (int ctr2 = 0; ctr2 < extractedModelFiles.length; ctr2++) {
148:                                    final File extractedFile = extractedModelFiles[ctr2];
149:                                    final String extractedFilePath = extractedFile
150:                                            .toString();
151:                                    if (extractedFile.isFile()
152:                                            && extractedFilePath
153:                                                    .matches(this .modelFilePattern)) {
154:                                        final File newFile = new File(
155:                                                buildDirectory,
156:                                                this .finalName
157:                                                        + '.'
158:                                                        + FileUtils
159:                                                                .getExtension(extractedFile
160:                                                                        .toString()));
161:                                        extractedFile.renameTo(newFile);
162:                                        String contents = IOUtils
163:                                                .toString(new FileReader(
164:                                                        newFile));
165:                                        if (replaceExtensions) {
166:                                            for (int ctr3 = 0; ctr3 < replacementExtensions.length; ctr3++) {
167:                                                final String version = escapePattern(this .project
168:                                                        .getVersion());
169:                                                final String extension = escapePattern(replacementExtensions[ctr3]);
170:                                                final String extensionPattern = "((\\-"
171:                                                        + version
172:                                                        + ")?)"
173:                                                        + extension;
174:                                                final String newExtension = "\\-"
175:                                                        + version + extension;
176:                                                contents = contents.replaceAll(
177:                                                        extensionPattern,
178:                                                        newExtension);
179:                                            }
180:                                        }
181:                                        final FileWriter fileWriter = new FileWriter(
182:                                                newFile);
183:                                        fileWriter.write(contents);
184:                                        fileWriter.flush();
185:                                    }
186:                                }
187:                            }
188:                        }
189:                    }
190:
191:                    final File uml2File = new File(buildDirectory,
192:                            this .finalName + ".uml2");
193:
194:                    final Artifact artifact = this .project.getArtifact();
195:
196:                    // - set the artifact file back to the correct file (since we've installed modelJar already)
197:                    artifact.setFile(uml2File);
198:                } catch (final Throwable throwable) {
199:                    throw new MojoExecutionException("Error assembling model",
200:                            throwable);
201:                }
202:            }
203:
204:            /**
205:             * Escapes the pattern so that the reserved regular expression
206:             * characters are used literally.
207:             * @param pattern the pattern to replace.
208:             * @return the resulting pattern.
209:             */
210:            private static String escapePattern(String pattern) {
211:                pattern = StringUtils.replace(pattern, ".", "\\.");
212:                pattern = StringUtils.replace(pattern, "-", "\\-");
213:                return pattern;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.