use of org.sonatype.aether.resolution.ArtifactResult in project storm by apache.
the class DependencyResolverMain method main.
public static void main(String[] args) {
if (args.length < 1) {
throw new IllegalArgumentException("artifacts must be presented.");
}
String artifactsArg = args[0];
// DO NOT CHANGE THIS TO SYSOUT
System.err.println("DependencyResolver input - artifacts: " + artifactsArg);
List<Dependency> dependencies = parseArtifactArgs(artifactsArg);
List<RemoteRepository> repositories;
if (args.length > 1) {
String remoteRepositoryArg = args[1];
// DO NOT CHANGE THIS TO SYSOUT
System.err.println("DependencyResolver input - repositories: " + remoteRepositoryArg);
repositories = parseRemoteRepositoryArgs(remoteRepositoryArg);
} else {
repositories = Collections.emptyList();
}
try {
String localMavenRepoPath = getOrDefaultLocalMavenRepositoryPath("local-repo");
DependencyResolver resolver = new DependencyResolver(localMavenRepoPath, repositories);
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.sonatype.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.sonatype.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.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testResolveLocalArtifactSuccessful.
@Test
public void testResolveLocalArtifactSuccessful() throws IOException, ArtifactResolutionException {
File tmpFile = TestFileUtils.createTempFile("tmp");
Map<String, String> properties = new HashMap<String, String>();
properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
artifact = artifact.setProperties(properties);
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).setVersion(request.getArtifact().getVersion());
}
});
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
Aggregations