Skip to content

Commit

Permalink
[test] remove Java source level 1.5 workaround
Browse files Browse the repository at this point in the history
to avoid warnings in build output

#2975
  • Loading branch information
EcljpseB0T committed Sep 18, 2024
1 parent a431ff8 commit 033e0ca
Showing 1 changed file with 6 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.io.*;
import java.lang.ref.Cleaner;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Verifies that the .class files resulting from a compilation can be loaded
Expand Down Expand Up @@ -377,7 +377,7 @@ public String getExecutionError(){
* {@link #READ_VERIFY_TEST_FROM_FILE} after calling this method for the first time, the return value will not change
* anymore.
*
* @return {@link VerifyTests} source code, filtered by {@link #filterSourceCode(Stream)}
* @return {@link VerifyTests} source code
*/
String getVerifyTestsCode() {
synchronized (verifyTestCodeLock) {
Expand All @@ -387,8 +387,8 @@ String getVerifyTestsCode() {
if (!new File(sourceFile).exists()) {
sourceFile = PROJECT_BASE_DIR + "/org.eclipse.jdt.core.tests.compiler/" + sourceFile;
}
try (BufferedReader reader = new BufferedReader(new FileReader(sourceFile))) {
verifyTestCode = filterSourceCode(reader.lines());
try {
verifyTestCode=Files.readString(Path.of(sourceFile));
}
catch (IOException e) {
System.out.println("WARNING: Cannot read & filter VerifyTests source code from file, using default value");
Expand All @@ -397,35 +397,12 @@ String getVerifyTestsCode() {
}
}
if (verifyTestCode == null) {
try (BufferedReader reader = new BufferedReader(new StringReader(VERIFY_TEST_CODE_DEFAULT))) {
verifyTestCode = filterSourceCode(reader.lines());
}
catch (IOException e) {
System.out.println("WARNING: Cannot filter VerifyTests source code default value, using unfiltered value");
System.out.println(" - exception: " + e);
verifyTestCode = VERIFY_TEST_CODE_DEFAULT;
}
verifyTestCode = VERIFY_TEST_CODE_DEFAULT;
}
return verifyTestCode;
}
}

/**
* Filter some elements incompatible with Java source level 1.5 from source code
* <p>
* This method cannot convert things like catch-with-resources or other language elements back to Java 1.5, you have to
* take care of keeping the source code backward compatible by yourself. But a few things you can still use in the
* source code, such as {@code @SuppressWarnings}, {@code @Override} in interfaces or single-line {@code assert}.
*
* @param sourceCodeLines stream of source code lines
* @return filtered source code file as a string
*/
private String filterSourceCode(Stream<String> sourceCodeLines) {
return sourceCodeLines
.filter(s -> !(s.contains("@SuppressWarnings") || s.contains("@Override") || s.contains("assert ")))
.collect(Collectors.joining("\n"));
}

/**
* Remove non-essential parts of the test JVM classpath
* <p>
Expand Down

0 comments on commit 033e0ca

Please sign in to comment.