use of org.eclipse.aether.artifact.DefaultArtifact in project acceptance-test-harness by jenkinsci.
the class PluginMetadata method resolve.
public File resolve(Injector i, String version) {
DefaultArtifact artifact = getDefaultArtifact();
if (version != null) {
artifact.setVersion(version);
}
ArtifactResolverUtil resolverUtil = i.getInstance(ArtifactResolverUtil.class);
ArtifactResult r = resolverUtil.resolve(artifact);
return r.getArtifact().getFile();
}
use of org.eclipse.aether.artifact.DefaultArtifact in project acceptance-test-harness by jenkinsci.
the class LocalOverrideUpdateCenterMetadataDecoratorImpl method decorate.
@Override
public void decorate(UpdateCenterMetadata ucm) {
if ("true".equals(System.getenv("LOCAL_SNAPSHOTS"))) {
File userHome = new File(System.getProperty("user.home"));
File localRepo = MavenLocalRepository.getMavenLocalRepository();
VersionScheme versionScheme = new GenericVersionScheme();
for (Iterator<Map.Entry<String, PluginMetadata>> it = ucm.plugins.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, PluginMetadata> entry = it.next();
DefaultArtifact artifact = entry.getValue().getDefaultArtifact();
File artifactDir = new File(new File(localRepo, artifact.getGroupId().replace('.', File.separatorChar)), artifact.getArtifactId());
File metadata = new File(artifactDir, "maven-metadata-local.xml");
if (metadata.isFile()) {
try {
Version ucVersion = versionScheme.parseVersion(artifact.getVersion());
NodeList versions = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(metadata).getElementsByTagName("version");
for (int i = 0; i < versions.getLength(); i++) {
String version = versions.item(i).getTextContent();
if (version.endsWith("-SNAPSHOT") && versionScheme.parseVersion(version).compareTo(ucVersion) > 0) {
File hpi = new File(new File(artifactDir, version), artifact.getArtifactId() + "-" + version + ".hpi");
if (hpi.isFile()) {
String name = entry.getKey();
System.err.println("Overriding " + name + " " + ucVersion + " with local build of " + version);
PluginMetadata m = PluginMetadata.LocalOverride.create(hpi);
String parsedName = m.getName();
if (!name.equals(parsedName)) {
throw new AssertionError("wrong name: " + parsedName + " vs. " + name);
}
entry.setValue(m);
}
}
}
} catch (Exception x) {
x.printStackTrace();
}
}
}
}
// deprecated mechanism, as of 1.57
for (Map.Entry<String, String> e : System.getenv().entrySet()) {
String key = e.getKey();
if (!isPluginEnvironmentVariable(key))
continue;
try {
override(ucm, e.getValue());
System.err.println("Using XXX.jpi/XXX_JPI env vars is deprecated. Use LOCAL_JARS instead.");
} catch (Exception x) {
throw new IllegalArgumentException("Unable to honor environment variable " + key, x);
}
}
// past 1.57, preferred way
String localJars = System.getenv("LOCAL_JARS");
if (localJars != null) {
for (String jar : localJars.split(File.pathSeparator)) {
try {
override(ucm, jar);
} catch (Exception x) {
throw new IllegalArgumentException("Unable to honor LOCAL_JARS environment variable", x);
}
}
}
}
use of org.eclipse.aether.artifact.DefaultArtifact 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());
}
use of org.eclipse.aether.artifact.DefaultArtifact in project gate-core by GateNLP.
the class SimpleModelResolver method resolveModel.
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
try {
ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
pomArtifact = system.resolveArtifact(session, request).getArtifact();
} catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
}
File pomFile = pomArtifact.getFile();
return new FileModelSource(pomFile);
}
use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.
the class AetherClassPathClassifier method buildTestRunnerUrlClassification.
/**
* Application classification is being done by resolving the direct dependencies with scope
* {@value org.eclipse.aether.util.artifact.JavaScopes#TEST} for the rootArtifact. Due to Eclipse Aether resolution excludes by
* {@value org.eclipse.aether.util.artifact.JavaScopes#TEST} dependencies an imaginary pom will be created with these
* dependencies as {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} so the dependency graph can be resolved (with
* the same results as it will be obtained from Maven).
* <p/>
* If the rootArtifact was classified as plugin its {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} will be changed
* to {@value org.eclipse.aether.util.artifact.JavaScopes#PROVIDED} in order to exclude them from the dependency graph.
* <p/>
* Filtering logic includes the following pattern to includes the patterns defined at
* {@link ClassPathClassifierContext#getTestInclusions()}. It also excludes
* {@link ClassPathClassifierContext#getExcludedArtifacts()}, {@link ClassPathClassifierContext#getTestExclusions()}.
* <p/>
* If the application artifact has not been classified as plugin its going to be resolved as {@value #JAR_EXTENSION} in order to
* include this its compiled classes classification.
*
* @param context {@link ClassPathClassifierContext} with settings for the classification process
* @param directDependencies {@link List} of {@link Dependency} with direct dependencies for the rootArtifact
* @param rootArtifactType {@link ArtifactClassificationType} for rootArtifact @return {@link URL}s for application class loader
* @param rootArtifactRemoteRepositories remote repositories defined at the rootArtifact
*/
private List<URL> buildTestRunnerUrlClassification(ClassPathClassifierContext context, List<Dependency> directDependencies, ArtifactClassificationType rootArtifactType, List<RemoteRepository> rootArtifactRemoteRepositories) {
logger.debug("Building application classification");
Artifact rootArtifact = context.getRootArtifact();
DependencyFilter dependencyFilter = new PatternInclusionsDependencyFilter(context.getTestInclusions());
logger.debug("Using filter for dependency graph to include: '{}'", context.getTestInclusions());
List<File> appFiles = newArrayList();
List<String> exclusionsPatterns = newArrayList();
if (APPLICATION.equals(rootArtifactType)) {
logger.debug("RootArtifact identified as {} so is going to be added to application classification", APPLICATION);
File rootArtifactOutputFile = resolveRootArtifactFile(rootArtifact);
if (rootArtifactOutputFile != null) {
appFiles.add(rootArtifactOutputFile);
} else {
logger.warn("rootArtifact '{}' identified as {} but doesn't have an output {} file", rootArtifact, rootArtifactType, JAR_EXTENSION);
}
} else {
logger.debug("RootArtifact already classified as plugin or module, excluding it from application classification");
exclusionsPatterns.add(rootArtifact.getGroupId() + MAVEN_COORDINATES_SEPARATOR + rootArtifact.getArtifactId() + MAVEN_COORDINATES_SEPARATOR + "*" + MAVEN_COORDINATES_SEPARATOR + "*" + MAVEN_COORDINATES_SEPARATOR + rootArtifact.getVersion());
}
directDependencies = directDependencies.stream().map(toTransform -> {
if (toTransform.getScope().equals(TEST)) {
if (TESTS_CLASSIFIER.equals(toTransform.getArtifact().getClassifier())) {
// Exclude transitive dependencies of test-jar artifacts
return toTransform.setScope(COMPILE).setExclusions(singleton(new Exclusion("*", "*", "*", "*")));
} else {
return toTransform.setScope(COMPILE);
}
}
if ((PLUGIN.equals(rootArtifactType) || MULE_PLUGIN_CLASSIFIER.equals(toTransform.getArtifact().getClassifier()) || MULE_SERVICE_CLASSIFIER.equals(toTransform.getArtifact().getClassifier())) && toTransform.getScope().equals(COMPILE)) {
return toTransform.setScope(PROVIDED);
}
if (rootArtifactType == MODULE && toTransform.getScope().equals(COMPILE)) {
return toTransform.setScope(PROVIDED);
}
Artifact artifact = toTransform.getArtifact();
if (context.getApplicationSharedLibCoordinates().contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) {
return toTransform.setScope(COMPILE);
}
return toTransform;
}).collect(toList());
logger.debug("OR exclude: {}", context.getExcludedArtifacts());
exclusionsPatterns.addAll(context.getExcludedArtifacts());
if (!context.getTestExclusions().isEmpty()) {
logger.debug("OR exclude application specific artifacts: {}", context.getTestExclusions());
exclusionsPatterns.addAll(context.getTestExclusions());
}
try {
List<Dependency> managedDependencies = newArrayList(dependencyResolver.readArtifactDescriptor(rootArtifact).getManagedDependencies());
managedDependencies.addAll(directDependencies.stream().filter(directDependency -> !directDependency.getScope().equals(TEST)).collect(toList()));
logger.debug("Resolving dependency graph for '{}' scope direct dependencies: {} and managed dependencies {}", TEST, directDependencies, managedDependencies);
final Dependency rootTestDependency = new Dependency(new DefaultArtifact(rootArtifact.getGroupId(), rootArtifact.getArtifactId(), TESTS_CLASSIFIER, JAR_EXTENSION, rootArtifact.getVersion()), TEST);
List<File> urls = dependencyResolver.resolveDependencies(rootTestDependency, directDependencies, managedDependencies, orFilter(dependencyFilter, new PatternExclusionsDependencyFilter(exclusionsPatterns)), rootArtifactRemoteRepositories);
appFiles.addAll(urls);
} catch (Exception e) {
throw new IllegalStateException("Couldn't resolve dependencies for application '" + context.getRootArtifact() + "' classification", e);
}
List<URL> testRunnerLibUrls = newArrayList(toUrl(appFiles));
logger.debug("Appending URLs to test runner plugin: {}", context.getTestRunnerPluginUrls());
testRunnerLibUrls.addAll(context.getTestRunnerPluginUrls());
resolveSnapshotVersionsToTimestampedFromClassPath(testRunnerLibUrls, context.getClassPathURLs());
return testRunnerLibUrls;
}
Aggregations