Download openjdk sources for tests

This commit is contained in:
2025-03-29 00:44:30 +03:00
parent 1116758902
commit e782d88f37
4 changed files with 76 additions and 8 deletions

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@
/third-party/downloads/*
/third-party/**/*.jar
/src/test/resources/downloads/*
/*.jar
/docs

View File

@@ -1,6 +1,13 @@
import static notest.Test.Util.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import notest.Test;
class TestJtags {
@@ -18,10 +25,70 @@ class TestJtags {
Jtags,
"-o",
"-",
"src/test/java/examples/BasicExample.java");
"src/test/resources/BasicExample.java");
var tags = readAllLines(process.inputReader());
getSnapshot().assertEquals(tags);
}
static void downloadOpenjdkSources() throws IOException {
Path destination = Path.of("src", "test", "resources", "downloads");
if (Files.exists(destination.resolve("openjdk-src"))) return;
URL openjdkSrcZipURL =
URI.create("https://github.com/openjdk/jdk24u/archive/refs/tags/jdk-24+36.zip").toURL();
Path openjdkSrcZip = destination.resolve("jdk-24+36.zip");
if (!Files.exists(openjdkSrcZip)) {
System.err.println("Downloading openjdk sources jdk-24+36.zip (~118MB)...");
openjdkSrcZipURL
.openConnection()
.getInputStream()
.transferTo(Files.newOutputStream(openjdkSrcZip));
}
System.err.println("Extracting openjdk sources...");
Files.createDirectories(destination.resolve("openjdk-src"));
try (InputStream in = Files.newInputStream(openjdkSrcZip);
ZipInputStream zin = new ZipInputStream(in)) {
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
if (!entry.getName().startsWith("jdk24u-jdk-24-36/src/j")) {
zin.closeEntry();
entry = zin.getNextEntry();
continue;
}
Path entryPath =
destination.resolve(
"openjdk-src", entry.getName().substring("jdk24u-jdk-24-36/src/".length()));
if (entry.isDirectory()) {
Files.createDirectories(entryPath);
} else {
var bytes = zin.readAllBytes();
Files.write(entryPath, bytes);
}
zin.closeEntry();
}
}
}
@Test
static void openjdkSources() throws IOException {
downloadOpenjdkSources();
// var process =
// runJava(
// new String[] {"-Dlogger.level=CONFIG"},
// Jtags,
// Stream.concat(Stream.of("-o", "-"),
// Arrays.stream(glob("src/test/resources/downloads/**/.java")))
// .toArray(String[]::new));
// var tags = readAllLines(process.inputReader());
// getSnapshot().assertEquals(tags);
}
}

View File

@@ -1,9 +1,9 @@
ABC
!_TAG_FILE_ENCODING utf-8
!_TAG_FILE_SORTED 2 /0=unsorted, 1=sorted, 2=foldcase/
InnerClass src/test/java/examples/BasicExample.java /^ class InnerClass {$/;" Cls package:examples class:BasicExample
method1 src/test/java/examples/BasicExample.java /^ private boolean method1() {$/;" mthd class:BasicExample
method2 src/test/java/examples/BasicExample.java /^ void method2() {}$/;" mthd class:(Anonymous)
methodX src/test/java/examples/BasicExample.java /^ public static void method2($/;" mthd file: class:BasicExample
method3 src/test/java/examples/BasicExample.java /^ void method3() {}$/;" mthd class:InnerClass
method4 src/test/java/examples/BasicExample.java /^ private void method4() {}$/;" mthd class:InnerClass
BasicExample src/test/resources/BasicExample.java /^public class BasicExample {$/;" Cls package:examples
InnerClass src/test/resources/BasicExample.java /^ class InnerClass {$/;" Cls package:examples class:BasicExample
method1 src/test/resources/BasicExample.java /^ private boolean method1() {$/;" mthd class:BasicExample
method2 src/test/resources/BasicExample.java /^ void method2() {}$/;" mthd class:(Anonymous)
method2 src/test/resources/BasicExample.java /^ public static void method2($/;" mthd file: class:BasicExample
method3 src/test/resources/BasicExample.java /^ void method3() {}$/;" mthd class:InnerClass
method4 src/test/resources/BasicExample.java /^ private void method4() {}$/;" mthd class:InnerClass