org.apache.commons.release.plugin.mojos

## Class CommonsDistributionDetachmentMojo

- java.lang.Object
- - org.apache.maven.plugin.AbstractMojo
  - - org.apache.commons.release.plugin.mojos.CommonsDistributionDetachmentMojo

- All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

      @Mojo(name="detach-distributions",
            defaultPhase=VERIFY,
            threadSafe=true,
            aggregator=true)
      public class CommonsDistributionDetachmentMojo
      extends org.apache.maven.plugin.AbstractMojo

  The purpose of this Maven mojo is to detach the artifacts generated by the maven-assembly-plugin, which for the Apache Commons Project do not get uploaded to Nexus, and putting those artifacts in the dev distribution location for Apache projects.
  Since:
    1.0
  Author:
    chtompki

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static Set<String>` | `ARTIFACT_TYPES_TO_DETACH` A list of "artifact types" in the Maven vernacular, to be detached from the deployment.
    `private Properties` | `artifactSha1s` A `Properties` of `Artifact` → `String` containing the sha1 signatures for the individual artifacts, where the `Artifact` is represented as: `groupId:artifactId:version:type=sha1`.
    `private Properties` | `artifactSha256s` A `Properties` of `Artifact` → `String` containing the sha256 signatures for the individual artifacts, where the `Artifact` is represented as: `groupId:artifactId:version:type=sha1`.
    `private List<org.apache.maven.artifact.Artifact>` | `detachedArtifacts` This list is supposed to hold the Maven references to the aforementioned artifacts so that we can upload them to svn after they've been detached from the Maven deployment.
    `private String` | `distSvnStagingUrl` The subversion staging url to which we upload all of our staged artifacts.
    `private Boolean` | `isDistModule` A parameter to generally avoid running unless it is specifically turned on by the consuming module.
    `private org.apache.maven.project.MavenProject` | `project` The maven project context injection so that we can get a hold of the variables at hand.
    `private File` | `workingDirectory` The working directory in `target` that we use as a sandbox for the plugin.

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

      `ROLE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CommonsDistributionDetachmentMojo()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `copyRemovedArtifactsToWorkingDirectory()` A helper method to copy the newly detached artifacts to `target/commons-release-plugin` so that the `CommonsDistributionStagingMojo` can find the artifacts later.
    `void` | `execute()`
    `private String` | `getArtifactKey(org.apache.maven.artifact.Artifact artifact)` Generates the unique artifact key for storage in our sha1 map and sha256 map.
    `private String` | `getMd5FilePath(File directory, File file)` A helper method to create a file path for the `md5` signature file from a given file.
    `private String` | `getSha1FilePath(File directory, File file)` A helper method to create a file path for the `sha1` signature file from a given file.
    `private String` | `getSha256FilePath(File directory, File file)` A helper method to create a file path for the `sha1` signature file from a given file.
    `private void` | `hashArtifacts()` A helper method that creates md5, sha1, and sha256 signature files for our detached artifacts in the `target/commons-release-plugin` directory for the purpose of being uploaded by the `CommonsDistributionStagingMojo`.
    `private void` | `putAttachedArtifactInSha1Map(org.apache.maven.artifact.Artifact artifact)` Takes an attached artifact and puts the signature in the map.
    `private void` | `putAttachedArtifactInSha256Map(org.apache.maven.artifact.Artifact artifact)` Takes an attached artifact and puts the signature in the map.
    `private void` | `writeAllArtifactsInSha1PropertiesFile()` Writes to ./target/commons-release-plugin/sha1.properties the artifact sha1's.
    `private void` | `writeAllArtifactsInSha256PropertiesFile()` Writes to ./target/commons-release-plugin/sha256.properties the artifact sha256's.

    - ### 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

    - #### ARTIFACT_TYPES_TO_DETACH

          private static final Set<String> ARTIFACT_TYPES_TO_DETACH

      A list of "artifact types" in the Maven vernacular, to be detached from the deployment. For the time being we want all artifacts generated by the maven-assembly-plugin to be detached from the deployment, namely *-src.zip, *-src.tar.gz, *-bin.zip, *-bin.tar.gz, and the corresponding .asc pgp signatures.

    - #### detachedArtifacts

          private final List<org.apache.maven.artifact.Artifact> detachedArtifacts

      This list is supposed to hold the Maven references to the aforementioned artifacts so that we can upload them to svn after they've been detached from the Maven deployment.

    - #### artifactSha1s

          private final Properties artifactSha1s

      A `Properties` of `Artifact` → `String` containing the sha1 signatures for the individual artifacts, where the `Artifact` is represented as: `groupId:artifactId:version:type=sha1`.

    - #### artifactSha256s

          private final Properties artifactSha256s

      A `Properties` of `Artifact` → `String` containing the sha256 signatures for the individual artifacts, where the `Artifact` is represented as: `groupId:artifactId:version:type=sha1`.

    - #### project

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

      The maven project context injection so that we can get a hold of the variables at hand.

    - #### workingDirectory

          @Parameter(defaultValue="${project.build.directory}/commons-release-plugin",
                     property="commons.outputDirectory")
          private File workingDirectory

      The working directory in `target` that we use as a sandbox for the plugin.

    - #### distSvnStagingUrl

          @Parameter(defaultValue="",
                     property="commons.distSvnStagingUrl")
          private String distSvnStagingUrl

      The subversion staging url to which we upload all of our staged artifacts.

    - #### isDistModule

          @Parameter(defaultValue="false",
                     property="commons.release.isDistModule")
          private Boolean isDistModule

      A parameter to generally avoid running unless it is specifically turned on by the consuming module.

  - ### Constructor Detail

    - #### CommonsDistributionDetachmentMojo

          public CommonsDistributionDetachmentMojo()

  - ### Method Detail

    - #### execute

          public void execute()
                       throws org.apache.maven.plugin.MojoExecutionException

      Throws:
        `org.apache.maven.plugin.MojoExecutionException`

    - #### putAttachedArtifactInSha1Map

          private void putAttachedArtifactInSha1Map(org.apache.maven.artifact.Artifact artifact)
                                             throws org.apache.maven.plugin.MojoExecutionException

      Takes an attached artifact and puts the signature in the map.
      Parameters:
        `artifact` - is a Maven `Artifact` taken from the project at start time of mojo.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if an `IOException` occurs when getting the sha1 of the artifact.

    - #### putAttachedArtifactInSha256Map

          private void putAttachedArtifactInSha256Map(org.apache.maven.artifact.Artifact artifact)
                                               throws org.apache.maven.plugin.MojoExecutionException

      Takes an attached artifact and puts the signature in the map.
      Parameters:
        `artifact` - is a Maven `Artifact` taken from the project at start time of mojo.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if an `IOException` occurs when getting the sha1 of the artifact.

    - #### writeAllArtifactsInSha1PropertiesFile

          private void writeAllArtifactsInSha1PropertiesFile()
                                                      throws org.apache.maven.plugin.MojoExecutionException

      Writes to ./target/commons-release-plugin/sha1.properties the artifact sha1's.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if we can't write the file due to an `IOException`.

    - #### writeAllArtifactsInSha256PropertiesFile

          private void writeAllArtifactsInSha256PropertiesFile()
                                                        throws org.apache.maven.plugin.MojoExecutionException

      Writes to ./target/commons-release-plugin/sha256.properties the artifact sha256's.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if we can't write the file due to an `IOException`.

    - #### copyRemovedArtifactsToWorkingDirectory

          private void copyRemovedArtifactsToWorkingDirectory()
                                                       throws org.apache.maven.plugin.MojoExecutionException

      A helper method to copy the newly detached artifacts to `target/commons-release-plugin` so that the `CommonsDistributionStagingMojo` can find the artifacts later.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if some form of an `IOException` occurs, we want it properly wrapped so that Maven can handle it.

    - #### hashArtifacts

          private void hashArtifacts()
                              throws org.apache.maven.plugin.MojoExecutionException

      A helper method that creates md5, sha1, and sha256 signature files for our detached artifacts in the `target/commons-release-plugin` directory for the purpose of being uploaded by the `CommonsDistributionStagingMojo`.
      Throws:
        `org.apache.maven.plugin.MojoExecutionException` - if some form of an `IOException` occurs, we want it properly wrapped so that Maven can handle it.

    - #### getMd5FilePath

          private String getMd5FilePath(File directory,
                                        File file)

      A helper method to create a file path for the `md5` signature file from a given file.
      Parameters:
        `directory` - is the `File` for the directory in which to make the `.md5` file.
        `file` - the `File` whose name we should use to create the `.md5` file.
      Returns:
        a `String` that is the absolute path to the `.md5` file.

    - #### getSha1FilePath

          private String getSha1FilePath(File directory,
                                         File file)

      A helper method to create a file path for the `sha1` signature file from a given file.
      Parameters:
        `directory` - is the `File` for the directory in which to make the `.sha1` file.
        `file` - the `File` whose name we should use to create the `.sha1` file.
      Returns:
        a `String` that is the absolute path to the `.sha1` file.

    - #### getSha256FilePath

          private String getSha256FilePath(File directory,
                                           File file)

      A helper method to create a file path for the `sha1` signature file from a given file.
      Parameters:
        `directory` - is the `File` for the directory in which to make the `.sha1` file.
        `file` - the `File` whose name we should use to create the `.sha1` file.
      Returns:
        a `String` that is the absolute path to the `.sha1` file.

    - #### getArtifactKey

          private String getArtifactKey(org.apache.maven.artifact.Artifact artifact)

      Generates the unique artifact key for storage in our sha1 map and sha256 map. For example, commons-test-1.4-src.tar.gz should have it's name as the key.
      Parameters:
        `artifact` - the `Artifact` that we wish to generate a key for.
      Returns:
        the generated key

Copyright © 2018 The Apache Software Foundation. All rights reserved.