Class ArtifactHelper
- java.lang.Object
-
- com.lingocoder.file.ArtifactHelper
-
public class ArtifactHelper extends java.lang.Object
A 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.String
extractArtifact(java.lang.String coordinates)
Map the givencoordinates
to only theartifact
part.java.util.Optional<java.lang.String>
extractClassifier(java.lang.String coordinates)
Map the givencoordinates
to only theclassifier
part.java.lang.String
extractGroup(java.lang.String coordinates)
Map the givencoordinates
to only thegroup
part.java.lang.String
extractVersion(java.lang.String coordinates)
Map the givencoordinates
to only theversion
part.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
,version
andOptional
classifier
to aPath
.java.util.Optional<java.nio.file.Path>
groupArtifactToPath(java.lang.String group, java.lang.String artifact)
Map the givengroup
andartifact
to aPath
.java.util.Optional<java.nio.file.Path>
groupArtifactVerToPath(java.lang.String group, java.lang.String artifact, java.lang.String version)
Map the givengroup
,artifact
andversion
to aPath
.java.util.Optional<java.nio.file.Path>
groupToPath(java.lang.String group)
Map the givengroup
to 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 givencoordinates
to 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_HOME
andGRADLE_HOME
. It will also look for amaven.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 givengroup
to aPath
.- Parameters:
group
- Thegroup
to be resolved to aPath
.- Returns:
- An
Optional
-wrappedPath
relative 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 givengroup
andartifact
to aPath
.- Parameters:
group
- Thegroup
to be resolved to aPath
.artifact
- Theartifact
to be resolved to aPath
.- Returns:
- An
Optional
-wrappedPath
relative to this instancesrepoLocation
– if the location specified by the givengroup
andartifact
exists. Otherwise, anOptional.empty()
if no actual location exists for the givengroup
andartifact
.
-
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
,artifact
andversion
to aPath
.- Parameters:
group
- Thegroup
to be resolved to aPath
.artifact
- Theartifact
to be resolved to aPath
.version
- Theversion
to be resolved to aPath
.- Returns:
- An
Optional
-wrappedPath
relative to this instancesrepoLocation
– if the location specified by the givengroup
,artifact
andversion
exists. Otherwise, anOptional.empty()
if no actual location exists for the givengroup
,artifact
andversion
.
-
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
,version
andOptional
classifier
to aPath
.- Parameters:
group
- Thegroup
to be resolved to aPath
.artifact
- Theartifact
to be resolved to aPath
.version
- Theversion
to be resolved to aPath
.classifier
- AnOptional
classifier
to be resolved to aPath
.- Returns:
- An
Optional
-wrappedPath
relative to this instancesrepoLocation
– if the location specified by the givengroup
,artifact
,version
andclassifier
exists. Otherwise, anOptional.empty()
if no actual location exists for the givengroup
,artifact
,version
andclassifier
.
-
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
File
located at the given coordinates.
-
extractGroup
public java.lang.String extractGroup(java.lang.String coordinates)
Map the givencoordinates
to only thegroup
part.- Parameters:
coordinates
- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
group
part of the givencoordinates
.
-
extractArtifact
public java.lang.String extractArtifact(java.lang.String coordinates)
Map the givencoordinates
to only theartifact
part.- Parameters:
coordinates
- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
artifact
part of the givencoordinates
.
-
extractVersion
public java.lang.String extractVersion(java.lang.String coordinates)
Map the givencoordinates
to only theversion
part.- Parameters:
coordinates
- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
version
part of the givencoordinates
.
-
extractClassifier
public java.util.Optional<java.lang.String> extractClassifier(java.lang.String coordinates)
Map the givencoordinates
to only theclassifier
part.- Parameters:
coordinates
- Expected to be in the standard colon-delimited form: „group:artifact:version[:classifier]“.- Returns:
- The
classifier
part of the givencoordinates
.
-
splitCoordinates
public java.lang.String[] splitCoordinates(java.lang.String coordinates)
Map the givencoordinates
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 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.
-
-