use of org.eclipse.aether.artifact.Artifact in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependenciesFromPom.
protected DependencyNode collectDependenciesFromPom(File rootPom, Model model, Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
Map<String, String> props = Collections.singletonMap(ArtifactProperties.LOCAL_PATH, rootPom.toString());
// lets load the model so we can get the version which is required for the transformer...
String groupId = model.getGroupId();
String artifactId = model.getArtifactId();
String pomVersion = model.getVersion();
String packaging = "pom";
if (groupId == null || artifactId == null || pomVersion == null) {
throw new IllegalArgumentException("Pomegranate pom.xml has missing groupId:artifactId:version " + groupId + ":" + artifactId + ":" + pomVersion);
}
Artifact root = new DefaultArtifact(groupId, artifactId, null, packaging, pomVersion, props, rootPom);
return collectDependencies(root, pomVersion, excludeDependencyFilter);
}
use of org.eclipse.aether.artifact.Artifact in project spf4j by zolyfarkas.
the class MavenRepositoryUtils method resolveArtifactAndDependencies.
public static Set<File> resolveArtifactAndDependencies(final String scope, final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr, final List<RemoteRepository> repos, final RepositorySystem repositorySystem, final RepositorySystemSession session) throws DependencyResolutionException {
Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, versionExpr);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, scope));
collectRequest.setRepositories(repos);
DependencyFilter dependencyFilter = DependencyFilterUtils.classpathFilter(scope);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, dependencyFilter);
DependencyResult depresult = repositorySystem.resolveDependencies(session, dependencyRequest);
List<ArtifactResult> artifactResults = depresult.getArtifactResults();
Set<File> result = Sets.newHashSetWithExpectedSize(artifactResults.size());
for (ArtifactResult ar : artifactResults) {
result.add(ar.getArtifact().getFile());
}
return result;
}
use of org.eclipse.aether.artifact.Artifact in project liferay-ide by liferay.
the class AetherUtil method getLatestAvailableArtifact.
public static Artifact getLatestAvailableArtifact(String gavCoords) {
Artifact retval = null;
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system);
String latestVersion = getLatestVersion(gavCoords, system, session);
String[] gav = gavCoords.split(":");
Artifact defaultArtifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":" + latestVersion);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(defaultArtifact);
artifactRequest.addRepository(newCentralRepository());
try {
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
retval = artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
LiferayMavenCore.logError("Unable to get latest Liferay archetype", e);
artifactRequest.setArtifact(new DefaultArtifact(gavCoords));
try {
retval = system.resolveArtifact(session, artifactRequest).getArtifact();
} catch (ArtifactResolutionException e1) {
LiferayMavenCore.logError("Unable to get default Liferay archetype", e1);
}
}
if (retval == null) {
retval = defaultArtifact;
}
return retval;
}
use of org.eclipse.aether.artifact.Artifact in project liferay-ide by liferay.
the class AetherUtil method getLatestVersion.
public static String getLatestVersion(String gavCoords, RepositorySystem system, RepositorySystemSession session) {
String retval = null;
String[] gav = gavCoords.split(":");
if ((gav == null) || (gav.length != 3)) {
throw new IllegalArgumentException("gavCoords should be group:artifactId:version");
}
Artifact artifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":[" + gav[2] + ",)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.addRepository(newCentralRepository());
try {
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
Version newestVersion = rangeResult.getHighestVersion();
List<Version> versions = rangeResult.getVersions();
if ((versions.size() > 1) && newestVersion.toString().endsWith("-SNAPSHOT")) {
retval = versions.get(versions.size() - 2).toString();
} else if (newestVersion != null) {
retval = newestVersion.toString();
}
} catch (VersionRangeResolutionException vrre) {
LiferayMavenCore.logError("Unable to get latest artifact version.", vrre);
}
if (retval == null) {
retval = gav[2];
}
return retval;
}
use of org.eclipse.aether.artifact.Artifact in project revapi by revapi.
the class ArtifactResolver method resolveNewestMatching.
/**
* Tries to find the newest version of the artifact that matches given regular expression.
* The found version will be older than the {@code upToVersion} or newest available if {@code upToVersion} is null.
*
* @param gav the coordinates of the artifact. The version part is ignored
* @param upToVersion the version up to which the versions will be matched
* @param versionMatcher the matcher to match the version
* @param remoteOnly true if only remotely available artifacts should be considered
* @param upToInclusive whether the {@code upToVersion} should be considered inclusive or exclusive
* @return the resolved artifact
* @throws VersionRangeResolutionException
*/
public Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher, boolean remoteOnly, boolean upToInclusive) throws VersionRangeResolutionException, ArtifactResolutionException {
Artifact artifact = new DefaultArtifact(gav);
artifact = artifact.setVersion(upToVersion == null ? "[,)" : "[," + upToVersion + (upToInclusive ? "]" : ")"));
VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);
RepositorySystemSession session = remoteOnly ? makeRemoteOnly(this.session) : this.session;
VersionRangeResult result = repositorySystem.resolveVersionRange(session, rangeRequest);
List<Version> versions = new ArrayList<>(result.getVersions());
Collections.reverse(versions);
for (Version v : versions) {
if (versionMatcher.matcher(v.toString()).matches()) {
return resolveArtifact(artifact.setVersion(v.toString()), session);
}
}
throw new VersionRangeResolutionException(result) {
@Override
public String getMessage() {
return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '" + versionMatcher + "'. The versions found were: " + versions;
}
};
}
Aggregations