Search in sources :

Example 11 with DefaultRepositorySystemSession

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

the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method assertSessionCustomization.

private void assertSessionCustomization(String userHome) {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    SystemProperties.doWithSystemProperties(new Runnable() {

        @Override
        public void run() {
            new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session, SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
        }
    }, "user.home:" + userHome);
    RemoteRepository repository = new RemoteRepository.Builder("my-server", "default", "http://maven.example.com").build();
    assertMirrorSelectorConfiguration(session, repository);
    assertProxySelectorConfiguration(session, repository);
    assertAuthenticationSelectorConfiguration(session, repository);
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 12 with DefaultRepositorySystemSession

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

the class AetherGrapeEngineFactory method create.

public static AetherGrapeEngine create(GroovyClassLoader classLoader, List<RepositoryConfiguration> repositoryConfigurations, DependencyResolutionContext dependencyResolutionContext) {
    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);
    return new AetherGrapeEngine(classLoader, repositorySystem, repositorySystemSession, createRepositories(repositoryConfigurations), dependencyResolutionContext);
}
Also used : DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession)

Example 13 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project pinpoint by naver.

the class DependencyResolver method newRepositorySystemSession.

private static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    String localRepositoryPath = resolveLocalRepository();
    logger.info("Local repository: " + localRepositoryPath);
    LocalRepository localRepository = new LocalRepository(localRepositoryPath);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository));
    return session;
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Example 14 with DefaultRepositorySystemSession

use of org.eclipse.aether.DefaultRepositorySystemSession in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method doResolveProject.

@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
    final File file = files.size() == 1 ? files.iterator().next() : null;
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
    final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
    executeWithMavenSession(request, new Runnable() {

        @Override
        public void run() {
            try {
                RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) repositorySession;
                    session.setTransferListener(new TransferListenerAdapter(myCurrentIndicator));
                    if (myWorkspaceMap != null) {
                        session.setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
                    }
                    session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
                    session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
                }
                List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
                for (ProjectBuildingResult buildingResult : buildingResults) {
                    MavenProject project = buildingResult.getProject();
                    if (project == null) {
                        List<Exception> exceptions = new ArrayList<Exception>();
                        for (ModelProblem problem : buildingResult.getProblems()) {
                            exceptions.add(problem.getException());
                        }
                        MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
                        executionResults.add(mavenExecutionResult);
                        continue;
                    }
                    List<Exception> exceptions = new ArrayList<Exception>();
                    loadExtensions(project, exceptions);
                    //Artifact projectArtifact = project.getArtifact();
                    //Map managedVersions = project.getManagedVersionMap();
                    //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                    project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                        addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
                    } else {
                        final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
                        final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
                        final Map<Dependency, Artifact> winnerDependencyMap = new IdentityHashMap<Dependency, Artifact>();
                        Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                        dependencyResolutionResult.getDependencyGraph().accept(new TreeDependencyVisitor(new DependencyVisitor() {

                            @Override
                            public boolean visitEnter(org.eclipse.aether.graph.DependencyNode node) {
                                final Object winner = node.getData().get(ConflictResolver.NODE_DATA_WINNER);
                                final Dependency dependency = node.getDependency();
                                if (dependency != null && winner == null) {
                                    Artifact winnerArtifact = Maven3AetherModelConverter.toArtifact(dependency);
                                    winnerDependencyMap.put(dependency, winnerArtifact);
                                }
                                return true;
                            }

                            @Override
                            public boolean visitLeave(org.eclipse.aether.graph.DependencyNode node) {
                                return true;
                            }
                        }));
                        for (Dependency dependency : dependencies) {
                            final Artifact artifact = winnerDependencyMap.get(dependency);
                            if (artifact != null) {
                                artifacts.add(artifact);
                                resolveAsModule(artifact);
                            }
                        }
                        project.setArtifacts(artifacts);
                        executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                    }
                }
            } catch (Exception e) {
                executionResults.add(handleException(e));
            }
        }
    });
    return executionResults;
}
Also used : THashSet(gnu.trove.THashSet) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) ModelProblem(org.apache.maven.model.building.ModelProblem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) Dependency(org.eclipse.aether.graph.Dependency) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Artifact(org.apache.maven.artifact.Artifact) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) File(java.io.File) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DefaultRepositorySystemSession

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

the class AetherRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    DigestInputStream digestStream = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
    final File tmpFile = IO.createTempFile(cacheDir, "put", ".bnd");
    try {
        IO.copy(digestStream, tmpFile);
        byte[] digest = digestStream.getMessageDigest().digest();
        if (options.digest != null && !Arrays.equals(options.digest, digest))
            throw new IOException("Retrieved artifact digest doesn't match specified digest");
        // Get basic info about the bundle we're deploying
        Jar jar = new Jar(tmpFile);
        Artifact artifact = ConversionUtils.fromBundleJar(jar);
        artifact = artifact.setFile(tmpFile);
        // Setup the Aether repo session and create the deployment request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        final DeployRequest request = new DeployRequest();
        request.addArtifact(artifact);
        request.setRepository(remoteRepo);
        // Capture the result including remote resource URI
        final ResultHolder resultHolder = new ResultHolder();
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferSucceeded(TransferEvent event) {
                TransferResource resource = event.getResource();
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(resource.getFile())) {
                    PutResult result = new PutResult();
                    result.artifact = URI.create(resource.getRepositoryUrl() + resource.getResourceName());
                    resultHolder.result = result;
                    System.out.println("UPLOADED to: " + URI.create(resource.getRepositoryUrl() + resource.getResourceName()));
                }
            }

            @Override
            public void transferFailed(TransferEvent event) {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }

            @Override
            public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }
        });
        // Do the deploy and report results
        repoSystem.deploy(session, request);
        if (resultHolder.result != null) {
            if (indexedRepo != null)
                indexedRepo.reset();
            return resultHolder.result;
        } else if (resultHolder.error != null) {
            throw new Exception("Error during artifact upload", resultHolder.error);
        } else {
            throw new Exception("Artifact was not uploaded");
        }
    } finally {
        if (tmpFile != null && tmpFile.isFile())
            IO.delete(tmpFile);
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) DeployRequest(org.eclipse.aether.deployment.DeployRequest) AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) TransferResource(org.eclipse.aether.transfer.TransferResource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Aggregations

DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)18 File (java.io.File)7 LocalRepository (org.eclipse.aether.repository.LocalRepository)6 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 Artifact (org.eclipse.aether.artifact.Artifact)5 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 RepositorySystem (org.eclipse.aether.RepositorySystem)4 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 IOException (java.io.IOException)3 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 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2