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");
}
Aggregations