Class AbstractSourceJarMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    OsgiSourceMojo

    public abstract class AbstractSourceJarMojo
    extends org.apache.maven.plugin.AbstractMojo
    Base class for bundling sources into a jar archive.
    Since:
    2.0.3
    Version:
    $Id: AbstractSourceJarMojo.java 763422 2009-04-08 21:59:54Z pgier $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.maven.archiver.MavenArchiveConfiguration archive
      The archive configuration to use.
      private boolean attach
      Specifies whether or not to attach the artifact to the project
      private static java.lang.String[] DEFAULT_EXCLUDES  
      private static java.lang.String[] DEFAULT_INCLUDES  
      private java.io.File defaultManifestFile
      Path to the default MANIFEST file to use.
      protected boolean excludeResources
      Specifies whether or not to exclude resources from the sources-jar.
      private java.lang.String[] excludes
      List of files to exclude.
      protected java.lang.String finalName
      The filename to be used for the generated archive file.
      private boolean forceCreation
      NOT SUPPORTED.
      protected boolean includePom
      Specifies whether or not to include the POM file in the sources-jar.
      private java.lang.String[] includes
      List of files to include.
      private org.codehaus.plexus.archiver.jar.JarArchiver jarArchiver
      The Jar archiver.
      protected java.io.File outputDirectory
      The directory where the generated archive file will be put.
      protected org.apache.maven.project.MavenProject project
      The Maven Project Object
      private org.apache.maven.project.MavenProjectHelper projectHelper
      Used for attaching the source jar to the project.
      protected java.util.List reactorProjects
      Contains the full list of projects in the reactor.
      protected org.apache.maven.execution.MavenSession session
      The Maven Session Object
      private boolean useDefaultExcludes
      Exclude commonly excluded files such as SCM configuration.
      private boolean useDefaultManifestFile
      Set this to true to enable the use of the defaultManifestFile.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addDirectory​(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String[] includes, java.lang.String[] excludes)  
      protected void addDirectory​(org.codehaus.plexus.archiver.Archiver archiver, java.io.File sourceDirectory, java.lang.String prefix, java.lang.String[] includes, java.lang.String[] excludes)  
      protected void archiveProjectContent​(org.apache.maven.project.MavenProject p, org.codehaus.plexus.archiver.Archiver archiver)  
      protected org.apache.maven.archiver.MavenArchiver createArchiver()  
      void execute()
      protected abstract java.lang.String getClassifier()  
      private java.lang.String[] getCombinedExcludes​(java.util.List<java.lang.String> additionalExcludes)
      Combines the user parameter excludes, 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.String getExtension()  
      protected org.apache.maven.project.MavenProject getProject​(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<org.apache.maven.model.Resource> getSources​(org.apache.maven.project.MavenProject p)  
      protected java.lang.String getType()  
      protected abstract boolean isRelevantProject​(org.apache.maven.project.MavenProject p)  
      protected void packageSources​(java.util.List<org.apache.maven.project.MavenProject> projects)  
      protected void packageSources​(org.apache.maven.project.MavenProject p)  
      protected void updateSourceManifest​(org.apache.maven.archiver.MavenArchiveConfiguration mavenArchiveConfiguration)  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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(defaultValue="true")
        private boolean useDefaultExcludes
        Exclude commonly excluded files such as SCM configuration. These are defined in the plexus FileUtils.getDefaultExcludes()
        Since:
        2.1
      • project

        @Parameter(property="project",
                   readonly=true,
                   required=true)
        protected org.apache.maven.project.MavenProject project
        The Maven Project Object
      • session

        @Parameter(property="session",
                   readonly=true)
        protected org.apache.maven.execution.MavenSession session
        The Maven Session Object
      • jarArchiver

        @Component(role=org.codehaus.plexus.archiver.Archiver.class,
                   hint="jar")
        private org.codehaus.plexus.archiver.jar.JarArchiver jarArchiver
        The Jar archiver.
      • archive

        @Parameter
        private org.apache.maven.archiver.MavenArchiveConfiguration archive
        The archive configuration to use. See Maven Archiver Reference.
        Since:
        2.1
      • defaultManifestFile

        @Parameter(defaultValue="${project.build.outputDirectory}/META-INF/MANIFEST.MF",
                   required=true,
                   readonly=true)
        private java.io.File defaultManifestFile
        Path to the default MANIFEST file to use. It will be used if useDefaultManifestFile is set to true.
        Since:
        2.1
      • useDefaultManifestFile

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

        @Parameter(property="attach",
                   defaultValue="true")
        private boolean attach
        Specifies whether or not to attach the artifact to the project
      • excludeResources

        @Parameter(property="source.excludeResources",
                   defaultValue="false")
        protected boolean excludeResources
        Specifies 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="source.includePom",
                   defaultValue="false")
        protected boolean includePom
        Specifies 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(property="project.build.directory")
        protected java.io.File outputDirectory
        The directory where the generated archive file will be put.
      • finalName

        @Parameter(property="project.build.finalName")
        protected java.lang.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(property="reactorProjects",
                   readonly=true)
        protected java.util.List reactorProjects
        Contains the full list of projects in the reactor.
      • forceCreation

        @Parameter(property="source.forceCreation",
                   defaultValue="false")
        private boolean forceCreation
        NOT SUPPORTED. 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
    • Constructor Detail

      • AbstractSourceJarMojo

        public AbstractSourceJarMojo()
    • 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 sources or test-sources
      • getSources

        protected abstract java.util.List<org.apache.maven.model.Resource> getSources​(org.apache.maven.project.MavenProject p)
                                                                               throws org.apache.maven.plugin.MojoExecutionException
        Parameters:
        p - not null
        Returns:
        the compile or test sources
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • 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 - not null
        Returns:
        the compile or test resources
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • packageSources

        protected void packageSources​(org.apache.maven.project.MavenProject p)
                               throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • isRelevantProject

        protected abstract boolean isRelevantProject​(org.apache.maven.project.MavenProject p)
      • packageSources

        protected void packageSources​(java.util.List<org.apache.maven.project.MavenProject> projects)
                               throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • updateSourceManifest

        protected void updateSourceManifest​(org.apache.maven.archiver.MavenArchiveConfiguration mavenArchiveConfiguration)
      • archiveProjectContent

        protected void archiveProjectContent​(org.apache.maven.project.MavenProject p,
                                             org.codehaus.plexus.archiver.Archiver archiver)
                                      throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • createArchiver

        protected org.apache.maven.archiver.MavenArchiver createArchiver()
                                                                  throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • addDirectory

        protected void addDirectory​(org.codehaus.plexus.archiver.Archiver archiver,
                                    java.io.File sourceDirectory,
                                    java.lang.String[] includes,
                                    java.lang.String[] excludes)
                             throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • addDirectory

        protected void addDirectory​(org.codehaus.plexus.archiver.Archiver archiver,
                                    java.io.File sourceDirectory,
                                    java.lang.String prefix,
                                    java.lang.String[] includes,
                                    java.lang.String[] excludes)
                             throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getExtension

        protected java.lang.String getExtension()
      • getProject

        protected org.apache.maven.project.MavenProject getProject​(org.apache.maven.project.MavenProject p)
      • getType

        protected java.lang.String getType()
      • getCombinedIncludes

        private java.lang.String[] getCombinedIncludes​(java.util.List<java.lang.String> additionalIncludes)
        Combines the includes parameter and additional includes. Defaults to DEFAULT_INCLUDES If 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 parameter excludes, 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.