Package org.apache.maven.plugins.source
Class AbstractSourceJarMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.source.AbstractSourceJarMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
SourceJarNoForkMojo,TestSourceJarNoForkMojo
public abstract class AbstractSourceJarMojo extends org.apache.maven.plugin.AbstractMojoBase class for bundling sources into a jar archive.- Since:
- 2.0.3
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.maven.archiver.MavenArchiveConfigurationarchiveThe archive configuration to use.private booleanattachSpecifies whether or not to attach the artifact to the projectprivate static java.lang.String[]DEFAULT_EXCLUDESprivate static java.lang.String[]DEFAULT_INCLUDESprivate java.io.FiledefaultManifestFilePath to the default MANIFEST file to use.protected booleanexcludeResourcesSpecifies whether or not to exclude resources from the sources-jar.private java.lang.String[]excludesList of files to exclude.protected java.lang.StringfinalNameThe filename to be used for the generated archive file.private booleanforceCreationWhether creating the archive should be forced.protected booleanincludePomSpecifies whether or not to include the POM file in the sources-jar.private java.lang.String[]includesList of files to include.private org.codehaus.plexus.archiver.jar.JarArchiverjarArchiverThe Jar archiver.protected java.io.FileoutputDirectoryThe directory where the generated archive file will be put.private java.lang.StringoutputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).private org.apache.maven.project.MavenProjectprojectThe Maven Project Objectprivate org.apache.maven.project.MavenProjectHelperprojectHelperUsed for attaching the source jar to the project.protected java.util.List<org.apache.maven.project.MavenProject>reactorProjectsContains the full list of projects in the reactor.private org.apache.maven.execution.MavenSessionsessionThe Maven session.private booleanskipSourceA flag used to disable the source procedure.private booleanuseDefaultExcludesExclude commonly excluded files such as SCM configuration.private booleanuseDefaultManifestFileSet this totrueto enable the use of thedefaultManifestFile.
-
Constructor Summary
Constructors Constructor Description AbstractSourceJarMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddDirectory(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String[] pIncludes, java.lang.String[] pExcludes)protected voidaddDirectory(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String prefix, java.lang.String[] pIncludes, java.lang.String[] pExcludes)protected voidarchiveProjectContent(org.apache.maven.project.MavenProject p, org.codehaus.plexus.archiver.Archiver archiver)protected org.apache.maven.archiver.MavenArchivercreateArchiver()voidexecute()protected abstract java.lang.StringgetClassifier()private java.lang.String[]getCombinedExcludes(java.util.List<java.lang.String> additionalExcludes)Combines the user parameterexcludes, the default excludes from plexus FileUtils, and the contents of the parameter addionalExcludes.private java.lang.String[]getCombinedIncludes(java.util.List<java.lang.String> additionalIncludes)Combines the includes parameter and additional includes.protected java.lang.StringgetExtension()protected org.apache.maven.project.MavenProjectgetProject()protected org.apache.maven.project.MavenProjectgetProject(org.apache.maven.project.MavenProject p)protected abstract java.util.List<org.apache.maven.model.Resource>getResources(org.apache.maven.project.MavenProject p)protected abstract java.util.List<java.lang.String>getSources(org.apache.maven.project.MavenProject p)protected java.lang.StringgetType()protected voidpackageSources(java.util.List<org.apache.maven.project.MavenProject> theProjects)protected voidpackageSources(org.apache.maven.project.MavenProject p)protected voidsetProject(org.apache.maven.project.MavenProject project)
-
-
-
Field Detail
-
DEFAULT_INCLUDES
private static final java.lang.String[] DEFAULT_INCLUDES
-
DEFAULT_EXCLUDES
private static final java.lang.String[] DEFAULT_EXCLUDES
-
includes
@Parameter private java.lang.String[] includes
List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.- Since:
- 2.1
-
excludes
@Parameter private java.lang.String[] excludes
List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.- Since:
- 2.1
-
useDefaultExcludes
@Parameter(property="maven.source.useDefaultExcludes", defaultValue="true") private boolean useDefaultExcludesExclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()- Since:
- 2.1
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe Maven Project Object
-
jarArchiver
@Component(role=org.codehaus.plexus.archiver.Archiver.class, hint="jar") private org.codehaus.plexus.archiver.jar.JarArchiver jarArchiverThe Jar archiver.
-
archive
@Parameter private org.apache.maven.archiver.MavenArchiveConfiguration archive
The archive configuration to use. See Maven Archiver Reference.
Note: Since 3.0.0 the resulting archives contain a maven descriptor. If you need to suppress the generation of the maven descriptor you can simply achieve this by using the archiver configuration..- Since:
- 2.1
-
defaultManifestFile
@Parameter(defaultValue="${project.build.outputDirectory}/META-INF/MANIFEST.MF", readonly=false, required=true) private java.io.File defaultManifestFilePath to the default MANIFEST file to use. It will be used ifuseDefaultManifestFileis set totrue.- Since:
- 2.1
-
useDefaultManifestFile
@Parameter(property="maven.source.useDefaultManifestFile", defaultValue="false") private boolean useDefaultManifestFileSet this totrueto enable the use of thedefaultManifestFile.- Since:
- 2.1
-
attach
@Parameter(property="maven.source.attach", defaultValue="true") private boolean attachSpecifies whether or not to attach the artifact to the project
-
excludeResources
@Parameter(property="maven.source.excludeResources", defaultValue="false") protected boolean excludeResourcesSpecifies whether or not to exclude resources from the sources-jar. This can be convenient if your project includes large resources, such as images, and you don't want to include them in the sources-jar.- Since:
- 2.0.4
-
includePom
@Parameter(property="maven.source.includePom", defaultValue="false") protected boolean includePomSpecifies whether or not to include the POM file in the sources-jar.- Since:
- 2.1
-
projectHelper
@Component private org.apache.maven.project.MavenProjectHelper projectHelper
Used for attaching the source jar to the project.
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}") protected java.io.File outputDirectoryThe directory where the generated archive file will be put.
-
finalName
@Parameter(defaultValue="${project.build.finalName}") protected java.lang.String finalNameThe filename to be used for the generated archive file. For the source:jar goal, "-sources" is appended to this filename. For the source:test-jar goal, "-test-sources" is appended.
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true) protected java.util.List<org.apache.maven.project.MavenProject> reactorProjectsContains the full list of projects in the reactor.
-
forceCreation
@Parameter(property="maven.source.forceCreation", defaultValue="false") private boolean forceCreationWhether creating the archive should be forced. If set to true, the jar will always be created. If set to false, the jar will only be created when the sources are newer than the jar.- Since:
- 2.1
-
skipSource
@Parameter(property="maven.source.skip", defaultValue="false") private boolean skipSourceA flag used to disable the source procedure. This is primarily intended for usage from the command line to occasionally adjust the build.- Since:
- 2.2
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession sessionThe Maven session.
-
outputTimestamp
@Parameter(defaultValue="${project.build.outputTimestamp}") private java.lang.String outputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.2.0
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getClassifier
protected abstract java.lang.String getClassifier()
- Returns:
- the wanted classifier, ie
sourcesortest-sources
-
getSources
protected abstract java.util.List<java.lang.String> getSources(org.apache.maven.project.MavenProject p) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
p-MavenProjectnot null- Returns:
- the compile or test sources
- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
getResources
protected abstract java.util.List<org.apache.maven.model.Resource> getResources(org.apache.maven.project.MavenProject p) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
p-MavenProjectnot null- Returns:
- the compile or test resources
- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
packageSources
protected void packageSources(org.apache.maven.project.MavenProject p) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
p-MavenProject- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
packageSources
protected void packageSources(java.util.List<org.apache.maven.project.MavenProject> theProjects) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
theProjects-MavenProject- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
archiveProjectContent
protected void archiveProjectContent(org.apache.maven.project.MavenProject p, org.codehaus.plexus.archiver.Archiver archiver) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
p-MavenProjectarchiver-Archiver- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
createArchiver
protected org.apache.maven.archiver.MavenArchiver createArchiver() throws org.apache.maven.plugin.MojoExecutionException- Returns:
MavenArchiver- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
addDirectory
protected void addDirectory(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String[] pIncludes, java.lang.String[] pExcludes) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
archiver-ArchiversourceDirectory-FilepIncludes- The list of includes.pExcludes- The list of excludes.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
addDirectory
protected void addDirectory(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String prefix, java.lang.String[] pIncludes, java.lang.String[] pExcludes) throws org.apache.maven.plugin.MojoExecutionException- Parameters:
archiver-ArchiversourceDirectory-Fileprefix- The prefix.pIncludes- the includes.pExcludes- the excludes.- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
getExtension
protected java.lang.String getExtension()
- Returns:
- The extension
.jar
-
getProject
protected org.apache.maven.project.MavenProject getProject(org.apache.maven.project.MavenProject p)
- Parameters:
p-MavenProject- Returns:
- The execution projet.
-
getType
protected java.lang.String getType()
- Returns:
- The type
java-source
-
getCombinedIncludes
private java.lang.String[] getCombinedIncludes(java.util.List<java.lang.String> additionalIncludes)
Combines the includes parameter and additional includes. Defaults toDEFAULT_INCLUDESIf the additionalIncludes parameter is null, it is not added to the combined includes.- Parameters:
additionalIncludes- The includes specified in the pom resources section- Returns:
- The combined array of includes.
-
getCombinedExcludes
private java.lang.String[] getCombinedExcludes(java.util.List<java.lang.String> additionalExcludes)
Combines the user parameterexcludes, the default excludes from plexus FileUtils, and the contents of the parameter addionalExcludes.- Parameters:
additionalExcludes- Additional excludes to add to the array- Returns:
- The combined list of excludes.
-
getProject
protected org.apache.maven.project.MavenProject getProject()
- Returns:
- The current project.
-
setProject
protected void setProject(org.apache.maven.project.MavenProject project)
- Parameters:
project-MavenProject
-
-