Search in sources :

Example 66 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project pinpoint by naver.

the class DependencyResolver method resolveArtifactsAndDependencies.

public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws DependencyResolutionException {
    List<Dependency> dependencies = new ArrayList<>();
    for (Artifact artifact : artifacts) {
        dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
    }
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    DependencyResult result = system.resolveDependencies(session, dependencyRequest);
    List<File> files = new ArrayList<>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 67 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project sts4 by spring-projects.

the class MavenBridge method resolve.

public Artifact resolve(final Artifact artifact, List<ArtifactRepository> remoteRepositories, MavenExecutionRequest executionRequest) throws MavenException {
    if (remoteRepositories == null) {
        try {
            remoteRepositories = getArtifactRepositories();
        } catch (MavenException e) {
            // we've tried
            remoteRepositories = Collections.emptyList();
        }
    }
    final List<ArtifactRepository> _remoteRepositories = remoteRepositories;
    org.eclipse.aether.RepositorySystem repoSystem = lookup(org.eclipse.aether.RepositorySystem.class);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(RepositoryUtils.toArtifact(artifact));
    request.setRepositories(RepositoryUtils.toRepos(_remoteRepositories));
    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(createRepositorySession(executionRequest), request);
    } catch (ArtifactResolutionException ex) {
        result = ex.getResults().get(0);
    }
    setLastUpdated(executionRequest.getLocalRepository(), _remoteRepositories, artifact);
    if (result.isResolved()) {
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
    } else {
        throw new MavenException(result.getExceptions().toArray(new Exception[result.getExceptions().size()]));
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) DuplicateProjectException(org.apache.maven.project.DuplicateProjectException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) NoSuchRealmException(org.codehaus.plexus.classworlds.realm.NoSuchRealmException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) CycleDetectedException(org.codehaus.plexus.util.dag.CycleDetectedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 68 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project launcher by runelite.

the class ReflectionLauncher method launch.

public static void launch(List<ArtifactResult> results, String clientArgs, OptionSet options) throws Exception {
    URL[] jarUrls = new URL[results.size()];
    int i = 0;
    for (ArtifactResult ar : results) {
        URL url = ar.getArtifact().getFile().toURI().toURL();
        logger.debug("Adding jar: {}", url);
        jarUrls[i++] = url;
    }
    URLClassLoader loader = new URLClassLoader(jarUrls, null);
    // hack for Substance
    UIManager.put("ClassLoader", loader);
    Thread thread = new Thread() {

        public void run() {
            try {
                Class<?> mainClass = loader.loadClass(CLIENT_MAIN_CLASS);
                Method main = mainClass.getMethod("main", String[].class);
                String[] args = clientArgs != null ? clientArgs.split(" ") : new String[0];
                main.invoke(null, (Object) args);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    thread.setName("RuneLite");
    thread.start();
}
Also used : URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) URL(java.net.URL) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 69 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project unleash-maven-plugin by shillner.

the class ArtifactCacheLoader method load.

@Override
public Optional<ArtifactResult> load(ArtifactCoordinates coordinates) throws Exception {
    Artifact artifact = new DefaultArtifact(coordinates.toString());
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(this.remoteProjectRepos);
    ArtifactResult artifactResult;
    try {
        artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest);
    } catch (ArtifactResolutionException e) {
        // must not throw the error or log as an error since this is an expected behavior
        artifactResult = null;
    }
    return Optional.fromNullable(artifactResult);
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 70 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project zeppelin by apache.

the class DependencyResolver method loadFromMvn.

private List<File> loadFromMvn(String artifact, Collection<String> excludes) throws RepositoryException {
    Collection<String> allExclusions = new LinkedList<>();
    allExclusions.addAll(excludes);
    allExclusions.addAll(Arrays.asList(exclusions));
    List<ArtifactResult> listOfArtifact;
    listOfArtifact = getArtifactsWithDep(artifact, allExclusions);
    Iterator<ArtifactResult> it = listOfArtifact.iterator();
    while (it.hasNext()) {
        Artifact a = it.next().getArtifact();
        String gav = a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion();
        for (String exclude : allExclusions) {
            if (gav.startsWith(exclude)) {
                it.remove();
                break;
            }
        }
    }
    List<File> files = new LinkedList<>();
    for (ArtifactResult artifactResult : listOfArtifact) {
        files.add(artifactResult.getArtifact().getFile());
        LOGGER.debug("load {}", artifactResult.getArtifact().getFile().getAbsolutePath());
    }
    return files;
}
Also used : File(java.io.File) LinkedList(java.util.LinkedList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)83 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)53 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)51 Artifact (org.eclipse.aether.artifact.Artifact)41 File (java.io.File)37 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)37 IOException (java.io.IOException)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)16 ArrayList (java.util.ArrayList)15 Dependency (org.eclipse.aether.graph.Dependency)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)13 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)10 FileNotFoundException (java.io.FileNotFoundException)9 RepositorySystem (org.eclipse.aether.RepositorySystem)8 Test (org.junit.Test)8 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7