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);
}
}
}
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");
}
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);
}
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;
}
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;
}
Aggregations