Skip to content

Commit

Permalink
Move back to PlexusContainer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cstamas committed Sep 6, 2024
1 parent 19c2052 commit 223acb4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,17 +45,17 @@ public class DefaultProvisioningAgent implements IProvisioningAgent {
private final EquinoxServiceFactory serviceFactory;
private final Map<String, IAgentServiceFactory> 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<String, IAgentServiceFactory> agentFactories,
MavenPropertyHelper propertyHelper,
BeanLocator beanLocator) {
PlexusContainer plexusContainer) {
this.serviceFactory = serviceFactory;
this.agentFactories = agentFactories;
this.propertyHelper = propertyHelper;
this.beanLocator = beanLocator;
this.plexusContainer = plexusContainer;
}

@Override
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -86,32 +86,31 @@ 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 <T> void visitPluginExtensions(MavenProject project, MavenSession mavenSession, Class<T> type,
Consumer<? super T> consumer) throws PluginVersionResolutionException, PluginDescriptorParsingException,
InvalidPluginDescriptorException, PluginResolutionException, PluginManagerException {
Set<String> visited = new HashSet<>();
execute(project, mavenSession, () -> {
Iterable<? extends BeanEntry<Annotation, T>> 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);
}

Expand Down

0 comments on commit 223acb4

Please sign in to comment.