public static AetherGrapeEngine create( GroovyClassLoader classLoader, List<RepositoryConfiguration> repositoryConfigurations) { RepositorySystem repositorySystem = createServiceLocator().getService(RepositorySystem.class); DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils.newSession(); ServiceLoader<RepositorySystemSessionAutoConfiguration> autoConfigurations = ServiceLoader.load(RepositorySystemSessionAutoConfiguration.class); for (RepositorySystemSessionAutoConfiguration autoConfiguration : autoConfigurations) { autoConfiguration.apply(repositorySystemSession, repositorySystem); } new DefaultRepositorySystemSessionAutoConfiguration() .apply(repositorySystemSession, repositorySystem); List<Dependency> managedDependencies = new ManagedDependenciesFactory().getManagedDependencies(); return new AetherGrapeEngine( classLoader, repositorySystem, repositorySystemSession, createRepositories(repositoryConfigurations), managedDependencies); }
private RepositorySystem newRepositorySystem() { DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); locator.addService(TransporterFactory.class, FileTransporterFactory.class); locator.addService(TransporterFactory.class, HttpTransporterFactory.class); return locator.getService(RepositorySystem.class); }
private RepositorySystemSession newSession(RepositorySystem system) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository(localRepoPath); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); return session; }
/** * Attempts to resolve an {@link Artifact} to a {@link File}. * * @param artifact to resolve * @return a {@link File} to the resolved artifact, never <code>null</code>. * @throws MojoExecutionException if the artifact could not be resolved. */ protected File resolveArtifactToFile(Artifact artifact) throws MojoExecutionException { Artifact resolvedArtifact = null; if (container.hasComponent("org.sonatype.aether.RepositorySystem")) { org.sonatype.aether.RepositorySystem system; try { system = container.lookup(org.sonatype.aether.RepositorySystem.class); } catch (ComponentLookupException e) { throw new MojoExecutionException(e.getMessage()); } org.sonatype.aether.RepositorySystemSession repositorySession = session.getRepositorySession(); List<org.sonatype.aether.repository.RemoteRepository> remoteProjectRepositories = project.getRemoteProjectRepositories(); resolvedArtifact = AetherHelper.resolveArtifact( artifact, system, repositorySession, remoteProjectRepositories); } else if (container.hasComponent("org.eclipse.aether.RepositorySystem")) { org.eclipse.aether.RepositorySystem system; try { system = container.lookup(org.eclipse.aether.RepositorySystem.class); } catch (ComponentLookupException e) { throw new MojoExecutionException(e.getMessage()); } org.eclipse.aether.DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); org.eclipse.aether.repository.LocalRepository localRepo = new org.eclipse.aether.repository.LocalRepository(Utility.getLocalRepoPath()); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); List<?> repositories = project.getRemoteProjectRepositories(); resolvedArtifact = EclipseAetherHelper.resolveArtifact(artifact, system, session, repositories); } final File jar = resolvedArtifact.getFile(); if (jar == null) { throw new MojoExecutionException( "Could not resolve artifact " + artifact.getId() + ". Please install it with \"mvn install:install-file ...\" or deploy it to a repository " + "with \"mvn deploy:deploy-file ...\""); } return jar; }
private RepositorySystemSession newRepositorySystemSession() { if (this.session != null) { return this.session; } DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository(mavenSettings.getLocalRepository().toString()); session.setLocalRepositoryManager( REPOSITORY_SYSTEM.newLocalRepositoryManager(session, localRepo)); // Copy these from the aether demo if they are nice to have session.setTransferListener(new ConsoleTransferListener()); session.setRepositoryListener(new ConsoleRepositoryListener()); session.setTransferListener( new AbstractTransferListener() { @Override public void transferFailed(TransferEvent event) { super.transferFailed(event); } }); this.session = session; return session; }