Skip to content

Commit

Permalink
Properly add "on the fly" compiled classes to the started JVM classpath
Browse files Browse the repository at this point in the history
Fixes #503
  • Loading branch information
iloveeclipse committed Oct 7, 2024
1 parent ff99117 commit 70049d8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
4 changes: 3 additions & 1 deletion org.eclipse.jdt.debug.jdi.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Bundle-Version: 1.1.200.qualifier
Bundle-ClassPath: .
Bundle-Vendor: Eclipse
Require-Bundle: org.junit,
org.eclipse.jdt.debug
org.eclipse.jdt.debug,
org.eclipse.equinox.common,
org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Expand Down
4 changes: 3 additions & 1 deletion org.eclipse.jdt.debug.jdi.tests/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ output.. = bin/
bin.includes = about.html,\
test.xml,\
META-INF/,\
.
.,\
java19/

Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ private void launchJavaTarget() {
}

commandLine.add("-classpath");
commandLine.add(fClassPath);
commandLine.add(enhanceClasspath(fClassPath));
addDebugOptions(commandLine);
addNoJITCompilerOption(commandLine);
commandLine.add("-Xrunjdwp:transport=dt_socket,address=" + fBackEndPort + ",suspend=y,server=y");
Expand All @@ -765,6 +765,15 @@ private void launchJavaTarget() {
}
}

/**
* @param classPath
* current classpath used for JVM
* @return possibly updated classpath with more entries required by a test
*/
protected String enhanceClasspath(String classPath) {
return fClassPath;
}

/**
* Launches the target Sun VM.
*/
Expand Down Expand Up @@ -794,7 +803,7 @@ private void launchSunTarget() {
commandLine.add(fBootPath);
}
commandLine.add("-classpath");
commandLine.add(fClassPath);
commandLine.add(enhanceClasspath(fClassPath));
addDebugOptions(commandLine);
addNoJITCompilerOption(commandLine);
commandLine.add("-Xrunjdwp:transport=dt_socket,address=" + fBackEndPort + ",suspend=y,server=y");
Expand Down Expand Up @@ -828,7 +837,7 @@ private void launchIBMTarget() {
}

commandLine.add("-classpath");
commandLine.add(fClassPath);
commandLine.add(enhanceClasspath(fClassPath));
addDebugOptions(commandLine);
addNoJITCompilerOption(commandLine);
commandLine.add("-Xrunjdwp:transport=dt_socket,address=" + fBackEndPort + ",suspend=y,server=y");
Expand Down Expand Up @@ -1214,7 +1223,7 @@ public void shutDownTarget() {
fBackEndPort = availablePort;
} catch (IOException e) {
fBackEndPort +=2;

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;

Expand All @@ -29,7 +31,11 @@
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdi.internal.ThreadReferenceImpl;
import org.osgi.framework.Bundle;

import com.sun.jdi.ThreadReference;
import com.sun.jdi.event.ThreadDeathEvent;
Expand All @@ -56,6 +62,7 @@ public class VirtualThreadTest extends AbstractJDITest {
private ThreadReference fVirtualThread;
private ThreadReference fThread;
private ThreadReference fMainThread;
private static Path tempClassesDirectory;

/**
* Init the fields that are used by this test only.
Expand Down Expand Up @@ -95,21 +102,26 @@ public void setVMInfo(VMInformation info) {
// do nothing
}

public static void main(String[] args) throws Exception {
compileTestProgram();
new VirtualThreadTest().runSuite(args);
}

protected static void compileTestProgram() throws Exception {
if (Runtime.version().feature() < 19) {
return;
}

String sourceFilePath = new File("./java19/TryVirtualThread.java").getAbsolutePath();
String outputFilePath = new File("./bin").getAbsolutePath();
tempClassesDirectory = Files.createTempDirectory("VirtualThreadTest");
tempClassesDirectory.toFile().deleteOnExit();
String outputFilePath = tempClassesDirectory.toString();

Bundle bundle = Platform.getBundle("org.eclipse.jdt.debug.jdi.tests");
URL bundleUrl = FileLocator.find(bundle, IPath.fromOSString("java19/TryVirtualThread.java"), null);
URL fileURL = FileLocator.toFileURL(bundleUrl);
String sourceFilePath = fileURL.getFile();
compileFiles(sourceFilePath, outputFilePath);
}

@Override
protected String enhanceClasspath(String classPath) {
return classPath + File.pathSeparator + tempClassesDirectory;
}

private static void compileFiles(String sourceFilePath, String outputPath) throws Exception {
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, Locale.ENGLISH, StandardCharsets.UTF_8);
Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(new File(sourceFilePath));
Expand Down

0 comments on commit 70049d8

Please sign in to comment.