From 223acb4b9831acf84d86dadae55f54db649e2db0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 6 Sep 2024 16:43:26 +0200 Subject: [PATCH] Move back to PlexusContainer Am too spoiled to use Sisu internals, but in case of Maven3 whole sisu is _not exposed_ only JSR330 is. While in Plx land, whole Plexus _is_ exposed. --- .../p2maven/DefaultProvisioningAgent.java | 15 +++++++------ .../JarDirectoryBundlesTest.java | 3 ++- .../target/TargetPlatformLocationsTest.java | 3 ++- .../tycho/helper/PluginRealmHelper.java | 21 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/DefaultProvisioningAgent.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/DefaultProvisioningAgent.java index 1a8994b03a..d6a733c2bb 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/DefaultProvisioningAgent.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/DefaultProvisioningAgent.java @@ -16,13 +16,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; -import com.google.inject.Key; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.artifact.repository.MirrorSelector; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; import org.eclipse.sisu.equinox.EquinoxServiceFactory; -import org.eclipse.sisu.inject.BeanLocator; import org.eclipse.tycho.helper.MavenPropertyHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,17 +45,17 @@ public class DefaultProvisioningAgent implements IProvisioningAgent { private final EquinoxServiceFactory serviceFactory; private final Map agentFactories; private final MavenPropertyHelper propertyHelper; - private final BeanLocator beanLocator; + private final PlexusContainer plexusContainer; // TODO: get rid of this (or Maven should offer alternative) @Inject public DefaultProvisioningAgent(@Named("connect") EquinoxServiceFactory serviceFactory, Map agentFactories, MavenPropertyHelper propertyHelper, - BeanLocator beanLocator) { + PlexusContainer plexusContainer) { this.serviceFactory = serviceFactory; this.agentFactories = agentFactories; this.propertyHelper = propertyHelper; - this.beanLocator = beanLocator; + this.plexusContainer = plexusContainer; } @Override @@ -73,9 +73,8 @@ public Object getService(String serviceName) { logger.debug("Service " + serviceName + " not found in Plexus AgentServiceFactories, look it up in Plexus Container"); try { - Class clazz = Thread.currentThread().getContextClassLoader().loadClass(serviceName); - return beanLocator.locate(Key.get(clazz, com.google.inject.name.Named.class)).iterator().next().getValue(); - } catch (ClassNotFoundException e) { + return plexusContainer.lookup(serviceName); + } catch (ComponentLookupException e) { logger.debug("Service " + serviceName + " was not found in PlexusContainer"); } logger.warn("Cannot locate service " + serviceName + " because no provisioning agent was found"); diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/MNGECLIPSE949jarDirectoryBundles/JarDirectoryBundlesTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/MNGECLIPSE949jarDirectoryBundles/JarDirectoryBundlesTest.java index e709cb5766..cf1811d811 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/MNGECLIPSE949jarDirectoryBundles/JarDirectoryBundlesTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/MNGECLIPSE949jarDirectoryBundles/JarDirectoryBundlesTest.java @@ -21,6 +21,7 @@ import org.eclipse.tycho.core.osgitools.DefaultBundleReader; import org.eclipse.tycho.core.osgitools.OsgiManifest; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; +import org.eclipse.tycho.test.util.NoopFileLockService; import org.junit.Test; public class JarDirectoryBundlesTest extends AbstractTychoIntegrationTest { @@ -38,7 +39,7 @@ public void test() throws Exception { assertEquals(1, sitePlugins.length); // verify the bundle actually makes sense - DefaultBundleReader reader = new DefaultBundleReader(); + DefaultBundleReader reader = new DefaultBundleReader(new NoopFileLockService()); OsgiManifest siteBundleManifest = reader.loadManifest(sitePlugins[0]); assertEquals("platform.jar", siteBundleManifest.getBundleClasspath()[0]); assertEquals("org.eclipse.platform", siteBundleManifest.getBundleSymbolicName()); diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java index 2aed914678..7b3eb54ece 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java @@ -33,6 +33,7 @@ import org.eclipse.tycho.core.osgitools.DefaultBundleReader; import org.eclipse.tycho.core.osgitools.OsgiManifest; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; +import org.eclipse.tycho.test.util.NoopFileLockService; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -108,7 +109,7 @@ public void testTargetPlatformArtifactCaching() throws Exception { File annotBundleManifestFile = new File(verifier.getBasedir(), "target.test/plugins/osgi.annotation.bundle_0.0.1/META-INF/MANIFEST.MF"); - DefaultBundleReader reader = new DefaultBundleReader(); + DefaultBundleReader reader = new DefaultBundleReader(new NoopFileLockService()); OsgiManifest annotBundleManifest = reader.loadManifest(annotBundleManifestFile); Assert.assertEquals("tycho.test.package", annotBundleManifest.getValue("Export-Package")); verifier.executeGoal("verify"); diff --git a/tycho-spi/src/main/java/org/eclipse/tycho/helper/PluginRealmHelper.java b/tycho-spi/src/main/java/org/eclipse/tycho/helper/PluginRealmHelper.java index 6bd8e1f76b..b854b95be3 100644 --- a/tycho-spi/src/main/java/org/eclipse/tycho/helper/PluginRealmHelper.java +++ b/tycho-spi/src/main/java/org/eclipse/tycho/helper/PluginRealmHelper.java @@ -31,10 +31,10 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentDependency; -import org.eclipse.sisu.BeanEntry; -import org.eclipse.sisu.inject.BeanLocator; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,19 +86,19 @@ public interface PluginFilter { private final LifecyclePluginResolver lifecyclePluginResolver; private final MavenPluginManager mavenPluginManager; private final ProjectHelper projectHelper; - private final BeanLocator beanLocator; + private final PlexusContainer plexusContainer; // TODO: get rid of this (or Maven should offer alternative) @Inject public PluginRealmHelper(BuildPluginManager buildPluginManager, LifecyclePluginResolver lifecyclePluginResolver, MavenPluginManager mavenPluginManager, ProjectHelper projectHelper, - BeanLocator beanLocator) { + PlexusContainer plexusContainer) { this.buildPluginManager = buildPluginManager; this.lifecyclePluginResolver = lifecyclePluginResolver; this.mavenPluginManager = mavenPluginManager; this.projectHelper = projectHelper; - this.beanLocator = beanLocator; + this.plexusContainer = plexusContainer; } public void visitPluginExtensions(MavenProject project, MavenSession mavenSession, Class type, @@ -106,12 +106,11 @@ public void visitPluginExtensions(MavenProject project, MavenSession mavenSe InvalidPluginDescriptorException, PluginResolutionException, PluginManagerException { Set visited = new HashSet<>(); execute(project, mavenSession, () -> { - Iterable> beans = beanLocator.locate(Key.get(type)); - beans.iterator().forEachRemaining(e -> { - if (visited.add(e.getValue().getClass().getName())) { - consumer.accept(e.getValue()); - } - }); + try { + plexusContainer.lookupList(type).stream().filter(x -> visited.add(x.getClass().getName())).forEach(consumer); + } catch (ComponentLookupException e) { + logger.debug("Cannot lookup any item of type: " + type); + } }, PluginRealmHelper::isTychoEmbedderPlugin); }