Search in sources :

Example 91 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project acceptance-test-harness by jenkinsci.

the class PluginMetadata method resolve.

public File resolve(Injector i, String version) {
    DefaultArtifact artifact = getDefaultArtifact();
    if (version != null) {
        artifact.setVersion(version);
    }
    ArtifactResolverUtil resolverUtil = i.getInstance(ArtifactResolverUtil.class);
    ArtifactResult r = resolverUtil.resolve(artifact);
    return r.getArtifact().getFile();
}
Also used : DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResolverUtil(org.jenkinsci.test.acceptance.utils.aether.ArtifactResolverUtil) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 92 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project acceptance-test-harness by jenkinsci.

the class LocalOverrideUpdateCenterMetadataDecoratorImpl method decorate.

@Override
public void decorate(UpdateCenterMetadata ucm) {
    if ("true".equals(System.getenv("LOCAL_SNAPSHOTS"))) {
        File userHome = new File(System.getProperty("user.home"));
        File localRepo = MavenLocalRepository.getMavenLocalRepository();
        VersionScheme versionScheme = new GenericVersionScheme();
        for (Iterator<Map.Entry<String, PluginMetadata>> it = ucm.plugins.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<String, PluginMetadata> entry = it.next();
            DefaultArtifact artifact = entry.getValue().getDefaultArtifact();
            File artifactDir = new File(new File(localRepo, artifact.getGroupId().replace('.', File.separatorChar)), artifact.getArtifactId());
            File metadata = new File(artifactDir, "maven-metadata-local.xml");
            if (metadata.isFile()) {
                try {
                    Version ucVersion = versionScheme.parseVersion(artifact.getVersion());
                    NodeList versions = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(metadata).getElementsByTagName("version");
                    for (int i = 0; i < versions.getLength(); i++) {
                        String version = versions.item(i).getTextContent();
                        if (version.endsWith("-SNAPSHOT") && versionScheme.parseVersion(version).compareTo(ucVersion) > 0) {
                            File hpi = new File(new File(artifactDir, version), artifact.getArtifactId() + "-" + version + ".hpi");
                            if (hpi.isFile()) {
                                String name = entry.getKey();
                                System.err.println("Overriding " + name + " " + ucVersion + " with local build of " + version);
                                PluginMetadata m = PluginMetadata.LocalOverride.create(hpi);
                                String parsedName = m.getName();
                                if (!name.equals(parsedName)) {
                                    throw new AssertionError("wrong name: " + parsedName + " vs. " + name);
                                }
                                entry.setValue(m);
                            }
                        }
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        }
    }
    // deprecated mechanism, as of 1.57
    for (Map.Entry<String, String> e : System.getenv().entrySet()) {
        String key = e.getKey();
        if (!isPluginEnvironmentVariable(key))
            continue;
        try {
            override(ucm, e.getValue());
            System.err.println("Using XXX.jpi/XXX_JPI env vars is deprecated. Use LOCAL_JARS instead.");
        } catch (Exception x) {
            throw new IllegalArgumentException("Unable to honor environment variable " + key, x);
        }
    }
    // past 1.57, preferred way
    String localJars = System.getenv("LOCAL_JARS");
    if (localJars != null) {
        for (String jar : localJars.split(File.pathSeparator)) {
            try {
                override(ucm, jar);
            } catch (Exception x) {
                throw new IllegalArgumentException("Unable to honor LOCAL_JARS environment variable", x);
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) VersionScheme(org.eclipse.aether.version.VersionScheme) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) Version(org.eclipse.aether.version.Version) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) File(java.io.File) Map(java.util.Map) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 93 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method resolveAll.

@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    List<DependencyNode> nodes;
    if (transitive) {
        final CollectRequest request = new CollectRequest();
        request.setRepositories(this.remoteRepositories);
        // SWARM-1031
        if (this.dependencyManagement != null) {
            List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
                DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
                return new Dependency(artifact, mavenDep.getScope());
            }).collect(Collectors.toList());
            request.setManagedDependencies(managedDependencies);
        }
        specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
        RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
        CollectResult result = this.system.collectDependencies(tempSession, request);
        PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
        result.getRoot().accept(gen);
        nodes = gen.getNodes();
    } else {
        nodes = new ArrayList<>();
        for (ArtifactSpec spec : specs) {
            Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
            DefaultDependencyNode node = new DefaultDependencyNode(dependency);
            nodes.add(node);
        }
    }
    List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
    nodes.addAll(extraDependencies);
    resolveDependenciesInParallel(nodes);
    return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
        final Artifact artifact = node.getArtifact();
        return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
    }).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) Proxy(org.eclipse.aether.repository.Proxy) Dependency(org.eclipse.aether.graph.Dependency) DependencyManagement(org.apache.maven.model.DependencyManagement) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest) CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) Authentication(org.apache.maven.artifact.repository.Authentication) Artifact(org.eclipse.aether.artifact.Artifact) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) Set(java.util.Set) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Collectors(java.util.stream.Collectors) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) Objects(java.util.Objects) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) List(java.util.List) ArtifactResolver(org.eclipse.aether.impl.ArtifactResolver) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Collections(java.util.Collections) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) CollectResult(org.eclipse.aether.collection.CollectResult) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 94 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project gate-core by GateNLP.

the class SimpleModelResolver method resolveModel.

@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
    try {
        ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
        pomArtifact = system.resolveArtifact(session, request).getArtifact();
    } catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
        throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
    }
    File pomFile = pomArtifact.getFile();
    return new FileModelSource(pomFile);
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) FileModelSource(org.apache.maven.model.building.FileModelSource) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 95 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class AetherClassPathClassifier method buildTestRunnerUrlClassification.

/**
 * Application classification is being done by resolving the direct dependencies with scope
 * {@value org.eclipse.aether.util.artifact.JavaScopes#TEST} for the rootArtifact. Due to Eclipse Aether resolution excludes by
 * {@value org.eclipse.aether.util.artifact.JavaScopes#TEST} dependencies an imaginary pom will be created with these
 * dependencies as {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} so the dependency graph can be resolved (with
 * the same results as it will be obtained from Maven).
 * <p/>
 * If the rootArtifact was classified as plugin its {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} will be changed
 * to {@value org.eclipse.aether.util.artifact.JavaScopes#PROVIDED} in order to exclude them from the dependency graph.
 * <p/>
 * Filtering logic includes the following pattern to includes the patterns defined at
 * {@link ClassPathClassifierContext#getTestInclusions()}. It also excludes
 * {@link ClassPathClassifierContext#getExcludedArtifacts()}, {@link ClassPathClassifierContext#getTestExclusions()}.
 * <p/>
 * If the application artifact has not been classified as plugin its going to be resolved as {@value #JAR_EXTENSION} in order to
 * include this its compiled classes classification.
 *
 * @param context {@link ClassPathClassifierContext} with settings for the classification process
 * @param directDependencies {@link List} of {@link Dependency} with direct dependencies for the rootArtifact
 * @param rootArtifactType {@link ArtifactClassificationType} for rootArtifact @return {@link URL}s for application class loader
 * @param rootArtifactRemoteRepositories remote repositories defined at the rootArtifact
 */
private List<URL> buildTestRunnerUrlClassification(ClassPathClassifierContext context, List<Dependency> directDependencies, ArtifactClassificationType rootArtifactType, List<RemoteRepository> rootArtifactRemoteRepositories) {
    logger.debug("Building application classification");
    Artifact rootArtifact = context.getRootArtifact();
    DependencyFilter dependencyFilter = new PatternInclusionsDependencyFilter(context.getTestInclusions());
    logger.debug("Using filter for dependency graph to include: '{}'", context.getTestInclusions());
    List<File> appFiles = newArrayList();
    List<String> exclusionsPatterns = newArrayList();
    if (APPLICATION.equals(rootArtifactType)) {
        logger.debug("RootArtifact identified as {} so is going to be added to application classification", APPLICATION);
        File rootArtifactOutputFile = resolveRootArtifactFile(rootArtifact);
        if (rootArtifactOutputFile != null) {
            appFiles.add(rootArtifactOutputFile);
        } else {
            logger.warn("rootArtifact '{}' identified as {} but doesn't have an output {} file", rootArtifact, rootArtifactType, JAR_EXTENSION);
        }
    } else {
        logger.debug("RootArtifact already classified as plugin or module, excluding it from application classification");
        exclusionsPatterns.add(rootArtifact.getGroupId() + MAVEN_COORDINATES_SEPARATOR + rootArtifact.getArtifactId() + MAVEN_COORDINATES_SEPARATOR + "*" + MAVEN_COORDINATES_SEPARATOR + "*" + MAVEN_COORDINATES_SEPARATOR + rootArtifact.getVersion());
    }
    directDependencies = directDependencies.stream().map(toTransform -> {
        if (toTransform.getScope().equals(TEST)) {
            if (TESTS_CLASSIFIER.equals(toTransform.getArtifact().getClassifier())) {
                // Exclude transitive dependencies of test-jar artifacts
                return toTransform.setScope(COMPILE).setExclusions(singleton(new Exclusion("*", "*", "*", "*")));
            } else {
                return toTransform.setScope(COMPILE);
            }
        }
        if ((PLUGIN.equals(rootArtifactType) || MULE_PLUGIN_CLASSIFIER.equals(toTransform.getArtifact().getClassifier()) || MULE_SERVICE_CLASSIFIER.equals(toTransform.getArtifact().getClassifier())) && toTransform.getScope().equals(COMPILE)) {
            return toTransform.setScope(PROVIDED);
        }
        if (rootArtifactType == MODULE && toTransform.getScope().equals(COMPILE)) {
            return toTransform.setScope(PROVIDED);
        }
        Artifact artifact = toTransform.getArtifact();
        if (context.getApplicationSharedLibCoordinates().contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) {
            return toTransform.setScope(COMPILE);
        }
        return toTransform;
    }).collect(toList());
    logger.debug("OR exclude: {}", context.getExcludedArtifacts());
    exclusionsPatterns.addAll(context.getExcludedArtifacts());
    if (!context.getTestExclusions().isEmpty()) {
        logger.debug("OR exclude application specific artifacts: {}", context.getTestExclusions());
        exclusionsPatterns.addAll(context.getTestExclusions());
    }
    try {
        List<Dependency> managedDependencies = newArrayList(dependencyResolver.readArtifactDescriptor(rootArtifact).getManagedDependencies());
        managedDependencies.addAll(directDependencies.stream().filter(directDependency -> !directDependency.getScope().equals(TEST)).collect(toList()));
        logger.debug("Resolving dependency graph for '{}' scope direct dependencies: {} and managed dependencies {}", TEST, directDependencies, managedDependencies);
        final Dependency rootTestDependency = new Dependency(new DefaultArtifact(rootArtifact.getGroupId(), rootArtifact.getArtifactId(), TESTS_CLASSIFIER, JAR_EXTENSION, rootArtifact.getVersion()), TEST);
        List<File> urls = dependencyResolver.resolveDependencies(rootTestDependency, directDependencies, managedDependencies, orFilter(dependencyFilter, new PatternExclusionsDependencyFilter(exclusionsPatterns)), rootArtifactRemoteRepositories);
        appFiles.addAll(urls);
    } catch (Exception e) {
        throw new IllegalStateException("Couldn't resolve dependencies for application '" + context.getRootArtifact() + "' classification", e);
    }
    List<URL> testRunnerLibUrls = newArrayList(toUrl(appFiles));
    logger.debug("Appending URLs to test runner plugin: {}", context.getTestRunnerPluginUrls());
    testRunnerLibUrls.addAll(context.getTestRunnerPluginUrls());
    resolveSnapshotVersionsToTimestampedFromClassPath(testRunnerLibUrls, context.getClassPathURLs());
    return testRunnerLibUrls;
}
Also used : PatternInclusionsDependencyFilter(org.mule.test.runner.classification.PatternInclusionsDependencyFilter) PatternExclusionsDependencyFilter(org.mule.test.runner.classification.PatternExclusionsDependencyFilter) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL) PatternExclusionsDependencyFilter(org.mule.test.runner.classification.PatternExclusionsDependencyFilter) PatternInclusionsDependencyFilter(org.mule.test.runner.classification.PatternInclusionsDependencyFilter) Exclusion(org.eclipse.aether.graph.Exclusion) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)110 Artifact (org.eclipse.aether.artifact.Artifact)70 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)42 File (java.io.File)39 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)34 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)29 IOException (java.io.IOException)24 Dependency (org.eclipse.aether.graph.Dependency)23 ArrayList (java.util.ArrayList)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)13 CollectRequest (org.eclipse.aether.collection.CollectRequest)12 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)12 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)12 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)12 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)12 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)11 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)10 Version (org.eclipse.aether.version.Version)10 Model (org.apache.maven.model.Model)9 RepositorySystem (org.eclipse.aether.RepositorySystem)9