Package org.apache.maven.plugins.source
Class AbstractSourceJarMojo
java.lang.Object
org.apache.maven.plugins.source.AbstractSourceJarMojo
- All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
- Direct Known Subclasses:
SourceJarNoForkMojo
,TestSourceJarNoForkMojo
public abstract class AbstractSourceJarMojo
extends Object
implements org.apache.maven.api.plugin.Mojo
Base class for bundling sources into a jar archive.
- Since:
- 2.0.3
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.apache.maven.archiver.MavenArchiveConfiguration
The archive configuration to use.protected boolean
Specifies whether to attach the artifact to the projectprotected Path
Path to the default MANIFEST file to use.protected boolean
Specifies whether to exclude resources from the sources-jar.protected String[]
List of files to exclude.protected String
The filename to be used for the generated archive file.protected boolean
Whether creating the archive should be forced.protected boolean
Specifies whether to include the POM file in the sources-jar.protected String[]
List of files to include.protected org.codehaus.plexus.archiver.jar.JarArchiver
The Jar archiver.protected org.apache.maven.api.plugin.Log
protected Path
The directory where the generated archive file will be put.protected String
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXX
or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).protected org.apache.maven.api.Project
The Maven Project Objectprotected org.apache.maven.api.services.ProjectManager
Used for attaching the source jar to the project.protected List
<org.apache.maven.api.Project> Contains the full list of projects in the reactor.protected org.apache.maven.api.Session
The Maven session.protected boolean
A flag used to disable the source procedure.protected boolean
Exclude commonly excluded files such as SCM configuration.protected boolean
Set this totrue
to enable the use of thedefaultManifestFile
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDirectory
(org.codehaus.plexus.archiver.Archiver archiver, Path sourceDirectory, String[] pIncludes, String[] pExcludes) protected void
addDirectory
(org.codehaus.plexus.archiver.Archiver archiver, Path sourceDirectory, String prefix, String[] pIncludes, String[] pExcludes) protected void
archiveProjectContent
(org.apache.maven.api.Project project, org.codehaus.plexus.archiver.Archiver archiver) protected org.apache.maven.archiver.MavenArchiver
protected void
void
execute()
protected abstract String
protected String
org.apache.maven.api.plugin.Log
getLog()
protected org.apache.maven.api.Project
protected org.apache.maven.api.Project
getProject
(org.apache.maven.api.Project p) protected abstract List
<org.apache.maven.api.model.Resource> getResources
(org.apache.maven.api.Project p) getSources
(org.apache.maven.api.Project p) protected String
getType()
protected void
packageSources
(List<org.apache.maven.api.Project> theProjects) protected void
packageSources
(org.apache.maven.api.Project p) protected void
setProject
(org.apache.maven.api.Project project)
-
Field Details
-
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
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") protected boolean useDefaultExcludesExclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()- Since:
- 2.1
-
project
@Inject protected org.apache.maven.api.Project projectThe Maven Project Object -
jarArchiver
@Inject protected org.codehaus.plexus.archiver.jar.JarArchiver jarArchiverThe Jar archiver. -
archive
@Parameter protected org.apache.maven.archiver.MavenArchiveConfiguration archiveThe 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) protected Path defaultManifestFilePath to the default MANIFEST file to use. It will be used ifuseDefaultManifestFile
is set totrue
.- Since:
- 2.1
-
useDefaultManifestFile
@Parameter(property="maven.source.useDefaultManifestFile", defaultValue="false") protected boolean useDefaultManifestFileSet this totrue
to enable the use of thedefaultManifestFile
.- Since:
- 2.1
-
attach
@Parameter(property="maven.source.attach", defaultValue="true") protected boolean attachSpecifies whether to attach the artifact to the project -
excludeResources
@Parameter(property="maven.source.excludeResources", defaultValue="false") protected boolean excludeResourcesSpecifies whether 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 to include the POM file in the sources-jar.- Since:
- 2.1
-
outputDirectory
The directory where the generated archive file will be put. -
finalName
The 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="${session.projects}", readonly=true) protected List<org.apache.maven.api.Project> reactorProjectsContains the full list of projects in the reactor. -
forceCreation
@Parameter(property="maven.source.forceCreation", defaultValue="false") protected 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") protected 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
@Inject protected org.apache.maven.api.Session sessionThe Maven session. -
outputTimestamp
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXX
or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.2.0
-
log
@Inject protected org.apache.maven.api.plugin.Log log -
projectManager
protected org.apache.maven.api.services.ProjectManager projectManagerUsed for attaching the source jar to the project.
-
-
Constructor Details
-
AbstractSourceJarMojo
public AbstractSourceJarMojo()
-
-
Method Details
-
getLog
public org.apache.maven.api.plugin.Log getLog() -
execute
public void execute() throws org.apache.maven.api.plugin.MojoException- Specified by:
execute
in interfaceorg.apache.maven.api.plugin.Mojo
- Throws:
org.apache.maven.api.plugin.MojoException
-
doExecute
protected void doExecute() -
getClassifier
- Returns:
- the wanted classifier, ie
sources
ortest-sources
-
getSources
protected abstract List<Path> getSources(org.apache.maven.api.Project p) throws org.apache.maven.api.plugin.MojoException - Parameters:
p
-Project
not null- Returns:
- the compile or test sources
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
getResources
protected abstract List<org.apache.maven.api.model.Resource> getResources(org.apache.maven.api.Project p) throws org.apache.maven.api.plugin.MojoException - Parameters:
p
-Project
not null- Returns:
- the compile or test resources
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
packageSources
protected void packageSources(org.apache.maven.api.Project p) throws org.apache.maven.api.plugin.MojoException - Parameters:
p
-Project
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
packageSources
protected void packageSources(List<org.apache.maven.api.Project> theProjects) throws org.apache.maven.api.plugin.MojoException - Parameters:
theProjects
-Project
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
archiveProjectContent
protected void archiveProjectContent(org.apache.maven.api.Project project, org.codehaus.plexus.archiver.Archiver archiver) throws org.apache.maven.api.plugin.MojoException - Parameters:
project
-Project
archiver
-Archiver
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
createArchiver
protected org.apache.maven.archiver.MavenArchiver createArchiver() throws org.apache.maven.api.plugin.MojoException- Returns:
MavenArchiver
- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
addDirectory
protected void addDirectory(org.codehaus.plexus.archiver.Archiver archiver, Path sourceDirectory, String[] pIncludes, String[] pExcludes) throws org.apache.maven.api.plugin.MojoException - Parameters:
archiver
-Archiver
sourceDirectory
-Path
pIncludes
- The list of includes.pExcludes
- The list of excludes.- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
addDirectory
protected void addDirectory(org.codehaus.plexus.archiver.Archiver archiver, Path sourceDirectory, String prefix, String[] pIncludes, String[] pExcludes) throws org.apache.maven.api.plugin.MojoException - Parameters:
archiver
-Archiver
sourceDirectory
-Path
prefix
- The prefix.pIncludes
- the includes.pExcludes
- the excludes.- Throws:
org.apache.maven.api.plugin.MojoException
- in case of an error.
-
getExtension
- Returns:
- The extension
.jar
-
getProject
protected org.apache.maven.api.Project getProject(org.apache.maven.api.Project p) - Parameters:
p
-Project
- Returns:
- The execution projet.
-
getType
- Returns:
- The type
java-source
-
getProject
protected org.apache.maven.api.Project getProject()- Returns:
- The current project.
-
setProject
protected void setProject(org.apache.maven.api.Project project) - Parameters:
project
-Project
-