Skip to content

Commit 00c5518

Browse files
laeubieclipse-tycho-bot
authored andcommitted
Fix dependency is ignored when previously found with other scope
Currently if a maven dependency is reachable to different chains of dependencies it can happen that the first visited one is from an excluded scope. In this case the maven-target marks the dependency as already processed but then ignore it. If it now appears later with a valid scope it is ignored because already processed. This now changes the check so it first test if it is a valid scope before processing it any further. (cherry picked from commit e164f9a)
1 parent 93682a3 commit 00c5518

File tree

3 files changed

+76
-29
lines changed

3 files changed

+76
-29
lines changed

tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/MavenDependencyCollector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,15 @@ public DependencyResult collect(MavenRootDependency root) throws RepositoryExcep
112112
while (!queue.isEmpty()) {
113113
ArtifactDescriptor current = queue.poll();
114114
for (Dependency dependency : current.dependencies()) {
115-
if (isValidDependency(dependency)) {
115+
if (isValidDependency(dependency) && isValidScope(dependency)) {
116116
if (isVersionRanged(dependency)) {
117117
ArtifactDescriptor dependencyDescriptor = resolveHighestVersion(dependency, current.node(),
118118
artifacts, nodes);
119119
if (dependencyDescriptor != null
120120
&& collected.add(getId(dependencyDescriptor.node().getDependency()))) {
121121
queue.add(dependencyDescriptor);
122122
}
123-
}
124-
if (collected.add(getId(dependency))) {
123+
} else if (collected.add(getId(dependency))) {
125124
ArtifactDescriptor dependencyDescriptor = readArtifactDescriptor(dependency, current.node(),
126125
artifacts, nodes);
127126
if (dependencyDescriptor != null) {

tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/AbstractMavenTargetTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ private static <T> boolean isOriginalArtifact(ExpectedUnit expectedUnit, T unit,
126126
if (key == null) {
127127
return false;
128128
}
129+
if (key.groupId().equals("-")) {
130+
return true;
131+
}
129132
URI location = getLocation.apply(unit);
130133
String expectedPathSuffix = "/" + String.join("/", ".m2", "repository", key.groupId().replace('.', '/'),
131134
key.artifactId(), key.version(), key.artifactId() + "-" + key.version() + ".jar");
@@ -148,6 +151,10 @@ static ExpectedBundle generatedBundle(String bsn, String version, String groupAr
148151
ArtifactKey.fromPortableString(groupArtifact + ":" + version + "::"));
149152
}
150153

154+
static ExpectedBundle bundle(String bsn, String version) {
155+
return new ExpectedBundle(bsn, version, false, true, new ArtifactKey("-", bsn, version, ""));
156+
}
157+
151158
static List<ExpectedBundle> withSourceBundles(List<ExpectedBundle> mainBundles) {
152159
return mainBundles.stream().<ExpectedBundle> mapMulti((unit, downStream) -> {
153160
downStream.accept(unit);

tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/MavenContentTest.java

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,71 @@
2121
* Tests that the content of a location matches the expectation
2222
*/
2323
public class MavenContentTest extends AbstractMavenTargetTest {
24-
@Test
25-
public void testIncludeProvidedInfinite() throws Exception {
26-
ITargetLocation target = resolveMavenTarget(
27-
"""
28-
<location includeDependencyDepth="infinite" includeDependencyScopes="provided" includeSource="false" missingManifest="ignore" type="Maven">
29-
<dependencies>
30-
<dependency>
31-
<groupId>org.osgi</groupId>
32-
<artifactId>org.osgi.test.common</artifactId>
33-
<version>1.3.0</version>
34-
<type>jar</type>
35-
</dependency>
36-
</dependencies>
37-
</location>
38-
""");
39-
assertStatusOk(getTargetStatus(target));
40-
List<ExpectedBundle> expectedBundles = List.of( //
41-
originalOSGiBundle("osgi.annotation", "8.1.0.202202082230", "org.osgi:osgi.annotation", "8.1.0"),
42-
originalOSGiBundle("org.osgi.util.tracker", "1.5.4.202109301733", "org.osgi:org.osgi.util.tracker",
43-
"1.5.4"),
44-
originalOSGiBundle("org.osgi.test.common", "1.3.0", "org.osgi:org.osgi.test.common"),
45-
originalOSGiBundle("org.osgi.dto", "1.0.0.201505202023", "org.osgi:org.osgi.dto", "1.0.0"),
46-
originalOSGiBundle("org.osgi.framework", "1.8.0.201505202023", "org.osgi:org.osgi.framework", "1.8.0"),
47-
originalOSGiBundle("org.osgi.resource", "1.0.0.201505202023", "org.osgi:org.osgi.resource", "1.0.0"));
48-
assertTargetBundles(target, expectedBundles);
49-
}
24+
@Test
25+
public void testIncludeProvidedInfinite() throws Exception {
26+
ITargetLocation target = resolveMavenTarget(
27+
"""
28+
<location includeDependencyDepth="infinite" includeDependencyScopes="provided" includeSource="false" missingManifest="ignore" type="Maven">
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.osgi</groupId>
32+
<artifactId>org.osgi.test.common</artifactId>
33+
<version>1.3.0</version>
34+
<type>jar</type>
35+
</dependency>
36+
</dependencies>
37+
</location>
38+
""");
39+
assertStatusOk(getTargetStatus(target));
40+
List<ExpectedBundle> expectedBundles = List.of( //
41+
originalOSGiBundle("osgi.annotation", "8.1.0.202202082230", "org.osgi:osgi.annotation", "8.1.0"),
42+
originalOSGiBundle("org.osgi.util.tracker", "1.5.4.202109301733", "org.osgi:org.osgi.util.tracker",
43+
"1.5.4"),
44+
originalOSGiBundle("org.osgi.test.common", "1.3.0", "org.osgi:org.osgi.test.common"),
45+
originalOSGiBundle("org.osgi.dto", "1.0.0.201505202023", "org.osgi:org.osgi.dto", "1.0.0"),
46+
originalOSGiBundle("org.osgi.framework", "1.8.0.201505202023", "org.osgi:org.osgi.framework", "1.8.0"),
47+
originalOSGiBundle("org.osgi.resource", "1.0.0.201505202023", "org.osgi:org.osgi.resource", "1.0.0"));
48+
assertTargetBundles(target, expectedBundles);
49+
}
50+
51+
@Test
52+
public void testJettyWithInDependencies() throws Exception {
53+
ITargetLocation target = resolveMavenTarget(
54+
"""
55+
<location includeDependencyDepth="infinite" includeDependencyScopes="compile,provided,runtime" includeSource="false" label="Jetty" missingManifest="error" type="Maven">
56+
<dependencies>
57+
<dependency>
58+
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
59+
<artifactId>jetty-ee10-websocket-jakarta-server</artifactId>
60+
<version>12.0.9</version>
61+
<type>jar</type>
62+
</dependency>
63+
</dependencies>
64+
</location>
65+
""");
66+
assertStatusOk(getTargetStatus(target));
67+
List<ExpectedBundle> expectedBundles = List.of(bundle("org.eclipse.jetty.ee10.plus", "12.0.9"),
68+
bundle("jakarta.enterprise.lang-model", "4.0.1"), bundle("jakarta.transaction-api", "2.0.1"),
69+
bundle("org.eclipse.jetty.http", "12.0.9"), bundle("slf4j.api", "2.0.12"),
70+
bundle("jakarta.servlet-api", "6.0.0"), bundle("org.eclipse.jetty.ee10.webapp", "12.0.9"),
71+
bundle("org.eclipse.jetty.io", "12.0.9"), bundle("org.eclipse.jetty.util", "12.0.9"),
72+
bundle("jakarta.websocket-api", "2.1.1"), bundle("org.eclipse.jetty.ee10.annotations", "12.0.9"),
73+
bundle("jakarta.annotation-api", "2.1.1"), bundle("org.eclipse.jetty.websocket.core.common", "12.0.9"),
74+
bundle("org.eclipse.jetty.jndi", "12.0.9"), bundle("org.eclipse.jetty.security", "12.0.9"),
75+
bundle("jakarta.enterprise.cdi-api", "4.0.1"), bundle("jakarta.websocket-client-api", "2.1.1"),
76+
bundle("org.eclipse.jetty.ee10.servlet", "12.0.9"),
77+
bundle("org.eclipse.jetty.websocket.core.client", "12.0.9"), bundle("org.objectweb.asm.tree", "9.7"),
78+
bundle("org.eclipse.jetty.ee10.websocket.jakarta.client", "12.0.9"),
79+
bundle("org.eclipse.jetty.server", "12.0.9"), bundle("jakarta.el-api", "5.0.0"),
80+
bundle("org.eclipse.jetty.ee10.websocket.jakarta.server", "12.0.9"),
81+
bundle("org.eclipse.jetty.ee10.websocket.servlet", "12.0.9"),
82+
bundle("org.eclipse.jetty.ee10.websocket.jakarta.common", "12.0.9"),
83+
bundle("org.eclipse.jetty.websocket.core.server", "12.0.9"),
84+
bundle("org.eclipse.jetty.client", "12.0.9"), bundle("org.eclipse.jetty.session", "12.0.9"),
85+
bundle("org.eclipse.jetty.ee", "12.0.9"), bundle("org.eclipse.jetty.plus", "12.0.9"),
86+
bundle("org.objectweb.asm.commons", "9.7"), bundle("jakarta.inject.jakarta.inject-api", "2.0.1"),
87+
bundle("org.eclipse.jetty.alpn.client", "12.0.9"), bundle("org.objectweb.asm", "9.7"),
88+
bundle("org.eclipse.jetty.xml", "12.0.9"), bundle("jakarta.interceptor-api", "2.1.0"));
89+
assertTargetBundles(target, expectedBundles);
90+
}
5091
}

0 commit comments

Comments
 (0)