Class JarCollector

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.sis.internal.maven.JarCollector
All Implemented Interfaces:
FileFilter, org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="collect-jars", defaultPhase=PACKAGE, requiresDependencyResolution=RUNTIME) public final class JarCollector extends org.apache.maven.plugin.AbstractMojo implements FileFilter
Collects .jar files in a single "target/binaries" directory. Dependencies are collected as well, except if already presents. This mojo uses hard links on platforms that support them. If hard links are not supported, then this mojo will instead creates a "target/binaries/other_dependencies.txt" file listing the dependencies.
Since:
0.3
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.apache.maven.project.MavenProject
    The Maven project running this plugin.
    private String
    The root directory (without the "target/binaries" sub-directory) where JARs are to be copied.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Invoked by reflection for creating the MOJO.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    accept(File pathname)
    Filters the content of the "target" directory in order to keep only the project build result.
    private void
    Implementation of the execute() method.
    void
    Copies the *.jar files to the collect directory.
    private static String
    getFinalName(File file, org.apache.maven.artifact.Artifact artifact)
    Returns the name of the given file.
    private File
    Returns the JAR file, or null if none.
    private static void
    Creates a link from the given source file to the given target file.
    private static Set<String>
    loadDependencyList(File dependenciesFile)
    Loads the from the given directory, if it exists.

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • project

      @Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject project
      The Maven project running this plugin.
    • rootDirectory

      @Parameter(property="session.executionRootDirectory", required=true) private String rootDirectory
      The root directory (without the "target/binaries" sub-directory) where JARs are to be copied. It should be the directory of the root pom.xml.
  • Constructor Details

    • JarCollector

      public JarCollector()
      Invoked by reflection for creating the MOJO.
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Copies the *.jar files to the collect directory.
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if the plugin execution failed.
    • collect

      private void collect() throws org.apache.maven.plugin.MojoExecutionException, IOException
      Implementation of the execute() method.
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      IOException
    • accept

      public boolean accept(File pathname)
      Filters the content of the "target" directory in order to keep only the project build result. We scan the directory because the final name may be different than the actual file name, because a classifier may have been added to the name.

      The .jar extension is not quite appropriate for source and Javadoc files; a better extension would be .zip. Unfortunately, the .jar extension for those content is a very common practice, so we have to filter them.

      Specified by:
      accept in interface FileFilter
    • getProjectFile

      private File getProjectFile()
      Returns the JAR file, or null if none. In case of doubt, conservatively returns null.
    • getFinalName

      private static String getFinalName(File file, org.apache.maven.artifact.Artifact artifact)
      Returns the name of the given file. If the given file is a snapshot, then the "SNAPSHOT" will be replaced by the timestamp if possible.
      Parameters:
      file - the file from which to get the filename.
      artifact - the artifact that produced the given file.
      Returns:
      the filename to use.
    • linkFileToDirectory

      private static void linkFileToDirectory(File file, File copy) throws IOException
      Creates a link from the given source file to the given target file. On platforms that do not support links, this method rather updates the "other_dependencies.txt" file.
      Parameters:
      file - the source file to read.
      copy - the destination file to create.
      Throws:
      IOException
    • loadDependencyList

      private static Set<String> loadDependencyList(File dependenciesFile) throws IOException
      Loads the from the given directory, if it exists. Otherwise returns an empty but modifiable set. This method is invoked on platforms that do not support hard links.
      Throws:
      IOException