Skip to content

Commit d2d9987

Browse files
committed
Copy all jars resolved by Gradle for ModularUserGuideTests
1 parent 8f2a49b commit d2d9987

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ dependencies {
5858
because("it uses the OS enum to support Windows")
5959
}
6060

61-
thirdPartyJars(libs.junit4)
61+
thirdPartyJars(libs.junit4) {
62+
exclude(group = "org.hamcrest")
63+
}
6264
thirdPartyJars(libs.assertj)
6365
thirdPartyJars(libs.apiguardian)
6466
thirdPartyJars(libs.hamcrest)

platform-tooling-support-tests/src/main/java/platform/tooling/support/ThirdPartyJars.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
1414

1515
import java.io.File;
16+
import java.io.IOException;
17+
import java.io.UncheckedIOException;
1618
import java.nio.file.Files;
1719
import java.nio.file.Path;
1820
import java.util.stream.Stream;
@@ -22,16 +24,34 @@ public class ThirdPartyJars {
2224
private ThirdPartyJars() {
2325
}
2426

25-
public static void copy(Path targetDir, String group, String artifact) throws Exception {
27+
public static void copy(Path targetDir, String group, String artifact) {
2628
Path source = find(group, artifact);
27-
Files.copy(source, targetDir.resolve(source.getFileName()), REPLACE_EXISTING);
29+
copy(source, targetDir);
30+
}
31+
32+
public static void copyAll(Path targetDir) {
33+
thirdPartyJars().forEach(path -> copy(path, targetDir));
34+
}
35+
36+
private static void copy(Path source, Path targetDir) {
37+
try {
38+
Files.copy(source, targetDir.resolve(source.getFileName()), REPLACE_EXISTING);
39+
}
40+
catch (IOException e) {
41+
throw new UncheckedIOException("Failed to copy %s to %s".formatted(source, targetDir), e);
42+
}
2843
}
2944

3045
public static Path find(String group, String artifact) {
31-
return Stream.of(System.getProperty("thirdPartyJars").split(File.pathSeparator)) //
32-
.filter(it -> it.replace(File.separator, "/").contains("/" + group + "/" + artifact + "/")) //
33-
.map(Path::of) //
46+
return thirdPartyJars() //
47+
.filter(it -> it.toAbsolutePath().toString().replace(File.separator, "/").contains(
48+
"/" + group + "/" + artifact + "/")) //
3449
.findFirst() //
3550
.orElseThrow(() -> new AssertionError("Failed to find JAR file for " + group + ":" + artifact));
3651
}
52+
53+
private static Stream<Path> thirdPartyJars() {
54+
return Stream.of(System.getProperty("thirdPartyJars").split(File.pathSeparator)) //
55+
.map(Path::of);
56+
}
3757
}

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ModularUserGuideTests.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,7 @@ private static List<String> compile(Path temp, Writer out, Writer err) throws Ex
8383
args.add(temp.resolve("destination").toString());
8484

8585
var lib = Files.createDirectories(temp.resolve("lib"));
86-
ThirdPartyJars.copy(lib, "junit", "junit");
87-
ThirdPartyJars.copy(lib, "org.assertj", "assertj-core");
88-
// Byte Buddy is used by AssertJ's soft assertions which are used by the Engine Test Kit
89-
ThirdPartyJars.copy(lib, "net.bytebuddy", "byte-buddy");
90-
ThirdPartyJars.copy(lib, "org.apiguardian", "apiguardian-api");
91-
ThirdPartyJars.copy(lib, "org.hamcrest", "hamcrest");
92-
ThirdPartyJars.copy(lib, "org.jspecify", "jspecify");
93-
ThirdPartyJars.copy(lib, "org.opentest4j", "opentest4j");
94-
ThirdPartyJars.copy(lib, "org.opentest4j.reporting", "open-test-reporting-tooling-spi");
95-
ThirdPartyJars.copy(lib, "com.google.jimfs", "jimfs");
96-
ThirdPartyJars.copy(lib, "com.google.guava", "guava");
97-
ThirdPartyJars.copy(lib, "com.google.guava", "failureaccess");
86+
ThirdPartyJars.copyAll(lib);
9887
loadAllJUnitModules(lib);
9988
args.add("--module-path");
10089
args.add(lib.toString());
@@ -161,31 +150,17 @@ void runTestsFromUserGuideWithinModularBoundaries(@TempDir Path temp,
161150
var err = new StringWriter();
162151

163152
var args = compile(temp, out, err);
164-
// args.forEach(System.out::println);
165153

166154
assertTrue(err.toString().isBlank(), () -> err + "\n\n" + String.join("\n", args));
167155
var listing = treeWalk(temp);
168156
assertLinesMatch(List.of( //
169157
"destination", //
170-
">> CLASSES >>", //
171-
"lib", //
172-
"lib/apiguardian-api-.+\\.jar", //
173-
"lib/assertj-core-.+\\.jar", //
174-
"lib/byte-buddy-.+", //
175-
"lib/failureaccess-.+\\.jar", //
176-
"lib/guava-.+\\.jar", //
177-
"lib/hamcrest-.+\\.jar", //
178-
"lib/jimfs-.+\\.jar", //
179-
"lib/jspecify-.+\\.jar", //
180-
"lib/junit-.+\\.jar", //
181-
">> ALL JUNIT 5 JARS >>", //
158+
">> CLASSES AND JARS >>", //
182159
"lib/opentest4j-.+\\.jar", //
183160
"src", //
184161
"src/documentation", //
185162
"src/documentation/module-info.java" //
186163
), listing);
187-
// System.out.println("______________");
188-
// listing.forEach(System.out::println);
189164

190165
junit(temp, outputFiles);
191166
}

0 commit comments

Comments
 (0)