use of org.eclipse.aether.graph.Dependency in project storm by apache.
the class DependencyResolverMain method main.
/**
* Main entry of dependency resolver.
*
* @param args console arguments
* @throws ParseException If there's parsing error on option parse.
* @throws MalformedURLException If proxy URL is malformed.
*/
public static void main(String[] args) throws ParseException, MalformedURLException {
Options options = buildOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (!commandLine.hasOption(OPTION_ARTIFACTS_LONG)) {
throw new IllegalArgumentException("artifacts must be presented.");
}
String artifactsArg = commandLine.getOptionValue(OPTION_ARTIFACTS_LONG);
// DO NOT CHANGE THIS TO SYSOUT
System.err.println("DependencyResolver input - artifacts: " + artifactsArg);
List<Dependency> dependencies = parseArtifactArgs(artifactsArg);
List<RemoteRepository> repositories;
if (commandLine.hasOption(OPTION_ARTIFACT_REPOSITORIES_LONG)) {
String remoteRepositoryArg = commandLine.getOptionValue(OPTION_ARTIFACT_REPOSITORIES_LONG);
// DO NOT CHANGE THIS TO SYSOUT
System.err.println("DependencyResolver input - repositories: " + remoteRepositoryArg);
repositories = parseRemoteRepositoryArgs(remoteRepositoryArg);
} else {
repositories = Collections.emptyList();
}
try {
String localMavenRepoPath = getOrDefaultLocalMavenRepositoryPath(commandLine.getOptionValue(OPTION_MAVEN_LOCAL_REPOSITORY_DIRECTORY_LONG), DEFAULT_FAILBACK_MAVEN_LOCAL_REPOSITORY_DIRECTORY);
// create root directory if not exist
Files.createDirectories(new File(localMavenRepoPath).toPath());
DependencyResolver resolver = new DependencyResolver(localMavenRepoPath, repositories);
if (commandLine.hasOption(OPTION_PROXY_URL_LONG)) {
String proxyUrl = commandLine.getOptionValue(OPTION_PROXY_URL_LONG);
String proxyUsername = commandLine.getOptionValue(OPTION_PROXY_USERNAME_LONG);
String proxyPassword = commandLine.getOptionValue(OPTION_PROXY_PASSWORD_LONG);
resolver.setProxy(parseProxyArg(proxyUrl, proxyUsername, proxyPassword));
}
List<ArtifactResult> artifactResults = resolver.resolve(dependencies);
Iterable<ArtifactResult> missingArtifacts = filterMissingArtifacts(artifactResults);
if (missingArtifacts.iterator().hasNext()) {
printMissingArtifactsToSysErr(missingArtifacts);
throw new RuntimeException("Some artifacts are not resolved");
}
System.out.println(JSONValue.toJSONString(transformArtifactResultToArtifactToPaths(artifactResults)));
System.out.flush();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.aether.graph.Dependency in project druid by druid-io.
the class PullDependencies method downloadExtension.
private void downloadExtension(Artifact versionedArtifact, File toLocation, Dependencies exclusions) {
final CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), (node, parents) -> {
String scope = node.getDependency().getScope();
if (scope != null) {
scope = StringUtils.toLowerCase(scope);
if ("provided".equals(scope)) {
return false;
}
if ("test".equals(scope)) {
return false;
}
if ("system".equals(scope)) {
return false;
}
}
if (exclusions.contain(node.getArtifact())) {
return false;
}
for (DependencyNode parent : parents) {
if (exclusions.contain(parent.getArtifact())) {
return false;
}
}
return true;
}));
try {
log.info("Start downloading extension [%s]", versionedArtifact);
final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
for (Artifact artifact : artifacts) {
if (exclusions.contain(artifact)) {
log.debug("Skipped Artifact[%s]", artifact);
} else {
log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
org.apache.commons.io.FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
}
}
} catch (Exception e) {
log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
throw new RuntimeException(e);
}
log.info("Finish downloading extension [%s]", versionedArtifact);
}
use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.
the class MavenResolverGrapeEngine method grab.
@Override
public Object grab(Map args, Map... dependencyMaps) {
List<Exclusion> exclusions = createExclusions(args);
List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
try {
List<File> files = resolve(dependencies);
GroovyClassLoader classLoader = getClassLoader(args);
for (File file : files) {
classLoader.addURL(file.toURI().toURL());
}
} catch (ArtifactResolutionException | MalformedURLException ex) {
throw new DependencyResolutionFailedException(ex);
}
return null;
}
use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.
the class DependencyResolutionContext method addDependencyManagement.
public void addDependencyManagement(DependencyManagement dependencyManagement) {
for (org.springframework.boot.cli.compiler.dependencies.Dependency dependency : dependencyManagement.getDependencies()) {
List<Exclusion> aetherExclusions = new ArrayList<>();
for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency.getExclusions()) {
aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*"));
}
Dependency aetherDependency = new Dependency(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "jar", dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions);
this.managedDependencies.add(0, aetherDependency);
this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), aetherDependency);
}
this.dependencyManagement = (this.dependencyManagement != null) ? new CompositeDependencyManagement(dependencyManagement, this.dependencyManagement) : dependencyManagement;
this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver(this.dependencyManagement);
}
use of org.eclipse.aether.graph.Dependency in project zeppelin by apache.
the class DependencyResolver method getArtifactsWithDep.
/**
* @param dependency
* @param excludes list of pattern can either be of the form groupId:artifactId
* @return
* @throws Exception
*/
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
Artifact artifact = new DefaultArtifact(dependency);
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
synchronized (repos) {
for (RemoteRepository repo : repos) {
collectRequest.addRepository(repo);
}
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
try {
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
} catch (NullPointerException | DependencyResolutionException ex) {
throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
}
}
Aggregations