Skip to content

Commit

Permalink
issue #610 slicer requirements failure
Browse files Browse the repository at this point in the history
make SlicerResolutionStrategy not consider warnings from slicer as failure to be consistent with eclipse
update tests for target resolution to expect that slicer does not fail if dependencies are missing
  • Loading branch information
Vaclav Hala authored and laeubi committed Feb 8, 2022
1 parent 881df5d commit 29e62f8
Show file tree
Hide file tree
Showing 37 changed files with 831 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import static org.eclipse.tycho.p2.target.TargetDefinitionResolverTest.definitionWith;
import static org.eclipse.tycho.p2.target.TargetDefinitionResolverTest.versionedIdList;
import static org.eclipse.tycho.p2.target.TargetDefinitionResolverTest.versionedIdsOf;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void testResolveWithPlanner() throws Exception {
}

@Test(expected = ResolverException.class)
public void testUnsatisfiedDependencyWithPlanner() throws Exception {
public void testUnsatisfiedDependencyWithPlannerFails() throws Exception {
// ignore logged errors
logVerifier.expectError(any(String.class));

Expand All @@ -79,6 +81,16 @@ public void testUnsatisfiedDependencyWithPlanner() throws Exception {
subject.resolveContentWithExceptions(definition, p2Context.getAgent());
}

@Test(expected = ResolverException.class)
public void testUnsatisfiedInclusionWithPlannerFails() throws Exception {
// ignore logged errors
logVerifier.expectError(any(String.class));

TargetDefinition definition = definitionWith(
new PlannerLocationStub(TestRepositories.UNSATISFIED, TARGET_FEATURE));
subject.resolveContentWithExceptions(definition, p2Context.getAgent());
}

@Test
public void testResolveWithSlicer() throws Exception {
TargetDefinition definition = definitionWith(
Expand All @@ -90,13 +102,20 @@ public void testResolveWithSlicer() throws Exception {

@Test
public void testUnsatisfiedDependencyWithSlicerIsOk() throws Exception {
// TODO this missing dependency is not logged because Slicer is created
// in SlicerResolutionStrategy with configuration to only consider strict dependencies
// so it does not consider this dependency at all
// expectWarningMissingDependency(MAIN_BUNDLE, REFERENCED_BUNDLE_V1);
expectNoErrors();
TargetDefinition definition = definitionWith(new SlicerLocationStub(TestRepositories.UNSATISFIED, MAIN_BUNDLE));
TargetDefinitionContent units = subject.resolveContent(definition, p2Context.getAgent());
assertThat(versionedIdsOf(units), bagEquals(versionedIdList(MAIN_BUNDLE)));
}

@Test(expected = ResolverException.class)
public void testUnsatisfiedInclusionWithSlicerFails() throws Exception {
@Test
public void testUnsatisfiedInclusionWithSlicerIsOk() throws Exception {
expectWarningMissingDependency(TARGET_FEATURE, REFERENCED_BUNDLE_V1);
expectNoErrors();
TargetDefinition definition = definitionWith(
new SlicerLocationStub(TestRepositories.UNSATISFIED, TARGET_FEATURE));
subject.resolveContentWithExceptions(definition, p2Context.getAgent());
Expand All @@ -109,6 +128,16 @@ public void testResolveConflictingIncludeMode() throws Exception {
subject.resolveContentWithExceptions(definition, p2Context.getAgent());
}

private void expectWarningMissingDependency(IVersionedId from, IVersionedId to) {
var msgFrom = "from " + from.getId() + " " + from.getVersion();
var msgTo = "to org.eclipse.equinox.p2.iu; " + to.getId() + " [" + to.getVersion();
logVerifier.expectWarning(allOf(containsString(msgFrom), containsString(msgTo)));
}

private void expectNoErrors() {
logVerifier.expectError("");
}

static class PlannerLocationStub extends LocationStub implements InstallableUnitLocation {

public PlannerLocationStub(TestRepositories repositories, IVersionedId... seedUnits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.tycho.p2.target;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -149,11 +148,13 @@ public void testResolveIncludesDependencies() throws Exception {
assertThat(versionedIdsOf(units), hasItem(REFERENCED_BUNDLE_V1));
}

@Test(expected = BuildFailureException.class)
@Test
public void testResolveDependenciesAcrossLocations() throws Exception {
logVerifier.expectError(containsString("Cannot resolve target definition"));
// TODO currently slicer treats every location as isolated so it warns about dependencies not being available here
// but this behavior is confusing because the dependencies actually are available and planner would not warn
// logVerifier.expectNoWarnings();
TargetDefinition definition = definitionWith(new LocationStub(TestRepositories.UNSATISFIED, TARGET_FEATURE),
new LocationStub(TestRepositories.V1_AND_V2));
new LocationStub(TestRepositories.V1_AND_V2, MAIN_BUNDLE, REFERENCED_BUNDLE_V1));
TargetDefinitionContent units = subject.resolveContent(definition, p2Context.getAgent());
assertThat(versionedIdsOf(units), hasItem(MAIN_BUNDLE));
assertThat(versionedIdsOf(units), hasItem(REFERENCED_BUNDLE_V1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* Contributors:
* Sonatype Inc. - initial API and implementation
* Christoph Läubrich - #462 - Delay Pom considered items to the final Target Platform calculation
* Christoph Läubrich - #462 - Delay Pom considered items to the final Target Platform calculation
*******************************************************************************/
package org.eclipse.tycho.p2.util.resolution;

Expand All @@ -27,6 +27,7 @@
import java.util.UUID;

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.Explanation;
import org.eclipse.equinox.internal.p2.director.Explanation.HardRequirement;
Expand Down Expand Up @@ -106,6 +107,7 @@ protected final IQueryable<IInstallableUnit> slice(Map<String, String> propertie
throw new ResolverException(StatusTool.toLogMessage(slicerStatus), properties.toString(),
StatusTool.findException(slicerStatus));
}
warnAboutMissingDependencies(slicerStatus);

if (logger.isExtendedDebugEnabled()) {
logger.debug("Slice:\n" + ResolverDebugUtils.toDebugString(slice, false, monitor));
Expand All @@ -114,6 +116,21 @@ protected final IQueryable<IInstallableUnit> slice(Map<String, String> propertie
return slice;
}

private void warnAboutMissingDependencies(MultiStatus slicerStatus) {
var msg = new StringBuilder(
"Following dependencies were not found by the slicer (you can disregard this if it is intentional):\n");
var anyWarnPresent = false;
for (var statusItem : slicerStatus.getChildren()) {
if (statusItem.getSeverity() == IStatus.WARNING) {
anyWarnPresent = true;
msg.append(statusItem.getMessage()).append("\n");
}
}
if (anyWarnPresent) {
logger.warn(msg.toString());
}
}

protected abstract boolean isSlicerError(MultiStatus slicerStatus);

protected abstract Slicer newSlicer(IQueryable<IInstallableUnit> availableIUs, Map<String, String> properties);
Expand Down Expand Up @@ -199,14 +216,14 @@ protected IInstallableUnit createUnitProviding(String name, Collection<IRequirem
* Computes a list of current missing requirements. The list only contains requirements up to
* the point where it is known that this is a 'root' that means a requirement that prevents
* computation of a complete solution.
*
*
* @param explanation
* @return
*/
protected List<IRequirement> computeMissingRequirements(Set<Explanation> explanation) {
List<IRequirement> missingRequirements = new ArrayList<>();
//We collect here all units that are available but maybe incomplete due to an missing requirement.
//This is important as otherwise we could generate false missing requirements as they might just be chained
//This is important as otherwise we could generate false missing requirements as they might just be chained
// Here is an example:
// a) Bundle require an EE or package what is missing
// b) Feature requires the Bundle
Expand Down Expand Up @@ -268,7 +285,7 @@ protected List<IRequirement> computeMissingRequirements(Set<Explanation> explana

/**
* Check if this is an EE environment requirement
*
*
* @param requirement
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected Slicer newSlicer(IQueryable<IInstallableUnit> availableIUs, Map<String

@Override
protected boolean isSlicerError(MultiStatus slicerStatus) {
return slicerStatus.matches(IStatus.WARNING | IStatus.ERROR | IStatus.CANCEL);
return slicerStatus.matches(IStatus.ERROR | IStatus.CANCEL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<resolver>p2</resolver>
<pomDependencies>consider</pomDependencies>
<executionEnvironment>JavaSE-11</executionEnvironment>
<target>
<artifact>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>targetplatform</artifactId>
<version>1.0.0</version>
</artifact>
</target>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>

<modules>
<module>targetplatform</module>
<module>project</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: project
Bundle-Version: 1.0.0
Automatic-Module-Name: bundle3
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: bundle2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source.. = src/
bin.includes = META-INF/,.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>project</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>targetplatform</artifactId>
<packaging>eclipse-target-definition</packaging>
<parent>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<target name="p2Repository.slicerDependencies" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository id="repoA" location="url"/>

<unit id="bundle1" version="1.0.0"/>
</location>

<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository id="repoB" location="url"/>

<unit id="bundle2" version="1.0.0"/>
<unit id="feature2.feature.group" version="1.0.0"/>
</location>
</locations>
</target>
59 changes: 59 additions & 0 deletions tycho-its/projects/target.plannerWithMissingDependencies/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<resolver>p2</resolver>
<pomDependencies>consider</pomDependencies>
<executionEnvironment>JavaSE-11</executionEnvironment>
<target>
<artifact>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>targetplatform</artifactId>
<version>1.0.0</version>
</artifact>
</target>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>

<modules>
<module>targetplatform</module>
<module>project</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: project
Bundle-Version: 1.0.0
Automatic-Module-Name: bundle3
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: bundle2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source.. = src/
bin.includes = META-INF/,.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>project</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>tycho-its-project.p2Repository.slicerDependencies</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0</version>
</parent>

</project>
Loading

0 comments on commit 29e62f8

Please sign in to comment.