Source Code Cross Referenced for WriteFileNameArtifactsMojo.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » plugin » artifact » 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 » J2EE » ow2 easybeans » org.ow2.easybeans.plugin.artifact 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2007 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
019:         *
020:         * --------------------------------------------------------------------------
021:         * $Id: WriteFileNameArtifactsMojo.java 1970 2007-10-16 11:49:25Z benoitf $
022:         * --------------------------------------------------------------------------
023:         */package org.ow2.easybeans.plugin.artifact;
024:
025:        import java.io.File;
026:        import java.io.FileWriter;
027:        import java.io.IOException;
028:        import java.util.ArrayList;
029:        import java.util.List;
030:
031:        import org.apache.maven.artifact.Artifact;
032:        import org.apache.maven.artifact.factory.ArtifactFactory;
033:        import org.apache.maven.artifact.repository.ArtifactRepository;
034:        import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
035:        import org.apache.maven.artifact.resolver.ArtifactResolutionException;
036:        import org.apache.maven.artifact.resolver.ArtifactResolver;
037:        import org.apache.maven.model.Dependency;
038:        import org.apache.maven.model.DependencyManagement;
039:        import org.apache.maven.plugin.AbstractMojo;
040:        import org.apache.maven.plugin.MojoExecutionException;
041:        import org.apache.maven.project.MavenProject;
042:
043:        /**
044:         * Dump the name of the given Artifacts into a file.
045:         * @goal resolve
046:         * @phase compile
047:         * @author Florent Benoit
048:         */
049:        public class WriteFileNameArtifactsMojo extends AbstractMojo {
050:
051:            /**
052:             * Artifact Factory used to create Artifacts.
053:             * @component
054:             */
055:            private ArtifactFactory artifactFactory;
056:
057:            /**
058:             * Artifact Resolver used to resolve artifacts.
059:             * @component
060:             */
061:            private ArtifactResolver artifactResolver;
062:
063:            /**
064:             * Local Maven repository used by the Artifact Resolver.
065:             * @parameter expression="${localRepository}"
066:             */
067:            private ArtifactRepository localRepository;
068:
069:            /**
070:             * List of Maven repositories (remote) used by the Artifact Resolver.
071:             * @parameter expression="${project.remoteArtifactRepositories}"
072:             */
073:            private List<?> repositories;
074:
075:            /**
076:             * Path of the build directory.
077:             * @parameter expression="${project.build.directory}"
078:             */
079:            private File buildDirectory;
080:
081:            /**
082:             * Name of the file where to print the list of the files.
083:             * @parameter
084:             */
085:            private File outputFile;
086:
087:            /**
088:             * List of Modules that needs to be printed in a file.
089:             * @parameter
090:             */
091:            private Module[] modules;
092:
093:            /**
094:             * The maven project.
095:             * @parameter expression="${project}"
096:             * @required
097:             * @readonly
098:             */
099:            private MavenProject project;
100:
101:            /**
102:             * Execute the Maven plugin.
103:             * @throws MojoExecutionException if the file is not generated.
104:             */
105:            @SuppressWarnings("unchecked")
106:            public void execute() throws MojoExecutionException {
107:
108:                // No parameter, use default
109:                if (outputFile == null) {
110:                    outputFile = new File(buildDirectory, "list-of-files.txt");
111:                }
112:
113:                // Create directory if not existing
114:                outputFile.getParentFile().mkdirs();
115:
116:                // Build artifacts from modules
117:                if (modules == null) {
118:                    throw new MojoExecutionException(
119:                            "No modules element has been set");
120:                }
121:
122:                // Create list
123:                List<Artifact> artifacts = new ArrayList<Artifact>();
124:
125:                // for each module, build artifact.
126:                for (Module module : modules) {
127:                    String groupId = module.getGroupId();
128:                    String artifactId = module.getArtifactId();
129:                    String type = module.getType();
130:                    String version = module.getVersion();
131:
132:                    if (groupId == null) {
133:                        throw new MojoExecutionException(
134:                                "No groupdId set for module '" + module + "'");
135:                    }
136:                    if (artifactId == null) {
137:                        throw new MojoExecutionException(
138:                                "No artifactId set for module '" + module + "'");
139:                    }
140:
141:                    if (type == null) {
142:                        getLog().debug(
143:                                "No type set for module '" + module
144:                                        + "', assume it is jar type");
145:                        type = "jar";
146:                        module.setType(type);
147:                    }
148:
149:                    if (version == null) {
150:                        // try to find version with dependency management
151:                        DependencyManagement dependencyManagement = project
152:                                .getDependencyManagement();
153:
154:                        if (dependencyManagement != null) {
155:                            // try to find a version for this component
156:                            List<Dependency> dependencies = dependencyManagement
157:                                    .getDependencies();
158:                            if (dependencies != null) {
159:                                for (Dependency dependency : dependencies) {
160:                                    getLog()
161:                                            .debug("Dependency = " + dependency);
162:                                    if (groupId.equals(dependency.getGroupId())
163:                                            && artifactId.equals(dependency
164:                                                    .getArtifactId())
165:                                            && type
166:                                                    .equals(dependency
167:                                                            .getType())) {
168:                                        getLog().debug(
169:                                                "Using version of dependency management"
170:                                                        + dependency
171:                                                                .getVersion());
172:                                        version = dependency.getVersion();
173:                                        break;
174:                                    }
175:                                }
176:                            }
177:                        }
178:                        if (version == null) {
179:                            throw new MojoExecutionException(
180:                                    "No version set for module '" + module
181:                                            + "'");
182:                        }
183:                    }
184:
185:                    Artifact artifact = artifactFactory.createBuildArtifact(
186:                            groupId, artifactId, version, type);
187:                    getLog().debug("Built Artifact = " + artifact);
188:
189:                    // now resolve this artifact
190:                    try {
191:                        artifactResolver.resolve(artifact, repositories,
192:                                localRepository);
193:                    } catch (ArtifactResolutionException e) {
194:                        throw new MojoExecutionException(
195:                                "Cannot resolve artifact '" + artifactId + "'.",
196:                                e);
197:                    } catch (ArtifactNotFoundException e) {
198:                        throw new MojoExecutionException("Artifact '"
199:                                + artifactId + "' not found.", e);
200:                    }
201:
202:                    // Add artifact
203:                    artifacts.add(artifact);
204:
205:                }
206:
207:                FileWriter fileWriter = null;
208:                try {
209:                    // Create file writer
210:                    try {
211:                        fileWriter = new FileWriter(outputFile);
212:                    } catch (IOException e) {
213:                        throw new MojoExecutionException(
214:                                "Cannot create a file on '" + outputFile + "'",
215:                                e);
216:                    }
217:
218:                    // Write the name of the files
219:                    for (Artifact artifact : artifacts) {
220:                        try {
221:                            getLog().debug(
222:                                    "Writing " + artifact.getFile().getName());
223:                            fileWriter.write(artifact.getFile().getName());
224:                            fileWriter.write("\n");
225:                        } catch (IOException e) {
226:                            throw new MojoExecutionException(
227:                                    "Cannot write the line for Artifact '"
228:                                            + artifact + "' in the file '"
229:                                            + outputFile + "'", e);
230:                        }
231:                    }
232:                } finally {
233:                    // close file writer
234:                    if (fileWriter != null) {
235:                        try {
236:                            fileWriter.close();
237:                        } catch (IOException e) {
238:                            getLog().debug("Cannot close the file writer", e);
239:                        }
240:                    }
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.