Class ArtifactHelper


  • public class ArtifactHelper
    extends java.lang.Object
    A utility class that provides methods that convert sequences of strings to the standard Maven-defined group:artifact:version (aka, „GAV“) format.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArtifactHelper()
      Create an instance with default state.
      ArtifactHelper​(java.net.URI repoLocation)
      Create an instance that will do its work at the given repoLocation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String extractArtifact​(java.lang.String coordinates)
      Map the given coordinates to only the artifact part.
      java.util.Optional<java.lang.String> extractClassifier​(java.lang.String coordinates)
      Map the given coordinates to only the classifier part.
      java.lang.String extractGroup​(java.lang.String coordinates)
      Map the given coordinates to only the group part.
      java.lang.String extractVersion​(java.lang.String coordinates)
      Map the given coordinates to only the version part.
      java.util.Optional<java.io.File> fromMavenLocal​(java.lang.String coordinates)
      Fetch a dependency from the local Maven repo as a jar File.
      java.util.Optional<java.nio.file.Path> gavClassifierToPath​(java.lang.String group, java.lang.String artifact, java.lang.String version, java.util.Optional<java.lang.String> classifier)
      Map the given group, artifact, version and Optional classifier to a Path.
      java.util.Optional<java.nio.file.Path> groupArtifactToPath​(java.lang.String group, java.lang.String artifact)
      Map the given group and artifact to a Path.
      java.util.Optional<java.nio.file.Path> groupArtifactVerToPath​(java.lang.String group, java.lang.String artifact, java.lang.String version)
      Map the given group, artifact and version to a Path.
      java.util.Optional<java.nio.file.Path> groupToPath​(java.lang.String group)
      Map the given group to a Path.
      java.util.Optional<java.net.URI> locateMavenLocal()
      Looks for a local Maven repository in one of three standard locations on the file system: The default local Maven repository location: $HOME/.m2/repository/ A path referenced by an $M2_REPO_ENV environment variable A path referenced by a -Dmaven.local.repo=${...} system property
      java.lang.String[] splitCoordinates​(java.lang.String coordinates)
      Map the given coordinates to an array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArtifactHelper

        public ArtifactHelper()

        Create an instance with default state. The created instance will attempt to locate and work with a local file system dependency cache it assumes will be installed at a standard default location. It will look for environment variables such as M2_REPO, GRADLE_USER_HOME and GRADLE_HOME. It will also look for a maven.local.repo System property.

        If no such environment or property is found, it will assume the caller intends for this instance to work with a local file system dependency cache located in the home directory of the current user.

        The methods of this instance operate in the context of the locations described above.

      • ArtifactHelper

        public ArtifactHelper​(java.net.URI repoLocation)

        Create an instance that will do its work at the given repoLocation.

        The created instance will attempt to locate and work with a local file system dependency cache it assumes will be installed at the specified URI.

        The methods of this instance operate in the context of the location of the specified URI.

        Parameters:
        repoLocation - The location on the local file system where a dependency cache can be found.
    • Method Detail

      • groupToPath

        public java.util.Optional<java.nio.file.Path> groupToPath​(java.lang.String group)
        Map the given group to a Path.
        Parameters:
        group - The group to be resolved to a Path.
        Returns:
        An Optional-wrapped Path relative to this instances repoLocation – if the location specified by the given group exists. Otherwise, an Optional.empty() if no actual location exists for the given group.
      • groupArtifactToPath

        public java.util.Optional<java.nio.file.Path> groupArtifactToPath​(java.lang.String group,
                                                                          java.lang.String artifact)
        Map the given group and artifact to a Path.
        Parameters:
        group - The group to be resolved to a Path.
        artifact - The artifact to be resolved to a Path.
        Returns:
        An Optional-wrapped Path relative to this instances repoLocation – if the location specified by the given group and artifact exists. Otherwise, an Optional.empty() if no actual location exists for the given group and artifact.
      • groupArtifactVerToPath

        public java.util.Optional<java.nio.file.Path> groupArtifactVerToPath​(java.lang.String group,
                                                                             java.lang.String artifact,
                                                                             java.lang.String version)
        Map the given group, artifact and version to a Path.
        Parameters:
        group - The group to be resolved to a Path.
        artifact - The artifact to be resolved to a Path.
        version - The version to be resolved to a Path.
        Returns:
        An Optional-wrapped Path relative to this instances repoLocation – if the location specified by the given group, artifact and version exists. Otherwise, an Optional.empty() if no actual location exists for the given group, artifact and version.
      • gavClassifierToPath

        public java.util.Optional<java.nio.file.Path> gavClassifierToPath​(java.lang.String group,
                                                                          java.lang.String artifact,
                                                                          java.lang.String version,
                                                                          java.util.Optional<java.lang.String> classifier)
        Map the given group, artifact, version and Optional classifier to a Path.
        Parameters:
        group - The group to be resolved to a Path.
        artifact - The artifact to be resolved to a Path.
        version - The version to be resolved to a Path.
        classifier - An Optional classifier to be resolved to a Path.
        Returns:
        An Optional-wrapped Path relative to this instances repoLocation – if the location specified by the given group, artifact, version and classifier exists. Otherwise, an Optional.empty() if no actual location exists for the given group, artifact, version and classifier.
      • fromMavenLocal

        public java.util.Optional<java.io.File> fromMavenLocal​(java.lang.String coordinates)
        Fetch a dependency from the local Maven repo as a jar File.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        - The jar File located at the given coordinates.
      • extractGroup

        public java.lang.String extractGroup​(java.lang.String coordinates)
        Map the given coordinates to only the group part.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        The group part of the given coordinates.
      • extractArtifact

        public java.lang.String extractArtifact​(java.lang.String coordinates)
        Map the given coordinates to only the artifact part.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        The artifact part of the given coordinates.
      • extractVersion

        public java.lang.String extractVersion​(java.lang.String coordinates)
        Map the given coordinates to only the version part.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        The version part of the given coordinates.
      • extractClassifier

        public java.util.Optional<java.lang.String> extractClassifier​(java.lang.String coordinates)
        Map the given coordinates to only the classifier part.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        The classifier part of the given coordinates.
      • splitCoordinates

        public java.lang.String[] splitCoordinates​(java.lang.String coordinates)
        Map the given coordinates to an array.
        Parameters:
        coordinates - Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.
        Returns:
        A String array whose elements will be the colon-delimited parts of the given coordinates.
      • locateMavenLocal

        public java.util.Optional<java.net.URI> locateMavenLocal()
        Looks for a local Maven repository in one of three standard locations on the file system:
        1. The default local Maven repository location: $HOME/.m2/repository/
        2. A path referenced by an $M2_REPO_ENV environment variable
        3. A path referenced by a -Dmaven.local.repo=${...} system property
        Returns:
        Either the location on the file system of a local Maven repository, or Optional.empty() if none was found.