use of org.apache.maven.cli.transfer.BatchModeMavenTransferListener in project maven-plugin by jenkinsci.
the class RedeployPublisher method createEmbedder.
/**
* copy from MavenUtil but here we have to ignore localRepo path and setting as thoses paths comes
* from the remote node and can not exist in controller see https://issues.jenkins.io/browse/JENKINS-8711
*/
private MavenEmbedder createEmbedder(TaskListener listener, AbstractBuild<?, ?> build) throws MavenEmbedderException, IOException, InterruptedException {
MavenInstallation m = null;
File settingsLoc = null, remoteGlobalSettingsFromConfig = null;
String profiles = null;
Properties systemProperties = null;
String privateRepository = null;
File tmpSettings = File.createTempFile("jenkins", "temp-settings.xml");
File tmpSettingsGlobal = File.createTempFile("jenkins", "temp-global-settings.xml");
try {
AbstractProject project = build.getProject();
// NOTE: Do not use instanceof to not have a dependency to the promotion plugin
if ("hudson.plugins.promoted_builds.PromotionProcess".equals(project.getClass().getName())) {
project = project.getRootProject();
}
if (project instanceof MavenModuleSet) {
MavenModuleSet mavenModuleSet = ((MavenModuleSet) project);
profiles = mavenModuleSet.getProfiles();
systemProperties = mavenModuleSet.getMavenProperties();
// olamy see
// we have to take about the settings use for the project
// order tru configuration
// TODO maybe in goals with -s,--settings last wins but not done in during pom parsing
// or -Dmaven.repo.local
// if not we must get ~/.m2/settings.xml then $M2_HOME/conf/settings.xml
// TODO check if the remoteSettings has a localRepository configured and disabled it
String altSettingsPath = SettingsProvider.getSettingsRemotePath(((MavenModuleSet) project).getSettings(), build, listener);
Node buildNode = build.getBuiltOn();
if (buildNode == null) {
// assume that build was made on the built-in node
buildNode = Jenkins.get();
}
if (StringUtils.isBlank(altSettingsPath)) {
// get userHome from the node where job has been executed
String remoteUserHome = build.getWorkspace().act(new GetUserHome());
altSettingsPath = remoteUserHome + "/.m2/settings.xml";
}
// we copy this file in the controller in a temporary file
FilePath filePath = new FilePath(tmpSettings);
FilePath remoteSettings = build.getWorkspace().child(altSettingsPath);
if (!remoteSettings.exists()) {
// JENKINS-9084 we finally use $M2_HOME/conf/settings.xml as maven does
String mavenHome = ((MavenModuleSet) project).getMaven().forNode(buildNode, listener).getHome();
String settingsPath = mavenHome + "/conf/settings.xml";
remoteSettings = build.getWorkspace().child(settingsPath);
}
listener.getLogger().println("Maven RedeployPublisher use remote " + (buildNode != null ? buildNode.getNodeName() : "local") + " maven settings from : " + remoteSettings.getRemote());
remoteSettings.copyTo(filePath);
settingsLoc = tmpSettings;
String remoteGlobalSettingsPath = GlobalSettingsProvider.getSettingsRemotePath(((MavenModuleSet) project).getGlobalSettings(), build, listener);
if (remoteGlobalSettingsPath != null) {
// copy global settings from agent's remoteGlobalSettingsPath to tmpSettingsGlobal
FilePath filePathGlobal = new FilePath(tmpSettingsGlobal);
FilePath remoteSettingsGlobal = build.getWorkspace().child(remoteGlobalSettingsPath);
listener.getLogger().println("Maven RedeployPublisher use remote " + (buildNode != null ? buildNode.getNodeName() : "local") + " maven global settings from : " + remoteSettingsGlobal.getRemote());
remoteSettingsGlobal.copyTo(filePathGlobal);
remoteGlobalSettingsFromConfig = tmpSettingsGlobal;
}
}
MavenEmbedderRequest mavenEmbedderRequest = new MavenEmbedderRequest(listener, m != null ? m.getHomeDir() : null, profiles, systemProperties, privateRepository, settingsLoc);
if (remoteGlobalSettingsFromConfig != null) {
mavenEmbedderRequest.setGlobalSettings(remoteGlobalSettingsFromConfig);
}
mavenEmbedderRequest.setTransferListener(new BatchModeMavenTransferListener(listener.getLogger()));
return MavenUtil.createEmbedder(mavenEmbedderRequest);
} finally {
if (tmpSettings != null) {
tmpSettings.delete();
}
if (tmpSettingsGlobal != null) {
tmpSettingsGlobal.delete();
}
}
}
use of org.apache.maven.cli.transfer.BatchModeMavenTransferListener 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