Search in sources :

Example 61 with DefaultArtifact

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());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 62 with DefaultArtifact

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());
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 63 with DefaultArtifact

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);
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 64 with DefaultArtifact

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;
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 65 with DefaultArtifact

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;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Version(org.eclipse.aether.version.Version) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)110 Artifact (org.eclipse.aether.artifact.Artifact)70 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)42 File (java.io.File)39 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)34 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)29 IOException (java.io.IOException)24 Dependency (org.eclipse.aether.graph.Dependency)23 ArrayList (java.util.ArrayList)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)13 CollectRequest (org.eclipse.aether.collection.CollectRequest)12 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)12 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)12 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)12 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)12 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)11 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)10 Version (org.eclipse.aether.version.Version)10 Model (org.apache.maven.model.Model)9 RepositorySystem (org.eclipse.aether.RepositorySystem)9