Search in sources :

Example 16 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class ConversionUtilsTest method testBsnMappingWithGroupIdNotPrefix.

public void testBsnMappingWithGroupIdNotPrefix() throws Exception {
    Jar jar = new Jar(IO.getFile("testdata/3.jar"));
    Artifact artifact = ConversionUtils.fromBundleJar(jar);
    assertEquals("com.paremus", artifact.getGroupId());
    assertEquals("org.bndtools.example.foo", artifact.getArtifactId());
}
Also used : Jar(aQute.bnd.osgi.Jar) Artifact(org.eclipse.aether.artifact.Artifact)

Example 17 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class ConversionUtilsTest method testBsnMappingWithGroupId.

public void testBsnMappingWithGroupId() throws Exception {
    Jar jar = new Jar(IO.getFile("testdata/2.jar"));
    Artifact artifact = ConversionUtils.fromBundleJar(jar);
    assertEquals("org.bndtools", artifact.getGroupId());
    assertEquals("example.foo", artifact.getArtifactId());
}
Also used : Jar(aQute.bnd.osgi.Jar) Artifact(org.eclipse.aether.artifact.Artifact)

Example 18 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class RemotePostProcessor method postProcessSnapshot.

private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
    for (RemoteRepository repository : request.getRepositories()) {
        if (!repository.getPolicy(true).isEnabled()) {
            // Skip the repo if it isn't enabled for snapshots
            continue;
        }
        // Remove the workspace from the session so that we don't use it
        DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
        newSession.setWorkspaceReader(null);
        // Find the snapshot metadata for the module
        MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
        for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
            if (metadataResult.isResolved()) {
                String version;
                try {
                    Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
                    Versioning versioning = read.getVersioning();
                    if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
                        continue;
                    } else {
                        version = versioning.getSnapshotVersions().get(0).getVersion();
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
                }
                Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
                try {
                    ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
                    if (result.isResolved()) {
                        File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
                        if (!toUse.exists()) {
                            logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
                            continue;
                        } else {
                            logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
                        }
                        result.getArtifact().setFile(toUse);
                        return result;
                    }
                } catch (ArtifactResolutionException e) {
                    logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
                }
            }
        }
    }
    logger.debug("Unable to resolve a remote repository containing {}", artifact);
    return null;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Artifact(org.eclipse.aether.artifact.Artifact) MetadataResult(org.eclipse.aether.resolution.MetadataResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MetadataRequest(org.eclipse.aether.resolution.MetadataRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File)

Example 19 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class RemotePostProcessor method postProcessResult.

@Override
public ArtifactResult postProcessResult(ArtifactResult resolvedArtifact) throws MojoExecutionException {
    if (localURLs == LocalURLs.REQUIRED) {
        // Skip the search as we will use the local file anyway
        return resolvedArtifact;
    }
    String repoId = resolvedArtifact.getRepository().getId();
    Artifact artifact = resolvedArtifact.getArtifact();
    if ("workspace".equals(repoId) || "local".equals(repoId)) {
        logger.debug("Post processing {} to determine a remote source", artifact);
        ArtifactResult postProcessed;
        if (artifact.isSnapshot()) {
            postProcessed = postProcessSnapshot(resolvedArtifact.getRequest(), artifact);
        } else {
            postProcessed = postProcessRelease(resolvedArtifact.getRequest(), artifact);
        }
        if (postProcessed != null) {
            return postProcessed;
        }
    }
    return resolvedArtifact;
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 20 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)30 File (java.io.File)11 Dependency (org.eclipse.aether.graph.Dependency)9 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)9 IOException (java.io.IOException)8 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArrayList (java.util.ArrayList)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)7 Path (java.nio.file.Path)6 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)6 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 STGroupString (org.stringtemplate.v4.STGroupString)5 Jar (aQute.bnd.osgi.Jar)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 List (java.util.List)4 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4