Class MavenArtifactLoader

java.lang.Object
de.softwareforge.testing.maven.MavenArtifactLoader

public final class MavenArtifactLoader extends Object
A quick and dirty artifact loader. Downloads published artifacts from the Maven repository system.

The loader respects the local maven settings (repositories, mirrors etc.) if present. If no configuration is found, a hard-coded reference to Maven Central is used.

  • Constructor Details

    • MavenArtifactLoader

      Creates a new artifact loader for 'jar' artifacts.
    • MavenArtifactLoader

      public MavenArtifactLoader(String extension)
      Creates a new artifact loader for artifacts.
      Parameters:
      extension - The artifact extension. Must not be null.
  • Method Details

    • builder

      public MavenVersionMatchBuilder builder(String groupId, String artifactId)
      Create a new version match builder to retrieve an artifact.
      Parameters:
      groupId - The Apache Maven Group Id. Must not be null.
      artifactId - The Apache Maven Artifact Id. Must not be null.
      Returns:
      A MavenVersionMatchBuilder instance
    • getArtifactFile

      public File getArtifactFile(String groupId, String artifactId, String version) throws IOException
      Download an artifact file from the Maven repository system.
      Parameters:
      groupId - The Apache Maven Group Id. Must not be null.
      artifactId - The Apache Maven Artifact Id. Must not be null.
      version - The Apache Maven Artifact version. Must not be null.
      Returns:
      A file representing a successfully downloaded artifact.
      Throws:
      IOException - If the artifact could not be found or an IO problem happened while locating or downloading the artifact.
    • findLatestVersion

      public String findLatestVersion(String groupId, String artifactId, String version) throws IOException
      Find a matching artifact version from a partially defined artifact version.

      Any located artifact in the repository system is compared to the version given.
      Using this method is equivalent to calling

        builder(groupId, artifactId)
                       .partialMatch(version)
                       .extension(extension)
                       .includeSnapshots(true)
                       .findBestMatch();
       
      but will throw an IOException if no version could be found.
      Parameters:
      groupId - The Apache Maven Group Id. Must not be null.
      artifactId - The Apache Maven Artifact Id. Must not be null.
      version - A partial version string. Must not be null. An empty string matches any version.
      Returns:
      The latest version that matches the partial version string. It either starts with the partial version string given (an empty version string matches any version) or is exactly the provided version.
      Throws:
      IOException - If an IO problem happened during artifact download or no versions were found during resolution.