Package org.apache.sis.internal.maven
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
FieldsModifier and TypeFieldDescriptionprivate 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 -
Method Summary
Modifier and TypeMethodDescriptionboolean
Filters the content of the "target" directory in order to keep only the project build result.private void
collect()
Implementation of theexecute()
method.void
execute()
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, ornull
if none.private static void
linkFileToDirectory
(File file, File copy) Creates a link from the given source file to the given target file.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
-
Field Details
-
project
@Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject projectThe Maven project running this plugin. -
rootDirectory
The root directory (without the "target/binaries
" sub-directory) where JARs are to be copied. It should be the directory of the rootpom.xml
.
-
-
Constructor Details
-
JarCollector
public JarCollector()Invoked by reflection for creating the MOJO.
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionExceptionCopies the*.jar
files to the collect directory.- Specified by:
execute
in interfaceorg.apache.maven.plugin.Mojo
- Throws:
org.apache.maven.plugin.MojoExecutionException
- if the plugin execution failed.
-
collect
Implementation of theexecute()
method.- Throws:
org.apache.maven.plugin.MojoExecutionException
IOException
-
accept
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 interfaceFileFilter
-
getProjectFile
Returns the JAR file, ornull
if none. In case of doubt, conservatively returnsnull
. -
getFinalName
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
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
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
-