Skip to content

Commit

Permalink
Only consider product requirements if they match the context
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 22, 2024
1 parent 0baa04a commit 155e4bc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected Set<IRequirement> getRequiredCapabilities() {
}
if (type == ProductContentType.BUNDLES || type == ProductContentType.MIXED) {
for (FeatureEntry plugin : ((ProductFile) product).getProductEntries()) {
addRequiredCapability(required, plugin.getId(), Version.parseVersion(plugin.getVersion()), null, true);
addRequiredCapability(required, plugin.getId(), Version.parseVersion(plugin.getVersion()), null, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws
+ " with context " + resolverException.getSelectionContext()
+ System.lineSeparator() + resolverException.explanations()
.map(exp -> " " + exp.toString()).collect(Collectors.joining("\n")),
null, mavenProject);
null, mavenProject, resolverException);
}
}
TychoProject tychoProject = projectManager.getTychoProject(mavenProject).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.Explanation;
import org.eclipse.equinox.internal.p2.director.Projector;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.director.SimplePlanner;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.StatusTool;
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2tools.copiedfromp2.Projector;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;

public class ProjectorResolutionStrategy extends AbstractSlicerResolutionStrategy {
Expand Down Expand Up @@ -78,9 +81,32 @@ public Collection<IInstallableUnit> resolve(Map<String, String> properties, IPro
// force profile UIs to be used during resolution
seedUnits.addAll(data.getEEResolutionHints().getMandatoryUnits());
seedRequires.addAll(data.getEEResolutionHints().getMandatoryRequires());

Projector projector = new Projector(slice(properties, generatedUnits, monitor), selectionContext,
new HashSet<>(), false);
new HashSet<>(), false) {
IQueryable<IInstallableUnit> units;

@Override
protected Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
Collection<IRequirement> requiredCapabilities = super.getRequiredCapabilities(iu);
if (QueryUtil.isProduct(iu)) {
if (units == null) {
units = data.units();
}
return requiredCapabilities.stream().filter(requirement -> {
IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery(requirement.getMatches());
IQueryResult<IInstallableUnit> result = units.query(query, null);
if (result.isEmpty()) {
//this must fail the resolve so we need to include the requirement
return true;
}
//If none of the results are applicable this means they are filtered and need not to be considered
//this happens in plugin based products that include native fragments from different platforms
return result.stream().anyMatch(matchIu -> isApplicable(matchIu));
}).toList();
}
return requiredCapabilities;
}
};
projector.encode(createUnitRequiring("tycho", seedUnits, seedRequires),
EMPTY_IU_ARRAY /* alreadyExistingRoots */,
new QueryableArray(List.of()) /* installedIUs */, seedUnits /* newRoots */, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.query.CollectionResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.tycho.ExecutionEnvironmentResolutionHints;
import org.eclipse.tycho.p2maven.ListQueryable;

public interface ResolutionData {

Expand All @@ -42,4 +44,14 @@ public interface ResolutionData {
Predicate<IInstallableUnit> getIInstallableUnitAcceptor();

IQueryable<IInstallableUnit> getAdditionalUnitStore();

default IQueryable<IInstallableUnit> units() {
ListQueryable<IInstallableUnit> listQueryable = new ListQueryable<>();
listQueryable.add(new CollectionResult<>(getAvailableIUs()));
IQueryable<IInstallableUnit> unitStore = getAdditionalUnitStore();
if (unitStore != null) {
listQueryable.add(unitStore);
}
return listQueryable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ private void createNegation(IInstallableUnit iu, IRequirement req) throws Contra
}

// Check whether the requirement is applicable
private boolean isApplicable(IRequirement req) {
protected boolean isApplicable(IRequirement req) {
IMatchExpression<IInstallableUnit> filter = req.getFilter();
return filter == null || filter.isMatch(selectionContext);
}

private boolean isApplicable(IInstallableUnit iu) {
protected boolean isApplicable(IInstallableUnit iu) {
IMatchExpression<IInstallableUnit> filter = iu.getFilter();
return filter == null || filter.isMatch(selectionContext);
}
Expand Down Expand Up @@ -536,7 +536,7 @@ public void processIU(IInstallableUnit iu, boolean isRootIU) throws Contradictio
}
}

private Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
protected Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
boolean isFragment = iu instanceof IInstallableUnitFragment;
//Short-circuit for the case of an IInstallableUnit
if ((!isFragment) && iu.getMetaRequirements().size() == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;

public class InstallableUnitUtil {

static final String IU_CAPABILITY_NS = "org.eclipse.equinox.p2.iu"; // see IInstallableUnit.NAMESPACE_IU_ID;
static final String BUNDLE_CAPABILITY_NS = "osgi.bundle"; // see BundlesAction.CAPABILITY_NS_OSGI_BUNDLE
static final String PRODUCT_TYPE_PROPERTY = "org.eclipse.equinox.p2.type.product"; // see InstallableUnitDescription.PROP_TYPE_PRODUCT;
static final String FEATURE_TYPE_PROPERTY = "org.eclipse.equinox.p2.type.group"; // see InstallableUnitDescription.PROP_TYPE_GROUP;
static final String IU_CAPABILITY_NS = IInstallableUnit.NAMESPACE_IU_ID;
static final String BUNDLE_CAPABILITY_NS = BundlesAction.CAPABILITY_NS_OSGI_BUNDLE;
static final String PRODUCT_TYPE_PROPERTY = InstallableUnitDescription.PROP_TYPE_PRODUCT;
static final String FEATURE_TYPE_PROPERTY = InstallableUnitDescription.PROP_TYPE_GROUP;

public static String DEFAULT_VERSION = "0.0.20";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<artifact>
<groupId>org.eclipse</groupId>
<artifactId>eclipse-sdk-prereqs</artifactId>
<version>4.31.0-SNAPSHOT</version>
</artifact>
</target>
<environments>
<environment>
<os>linux</os>
Expand Down

0 comments on commit 155e4bc

Please sign in to comment.