sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1811349 - in /sis/branches/JDK8: application/sis-console/ core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/ core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/
Date Fri, 06 Oct 2017 16:09:17 GMT
Author: desruisseaux
Date: Fri Oct  6 16:09:17 2017
New Revision: 1811349

URL: http://svn.apache.org/viewvc?rev=1811349&view=rev
Log:
Avoid usage of deprecated Maven API, and get the resource to include in PACK200 from Maven
itself instead than from "target/binaries" directory.

Modified:
    sis/branches/JDK8/application/sis-console/pom.xml
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Filenames.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/JarCollector.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/UnoPkg.java

Modified: sis/branches/JDK8/application/sis-console/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/pom.xml?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/pom.xml (original)
+++ sis/branches/JDK8/application/sis-console/pom.xml Fri Oct  6 16:09:17 2017
@@ -129,6 +129,12 @@ Console application.
       <version>${project.version}</version>
       <scope>runtime</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.sis.storage</groupId>
+      <artifactId>sis-gdal</artifactId>
+      <version>${project.version}</version>
+      <scope>runtime</scope>
+    </dependency>
 
     <!-- Test dependencies -->
     <dependency>

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Assembler.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -26,6 +26,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
@@ -36,24 +37,23 @@ import static org.apache.sis.internal.ma
 /**
  * Creates a ZIP files containing the content of the <code>application/sis-console/src/main/artifact</code>
  * directory together with the Pack200 file created by <code>BundleCreator</code>.
- * This mojo can be invoked from the command line as below:
+ * This mojo can be invoked from the command line in the {@code sis-console} module as below:
  *
- * <blockquote><code>mvn org.apache.sis.core:sis-build-helper:dist --non-recursive</code></blockquote>
- *
- * Do not forget the <code>--non-recursive</code> option, otherwise the Mojo
will be executed many time.
+ * <blockquote><code>mvn package org.apache.sis.core:sis-build-helper:dist</code></blockquote>
  *
  * <p><b>Current limitation:</b>
  * The current implementation uses some hard-coded paths and filenames.
- * See the <cite>Distribution file and Pack200 bundle</cite> section in the <code>src/site/apt/index.apt</code>
- * file for more information.</p>
+ * See the <cite>Distribution file and Pack200 bundle</cite> section in
+ * <a href="http://sis.apache.org/build.html">Build from source</a> page
+ * for more information.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
  * @since   0.4
  * @module
  */
-@Mojo(name = "dist", defaultPhase = LifecyclePhase.INSTALL)
-public class Assembler extends AbstractMojo implements FilenameFilter {
+@Mojo(name = "dist", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution
= ResolutionScope.COMPILE)
+public final class Assembler extends AbstractMojo implements FilenameFilter {
     /**
      * Project information (name, version, URL).
      */
@@ -61,6 +61,13 @@ public class Assembler extends AbstractM
     private MavenProject project;
 
     /**
+     * Base directory of the module to compile.
+     * Artifact content is expected in the {@code "src/main/artifact"} subdirectory.
+     */
+    @Parameter(property="basedir", required=true, readonly=true)
+    private String baseDirectory;
+
+    /**
      * The root directory (without the "<code>target/binaries</code>" sub-directory)
where JARs
      * are to be copied. It should be the directory of the root <code>pom.xml</code>.
      */
@@ -80,7 +87,7 @@ public class Assembler extends AbstractM
      */
     @Override
     public void execute() throws MojoExecutionException {
-        final File sourceDirectory = new File(rootDirectory, ARTIFACT_PATH);
+        final File sourceDirectory = new File(baseDirectory, ARTIFACT_PATH);
         if (!sourceDirectory.isDirectory()) {
             throw new MojoExecutionException("Directory not found: " + sourceDirectory);
         }
@@ -97,7 +104,7 @@ public class Assembler extends AbstractM
                  * have been zipped.  Now generate the Pack200 file and zip it directly (without
creating
                  * a temporary "sis.pack.gz" file).
                  */
-                final Packer packer = new Packer(project.getName(), version, targetDirectory);
+                final Packer packer = new Packer(project.getName(), version, BundleCreator.files(project),
targetDirectory);
                 final ZipArchiveEntry entry = new ZipArchiveEntry(
                         artifactBase + '/' + LIB_DIRECTORY + '/' + FATJAR_FILE + PACK_EXTENSION);
                 entry.setMethod(ZipArchiveEntry.STORED);

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/BundleCreator.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -18,11 +18,15 @@ package org.apache.sis.internal.maven;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
 
 import static org.apache.sis.internal.maven.Filenames.*;
@@ -38,16 +42,17 @@ import static org.apache.sis.internal.ma
  *
  * <p><b>Current limitation:</b>
  * The current implementation uses some hard-coded paths and filenames.
- * See the <cite>Distribution file and Pack200 bundle</cite> section in the <code>src/site/apt/index.apt</code>
- * file for more information.</p>
+ * See the <cite>Distribution file and Pack200 bundle</cite> section in
+ * <a href="http://sis.apache.org/build.html">Build from source</a> page
+ * for more information.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
  * @since   0.3
  * @module
  */
-@Mojo(name = "pack", defaultPhase = LifecyclePhase.INSTALL)
-public class BundleCreator extends AbstractMojo {
+@Mojo(name = "pack", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution
= ResolutionScope.COMPILE)
+public final class BundleCreator extends AbstractMojo {
     /**
      * Project information (name, version, URL).
      */
@@ -80,10 +85,30 @@ public class BundleCreator extends Abstr
         }
         final String version = project.getVersion();
         try {
-            final Packer packer = new Packer(project.getName(), version, targetDirectory);
+            final Packer packer = new Packer(project.getName(), version, files(project),
targetDirectory);
             packer.preparePack200(FINALNAME_PREFIX + version + ".jar").pack();
         } catch (IOException e) {
             throw new MojoExecutionException(e.getLocalizedMessage(), e);
         }
     }
+
+    /**
+     * Returns all files to include for the given Maven project.
+     */
+    static Set<File> files(final MavenProject project) throws MojoExecutionException
{
+        final Set<File> files = new LinkedHashSet<>();
+        files.add(project.getArtifact().getFile());
+        for (final Artifact dep : project.getArtifacts()) {
+            final String scope = dep.getScope();
+            if (Artifact.SCOPE_COMPILE.equalsIgnoreCase(scope) ||
+                Artifact.SCOPE_RUNTIME.equalsIgnoreCase(scope))
+            {
+                files.add(dep.getFile());
+            }
+        }
+        if (files.remove(null)) {
+            throw new MojoExecutionException("Invocation of this MOJO shall be done together
with a \"package\" Maven phase.");
+        }
+        return files;
+    }
 }

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Filenames.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Filenames.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Filenames.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Filenames.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -59,9 +59,9 @@ final class Filenames {
     static final String DISTRIBUTION_DIRECTORY = "distribution";
 
     /**
-     * The path to the directory (relative to the project root) to zip for creating the distribution
ZIP file.
+     * The path to the directory (relative to the project directory) to zip for creating
the distribution ZIP file.
      */
-    static final String ARTIFACT_PATH = "application/sis-console/src/main/artifact";
+    static final String ARTIFACT_PATH = "src/main/artifact";
 
     /**
      * The name of the sub-directory inside {@value #ARTIFACT_PATH} where the Pack200 file
will be located.

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/JarCollector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/JarCollector.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/JarCollector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/JarCollector.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -262,10 +262,10 @@ public final class JarCollector extends
 
     /**
      * Loads the {@value #CONTENT_FILE} from the given directory, if it exists.
-     * Otherwise returns an empty but modifiable set. This method is invoked only on
+     * Otherwise returns an empty but modifiable set. This method is invoked on
      * platforms that do not support hard links.
      */
-    static Set<String> loadDependencyList(final File dependenciesFile) throws IOException
{
+    private static Set<String> loadDependencyList(final File dependenciesFile) throws
IOException {
         final Set<String> dependencies = new LinkedHashSet<>();
         if (dependenciesFile.exists()) {
             try (BufferedReader in = new BufferedReader(new FileReader(dependenciesFile)))
{

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/maven/Packer.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -18,11 +18,8 @@ package org.apache.sis.internal.maven;
 
 import java.util.Map;
 import java.util.Set;
-import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.io.File;
-import java.io.FilenameFilter;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import static org.apache.sis.internal.maven.Filenames.*;
@@ -38,51 +35,36 @@ import static org.apache.sis.internal.ma
  * @since   0.3
  * @module
  */
-final class Packer implements FilenameFilter {
+final class Packer {
     /**
      * The project name and version to declare in the manifest file, or {@code null} if none.
      */
     private final String projectName, version;
 
     /**
-     * The Maven target directory. Shall contain the {@code "binaries"} sub-directory,
-     * which shall contain all JAR files collected by {@code sis-build-helper} plugin.
+     * JAR files of the main project together with its dependencies.
      */
-    private final File targetDirectory;
+    private final Set<File> files;
 
     /**
-     * The directory of input JAR files. Shall be {@code "target/binaries"}.
+     * The Maven target directory. Shall contain the {@code "binaries"} sub-directory,
+     * which shall contain all JAR files collected by {@code sis-build-helper} plugin.
      */
-    private final File binariesDirectory;
+    private final File targetDirectory;
 
     /**
      * Creates a packer.
      *
      * @param  projectName      the project name to declare in the manifest file, or {@code
null} if none.
      * @param  version          the project version to declare in the manifest file, or {@code
null} if none.
+     * @param  files            the JAR files of the main project together with its dependencies.
      * @param  targetDirectory  the Maven target directory.
-     * @throws FileNotFoundException if the {@code target/binaries} directory is not found.
      */
-    Packer(final String projectName, final String version, final File targetDirectory) throws
FileNotFoundException {
-        this.projectName = projectName;
-        this.version     = version;
+    Packer(final String projectName, final String version, final Set<File> files, final
File targetDirectory) {
+        this.projectName     = projectName;
+        this.version         = version;
+        this.files           = files;
         this.targetDirectory = targetDirectory;
-        this.binariesDirectory = new File(targetDirectory, BINARIES_DIRECTORY);
-        if (!binariesDirectory.isDirectory()) {
-            throw new FileNotFoundException("Directory not found: " + binariesDirectory);
-        }
-    }
-
-    /**
-     * Filter the input JAR files. This is for internal usage by {@link #createOutputJAR(String)}
only.
-     *
-     * @param  directory  the directory (ignored).
-     * @param  name       the filename.
-     * @return {@code true} if the given filename ends with {@code ".jar"}.
-     */
-    @Override
-    public boolean accept(final File directory, final String name) {
-        return name.endsWith(".jar");
     }
 
     /**
@@ -90,14 +72,8 @@ final class Packer implements FilenameFi
      * All input JAR files are opened by this method. They will need to be closed by {@link
PackInput#close()}.
      */
     private Map<File,PackInput> getInputJARs() throws IOException {
-        final Set<String> filenames = JarCollector.loadDependencyList(new File(binariesDirectory,
CONTENT_FILE));
-        filenames.addAll(Arrays.asList(binariesDirectory.list(this)));
-        final Map<File,PackInput> inputJARs = new LinkedHashMap<>(filenames.size()
* 4/3);
-        for (final String filename : filenames) {
-            File file = new File(filename);
-            if (!file.isAbsolute()) {
-                file = new File(binariesDirectory, filename);
-            }
+        final Map<File,PackInput> inputJARs = new LinkedHashMap<>(files.size()
* 4/3);
+        for (final File file : files) {
             if (!file.isFile() || !file.canRead()) {
                 throw new IllegalArgumentException("Not a file or can not read: " + file);
             }

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/UnoPkg.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/UnoPkg.java?rev=1811349&r1=1811348&r2=1811349&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/UnoPkg.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/unopkg/UnoPkg.java
[UTF-8] Fri Oct  6 16:09:17 2017
@@ -31,6 +31,7 @@ import org.apache.maven.artifact.Artifac
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
 
 import static java.util.jar.Pack200.Packer;
 
@@ -43,7 +44,7 @@ import static java.util.jar.Pack200.Pack
  * @since   0.8
  * @module
  */
-@Mojo(name = "unopkg", defaultPhase = LifecyclePhase.PACKAGE)
+@Mojo(name = "unopkg", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution
= ResolutionScope.COMPILE)
 public final class UnoPkg extends AbstractMojo implements FilenameFilter {
     /**
      * The subdirectory (relative to {@link #baseDirectory}) where the UNO files are expected.
@@ -62,7 +63,7 @@ public final class UnoPkg extends Abstra
 
     /**
      * Base directory of the module to compile.
-     * The UNO files are expect in the {@code "src/main/unopkg"} subdirectory.
+     * The UNO files are expected in the {@code "src/main/unopkg"} subdirectory.
      * The plugin will look for the {@code META-INF/manifest.xml} and {@code *.rdb} files
in that directory.
      */
     @Parameter(property="basedir", required=true, readonly=true)
@@ -184,6 +185,8 @@ public final class UnoPkg extends Abstra
             }
             /*
              * Copies the dependencies, optionally in a single PACK200 entry.
+             * We discard most debug information because stack traces are not
+             * easy to get from an application running in OpenOffice anyway.
              */
             Pack200.Packer packer = null;
             if (Boolean.parseBoolean(pack200)) {
@@ -199,11 +202,10 @@ public final class UnoPkg extends Abstra
                 p.put(Packer.DEFLATE_HINT,      Packer.TRUE);       // transmitting a single
request to use "compress" mode.
                 p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);      // throw an error if
an attribute is unrecognized.
             }
-            for (final Artifact artifact : project.getDependencyArtifacts()) {
+            for (final Artifact artifact : project.getArtifacts()) {
                 final String scope = artifact.getScope();
-                if (scope != null &&  // Maven 2.0.6 bug?
-                   (scope.equalsIgnoreCase(Artifact.SCOPE_COMPILE) ||
-                    scope.equalsIgnoreCase(Artifact.SCOPE_RUNTIME)))
+                if (Artifact.SCOPE_COMPILE.equalsIgnoreCase(scope) ||
+                    Artifact.SCOPE_RUNTIME.equalsIgnoreCase(scope))
                 {
                     final File file = artifact.getFile();
                     String name = file.getName();
@@ -211,7 +213,7 @@ public final class UnoPkg extends Abstra
                         name = prefix + name;
                     }
                     if (packer != null && name.endsWith(".jar")) {
-                        name = name.substring(0, name.length()-3) + "pack";
+                        name = name.substring(0, name.length() - 3) + "pack";
                         try (JarFile jar = new FilteredJarFile(file)) {
                             out.putNextEntry(new ZipEntry(name));
                             packer.pack(jar, out);



Mime
View raw message