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

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.maven.archiver.MavenArchiveConfiguration
    The archive configuration to use.
    protected boolean
    Specifies whether to attach the artifact to the project
    protected 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 8601 yyyy-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 Object
    protected 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 to true to enable the use of the defaultManifestFile.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    protected abstract String
     
    protected String
     
    org.apache.maven.api.plugin.Log
     
    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)
     
    protected abstract List<Path>
    getSources(org.apache.maven.api.Project p)
     
    protected String
     
    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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • includes

      @Parameter protected 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 protected 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") protected boolean useDefaultExcludes
      Exclude 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 project
      The Maven Project Object
    • jarArchiver

      @Inject protected org.codehaus.plexus.archiver.jar.JarArchiver jarArchiver
      The Jar archiver.
    • archive

      @Parameter protected 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) protected Path defaultManifestFile
      Path to the default MANIFEST file to use. It will be used if useDefaultManifestFile is set to true.
      Since:
      2.1
    • useDefaultManifestFile

      @Parameter(property="maven.source.useDefaultManifestFile", defaultValue="false") protected boolean useDefaultManifestFile
      Set this to true to enable the use of the defaultManifestFile.
      Since:
      2.1
    • attach

      @Parameter(property="maven.source.attach", defaultValue="true") protected boolean attach
      Specifies whether to attach the artifact to the project
    • excludeResources

      @Parameter(property="maven.source.excludeResources", defaultValue="false") protected boolean excludeResources
      Specifies 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 includePom
      Specifies whether to include the POM file in the sources-jar.
      Since:
      2.1
    • outputDirectory

      @Parameter(defaultValue="${project.build.directory}") protected Path outputDirectory
      The directory where the generated archive file will be put.
    • finalName

      @Parameter(defaultValue="${project.build.finalName}") protected String 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> reactorProjects
      Contains the full list of projects in the reactor.
    • forceCreation

      @Parameter(property="maven.source.forceCreation", defaultValue="false") protected boolean forceCreation
      Whether 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 skipSource
      A 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 session
      The Maven session.
    • outputTimestamp

      @Parameter(defaultValue="${project.build.outputTimestamp}") protected String outputTimestamp
      Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-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 projectManager
      Used 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 interface org.apache.maven.api.plugin.Mojo
      Throws:
      org.apache.maven.api.plugin.MojoException
    • doExecute

      protected void doExecute()
    • getClassifier

      protected abstract String getClassifier()
      Returns:
      the wanted classifier, ie sources or test-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

      protected String 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

      protected String 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