Java Code Examples for org.eclipse.aether.resolution.ArtifactResolutionException#getMessage()

The following examples show how to use org.eclipse.aether.resolution.ArtifactResolutionException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingerMojo.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private Path findMain() {
    final LocalRepositoryManager lrm = repositorySystemSession.getLocalRepositoryManager();
    final Artifact artifact = new DefaultArtifact(GAV.GROUP, "component-kitap", "fatjar", "jar", GAV.VERSION);
    final File location = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    if (!location.exists()) {
        final ArtifactRequest artifactRequest =
                new ArtifactRequest().setArtifact(artifact).setRepositories(remoteRepositories);
        try {
            final ArtifactResult result =
                    repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
            if (result.isMissing()) {
                throw new IllegalStateException("Can't find " + artifact);
            }
            return result.getArtifact().getFile().toPath();
        } catch (final ArtifactResolutionException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
    return location.toPath();
}
 
Example 2
Source File: MeecrowaveBundleMojo.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
private File resolve(final String group, final String artifact, final String version, final String classifier) {
    final DefaultArtifact art = new DefaultArtifact(group, artifact, classifier, "jar", version);
    final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);

    final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    art.setFile(new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifactRequest.getArtifact())));

    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(session, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find commons-cli, please add it to the pom.");
        }
        return result.getArtifact().getFile();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 3
Source File: JAXRSAnalyzerMojo.java    From jaxrs-analyzer-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Path fetchDependency(final String artifactIdentifier) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    final DefaultArtifact artifact = new DefaultArtifact(artifactIdentifier);
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);

    LogProvider.debug("Resolving artifact " + artifact + " from " + remoteRepos);

    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    LogProvider.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile().toPath();
}
 
Example 4
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
         throws UnresolvableModelException
{
   Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
   try
   {
      final ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
      pomArtifact = system.resolveArtifact(session, request).getArtifact();

   }
   catch (ArtifactResolutionException e)
   {
      throw new UnresolvableModelException("Failed to resolve POM for " + groupId + ":" + artifactId + ":"
               + version + " due to " + e.getMessage(), groupId, artifactId, version, e);
   }

   final File pomFile = pomArtifact.getFile();

   return new FileModelSource(pomFile);

}
 
Example 5
Source File: DependencyFinder.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the specified artifact (using its GAV, classifier and packaging).
 *
 * @param mojo       the mojo
 * @param groupId    the groupId of the artifact to resolve
 * @param artifactId the artifactId of the artifact to resolve
 * @param version    the version
 * @param type       the type
 * @param classifier the classifier
 * @return the artifact's file if it can be revolved. The file is located in the local maven repository.
 * @throws MojoExecutionException if the artifact cannot be resolved
 */
public static File resolve(AbstractWisdomMojo mojo, String groupId, String artifactId, String version,
                           String type, String classifier) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(
            new DefaultArtifact(groupId, artifactId, classifier, type, version));
    request.setRepositories(mojo.remoteRepos);

    mojo.getLog().info("Resolving artifact " + artifactId +
            " from " + mojo.remoteRepos);

    ArtifactResult result;
    try {
        result = mojo.repoSystem.resolveArtifact(mojo.repoSession, request);
    } catch (ArtifactResolutionException e) {
        mojo.getLog().error("Cannot resolve " + groupId + ":" + artifactId + ":" + version + ":" + type);
        throw new MojoExecutionException(e.getMessage(), e);
    }

    mojo.getLog().info("Resolved artifact " + artifactId + " to " +
            result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}
 
Example 6
Source File: DependencyFinder.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the specified artifact (using the : separated syntax).
 *
 * @param mojo   the mojo
 * @param coords the coordinates ot the artifact to resolve using the : separated syntax -
 *               {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}
 * @return the artifact's file if it can be revolved. The file is located in the local maven repository.
 * @throws MojoExecutionException if the artifact cannot be resolved
 */
public static File resolve(AbstractWisdomMojo mojo, String coords) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(
            new DefaultArtifact(coords));
    request.setRepositories(mojo.remoteRepos);

    mojo.getLog().info("Resolving artifact " + coords +
            " from " + mojo.remoteRepos);

    ArtifactResult result;
    try {
        result = mojo.repoSystem.resolveArtifact(mojo.repoSession, request);
    } catch (ArtifactResolutionException e) {
        mojo.getLog().error("Cannot resolve " + coords);
        throw new MojoExecutionException(e.getMessage(), e);
    }

    mojo.getLog().info("Resolved artifact " + coords + " to " +
            result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}
 
Example 7
Source File: EclipseAetherArtifactResolver.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Path resolve(final RepositorySystemSession session, final List<RemoteRepository> repositories, final ArtifactName name) {
    final ArtifactResult result;
    try {
        final ArtifactRequest request = new ArtifactRequest();
        final Artifact defaultArtifact = new DefaultArtifact(name.getGroupId(), name.getArtifactId(), name.getClassifier(), name.getPackaging(), name.getVersion());
        request.setArtifact(defaultArtifact);
        request.setRepositories(repositories);
        result = repoSystem.resolveArtifact(session, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (!result.isResolved()) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    final Artifact artifact = result.getArtifact();
    final File artifactFile;
    if (artifact == null || (artifactFile = artifact.getFile()) == null) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    return artifactFile.toPath();
}
 
Example 8
Source File: ArtifactDownload.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method fetches the artifact from the remote server using aether library
 * 
 * @param groupId group ID of the artifact
 * @param artifactId artifact ID of the artifact
 * @param version artifact version to be downloaded
 * @param classifier classifier of the artifact
 * @param packaging packaging of the artifact
 * @param localRepository destination path
 * @return location of the downloaded artifact in the local system
 * @throws IOException
 */
public static File getArtifactByAether(String groupId, String artifactId, String version, String classifier, String packaging, File localRepository) throws IOException {
	RepositorySystem repositorySystem = newRepositorySystem();
	RepositorySystemSession session = newSession(repositorySystem, localRepository);

	Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, packaging, version);
	ArtifactRequest artifactRequest = new ArtifactRequest();
	artifactRequest.setArtifact(artifact);

	List<RemoteRepository> repositories = new ArrayList<>();
	Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER);

	RemoteRepository remoteRepository = new RemoteRepository.Builder("public", "default", ini.get(Constants.INI_NEXUS_SOOT_RELEASE)).build();

	repositories.add(remoteRepository);

	artifactRequest.setRepositories(repositories);
	File result = null;

	try {
		ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
		artifact = artifactResult.getArtifact();
		if (artifact != null) {
			result = artifact.getFile();
		}
	}
	catch (ArtifactResolutionException e) {
		throw new IOException("Artifact " + groupId + ":" + artifactId + ":" + version + " could not be downloaded due to " + e.getMessage());
	}

	return result;

}
 
Example 9
Source File: RepackageExtensionMojo.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * @param artifact The artifact coordinates in the format {@code
 * <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not
 *            be {@code null}.
 *
 */
private ArtifactResult downloadAndInstallArtifact(final String artifact) {
    final ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifact));
    request.setRepositories(remoteRepos);

    getLog().info("Resolving artifact " + artifact + " from " + remoteRepos);
    try {
        return repository.resolveArtifact(session, request);
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 10
Source File: ComponentDependenciesBase.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
protected Artifact resolve(final Artifact art) {
    final ArtifactRequest artifactRequest =
            new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);
    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find " + art);
        }
        return result.getArtifact();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 11
Source File: ArtemisAbstractPlugin.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
   ArtifactRequest request = new ArtifactRequest();
   request.setArtifact(artifact);
   request.setRepositories(remoteRepos);

   ArtifactResult result;
   try {
      result = repositorySystem.resolveArtifact(repoSession, request);
   } catch (ArtifactResolutionException e) {
      throw new MojoExecutionException(e.getMessage(), e);
   }

   return result.getArtifact().getFile();
}
 
Example 12
Source File: MyArtifactResolver.java    From elasticsearch-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves an Artifact from the repositories.
 * 
 * @param coordinates The artifact coordinates
 * @return The local file resolved/downloaded for the given coordinates
 * @throws ArtifactException If the artifact cannot be resolved
 */
@Override
public File resolveArtifact(String coordinates) throws ArtifactException
{
    ArtifactRequest request = new ArtifactRequest();
    Artifact artifact = new DefaultArtifact(coordinates);
    request.setArtifact(artifact);
    request.setRepositories(remoteRepositories);

    log.debug(String.format("Resolving artifact %s from %s", artifact, remoteRepositories));

    ArtifactResult result;
    try
    {
        result = repositorySystem.resolveArtifact(repositorySession, request);
    }
    catch (ArtifactResolutionException e)
    {
        throw new ArtifactException(e.getMessage(), e);
    }

    log.debug(String.format("Resolved artifact %s to %s from %s",
            artifact,
            result.getArtifact().getFile(),
            result.getRepository()));

    return result.getArtifact().getFile();
}