use of org.eclipse.aether.util.artifact.JavaScopes.PROVIDED in project mule by mulesoft.
the class AetherClassPathClassifier method buildContainerUrlClassification.
/**
* Container classification is being done by resolving the {@value org.eclipse.aether.util.artifact.JavaScopes#PROVIDED} direct
* dependencies of the rootArtifact. Is uses the exclusions defined in
* {@link ClassPathClassifierContext#getProvidedExclusions()} to filter the dependency graph plus
* {@link ClassPathClassifierContext#getExcludedArtifacts()}.
* <p/>
* In order to resolve correctly the {@value org.eclipse.aether.util.artifact.JavaScopes#PROVIDED} direct dependencies it will
* get for each one the manage dependencies and use that list to resolve the graph.
*
* @param context {@link ClassPathClassifierContext} with settings for the classification process
* @param pluginUrlClassifications {@link PluginUrlClassification}s to check if rootArtifact was classified as plugin
* @param rootArtifactType {@link ArtifactClassificationType} for rootArtifact
* @param rootArtifactRemoteRepositories remote repositories defined at the rootArtifact
* @return {@link List} of {@link URL}s for the container class loader
*/
private List<URL> buildContainerUrlClassification(ClassPathClassifierContext context, List<Dependency> directDependencies, List<ArtifactUrlClassification> serviceUrlClassifications, List<PluginUrlClassification> pluginUrlClassifications, ArtifactClassificationType rootArtifactType, List<RemoteRepository> rootArtifactRemoteRepositories) {
directDependencies = directDependencies.stream().filter(getContainerDirectDependenciesFilter(rootArtifactType)).filter(dependency -> {
Artifact artifact = dependency.getArtifact();
return (!serviceUrlClassifications.stream().filter(artifactUrlClassification -> artifactUrlClassification.getArtifactId().equals(toId(artifact))).findAny().isPresent() && !pluginUrlClassifications.stream().filter(artifactUrlClassification -> artifactUrlClassification.getArtifactId().equals(toId(artifact))).findAny().isPresent());
}).map(depToTransform -> depToTransform.setScope(COMPILE)).collect(toList());
// Add logging dependencies to avoid every module from having to declare this dependency.
// This brings the slf4j bridges required by transitive dependencies of the container to its classpath
// TODO MULE-10837 Externalize this dependency along with the other commonly used container dependencies.
directDependencies.add(new Dependency(new DefaultArtifact(RUNTIME_GROUP_ID, LOGGING_ARTIFACT_ID, JAR_EXTENSION, muleVersion), COMPILE));
logger.debug("Selected direct dependencies to be used for resolving container dependency graph (changed to compile in " + "order to resolve the graph): {}", directDependencies);
Set<Dependency> managedDependencies = selectContainerManagedDependencies(context, directDependencies, rootArtifactType, rootArtifactRemoteRepositories);
logger.debug("Collected managed dependencies from direct provided dependencies to be used for resolving container " + "dependency graph: {}", managedDependencies);
List<String> excludedFilterPattern = newArrayList(context.getProvidedExclusions());
excludedFilterPattern.addAll(context.getExcludedArtifacts());
if (!pluginUrlClassifications.isEmpty()) {
excludedFilterPattern.addAll(pluginUrlClassifications.stream().map(pluginUrlClassification -> pluginUrlClassification.getArtifactId()).collect(toList()));
}
if (!serviceUrlClassifications.isEmpty()) {
excludedFilterPattern.addAll(serviceUrlClassifications.stream().map(serviceUrlClassification -> serviceUrlClassification.getArtifactId()).collect(toList()));
}
logger.debug("Resolving dependencies for container using exclusion filter patterns: {}", excludedFilterPattern);
final DependencyFilter dependencyFilter = new PatternExclusionsDependencyFilter(excludedFilterPattern);
List<URL> containerUrls;
try {
containerUrls = toUrl(dependencyResolver.resolveDependencies(null, directDependencies, newArrayList(managedDependencies), dependencyFilter, rootArtifactRemoteRepositories));
} catch (Exception e) {
throw new IllegalStateException("Couldn't resolve dependencies for Container", e);
}
containerUrls = containerUrls.stream().filter(url -> {
String file = toFile(url).getAbsolutePath();
return !(endsWithIgnoreCase(file, POM_XML) || endsWithIgnoreCase(file, POM_EXTENSION) || endsWithIgnoreCase(file, ZIP_EXTENSION));
}).collect(toList());
if (MODULE.equals(rootArtifactType)) {
File rootArtifactOutputFile = resolveRootArtifactFile(context.getRootArtifact());
if (rootArtifactOutputFile == null) {
throw new IllegalStateException("rootArtifact (" + context.getRootArtifact() + ") identified as MODULE but doesn't have an output");
}
containerUrls.add(0, toUrl(rootArtifactOutputFile));
}
resolveSnapshotVersionsToTimestampedFromClassPath(containerUrls, context.getClassPathURLs());
return containerUrls;
}
Aggregations