Search in sources :

Example 1 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project spring-boot by spring-projects.

the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method propertyInterpolation.

@Test
public void propertyInterpolation() throws SettingsBuildingException {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    given(this.repositorySystem.newLocalRepositoryManager(eq(session), any(LocalRepository.class))).willAnswer(new Answer<LocalRepositoryManager>() {

        @Override
        public LocalRepositoryManager answer(InvocationOnMock invocation) throws Throwable {
            LocalRepository localRepository = invocation.getArgument(1);
            return new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepository);
        }
    });
    SystemProperties.doWithSystemProperties(new Runnable() {

        @Override
        public void run() {
            new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session, SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
        }
    }, "user.home:src/test/resources/maven-settings/property-interpolation", "foo:bar");
    assertThat(session.getLocalRepository().getBasedir().getAbsolutePath()).endsWith(File.separatorChar + "bar" + File.separatorChar + "repository");
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LocalRepository(org.eclipse.aether.repository.LocalRepository) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) Test(org.junit.Test)

Example 2 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project spring-boot by spring-projects.

the class ModifiedClassPathRunner method resolveCoordinates.

private List<URL> resolveCoordinates(String[] coordinates) throws Exception {
    DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
    serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
    session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
    CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2").build()));
    collectRequest.setDependencies(createDependencies(coordinates));
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
    DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
    List<URL> resolvedArtifacts = new ArrayList<URL>();
    for (ArtifactResult artifact : result.getArtifactResults()) {
        resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
    }
    return resolvedArtifacts;
}
Also used : DependencyResult(org.eclipse.aether.resolution.DependencyResult) LocalRepository(org.eclipse.aether.repository.LocalRepository) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) CollectRequest(org.eclipse.aether.collection.CollectRequest) URL(java.net.URL) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest)

Example 3 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project bazel by bazelbuild.

the class MavenConnector method newRepositorySystemSession.

public RepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(localRepositoryPath);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    session.setTransferListener(new AbstractTransferListener() {
    });
    session.setRepositoryListener(new AbstractRepositoryListener() {
    });
    return session;
}
Also used : AbstractRepositoryListener(org.eclipse.aether.AbstractRepositoryListener) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Example 4 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project karaf by apache.

the class Dependency31Helper method getDependencyTree.

private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
    try {
        CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
        DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
        session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
        // between aether-util 0.9.0.M1 and M2, JavaEffectiveScopeCalculator was removed
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=397241
        DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), new JavaDependencyContextRefiner());
        session.setDependencyGraphTransformer(transformer);
        CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
        return result.getRoot();
    } catch (DependencyCollectionException e) {
        throw new MojoExecutionException("Cannot build project dependency tree", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) Dependency(org.eclipse.aether.graph.Dependency) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Example 5 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project bnd by bndtools.

the class AetherRepository method get.

@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
    init();
    // Use the index by preference
    if (indexedRepo != null)
        return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
    File file = null;
    boolean getSource = false;
    try {
        // Setup the Aether repo session and request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        if (bsn.endsWith(".source")) {
            String originalBsn = properties.get("bsn");
            if (originalBsn != null) {
                bsn = originalBsn;
                getSource = true;
            }
        }
        String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
        MavenVersion mvnVersion = new MavenVersion(version);
        String versionStr = null;
        if ("exact".equals(properties.get("strategy")) || getSource) {
            versionStr = properties.get("version");
        } else {
            versionStr = mvnVersion.toString();
        }
        Artifact artifact = null;
        if (getSource) {
            artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
        } else {
            artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
        }
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(artifact);
        request.setRepositories(Collections.singletonList(remoteRepo));
        // Log the transfer
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferStarted(TransferEvent event) throws TransferCancelledException {
                System.err.println(event);
            }

            @Override
            public void transferSucceeded(TransferEvent event) {
                System.err.println(event);
            }

            @Override
            public void transferFailed(TransferEvent event) {
                System.err.println(event);
            }
        });
        try {
            // Resolve the version
            ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
            artifact = artifactResult.getArtifact();
            file = artifact.getFile();
        } catch (ArtifactResolutionException ex) {
        // could not download artifact, simply return null
        }
        return file;
    } finally {
        for (DownloadListener dl : listeners) {
            if (file != null)
                dl.success(file);
            else
                dl.failure(null, "Download failed");
        }
    }
}
Also used : AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenVersion(aQute.bnd.version.MavenVersion) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)17 File (java.io.File)6 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 Artifact (org.eclipse.aether.artifact.Artifact)5 LocalRepository (org.eclipse.aether.repository.LocalRepository)5 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 RepositorySystem (org.eclipse.aether.RepositorySystem)4 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 DeployRequest (org.eclipse.aether.deployment.DeployRequest)3 Dependency (org.eclipse.aether.graph.Dependency)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 TransferCancelledException (org.eclipse.aether.transfer.TransferCancelledException)3 MavenVersion (aQute.bnd.version.MavenVersion)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)2