Skip to content

Commit

Permalink
Fail on missing plugin product requirement
Browse files Browse the repository at this point in the history
Currently Tycho does not fail if a requirement of a product can't be
found in the resolve phase but only if the product is materialized. Even
then it fails with an obscure error that claims the products bundle is
not found where actually the dependency can't be found.
  • Loading branch information
laeubi committed Jan 22, 2024
1 parent da6ff7d commit 08be6ce
Show file tree
Hide file tree
Showing 23 changed files with 478 additions and 124 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 @@ -37,7 +37,45 @@
public class TargetPlatformConfigurationMojo extends AbstractMojo {

/**
* <p>
* Target environments (os/ws/arch) to consider.
* </p>
* Example:
*
* <pre>
*&lt;environments&gt;
* &lt;environment&gt;
* &lt;os&gt;linux&lt;/os&gt;
* &lt;ws&gt;gtk&lt;/ws&gt;
* &lt;arch&gt;x86_64&lt;/arch&gt;
* &lt;/environment&gt;
* &lt;environment&gt;
* &lt;os&gt;linux&lt;/os&gt;
* &lt;ws&gt;gtk&lt;/ws&gt;
* &lt;arch&gt;ppc64le&lt;/arch&gt;
* &lt;/environment&gt;
* &lt;environment&gt;
* &lt;os&gt;linux&lt;/os&gt;
* &lt;ws&gt;gtk&lt;/ws&gt;
* &lt;arch&gt;aarch64&lt;/arch&gt;
* &lt;/environment&gt;
* &lt;environment&gt;
* &lt;os&gt;win32&lt;/os&gt;
* &lt;ws&gt;win32&lt;/ws&gt;
* &lt;arch&gt;x86_64&lt;/arch&gt;
* &lt;/environment&gt;
* &lt;environment&gt;
* &lt;os&gt;macosx&lt;/os&gt;
* &lt;ws&gt;cocoa&lt;/ws&gt;
* &lt;arch&gt;x86_64&lt;/arch&gt;
* &lt;/environment&gt;
* &lt;environment&gt;
* &lt;os&gt;macosx&lt;/os&gt;
* &lt;ws&gt;cocoa&lt;/ws&gt;
* &lt;arch&gt;aarch64&lt;/arch&gt;
* &lt;/environment&gt;
*&lt;/environments&gt;
* </pre>
*/
@Parameter(name = DefaultTargetPlatformConfigurationReader.ENVIRONMENTS)
private TargetEnvironment[] environments;
Expand Down Expand Up @@ -208,8 +246,9 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
private IncludeSourceMode targetDefinionIncludeSource;

/**
* Configures if referenced repositories should be included when fetching repositories.
* The default is <code>ignore</code>. To specify to use referenced repositories, pass <code>include</code>.
* Configures if referenced repositories should be included when fetching repositories. The
* default is <code>ignore</code>. To specify to use referenced repositories, pass
* <code>include</code>.
*/
@Parameter(name = DefaultTargetPlatformConfigurationReader.REFERENCED_REPOSITORY_MODE)
private ReferencedRepositoryMode referencedRepositoryMode;
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.RequiredPropertiesMatch;
Expand All @@ -48,6 +47,7 @@
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.Slicer;

abstract class AbstractSlicerResolutionStrategy extends AbstractResolutionStrategy {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
import org.eclipse.tycho.p2.publisher.DownloadStatsAdvice;
import org.eclipse.tycho.p2.publisher.FeatureDependenciesAction;
import org.eclipse.tycho.p2.publisher.P2Artifact;
import org.eclipse.tycho.p2.publisher.ProductDependenciesAction;
import org.eclipse.tycho.p2.publisher.TransientArtifactRepository;
import org.eclipse.tycho.p2.publisher.rootfiles.FeatureRootAdvice;
import org.eclipse.tycho.p2.repository.ArtifactsIO;
import org.eclipse.tycho.p2.repository.MetadataIO;
import org.eclipse.tycho.p2maven.actions.CategoryDependenciesAction;
import org.eclipse.tycho.p2maven.actions.ProductDependenciesAction;
import org.eclipse.tycho.p2maven.actions.ProductFile2;
import org.osgi.framework.BundleException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.felix.resolver.util.CopyOnWriteSet;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IProvidedCapability;
Expand Down Expand Up @@ -76,6 +75,7 @@
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

public class P2ResolverImpl implements P2Resolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
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.internal.p2.director.Slicer;
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 @@ -79,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 @@ -22,14 +22,14 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2tools.copiedfromp2.PermissiveSlicer;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;

public class SlicerResolutionStrategy extends AbstractSlicerResolutionStrategy {

Expand Down
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
@@ -0,0 +1,11 @@
###############################################################################
# Copyright (c) 2010, 2011 SAP AG and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# SAP AG - initial API and implementation
###############################################################################
bin.includes = feature.xml
Loading

0 comments on commit 08be6ce

Please sign in to comment.