Skip to content

Commit 3b4269f

Browse files
committed
Add comprehensive classpath resolution test for transitive forbidden
access rules Validates that PDE correctly adds transitive dependencies to the JDT classpath with K_NON_ACCESSIBLE access rules (PR #2218). Asserts exact access rule structure, marker line numbers, problem IDs, severity, and message patterns for all 24 expected forbidden reference markers. Also Tests both forbiddenReference=warning (project A) and forbiddenReference=error (project Ae, JDT default) compiler settings. Additionally tests of discouraged access tests for x-internal:=true packages
1 parent 12eae51 commit 3b4269f

87 files changed

Lines changed: 1596 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/core/tests/internal/classpath/ClasspathResolutionTest2.java

Lines changed: 750 additions & 0 deletions
Large diffs are not rendered by default.

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import org.eclipse.pde.core.tests.internal.AllPDECoreTests;
1717
import org.eclipse.pde.core.tests.internal.classpath.ClasspathResolutionTest;
18+
import org.eclipse.pde.core.tests.internal.classpath.ClasspathResolutionTest2;
1819
import org.eclipse.pde.core.tests.internal.core.builders.BundleErrorReporterTest;
1920
import org.eclipse.pde.core.tests.internal.util.PDESchemaHelperTest;
2021
import org.eclipse.pde.ui.tests.build.properties.AllValidatorTests;
@@ -63,6 +64,7 @@
6364
ClasspathContributorTest.class, //
6465
DynamicPluginProjectReferencesTest.class, //
6566
ClasspathResolutionTest.class, //
67+
ClasspathResolutionTest2.class, //
6668
BundleErrorReporterTest.class, //
6769
AllPDECoreTests.class, //
6870
ProjectSmartImportTest.class, //
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>A</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+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 6 additions & 0 deletions
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=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.release=enabled
5+
org.eclipse.jdt.core.compiler.source=21
6+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: A
4+
Bundle-SymbolicName: A
5+
Bundle-Version: 1.0.0.qualifier
6+
Export-Package: a.api
7+
Import-Package: b.api;version="1.0.0",
8+
g.api;version="1.0.0"
9+
Automatic-Module-Name: A
10+
Bundle-RequiredExecutionEnvironment: JavaSE-21
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package a.api;
2+
3+
/**
4+
* Test class that references types from multiple bundles to exercise OSGi
5+
* visibility and JDT access rules.
6+
* <p>
7+
* Bundle A declares: {@code Import-Package: b.api, g.api}
8+
* <p>
9+
* With the correct PDE behavior (PR #2218), all bundles in the transitive
10+
* dependency closure are present on the compilation classpath:
11+
* <ul>
12+
* <li><b>Directly imported bundles</b> (B, G): exported packages are
13+
* {@code K_ACCESSIBLE}, non-exported packages caught by EXCLUDE_ALL_RULE
14+
* ({@code K_NON_ACCESSIBLE})</li>
15+
* <li><b>Transitive dependencies</b> (C, D, E, F, H): all-forbidden access
16+
* rules (single {@code **&#47;* K_NON_ACCESSIBLE} rule) — compiler can
17+
* resolve types but direct usage produces forbidden reference warnings
18+
* (configured via {@code forbiddenReference=warning})</li>
19+
* </ul>
20+
* <p>
21+
* At <b>OSGi runtime</b>, only directly imported packages (b.api, g.api)
22+
* would be accessible to A's classloader (OSGi Core R8 §3.9.4). The JDT
23+
* access rules enforce this visibility at compile time.
24+
*/
25+
public class AClass {
26+
// ---- Directly imported bundles (K_ACCESSIBLE for exported packages) ----
27+
28+
// B exports b.api, A imports b.api → K_ACCESSIBLE → no marker
29+
public Object objectFromB_allowed = new b.api.MyObject();
30+
// B's b.internal is NOT exported → caught by EXCLUDE_ALL → forbidden warning
31+
public Object objectFromB_forbidden = new b.internal.MyObject();
32+
33+
// G exports g.api, A imports g.api → K_ACCESSIBLE → no marker
34+
public Object objectFromG_allowed = new g.api.MyObject();
35+
// G's g.internal is NOT exported → caught by EXCLUDE_ALL → forbidden warning
36+
public Object objectFromG_forbidden = new g.internal.MyObject();
37+
38+
// ---- Transitive dependencies (all-forbidden access rules) ----
39+
// These types CAN be resolved by the compiler (on classpath for type
40+
// hierarchy validation), but produce forbidden reference warnings because
41+
// their entries have only **/* K_NON_ACCESSIBLE access rules.
42+
// At OSGi runtime, A's classloader cannot load any of these types (§3.9.4).
43+
44+
// C: Required by B (Require-Bundle: C, default visibility:=private §3.13.1)
45+
public Object objectFromC_forbidden1 = new c.api.MyObject();
46+
public Object objectFromC_forbidden2 = new c.internal.MyObject();
47+
48+
// D: Package imported by B (Import-Package: d.api) — never re-exports §3.6.4
49+
public Object objectFromD_forbidden1 = new d.api.MyObject();
50+
public Object objectFromD_forbidden2 = new d.internal.MyObject();
51+
52+
// E: Optionally required by B (Require-Bundle: E;resolution:=optional §3.7.5)
53+
public Object objectFromE_forbidden1 = new e.api.MyObject();
54+
public Object objectFromE_forbidden2 = new e.internal.MyObject();
55+
56+
// F: Optionally imported by B (Import-Package: f.api;resolution:=optional)
57+
public Object objectFromF_forbidden1 = new f.api.MyObject();
58+
public Object objectFromF_forbidden2 = new f.internal.MyObject();
59+
60+
// H: Optionally imported by G (Import-Package: h.api;resolution:=optional)
61+
public Object objectFromH_forbidden1 = new h.api.MyObject();
62+
public Object objectFromH_forbidden2 = new h.internal.MyObject();
63+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

0 commit comments

Comments
 (0)