use of org.eclipse.aether.artifact.Artifact in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiMavenService method getBomVersions.
/**
* Returns the available Google Cloud Java client library BOM versions from Maven Central.
*
* @return returns the {@link Version versions} of the BOMs
*/
List<Version> getBomVersions() {
Artifact artifact = new DefaultArtifact(toBomCoordinates(GOOGLE_CLOUD_JAVA_BOM_ALL_VERSIONS_CONSTRAINT));
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.addRepository(MAVEN_CENTRAL_REPOSITORY);
try {
VersionRangeResult result = SYSTEM.resolveVersionRange(SESSION, rangeRequest);
return result.getVersions();
} catch (VersionRangeResolutionException e) {
logger.warn("Error fetching available BOM versions from Maven Central", e);
return ImmutableList.of();
}
}
use of org.eclipse.aether.artifact.Artifact in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiMavenService method getManagedDependencyVersion.
/**
* Finds the version of the passed in {@link CloudLibraryClientMavenCoordinates} that is managed
* by the given BOM version.
*
* @param libraryMavenCoordinates the maven coordinates of the {@link CloudLibrary} for which we
* are finding the version
* @param bomVersion the version of the BOM from which to fetch the library version
* @return the optional version of the library found in the given BOM
*/
Optional<String> getManagedDependencyVersion(CloudLibraryClientMavenCoordinates libraryMavenCoordinates, String bomVersion) {
Artifact bomArtifact = new DefaultArtifact(toBomCoordinates(bomVersion));
ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
request.setArtifact(bomArtifact);
request.addRepository(MAVEN_CENTRAL_REPOSITORY);
try {
ArtifactDescriptorResult result = SYSTEM.readArtifactDescriptor(SESSION, request);
return result.getManagedDependencies().stream().filter(dependency -> {
Artifact artifact = dependency.getArtifact();
String coordinatesFromBom = toFormattedMavenCoordinates(libraryMavenCoordinates.getGroupId(), libraryMavenCoordinates.getArtifactId());
String libraryCoordinates = toFormattedMavenCoordinates(artifact.getGroupId(), artifact.getArtifactId());
return coordinatesFromBom.equalsIgnoreCase(libraryCoordinates);
}).findFirst().map(dependency -> dependency.getArtifact().getVersion());
} catch (ArtifactDescriptorException e) {
logger.warn("Error fetching version of client library from bom version " + bomVersion);
return Optional.empty();
}
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class ReportAggregateMojo method getRunConfig.
private ProjectVersions getRunConfig(MavenProject project) {
ProjectVersions ret = new ProjectVersions();
Plugin revapiPlugin = findRevapi(project);
if (revapiPlugin == null) {
return ret;
}
Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration();
String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts");
String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts");
String oldVersion = getValueOfChild(pluginConfig, "oldVersion");
if (oldVersion == null) {
oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE);
}
String newVersion = getValueOfChild(pluginConfig, "newVersion");
if (newVersion == null) {
newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion());
}
String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion);
String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion);
if (oldArtifacts == null || oldArtifacts.length == 0) {
if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
return ret;
}
oldArtifacts = new String[] { defaultOldArtifact };
}
if (newArtifacts == null || newArtifacts.length == 0) {
if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
return ret;
}
newArtifacts = new String[] { defaultNewArtifact };
}
String versionRegexString = getValueOfChild(pluginConfig, "versionFormat");
Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
if (alwaysCheckForReleaseVersion) {
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
}
ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories());
Function<String, Artifact> resolve = gav -> {
try {
return Analyzer.resolveConstrained(project, gav, versionRegex, resolver);
} catch (VersionRangeResolutionException | ArtifactResolutionException e) {
getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage());
return null;
}
};
ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
return ret;
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class ArtifactResolver method makeRemoteOnly.
private RepositorySystemSession makeRemoteOnly(RepositorySystemSession session) {
return new AbstractForwardingRepositorySystemSession() {
@Override
protected RepositorySystemSession getSession() {
return session;
}
@Override
public WorkspaceReader getWorkspaceReader() {
return null;
}
@Override
public LocalRepositoryManager getLocalRepositoryManager() {
LocalRepositoryManager wrapped = session.getLocalRepositoryManager();
return new LocalRepositoryManager() {
@Override
public LocalRepository getRepository() {
return wrapped.getRepository();
}
@Override
public String getPathForLocalArtifact(Artifact artifact) {
return wrapped.getPathForLocalArtifact(artifact);
}
@Override
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return wrapped.getPathForRemoteArtifact(artifact, repository, context);
}
@Override
public String getPathForLocalMetadata(Metadata metadata) {
return wrapped.getPathForLocalMetadata(metadata);
}
@Override
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return wrapped.getPathForRemoteMetadata(metadata, repository, context);
}
@Override
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
return wrapped.find(session, request);
}
@Override
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
wrapped.add(session, request);
}
@Override
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
if (request.getRepository() == null) {
// local metadata request... the returned file must not be null but may not exist
// we exploit that to not include the locally built results
LocalMetadataResult ret = new LocalMetadataResult(request);
ret.setFile(new File("<faked-to-force-remote-only-resolution-of-artifacts>"));
return ret;
} else {
return wrapped.find(session, request);
}
}
@Override
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
wrapped.add(session, request);
}
};
}
};
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class ArtifactResolver method collectTransitiveDeps.
protected void collectTransitiveDeps(String gav, Set<Artifact> resolvedArtifacts, Set<Exception> failures) throws RepositoryException {
final Artifact rootArtifact = resolveArtifact(gav);
CollectRequest collectRequest = new CollectRequest(new Dependency(rootArtifact, null), repositories);
DependencyRequest request = new DependencyRequest(collectRequest, null);
DependencyResult result;
try {
result = repositorySystem.resolveDependencies(session, request);
} catch (DependencyResolutionException dre) {
result = dre.getResult();
}
result.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {
@Override
public boolean visitEnter(DependencyNode node) {
return true;
}
@Override
public boolean visitLeave(DependencyNode node) {
Dependency dep = node.getDependency();
if (dep == null || dep.getArtifact().equals(rootArtifact)) {
return true;
}
resolvedArtifacts.add(dep.getArtifact());
return true;
}
}));
failures.addAll(result.getCollectExceptions());
}
Aggregations