From 0b1d2d7cebf2e70590366053bea026e0e0dbffcf Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 13:39:20 +0000 Subject: [PATCH 01/19] Bump project to run on a minimum of Java 17 --- .github/workflows/build.yml | 1 - .github/workflows/codeql.yml | 4 +- .github/workflows/deploy.yml | 1 - .github/workflows/security.yml | 1 + .github/workflows/validate.yml | 29 ----- CONTRIBUTING.md | 104 ++++++------------ README.md | 6 +- .../src/it/checkerframework/pom.xml | 13 --- .../src/it/google-error-prone/pom.xml | 13 --- java-compiler-testing/src/it/spring/pom.xml | 12 -- pom.xml | 2 +- 11 files changed, 42 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/validate.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ef361a95..f277507cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,6 @@ jobs: matrix: os-name: [ubuntu-latest] java-version: - - 11 # LTS - 17 # LTS - 21 # LTS - GA # General access diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f0bfde4cf..b79cb525c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -3,12 +3,14 @@ on: pull_request: branches: - main + - v5 types: - opened - synchronize push: branches: - main + - v5 workflow_call: {} workflow_dispatch: {} @@ -18,7 +20,7 @@ jobs: runs-on: ubuntu-latest concurrency: - group: codeql-codeql-${{ github.head_ref || github.run_id }} + group: codeql-${{ github.head_ref || github.run_id }} cancel-in-progress: true permissions: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a51143d37..e356762c6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,7 +35,6 @@ jobs: uses: actions/setup-java@v4 with: distribution: zulu - # Must use >= JDK 17 for Javadocs to generate correctly java-version: 23 server-id: ossrh server-username: OSSRH_USERNAME diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 365c0097f..2b8493db8 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - v5 jobs: submit-dependency-snapshot: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index 3fded06fc..000000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Validate configuration - -on: - push: - branches: [ "main" ] - pull_request: - branches: - - main - workflow_call: {} - workflow_dispatch: {} - -jobs: - build: - name: Validate configuration - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master - with: - check_together: 'yes' - scandir: './scripts' - - - name: Validate codecov.yml - shell: bash - run: curl -vvv --fail --data-binary @- https://codecov.io/validate < codecov.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8b13b797..1e730281c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,56 +1,34 @@ # Contribution guidelines and info -Hi! Thanks for taking an interest in this project! -If you would like to contribute, then help is always -welcome however big or small! +Hi! Thanks for taking an interest in this project! If you would like to contribute, then help is +always welcome however big or small! ## Finding something to contribute -If you are new and would like to pick something up, -check the issues tab to see if anything is of interest. -If you want further clarification, feel free to drop a -comment. +If you are new and would like to pick something up, check the issues tab to see if anything is of +interest. If you want further clarification, feel free to drop a comment. > [!TIP] > You could alternatively add a message on the discussions > tab! -Contributions do not necessarily need to be code changes -either. You can also contribute by: +Contributions do not necessarily need to be code changes either. You can also contribute by: -- Testing this project out for yourself and discussing any - feedback on the discussions page. +- Testing this project out for yourself and discussing any feedback on the discussions page. - Fixing and improving documentation. - Contributing new Wiki pages. - Raising bugs in the issue tab. -## Raising issues - -If raising an issue, please make sure that you include -some details such as: - -- The problem in a short description. -- What do you expect to happen? -- What actually happens? -- How did you reproduce this (if applicable)? -- What JDK you are using -- What OS you are using - -If these are not relevant to you, then they can be -ignored. - ## Getting help -Please make a discussion in the discussions tab rather -than opening a new issue if you need help with using this library. +Please make a discussion in the discussions tab rather than opening a new issue if you need help +with using this library. ## Contributing changes to fix issues -If you are contributing to an issue, drop a message on -that issue so that I can assign it to you! **If you would be -able to keep me up to date with any progress on that issue, -that would be fantastic**, since it enables me to track -how much work is left to do and to be able to provide any +If you are contributing to an issue, drop a message on that issue so that I can assign it to you! +**If you would be able to keep me up to date with any progress on that issue, that would be +fantastic**, since it enables me to track how much work is left to do and to be able to provide any help if needed. Everyone is entitled to their own life, but if I haven't heard anything back for a while, @@ -62,22 +40,18 @@ but never actually finished. ## Branching -When you are ready, make a fork of this repo. When you -work on your fork, make sure you create a new branch to -work off of rather than committing to your master/main -branch. This will make it easier for you to update your -copy with any new changes to this project, and avoid -filling pull requests with lots of messy merge commits -unnecessarily! +When you are ready, make a fork of this repo. When you work on your fork, make sure you create +a new branch to work off of rather than committing to your master/main branch. This will make it +easier for you to update your copy with any new changes to this project, and avoid filling pull +requests with lots of messy merge commits unnecessarily! ## Building this project > [!IMPORTANT] > This project uses Apache Maven as the build system, and -> requires JDK 11 or newer. +> requires JDK 17 or newer. -To build this project and run the tests, you can run the -following in your terminal: +To build this project and run the tests, you can run the following in your terminal: ```bash # Linux, Mac OS, Git Bash users @@ -87,25 +61,20 @@ following in your terminal: .\mvnw.cmd clean package verify ``` -If you use Windows, you should download the JDK from -somewhere such as https://adoptium.net/en-GB/temurin/. +If you use Windows, you should download the JDK from somewhere such as +https://adoptium.net/en-GB/temurin/. -On Linux and MacOS, I tend to use a tool called -[SDKMan](https://sdkman.io/) to download and install -Java tooling. I personally use Amazon Corretto 17, but -you can use any JDK implementation you like, such as -Temurin, Graal, Liberica, SAP, etc. All should work +On Linux and macOS, I tend to use a tool called [SDKMan](https://sdkman.io/) +to download and install Java tooling. I personally use Amazon Corretto, but you can use any JDK +implementation you like, such as Temurin, Graal, Liberica, SAP, etc. All should work the same for the most part. ## Licensing -All changes that you make will be applied under the -Apache license, as documented in this repository. -You can find out more about what this means at -[TLDRLegal](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))! +All changes that you make will be applied under the Apache license, as documented in this +repository. You can find out more about what this means at [TLDRLegal](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))! -Each file that you create must have a special header -comment at the top that mentions this license. +Each file that you create must have a special header comment at the top that mentions this license. > [!TIP] > If you need to add this header to your files, you can run @@ -113,9 +82,8 @@ comment at the top that mentions this license. ## Code style -This project uses a modified version of the Google -Code Style guide for Java. The main things to remember -are: +This project uses a modified version of the Google Code Style guide for Java. The main things to +remember are: - 2-space indentation rather than tabs - Public classes and methods need a JavaDoc @@ -123,9 +91,8 @@ are: Good things to remember: -- Keep lines of code simple. It is fine to use multiple - lines of code to declare something if it makes it easier - to read. +- Keep lines of code simple. It is fine to use multiple lines of code to declare something if it +- makes it easier to read. - Keep naming clear and simple! A tool called CheckStyle will attempt to enforce these rules @@ -136,10 +103,9 @@ for you. ## Commits -Please try to keep commits atomic and clear. Each commit -should ideally leave the project in a working state. Each -commit should also have a clear title and explaination as -to what the commit changes, and why. +Please try to keep commits atomic and clear. Each commit should ideally leave the project in a +working state. Each commit should also have a clear title and explanation as to what the commit +changes, and why. ## Deployment process @@ -153,6 +119,6 @@ Changelogs are automatically generated from the pull request history between the `main` branch and the last tag that was added. This is why it is important to have descriptive pull requests where appropriate. -Upon successfully deploying to Maven Central, a release will be added to the -[releases](../../releases) page on the repository. A changelog will automatically get -attached and any contributors will be `@mentioned` in those changelogs. +Upon successfully deploying to Maven Central, a release will be added to the [releases](../../releases) +page on the repository. A changelog will automatically get attached and any contributors will be +`@mentioned` in those changelogs. diff --git a/README.md b/README.md index 626bd7a63..1a1f2b518 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Java 11+](https://img.shields.io/badge/Java-11--24-brown?logo=openjdk&logoColor=white) +![Java 17+](https://img.shields.io/badge/Java-17%2B-brown?logo=openjdk&logoColor=white) [![Build Status](https://github.com/ascopes/java-compiler-testing/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/ascopes/java-compiler-testing/actions/workflows/build.yml) [![Maven Central](https://img.shields.io/maven-central/v/io.github.ascopes.jct/java-compiler-testing)](https://repo1.maven.org/maven2/io/github/ascopes/jct/java-compiler-testing) [![Code Coverage](https://codecov.io/gh/ascopes/java-compiler-testing/branch/main/graph/badge.svg?token=VT74BP2742)](https://codecov.io/gh/ascopes/java-compiler-testing) @@ -331,9 +331,7 @@ holding the flags you wish to use. `-XX:+TieredCompilation -XX:TieredStopAtLevel=1` to set this up. Enabling this in the JCT builds reduced the overall build time by around 20 seconds. 2. Use the ZGC - the ZGC will reduce lag when performing garbage collection on code that - has a high churn of objects. On Java 11, the ZGC is an experimental feature, which needs - to be enabled with `-XX:+UnlockExperimentalOptions -XX:+UseZGC`. On Java 17, you just - need to pass `-XX:+UseZGC` alone. + has a high churn of objects. You just need to pass `-XX:+UseZGC` alone. ## Third-party compiler support diff --git a/java-compiler-testing/src/it/checkerframework/pom.xml b/java-compiler-testing/src/it/checkerframework/pom.xml index bbb6aa696..55ca0a419 100644 --- a/java-compiler-testing/src/it/checkerframework/pom.xml +++ b/java-compiler-testing/src/it/checkerframework/pom.xml @@ -98,17 +98,4 @@ - - - - ${project.artifactId}-incompatible-jdk - - - 16 - - - true - - - diff --git a/java-compiler-testing/src/it/google-error-prone/pom.xml b/java-compiler-testing/src/it/google-error-prone/pom.xml index c044da072..1277358b2 100644 --- a/java-compiler-testing/src/it/google-error-prone/pom.xml +++ b/java-compiler-testing/src/it/google-error-prone/pom.xml @@ -89,17 +89,4 @@ - - - - - ${project.artifactId}-incompatible-jdk - - [,12) - - - true - - - diff --git a/java-compiler-testing/src/it/spring/pom.xml b/java-compiler-testing/src/it/spring/pom.xml index 1b74e3906..3eaba010c 100644 --- a/java-compiler-testing/src/it/spring/pom.xml +++ b/java-compiler-testing/src/it/spring/pom.xml @@ -108,16 +108,4 @@ - - - - ${project.artifactId}-incompatible-jdk - - [,17) - - - true - - - diff --git a/pom.xml b/pom.xml index a272ca3b0..59e3979fb 100644 --- a/pom.xml +++ b/pom.xml @@ -160,7 +160,7 @@ UTF-8 - 11 + 17 2025 From eba91323afab28da01ee0e550a83ae2d76c6fdb7 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 13:59:23 +0000 Subject: [PATCH 02/19] Fix test failures on Java 17 --- .../jct/junit/AbstractCompilersProviderTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java index e174176f7..c85667795 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java @@ -22,6 +22,7 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockConstruction; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.withSettings; @@ -30,6 +31,7 @@ import io.github.ascopes.jct.compilers.JctCompilerConfigurer; import io.github.ascopes.jct.ex.JctIllegalInputException; import io.github.ascopes.jct.ex.JctJunitConfigurerException; +import io.github.ascopes.jct.fixtures.Fixtures; import java.lang.reflect.InvocationTargetException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -98,13 +100,14 @@ void configuringTheProviderWithNullVersionStrategyWillRaiseException() { void configuringTheProviderWithVersionStrategyUsesThatStrategy() { // Given var provider = new CompilersProviderImpl(8, 17); - var versionStrategy = mock(VersionStrategy.class); + // Mockito refuses to mock enums past Java 17, but we _can_ still spy on them. + var versionStrategy = spy(Fixtures.oneOf(VersionStrategy.class)); // When provider.configureInternals(10, 15, versionStrategy); var compilers = provider.provideArguments(mock(ExtensionContext.class)) .map(args -> (JctCompiler) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then for (var i = 0; i < compilers.size(); ++i) { @@ -121,7 +124,8 @@ void configuringTheProviderWithVersionStrategyUsesThatStrategy() { void configuringTheProviderRespectsTheMinimumVersionBound() { // Given var provider = new CompilersProviderImpl(15, 17); - var versionStrategy = mock(VersionStrategy.class); + // Mockito refuses to mock enums past Java 17, but we _can_ still spy on them. + var versionStrategy = spy(Fixtures.oneOf(VersionStrategy.class)); // When provider.configureInternals(10, 17, versionStrategy); @@ -144,7 +148,8 @@ void configuringTheProviderRespectsTheMinimumVersionBound() { void configuringTheProviderRespectsTheMaximumVersionBound() { // Given var provider = new CompilersProviderImpl(15, 17); - var versionStrategy = mock(VersionStrategy.class); + // Mockito refuses to mock enums past Java 17, but we _can_ still spy on them. + var versionStrategy = spy(Fixtures.oneOf(VersionStrategy.class)); // When provider.configureInternals(15, 20, versionStrategy); From bc1f17771c66bc9cc9eeb22b57c552ee2a6b8648 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:01:53 +0000 Subject: [PATCH 03/19] Remove usages of Collectors.toList() --- .../jct/compilers/impl/JctCompilationFactoryImpl.java | 3 +-- .../java/io/github/ascopes/jct/ex/package-info.java | 2 -- .../ascopes/jct/filemanagers/config/package-info.java | 2 -- .../ascopes/jct/junit/AbstractCompilersProvider.java | 1 - .../java/io/github/ascopes/jct/utils/StringUtils.java | 3 +-- .../ascopes/jct/utils/VisibleForTestingOnly.java | 1 - .../compilers/impl/JavacJctFlagBuilderImplTest.java | 11 +++++------ .../compilers/impl/JctCompilationFactoryImplTest.java | 3 +-- .../jct/compilers/impl/JctCompilationImplTest.java | 6 +++--- .../jct/filemanagers/impl/JctFileManagerImplTest.java | 2 +- .../java/io/github/ascopes/jct/fixtures/Fixtures.java | 3 +-- .../jct/junit/AbstractCompilersProviderTest.java | 7 +++---- .../ascopes/jct/junit/JavacCompilersProviderTest.java | 7 +++---- .../ascopes/jct/utils/SpecialLocationsUtilsTest.java | 2 +- .../io/github/ascopes/jct/utils/StringSlicerTest.java | 3 +-- .../impl/MemoryFileSystemProviderImplTest.java | 3 +-- 16 files changed, 22 insertions(+), 37 deletions(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java index 56fbd2a15..fd5246852 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java @@ -16,7 +16,6 @@ package io.github.ascopes.jct.compilers.impl; import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.toList; import io.github.ascopes.jct.compilers.JctCompilation; import io.github.ascopes.jct.compilers.JctCompilationFactory; @@ -139,7 +138,7 @@ public JctCompilation createCompilation( .arguments(flags) .compilationUnits(Set.copyOf(compilationUnits)) .fileManager(fileManager) - .outputLines(writer.getContent().lines().collect(toList())) + .outputLines(writer.getContent().lines().toList()) .diagnostics(diagnosticListener.getDiagnostics()) .success(success) .failOnWarnings(compiler.isFailOnWarnings()) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/package-info.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/package-info.java index 17205b6f8..8f71a291b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/package-info.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/ex/package-info.java @@ -18,5 +18,3 @@ */ package io.github.ascopes.jct.ex; -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/package-info.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/package-info.java index efb0deced..5ef8b61f2 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/package-info.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/package-info.java @@ -18,5 +18,3 @@ */ package io.github.ascopes.jct.filemanagers.config; -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java index b9df70e34..650e46332 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java @@ -23,7 +23,6 @@ import io.github.ascopes.jct.ex.JctIllegalInputException; import io.github.ascopes.jct.ex.JctJunitConfigurerException; import java.lang.reflect.Constructor; -import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.util.stream.IntStream; import java.util.stream.Stream; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java index 9bd0301de..b976a2381 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; import me.xdrop.fuzzywuzzy.FuzzySearch; import me.xdrop.fuzzywuzzy.ToStringFunction; import me.xdrop.fuzzywuzzy.model.BoundExtractedResult; @@ -282,7 +281,7 @@ public static String resultNotFoundWithFuzzySuggestions( .map(BoundExtractedResult::getReferent) .map(userFriendlyStringifier) .sorted() - .collect(Collectors.toList()); + .toList(); if (!closestMatches.isEmpty()) { errorBuilder.append(" Maybe you meant:"); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java index 3050c67bd..680fe0bfd 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java @@ -17,7 +17,6 @@ import java.lang.annotation.Documented; import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImplTest.java index 43e516036..ae7a7af02 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImplTest.java @@ -25,7 +25,6 @@ import io.github.ascopes.jct.compilers.DebuggingInfo; import io.github.ascopes.jct.fixtures.Fixtures; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -467,7 +466,7 @@ void addsAnnotationProcessorOptions() { var options = Stream .generate(Fixtures::someText) .limit(5) - .collect(Collectors.toList()); + .toList(); // When flagBuilder.annotationProcessorOptions(options); @@ -476,7 +475,7 @@ void addsAnnotationProcessorOptions() { assertThat(flagBuilder.build()) .containsSequence(options.stream() .map("-A"::concat) - .collect(Collectors.toList())); + .toList()); } @DisplayName(".annotationProcessorOptions(...) returns the flag builder") @@ -486,7 +485,7 @@ void returnsFlagBuilder() { var options = Stream .generate(Fixtures::someText) .limit(5) - .collect(Collectors.toList()); + .toList(); // Then assertThat(flagBuilder.annotationProcessorOptions(options)) @@ -505,7 +504,7 @@ void addsCompilerOptions() { var options = Stream .generate(Fixtures::someText) .limit(5) - .collect(Collectors.toList()); + .toList(); // When flagBuilder.compilerOptions(options); @@ -522,7 +521,7 @@ void returnsFlagBuilder() { var options = Stream .generate(Fixtures::someText) .limit(5) - .collect(Collectors.toList()); + .toList(); // Then assertThat(flagBuilder.compilerOptions(options)) diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java index 3e7b88845..77e27a24e 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java @@ -23,7 +23,6 @@ import static io.github.ascopes.jct.fixtures.Fixtures.someText; import static io.github.ascopes.jct.fixtures.Fixtures.someTraceDiagnostic; import static io.github.ascopes.jct.utils.IterableUtils.flatten; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; @@ -388,7 +387,7 @@ void teeWriterLogsShouldBePlacedInTheCompilationResult() throws IOException { // Then assertThat(result.getOutputLines()) - .containsExactlyElementsOf(lines.lines().collect(toList())); + .containsExactlyElementsOf(lines.lines().toList()); // Ensure we flushed before we called toString, otherwise data might be missing. order.verify(teeWriter).flush(); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java index 208152910..f8c1dcb88 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java @@ -55,7 +55,7 @@ void getArgumentsReturnsExpectedValue(int argumentCount) { var arguments = Stream .generate(Fixtures::someFlag) .limit(argumentCount) - .collect(Collectors.toList()); + .toList(); var compilation = filledBuilder() .arguments(arguments) @@ -102,7 +102,7 @@ void getOutputLinesReturnsExpectedValue(int lineCount) { .generate(UUID::randomUUID) .map(Objects::toString) .limit(lineCount) - .collect(Collectors.toList()); + .toList(); var compilation = filledBuilder() .outputLines(lines) @@ -141,7 +141,7 @@ void getDiagnosticsReturnsExpectedValue(int diagnosticCount) { var diagnostics = Stream .generate(Fixtures::someTraceDiagnostic) .limit(diagnosticCount) - .collect(Collectors.toList()); + .toList(); var compilation = filledBuilder() .diagnostics(diagnostics) diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImplTest.java index 597e23300..8c44826db 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImplTest.java @@ -135,7 +135,7 @@ void addPathsDelegatesMultipleCallsToTheRepository() { var pathRoots = Stream .generate(Fixtures::somePathRoot) .limit(10) - .collect(Collectors.toList()); + .toList(); // When fileManager.addPaths(location, pathRoots); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java index d5c9f5758..1cd4831fb 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java @@ -44,7 +44,6 @@ import java.util.Random; import java.util.Set; import java.util.UUID; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.tools.Diagnostic; import javax.tools.Diagnostic.Kind; @@ -180,7 +179,7 @@ public static List someFlags() { return Stream .generate(Fixtures::someFlag) .limit(someInt(2, 4)) - .collect(Collectors.toList()); + .toList(); } /** diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java index c85667795..4dde7eb34 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java @@ -33,7 +33,6 @@ import io.github.ascopes.jct.ex.JctJunitConfigurerException; import io.github.ascopes.jct.fixtures.Fixtures; import java.lang.reflect.InvocationTargetException; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -131,7 +130,7 @@ void configuringTheProviderRespectsTheMinimumVersionBound() { provider.configureInternals(10, 17, versionStrategy); var compilers = provider.provideArguments(mock(ExtensionContext.class)) .map(args -> (JctCompiler) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertThat(compilers).hasSize(3); @@ -155,7 +154,7 @@ void configuringTheProviderRespectsTheMaximumVersionBound() { provider.configureInternals(15, 20, versionStrategy); var compilers = provider.provideArguments(mock(ExtensionContext.class)) .map(args -> (JctCompiler) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertThat(compilers).hasSize(3); @@ -185,7 +184,7 @@ void configuringTheProviderWithConfigurersWillUseConfigurers() { ); var compilers = provider.provideArguments(mock(ExtensionContext.class)) .map(args -> (JctCompiler) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertSoftly(softly -> { diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java index 021421ee9..7eb9d5d9d 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java @@ -25,7 +25,6 @@ import io.github.ascopes.jct.compilers.JctCompilerConfigurer; import io.github.ascopes.jct.compilers.impl.JavacJctCompilerImpl; import java.lang.reflect.AnnotatedElement; -import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtensionContext; @@ -51,7 +50,7 @@ void providerUsesTheUserProvidedVersionRangesWhenValid() { var consumer = initialize(test, new JavacCompilersProvider()); var compilers = consumer.provideArguments(context) .map(args -> (JavacJctCompilerImpl) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertThat(compilers) @@ -87,7 +86,7 @@ void providerUsesTheMinCompilerVersionAllowedIfExceeded() { var consumer = initialize(test, new JavacCompilersProvider()); var compilers = consumer.provideArguments(context) .map(args -> (JavacJctCompilerImpl) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertThat(compilers) @@ -123,7 +122,7 @@ void providerUsesTheMaxCompilerVersionAllowedIfExceeded() { var consumer = initialize(test, new JavacCompilersProvider()); var compilers = consumer.provideArguments(context) .map(args -> (JavacJctCompilerImpl) args.get()[0]) - .collect(Collectors.toList()); + .toList(); // Then assertThat(compilers) diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java index 7bb77e329..cf00c655a 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java @@ -180,7 +180,7 @@ private List allExcept(Path... excludedPaths) { return paths .stream() .filter(not(List.of(excludedPaths)::contains)) - .collect(Collectors.toList()); + .toList(); } private String toPathString() { diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/StringSlicerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/StringSlicerTest.java index 3f7930e84..8dcd2c6f1 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/StringSlicerTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/StringSlicerTest.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.BDDAssertions.thenCode; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -82,7 +81,7 @@ void slicingStringIntoStreamReturnsTheExpectedResult( // When var actual = slicer .splitToStream(input) - .collect(Collectors.toList()); + .toList(); // Then then(actual).isEqualTo(expected); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/workspaces/impl/MemoryFileSystemProviderImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/workspaces/impl/MemoryFileSystemProviderImplTest.java index 11d4597d8..69f16b8b5 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/workspaces/impl/MemoryFileSystemProviderImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/workspaces/impl/MemoryFileSystemProviderImplTest.java @@ -30,7 +30,6 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.ArrayList; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -54,7 +53,7 @@ void theClassIsSingleton() { var instances = Stream .generate(MemoryFileSystemProvider::getInstance) .limit(10) - .collect(Collectors.toList()); + .toList(); // Then assertThat(instances) From fb4de4daa472abf8b5c8920c128c485a0ab0dbf7 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:03:53 +0000 Subject: [PATCH 04/19] Use switch expressions --- .../impl/JavacJctFlagBuilderImpl.java | 14 +++------- .../TracingDiagnosticListener.java | 14 ++++------ ...nnotationProcessorClassPathConfigurer.java | 18 ++++++------ .../JctFileManagerLoggingProxyConfigurer.java | 17 +++++------ .../github/ascopes/jct/utils/StringUtils.java | 11 ++------ .../ascopes/jct/utils/ToStringBuilder.java | 28 ++++++------------- .../jct/workspaces/impl/FileBuilderImpl.java | 15 ++++------ 7 files changed, 45 insertions(+), 72 deletions(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImpl.java index d16f8d135..c6e2e075b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImpl.java @@ -81,21 +81,15 @@ public JavacJctFlagBuilderImpl failOnWarnings(boolean enabled) { @Override public JctFlagBuilder compilationMode(CompilationMode compilationMode) { switch (compilationMode) { - case COMPILATION_ONLY: - craftedFlags.add(PROC_NONE); - break; - - case ANNOTATION_PROCESSING_ONLY: - craftedFlags.add(PROC_ONLY); - break; - - default: + case COMPILATION_ONLY -> craftedFlags.add(PROC_NONE); + case ANNOTATION_PROCESSING_ONLY -> craftedFlags.add(PROC_ONLY); + default -> { if (Runtime.version().feature() >= 22) { // In Java 22, the default is to disable all annotation processing by default // Prior to Java 22, the default was to enable all annotation processing by default. craftedFlags.add(PROC_FULL); } - break; + } } return this; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java index b2667021b..df6f8841c 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java @@ -149,15 +149,11 @@ public final void report(Diagnostic diagnostic) { } private Level diagnosticToLevel(Diagnostic diagnostic) { - switch (diagnostic.getKind()) { - case ERROR: - return Level.ERROR; - case WARNING: - case MANDATORY_WARNING: - return Level.WARN; - default: - return Level.INFO; - } + return switch (diagnostic.getKind()) { + case ERROR -> Level.ERROR; + case WARNING, MANDATORY_WARNING -> Level.WARN; + default -> Level.INFO; + }; } private Supplier messageGetter(Diagnostic diagnostic) { diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerAnnotationProcessorClassPathConfigurer.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerAnnotationProcessorClassPathConfigurer.java index 16f0f5abd..79da81c51 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerAnnotationProcessorClassPathConfigurer.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerAnnotationProcessorClassPathConfigurer.java @@ -64,26 +64,28 @@ public JctFileManagerAnnotationProcessorClassPathConfigurer(JctCompiler compiler public JctFileManager configure(JctFileManager fileManager) { log.debug("Configuring annotation processor discovery mechanism"); - switch (compiler.getAnnotationProcessorDiscovery()) { - case ENABLED: + return switch (compiler.getAnnotationProcessorDiscovery()) { + case ENABLED -> { log.trace("Annotation processor discovery is enabled, ensuring empty location exists"); INHERITED_AP_PATHS.values().forEach(fileManager::createEmptyLocation); - return fileManager; + yield fileManager; + } - case INCLUDE_DEPENDENCIES: + case INCLUDE_DEPENDENCIES -> { log.trace("Annotation processor discovery is enabled, copying classpath dependencies " + "into the annotation processor path"); INHERITED_AP_PATHS.forEach(fileManager::copyContainers); INHERITED_AP_PATHS.values().forEach(fileManager::createEmptyLocation); - return fileManager; + yield fileManager; + } - default: - throw new JctIllegalInputException("Cannot configure annotation processor discovery"); - } + default -> throw new JctIllegalInputException( + "Cannot configure annotation processor discovery"); + }; } @Override diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerLoggingProxyConfigurer.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerLoggingProxyConfigurer.java index 8c845e70d..5427143c9 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerLoggingProxyConfigurer.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/config/JctFileManagerLoggingProxyConfigurer.java @@ -50,16 +50,17 @@ public JctFileManagerLoggingProxyConfigurer(JctCompiler compiler) { public JctFileManager configure(JctFileManager fileManager) { log.debug("Configuring compiler operation audit logging"); - switch (compiler.getFileManagerLoggingMode()) { - case STACKTRACES: + return switch (compiler.getFileManagerLoggingMode()) { + case STACKTRACES -> { log.trace("Decorating file manager {} in a logger proxy with stack traces", fileManager); - return LoggingFileManagerProxy.wrap(fileManager, true); - case ENABLED: + yield LoggingFileManagerProxy.wrap(fileManager, true); + } + case ENABLED -> { log.trace("Decorating file manager {} in a logger proxy", fileManager); - return LoggingFileManagerProxy.wrap(fileManager, false); - default: - throw new IllegalStateException("Cannot configure logger proxy"); - } + yield LoggingFileManagerProxy.wrap(fileManager, false); + } + default -> throw new IllegalStateException("Cannot configure logger proxy"); + }; } @Override diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java index b976a2381..4856db87b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java @@ -228,14 +228,9 @@ private static void appendQuoted(StringBuilder builder, @Nullable Object object) for (var i = 0; i < objectStr.length(); ++i) { var c = objectStr.charAt(i); switch (c) { - case '\\': - builder.append("\\\\"); - break; - case '"': - builder.append("\\\""); - break; - default: - builder.append(c); + case '\\' -> builder.append("\\\\"); + case '"' -> builder.append("\\\""); + default -> builder.append(c); } } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java index 57411e908..9d15f6ff4 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java @@ -135,25 +135,13 @@ private static void appendToStringCharSequence(StringBuilder builder, CharSequen for (var i = 0; i < len; ++i) { var next = chars.charAt(i); switch (next) { - case '\0': - builder.append("\\0"); - break; - case '\r': - builder.append("\\r"); - break; - case '\n': - builder.append("\\n"); - break; - case '\t': - builder.append("\\t"); - break; - case '\"': - builder.append("\\\""); - break; - case '\\': - builder.append("\\\\"); - break; - default: + case '\0' -> builder.append("\\0"); + case '\r' -> builder.append("\\r"); + case '\n' -> builder.append("\\n"); + case '\t' -> builder.append("\\t"); + case '\"' -> builder.append("\\\""); + case '\\' -> builder.append("\\\\"); + default -> { if (0x20 <= next && next <= 0x7E || 0x80 <= next && next <= 0xFF) { builder.append(next); } else { @@ -162,7 +150,7 @@ private static void appendToStringCharSequence(StringBuilder builder, CharSequen .append("0".repeat(4 - hex.length())) .append(hex); } - break; + } } } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/FileBuilderImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/FileBuilderImpl.java index 7f9115dff..df8b0bac9 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/FileBuilderImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/FileBuilderImpl.java @@ -169,16 +169,13 @@ private static InputStream maybeBuffer(InputStream input, @Nullable String schem ? "unknown" : scheme.toLowerCase(Locale.ENGLISH); - switch (scheme) { - case "classpath": - case "memory": - case "jrt": - case "ram": - return input; - default: + return switch (scheme) { + case "classpath", "memory", "jrt", "ram" -> input; + default -> { log.trace("Decided to wrap input {} in a buffer - scheme was {}", input, scheme); - return new BufferedInputStream(input); - } + yield new BufferedInputStream(input); + } + }; } private static ClassLoader currentCallerClassLoader() { From c332129f29ac08b4b0b480fa764731566b786a69 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:09:28 +0000 Subject: [PATCH 05/19] Use sealed classes where possible --- .../ascopes/jct/workspaces/impl/AbstractManagedDirectory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java index 52c2dde56..017112a23 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java @@ -43,7 +43,9 @@ * @author Ashley Scopes * @since 0.0.1 */ -public abstract class AbstractManagedDirectory implements ManagedDirectory { +public abstract sealed class AbstractManagedDirectory + implements ManagedDirectory + permits RamDirectoryImpl, TempDirectoryImpl { private final String name; private final Path rootDirectory; From f8db805acf684d6d4e75884c63992c9250f236ab Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:46:48 +0000 Subject: [PATCH 06/19] Dogfood on Java 17 min --- .../ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-compiler-testing/src/it/dogfood/src/test/java/io/github/ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java b/java-compiler-testing/src/it/dogfood/src/test/java/io/github/ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java index 61d672209..2817aba72 100644 --- a/java-compiler-testing/src/it/dogfood/src/test/java/io/github/ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java +++ b/java-compiler-testing/src/it/dogfood/src/test/java/io/github/ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java @@ -52,7 +52,7 @@ class JctDogfoodTest { .resolve("classes"); @DisplayName("JCT can compile itself as a legacy module source") - @JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class) + @JavacCompilerTest(minVersion = 17, configurers = JctCompilationConfigurer.class) void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException { // Given try (var workspace = Workspaces.newWorkspace()) { From c01ae00eaa4fa0497433bc2fe9c1fda4e1acef3c Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:18:09 +0000 Subject: [PATCH 07/19] Simplify build.yml --- .github/workflows/build.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f277507cc..ea209d4be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,23 @@ on: workflow_dispatch: {} jobs: + validate: + name: Validation steps + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + check_together: 'yes' + scandir: './scripts' + + - name: Validate codecov.yml + shell: bash + run: curl -vvv --fail --data-binary @- https://codecov.io/validate < codecov.yml + build: name: Build on JDK ${{ matrix.java-version }} (${{ matrix.os-name }}) runs-on: ${{ matrix.os-name }} @@ -28,6 +45,7 @@ jobs: java-version: GA - os-name: macos-latest java-version: GA + steps: - name: Checkout repository uses: actions/checkout@v4 From 3566422a2024e142ab3b5c46c1877deb8a2629a6 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sat, 28 Dec 2024 11:44:15 +0000 Subject: [PATCH 08/19] Disable CodeQL which is breaking --- .github/workflows/codeql.yml | 55 ------------------------------------ 1 file changed, 55 deletions(-) delete mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index b79cb525c..000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: CodeQL analysis -on: - pull_request: - branches: - - main - - v5 - types: - - opened - - synchronize - push: - branches: - - main - - v5 - workflow_call: {} - workflow_dispatch: {} - -jobs: - codeql: - name: CodeQL analysis (${{ matrix.language }}) - runs-on: ubuntu-latest - - concurrency: - group: codeql-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - # Do not freeze. Enables automatic updates to how CodeQL scans - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - - - name: Autobuild - # Do not freeze. Enables automatic updates to how CodeQL scans - uses: github/codeql-action/autobuild@v3 - - - name: Perform CodeQL Analysis - # Do not freeze. Enables automatic updates to how CodeQL scans - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" From 515a476004c98418322c2b1765bd4b515026a296 Mon Sep 17 00:00:00 2001 From: Ashley <73482956+ascopes@users.noreply.github.com> Date: Sat, 28 Dec 2024 11:50:18 +0000 Subject: [PATCH 09/19] Replace manual casts with new instanceof expression syntax (#774) --- .../autovalue/AutoValueTest.java | 4 +- .../immutables/ImmutablesTest.java | 4 +- .../mapstruct/MapStructTest.java | 4 +- .../impl/ContainerGroupRepositoryImpl.java | 9 ++-- .../impl/ModuleContainerGroupImpl.java | 4 +- .../jct/filemanagers/ModuleLocation.java | 11 ++--- .../filemanagers/impl/JctFileManagerImpl.java | 49 ++++++++----------- .../filemanagers/impl/PathFileObjectImpl.java | 3 +- .../jct/junit/AbstractCompilersProvider.java | 4 +- .../ascopes/jct/utils/ModuleDiscoverer.java | 9 ++-- .../ascopes/jct/utils/ToStringBuilder.java | 8 +-- .../impl/AbstractManagedDirectory.java | 6 +-- .../jct/workspaces/impl/WorkspaceImpl.java | 7 ++- .../impl/WrappingDirectoryImpl.java | 6 +-- .../github/ascopes/jct/fixtures/Fixtures.java | 17 ++++--- .../ascopes/jct/fixtures/Slf4jLoggerFake.java | 15 +++--- 16 files changed, 70 insertions(+), 90 deletions(-) diff --git a/java-compiler-testing/src/it/google-auto-value/src/test/java/io/github/ascopes/jct/acceptancetests/autovalue/AutoValueTest.java b/java-compiler-testing/src/it/google-auto-value/src/test/java/io/github/ascopes/jct/acceptancetests/autovalue/AutoValueTest.java index f556045e7..6428e27db 100644 --- a/java-compiler-testing/src/it/google-auto-value/src/test/java/io/github/ascopes/jct/acceptancetests/autovalue/AutoValueTest.java +++ b/java-compiler-testing/src/it/google-auto-value/src/test/java/io/github/ascopes/jct/acceptancetests/autovalue/AutoValueTest.java @@ -72,8 +72,8 @@ void autoValueImplementationClassIsCreatedAsExpected(JctCompiler compiler) throw } private Object callMethod(Object obj, String method, Object... args) throws Throwable { - var cls = obj instanceof Class - ? (Class) obj + var cls = obj instanceof Class castCls + ? castCls : obj.getClass(); // Enforce reflective access to be allowed. diff --git a/java-compiler-testing/src/it/immutables/src/test/java/io/github/ascopes/jct/acceptancetests/immutables/ImmutablesTest.java b/java-compiler-testing/src/it/immutables/src/test/java/io/github/ascopes/jct/acceptancetests/immutables/ImmutablesTest.java index 9190fe611..6def86ae7 100644 --- a/java-compiler-testing/src/it/immutables/src/test/java/io/github/ascopes/jct/acceptancetests/immutables/ImmutablesTest.java +++ b/java-compiler-testing/src/it/immutables/src/test/java/io/github/ascopes/jct/acceptancetests/immutables/ImmutablesTest.java @@ -100,8 +100,8 @@ void immutablesValueProducesTheExpectedClassForModules(JctCompiler compiler) thr } private Object callMethod(Object obj, String method, Object... args) throws Throwable { - var cls = obj instanceof Class - ? (Class) obj + var cls = obj instanceof Class castCls + ? castCls : obj.getClass(); // Enforce reflective access to be allowed. diff --git a/java-compiler-testing/src/it/mapstruct/src/test/java/io/github/ascopes/jct/acceptancetests/mapstruct/MapStructTest.java b/java-compiler-testing/src/it/mapstruct/src/test/java/io/github/ascopes/jct/acceptancetests/mapstruct/MapStructTest.java index b5136fb69..72b5c6b5a 100644 --- a/java-compiler-testing/src/it/mapstruct/src/test/java/io/github/ascopes/jct/acceptancetests/mapstruct/MapStructTest.java +++ b/java-compiler-testing/src/it/mapstruct/src/test/java/io/github/ascopes/jct/acceptancetests/mapstruct/MapStructTest.java @@ -108,8 +108,8 @@ void mapStructGeneratesExpectedMappingCodeForModules(JctCompiler compiler) throw } private T getAttr(Object obj, String name) throws Throwable { - final var cls = obj instanceof Class - ? (Class) obj + final var cls = obj instanceof Class castCls + ? castCls : obj.getClass(); final var instance = cls == obj diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ContainerGroupRepositoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ContainerGroupRepositoryImpl.java index d87f82510..32fbddf7f 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ContainerGroupRepositoryImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ContainerGroupRepositoryImpl.java @@ -76,10 +76,9 @@ public ContainerGroupRepositoryImpl(String release) { * @throws JctIllegalInputException if the location is an output location and is misconfigured. */ public void addPath(Location location, PathRoot pathRoot) { - if (location instanceof ModuleLocation) { + if (location instanceof ModuleLocation moduleLocation) { // If we are adding a specific module, we should resolve where it needs to live // using custom logic so that we know it gets registered in the right place. - var moduleLocation = (ModuleLocation) location; addModulePath(moduleLocation, pathRoot); } else if (location.isModuleOrientedLocation()) { // If we are adding a module-oriented location of any type, then we should discover @@ -268,8 +267,7 @@ public Collection getPackageContainerGroups() { */ @Nullable public PackageContainerGroup getPackageOrientedContainerGroup(Location location) { - if (location instanceof ModuleLocation) { - var moduleLocation = (ModuleLocation) location; + if (location instanceof ModuleLocation moduleLocation) { var group = getModuleOrientedContainerGroup(moduleLocation.getParent()); return group == null ? null @@ -298,8 +296,7 @@ public String getRelease() { * @return {@code true} if the location exists, or {@code false} if it does not. */ public boolean hasLocation(Location location) { - if (location instanceof ModuleLocation) { - var moduleLocation = (ModuleLocation) location; + if (location instanceof ModuleLocation moduleLocation) { var parentLocation = moduleLocation.getParent(); var group = parentLocation.isOutputLocation() ? outputs.get(parentLocation) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ModuleContainerGroupImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ModuleContainerGroupImpl.java index 1fa3a7114..5e1616d29 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ModuleContainerGroupImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/impl/ModuleContainerGroupImpl.java @@ -114,8 +114,8 @@ public void close() throws IOException { public boolean contains(PathFileObject fileObject) { var location = fileObject.getLocation(); - if (location instanceof ModuleLocation) { - var module = modules.get((ModuleLocation) location); + if (location instanceof ModuleLocation moduleLocation) { + var module = modules.get(moduleLocation); if (module != null) { return module.contains(fileObject); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/ModuleLocation.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/ModuleLocation.java index 3a26d4b44..19faf713b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/ModuleLocation.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/ModuleLocation.java @@ -95,14 +95,11 @@ public boolean isModuleOrientedLocation() { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof ModuleLocation)) { - return false; + if (other instanceof ModuleLocation that) { + return parent.equals(that.parent) + && moduleName.equals(that.moduleName); } - - var that = (ModuleLocation) other; - - return parent.equals(that.parent) - && moduleName.equals(that.moduleName); + return false; } @Override diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImpl.java index abd212e34..ca2c12aa4 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerImpl.java @@ -74,13 +74,12 @@ public void close() { } @Override - public boolean contains(Location location, FileObject fo) { - if (!(fo instanceof PathFileObject)) { - return false; + public boolean contains(Location location, FileObject fileObject) { + if (fileObject instanceof PathFileObject pathFileObject) { + var group = repository.getContainerGroup(location); + return group != null && group.contains(pathFileObject); } - - var group = repository.getContainerGroup(location); - return group != null && group.contains((PathFileObject) fo); + return false; } @Override @@ -143,8 +142,7 @@ public FileObject getFileForOutput( PackageContainerGroup group = null; // If we have a module, we may need to create a brand-new location for it. - if (location instanceof ModuleLocation) { - var moduleLocation = ((ModuleLocation) location); + if (location instanceof ModuleLocation moduleLocation) { var parentGroup = repository.getOutputContainerGroup(moduleLocation.getParent()); if (parentGroup != null) { @@ -186,8 +184,7 @@ public JavaFileObject getJavaFileForOutput( PackageContainerGroup group = null; // If we have a module, we may need to create a brand-new location for it. - if (location instanceof ModuleLocation) { - var moduleLocation = ((ModuleLocation) location); + if (location instanceof ModuleLocation moduleLocation) { var parentGroup = repository.getOutputContainerGroup(moduleLocation.getParent()); if (parentGroup != null) { @@ -216,18 +213,13 @@ public ModuleLocation getLocationForModule(Location location, String moduleName) public ModuleLocation getLocationForModule(Location location, JavaFileObject fileObject) { requireOutputOrModuleOrientedLocation(location); - if (fileObject instanceof PathFileObject) { - var pathFileObject = (PathFileObject) fileObject; - var moduleLocation = pathFileObject.getLocation(); - - if (moduleLocation instanceof ModuleLocation) { - return (ModuleLocation) moduleLocation; - } - + if (fileObject instanceof PathFileObject pathFileObject) { // The expectation is to return null if this is not for a module. Certain frameworks like // manifold expect this behaviour, despite it not being documented very clearly in the // Java compiler API. - return null; + return pathFileObject.getLocation() instanceof ModuleLocation moduleLocation + ? moduleLocation + : null; } throw new JctIllegalInputException( @@ -297,18 +289,17 @@ public boolean hasLocation(Location location) { @Nullable @Override - public String inferBinaryName(Location location, JavaFileObject file) { + public String inferBinaryName(Location location, JavaFileObject fileObject) { requirePackageOrientedLocation(location); - if (!(file instanceof PathFileObject)) { - return null; + if (fileObject instanceof PathFileObject pathFileObject) { + var group = repository.getPackageOrientedContainerGroup(location); + if (group != null) { + return group.inferBinaryName(pathFileObject); + } } - var group = repository.getPackageOrientedContainerGroup(location); - - return group == null - ? null - : group.inferBinaryName((PathFileObject) file); + return null; } @Nullable @@ -316,8 +307,8 @@ public String inferBinaryName(Location location, JavaFileObject file) { public String inferModuleName(Location location) { requirePackageOrientedLocation(location); - return location instanceof ModuleLocation - ? ((ModuleLocation) location).getModuleName() + return location instanceof ModuleLocation moduleLocation + ? moduleLocation.getModuleName() : null; } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/PathFileObjectImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/PathFileObjectImpl.java index 26ddec546..46bb4190b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/PathFileObjectImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/PathFileObjectImpl.java @@ -115,7 +115,8 @@ public boolean delete() { @Override public boolean equals(@Nullable Object other) { // Roughly the same as what Javac does. - return other instanceof FileObject && uri.equals(((FileObject) other).toUri()); + return other instanceof FileObject that + && uri.equals(that.toUri()); } @Override diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java index 650e46332..4485e767a 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java @@ -280,8 +280,8 @@ private JctCompilerConfigurer initializeConfigurer( return constructor.newInstance(); } catch (ReflectiveOperationException ex) { - if (ex instanceof InvocationTargetException) { - var target = ((InvocationTargetException) ex).getTargetException(); + if (ex instanceof InvocationTargetException iee) { + var target = iee.getTargetException(); if (isTestAbortedException(target)) { target.addSuppressed(ex); throw (RuntimeException) target; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java index 7337c1558..4735be978 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java @@ -132,13 +132,10 @@ public ModuleDescriptor getDescriptor() { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof ModuleCandidate)) { - return false; + if (other instanceof ModuleCandidate that) { + return name.equals(that.name) && path.equals(that.path); } - - var that = (ModuleCandidate) other; - - return name.equals(that.name) && path.equals(that.path); + return false; } @Override diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java index 9d15f6ff4..4a11898c4 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ToStringBuilder.java @@ -117,12 +117,12 @@ private static void appendToString(StringBuilder builder, @Nullable Object objec builder.append(NULL); } else if (TYPES_TO_TREAT_AS_STRINGS.stream().anyMatch(cls -> cls.isInstance(object))) { appendToStringCharSequence(builder, object.toString()); - } else if (object instanceof Map) { - appendToStringMap(builder, (Map) object); + } else if (object instanceof Map map) { + appendToStringMap(builder, map); } else if (object.getClass().isArray()) { appendToStringArray(builder, object); - } else if (object instanceof Iterable) { - appendToStringIterable(builder, ((Iterable) object)); + } else if (object instanceof Iterable iterable) { + appendToStringIterable(builder, iterable); } else { builder.append(object); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java index 017112a23..ac7177852 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java @@ -148,9 +148,9 @@ public ManagedDirectory thatIsEmpty() { } @Override - public boolean equals(@Nullable Object that) { - return that instanceof AbstractManagedDirectory - && ((AbstractManagedDirectory) that).uri.equals(uri); + public boolean equals(@Nullable Object other) { + return other instanceof AbstractManagedDirectory that + && uri.equals(that.uri); } @Override 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 e37b01f0f..002f786b8 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 @@ -69,9 +69,9 @@ public void close() { for (var list : paths.values()) { for (var path : list) { - if (path instanceof AbstractManagedDirectory) { + if (path instanceof AbstractManagedDirectory dir) { try { - ((AbstractManagedDirectory) path).close(); + dir.close(); } catch (Exception ex) { exceptions.add(ex); @@ -206,8 +206,7 @@ public Map> getModules(Location location) { var results = new HashMap>(); paths.forEach((pathLocation, pathRoots) -> { - if (pathLocation instanceof ModuleLocation) { - var modulePathLocation = (ModuleLocation) pathLocation; + if (pathLocation instanceof ModuleLocation modulePathLocation) { if (modulePathLocation.getParent().equals(location)) { results.computeIfAbsent(modulePathLocation.getModuleName(), name -> new ArrayList<>()) .addAll(pathRoots); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WrappingDirectoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WrappingDirectoryImpl.java index 388e98d26..c06c43852 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WrappingDirectoryImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WrappingDirectoryImpl.java @@ -121,9 +121,9 @@ public URL getUrl() { } @Override - public boolean equals(@Nullable Object that) { - return that instanceof WrappingDirectoryImpl - && ((WrappingDirectoryImpl) that).getUri().equals(uri); + public boolean equals(@Nullable Object other) { + return other instanceof WrappingDirectoryImpl that + && uri.equals(that.uri); } @Override diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java index 1cd4831fb..ff0f0d855 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java @@ -465,17 +465,18 @@ public static > E oneOf(Class cls) { * @param the type. * @return the element. */ + @SuppressWarnings("unchecked") public static T oneOf(Collection items) { var index = RANDOM.nextInt(items.size()); - if (items instanceof List) { - return ((List) 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 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 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> 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 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 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