Skip to content

Commit 215a618

Browse files
Copilotlaeubi
andcommitted
Fix regression in ProjectTypeContainer package discovery
Co-authored-by: laeubi <[email protected]>
1 parent 27f380f commit 215a618

File tree

11 files changed

+147
-0
lines changed

11 files changed

+147
-0
lines changed

apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/compatibility/ProjectTypeContainerTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,36 @@ public void visit(String packageName, IApiTypeRoot typeroot) {
250250
assertThat(pkgNames).containsAll(getAllPackageNames());
251251
}
252252

253+
/**
254+
* Tests that packages are correctly discovered in projects with multiple
255+
* source folders that share the same output folder. This is a regression
256+
* test for issue #2096 where packages were missing when multiple source
257+
* folders output to the same location.
258+
*/
259+
public void testMultipleSourceFoldersWithSharedOutput() throws CoreException {
260+
IApiComponent component = getComponent("bundle.multisource"); //$NON-NLS-1$
261+
IApiTypeContainer[] containers = component.getApiTypeContainers();
262+
assertEquals("Wrong number of API type containers", 1, containers.length); //$NON-NLS-1$
263+
IApiTypeContainer container = containers[0];
264+
assertEquals("Should be a composite type container", IApiTypeContainer.COMPOSITE, //$NON-NLS-1$
265+
container.getContainerType());
266+
267+
String[] packageNames = container.getPackageNames();
268+
Set<String> pkgSet = new HashSet<>();
269+
for (String pkg : packageNames) {
270+
pkgSet.add(pkg);
271+
}
272+
273+
// Both packages from different source folders should be found
274+
assertTrue("Missing package test.pkg1 from src1 folder", pkgSet.contains("test.pkg1")); //$NON-NLS-1$ //$NON-NLS-2$
275+
assertTrue("Missing package test.pkg2 from src2 folder", pkgSet.contains("test.pkg2")); //$NON-NLS-1$ //$NON-NLS-2$
276+
277+
// Verify we can find types from both source folders
278+
IApiTypeRoot type1 = container.findTypeRoot("test.pkg1.TestClass1"); //$NON-NLS-1$
279+
assertNotNull("Should find TestClass1 from src1", type1); //$NON-NLS-1$
280+
281+
IApiTypeRoot type2 = container.findTypeRoot("test.pkg2.TestClass2"); //$NON-NLS-1$
282+
assertNotNull("Should find TestClass2 from src2", type2); //$NON-NLS-1$
283+
}
284+
253285
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src1"/>
6+
<classpathentry kind="src" path="src2"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>bundle.multisource</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.pde.PluginNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
33+
</natures>
34+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
6+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Multi Source Test Bundle
4+
Bundle-SymbolicName: bundle.multisource
5+
Bundle-Version: 1.0.0
6+
Bundle-RequiredExecutionEnvironment: JavaSE-17
7+
Export-Package: test.pkg1,
8+
test.pkg2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source.. = src1/,\
2+
src2/
3+
output.. = bin/
4+
bin.includes = META-INF/,\
5+
.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test.pkg1;
2+
3+
/**
4+
* Test class in source folder 1
5+
*/
6+
public class TestClass1 {
7+
public void method1() {
8+
// Test method
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test.pkg2;
2+
3+
/**
4+
* Test class in source folder 2
5+
*/
6+
public class TestClass2 {
7+
public void method2() {
8+
// Test method
9+
}
10+
}

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/CompositeApiTypeContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public CompositeApiTypeContainer(IApiElement parent, List<IApiTypeContainer> con
3939
this.fContainers = containers;
4040
}
4141

42+
@Override
43+
public int getContainerType() {
44+
return COMPOSITE;
45+
}
46+
4247
@Override
4348
protected List<IApiTypeContainer> createApiTypeContainers() throws CoreException {
4449
return fContainers;

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ProjectComponent.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.pde.api.tools.internal.model;
1515

1616
import java.util.ArrayList;
17+
import java.util.Arrays;
1718
import java.util.Collections;
1819
import java.util.List;
1920
import java.util.Map;
@@ -418,6 +419,30 @@ private static IApiTypeContainer getApiTypeContainer(String location, ProjectCom
418419
}
419420
cfc = new ProjectTypeContainer(component, container, root);
420421
outputLocationToContainer.put(outputLocation, cfc);
422+
} else {
423+
// Multiple source folders share the same output location
424+
// Create a composite container to include packages from all source roots
425+
List<IApiTypeContainer> containers = new ArrayList<>();
426+
if (cfc instanceof CompositeApiTypeContainer) {
427+
// Already a composite, add to it
428+
IApiTypeContainer[] typeContainers = ((CompositeApiTypeContainer) cfc)
429+
.getApiTypeContainers();
430+
containers.addAll(Arrays.asList(typeContainers));
431+
} else {
432+
// Convert single container to composite
433+
containers.add(cfc);
434+
}
435+
// Add new container for this source root
436+
IPath projectFullPath = project.getProject().getFullPath();
437+
IContainer container = null;
438+
if (projectFullPath.equals(outputLocation)) {
439+
container = project.getProject();
440+
} else {
441+
container = project.getProject().getWorkspace().getRoot().getFolder(outputLocation);
442+
}
443+
containers.add(new ProjectTypeContainer(component, container, root));
444+
cfc = new CompositeApiTypeContainer(component, containers);
445+
outputLocationToContainer.put(outputLocation, cfc);
421446
}
422447
return cfc;
423448
}

0 commit comments

Comments
 (0)