Class AbstractJarsignerMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.jarsigner.AbstractJarsignerMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
JarsignerSignMojo, JarsignerVerifyMojo

public abstract class AbstractJarsignerMojo extends org.apache.maven.plugin.AbstractMojo
Maven Jarsigner Plugin base class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
    See options.
    private File
    Archive to process.
    private File
    The base directory to scan for JAR files using Ant-like inclusion/exclusion patterns.
    private String[]
    List of additional arguments to append to the jarsigner command line.
    private String[]
    A set of artifact classifiers describing the project attachments that should not be processed.
    private String[]
    The Ant-like exclusion patterns used to exclude JAR files from processing.
    private String[]
    A set of artifact classifiers describing the project attachments that should be processed.
    private String[]
    The Ant-like inclusion patterns used to select JAR files to process.
    private org.apache.maven.shared.jarsigner.JarSigner
     
    private String
    See options.
    private String
    The maximum memory available to the JAR signer, e.g.
    private boolean
    Controls processing of project attachments.
    private boolean
    Controls processing of the main artifact produced by the project.
    private org.apache.maven.project.MavenProject
    The Maven project.
    private boolean
    Must be set to true if the password must be given via a protected authentication path such as a dedicated PIN reader.
    private String
    See options.
    private String
    See options.
    private String
    See options.
    private org.sonatype.plexus.components.sec.dispatcher.SecDispatcher
     
    private org.apache.maven.execution.MavenSession
    The current build session instance.
    private org.apache.maven.settings.Settings
    The Maven settings.
    private boolean
    Set to true to disable the plugin.
    private String
    See options.
    private String
    See options.
    private org.apache.maven.toolchain.ToolchainManager
    To obtain a toolchain if possible.
    private boolean
    See options.
    private File
    Location of the working directory.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract org.apache.maven.shared.jarsigner.JarSignerRequest
    Creates the jar signer request to be executed.
    protected String
    decrypt(String encoded)
     
    final void
     
    protected abstract void
    executeJarSigner(org.apache.maven.shared.jarsigner.JarSigner jarSigner, org.apache.maven.shared.jarsigner.JarSignerRequest request)
    Executes jarsigner (execute signing or verification for a jar file).
    private List<File>
    Finds all jar files, by looking at the Maven project and user configuration.
    protected String
    getCommandlineInfo(org.apache.maven.shared.utils.cli.Commandline commandLine)
    Gets a string representation of a Commandline.
    private Optional<File>
    getFileFromArtifact(org.apache.maven.artifact.Artifact artifact)
    Examines an Artifact and extract the File object pointing to the Artifact jar file.
    (package private) String
    getMessage(String key, Object... args)
    Gets a message for a given key from the resource bundle backing the implementation.
     
     
    private org.apache.maven.toolchain.Toolchain
    the part with ToolchainManager lookup once we depend on 2.0.9 (have it as prerequisite).
    private static boolean
    isZipFile(org.apache.maven.artifact.Artifact artifact)
    Checks whether the specified artifact is a ZIP file.
    protected void
    Pre-processes a given archive.
    protected final void
    Processes a given archive.
    protected void
    Process (sign/verify) a list of archives.
    protected void
    Validate the user supplied configuration/parameters.

    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 Details

    • verbose

      @Parameter(property="jarsigner.verbose", defaultValue="false") private boolean verbose
      See options.
    • keystore

      @Parameter(property="jarsigner.keystore") private String keystore
      See options.
    • storetype

      @Parameter(property="jarsigner.storetype") private String storetype
      See options.
    • storepass

      @Parameter(property="jarsigner.storepass") private String storepass
      See options.
    • providerName

      @Parameter(property="jarsigner.providerName") private String providerName
      See options.
    • providerClass

      @Parameter(property="jarsigner.providerClass") private String providerClass
      See options.
    • providerArg

      @Parameter(property="jarsigner.providerArg") private String providerArg
      See options.
    • alias

      @Parameter(property="jarsigner.alias") private String alias
      See options.
    • maxMemory

      @Parameter(property="jarsigner.maxMemory") private String maxMemory
      The maximum memory available to the JAR signer, e.g. 256M. See -Xmx for more details.
    • archive

      @Parameter(property="jarsigner.archive") private File archive
      Archive to process. If set, neither the project artifact nor any attachments or archive sets are processed.
    • archiveDirectory

      @Parameter(property="jarsigner.archiveDirectory") private File archiveDirectory
      The base directory to scan for JAR files using Ant-like inclusion/exclusion patterns.
      Since:
      1.1
    • includes

      @Parameter private String[] includes
      The Ant-like inclusion patterns used to select JAR files to process. The patterns must be relative to the directory given by the parameter archiveDirectory. By default, the pattern **/*.?ar is used.
      Since:
      1.1
    • excludes

      @Parameter private String[] excludes
      The Ant-like exclusion patterns used to exclude JAR files from processing. The patterns must be relative to the directory given by the parameter archiveDirectory.
      Since:
      1.1
    • arguments

      @Parameter(property="jarsigner.arguments") private String[] arguments
      List of additional arguments to append to the jarsigner command line. Each argument should be specified as a separate element. For example, to specify the name of the signed jar, two elements are needed:
      • Alternative using the command line: -Djarsigner.arguments="-signedjar,my-project_signed.jar"
      • Alternative using the Maven POM configuration:
       
       <configuration>
         <arguments>
           <argument>-signedjar</argument>
           <argument>my-project_signed.jar</argument>
         </arguments>
       </configuration>
       
    • skip

      @Parameter(property="jarsigner.skip", defaultValue="false") private boolean skip
      Set to true to disable the plugin.
    • processMainArtifact

      @Parameter(property="jarsigner.processMainArtifact", defaultValue="true") private boolean processMainArtifact
      Controls processing of the main artifact produced by the project.
      Since:
      1.1
    • processAttachedArtifacts

      @Parameter(property="jarsigner.processAttachedArtifacts", defaultValue="true") private boolean processAttachedArtifacts
      Controls processing of project attachments. If enabled, attached artifacts that are no JAR/ZIP files will be automatically excluded from processing.
      Since:
      1.1
    • protectedAuthenticationPath

      @Parameter(property="jarsigner.protectedAuthenticationPath", defaultValue="false") private boolean protectedAuthenticationPath
      Must be set to true if the password must be given via a protected authentication path such as a dedicated PIN reader.
      Since:
      1.3
    • includeClassifiers

      @Parameter private String[] includeClassifiers
      A set of artifact classifiers describing the project attachments that should be processed. This parameter is only relevant if processAttachedArtifacts is true. If empty, all attachments are included.
      Since:
      1.2
    • excludeClassifiers

      @Parameter private String[] excludeClassifiers
      A set of artifact classifiers describing the project attachments that should not be processed. This parameter is only relevant if processAttachedArtifacts is true. If empty, no attachments are excluded.
      Since:
      1.2
    • project

      @Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
      The Maven project.
    • settings

      @Parameter(defaultValue="${settings}", readonly=true, required=true) private org.apache.maven.settings.Settings settings
      The Maven settings.
      Since:
      1.5
    • workingDirectory

      @Parameter(defaultValue="${project.basedir}") private File workingDirectory
      Location of the working directory.
      Since:
      1.3
    • jarSigner

      @Component private org.apache.maven.shared.jarsigner.JarSigner jarSigner
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
      The current build session instance. This is used for toolchain manager API calls.
      Since:
      1.3
    • toolchainManager

      @Component private org.apache.maven.toolchain.ToolchainManager toolchainManager
      To obtain a toolchain if possible.
      Since:
      1.3
    • securityDispatcher

      @Component(hint="mng-4384") private org.sonatype.plexus.components.sec.dispatcher.SecDispatcher securityDispatcher
      Since:
      1.3.2
  • Constructor Details

    • AbstractJarsignerMojo

      public AbstractJarsignerMojo()
  • Method Details

    • execute

      public final void execute() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • findJarfiles

      private List<File> findJarfiles() throws org.apache.maven.plugin.MojoExecutionException
      Finds all jar files, by looking at the Maven project and user configuration.
      Returns:
      a List of File objects
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if it was not possible to build a list of jar files
    • createRequest

      protected abstract org.apache.maven.shared.jarsigner.JarSignerRequest createRequest(File archive) throws org.apache.maven.plugin.MojoExecutionException
      Creates the jar signer request to be executed.
      Parameters:
      archive - the archive file to treat by jarsigner
      Returns:
      the request
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if an exception occurs
      Since:
      1.3
    • getCommandlineInfo

      protected String getCommandlineInfo(org.apache.maven.shared.utils.cli.Commandline commandLine)
      Gets a string representation of a Commandline.

      This method creates the string representation by calling commandLine.toString() by default.

      Parameters:
      commandLine - The Commandline to get a string representation of.
      Returns:
      The string representation of commandLine.
      Throws:
      NullPointerException - if commandLine is null
    • getStoretype

      public String getStoretype()
    • getStorepass

      public String getStorepass()
    • isZipFile

      private static boolean isZipFile(org.apache.maven.artifact.Artifact artifact)
      Checks whether the specified artifact is a ZIP file.
      Parameters:
      artifact - The artifact to check, may be null.
      Returns:
      true if the artifact looks like a ZIP file, false otherwise.
    • getFileFromArtifact

      private Optional<File> getFileFromArtifact(org.apache.maven.artifact.Artifact artifact)
      Examines an Artifact and extract the File object pointing to the Artifact jar file.
      Parameters:
      artifact - the artifact to examine
      Returns:
      An Optional containing the File, or Optional.empty() if the File is not a jar file.
      Throws:
      NullPointerException - if artifact is null
    • preProcessArchive

      protected void preProcessArchive(File archive) throws org.apache.maven.plugin.MojoExecutionException
      Pre-processes a given archive.
      Parameters:
      archive - The archive to process, must not be null.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if pre-processing failed
    • validateParameters

      protected void validateParameters() throws org.apache.maven.plugin.MojoExecutionException
      Validate the user supplied configuration/parameters.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if the user supplied configuration make further execution impossible
    • processArchives

      protected void processArchives(List<File> archives) throws org.apache.maven.plugin.MojoExecutionException
      Process (sign/verify) a list of archives.
      Parameters:
      archives - list of jar files to process
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if an error occurs during the processing of archives
    • processArchive

      protected final void processArchive(File archive) throws org.apache.maven.plugin.MojoExecutionException
      Processes a given archive.
      Parameters:
      archive - The archive to process.
      Throws:
      NullPointerException - if archive is null
      org.apache.maven.plugin.MojoExecutionException - if processing archive fails
    • executeJarSigner

      protected abstract void executeJarSigner(org.apache.maven.shared.jarsigner.JarSigner jarSigner, org.apache.maven.shared.jarsigner.JarSignerRequest request) throws org.apache.maven.shared.utils.cli.javatool.JavaToolException, org.apache.maven.plugin.MojoExecutionException
      Executes jarsigner (execute signing or verification for a jar file).
      Parameters:
      jarSigner - the JarSigner execution interface
      request - the JarSignerRequest with parameters JarSigner should use
      Throws:
      org.apache.maven.shared.utils.cli.javatool.JavaToolException - if jarsigner could not be invoked
      org.apache.maven.plugin.MojoExecutionException - if the invocation of jarsigner succeeded, but returned a non-zero exit code
    • decrypt

      protected String decrypt(String encoded) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getMessage

      String getMessage(String key, Object... args)
      Gets a message for a given key from the resource bundle backing the implementation.
      Parameters:
      key - the key of the message to return
      args - arguments to format the message with
      Returns:
      the message with key key from the resource bundle backing the implementation
      Throws:
      NullPointerException - if key is null
      MissingResourceException - if there is no message available matching key or accessing the resource bundle fails
    • getToolchain

      private org.apache.maven.toolchain.Toolchain getToolchain()
      the part with ToolchainManager lookup once we depend on 2.0.9 (have it as prerequisite). Define as regular component field then. hint: check maven-compiler-plugin code
      Returns:
      Toolchain instance