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());
}
use of org.eclipse.aether.artifact.DefaultArtifact 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.DefaultArtifact 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.DefaultArtifact 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;
}
Aggregations