Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP De-plexus Tycho #4212

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 13 additions & 5 deletions p2-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@
<packaging>maven-plugin</packaging>
<name>P2 Maven Integration</name>
<description>The P2 Maven Plugin provides access to the P2 eco-system inside maven.</description>
<properties></properties>
<properties/>
<prerequisites>
<maven>${minimal-maven-version}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.p2.core</artifactId>
Expand Down Expand Up @@ -211,10 +223,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,67 @@
import java.util.function.Supplier;

import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
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.tycho.helper.MavenPropertyHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(role = IProvisioningAgent.class)
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

@Singleton
@Named
public class DefaultProvisioningAgent implements IProvisioningAgent {

static {
MirrorSelector.MIRROR_PARSE_ERROR_LEVEL = IStatus.INFO;
}

@Requirement
private Logger log;

@Requirement(hint = "connect")
private EquinoxServiceFactory serviceFactory;

@Requirement
private PlexusContainer plexusContainer;

@Requirement
Map<String, IAgentServiceFactory> agentFactories;

@Requirement
MavenPropertyHelper propertyHelper;

private Map<String, Supplier<Object>> agentServices = new ConcurrentHashMap<>();
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<String, Supplier<Object>> agentServices = new ConcurrentHashMap<>();

private final EquinoxServiceFactory serviceFactory;
private final Map<String, IAgentServiceFactory> agentFactories;
private final MavenPropertyHelper propertyHelper;
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,
PlexusContainer plexusContainer) {
this.serviceFactory = serviceFactory;
this.agentFactories = agentFactories;
this.propertyHelper = propertyHelper;
this.plexusContainer = plexusContainer;
}

@Override
public Object getService(String serviceName) {
Object agentService = getOSGiAgentService(serviceName);
if (agentService != null) {
return agentService;
}
log.debug("Service " + serviceName
logger.debug("Service " + serviceName
+ " not found in OSGi ProvisioningAgent agent, look it up in Plexus AgentServiceFactories");
Object factoryService = getAgentFactoryService(serviceName);
if (factoryService != null) {
return factoryService;
}
log.debug("Service " + serviceName
logger.debug("Service " + serviceName
+ " not found in Plexus AgentServiceFactories, look it up in Plexus Container");
try {
return plexusContainer.lookup(serviceName);
} catch (ComponentLookupException e) {
log.debug("Service " + serviceName + " was not found in PlexusContainer");
logger.debug("Service " + serviceName + " was not found in PlexusContainer");
}
log.warn("Cannot locate service " + serviceName + " because no provisioning agent was found");
logger.warn("Cannot locate service " + serviceName + " because no provisioning agent was found");
return null;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@

import java.net.URI;

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;

@Component(role = IProvisioningAgentProvider.class)
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

@Singleton
@Named
public class DefaultProvisioningAgentProvider implements IProvisioningAgentProvider {

@Requirement(hint = "connect")
private EquinoxServiceFactory serviceFactory;
private final EquinoxServiceFactory serviceFactory;

@Inject
public DefaultProvisioningAgentProvider(@Named("connect") EquinoxServiceFactory serviceFactory) {
this.serviceFactory = serviceFactory;
}

@Override
public IProvisioningAgent createAgent(URI location) throws ProvisionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
public class DependencyChain {

private ArtifactDescriptor root;
private Collection<ArtifactDescriptor> artifacts;
private final ArtifactDescriptor root;
private final Collection<ArtifactDescriptor> artifacts;

public DependencyChain(ArtifactDescriptor root, Collection<ArtifactDescriptor> artifacts) {
this.root = root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@
import java.util.stream.Stream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
Expand Down Expand Up @@ -69,44 +64,47 @@
import org.eclipse.tycho.p2maven.tmp.BundlesAction;
import org.eclipse.tycho.resolver.InstallableUnitProvider;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

/**
* Component used to generate {@link IInstallableUnit}s from other artifacts
*
*/
@Component(role = InstallableUnitGenerator.class)
@Singleton
@Named
public class InstallableUnitGenerator {

private static final boolean DUMP_DATA = Boolean.getBoolean("tycho.p2.dump")
|| Boolean.getBoolean("tycho.p2.dump.units");

@Requirement
private Logger log;

private static final String KEY_UNITS = "InstallableUnitGenerator.units";

private static final String KEY_ARTIFACT_FILE = "InstallableUnitGenerator.artifactFile";

@Requirement
private IProvisioningAgent provisioningAgent;

@Requirement(role = InstallableUnitProvider.class)
private Map<String, InstallableUnitProvider> additionalUnitProviders;

@Requirement
private PluginRealmHelper pluginRealmHelper;

@Requirement
private InstallableUnitPublisher publisher;

@Requirement
private PlexusContainer plexus;

@Requirement
ArtifactHandlerManager artifactHandlerManager;

private Map<Artifact, ArtifactUnits> artifactUnitMap = new ConcurrentHashMap<>();
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Artifact, ArtifactUnits> artifactUnitMap = new ConcurrentHashMap<>();

private final IProvisioningAgent provisioningAgent;
private final Map<String, InstallableUnitProvider> additionalUnitProviders;
private final PluginRealmHelper pluginRealmHelper;
private final InstallableUnitPublisher publisher;

@Inject
public InstallableUnitGenerator(IProvisioningAgent provisioningAgent,
Map<String, InstallableUnitProvider> additionalUnitProviders,
PluginRealmHelper pluginRealmHelper,
InstallableUnitPublisher publisher) {
this.provisioningAgent = provisioningAgent;
this.additionalUnitProviders = additionalUnitProviders;
this.pluginRealmHelper = pluginRealmHelper;
this.publisher = publisher;
}

/**
* Computes the {@link IInstallableUnit}s for a collection of projects.
Expand Down Expand Up @@ -165,11 +163,11 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
boolean forceUpdate) throws CoreException {
init();
Objects.requireNonNull(session);
log.debug("Computing installable units for " + project + ", force update = " + forceUpdate);
logger.debug("Computing installable units for " + project + ", force update = " + forceUpdate);
synchronized (project) {
File basedir = project.getBasedir();
if (basedir == null || !basedir.isDirectory()) {
log.warn("No valid basedir for " + project + " found");
logger.warn("No valid basedir for " + project + " found");
return Collections.emptyList();
}
File projectArtifact = getProjectArtifact(project);
Expand All @@ -181,15 +179,15 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
// now check if we are classlaoder compatible...
Collection<IInstallableUnit> collection = (Collection<IInstallableUnit>) contextValue;
if (isCompatible(collection)) {
log.debug("Using cached value for " + project);
logger.debug("Using cached value for " + project);
return collection;
} else {
log.debug("Cannot use cached value for " + project
logger.debug("Cannot use cached value for " + project
+ " because of incompatible classloaders, update is forced");
}
}
} else {
log.info("Cannot use cached value for " + project
logger.info("Cannot use cached value for " + project
+ " because project artifact has changed, update is forced");
}
}
Expand All @@ -200,9 +198,9 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
artifactId);
Collection<IInstallableUnit> publishedUnits = publisher.publishMetadata(actions);
for (InstallableUnitProvider unitProvider : getProvider(project, session)) {
log.debug("Asking " + unitProvider + " for additional units for " + project);
logger.debug("Asking " + unitProvider + " for additional units for " + project);
Collection<IInstallableUnit> installableUnits = unitProvider.getInstallableUnits(project, session);
log.debug("Provider " + unitProvider + " generated " + installableUnits.size() + " (" + installableUnits
logger.debug("Provider " + unitProvider + " generated " + installableUnits.size() + " (" + installableUnits
+ ") units for " + project);
publishedUnits.addAll(installableUnits);
}
Expand All @@ -215,7 +213,7 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
}
}
if (result.isEmpty()) {
log.debug("Cannot generate any InstallableUnit for packaging type '" + packaging + "' for " + project);
logger.debug("Cannot generate any InstallableUnit for packaging type '" + packaging + "' for " + project);
}
project.setContextValue(KEY_UNITS, result);
project.setContextValue(KEY_ARTIFACT_FILE, projectArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;
import java.util.Map.Entry;

import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -34,10 +33,14 @@
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;

import javax.inject.Named;
import javax.inject.Singleton;

/**
* Component that helps publishing units using publisher actions
*/
@Component(role = InstallableUnitPublisher.class)
@Singleton
@Named
public class InstallableUnitPublisher {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import java.util.Map;
import java.util.Objects;

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -32,16 +29,22 @@
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Named;
import javax.inject.Singleton;

/**
* A strategy that computes a slice from a set of all units.
*/
@Component(role = InstallableUnitSlicer.class)
@Singleton
@Named
public class InstallableUnitSlicer {

private static final SlicingOptions DEFAULT_SLICING_OPTIONS = new SlicingOptions();
@Requirement
private Logger log;

private final Logger logger = LoggerFactory.getLogger(getClass());

/**
* Computes a "slice" of a given set of {@link IInstallableUnit}s that include
Expand Down Expand Up @@ -70,7 +73,7 @@ public IQueryResult<IInstallableUnit> computeDependencies(Collection<IInstallabl
throw new CoreException(sliceStatus);
}
if (!sliceStatus.isOK()) {
log.debug("There are warnings from the slicer: " + sliceStatus);
logger.debug("There are warnings from the slicer: " + sliceStatus);
}
if (options.isLatestVersionOnly()) {
return slice.query(QueryUtil.createLatestIUQuery(), monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import java.util.concurrent.atomic.AtomicBoolean;

import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.slf4j.Logger;

public class LoggerProgressMonitor implements IProgressMonitor {

private final Logger log;

private AtomicBoolean canceled = new AtomicBoolean();
private final AtomicBoolean canceled = new AtomicBoolean();

public LoggerProgressMonitor(Logger log) {
this.log = log;
Expand Down
Loading
Loading