Search in sources :

Example 26 with DefaultArtifact

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

Example 27 with DefaultArtifact

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;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) TreeSet(java.util.TreeSet) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 28 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 29 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)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)29 Artifact (org.eclipse.aether.artifact.Artifact)13 File (java.io.File)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 IOException (java.io.IOException)5 Dependency (org.eclipse.aether.graph.Dependency)5 Path (java.nio.file.Path)4 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)4 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)4 Test (org.junit.Test)4 MavenVersion (aQute.bnd.version.MavenVersion)3 Rule (com.google.devtools.build.workspace.maven.Rule)3 ArrayList (java.util.ArrayList)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 CollectRequest (org.eclipse.aether.collection.CollectRequest)3 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)3 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)3 Version (org.eclipse.aether.version.Version)3