use of org.eclipse.aether.artifact.DefaultArtifact in project atlasmap by atlasmap.
the class AbstractAtlasMapMojo method resolveClasspath.
/**
* Resolves the classpath.
* @param artifacts artifacts
* @return resolved
* @throws MojoFailureException unexpected error
*/
protected List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
final List<URL> urls = new ArrayList<>();
try {
for (String gav : artifacts) {
Artifact artifact = new DefaultArtifact(gav);
getLog().debug("Resolving dependencies for artifact: " + artifact);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.setRepositories(getRemoteRepos());
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
DependencyResult dependencyResult = getSystem().resolveDependencies(getRepoSession(), dependencyRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
dependencyResult.getRoot().accept(nlg);
Iterator<DependencyNode> it = nlg.getNodes().iterator();
while (it.hasNext()) {
DependencyNode node = it.next();
if (node.getDependency() != null) {
Artifact x = node.getDependency().getArtifact();
if (x.getFile() != null) {
getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
urls.add(x.getFile().toURI().toURL());
}
}
}
}
} catch (IllegalArgumentException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (DependencyResolutionException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (MalformedURLException e) {
throw new MojoFailureException(e.getMessage(), e);
}
return urls;
}
use of org.eclipse.aether.artifact.DefaultArtifact in project grails-maven by grails.
the class AbstractGrailsMojo method resolveArtifactIds.
protected Collection<File> resolveArtifactIds(Collection<String> artifactIds) throws MojoExecutionException {
Collection<ArtifactRequest> requests = new ArrayList<ArtifactRequest>();
for (String artifactId : artifactIds) {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(artifactId));
request.setRepositories(remoteRepos);
getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
requests.add(request);
}
Collection<File> files = new ArrayList<File>();
try {
List<ArtifactResult> result = repoSystem.resolveArtifacts(repoSession, requests);
for (ArtifactResult artifactResult : result) {
File file = artifactResult.getArtifact().getFile();
files.add(file);
getLog().debug("Resolved artifact " + artifactResult.getArtifact().getArtifactId() + " to " + file + " from " + artifactResult.getRepository());
}
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
return files;
}
use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.
the class MavenPluginLocation method iterateAllVersions.
public Iterator<MavenPluginVersion> iterateAllVersions() {
Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
try {
VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
List<Version> versions = rangeResult.getVersions();
if (!versions.isEmpty()) {
Iterator<Version> versionIterator = Lists.reverse(versions).iterator();
return Iterators.transform(versionIterator, new Function<Version, MavenPluginVersion>() {
@Override
public MavenPluginVersion apply(Version version) {
try {
MavenPluginVersion mavenPluginVersion = createMavenVersion(version);
return mavenPluginVersion;
} catch (ArtifactDescriptorException | ArtifactResolutionException | IOException | XmlPullParserException e) {
LOGGER.error("", e);
}
return null;
}
});
}
} catch (VersionRangeResolutionException e) {
LOGGER.error("", e);
}
return Collections.emptyIterator();
}
use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getLatestVersionString.
public String getLatestVersionString() {
Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST");
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(lastArt);
request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
return resolveArtifact.getArtifact().getVersion();
} catch (ArtifactResolutionException e1) {
e1.printStackTrace();
}
return null;
}
use of org.eclipse.aether.artifact.DefaultArtifact in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getVersionJar.
public Path getVersionJar(String version) throws ArtifactResolutionException {
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "jar", version.toString());
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(versionArtifact);
request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
return resolveArtifact.getArtifact().getFile().toPath();
}
Aggregations