Java Code Examples for org.eclipse.aether.resolution.ArtifactResult#getArtifact()

The following examples show how to use org.eclipse.aether.resolution.ArtifactResult#getArtifact() . 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: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private DependencyGraph buildDependencyGraph(
    List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session) {
   
  try {
    DependencyNode node = resolveCompileTimeDependencies(dependencyNodes, session);
    return DependencyGraph.from(node);
  } catch (DependencyResolutionException ex) {
    DependencyResult result = ex.getResult();
    DependencyGraph graph = DependencyGraph.from(result.getRoot());

    for (ArtifactResult artifactResult : result.getArtifactResults()) {
      Artifact resolvedArtifact = artifactResult.getArtifact();

      if (resolvedArtifact == null) {
        Artifact requestedArtifact = artifactResult.getRequest().getArtifact();
        graph.addUnresolvableArtifactProblem(requestedArtifact);
      }
    }
    
    return graph;
  }
}
 
Example 2
Source File: ArtifactTransporter.java    From jenkins-build-monitor-plugin with MIT License 6 votes vote down vote up
public Path get(@NotNull String groupName, @NotNull String artifactName, @NotNull String version, @NotNull String artifactFileExtension) {
    Artifact artifact = new DefaultArtifact(groupName, artifactName, artifactFileExtension, version);

    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);

    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(repositories(system, session));

    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, request);

        artifact = artifactResult.getArtifact();

        Log.info(artifact + " resolved to  " + artifact.getFile());

        return artifact.getFile().toPath();

    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(format("Couldn't resolve a '%s' artifact for '%s:%s:%s'",
                artifactFileExtension, groupName, artifactName, version
        ), e);
    }
}
 
Example 3
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 4
Source File: Resolver.java    From buck with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords)
    throws RepositoryException {

  CollectRequest collectRequest = new CollectRequest();
  collectRequest.setRequestContext(JavaScopes.RUNTIME);
  collectRequest.setRepositories(repos);

  for (Dependency dep : mavenCoords) {
    collectRequest.addDependency(dep);
  }

  DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
  DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter);

  DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest);

  ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder();
  for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
    Artifact node = artifactResult.getArtifact();
    knownDeps.put(buildKey(node), node);
  }
  return knownDeps.build();
}
 
Example 5
Source File: ArtifactHelper.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves an artifact via the repository system.
 * @param repositoryParameters
 * @param artifactItem
 * @return a file object if a configuration file bundle was found, otherwise null
 * @throws MojoExecutionException 
 */
private static Artifact resolve(final IRepositoryParameters repositoryParameters, final ArtifactItem artifactItem)
        throws MojoExecutionException {
    try {
        final Artifact artifact = createDefaultArtifact(artifactItem);
        final ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(artifact);
        request.setRepositories(repositoryParameters.getRemoteRepositories());
        final ArtifactResult result = repositoryParameters.getRepositorySystem()
                .resolveArtifact(repositoryParameters.getRepositorySystemSession(), request);
        return result.getArtifact();
    } catch (IllegalArgumentException | ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
 
Example 6
Source File: ClassPathEntryTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static Artifact resolveArtifact(String coordinates) throws ArtifactResolutionException {
  RepositorySystem system = RepositoryUtility.newRepositorySystem();
  RepositorySystemSession session = RepositoryUtility.newSession(system);

  Artifact artifact = new DefaultArtifact(coordinates);    
  ArtifactRequest artifactRequest = new ArtifactRequest();
  artifactRequest.setArtifact(artifact);
  ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
  
  return artifactResult.getArtifact();
}
 
Example 7
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 8
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 9
Source File: ArtifactResolver.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private ResolutionResult getResolutionResult(ArtifactResult artifactResult, boolean remoteOnly) {
  ResolutionResult result = null;
  Artifact artifact = artifactResult.getArtifact();
  if (artifact != null) {
    String repositoryId = artifactResult.getRepository().getId();
    if (remoteOnly) {
      if (!Objects.equal(repositoryId, this.repoSession.getLocalRepository().getId())) {
        result = new ResolutionResult(artifact.getFile(), repositoryId);
      }
    } else {
      result = new ResolutionResult(artifact.getFile(), repositoryId);
    }
  }
  return result;
}
 
Example 10
Source File: ArtifactResolver.java    From revapi with Apache License 2.0 5 votes vote down vote up
private Artifact resolveArtifact(Artifact artifact, RepositorySystemSession session) throws ArtifactResolutionException {
    ArtifactRequest request = new ArtifactRequest().setArtifact(artifact)
            .setRepositories(repositories);

    ArtifactResult result = repositorySystem.resolveArtifact(session, request);

    if (!result.isResolved() || result.isMissing()) {
        throw new ArtifactResolutionException(Collections.singletonList(result), "The artifact was not" +
                " resolved or is missing: '" + artifact.toString() + "'.");
    }

    return result.getArtifact();
}
 
Example 11
Source File: AetherResolver.java    From onos with Apache License 2.0 5 votes vote down vote up
private Artifact resolveArtifact(Artifact artifact) throws Exception {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(repositories());
    ArtifactResult result = system.resolveArtifact(session, request);
    return result.getArtifact();
}
 
Example 12
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response<File[]> resolveResources(final AddonId addonId)
{
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   final String mavenCoords = toMavenCoords(addonId);
   Artifact queryArtifact = new DefaultArtifact(mavenCoords);
   session.setDependencyTraverser(new AddonDependencyTraverser(classifier));
   session.setDependencySelector(new AddonDependencySelector(classifier));
   Dependency dependency = new Dependency(queryArtifact, null);

   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);

   CollectRequest collectRequest = new CollectRequest(dependency, repositories);
   DependencyResult result;
   try
   {
      result = system.resolveDependencies(session, new DependencyRequest(collectRequest, null));
   }
   catch (DependencyResolutionException e)
   {
      throw new RuntimeException(e);
   }
   List<Exception> collectExceptions = result.getCollectExceptions();
   Set<File> files = new HashSet<File>();
   List<ArtifactResult> artifactResults = result.getArtifactResults();
   for (ArtifactResult artifactResult : artifactResults)
   {
      Artifact artifact = artifactResult.getArtifact();
      if (isFurnaceAPI(artifact) ||
               (this.classifier.equals(artifact.getClassifier())
                        && !addonId.getName().equals(artifact.getGroupId() + ":" + artifact.getArtifactId())))
      {
         continue;
      }
      files.add(artifact.getFile());
   }
   return new MavenResponseBuilder<File[]>(files.toArray(new File[files.size()])).setExceptions(collectExceptions);
}
 
Example 13
Source File: RemotePluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws ArtifactResolutionException {
	System.out.println("------------------------------------------------------------");
	System.out.println(RemotePluginRepository.class.getSimpleName());

	RepositorySystem system = newRepositorySystem();

	RepositorySystemSession session = newRepositorySystemSession(system);

	Artifact artifact = new DefaultArtifact("org.eclipse.aether:aether-util:1.0.0.v20140518");

	ArtifactRequest artifactRequest = new ArtifactRequest();
	artifactRequest.setArtifact(artifact);
	artifactRequest.setRepositories(newRepositories(system, session));

	ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);

	artifact = artifactResult.getArtifact();

	System.out.println(artifact + " resolved to  " + artifact.getFile());
}