Source Code Cross Referenced for JarCollector.java in  » GIS » GeoTools-2.4.1 » org » geotools » maven » 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 » GIS » GeoTools 2.4.1 » org.geotools.maven 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-2006, GeoTools Project Managment Committee (PMC)
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;
009:         *    version 2.1 of the License.
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:        package org.geotools.maven;
017:
018:        // J2SE dependencies
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.util.Iterator;
022:        import java.util.Set;
023:
024:        // Maven and Plexus dependencies
025:        import org.apache.maven.plugin.AbstractMojo;
026:        import org.apache.maven.plugin.MojoExecutionException;
027:        import org.apache.maven.project.MavenProject;
028:        import org.apache.maven.artifact.Artifact;
029:        import org.codehaus.plexus.util.FileUtils;
030:
031:        // Note: javadoc in class and fields descriptions must be XHTML.
032:        /**
033:         * Copies <code>.jar</code> files in a single directory. Dependencies are copied as well,
034:         * except if already presents.
035:         * 
036:         * @goal collect
037:         * @phase package
038:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/build/maven/jar-collector/src/main/java/org/geotools/maven/JarCollector.java $
039:         * @version $Id: JarCollector.java 25335 2007-04-25 13:46:57Z desruisseaux $
040:         * @author Martin Desruisseaux
041:         */
042:        public class JarCollector extends AbstractMojo {
043:            /**
044:             * The sub directory to create inside the "target" directory.
045:             */
046:            private static final String SUB_DIRECTORY = "binaries";
047:
048:            /**
049:             * The directory where JARs are to be copied. It should
050:             * be the "target" directory of the parent {@code pom.xml}.
051:             */
052:            private String collectDirectory;
053:
054:            /**
055:             * Directory containing the generated JAR.
056:             *
057:             * @parameter expression="${project.build.directory}"
058:             * @required
059:             */
060:            private String outputDirectory;
061:
062:            /**
063:             * Name of the generated JAR.
064:             *
065:             * @parameter expression="${project.build.finalName}"
066:             * @required
067:             */
068:            private String jarName;
069:
070:            /**
071:             * Project dependencies.
072:             *
073:             * @parameter expression="${project.artifacts}"
074:             * @required
075:             */
076:            private Set/*<Artifact>*/dependencies;
077:
078:            /**
079:             * The Maven project running this plugin.
080:             *
081:             * @parameter expression="${project}"
082:             * @required
083:             */
084:            private MavenProject project;
085:
086:            /**
087:             * Copies the {@code .jar} files to the collect directory.
088:             *
089:             * @throws MojoExecutionException if the plugin execution failed.
090:             */
091:            public void execute() throws MojoExecutionException {
092:                /*
093:                 * Gets the parent "target" directory.
094:                 */
095:                MavenProject parent = project;
096:                while (parent.hasParent()) {
097:                    parent = parent.getParent();
098:                }
099:                collectDirectory = parent.getBuild().getDirectory();
100:                /*
101:                 * Now collects the JARs.
102:                 */
103:                try {
104:                    collect();
105:                } catch (IOException e) {
106:                    throw new MojoExecutionException(
107:                            "Error collecting the JAR file.", e);
108:                }
109:            }
110:
111:            /**
112:             * Implementation of the {@link #execute} method.
113:             */
114:            private void collect() throws MojoExecutionException, IOException {
115:                /*
116:                 * Make sure that we are collecting the JAR file from a module which produced
117:                 * such file. Some modules use pom packaging, which do not produce any JAR file.
118:                 */
119:                final File jarFile = new File(outputDirectory, jarName + ".jar");
120:                if (!jarFile.isFile()) {
121:                    return;
122:                }
123:                /*
124:                 * Get the "target" directory of the parent pom.xml and make sure it exists.
125:                 */
126:                File collect = new File(collectDirectory);
127:                if (!collect.exists()) {
128:                    if (!collect.mkdir()) {
129:                        throw new MojoExecutionException(
130:                                "Failed to create target directory.");
131:                    }
132:                }
133:                if (collect.getCanonicalFile().equals(
134:                        jarFile.getParentFile().getCanonicalFile())) {
135:                    /*
136:                     * The parent's directory is the same one than this module's directory.
137:                     * In other words, this plugin is not executed from the parent POM. Do
138:                     * not copy anything, since this is not the place where we want to
139:                     * collect the JAR files.
140:                     */
141:                    return;
142:                }
143:                /*
144:                 * Creates a "binaries" subdirectory inside the "target" directory.
145:                 */
146:                collect = new File(collect, SUB_DIRECTORY);
147:                if (!collect.exists()) {
148:                    if (!collect.mkdir()) {
149:                        throw new MojoExecutionException(
150:                                "Failed to create binaries directory.");
151:                    }
152:                }
153:                int count = 1;
154:                FileUtils.copyFileToDirectory(jarFile, collect);
155:                if (dependencies != null) {
156:                    for (final Iterator it = dependencies.iterator(); it
157:                            .hasNext();) {
158:                        final Artifact artifact = (Artifact) it.next();
159:                        final String scope = artifact.getScope();
160:                        if (scope != null && // Maven 2.0.6 bug?
161:                                (scope.equalsIgnoreCase(Artifact.SCOPE_COMPILE) || scope
162:                                        .equalsIgnoreCase(Artifact.SCOPE_RUNTIME))) {
163:                            final File file = artifact.getFile();
164:                            final File copy = new File(collect, file.getName());
165:                            if (!copy.exists()) {
166:                                /*
167:                                 * Copies the dependency only if it was not already copied. Note that
168:                                 * the module's JAR was copied inconditionnaly above (because it may
169:                                 * be the result of a new compilation). If a Geotools JAR from the
170:                                 * dependencies list changed, it will be copied inconditionnaly when
171:                                 * the module for this JAR will be processed by Maven.
172:                                 */
173:                                FileUtils.copyFileToDirectory(file, collect);
174:                                count++;
175:                            }
176:                        }
177:                    }
178:                }
179:                getLog().info("Copied " + count + " JAR to parent directory.");
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.