From 2f81c3bc9e54c4104973c59f9cb3f96977c400c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 10 Dec 2023 05:24:13 +0100 Subject: [PATCH] Fixup Director Mojo when used as a plugin in pom.xml --- .../p2tools/TychoDirectorApplication.java | 32 +++++++++++++++++++ ...FeatureRootfileArtifactRepositoryTest.java | 3 +- .../resources/META-INF/maven/extension.xml | 2 ++ .../plugins/p2/director/DirectorMojo.java | 22 +++++++------ 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoDirectorApplication.java diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoDirectorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoDirectorApplication.java new file mode 100644 index 0000000000..459b414759 --- /dev/null +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoDirectorApplication.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2023 Christoph Läubrich and others. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christoph Läubrich - initial API and implementation + *******************************************************************************/ +package org.eclipse.tycho.p2tools; + +import org.eclipse.equinox.internal.p2.director.app.DirectorApplication; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.IProvisioningAgentProvider; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; + +/** + * Enhances the P2 {@link DirectorApplication} by injecting the agent provider from plexus context, + * additionally to that ensures that the extension classloader is used to load this class as it is + * part of tycho-core module. + */ +public class TychoDirectorApplication extends DirectorApplication { + + public TychoDirectorApplication(IProvisioningAgentProvider agentProvider, IProvisioningAgent agent) { + //TODO should be able to control agent creation see https://github.com/eclipse-equinox/p2/pull/398 + //Until now we need to fetch a service to trigger loading of the internal osgi framework... + agent.getService(IArtifactRepositoryManager.class); + } +} diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java index 167717a83b..4389ce1917 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java @@ -29,12 +29,13 @@ import org.eclipse.tycho.p2.metadata.IP2Artifact; import org.eclipse.tycho.p2.publisher.rootfiles.FeatureRootAdvice; import org.eclipse.tycho.p2maven.advices.MavenPropertiesAdvice; +import org.eclipse.tycho.testing.TychoPlexusTestCase; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -public class FeatureRootfileArtifactRepositoryTest { +public class FeatureRootfileArtifactRepositoryTest extends TychoPlexusTestCase { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); diff --git a/tycho-maven-plugin/src/main/resources/META-INF/maven/extension.xml b/tycho-maven-plugin/src/main/resources/META-INF/maven/extension.xml index 63947ce854..c6840c91a4 100644 --- a/tycho-maven-plugin/src/main/resources/META-INF/maven/extension.xml +++ b/tycho-maven-plugin/src/main/resources/META-INF/maven/extension.xml @@ -11,6 +11,8 @@ org.eclipse.equinox.internal.p2.updatesite org.eclipse.equinox.internal.p2.artifact.repository.simple + org.eclipse.equinox.internal.provisional.p2.core.eventbus + org.eclipse.equinox.internal.p2.core.helpers org.eclipse.equinox.p2.core org.eclipse.equinox.p2.metadata org.eclipse.equinox.p2.publisher diff --git a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java index 8ea217ffdc..5b0657ffee 100644 --- a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java +++ b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java @@ -16,7 +16,9 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Objects; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -26,10 +28,12 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.internal.p2.director.app.DirectorApplication; import org.eclipse.equinox.p2.core.IProvisioningAgent; -import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.core.IProvisioningAgentProvider; +import org.eclipse.osgi.service.environment.EnvironmentInfo; +import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.p2.CommandLineArguments; +import org.eclipse.tycho.p2tools.TychoDirectorApplication; /** * Allows to run the * */ -@Mojo(name = "director", defaultPhase = LifecyclePhase.NONE, threadSafe = true, requiresProject = false) +@Mojo(name = "director", defaultPhase = LifecyclePhase.NONE, threadSafe = true, requiresProject = true) public class DirectorMojo extends AbstractMojo { @Component private IProvisioningAgent agent; + @Component + private IProvisioningAgentProvider agentProvider; + /** * The folder in which the targeted product is located. */ @@ -321,9 +328,6 @@ public class DirectorMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { - //TODO should be able to control agent creation see https://github.com/eclipse-equinox/p2/pull/398 - //Until now we need to fetch a service to trigger loading of the internal osgi framework... - agent.getService(IArtifactRepositoryManager.class); CommandLineArguments args = new CommandLineArguments(); args.addNonNull("-destination", destination); args.addNonNull("-metadatarepository", metadatarepositories); @@ -364,7 +368,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { args.addNonNull("-trustedAuthorities", trustedAuthorities); args.addNonNull("-trustedPGPKeys", trustedPGPKeys); args.addNonNull("-trustedCertificates", trustedCertificates); - Object exitCode = new DirectorApplication().run(args.toArray()); + Object exitCode = new TychoDirectorApplication(agentProvider, agent).run(args.toArray()); if (!(IApplication.EXIT_OK.equals(exitCode))) { throw new MojoFailureException("Call to p2 director application failed with exit code " + exitCode + ". Program arguments were: '" + args + "'."); @@ -395,8 +399,8 @@ private List getUnitParameterList(String csvlist, List units) { list.add(iu.trim()); } } - if (install != null) { - for (IU iu : install) { + if (units != null) { + for (IU iu : units) { String id = iu.id; if (iu.feature) { id += ".feature.group";