use of org.eclipse.aether.graph.DependencyNode in project sts4 by spring-projects.
the class MavenCore method readDependencyTree.
/**
* Taken from M2E same named method from MavenModelManager
*
* @param repositorySystem
* @param repositorySession
* @param mavenProject
* @param scope
* @return
*/
private DependencyNode readDependencyTree(org.eclipse.aether.RepositorySystem repositorySystem, RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession);
ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
session.setDependencyGraphTransformer(transformer);
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true));
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
CollectRequest request = new CollectRequest();
// $NON-NLS-1$
request.setRequestContext("project");
request.setRepositories(mavenProject.getRemoteProjectRepositories());
for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) {
request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
DependencyManagement depMngt = mavenProject.getDependencyManagement();
if (depMngt != null) {
for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) {
request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
}
DependencyNode node;
try {
node = repositorySystem.collectDependencies(session, request).getRoot();
} catch (DependencyCollectionException ex) {
node = ex.getResult().getRoot();
}
Collection<String> scopes = new HashSet<String>();
Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST);
if (Artifact.SCOPE_COMPILE.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
} else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else {
scopes.clear();
}
CloningDependencyVisitor cloner = new CloningDependencyVisitor();
node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes)));
node = cloner.getRootNode();
return node;
}
use of org.eclipse.aether.graph.DependencyNode in project byte-buddy by raphw.
the class ClassLoaderResolver method doResolve.
/**
* Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
*
* @param mavenCoordinate The Maven coordinate to resolve.
* @return A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
* @throws MojoExecutionException If the user configuration results in an error.
* @throws MojoFailureException If the plugin application raises an error.
*/
private ClassLoader doResolve(MavenCoordinate mavenCoordinate) throws MojoExecutionException, MojoFailureException {
List<URL> urls = new ArrayList<URL>();
log.info("Resolving transformer dependency: " + mavenCoordinate);
try {
DependencyNode root = repositorySystem.collectDependencies(repositorySystemSession, new CollectRequest(new Dependency(mavenCoordinate.asArtifact(), "runtime"), remoteRepositories)).getRoot();
repositorySystem.resolveDependencies(repositorySystemSession, new DependencyRequest().setRoot(root));
PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator();
root.accept(preorderNodeListGenerator);
for (Artifact artifact : preorderNodeListGenerator.getArtifacts(false)) {
urls.add(artifact.getFile().toURI().toURL());
}
} catch (DependencyCollectionException exception) {
throw new MojoExecutionException("Could not collect dependencies for " + mavenCoordinate, exception);
} catch (DependencyResolutionException exception) {
throw new MojoExecutionException("Could not resolve dependencies for " + mavenCoordinate, exception);
} catch (MalformedURLException exception) {
throw new MojoFailureException("Could not resolve file as URL for " + mavenCoordinate, exception);
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), ByteBuddy.class.getClassLoader());
}
use of org.eclipse.aether.graph.DependencyNode in project bnd by bndtools.
the class DependencyResolver method resolve.
public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
if (resolvedDependencies != null) {
return resolvedDependencies;
}
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
request.setResolutionFilter(new DependencyFilter() {
@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
if (node.getDependency() != null) {
return scopes.contains(node.getDependency().getScope());
}
return false;
}
});
DependencyResolutionResult result;
try {
result = resolver.resolve(request);
} catch (DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Map<File, ArtifactResult> dependencies = new HashMap<>();
DependencyNode dependencyGraph = result.getDependencyGraph();
if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
if (deployRepo != null) {
remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
}
discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
}
return resolvedDependencies = dependencies;
}
use of org.eclipse.aether.graph.DependencyNode in project meecrowave by apache.
the class MeecrowaveBundleMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().warn(getClass().getSimpleName() + " skipped");
return;
}
final File distroFolder = new File(buildDirectory, rootName == null ? artifactId + "-distribution" : rootName);
if (distroFolder.exists()) {
delete(distroFolder);
}
Stream.of("bin", "conf", "logs", "lib").forEach(i -> new File(distroFolder, i).mkdirs());
// TODO: add .bat support
for (final String ext : asList("sh", "bat")) {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) {
write(new File(distroFolder, "bin/meecrowave." + ext), StrSubstitutor.replace(reader.lines().collect(joining("\n")), new HashMap<String, String>() {
{
put("main", main);
}
}));
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
copyProvidedFiles(distroFolder);
write(new File(distroFolder, "logs/you_can_safely_delete.txt"), DELETE_TEXT);
final Collection<String> includedArtifacts = project.getArtifacts().stream().filter(this::isIncluded).map(a -> {
addLib(distroFolder, a.getFile());
return a.getArtifactId();
}).collect(toList());
if (app.exists()) {
addLib(distroFolder, app);
}
if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4", ""));
}
if (libs != null) {
libs.forEach(l -> {
final String[] c = l.split(":");
if (c.length != 3 && c.length != 4) {
throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier]");
}
addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
});
}
if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core")) {
final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
request.setMavenProject(new MavenProject() {
{
getDependencies().add(new Dependency() {
{
setGroupId("org.apache.meecrowave");
setArtifactId("meecrowave-core");
setVersion(findVersion());
}
});
}
});
request.setRepositorySession(session);
try {
dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() {
@Override
public boolean visitEnter(final DependencyNode node) {
return true;
}
@Override
public boolean visitLeave(final DependencyNode node) {
final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) {
addLib(distroFolder, artifact.getFile());
}
return true;
}
});
} catch (final DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
for (final String format : formats) {
getLog().info(format + "-ing Custom Meecrowave Distribution");
final File output = new File(buildDirectory, artifactId + "-meecrowave-distribution." + format);
switch(format.toLowerCase(ENGLISH)) {
case "tar.gz":
try (final TarArchiveOutputStream tarGz = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output)))) {
tarGz.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (final String entry : distroFolder.list()) {
tarGz(tarGz, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
case "zip":
try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(output))) {
for (final String entry : distroFolder.list()) {
zip(zos, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
default:
throw new IllegalArgumentException(format + " is not supported");
}
attach(format, output);
}
if (!keepExplodedFolder) {
delete(distroFolder);
}
}
use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.
the class AetherBasedResolver method resolveDependencies.
protected DependencyNode resolveDependencies(RepositorySystemSession session, List<RemoteRepository> repos, DependencyNode pomNode, Dependency dependency, final Filter<Dependency> shouldExclude) throws FailedToResolveDependency {
if (!DependencyFilters.matches(dependency, shouldExclude)) {
CollectRequest cr = new CollectRequest(dependency, repos);
// request.setRequestContext("runtime");
try {
DependencyNode node = m_repoSystem.collectDependencies(session, cr).getRoot();
DependencyFilter filter = new DependencyFilter() {
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
return !DependencyFilters.matches(node, shouldExclude);
}
};
DependencyRequest request = new DependencyRequest(cr, filter);
m_repoSystem.resolveDependencies(session, request);
return node;
} catch (DependencyResolutionException | DependencyCollectionException e) {
handleDependencyResolveFailure(pomNode, dependency, e);
}
}
return null;
}
Aggregations