use of org.eclipse.aether.artifact.DefaultArtifact in project karaf by apache.
the class Dependency31Helper method pathFromAether.
@Override
public String pathFromAether(String name) throws MojoExecutionException {
DefaultArtifact artifact = new DefaultArtifact(name);
org.apache.maven.artifact.Artifact mavenArtifact = toArtifact(artifact);
return MavenUtil.layout.pathOf(mavenArtifact);
}
use of org.eclipse.aether.artifact.DefaultArtifact in project bnd by bndtools.
the class AetherRepository method versions.
@Override
public SortedSet<Version> versions(String bsn) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.versions(ConversionUtils.maybeMavenCoordsToBsn(bsn));
Artifact artifact = null;
try {
artifact = new DefaultArtifact(bsn + ":[0,)");
} catch (Exception e) {
// ignore non-GAV style dependencies
}
if (artifact == null)
return null;
// Setup the Aether repo session and create the range request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(Collections.singletonList(remoteRepo));
// Resolve the range
VersionRangeResult rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
// Add to the result
SortedSet<Version> versions = new TreeSet<Version>();
for (org.eclipse.aether.version.Version version : rangeResult.getVersions()) {
try {
versions.add(MavenVersion.parseString(version.toString()).getOSGiVersion());
} catch (IllegalArgumentException e) {
// ignore version
}
}
return versions;
}
use of org.eclipse.aether.artifact.DefaultArtifact in project bnd by bndtools.
the class ConversionUtils method fromBundleJar.
public static final Artifact fromBundleJar(Jar jar) throws Exception {
String groupId;
String artifactId;
String bsn = jar.getBsn();
groupId = jar.getManifest().getMainAttributes().getValue("Maven-GroupId");
if (groupId != null) {
String groupPrefix = groupId + ".";
if (bsn.startsWith(groupPrefix)) {
if (bsn.length() <= groupPrefix.length())
throw new IllegalArgumentException("Artifact ID appears to be empty");
artifactId = bsn.substring(groupPrefix.length());
} else {
artifactId = bsn;
}
} else {
int lastDot = bsn.lastIndexOf('.');
if (lastDot < 0)
throw new IllegalArgumentException(String.format("Cannot split symbolic name '%s' into group ID and artifact ID", bsn));
if (lastDot == 0)
throw new IllegalArgumentException("Group ID appears to be empty");
if (lastDot >= bsn.length() - 1)
throw new IllegalArgumentException("Artifact ID appear to be empty");
groupId = bsn.substring(0, lastDot);
artifactId = bsn.substring(lastDot + 1);
}
String versionString = jar.getVersion();
if (versionString == null)
versionString = "0";
else if (!Verifier.isVersion(versionString))
throw new IllegalArgumentException("Invalid version " + versionString);
Version version = Version.parseVersion(versionString);
return new DefaultArtifact(groupId, artifactId, JAR_EXTENSION, new MavenVersion(version).toString());
}
use of org.eclipse.aether.artifact.DefaultArtifact in project bnd by bndtools.
the class BaselineMojo method searchForBaseVersion.
private void searchForBaseVersion(Artifact artifact, List<RemoteRepository> aetherRepos) throws VersionRangeResolutionException {
logger.info("Automatically determining the baseline version for {} using repositories {}", artifact, aetherRepos);
Artifact toFind = new DefaultArtifact(base.getGroupId(), base.getArtifactId(), base.getClassifier(), base.getExtension(), base.getVersion());
Artifact toCheck = toFind.setVersion("(," + artifact.getVersion() + ")");
VersionRangeRequest request = new VersionRangeRequest(toCheck, aetherRepos, "baseline");
VersionRangeResult versions = system.resolveVersionRange(session, request);
logger.debug("Found versions {}", versions.getVersions());
base.setVersion(versions.getHighestVersion() != null ? versions.getHighestVersion().toString() : null);
logger.info("The baseline version was found to be {}", base.getVersion());
}
Aggregations