From 26a1d2136feb5b7564176422ae2680a092b12f28 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 16 Jan 2024 14:31:23 +0100 Subject: [PATCH] Option to ignore p2 mirrors via the Maven settings and the new eclipse.p2.mirrors option Commit 7e6d595 has removed the option for tycho.disableP2Mirrors to use the settings.xml to disable the usage of p2 mirrors. See https://github.com/eclipse-tycho/tycho/wiki/Frequently-asked-questions#how-do-i-disable-p2-mirrors (cherry picked from commit 22a18fdd79e203b7d3e3d7dbf97ed9093f481814) --- ...ArtifactRepositoryManagerAgentFactory.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/RemoteArtifactRepositoryManagerAgentFactory.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/RemoteArtifactRepositoryManagerAgentFactory.java index 0f638c3ea4..a9f7f23c72 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/RemoteArtifactRepositoryManagerAgentFactory.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/RemoteArtifactRepositoryManagerAgentFactory.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.p2maven.transport; +import org.apache.maven.plugin.LegacySupport; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -34,6 +35,9 @@ public class RemoteArtifactRepositoryManagerAgentFactory implements IAgentServic @Requirement MavenAuthenticator authenticator; + @Requirement + protected LegacySupport mavenContext; + @Override public Object createService(IProvisioningAgent agent) { IArtifactRepositoryManager plainRepoManager = (IArtifactRepositoryManager) new ArtifactRepositoryComponent() @@ -45,14 +49,36 @@ public Object createService(IProvisioningAgent agent) { } private boolean getDisableP2MirrorsConfiguration() { - String key = "tycho.disableP2Mirrors"; - String value = System.getProperty(key); - if (value != null) { - logger.info("Using " + key + String deprecatedKey = "tycho.disableP2Mirrors"; + String deprecatedValue = getMirrorProperty(deprecatedKey); + + if (deprecatedValue != null) { + logger.info("Using " + deprecatedKey + " to disable P2 mirrors is deprecated, use the property eclipse.p2.mirrors instead, see https://tycho.eclipseprojects.io/doc/" + TychoVersion.getTychoVersion() + "/SystemProperties.html for details."); - return Boolean.parseBoolean(value); + return Boolean.parseBoolean(deprecatedValue); + } + + String key = "eclipse.p2.mirrors "; + String value = getMirrorProperty(key); + + if (value != null) { + // eclipse.p2.mirrors false -> disable mirrors + return !Boolean.parseBoolean(value); } return false; + + } + + private String getMirrorProperty(String key) { + String value = System.getProperty(key); + if (key == null && mavenContext.getSession() != null) { + key = mavenContext.getSession().getSystemProperties().getProperty(key); + + if (key == null) { + key = mavenContext.getSession().getUserProperties().getProperty(key); + } + } + return value; } }