Search in sources :

Example 41 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project swagger-core by swagger-api.

the class BetterAbstractMojoTestCase method newMavenSession.

protected MavenSession newMavenSession() {
    try {
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        MavenExecutionResult result = new DefaultMavenExecutionResult();
        // populate sensible defaults, including repository basedir and remote repos
        MavenExecutionRequestPopulator populator;
        populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
        populator.populateDefaults(request);
        // this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
        // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
        request.setSystemProperties(System.getProperties());
        // and this is needed so that the repo session in the maven session
        // has a repo manager, and it points at the local repo
        // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
        DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
        DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven.newRepositorySession(request);
        repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository(request.getLocalRepository().getBasedir())));
        @SuppressWarnings("deprecation") MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
        return session;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultMaven(org.apache.maven.DefaultMaven) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory)

Example 42 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project spf4j by zolyfarkas.

the class MavenRepositoryUtils method getRepositorySystemSession.

public static RepositorySystemSession getRepositorySystemSession(final RepositorySystem system, final File localRepoPath) {
    DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepository = new LocalRepository(localRepoPath);
    repositorySystemSession.setLocalRepositoryManager(system.newLocalRepositoryManager(repositorySystemSession, localRepository));
    repositorySystemSession.setRepositoryListener(new AbstractRepositoryListener() {

        @Override
        public void artifactDownloaded(final RepositoryEvent event) {
            LOG.info("Downloaded artifact {}", event);
        }
    });
    return repositorySystemSession;
}
Also used : AbstractRepositoryListener(org.eclipse.aether.AbstractRepositoryListener) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) RepositoryEvent(org.eclipse.aether.RepositoryEvent) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Aggregations

LocalRepository (org.eclipse.aether.repository.LocalRepository)42 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)34 File (java.io.File)15 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 RepositorySystem (org.eclipse.aether.RepositorySystem)6 JarFile (java.util.jar.JarFile)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 SimpleLocalRepositoryManagerFactory (org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory)5 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)5 MalformedURLException (java.net.MalformedURLException)4 LinkedList (java.util.LinkedList)4 Artifact (org.eclipse.aether.artifact.Artifact)4 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)4 URL (java.net.URL)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 VersionConstraint (org.eclipse.aether.version.VersionConstraint)3