) items).get(index);
- } else {
- var iter = items.iterator();
- for (var i = 0; i < index - 1; ++i) {
- iter.next();
- }
- return iter.next();
+ if (items instanceof List> list) {
+ return (T) list.get(index);
+ }
+
+ var iter = items.iterator();
+ for (var i = 0; i < index - 1; ++i) {
+ iter.next();
}
+ return iter.next();
}
/**
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java
index c853d656f..519a06ba3 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java
@@ -167,16 +167,13 @@ private static class LogRecord {
}
@Override
- public boolean equals(Object obj) {
- if (!(obj instanceof LogRecord)) {
- return false;
+ public boolean equals(Object other) {
+ if (other instanceof LogRecord that) {
+ return Objects.equals(ex, that.ex)
+ && Objects.equals(message, that.message)
+ && Arrays.deepEquals(args, that.args);
}
-
- var that = (LogRecord) obj;
-
- return Objects.equals(ex, that.ex)
- && Objects.equals(message, that.message)
- && Arrays.deepEquals(args, that.args);
+ return false;
}
@Override
From 799be90623921225407cabe33ec2927859180fe6 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Sat, 28 Dec 2024 15:53:51 +0000
Subject: [PATCH 10/19] Rejig RAM directory naming, add ability to dump tree
view of workspaces
---
.../ascopes/jct/workspaces/Workspace.java | 12 +++
.../jct/workspaces/impl/RamDirectoryImpl.java | 8 +-
.../jct/workspaces/impl/WorkspaceImpl.java | 99 ++++++++++++++++---
...BasicModuleCompilationIntegrationTest.java | 4 +
4 files changed, 107 insertions(+), 16 deletions(-)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java
index fd79edffe..416b15c4e 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java
@@ -17,6 +17,7 @@
import io.github.ascopes.jct.filemanagers.JctFileManager;
import io.github.ascopes.jct.filemanagers.ModuleLocation;
+import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.List;
@@ -109,6 +110,17 @@ public interface Workspace extends AutoCloseable {
@Override
void close();
+ /**
+ * Dump a visual representation of this workspace to the given appendable.
+ *
+ * This provides a utility method for debugging.
+ *
+ * @param appendable the appendable to write to.
+ * @throws UncheckedIOException if an IO error occurs when writing to the appendable.
+ * @since 5.0.0
+ */
+ void dump(Appendable appendable);
+
/**
* Determine if the workspace is closed or not.
*
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/RamDirectoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/RamDirectoryImpl.java
index 378ac273b..451990939 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/RamDirectoryImpl.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/RamDirectoryImpl.java
@@ -85,10 +85,10 @@ public static RamDirectoryImpl newRamDirectory(String name) {
assertValidRootName(name);
// MemoryFileSystem needs unique FS names to work correctly, so use a UUID to enforce this.
-
- var uniqueName = name + "-" + UUID.randomUUID();
- var fileSystem = MemoryFileSystemProvider.getInstance().createFileSystem(uniqueName);
- var path = fileSystem.getRootDirectories().iterator().next().resolve(uniqueName);
+ var fileSystem = MemoryFileSystemProvider.getInstance()
+ .createFileSystem(UUID.randomUUID().toString());
+ var path = fileSystem.getRootDirectories().iterator().next()
+ .resolve(name);
// Ensure the base directory exists.
uncheckedIo(() -> Files.createDirectories(path));
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
index 002f786b8..e3e07a542 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
@@ -20,12 +20,18 @@
import io.github.ascopes.jct.ex.JctIllegalInputException;
import io.github.ascopes.jct.filemanagers.ModuleLocation;
+import io.github.ascopes.jct.utils.IoExceptionUtils;
+import io.github.ascopes.jct.utils.ToStringBuilder;
import io.github.ascopes.jct.workspaces.ManagedDirectory;
import io.github.ascopes.jct.workspaces.PathRoot;
import io.github.ascopes.jct.workspaces.PathStrategy;
import io.github.ascopes.jct.workspaces.Workspace;
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -47,8 +53,9 @@
public final class WorkspaceImpl implements Workspace {
private volatile boolean closed;
+ private final String id;
private final PathStrategy pathStrategy;
- private final Map> paths;
+ private final Map> locations;
/**
* Initialise this workspace.
@@ -56,9 +63,10 @@ public final class WorkspaceImpl implements Workspace {
* @param pathStrategy the path strategy to use for creating source and target paths.
*/
public WorkspaceImpl(PathStrategy pathStrategy) {
+ id = UUID.randomUUID().toString();
closed = false;
this.pathStrategy = requireNonNull(pathStrategy, "pathStrategy");
- paths = new HashMap<>();
+ locations = new HashMap<>();
}
@Override
@@ -67,7 +75,7 @@ public void close() {
// Close everything in a best-effort fashion.
var exceptions = new ArrayList();
- for (var list : paths.values()) {
+ for (var list : locations.values()) {
for (var path : list) {
if (path instanceof AbstractManagedDirectory dir) {
try {
@@ -90,6 +98,64 @@ public void close() {
}
}
+ @Override
+ public void dump(Appendable appendable) {
+ IoExceptionUtils.uncheckedIo(() -> {
+ appendable.append(toString()).append("\n");
+ for (var location : locations.keySet().stream().sorted().toList()) {
+ appendable.append(" Location ").append(location.toString()).append(": \n");
+
+ for (var pathRoot : locations.get(location)) {
+ appendable.append(" - ").append(pathRoot.getUri().toString()).append(" contents:\n");
+
+ var baseIndent = 8;
+ var basePath = pathRoot.getPath();
+
+ Files.walkFileTree(basePath, new SimpleFileVisitor<>() {
+ private int indent = 0;
+
+ @Override
+ public FileVisitResult preVisitDirectory(
+ Path dir,
+ BasicFileAttributes attrs
+ ) throws IOException {
+ if (!dir.equals(basePath)) {
+ appendIndent();
+ appendable.append(dir.getFileName().toString()).append("/\n");
+ indent += 2;
+ }
+
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
+ indent -= 2;
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(
+ Path file,
+ BasicFileAttributes attrs
+ ) throws IOException {
+ appendIndent();
+ appendable.append(file.getFileName().toString()).append("\n");
+ return FileVisitResult.CONTINUE;
+ }
+
+ private void appendIndent() throws IOException {
+ appendable.append(" ".repeat(baseIndent))
+ .append("·".repeat(indent));
+ }
+ });
+ }
+
+ appendable.append("\n");
+ }
+ });
+ }
+
@Override
public boolean isClosed() {
return closed;
@@ -109,7 +175,7 @@ public void addPackage(Location location, Path path) {
}
var dir = new WrappingDirectoryImpl(path);
- paths.computeIfAbsent(location, unused -> new ArrayList<>()).add(dir);
+ locations.computeIfAbsent(location, unused -> new ArrayList<>()).add(dir);
}
@Override
@@ -139,13 +205,12 @@ public ManagedDirectory createPackage(Location location) {
throw new JctIllegalInputException("Location must not be module-oriented");
}
- // Needs to be unique, and JIMFS cannot hold a file system name containing stuff like
- // underscores.
+ // Needs to be unique.
var fsName = location.getName().replaceAll("[^A-Za-z0-9]", "")
+ UUID.randomUUID();
var dir = pathStrategy.newInstance(fsName);
- paths.computeIfAbsent(location, unused -> new ArrayList<>()).add(dir);
+ locations.computeIfAbsent(location, unused -> new ArrayList<>()).add(dir);
return dir;
}
@@ -170,9 +235,9 @@ public ManagedDirectory createModule(Location location, String moduleName) {
@Override
public Map> getAllPaths() {
// Create an immutable copy.
- var pathsCopy = new HashMap>();
- paths.forEach((location, list) -> pathsCopy.put(location, List.copyOf(list)));
- return unmodifiableMap(pathsCopy);
+ var locationsCopy = new HashMap>();
+ locations.forEach((location, list) -> locationsCopy.put(location, List.copyOf(list)));
+ return unmodifiableMap(locationsCopy);
}
@Override
@@ -205,7 +270,7 @@ public Map> getModules(Location location) {
var results = new HashMap>();
- paths.forEach((pathLocation, pathRoots) -> {
+ locations.forEach((pathLocation, pathRoots) -> {
if (pathLocation instanceof ModuleLocation modulePathLocation) {
if (modulePathLocation.getParent().equals(location)) {
results.computeIfAbsent(modulePathLocation.getModuleName(), name -> new ArrayList<>())
@@ -233,9 +298,19 @@ public List extends PathRoot> getPackages(Location location) {
);
}
- var roots = paths.get(location);
+ var roots = locations.get(location);
return roots == null
? List.of()
: List.copyOf(roots);
}
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this)
+ .attribute("id", id)
+ .attribute("pathStrategy", pathStrategy)
+ .attribute("closed", closed)
+ .attribute("numberOfLocations", locations.size())
+ .toString();
+ }
}
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
index 06cd8bf1f..38e80b8ae 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
@@ -48,6 +48,8 @@ void helloWorldRamDisk(JctCompiler compiler) {
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
+ workspace.dump(System.out);
+
assertThatCompilation(compilation)
.classOutputPackages()
.fileExists("com", "example", "HelloWorld.class")
@@ -72,6 +74,8 @@ void helloWorldUsingTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.out);
+
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
From 233702b0760db9c975329daf0f0c57910ea74752 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Sat, 28 Dec 2024 16:52:01 +0000
Subject: [PATCH 11/19] Improve workspace dumper implementation
---
.../jct/workspaces/impl/WorkspaceDumper.java | 110 ++++++++++++++++++
.../jct/workspaces/impl/WorkspaceImpl.java | 60 +---------
.../src/main/java/module-info.java | 1 +
...BasicLegacyCompilationIntegrationTest.java | 4 +
...BasicModuleCompilationIntegrationTest.java | 6 +-
...MultiModuleCompilationIntegrationTest.java | 8 ++
...mpilingSpecificClassesIntegrationTest.java | 2 +
...MultiTieredCompilationIntegrationTest.java | 12 ++
8 files changed, 141 insertions(+), 62 deletions(-)
create mode 100644 java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
new file mode 100644
index 000000000..d614a2401
--- /dev/null
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
@@ -0,0 +1,110 @@
+package io.github.ascopes.jct.workspaces.impl;
+
+import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
+
+import io.github.ascopes.jct.workspaces.PathRoot;
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+import java.util.Map;
+import javax.tools.JavaFileManager.Location;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Helper for dumping the structure of locations in a workspace for debugging purposes.
+ *
+ * This is not thread-safe.
+ *
+ * @author Ashley Scopes
+ * @since 5.0.0
+ */
+final class WorkspaceDumper {
+
+ private final Appendable appendable;
+
+ WorkspaceDumper(Appendable appendable) {
+ this.appendable = appendable;
+ }
+
+ void dump(String repr, Map> locations) {
+ uncheckedIo(() -> appendable.append("Workspace ").append(repr).append(":\n"));
+ locations.forEach(this::dumpLocation);
+ }
+
+ private void dumpLocation(Location location, List pathRoots) {
+ uncheckedIo(() -> appendable.append(" Location ").append(location.toString()).append(":\n"));
+ pathRoots.forEach(this::dumpPath);
+ }
+
+ private void dumpPath(PathRoot pathRoot) {
+ uncheckedIo(() -> {
+ appendable.append(" - ").append(pathRoot.getUri().toString()).append("\n");
+ try (var walker = new Walker(7)) {
+ Files.walkFileTree(pathRoot.getPath(), walker);
+ }
+ });
+ }
+
+ private final class Walker extends SimpleFileVisitor implements AutoCloseable {
+
+ private static final int INDENT_SIZE = 2;
+
+ private int index;
+ private int indent;
+
+ private Walker(int indent) {
+ index = 0;
+ this.indent = indent;
+ }
+
+ @Override
+ public void close() throws IOException {
+ // Only 1 index implies an empty directory.
+ if (index <= 1) {
+ doIndent();
+ appendable.append(" [[empty]]\n");
+ }
+ appendable.append("\n");
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(
+ Path dir,
+ BasicFileAttributes attrs
+ ) throws IOException {
+ if (index > 0) {
+ doIndent();
+ appendable.append(dir.getFileName().toString()).append("/\n");
+ indent += INDENT_SIZE;
+ }
+
+ ++index;
+ return super.preVisitDirectory(dir, attrs);
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(
+ Path dir,
+ @Nullable IOException ex
+ ) throws IOException {
+ indent -= INDENT_SIZE;
+ return super.postVisitDirectory(dir, ex);
+ }
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ doIndent();
+ appendable.append(file.getFileName().toString()).append("\n");
+ return super.visitFile(file, attrs);
+ }
+
+ private void doIndent() throws IOException {
+ appendable.append(" ".repeat(indent));
+ }
+ }
+}
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
index e3e07a542..4ab9bce99 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceImpl.java
@@ -20,18 +20,13 @@
import io.github.ascopes.jct.ex.JctIllegalInputException;
import io.github.ascopes.jct.filemanagers.ModuleLocation;
-import io.github.ascopes.jct.utils.IoExceptionUtils;
import io.github.ascopes.jct.utils.ToStringBuilder;
import io.github.ascopes.jct.workspaces.ManagedDirectory;
import io.github.ascopes.jct.workspaces.PathRoot;
import io.github.ascopes.jct.workspaces.PathStrategy;
import io.github.ascopes.jct.workspaces.Workspace;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -100,60 +95,7 @@ public void close() {
@Override
public void dump(Appendable appendable) {
- IoExceptionUtils.uncheckedIo(() -> {
- appendable.append(toString()).append("\n");
- for (var location : locations.keySet().stream().sorted().toList()) {
- appendable.append(" Location ").append(location.toString()).append(": \n");
-
- for (var pathRoot : locations.get(location)) {
- appendable.append(" - ").append(pathRoot.getUri().toString()).append(" contents:\n");
-
- var baseIndent = 8;
- var basePath = pathRoot.getPath();
-
- Files.walkFileTree(basePath, new SimpleFileVisitor<>() {
- private int indent = 0;
-
- @Override
- public FileVisitResult preVisitDirectory(
- Path dir,
- BasicFileAttributes attrs
- ) throws IOException {
- if (!dir.equals(basePath)) {
- appendIndent();
- appendable.append(dir.getFileName().toString()).append("/\n");
- indent += 2;
- }
-
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
- indent -= 2;
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult visitFile(
- Path file,
- BasicFileAttributes attrs
- ) throws IOException {
- appendIndent();
- appendable.append(file.getFileName().toString()).append("\n");
- return FileVisitResult.CONTINUE;
- }
-
- private void appendIndent() throws IOException {
- appendable.append(" ".repeat(baseIndent))
- .append("·".repeat(indent));
- }
- });
- }
-
- appendable.append("\n");
- }
- });
+ new WorkspaceDumper(appendable).dump(toString(), locations);
}
@Override
diff --git a/java-compiler-testing/src/main/java/module-info.java b/java-compiler-testing/src/main/java/module-info.java
index c720259c2..ce510b28c 100644
--- a/java-compiler-testing/src/main/java/module-info.java
+++ b/java-compiler-testing/src/main/java/module-info.java
@@ -129,6 +129,7 @@
requires static org.junit.jupiter.api;
requires static org.junit.jupiter.params;
requires org.slf4j;
+ requires java.desktop;
//////////////////
/// PUBLIC API ///
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
index 7a4d47fb7..f95348066 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
@@ -43,6 +43,8 @@ void helloWorldJavacRamDirectory(JctCompiler compiler) {
.copyContentsFrom(resourcesDirectory());
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
@@ -64,6 +66,8 @@ void helloWorldJavacTempDirectory(JctCompiler compiler) {
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
index 38e80b8ae..5bd203b83 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
@@ -44,12 +44,12 @@ void helloWorldRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
- workspace.dump(System.out);
-
assertThatCompilation(compilation)
.classOutputPackages()
.fileExists("com", "example", "HelloWorld.class")
@@ -74,7 +74,7 @@ void helloWorldUsingTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.out);
+ workspace.dump(System.err);
// Then
assertThatCompilation(compilation)
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
index 9dbf34106..8e705dc57 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
@@ -45,6 +45,8 @@ void singleModuleInMultiModuleLayoutRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()
@@ -73,6 +75,8 @@ void singleModuleInMultiModuleLayoutTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()
@@ -105,6 +109,8 @@ void multipleModulesInMultiModuleLayoutRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
@@ -151,6 +157,8 @@ void multipleModulesInMultiModuleLayoutTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
+ workspace.dump(System.err);
+
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
index c73f7f61e..f98386224 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
@@ -41,6 +41,8 @@ void onlyTheClassesSpecifiedGetCompiled(JctCompiler compiler) {
var compilation = compiler.compile(workspace, "Fibonacci", "HelloWorld");
+ workspace.dump(System.err);
+
assertThat(compilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
index 738b465d1..c8415a06b 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
@@ -49,6 +49,9 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilation(
.copyContentsFrom(resourcesDirectory().resolve("first"));
var firstCompilation = compiler.compile(firstWorkspace);
+
+ firstWorkspace.dump(System.err);
+
assertThatCompilation(firstCompilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
@@ -62,6 +65,9 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilation(
.copyContentsFrom(resourcesDirectory().resolve("second"));
var secondCompilation = compiler.compile(secondWorkspace);
+
+ secondWorkspace.dump(System.err);
+
assertThatCompilation(secondCompilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
@@ -88,6 +94,7 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJa
.copyContentsFrom(resourcesDirectory().resolve("first"));
var firstCompilation = compiler.compile(firstWorkspace);
+
assertThatCompilation(firstCompilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
@@ -100,6 +107,8 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJa
.createFile("first.jar")
.asJarFrom(firstWorkspace.getClassOutputPackages().get(0));
+ firstWorkspace.dump(System.err);
+
var firstJar = firstWorkspace.getClassOutputPackages().get(1).getPath().resolve("first.jar");
secondWorkspace.addClassPathPackage(firstJar);
secondWorkspace
@@ -107,6 +116,9 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJa
.copyContentsFrom(resourcesDirectory().resolve("second"));
var secondCompilation = compiler.compile(secondWorkspace);
+
+ secondWorkspace.dump(System.err);
+
assertThatCompilation(secondCompilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
From ec2b89c54c1d01c94e54afc7105ba12e6c5c140d Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Sat, 28 Dec 2024 17:30:12 +0000
Subject: [PATCH 12/19] Update license headers
---
.../jct/workspaces/impl/WorkspaceDumper.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
index d614a2401..f7284db34 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2022 - 2024, the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package io.github.ascopes.jct.workspaces.impl;
import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
From 3ff5ca5bd3e9970de19ee523621d1b92346b306d Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Sun, 29 Dec 2024 09:15:40 +0000
Subject: [PATCH 13/19] Update license headers to 2025
---
.../io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
index f7284db34..cad0e06e7 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 - 2024, the original author or authors.
+ * Copyright (C) 2022 - 2025, the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
From 3f6cf24fb46c687622593ecde3e6350ee8561a25 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Tue, 31 Dec 2024 14:43:13 +0000
Subject: [PATCH 14/19] Fix bug rendering file trees in workspaces
---
.../io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
index cad0e06e7..7bf3912da 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java
@@ -115,6 +115,7 @@ public FileVisitResult postVisitDirectory(
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
doIndent();
appendable.append(file.getFileName().toString()).append("\n");
+ ++index;
return super.visitFile(file, attrs);
}
From 8800432d4f8275e53d0009d7c68594c84af4cdf4 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Tue, 31 Dec 2024 14:44:01 +0000
Subject: [PATCH 15/19] Fix reliance on undefined behaviour for package naming
semantics in multi-tiered test
---
.../compilation/MultiTieredCompilationIntegrationTest.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
index c8415a06b..d46aa0bcf 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/MultiTieredCompilationIntegrationTest.java
@@ -91,6 +91,7 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJa
) {
firstWorkspace
.createSourcePathPackage()
+ .createDirectory("org", "example", "first")
.copyContentsFrom(resourcesDirectory().resolve("first"));
var firstCompilation = compiler.compile(firstWorkspace);
@@ -113,6 +114,7 @@ void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJa
secondWorkspace.addClassPathPackage(firstJar);
secondWorkspace
.createSourcePathPackage()
+ .createDirectory("org", "example", "second")
.copyContentsFrom(resourcesDirectory().resolve("second"));
var secondCompilation = compiler.compile(secondWorkspace);
From 72038a42bfb3d1e35f6140771249d746dc8fa7e3 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Tue, 31 Dec 2024 15:10:49 +0000
Subject: [PATCH 16/19] Remove more unneeded Collectors usages
---
.../ascopes/jct/assertions/JctCompilationAssert.java | 3 +--
.../jct/assertions/TraceDiagnosticListAssert.java | 2 +-
.../ascopes/jct/assertions/TypeAwareListAssert.java | 12 +++---------
.../containers/impl/PathWrappingContainerImpl.java | 3 +--
.../java/io/github/ascopes/jct/utils/FileUtils.java | 5 ++---
.../ascopes/jct/utils/SpecialLocationUtils.java | 3 +--
6 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctCompilationAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctCompilationAssert.java
index 620dc3f5c..03bf93423 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctCompilationAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctCompilationAssert.java
@@ -16,7 +16,6 @@
package io.github.ascopes.jct.assertions;
import static java.util.Objects.requireNonNull;
-import static java.util.stream.Collectors.toUnmodifiableList;
import io.github.ascopes.jct.compilers.JctCompilation;
import io.github.ascopes.jct.containers.ContainerGroup;
@@ -351,7 +350,7 @@ private AssertionError failWithDiagnostics(
.getDiagnostics()
.stream()
.filter(diagnostic -> kindsToDisplay.contains(diagnostic.getKind()))
- .collect(toUnmodifiableList());
+ .toList();
return failure(
"%s\n\nDiagnostics:\n%s",
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
index 2009ffbe5..ab5e330a7 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
@@ -294,7 +294,7 @@ public TraceDiagnosticListAssert hasNoDiagnosticsOfKinds(Iterable kinds) {
var actualDiagnostics = actual
.stream()
.filter(kindIsOneOf(kinds))
- .collect(toUnmodifiableList());
+ .toList();
if (actualDiagnostics.isEmpty()) {
return myself;
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
index b4ffa144f..7a708825b 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
@@ -15,11 +15,7 @@
*/
package io.github.ascopes.jct.assertions;
-import static java.util.stream.Collectors.collectingAndThen;
-import static java.util.stream.Collectors.toList;
-
import java.util.List;
-import java.util.function.Function;
import java.util.stream.StreamSupport;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractListAssert;
@@ -60,12 +56,10 @@ protected A toAssert(@Nullable E value, String description) {
protected TypeAwareListAssert<@Nullable E, A> newAbstractIterableAssert(
Iterable extends @Nullable E> iterable
) {
- return StreamSupport
+ var list = StreamSupport
.stream(iterable.spliterator(), false)
- .collect(collectingAndThen(toList(), curry()));
- }
+ .toList();
- private Function<@Nullable List<@Nullable E>, TypeAwareListAssert<@Nullable E, A>> curry() {
- return list -> new TypeAwareListAssert<>(list, assertFactory);
+ return new TypeAwareListAssert<>(list, assertFactory);
}
}
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/PathWrappingContainerImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/PathWrappingContainerImpl.java
index a5980c200..8fa00e16b 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/PathWrappingContainerImpl.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/PathWrappingContainerImpl.java
@@ -31,7 +31,6 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.Set;
-import java.util.stream.Collectors;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
@@ -160,7 +159,7 @@ public String inferBinaryName(PathFileObject javaFileObject) {
@Override
public Collection listAllFiles() throws IOException {
try (var walker = Files.walk(root.getPath(), FileVisitOption.FOLLOW_LINKS)) {
- return walker.collect(Collectors.toUnmodifiableList());
+ return walker.toList();
}
}
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java
index a2fec6804..16ee36c00 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java
@@ -16,7 +16,6 @@
package io.github.ascopes.jct.utils;
import static io.github.ascopes.jct.utils.IterableUtils.requireAtLeastOne;
-import static java.util.stream.Collectors.toUnmodifiableList;
import io.github.ascopes.jct.ex.JctIllegalInputException;
import java.net.MalformedURLException;
@@ -47,7 +46,7 @@ public final class FileUtils extends UtilityClass {
private static final List KINDS = Stream
.of(Kind.values())
.filter(kind -> !kind.extension.isEmpty())
- .collect(toUnmodifiableList());
+ .toList();
private static final StringSlicer PACKAGE_SLICER = new StringSlicer(".");
private static final StringSlicer RESOURCE_SLICER = new StringSlicer("/");
@@ -254,7 +253,7 @@ public static Path resourceNameToPath(Path directory, String packageName, String
/**
* Convert a relative class path resource path to a NIO path.
*
- * @param directory the directory the resource sits within.
+ * @param directory the directory the resource sits within.
* @param pathFragments the path fragments to put together.
* @return the path to the resource on the file system.
*/
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java
index 84c0c6e10..63058b634 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java
@@ -22,7 +22,6 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -116,7 +115,7 @@ private static List createPaths(String raw) {
// src/main/java do not exist.
.distinct()
.filter(Files::exists)
- .collect(Collectors.toUnmodifiableList());
+ .toList();
}
private static boolean isNotBlank(String string) {
From 2ce352e44bcf9dd574012c43dbbffb3967149b1d Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Tue, 31 Dec 2024 15:23:23 +0000
Subject: [PATCH 17/19] Remove diagnostic dumping
---
.../BasicLegacyCompilationIntegrationTest.java | 4 ----
.../BasicModuleCompilationIntegrationTest.java | 4 ----
.../BasicMultiModuleCompilationIntegrationTest.java | 8 --------
.../CompilingSpecificClassesIntegrationTest.java | 2 --
4 files changed, 18 deletions(-)
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
index f95348066..7a4d47fb7 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicLegacyCompilationIntegrationTest.java
@@ -43,8 +43,6 @@ void helloWorldJavacRamDirectory(JctCompiler compiler) {
.copyContentsFrom(resourcesDirectory());
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
@@ -66,8 +64,6 @@ void helloWorldJavacTempDirectory(JctCompiler compiler) {
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
index 5bd203b83..06cd8bf1f 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicModuleCompilationIntegrationTest.java
@@ -44,8 +44,6 @@ void helloWorldRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
@@ -74,8 +72,6 @@ void helloWorldUsingTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
index 8e705dc57..9dbf34106 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/BasicMultiModuleCompilationIntegrationTest.java
@@ -45,8 +45,6 @@ void singleModuleInMultiModuleLayoutRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()
@@ -75,8 +73,6 @@ void singleModuleInMultiModuleLayoutTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()
@@ -109,8 +105,6 @@ void multipleModulesInMultiModuleLayoutRamDisk(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
@@ -157,8 +151,6 @@ void multipleModulesInMultiModuleLayoutTempDirectory(JctCompiler compiler) {
// When
var compilation = compiler.compile(workspace);
- workspace.dump(System.err);
-
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings();
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
index f98386224..c73f7f61e 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/integration/compilation/CompilingSpecificClassesIntegrationTest.java
@@ -41,8 +41,6 @@ void onlyTheClassesSpecifiedGetCompiled(JctCompiler compiler) {
var compilation = compiler.compile(workspace, "Fibonacci", "HelloWorld");
- workspace.dump(System.err);
-
assertThat(compilation)
.isSuccessfulWithoutWarnings()
.classOutputPackages()
From ca86022ffc34b2f55e1675ff0bda18cafaf30736 Mon Sep 17 00:00:00 2001
From: Ashley Scopes <73482956+ascopes@users.noreply.github.com>
Date: Mon, 6 Jan 2025 07:32:39 +0000
Subject: [PATCH 18/19] Use Java 17 ServiceLoader#stream in
AbstractContainerGroupAssert
---
.../AbstractContainerGroupAssert.java | 8 +++----
.../assertions/TraceDiagnosticListAssert.java | 3 ++-
.../jct/assertions/TypeAwareListAssert.java | 5 +----
.../AbstractContainerGroupAssertTest.java | 22 ++++++++++++++++++-
4 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssert.java
index a44af6e34..6dd6e0a43 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssert.java
@@ -19,8 +19,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import io.github.ascopes.jct.containers.ContainerGroup;
-import java.util.ArrayList;
import java.util.List;
+import java.util.ServiceLoader;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractListAssert;
import org.assertj.core.api.ObjectAssert;
@@ -74,9 +74,9 @@ public LocationAssert location() {
requireNonNull(type, "type must not be null");
isNotNull();
- var items = new ArrayList();
- actual.getServiceLoader(type).iterator().forEachRemaining(items::add);
-
+ var items = actual.getServiceLoader(type)
+ .stream()
+ .map(ServiceLoader.Provider::get);
return assertThat(items);
}
}
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
index ab5e330a7..2fa1aeaab 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TraceDiagnosticListAssert.java
@@ -353,7 +353,8 @@ protected TraceDiagnosticListAssert newAbstractIterableAssert(
}
private Predicate<@Nullable TraceDiagnostic extends JavaFileObject>> kindIsOneOf(
- Iterable kinds) {
+ Iterable kinds
+ ) {
var kindsSet = new LinkedHashSet();
kinds.forEach(kindsSet::add);
diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
index 7a708825b..72f82c12a 100644
--- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
+++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/TypeAwareListAssert.java
@@ -56,10 +56,7 @@ protected A toAssert(@Nullable E value, String description) {
protected TypeAwareListAssert<@Nullable E, A> newAbstractIterableAssert(
Iterable extends @Nullable E> iterable
) {
- var list = StreamSupport
- .stream(iterable.spliterator(), false)
- .toList();
-
+ var list = StreamSupport.stream(iterable.spliterator(), false).toList();
return new TypeAwareListAssert<>(list, assertFactory);
}
}
diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssertTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssertTest.java
index 53fc26cc0..01a6c9fc8 100644
--- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssertTest.java
+++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssertTest.java
@@ -27,6 +27,7 @@
import io.github.ascopes.jct.containers.ContainerGroup;
import java.util.List;
import java.util.ServiceLoader;
+import java.util.stream.Stream;
import org.assertj.core.api.AbstractListAssert;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.DisplayName;
@@ -117,7 +118,8 @@ void servicesReturnsListAssertionAcrossTheAvailableServices() {
var impl3 = mock(SomeServiceType.class);
ServiceLoader serviceLoader = mock();
- when(serviceLoader.iterator()).then(ctx -> List.of(impl1, impl2, impl3).iterator());
+ when(serviceLoader.stream()).then(ctx -> Stream.of(impl1, impl2, impl3)
+ .map(ServiceLoaderProvider::new));
var containerGroup = mock(ContainerGroup.class);
when(containerGroup.getServiceLoader(any())).then(ctx -> serviceLoader);
@@ -148,4 +150,22 @@ static final class AssertionImpl
super(containerGroup, AssertionImpl.class);
}
}
+
+ static class ServiceLoaderProvider implements ServiceLoader.Provider {
+ private final T service;
+
+ ServiceLoaderProvider(T service) {
+ this.service = service;
+ }
+
+ @Override
+ public T get() {
+ return service;
+ }
+
+ @Override
+ public Class extends T> type() {
+ return (Class) service.getClass();
+ }
+ }
}
From fe404c9307300e8f56b85fc82134613b278e2e9d Mon Sep 17 00:00:00 2001
From: Ashley <73482956+ascopes@users.noreply.github.com>
Date: Mon, 10 Mar 2025 06:30:46 +0000
Subject: [PATCH 19/19] Update to AssertJ 4.0.0-M1 (#790)
See
https://github.com/assertj/assertj/issues/2573\#issuecomment-2709477791
---------
Signed-off-by: Ashley <73482956+ascopes@users.noreply.github.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 59e3979fb..99853018f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,7 +94,7 @@
- 3.27.3
+ 4.0.0-M1
4.3.0
1.4.0
1.0.0