forked from geodmms/xdgnjobs

Dennis Kao
2014-01-15 94ae08701bbd7585a0b7e5a92d1975965a503c03
xdgnjobs/ximple-build/maven/jar-collector/src/main/java/com/ximple/eofms/maven/JarCollector.java
@@ -55,14 +55,6 @@
    private String jarName;
    /**
     * Project dependencies.
     *
     * @parameter expression="${project.artifacts}"
     * @required
     */
    private Set /*<Artifact>*/ dependencies;
    /**
     * The Maven project running this plugin.
     *
     * @parameter expression="${project}"
@@ -80,13 +72,10 @@
         * Gets the parent "target" directory.
         */
        MavenProject parent = project;
        while (parent.hasParent()) {
            parent = parent.getParent();
        }
        collectDirectory = parent.getBuild().getDirectory();
        /*
         * Now collects the JARs.
         */
@@ -106,22 +95,18 @@
         * such file. Some modules use pom packaging, which do not produce any JAR file.
         */
        final File jarFile = new File(outputDirectory, jarName + ".jar");
        if (!jarFile.isFile()) {
            return;
        }
        /*
         * Get the "target" directory of the parent pom.xml and make sure it exists.
         */
        File collect = new File(collectDirectory);
        if (!collect.exists()) {
            if (!collect.mkdir()) {
                throw new MojoExecutionException("Failed to create target directory.");
                throw new MojoExecutionException("Failed to create target directory: " + collect.getAbsolutePath());
            }
        }
        if (collect.getCanonicalFile().equals(jarFile.getParentFile().getCanonicalFile())) {
            /*
             * The parent's directory is the same one than this module's directory.
@@ -131,47 +116,42 @@
             */
            return;
        }
        /*
         * Creates a "binaries" subdirectory inside the "target" directory.
         */
        collect = new File(collect, SUB_DIRECTORY);
        if (!collect.exists()) {
            if (!collect.mkdir()) {
                throw new MojoExecutionException("Failed to create binaries directory.");
            }
        }
        int count = 1;
        FileUtils.copyFileToDirectory(jarFile, collect);
      Set<Artifact> dependencies = project.getDependencyArtifacts();
        if (dependencies != null) {
            for (final Iterator it = dependencies.iterator(); it.hasNext();) {
                final Artifact artifact = (Artifact) it.next();
            for (final Artifact artifact : dependencies) {
            System.out.println("+++++++++++++++++++++++ DEP: " + artifact.getDependencyTrail());
                final String scope = artifact.getScope();
                if ((scope != null) // Maven 2.0.6 bug?
                        && (scope.equalsIgnoreCase(Artifact.SCOPE_COMPILE)
                        || scope.equalsIgnoreCase(Artifact.SCOPE_RUNTIME))) {
                if (scope != null &&  // Maven 2.0.6 bug?
                   (scope.equalsIgnoreCase(Artifact.SCOPE_COMPILE) ||
                    scope.equalsIgnoreCase(Artifact.SCOPE_RUNTIME)))
                {
                    final File file = artifact.getFile();
                    final File copy = new File(collect, file.getName());
                    if (!copy.exists()) {
                        /*
                         * Copies the dependency only if it was not already copied. Note that
                         * the module's JAR was copied inconditionnaly above (because it may
                         * be the result of a new compilation). If a Geotools JAR from the
                         * dependencies list changed, it will be copied inconditionnaly when
                         * the module for this JAR will be processed by Maven.
                         */
                        FileUtils.copyFileToDirectory(file, collect);
                        count++;
                    if (!artifact.getGroupId().startsWith("com.ximple.eofms")) {
                        final File copy = new File(collect, file.getName());
                        if (copy.exists()) {
                            /*
                             * Copies the dependency only if it was not already copied. Note that
                             * the module's JAR was copied inconditionnaly above (because it may
                             * be the result of a new compilation). If a Geotools JAR from the
                             * dependencies list changed, it will be copied inconditionnaly when
                             * the module for this JAR will be processed by Maven.
                             */
                            continue;
                        }
                    }
                    FileUtils.copyFileToDirectory(file, collect);
                }
            }
        }
        getLog().info("Copied " + count + " JAR to parent directory.");
    }
}