use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class Analyzer method collectDeps.
@SuppressWarnings("unchecked")
private Set<MavenArchive> collectDeps(String depDescription, ArtifactResolver.CollectionResult res) {
Set<MavenArchive> ret = null;
try {
ret = new HashSet<>();
for (Artifact a : res.getResolvedArtifacts()) {
try {
ret.add(MavenArchive.of(a));
} catch (IllegalArgumentException e) {
res.getFailures().add(e);
}
}
if (!res.getFailures().isEmpty()) {
StringBuilder bld = new StringBuilder();
for (Exception e : res.getFailures()) {
bld.append(e.getMessage()).append(", ");
}
bld.replace(bld.length() - 2, bld.length(), "");
throw new MarkerException("Resolution of some artifacts failed: " + bld.toString());
} else {
return ret;
}
} catch (MarkerException e) {
return handleResolutionError(e, depDescription, ret);
}
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class Analyzer method resolveArtifacts.
@SuppressWarnings("unchecked")
void resolveArtifacts() {
if (resolvedOldApi == null) {
final ArtifactResolver resolver = new ArtifactResolver(repositorySystem, repositorySystemSession, project.getRemoteProjectRepositories());
Function<String, MavenArchive> toFileArchive = gav -> {
try {
Artifact a = resolveConstrained(project, gav, versionRegex, resolver);
return MavenArchive.of(a);
} catch (ArtifactResolutionException | VersionRangeResolutionException | IllegalArgumentException e) {
throw new MarkerException(e.getMessage(), e);
}
};
List<MavenArchive> oldArchives = new ArrayList<>(1);
try {
if (oldGavs != null) {
oldArchives = Stream.of(oldGavs).map(toFileArchive).collect(toList());
}
if (oldArtifacts != null) {
oldArchives.addAll(Stream.of(oldArtifacts).map(MavenArchive::of).collect(toList()));
}
} catch (MarkerException | IllegalArgumentException e) {
String message = "Failed to resolve old artifacts: " + e.getMessage() + ".";
if (failOnMissingArchives) {
throw new IllegalStateException(message, e);
} else {
log.warn(message + " The API analysis will proceed comparing the new archives against an empty" + " archive.");
}
}
List<MavenArchive> newArchives = new ArrayList<>(1);
try {
if (newGavs != null) {
newArchives = Stream.of(newGavs).map(toFileArchive).collect(toList());
}
if (newArtifacts != null) {
newArchives.addAll(Stream.of(newArtifacts).map(MavenArchive::of).collect(toList()));
}
} catch (MarkerException | IllegalArgumentException e) {
String message = "Failed to resolve new artifacts: " + e.getMessage() + ".";
if (failOnMissingArchives) {
throw new IllegalStateException(message, e);
} else {
log.warn(message + " The API analysis will not proceed.");
return;
}
}
// now we need to be a little bit clever. When using RELEASE or LATEST as the version of the old artifact
// it might happen that it gets resolved to the same version as the new artifacts - this notoriously happens
// when releasing using the release plugin - you first build your artifacts, put them into the local repo
// and then do the site updates for the released version. When you do the site, maven will find the released
// version in the repo and resolve RELEASE to it. You compare it against what you just built, i.e. the same
// code, et voila, the site report doesn't ever contain any found differences...
Set<MavenArchive> oldTransitiveDeps = new HashSet<>();
Set<MavenArchive> newTransitiveDeps = new HashSet<>();
if (resolveDependencies) {
String[] resolvedOld = oldArchives.stream().map(MavenArchive::getName).toArray(String[]::new);
String[] resolvedNew = newArchives.stream().map(MavenArchive::getName).toArray(String[]::new);
oldTransitiveDeps.addAll(collectDeps("old", resolver, resolvedOld));
newTransitiveDeps.addAll(collectDeps("new", resolver, resolvedNew));
}
resolvedOldApi = API.of(oldArchives).supportedBy(oldTransitiveDeps).build();
resolvedNewApi = API.of(newArchives).supportedBy(newTransitiveDeps).build();
}
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class Analyzer method resolveConstrained.
/**
* Resolves the gav using the resolver. If the gav corresponds to the project artifact and is an unresolved version
* for a RELEASE or LATEST, the gav is resolved such it a release not newer than the project version is found that
* optionally corresponds to the provided version regex, if provided.
*
* <p>If the gav exactly matches the current project, the file of the artifact is found on the filesystem in
* target directory and the resolver is ignored.
*
* @param project the project to restrict by, if applicable
* @param gav the gav to resolve
* @param versionRegex the optional regex the version must match to be considered.
* @param resolver the version resolver to use
* @return the resolved artifact matching the criteria.
*
* @throws VersionRangeResolutionException on error
* @throws ArtifactResolutionException on error
*/
static Artifact resolveConstrained(MavenProject project, String gav, Pattern versionRegex, ArtifactResolver resolver) throws VersionRangeResolutionException, ArtifactResolutionException {
boolean latest = gav.endsWith(":LATEST");
if (latest || gav.endsWith(":RELEASE")) {
Artifact a = new DefaultArtifact(gav);
if (latest) {
versionRegex = versionRegex == null ? ANY : versionRegex;
} else {
versionRegex = versionRegex == null ? ANY_NON_SNAPSHOT : versionRegex;
}
String upTo = project.getGroupId().equals(a.getGroupId()) && project.getArtifactId().equals(a.getArtifactId()) ? project.getVersion() : null;
return resolver.resolveNewestMatching(gav, upTo, versionRegex, latest, latest);
} else {
String projectGav = getProjectArtifactCoordinates(project, null);
Artifact ret = null;
if (projectGav.equals(gav)) {
ret = findProjectArtifact(project);
}
return ret == null ? resolver.resolveArtifact(gav) : ret;
}
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class ReportAggregateMojo method prepareAnalyzer.
private Analyzer prepareAnalyzer(Revapi revapi, MavenProject project, Locale locale, ProjectVersions storedVersions) {
Plugin runPluginConfig = findRevapi(project);
if (runPluginConfig == null) {
return null;
}
Xpp3Dom runConfig = (Xpp3Dom) runPluginConfig.getConfiguration();
Artifact[] oldArtifacts = storedVersions.oldGavs;
Artifact[] newArtifacts = storedVersions.newGavs;
if (oldArtifacts == null || oldArtifacts.length == 0 || newArtifacts == null || newArtifacts.length == 0) {
return null;
}
String versionRegex = getValueOfChild(runConfig, "versionFormat");
AnalyzerBuilder bld = AnalyzerBuilder.forArtifacts(oldArtifacts, newArtifacts).withAlwaysCheckForReleasedVersion(this.alwaysCheckForReleaseVersion).withAnalysisConfiguration(this.analysisConfiguration).withAnalysisConfigurationFiles(this.analysisConfigurationFiles).withCheckDependencies(this.checkDependencies).withResolveProvidedDependencies(this.resolveProvidedDependencies).withDisallowedExtensions(disallowedExtensions).withFailOnMissingConfigurationFiles(this.failOnMissingConfigurationFiles).withFailOnUnresolvedArtifacts(this.failOnUnresolvedArtifacts).withFailOnUnresolvedDependencies(this.failOnUnresolvedDependencies).withLocale(locale).withLog(getLog()).withProject(project).withRepositorySystem(repositorySystem).withRepositorySystemSession(repositorySystemSession).withSkip(skip).withVersionFormat(versionRegex);
if (revapi == null) {
bld = bld.withReporter(ReportTimeReporter.class);
} else {
bld = bld.withRevapiInstance(revapi);
}
Map<String, Object> contextData = new HashMap<>(1);
contextData.put(ReportTimeReporter.MIN_SEVERITY_KEY, reportSeverity.asDifferenceSeverity());
bld.withContextData(contextData);
return bld.build().analyzer;
}
use of org.eclipse.aether.artifact.Artifact 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());
}
Aggregations