Class BuildClasspathMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.dependency.AbstractDependencyMojo
-
- org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo
-
- org.apache.maven.plugins.dependency.fromDependencies.BuildClasspathMojo
-
- All Implemented Interfaces:
java.util.Comparator<org.apache.maven.artifact.Artifact>,org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="build-classpath", requiresDependencyResolution=TEST, defaultPhase=GENERATE_SOURCES, threadSafe=true) public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements java.util.Comparator<org.apache.maven.artifact.Artifact>This goal outputs a classpath string of dependencies from the local repository to a file or log.- Since:
- 2.0-alpha-2
-
-
Field Summary
Fields Modifier and Type Field Description private booleanattachAttach the classpath file to the main artifact so it can be installed and deployed.private java.lang.StringfileSeparatorOverride the char used between the paths.private java.lang.StringlocalRepoPropertyReplace the absolute path to the local repo with this property.private java.lang.StringoutputEncodingprivate java.io.FileoutputFileIf defined, the file to which the classpath string will be written.private booleanoutputFilterFileWrite out the classpath in a format compatible with filtering (classpath=xxxxx)private java.lang.StringoutputPropertyIf defined, the name of a property to which the classpath string will be written.private java.lang.StringpathSeparatorOverride the char used between path folders.private java.lang.StringprefixThe prefix to prepend on each dependent artifact.private org.apache.maven.project.MavenProjectHelperprojectHelperprivate booleanregenerateFileIf 'true', it skips the up-to-date-check, and always regenerates the classpath file.private booleanstripClassifierStrip artifact classifier during copy (only works if prefix is set)private booleanstripVersionStrip artifact version during copy (only works if prefix is set)private booleanuseBaseVersionEither append the artifact's baseVersion or uniqueVersion to the filename.-
Fields inherited from class org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo
classifier, excludeArtifactIds, excludeClassifiers, excludeGroupIds, excludeScope, excludeTransitive, excludeTypes, includeArtifactIds, includeClassifiers, includeGroupIds, includeScope, includeTypes, markersDirectory, overWriteIfNewer, overWriteReleases, overWriteSnapshots, prependGroupId, type
-
Fields inherited from class org.apache.maven.plugins.dependency.AbstractDependencyMojo
session
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBuildClasspathMojo(org.apache.maven.execution.MavenSession session, org.sonatype.plexus.build.incremental.BuildContext buildContext, org.apache.maven.project.MavenProject project, ResolverUtil resolverUtil, org.apache.maven.project.ProjectBuilder projectBuilder, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.project.MavenProjectHelper projectHelper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendArtifactPath(org.apache.maven.artifact.Artifact art, java.lang.StringBuilder sb)Appends the artifact path to the specified StringBuilder.protected voidattachFile(java.lang.String cpString)intcompare(org.apache.maven.artifact.Artifact art1, org.apache.maven.artifact.Artifact art2)Compares artifacts lexicographically, using pattern [group_id][artifact_id][version].protected voiddoExecute()Main entry into mojo.protected org.apache.maven.shared.artifact.filter.collection.ArtifactsFiltergetMarkedArtifactFilter()Return anArtifactsFilterindicating which artifacts must be filtered out.booleanisStripVersion()private booleanisUpToDate(java.lang.String cpString)Checks that new classpath differs from that found inside the old classpathFile.protected java.lang.StringreadClasspathFile()Reads the file specified by the mojo param 'outputFile' into a string.voidsetFileSeparator(java.lang.String theFileSeparator)voidsetLocalRepoProperty(java.lang.String localRepoProperty)voidsetOutputFile(java.io.File outputFile)voidsetOutputProperty(java.lang.String theOutputProperty)voidsetPathSeparator(java.lang.String thePathSeparator)voidsetPrefix(java.lang.String thePrefix)voidsetRegenerateFile(boolean theRegenerateFile)voidsetStripVersion(boolean theStripVersion)private voidstoreClasspathFile(java.lang.String cpString, java.io.File out)Stores the specified string into that file.-
Methods inherited from class org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo
filterMarkedDependencies, getDependencySets, getDependencySets, getMarkersDirectory, getResolvedDependencies, getResolverUtil, isPrependGroupId, setMarkersDirectory, setPrependGroupId
-
Methods inherited from class org.apache.maven.plugins.dependency.AbstractDependencyMojo
execute, getProject, isSilent, isSkip, setSilent, setSkip
-
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
-
-
-
Field Detail
-
outputEncoding
@Parameter(property="outputEncoding", defaultValue="${project.reporting.outputEncoding}") private java.lang.String outputEncoding
-
stripVersion
@Parameter(property="mdep.stripVersion", defaultValue="false") private boolean stripVersionStrip artifact version during copy (only works if prefix is set)
-
stripClassifier
@Parameter(property="mdep.stripClassifier", defaultValue="false") private boolean stripClassifierStrip artifact classifier during copy (only works if prefix is set)
-
prefix
@Parameter(property="mdep.prefix") private java.lang.String prefix
The prefix to prepend on each dependent artifact. If undefined, the paths refer to the actual files store in the local repository (the stripVersion parameter does nothing then).
-
outputProperty
@Parameter(property="mdep.outputProperty") private java.lang.String outputProperty
If defined, the name of a property to which the classpath string will be written. If neither this nor the outputFile parameter is set, the classpath will be logged at INFO level.
-
outputFile
@Parameter(property="mdep.outputFile") private java.io.File outputFile
If defined, the file to which the classpath string will be written. If neither this nor the outputProperty parameter is set, the classpath will be logged at INFO level.
-
regenerateFile
@Parameter(property="mdep.regenerateFile", defaultValue="false") private boolean regenerateFileIf 'true', it skips the up-to-date-check, and always regenerates the classpath file.
-
fileSeparator
@Parameter(property="mdep.fileSeparator", defaultValue="") private java.lang.String fileSeparatorOverride the char used between the paths. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\'. The default is File.separator.- Since:
- 2.0
-
pathSeparator
@Parameter(property="mdep.pathSeparator", defaultValue="") private java.lang.String pathSeparatorOverride the char used between path folders. The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.- Since:
- 2.0
-
localRepoProperty
@Parameter(property="mdep.localRepoProperty", defaultValue="") private java.lang.String localRepoPropertyReplace the absolute path to the local repo with this property. This field is ignored it prefix is declared. The value will be forced to "${M2_REPO}" if no value is provided AND the attach flag is true.- Since:
- 2.0
-
attach
@Parameter(defaultValue="false") private boolean attach
Attach the classpath file to the main artifact so it can be installed and deployed.- Since:
- 2.0
-
outputFilterFile
@Parameter(property="mdep.outputFilterFile", defaultValue="false") private boolean outputFilterFileWrite out the classpath in a format compatible with filtering (classpath=xxxxx)- Since:
- 2.0
-
useBaseVersion
@Parameter(property="mdep.useBaseVersion", defaultValue="true") private boolean useBaseVersionEither append the artifact's baseVersion or uniqueVersion to the filename. Will only be used ifisStripVersion()isfalse.- Since:
- 2.6
-
projectHelper
private final org.apache.maven.project.MavenProjectHelper projectHelper
-
-
Constructor Detail
-
BuildClasspathMojo
@Inject protected BuildClasspathMojo(org.apache.maven.execution.MavenSession session, org.sonatype.plexus.build.incremental.BuildContext buildContext, org.apache.maven.project.MavenProject project, ResolverUtil resolverUtil, org.apache.maven.project.ProjectBuilder projectBuilder, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.project.MavenProjectHelper projectHelper)
-
-
Method Detail
-
doExecute
protected void doExecute() throws org.apache.maven.plugin.MojoExecutionExceptionMain entry into mojo. Gets the list of dependencies and iterates to create a classpath.- Specified by:
doExecutein classAbstractDependencyMojo- Throws:
org.apache.maven.plugin.MojoExecutionException- with a message if an error occurs- See Also:
AbstractDependencyFilterMojo.getResolvedDependencies(boolean)
-
attachFile
protected void attachFile(java.lang.String cpString) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
cpString- the classpath- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error
-
appendArtifactPath
protected void appendArtifactPath(org.apache.maven.artifact.Artifact art, java.lang.StringBuilder sb)Appends the artifact path to the specified StringBuilder.- Parameters:
art-Artifactsb-StringBuilder
-
isUpToDate
private boolean isUpToDate(java.lang.String cpString)
Checks that new classpath differs from that found inside the old classpathFile.- Returns:
- true if the specified classpath equals the one found inside the file, false otherwise (including when file does not exist but new classpath does)
-
storeClasspathFile
private void storeClasspathFile(java.lang.String cpString, java.io.File out) throws org.apache.maven.plugin.MojoExecutionExceptionStores the specified string into that file.- Parameters:
cpString- the string to write into the file- Throws:
org.apache.maven.plugin.MojoExecutionException
-
readClasspathFile
protected java.lang.String readClasspathFile() throws java.io.IOExceptionReads the file specified by the mojo param 'outputFile' into a string. Assumes the field 'outputFile' is not null.- Returns:
- the string contained in the classpathFile, if it exists, or null otherwise
- Throws:
java.io.IOException- in case of an error
-
compare
public int compare(org.apache.maven.artifact.Artifact art1, org.apache.maven.artifact.Artifact art2)Compares artifacts lexicographically, using pattern [group_id][artifact_id][version].- Specified by:
comparein interfacejava.util.Comparator<org.apache.maven.artifact.Artifact>- Parameters:
art1- first objectart2- second object- Returns:
- the value
0if the argument string is equal to this string; a value less than0if this string is lexicographically less than the string argument; and a value greater than0if this string is lexicographically greater than the string argument
-
getMarkedArtifactFilter
protected org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter getMarkedArtifactFilter()
Description copied from class:AbstractDependencyFilterMojoReturn anArtifactsFilterindicating which artifacts must be filtered out.- Specified by:
getMarkedArtifactFilterin classAbstractDependencyFilterMojo- Returns:
- an
ArtifactsFilterindicating which artifacts must be filtered out
-
setOutputFile
public void setOutputFile(java.io.File outputFile)
- Parameters:
outputFile- the outputFile to set
-
setOutputProperty
public void setOutputProperty(java.lang.String theOutputProperty)
- Parameters:
theOutputProperty- the outputProperty to set
-
setFileSeparator
public void setFileSeparator(java.lang.String theFileSeparator)
- Parameters:
theFileSeparator- the fileSeparator to set
-
setPathSeparator
public void setPathSeparator(java.lang.String thePathSeparator)
- Parameters:
thePathSeparator- the pathSeparator to set
-
setPrefix
public void setPrefix(java.lang.String thePrefix)
- Parameters:
thePrefix- the prefix to set
-
setRegenerateFile
public void setRegenerateFile(boolean theRegenerateFile)
- Parameters:
theRegenerateFile- the regenerateFile to set
-
isStripVersion
public boolean isStripVersion()
- Returns:
- the stripVersion
-
setStripVersion
public void setStripVersion(boolean theStripVersion)
- Parameters:
theStripVersion- the stripVersion to set
-
setLocalRepoProperty
public void setLocalRepoProperty(java.lang.String localRepoProperty)
- Parameters:
localRepoProperty-localRepoProperty
-
-