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"));
}
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;
}
}
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);
}
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);
}
}
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;
}
Aggregations