Class ArtifactHelper
- java.lang.Object
-
- com.lingocoder.file.ArtifactHelper
-
public class ArtifactHelper extends java.lang.ObjectA utility class that provides methods that convert sequences of strings to the standard Maven-definedgroup: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 givenrepoLocation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringextractArtifact(java.lang.String coordinates)Map the givencoordinatesto only theartifactpart.java.util.Optional<java.lang.String>extractClassifier(java.lang.String coordinates)Map the givencoordinatesto only theclassifierpart.java.lang.StringextractGroup(java.lang.String coordinates)Map the givencoordinatesto only thegrouppart.java.lang.StringextractVersion(java.lang.String coordinates)Map the givencoordinatesto only theversionpart.java.util.Optional<java.io.File>fromMavenLocal(java.lang.String coordinates)Fetch a dependency from the local Maven repo as a jarFile.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 givengroup,artifact,versionandOptionalclassifierto aPath.java.util.Optional<java.nio.file.Path>groupArtifactToPath(java.lang.String group, java.lang.String artifact)Map the givengroupandartifactto aPath.java.util.Optional<java.nio.file.Path>groupArtifactVerToPath(java.lang.String group, java.lang.String artifact, java.lang.String version)Map the givengroup,artifactandversionto aPath.java.util.Optional<java.nio.file.Path>groupToPath(java.lang.String group)Map the givengroupto aPath.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 propertyjava.lang.String[]splitCoordinates(java.lang.String coordinates)Map the givencoordinatesto an array.
-
-
-
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_HOMEandGRADLE_HOME. It will also look for amaven.local.repoSystem 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 givengroupto aPath.- Parameters:
group- Thegroupto be resolved to aPath.- Returns:
- An
Optional-wrappedPathrelative to this instancesrepoLocation– if the location specified by the given group exists. Otherwise, anOptional.empty()if no actual location exists for the givengroup.
-
groupArtifactToPath
public java.util.Optional<java.nio.file.Path> groupArtifactToPath(java.lang.String group, java.lang.String artifact)Map the givengroupandartifactto aPath.- Parameters:
group- Thegroupto be resolved to aPath.artifact- Theartifactto be resolved to aPath.- Returns:
- An
Optional-wrappedPathrelative to this instancesrepoLocation– if the location specified by the givengroupandartifactexists. Otherwise, anOptional.empty()if no actual location exists for the givengroupandartifact.
-
groupArtifactVerToPath
public java.util.Optional<java.nio.file.Path> groupArtifactVerToPath(java.lang.String group, java.lang.String artifact, java.lang.String version)Map the givengroup,artifactandversionto aPath.- Parameters:
group- Thegroupto be resolved to aPath.artifact- Theartifactto be resolved to aPath.version- Theversionto be resolved to aPath.- Returns:
- An
Optional-wrappedPathrelative to this instancesrepoLocation– if the location specified by the givengroup,artifactandversionexists. Otherwise, anOptional.empty()if no actual location exists for the givengroup,artifactandversion.
-
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 givengroup,artifact,versionandOptionalclassifierto aPath.- Parameters:
group- Thegroupto be resolved to aPath.artifact- Theartifactto be resolved to aPath.version- Theversionto be resolved to aPath.classifier- AnOptionalclassifierto be resolved to aPath.- Returns:
- An
Optional-wrappedPathrelative to this instancesrepoLocation– if the location specified by the givengroup,artifact,versionandclassifierexists. Otherwise, anOptional.empty()if no actual location exists for the givengroup,artifact,versionandclassifier.
-
fromMavenLocal
public java.util.Optional<java.io.File> fromMavenLocal(java.lang.String coordinates)
Fetch a dependency from the local Maven repo as a jarFile.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- - The jar
Filelocated at the given coordinates.
-
extractGroup
public java.lang.String extractGroup(java.lang.String coordinates)
Map the givencoordinatesto only thegrouppart.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
grouppart of the givencoordinates.
-
extractArtifact
public java.lang.String extractArtifact(java.lang.String coordinates)
Map the givencoordinatesto only theartifactpart.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
artifactpart of the givencoordinates.
-
extractVersion
public java.lang.String extractVersion(java.lang.String coordinates)
Map the givencoordinatesto only theversionpart.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
versionpart of the givencoordinates.
-
extractClassifier
public java.util.Optional<java.lang.String> extractClassifier(java.lang.String coordinates)
Map the givencoordinatesto only theclassifierpart.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
classifierpart of the givencoordinates.
-
splitCoordinates
public java.lang.String[] splitCoordinates(java.lang.String coordinates)
Map the givencoordinatesto an array.- Parameters:
coordinates- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- A
Stringarray whose elements will be the colon-delimited parts of the givencoordinates.
-
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:- 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
- Returns:
- Either the location on the file system of a local Maven repository, or
Optional.empty()if none was found.
-
-