Skip to content

Commit

Permalink
Add a testcase for #822
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <[email protected]>
  • Loading branch information
laeubi committed Mar 31, 2022
1 parent 4912bd2 commit 55fc3f5
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,18 @@ public Set<IInstallableUnit> calculateDependencyFragments(ResolutionData data,
if (fragmentsList.isEmpty()) {
return Collections.emptySet();
}
MavenLogger logger = mavenContext.getLogger();
if (logger.isExtendedDebugEnabled() && !fragmentsList.isEmpty()) {
logger.debug("Possible candidate fragments:");
for (Entry<IInstallableUnit, IRequiredCapability> fragmentEntry : fragmentsList) {
logger.debug(" " + fragmentEntry.getKey().toString());
}
}

Map<String, List<IInstallableUnit>> resolvedUnitsById = resolvedUnits.stream()//
.collect(Collectors.groupingBy(iu -> iu.getId()));

return fragmentsList.stream()//
Set<IInstallableUnit> matching = fragmentsList.stream()//
.filter(entry -> {
IRequiredCapability hostRequirement = entry.getValue();
List<IInstallableUnit> potentialHosts = resolvedUnitsById.get(hostRequirement.getName());
Expand All @@ -152,6 +159,13 @@ public Set<IInstallableUnit> calculateDependencyFragments(ResolutionData data,
})//
.map(entry -> entry.getKey())//
.collect(Collectors.toSet());
if (logger.isDebugEnabled() && !matching.isEmpty()) {
logger.info("Resolved fragments:");
for (IInstallableUnit unit : matching) {
logger.info(" " + unit.toString());
}
}
return matching;
}

private static Optional<Entry<IInstallableUnit, IRequiredCapability>> findFragmentHostRequirement(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle 1
Bundle-SymbolicName: bundle1;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.swt;bundle-version="3.119.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
14 changes: 14 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/bundle1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>org.eclipse.tycho.its</groupId>
<artifactId>resolver-multiple-downloads-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>bundle1</artifactId>
<packaging>eclipse-plugin</packaging>

</project>
46 changes: 46 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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>org.eclipse.tycho.its</groupId>
<artifactId>resolver-multiple-downloads-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho-version>3.0.0-SNAPSHOT</tycho-version>
</properties>

<modules>
<module>bundle1</module>
</modules>

<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>
<target>
<file>../test.target</file>
</target>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>

</project>
10 changes: 10 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/sdk_4.21.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="Eclipse 4.21">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.21/"/>
<unit id="org.eclipse.platform.ide" version="4.21.0.I20210906-0500"/>
</location>
</locations>
</target>
10 changes: 10 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/sdk_4.22.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="Eclipse 4.22">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.22/"/>
<unit id="org.eclipse.platform.ide" version="4.22.0.I20211124-1800"/>
</location>
</locations>
</target>
10 changes: 10 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/sdk_4.23.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="Eclipse 4.23">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.23/"/>
<unit id="org.eclipse.platform.ide" version="4.23.0.I20220308-0310"/>
</location>
</locations>
</target>
9 changes: 9 additions & 0 deletions tycho-its/projects/resolver.multipleDownloads/test.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="test">
<locations>
<location type="Target" uri="file:${project_loc:/resolver-multiple-downloads-parent}/sdk_4.21.target"/>
<location type="Target" uri="file:${project_loc:/resolver-multiple-downloads-parent}/sdk_4.22.target"/>
<location type="Target" uri="file:${project_loc:/resolver-multiple-downloads-parent}/sdk_4.23.target"/>
</locations>
</target>
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
*******************************************************************************/
package org.eclipse.tycho.test.resolver;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.List;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Test;

public class ResolverTests extends AbstractTychoIntegrationTest {

private static final String SDK_23 = "org.eclipse.swt.gtk.linux.x86_64 3.119.0.v20220223-1102";
private static final String SDK_22 = "org.eclipse.swt.gtk.linux.x86_64 3.118.0.v20211123-0851";
private static final String SDK_21 = "org.eclipse.swt.gtk.linux.x86_64 3.117.0.v20210906-0842";

/**
* This test case tests a combination that at a first glance looks very simple
* but is hard to resolve due to the structure of 'org.eclipse.core.runtime'
Expand Down Expand Up @@ -53,4 +62,40 @@ public void testMixedReactor() throws Exception {
verifier.verifyErrorFreeLog();
}

@Test
public void testMultipleFragmentsOnlyOneIsChoosen() throws Exception {

Verifier verifier = getVerifier("resolver.multipleDownloads", false, false);
verifier.executeGoal("compile");
verifier.verifyErrorFreeLog();
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);

// [INFO] Resolved fragments:
// [INFO] org.eclipse.swt.gtk.linux.x86_64 3.118.0.v20211123-0851
// [INFO] org.eclipse.swt.gtk.linux.x86_64 3.119.0.v20220223-1102
// [INFO] org.eclipse.swt.gtk.linux.x86_64 3.117.0.v20210906-0842
// [INFO] ------------------------------------------------------------------------
boolean startLine = false;
boolean highestVersionFound = false;
for (String ansiLine : lines) {
String line = Verifier.stripAnsi(ansiLine);
if (startLine) {
if (line.endsWith("------")) {
break;
}
if (line.endsWith(SDK_21)) {
fail("3.117 was found but should not be part of the result");
}
if (line.endsWith(SDK_22)) {
fail("3.118 was found but should not be part of the result");
}
highestVersionFound |= line.endsWith(SDK_23);
} else {
startLine = line.endsWith("Resolved fragments:");
}
}
assertTrue("Start line not found!", startLine);
assertTrue("Highest version was not found", highestVersionFound);
}

}

0 comments on commit 55fc3f5

Please sign in to comment.