eclipse-jdt / eclipse.jdt.debug

Eclipse Public License 2.0
16 stars 46 forks source link

Attribute "Without test code" is ignored in the launcher #327

Closed oleosterhagen closed 9 months ago

oleosterhagen commented 11 months ago

When adding a project dependency to an existing project, it is possible to set the Without test code attribute, so that paths marked with Contains test sources are not added to the classpath.

grafik

This attribute is persisted as without_test_code in the .classpath file.

<classpathentry combineaccessrules="false" kind="src" path="/projectA">
    <attributes>
        <attribute name="without_test_code" value="true"/>
    </attributes>
</classpathentry>

The incremental Java compiler already takes this attribute into account, so that marked test classes from the project dependency are not accessible. But when launching a JUnit test the resolved classpath contains the output locations for the unwanted test paths. Here is an example (example.tar.gz):

Classpath of projectA

path="main", output="bin/main"
path="test", output="bin/test", test=true

Classpath of projectB

path="test", output="bin", test=true
path="/projectA", without_test_code=true

When launching a test from projectB, classes from /projectA/test are accessible via reflection - but they should'nt. (The reflective access is necessary here, because in the Java editor the compiler already cannot see these classes.) It is possible to exclude all test code in the launcher (see tab Dependencies) - but this a different thing.

To solve this problem, the two JavaRuntime.resolveRuntimeClasspathEntry(...) methods (one for launch configurations, another for projects) should evaluate the attribute without_test_code when resolving project dependencies.