Skip to content

Commit 05bcbf4

Browse files
committed
Add more logging to tests, fail test if project has JVM version below 21
See: #782
1 parent d3ef226 commit 05bcbf4

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/ModuleOptionsTests.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.jdt.core.JavaCore;
2626
import org.eclipse.jdt.core.JavaModelException;
2727
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
28+
import org.eclipse.jdt.launching.IVMInstall;
2829
import org.eclipse.jdt.launching.JavaRuntime;
2930

3031
public class ModuleOptionsTests extends AbstractDebugTest {
@@ -112,8 +113,9 @@ private int indexOfJREContainer(IClasspathEntry[] rawClasspath) {
112113
return -1;
113114
}
114115

115-
public void testAddModules1() throws JavaModelException {
116+
public void testAddModules1() throws Exception {
116117
IJavaProject javaProject = getProjectContext();
118+
checkVMInstall(javaProject);
117119
List<String> defaultModules = getDefaultModules(javaProject);
118120
defaultModules.add("jdk.crypto.cryptoki"); // requires jdk.crypto.ec up to Java 21
119121
try {
@@ -135,8 +137,9 @@ public void testAddModules1() throws JavaModelException {
135137
}
136138
}
137139

138-
public void testLimitModules_release9() throws CoreException {
140+
public void testLimitModules_release9() throws Exception {
139141
IJavaProject javaProject = getProjectContext();
142+
checkVMInstall(javaProject);
140143
try {
141144
javaProject.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
142145
List<String> defaultModules = getDefaultModules(javaProject);
@@ -153,7 +156,7 @@ public void testLimitModules_release9() throws CoreException {
153156
+ "jdk.net," //
154157
+ "jdk.nio.mapmode," //
155158
// + "jdk.packager,jdk.packager.services,jdk.plugin.dom,"
156-
// + "jdk.scripting.nashorn,"
159+
// + "jdk.scripting.nashorn,"
157160
+ "jdk.sctp,"
158161
+ "jdk.security.auth,jdk.security.jgss,jdk.unsupported," //
159162
+ "jdk.unsupported.desktop,jdk.xml.dom";
@@ -178,8 +181,10 @@ public void testLimitModules_release9() throws CoreException {
178181
}
179182
}
180183

181-
public void testLimitModules1() throws JavaModelException {
184+
public void testLimitModules1() throws Exception {
182185
IJavaProject javaProject = getProjectContext();
186+
javaProject.setOption(JavaCore.COMPILER_RELEASE, JavaCore.DISABLED);
187+
checkVMInstall(javaProject);
183188
List<String> defaultModules = getDefaultModules(javaProject);
184189
String expectedModules;
185190
String moduleList = String.join(",", defaultModules);
@@ -218,4 +223,10 @@ public void testLimitModules1() throws JavaModelException {
218223
removeClasspathAttributesFromSystemLibrary(javaProject);
219224
}
220225
}
226+
227+
private void checkVMInstall(IJavaProject javaProject) throws CoreException {
228+
IVMInstall vm = JavaRuntime.getVMInstall(javaProject);
229+
assertTrue("Expected at least Java 21 for project JVM but got: " + vm.getName() + ", with location: "
230+
+ vm.getInstallLocation(), JavaRuntime.compareJavaVersions(vm, JavaCore.VERSION_21) > 0);
231+
}
221232
}

org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.eclipse.core.runtime.preferences.DefaultScope;
3434
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
3535
import org.eclipse.core.runtime.preferences.InstanceScope;
36+
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
3637
import org.eclipse.jdt.launching.IVMInstall;
3738
import org.eclipse.jdt.launching.IVMInstall2;
3839
import org.eclipse.jdt.launching.IVMInstallType;
@@ -320,16 +321,24 @@ public static void initialize() {
320321
// early exit no need to read preferences or check env variable!
321322
return;
322323
}
323-
if (System.getProperty(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED) == null && Boolean.parseBoolean(System.getenv(ENV_CI))) {
324-
// exit because no explicit value for the property was given and we are running in a CI environment
325-
return;
324+
boolean ci = false;
325+
if (System.getProperty(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED) == null) {
326+
ci = Boolean.parseBoolean(System.getenv(ENV_CI));
327+
if (ci) {
328+
// exit because no explicit value for the property was given and we are running in a CI environment
329+
return;
330+
}
326331
}
327332
// finally look what is defined in the preferences
328333
IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
329334
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
330335
boolean defaultValue = defaultNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, true);
331336
if (instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) {
332337
new DetectVMInstallationsJob().schedule();
338+
if (ci) {
339+
// log that this job will run in a CI environment
340+
JDIDebugPlugin.log(Status.info("DetectVMInstallationsJob scheduled")); //$NON-NLS-1$
341+
}
333342
}
334343
}
335344

0 commit comments

Comments
 (0)