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:
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 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
FieldsModifier and TypeFieldDescriptionprivate booleanAttach the classpath file to the main artifact so it can be installed and deployed.private StringOverride the char used between the paths.private StringReplace the absolute path to the local repo with this property.private Stringprivate FileThe file to write the classpath string.private booleanWrite out the classpath in a format compatible with filtering (classpath=xxxxx)private StringIf defined, the name of a property to which the classpath string will be written.private StringOverride the char used between path folders.private StringThe prefix to prepend on each dependent artifact.private org.apache.maven.project.MavenProjectHelperMaven ProjectHelperprivate booleanIf 'true', it skips the up-to-date-check, and always regenerates the classpath file.private org.apache.maven.shared.transfer.repository.RepositoryManagerprivate booleanStrip artifact classifier during copy (only works if prefix is set)private booleanStrip artifact version during copy (only works if prefix is set)private booleanEither 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, typeFields inherited from class org.apache.maven.plugins.dependency.AbstractDependencyMojo
reactorProjects, sessionFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendArtifactPath(org.apache.maven.artifact.Artifact art, StringBuilder sb) Appends the artifact path into the specified StringBuilder.protected voidattachFile(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 voidMain entry into mojo.protected org.apache.maven.shared.artifact.filter.collection.ArtifactsFilterReturn anArtifactsFilterindicating which artifacts must be filtered out.booleanprivate booleanisUpToDate(String cpString) Checks that new classpath differs from that found inside the old classpathFile.protected StringReads the file specified by the mojo param 'outputFile' into a string.voidsetFileSeparator(String theFileSeparator) voidsetLocalRepoProperty(String localRepoProperty) voidsetOutputFile(File outputFile) voidsetOutputProperty(String theOutputProperty) voidsetPathSeparator(String thePathSeparator) voidvoidsetRegenerateFile(boolean theRegenerateFile) voidsetStripVersion(boolean theStripVersion) private voidstoreClasspathFile(String cpString, File out) Stores the specified string into that file.Methods inherited from class org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo
filterMarkedDependencies, getDependencyResolver, getDependencySets, getDependencySets, getMarkersDirectory, getRepositoryManager, getResolvedDependencies, getResolverUtil, isPrependGroupId, setMarkersDirectory, setPrependGroupIdMethods inherited from class org.apache.maven.plugins.dependency.AbstractDependencyMojo
execute, getProject, isSilent, isSkip, newResolveArtifactProjectBuildingRequest, newResolvePluginProjectBuildingRequest, setSilent, setSkipMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
outputEncoding
@Parameter(property="outputEncoding", defaultValue="${project.reporting.outputEncoding}") private 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
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
If defined, the name of a property to which the classpath string will be written. -
outputFile
The file to write the classpath string. If undefined, it just prints the classpath as [INFO]. -
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
Override 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
Override 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
Replace 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 attachAttach 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
@Component private org.apache.maven.project.MavenProjectHelper projectHelperMaven ProjectHelper -
repositoryManager
@Component private org.apache.maven.shared.transfer.repository.RepositoryManager repositoryManager
-
-
Constructor Details
-
BuildClasspathMojo
public BuildClasspathMojo()
-
-
Method Details
-
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:
-
attachFile
- Parameters:
cpString- The classpath.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
appendArtifactPath
Appends the artifact path into the specified StringBuilder.- Parameters:
art-Artifactsb-StringBuilder
-
isUpToDate
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(String cpString, File out) throws org.apache.maven.plugin.MojoExecutionException Stores the specified string into that file.- Parameters:
cpString- the string to write into the file- Throws:
org.apache.maven.plugin.MojoExecutionException
-
readClasspathFile
Reads 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:
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 interfaceComparator<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
- Parameters:
outputFile- the outputFile to set
-
setOutputProperty
- Parameters:
theOutputProperty- the outputProperty to set
-
setFileSeparator
- Parameters:
theFileSeparator- the fileSeparator to set
-
setPathSeparator
- Parameters:
thePathSeparator- the pathSeparator to set
-
setPrefix
- 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
- Parameters:
localRepoProperty-localRepoProperty
-