Search in sources :

Example 1 with DefaultRepositoryCache

use of org.eclipse.aether.DefaultRepositoryCache in project maven-resolver by apache.

the class HttpTransporterTest method testAuthSchemeReuse.

@Test
public void testAuthSchemeReuse() throws Exception {
    httpServer.setAuthentication("testuser", "testpass");
    httpServer.setProxyAuthentication("proxyuser", "proxypass");
    session.setCache(new DefaultRepositoryCache());
    auth = new AuthenticationBuilder().addUsername("testuser").addPassword("testpass").build();
    Authentication auth = new AuthenticationBuilder().addUsername("proxyuser").addPassword("proxypass").build();
    proxy = new Proxy(Proxy.TYPE_HTTP, httpServer.getHost(), httpServer.getHttpPort(), auth);
    newTransporter("http://bad.localhost:1/");
    GetTask task = new GetTask(URI.create("repo/file.txt"));
    transporter.get(task);
    assertEquals("test", task.getDataString());
    assertEquals(3, httpServer.getLogEntries().size());
    httpServer.getLogEntries().clear();
    newTransporter("http://bad.localhost:1/");
    task = new GetTask(URI.create("repo/file.txt"));
    transporter.get(task);
    assertEquals("test", task.getDataString());
    assertEquals(1, httpServer.getLogEntries().size());
    assertNotNull(httpServer.getLogEntries().get(0).headers.get("Authorization"));
    assertNotNull(httpServer.getLogEntries().get(0).headers.get("Proxy-Authorization"));
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) GetTask(org.eclipse.aether.spi.connector.transport.GetTask) Authentication(org.eclipse.aether.repository.Authentication) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) Test(org.junit.Test)

Example 2 with DefaultRepositoryCache

use of org.eclipse.aether.DefaultRepositoryCache in project maven by apache.

the class MavenCli method execute.

private int execute(CliRequest cliRequest) throws MavenExecutionRequestPopulationException {
    MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.request);
    if (cliRequest.request.getRepositoryCache() == null) {
        cliRequest.request.setRepositoryCache(new DefaultRepositoryCache());
    }
    eventSpyDispatcher.onEvent(request);
    MavenExecutionResult result = maven.execute(request);
    eventSpyDispatcher.onEvent(result);
    eventSpyDispatcher.close();
    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();
        Map<String, String> references = new LinkedHashMap<>();
        List<MavenProject> failedProjects = new ArrayList<>();
        for (Throwable exception : result.getExceptions()) {
            ExceptionSummary summary = handler.handleException(exception);
            logSummary(summary, references, "", cliRequest.showErrors);
            if (exception instanceof LifecycleExecutionException) {
                failedProjects.add(((LifecycleExecutionException) exception).getProject());
            }
        }
        slf4jLogger.error("");
        if (!cliRequest.showErrors) {
            slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the '{}' switch", buffer().strong("-e"));
        }
        if (!slf4jLogger.isDebugEnabled()) {
            slf4jLogger.error("Re-run Maven using the '{}' switch to enable verbose output", buffer().strong("-X"));
        }
        if (!references.isEmpty()) {
            slf4jLogger.error("");
            slf4jLogger.error("For more information about the errors and possible solutions" + ", please read the following articles:");
            for (Map.Entry<String, String> entry : references.entrySet()) {
                slf4jLogger.error("{} {}", buffer().strong(entry.getValue()), entry.getKey());
            }
        }
        if (result.canResume()) {
            logBuildResumeHint("mvn [args] -r");
        } else if (!failedProjects.isEmpty()) {
            List<MavenProject> sortedProjects = result.getTopologicallySortedProjects();
            // Sort the failedProjects list in the topologically sorted order.
            failedProjects.sort(comparing(sortedProjects::indexOf));
            MavenProject firstFailedProject = failedProjects.get(0);
            if (!firstFailedProject.equals(sortedProjects.get(0))) {
                String resumeFromSelector = getResumeFromSelector(sortedProjects, firstFailedProject);
                logBuildResumeHint("mvn [args] -rf " + resumeFromSelector);
            }
        }
        if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.request.getReactorFailureBehavior())) {
            slf4jLogger.info("Build failures were ignored.");
            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}
Also used : LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) LinkedHashMap(java.util.LinkedHashMap) DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) ExceptionHandler(org.apache.maven.exception.ExceptionHandler) ExceptionSummary(org.apache.maven.exception.ExceptionSummary) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) List(java.util.List) DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DefaultRepositoryCache

use of org.eclipse.aether.DefaultRepositoryCache in project maven by apache.

the class AbstractMavenProjectTestCase method initRepoSession.

protected void initRepoSession(ProjectBuildingRequest request) {
    File localRepo = new File(request.getLocalRepository().getBasedir());
    DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
    repoSession.setCache(new DefaultRepositoryCache());
    repoSession.setLocalRepositoryManager(new LegacyLocalRepositoryManager(localRepo));
    request.setRepositorySession(repoSession);
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache)

Example 4 with DefaultRepositoryCache

use of org.eclipse.aether.DefaultRepositoryCache in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckerRule method findProjectClasspath.

/**
 * Builds a class path for {@code mavenProject}.
 */
private static ClassPathResult findProjectClasspath(MavenProject mavenProject, RepositorySystemSession session, EnforcerRuleHelper helper) throws EnforcerRuleException {
    try {
        ProjectDependenciesResolver projectDependenciesResolver = helper.getComponent(ProjectDependenciesResolver.class);
        DefaultRepositorySystemSession fullDependencyResolutionSession = new DefaultRepositorySystemSession(session);
        // Clear artifact cache. Certain artifacts in the cache have dependencies without
        // ${os.detected.classifier} interpolated. They are instantiated before 'verify' phase:
        // https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/925
        fullDependencyResolutionSession.setCache(new DefaultRepositoryCache());
        // For netty-handler referencing its dependencies with ${os.detected.classifier}
        // allowing duplicate entries
        Map<String, String> properties = new HashMap<>();
        properties.putAll(fullDependencyResolutionSession.getSystemProperties());
        properties.putAll(OsProperties.detectOsProperties());
        fullDependencyResolutionSession.setSystemProperties(properties);
        fullDependencyResolutionSession.setDependencySelector(new AndDependencySelector(new NonTestDependencySelector(), new ExclusionDependencySelector(), new OptionalDependencySelector(), new FilteringZipDependencySelector()));
        DependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest(mavenProject, fullDependencyResolutionSession);
        DependencyResolutionResult resolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest);
        return buildClassPathResult(resolutionResult);
    } catch (ComponentLookupException e) {
        throw new EnforcerRuleException("Unable to lookup a component " + e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        return buildClasspathFromException(e);
    }
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) HashMap(java.util.HashMap) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) FilteringZipDependencySelector(com.google.cloud.tools.opensource.dependencies.FilteringZipDependencySelector) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) NonTestDependencySelector(com.google.cloud.tools.opensource.dependencies.NonTestDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Example 5 with DefaultRepositoryCache

use of org.eclipse.aether.DefaultRepositoryCache in project quarkus by quarkusio.

the class BootstrapMavenContext method newRepositorySystemSession.

private DefaultRepositorySystemSession newRepositorySystemSession() throws BootstrapMavenException {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    final Settings settings = getEffectiveSettings();
    final List<Mirror> mirrors = settings.getMirrors();
    if (mirrors != null && !mirrors.isEmpty()) {
        final boolean isBlockedMethodAvailable = mirrorIsBlockedMethodAvailable();
        final DefaultMirrorSelector ms = new DefaultMirrorSelector();
        for (Mirror m : mirrors) {
            if (isBlockedMethodAvailable) {
                ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.isBlocked(), m.getMirrorOf(), m.getMirrorOfLayouts());
            } else {
                // Maven pre-3.8.x
                ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.getMirrorOf(), m.getMirrorOfLayouts());
            }
        }
        session.setMirrorSelector(ms);
    }
    final String localRepoPath = getLocalRepo();
    session.setLocalRepositoryManager(getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(localRepoPath)));
    session.setOffline(isOffline());
    final BootstrapMavenOptions mvnArgs = getCliOptions();
    if (!mvnArgs.isEmpty()) {
        if (mvnArgs.hasOption(BootstrapMavenOptions.SUPRESS_SNAPSHOT_UPDATES)) {
            session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.UPDATE_SNAPSHOTS)) {
            session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
        }
        if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_FAILURE_POLICY)) {
            session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_WARNING_POLICY)) {
            session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
        }
    }
    final DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
    decrypt.setProxies(settings.getProxies());
    decrypt.setServers(settings.getServers());
    final SettingsDecryptionResult decrypted = new SettingsDecrypterImpl().decrypt(decrypt);
    if (!decrypted.getProblems().isEmpty() && log.isDebugEnabled()) {
        // this is how maven handles these
        for (SettingsProblem p : decrypted.getProblems()) {
            log.debug(p.getMessage(), p.getException());
        }
    }
    final DefaultProxySelector proxySelector = new DefaultProxySelector();
    for (org.apache.maven.settings.Proxy p : decrypted.getProxies()) {
        if (p.isActive()) {
            proxySelector.add(toAetherProxy(p), p.getNonProxyHosts());
        }
    }
    session.setProxySelector(proxySelector);
    final Map<Object, Object> configProps = new LinkedHashMap<>(session.getConfigProperties());
    configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
    configProps.put(ConfigurationProperties.INTERACTIVE, settings.isInteractiveMode());
    final DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
    for (Server server : decrypted.getServers()) {
        AuthenticationBuilder authBuilder = new AuthenticationBuilder();
        authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
        authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
        authSelector.add(server.getId(), authBuilder.build());
        if (server.getConfiguration() != null) {
            Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
            for (int i = dom.getChildCount() - 1; i >= 0; i--) {
                Xpp3Dom child = dom.getChild(i);
                if ("wagonProvider".equals(child.getName())) {
                    dom.removeChild(i);
                }
            }
            XmlPlexusConfiguration config = new XmlPlexusConfiguration(dom);
            configProps.put("aether.connector.wagon.config." + server.getId(), config);
        }
        configProps.put("aether.connector.perms.fileMode." + server.getId(), server.getFilePermissions());
        configProps.put("aether.connector.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
    }
    session.setAuthenticationSelector(authSelector);
    session.setConfigProperties(configProps);
    if (session.getCache() == null) {
        session.setCache(new DefaultRepositoryCache());
    }
    if (workspace != null) {
        session.setWorkspaceReader(workspace);
    }
    if (session.getTransferListener() == null && artifactTransferLogging) {
        TransferListener transferListener;
        if (mvnArgs.hasOption(BootstrapMavenOptions.NO_TRANSFER_PROGRESS)) {
            transferListener = new QuietMavenTransferListener();
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.BATCH_MODE)) {
            transferListener = new BatchModeMavenTransferListener(System.out);
        } else {
            transferListener = new ConsoleMavenTransferListener(System.out, true);
        }
        session.setTransferListener(transferListener);
    }
    return session;
}
Also used : ConsoleMavenTransferListener(org.apache.maven.cli.transfer.ConsoleMavenTransferListener) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener) TransferListener(org.eclipse.aether.transfer.TransferListener) BatchModeMavenTransferListener(org.apache.maven.cli.transfer.BatchModeMavenTransferListener) Server(org.apache.maven.settings.Server) DefaultProxySelector(org.eclipse.aether.util.repository.DefaultProxySelector) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) LinkedHashMap(java.util.LinkedHashMap) BatchModeMavenTransferListener(org.apache.maven.cli.transfer.BatchModeMavenTransferListener) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultAuthenticationSelector(org.eclipse.aether.util.repository.DefaultAuthenticationSelector) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener) Settings(org.apache.maven.settings.Settings) ConsoleMavenTransferListener(org.apache.maven.cli.transfer.ConsoleMavenTransferListener) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultMirrorSelector(org.eclipse.aether.util.repository.DefaultMirrorSelector) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Mirror(org.apache.maven.settings.Mirror) BootstrapMavenOptions(io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions)

Aggregations

DefaultRepositoryCache (org.eclipse.aether.DefaultRepositoryCache)8 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)5 File (java.io.File)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Settings (org.apache.maven.settings.Settings)2 LocalRepository (org.eclipse.aether.repository.LocalRepository)2 GetTask (org.eclipse.aether.spi.connector.transport.GetTask)2 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)2 Test (org.junit.Test)2 FilteringZipDependencySelector (com.google.cloud.tools.opensource.dependencies.FilteringZipDependencySelector)1 NonTestDependencySelector (com.google.cloud.tools.opensource.dependencies.NonTestDependencySelector)1 Profile (com.oracle.bedrock.runtime.Profile)1 PlatformSeparators (com.oracle.bedrock.runtime.options.PlatformSeparators)1 BootstrapMavenOptions (io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConnPoolControl (org.apache.http.pool.ConnPoolControl)1 PoolStats (org.apache.http.pool.PoolStats)1