Search in sources :

Example 71 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project karaf by apache.

the class DependencyHelperFactory method createDependencyHelper.

/**
     * <p>Create a new {@link DependencyHelper} based on what has been found in {@link org.codehaus.plexus.PlexusContainer}</p>
     *
     * <p>{@code karaf-maven-plugin} depends on {@code maven-core:3.0}, so for Maven 3.0.x, it may use this API directly.
     * When using Maven 3.1.x/3.2.x, it should use reflection to invoke org.apache.maven.RepositoryUtils.toArtifact(Artifact)
     * as this method directly references specific Aether implementation.</p>
     *
     * <p>When {@code karaf-maven-plugin} switches to {@code maven-core:3.1.0+}, reflection should be use for Sonatype variant of Aether.</p>
     *
     * @param container The Maven Plexus container to use.
     * @param mavenProject The Maven project to use.
     * @param mavenSession The Maven session.
     * @param log The log to use for the messages.
     * @return The {@link DependencyHelper} depending of the Maven version used.
     * @throws MojoExecutionException If the plugin execution fails.
     */
public static DependencyHelper createDependencyHelper(PlexusContainer container, MavenProject mavenProject, MavenSession mavenSession, Log log) throws MojoExecutionException {
    try {
        if (container.hasComponent("org.sonatype.aether.RepositorySystem")) {
            org.sonatype.aether.RepositorySystem system = container.lookup(org.sonatype.aether.RepositorySystem.class);
            org.sonatype.aether.RepositorySystemSession session = mavenSession.getRepositorySession();
            List<RemoteRepository> repositories = mavenProject.getRemoteProjectRepositories();
            return new Dependency30Helper(repositories, session, system);
        } else if (container.hasComponent("org.eclipse.aether.RepositorySystem")) {
            org.eclipse.aether.RepositorySystem system = container.lookup(org.eclipse.aether.RepositorySystem.class);
            Object session;
            try {
                session = MavenSession.class.getMethod("getRepositorySession").invoke(mavenSession);
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            List<?> repositories = mavenProject.getRemoteProjectRepositories();
            return new Dependency31Helper(repositories, session, system);
        }
    } catch (ComponentLookupException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    throw new MojoExecutionException("Cannot locate either org.sonatype.aether.RepositorySystem or org.eclipse.aether.RepositorySystem");
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenSession(org.apache.maven.execution.MavenSession) List(java.util.List)

Aggregations

RemoteRepository (org.sonatype.aether.repository.RemoteRepository)71 Artifact (org.sonatype.aether.artifact.Artifact)30 Test (org.junit.Test)27 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)18 File (java.io.File)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)15 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)13 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)13 Dependency (org.sonatype.aether.graph.Dependency)12 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)12 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)11 CollectRequest (org.sonatype.aether.collection.CollectRequest)10 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)10 ArrayList (java.util.ArrayList)8 RepositorySystem (org.sonatype.aether.RepositorySystem)8 IOException (java.io.IOException)7 Before (org.junit.Before)7 Metadata (org.sonatype.aether.metadata.Metadata)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7