Skip to content

Commit

Permalink
Fixup Director Mojo when used as a plugin in pom.xml
Browse files Browse the repository at this point in the history
(cherry picked from commit 2f81c3b)
  • Loading branch information
laeubi committed Dec 10, 2023
1 parent a9d4402 commit 949f9da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<!-- P2 Stuff TODO add more? -->
<exportedPackage>org.eclipse.equinox.internal.p2.updatesite</exportedPackage>
<exportedPackage>org.eclipse.equinox.internal.p2.artifact.repository.simple</exportedPackage>
<exportedPackage>org.eclipse.equinox.internal.provisional.p2.core.eventbus</exportedPackage>
<exportedPackage>org.eclipse.equinox.internal.p2.core.helpers</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.core</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.metadata</exportedPackage>
<exportedPackage>org.eclipse.equinox.p2.publisher</exportedPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <a href=
Expand Down Expand Up @@ -65,12 +69,15 @@
* </li>
* </ol>
*/
@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.
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 + "'.");
Expand Down Expand Up @@ -395,8 +399,8 @@ private List<String> getUnitParameterList(String csvlist, List<IU> 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";
Expand Down

0 comments on commit 949f9da

Please sign in to comment.