Skip to content

Commit

Permalink
Cleanup VirtualThreadTest
Browse files Browse the repository at this point in the history
- enable-preview not needed anymore
- don't hide exceptions
- use nio to create directories
- added more info about compiler used to compile program

See #503
  • Loading branch information
iloveeclipse committed Sep 23, 2024
1 parent 32fa010 commit 8ddcb8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.jdi.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JDI Tests
Bundle-SymbolicName: org.eclipse.jdt.debug.jdi.tests; singleton:=true
Bundle-Version: 1.1.100.qualifier
Bundle-Version: 1.1.200.qualifier
Bundle-ClassPath: .
Bundle-Vendor: Eclipse
Require-Bundle: org.junit,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.jdi.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.debug.jdi.tests</artifactId>
<version>1.1.100-SNAPSHOT</version>
<version>1.1.200-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
package org.eclipse.debug.jdi.tests;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;

Expand Down Expand Up @@ -56,10 +58,6 @@ public class VirtualThreadTest extends AbstractJDITest {
private ThreadReference fThread;
private ThreadReference fMainThread;

public VirtualThreadTest() {
fVmArgs = "--enable-preview";
}

/**
* Init the fields that are used by this test only.
*/
Expand All @@ -82,7 +80,13 @@ public void localTearDown() {

@Override
protected void setUp() {
compileTestProgram();
try {
compileTestProgram();
} catch (Exception e) {
StringWriter err = new StringWriter();
e.printStackTrace(new PrintWriter(err));
fail("Error in setup: " + err.toString());
}
super.setUp();
}

Expand All @@ -91,12 +95,12 @@ public void setVMInfo(VMInformation info) {
// do nothing
}

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

protected static void compileTestProgram() {
protected static void compileTestProgram() throws Exception {
if (Runtime.version().feature() < 19) {
return;
}
Expand All @@ -106,20 +110,21 @@ protected static void compileTestProgram() {
compileFiles(sourceFilePath, outputFilePath);
}

private static void compileFiles(String sourceFilePath, String outputPath) {
private static void compileFiles(String sourceFilePath, String outputPath) throws Exception {
DiagnosticCollector<? super JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, StandardCharsets.UTF_8);
Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(new File(sourceFilePath));
File outputFolder = new File(outputPath);
if (!outputFolder.exists()) {
outputFolder.mkdir();
Files.createDirectories(outputFolder.toPath());
}
String[] options = new String[] { "--release", "21", "-d", outputFolder.getAbsolutePath(), "-g", "-proc:none" };
final StringWriter output = new StringWriter();
CompilationTask task = compiler.getTask(output, fileManager, diagnosticCollector, Arrays.asList(options), null, javaFileObjects);
boolean result = task.call();
if (!result) {
throw new IllegalArgumentException("Compilation failed:\n" + output);
throw new IllegalArgumentException("Compilation failed:\n'" + output + "', compiler name: '" + compiler.name()
+ "', supported source versions: " + compiler.getSourceVersions());
}

}
Expand Down

0 comments on commit 8ddcb8f

Please sign in to comment.