use of org.eclipse.aether.resolution.ArtifactResult 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.resolution.ArtifactResult in project activemq-artemis by apache.
the class ArtemisAbstractPlugin method resolveArtifact.
protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(remoteRepos);
ArtifactResult result;
try {
result = repositorySystem.resolveArtifact(repoSession, request);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
return result.getArtifact().getFile();
}
use of org.eclipse.aether.resolution.ArtifactResult in project storm by apache.
the class DependencyResolverTest method resolveValid.
@Test
public void resolveValid() throws Exception {
// please pick small artifact which has small transitive dependency
// and let's mark as Ignore if we want to run test even without internet or maven central is often not stable
Dependency dependency = new Dependency(new DefaultArtifact("org.apache.storm:flux-core:1.0.0"), JavaScopes.COMPILE);
List<ArtifactResult> results = sut.resolve(Lists.newArrayList(dependency));
assertTrue(results.size() > 0);
// it should be org.apache.storm:flux-core:jar:1.0.0 and commons-cli:commons-cli:jar:1.2
assertContains(results, "org.apache.storm", "flux-core", "1.0.0");
assertContains(results, "commons-cli", "commons-cli", "1.2");
}
use of org.eclipse.aether.resolution.ArtifactResult in project storm by apache.
the class DependencyResolverMain method transformArtifactResultToArtifactToPaths.
private static Map<String, String> transformArtifactResultToArtifactToPaths(List<ArtifactResult> artifactResults) {
Map<String, String> artifactToPath = new LinkedHashMap<>();
for (ArtifactResult artifactResult : artifactResults) {
Artifact artifact = artifactResult.getArtifact();
artifactToPath.put(AetherUtils.artifactToString(artifact), artifact.getFile().getAbsolutePath());
}
return artifactToPath;
}
use of org.eclipse.aether.resolution.ArtifactResult 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);
}
}
Aggregations