use of org.eclipse.aether.artifact.DefaultArtifact in project wildfly-swarm by wildfly-swarm.
the class ExtraArtifactsHandler method createNode.
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
Artifact original = n.getArtifact();
Artifact withExtension = new DefaultArtifact(original.getGroupId(), original.getArtifactId(), classifier.orElse(original.getClassifier()), extension.orElse(original.getExtension()), original.getVersion(), original.getProperties(), (File) null);
DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));
return nodeWithClassifier;
}
use of org.eclipse.aether.artifact.DefaultArtifact in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method resolve.
@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
if (spec.file == null) {
final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version());
final LocalArtifactResult localResult = this.session.getLocalRepositoryManager().find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
if (localResult.isAvailable()) {
spec.file = localResult.getFile();
} else {
try {
final ArtifactResult result = resolver.resolveArtifact(this.session, new ArtifactRequest(artifact, this.remoteRepositories, null));
if (result.isResolved()) {
spec.file = result.getArtifact().getFile();
}
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
}
return spec.file != null ? spec : null;
}
use of org.eclipse.aether.artifact.DefaultArtifact 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.DefaultArtifact 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.DefaultArtifact in project revapi by revapi.
the class Main method run.
@SuppressWarnings("ConstantConditions")
private static void run(File cacheDir, String[] extensionGAVs, List<FileArchive> oldArchives, List<FileArchive> oldSupplementaryArchives, List<FileArchive> newArchives, List<FileArchive> newSupplementaryArchives, String[] configFiles, Map<String, String> additionalConfig) throws Exception {
ProjectModule.Builder bld = ProjectModule.build();
bld.localRepository(cacheDir);
if (extensionGAVs != null) {
for (String gav : extensionGAVs) {
bld.addDependency(gav);
}
}
Properties libraryVersionsProps = new Properties();
libraryVersionsProps.load(Main.class.getResourceAsStream("/library.versions"));
Set<Artifact> globalArtifacts = libraryVersionsProps.stringPropertyNames().stream().map(p -> {
String gav = p + ':' + libraryVersionsProps.get(p);
return new DefaultArtifact(gav);
}).collect(toSet());
bld.moduleSpecController(new ModuleSpecController() {
private boolean override;
private String currentModuleName;
@Override
public void start(String moduleName) {
currentModuleName = moduleName;
}
// TODO add warnings when the deps depend on another revapi version than the one bundled...
@Override
public DependencySpec modifyDependency(String dependencyName, DependencySpec original) {
boolean overrideThis = false;
Artifact a = new DefaultArtifact(dependencyName);
for (Artifact ga : globalArtifacts) {
if (ga.getGroupId().equals(a.getGroupId()) && ga.getArtifactId().equals(a.getArtifactId()) && !ga.getVersion().equals(a.getVersion())) {
LOG.warn("Detected version conflict in dependencies of extension " + currentModuleName + ". The extension depends on " + a + " while the CLI has " + ga + " on global" + " classpath. This will likely cause problems.");
}
}
override = override || overrideThis;
return overrideThis ? null : original;
}
@Override
public void modify(ModuleSpec.Builder bld) {
if (override) {
Set<String> revapiPaths = new HashSet<>(Arrays.asList("org/revapi", "org/revapi/configuration", "org/revapi/query", "org/revapi/simple"));
bld.addDependency(DependencySpec.createSystemDependencySpec(revapiPaths));
override = false;
}
}
@Override
public void end(String moduleName) {
currentModuleName = null;
}
});
LOG.info("Downloading extensions");
Module project = bld.create();
Revapi revapi = Revapi.builder().withAllExtensionsFrom(project.getClassLoader()).withAllExtensionsFromThreadContextClassLoader().build();
AnalysisContext.Builder ctxBld = AnalysisContext.builder(revapi).withOldAPI(API.of(oldArchives).supportedBy(oldSupplementaryArchives).build()).withNewAPI(API.of(newArchives).supportedBy(newSupplementaryArchives).build());
if (configFiles != null) {
for (String cf : configFiles) {
File f = new File(cf);
checkCanRead(f, "Configuration file");
try (FileInputStream is = new FileInputStream(f)) {
ctxBld.mergeConfigurationFromJSONStream(is);
}
}
}
for (Map.Entry<String, String> e : additionalConfig.entrySet()) {
String[] keyPath = e.getKey().split("\\.");
ModelNode additionalNode = new ModelNode();
ModelNode key = additionalNode.get(keyPath);
String value = e.getValue();
if (value.startsWith("[") && value.endsWith("]")) {
String[] values = value.substring(1, value.length() - 1).split("\\s*,\\s*");
for (String v : values) {
key.add(v);
}
} else {
key.set(value);
}
ctxBld.mergeConfiguration(additionalNode);
}
LOG.info("Starting analysis");
try (AnalysisResult result = revapi.analyze(ctxBld.build())) {
if (!result.isSuccess()) {
throw result.getFailure();
}
}
}
Aggregations