Search in sources :

Example 46 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project revapi by revapi.

the class AbstractVersionModifyingMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        return;
    }
    AnalysisResults analysisResults;
    if (!initializeComparisonArtifacts()) {
        // we've got non-file artifacts, for which there is no reason to run analysis
        DefaultArtifact oldArtifact = new DefaultArtifact(oldArtifacts[0]);
        analysisResults = new AnalysisResults(ApiChangeLevel.NO_CHANGE, oldArtifact.getVersion());
    } else {
        analysisResults = analyzeProject(project);
    }
    if (analysisResults == null) {
        return;
    }
    ApiChangeLevel changeLevel = analysisResults.apiChangeLevel;
    if (singleVersionForAllModules) {
        File changesFile = getChangesFile();
        try (PrintWriter out = new PrintWriter(new FileOutputStream(changesFile, true))) {
            out.println(project.getArtifact().toString() + "=" + changeLevel + "," + analysisResults.baseVersion);
        } catch (IOException e) {
            throw new MojoExecutionException("Failure while updating the changes tracking file.", e);
        }
    } else {
        Version v = nextVersion(analysisResults.baseVersion, changeLevel);
        updateProjectVersion(project, v);
    }
    if (singleVersionForAllModules && project.equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1))) {
        try (BufferedReader rdr = new BufferedReader(new FileReader(getChangesFile()))) {
            Map<String, AnalysisResults> projectChanges = new HashMap<>();
            String line;
            while ((line = rdr.readLine()) != null) {
                int equalsIdx = line.indexOf('=');
                String projectGav = line.substring(0, equalsIdx);
                String changeAndBaseVersion = line.substring(equalsIdx + 1);
                int commaIdx = changeAndBaseVersion.indexOf(',');
                String change = changeAndBaseVersion.substring(0, commaIdx);
                String baseVersion = changeAndBaseVersion.substring(commaIdx + 1);
                changeLevel = ApiChangeLevel.valueOf(change);
                projectChanges.put(projectGav, new AnalysisResults(changeLevel, baseVersion));
            }
            // establish the tree hierarchy of the projects
            Set<MavenProject> roots = new HashSet<>();
            Map<MavenProject, Set<MavenProject>> children = new HashMap<>();
            Deque<MavenProject> unprocessed = new ArrayDeque<>(mavenSession.getProjects());
            while (!unprocessed.isEmpty()) {
                MavenProject pr = unprocessed.pop();
                if (!projectChanges.containsKey(pr.getArtifact().toString())) {
                    continue;
                }
                MavenProject pa = pr.getParent();
                if (roots.contains(pa)) {
                    roots.remove(pr);
                    AnalysisResults paR = projectChanges.get(pa.getArtifact().toString());
                    AnalysisResults prR = projectChanges.get(pr.getArtifact().toString());
                    if (prR.apiChangeLevel.ordinal() > paR.apiChangeLevel.ordinal()) {
                        paR.apiChangeLevel = prR.apiChangeLevel;
                    }
                    children.get(pa).add(pr);
                } else {
                    roots.add(pr);
                }
                children.put(pr, new HashSet<MavenProject>());
            }
            Iterator<MavenProject> it = roots.iterator();
            while (it.hasNext()) {
                Deque<MavenProject> tree = new ArrayDeque<>();
                MavenProject p = it.next();
                tree.add(p);
                it.remove();
                AnalysisResults results = projectChanges.get(p.getArtifact().toString());
                Version v = nextVersion(results.baseVersion, results.apiChangeLevel);
                while (!tree.isEmpty()) {
                    MavenProject current = tree.pop();
                    updateProjectVersion(current, v);
                    Set<MavenProject> c = children.get(current);
                    if (c != null) {
                        for (MavenProject cp : c) {
                            updateProjectParentVersion(cp, v);
                        }
                        tree.addAll(c);
                    }
                }
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Failure while reading the changes tracking file.", e);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) IOException(java.io.IOException) ArrayDeque(java.util.ArrayDeque) MavenProject(org.apache.maven.project.MavenProject) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet)

Example 47 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project storm by apache.

the class DependencyResolverTest method resolveValid.

@Test
public void resolveValid() throws Exception {
    // please pick small artifact which has small transitive dependency
    // and let's mark as Ignore if we want to run test even without internet or maven central is often not stable
    Dependency dependency = new Dependency(new DefaultArtifact("org.apache.storm:flux-core:1.0.0"), JavaScopes.COMPILE);
    List<ArtifactResult> results = sut.resolve(Lists.newArrayList(dependency));
    assertTrue(results.size() > 0);
    // it should be org.apache.storm:flux-core:jar:1.0.0 and commons-cli:commons-cli:jar:1.2
    assertContains(results, "org.apache.storm", "flux-core", "1.0.0");
    assertContains(results, "commons-cli", "commons-cli", "1.2");
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 48 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project storm by apache.

the class AetherUtils method parseDependency.

/**
 * Parses dependency parameter and build {@link Dependency} object.
 *
 * @param dependency string representation of dependency parameter
 * @return Dependency object
 */
public static Dependency parseDependency(String dependency) {
    List<String> dependencyAndExclusions = Arrays.asList(dependency.split("\\^"));
    Collection<Exclusion> exclusions = new ArrayList<>();
    for (int idx = 1; idx < dependencyAndExclusions.size(); idx++) {
        exclusions.add(AetherUtils.createExclusion(dependencyAndExclusions.get(idx)));
    }
    Artifact artifact = new DefaultArtifact(dependencyAndExclusions.get(0));
    return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions);
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 49 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project pinpoint by naver.

the class DependencyResolver method resolveDependencySets.

public Map<String, List<Artifact>> resolveDependencySets(String... dependencies) {
    List<List<Artifact>> companions = resolve(dependencies);
    List<List<List<Artifact>>> xxx = new ArrayList<>();
    for (List<Artifact> companion : companions) {
        Artifact representative = companion.get(0);
        List<Version> versions;
        try {
            versions = getVersions(representative);
        } catch (VersionRangeResolutionException e) {
            throw new IllegalArgumentException("Fail to resolve version of: " + representative);
        }
        if (versions.isEmpty()) {
            throw new IllegalArgumentException("No version in the given range: " + representative);
        }
        List<List<Artifact>> companionVersions = new ArrayList<>(versions.size());
        for (Version version : versions) {
            List<Artifact> companionVersion = new ArrayList<>(companion.size());
            for (Artifact artifact : companion) {
                Artifact verArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version.toString());
                companionVersion.add(verArtifact);
            }
            companionVersions.add(companionVersion);
        }
        xxx.add(companionVersions);
    }
    Map<String, List<Artifact>> result = combination(xxx);
    return result;
}
Also used : ArrayList(java.util.ArrayList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Version(org.eclipse.aether.version.Version) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 50 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project frontend-maven-plugin by eirslett.

the class RepositoryCacheResolver method createArtifact.

private DefaultArtifact createArtifact(CacheDescriptor cacheDescriptor) {
    String version = cacheDescriptor.getVersion().replaceAll("^v", "");
    DefaultArtifact artifact;
    if (cacheDescriptor.getClassifier() == null) {
        artifact = new DefaultArtifact(GROUP_ID, cacheDescriptor.getName(), cacheDescriptor.getExtension(), version);
    } else {
        artifact = new DefaultArtifact(GROUP_ID, cacheDescriptor.getName(), cacheDescriptor.getClassifier(), cacheDescriptor.getExtension(), version);
    }
    return artifact;
}
Also used : 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