Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,14 @@ jobs:
uses: actions/checkout@v7

###
### Lint scripts and configuration files.
### Lint configuration files.
###

#- name: Validate shell scripts
# uses: ludeeus/action-shellcheck@master
# if: ${{ ! cancelled() }}
# with:
# check_together: 'yes'
# scandir: ./scripts

- name: Validate codecov.yml
shell: bash
if: ${{ ! cancelled() }}
run: curl -si --fail-with-body --data-binary @codecov.yml https://codecov.io/validate

###
### Lint GitHub Actions for issues.
###

- name: Lint GitHub Actions
shell: bash
if: ${{ ! cancelled() }}
run: >-
docker run
--rm
--user "$(id -u "${USER}"):$(id -g "${USER}")"
--volume "$(pwd):/repo"
--workdir /repo
rhysd/actionlint:latest
-color
-verbose

###
### Lint Java, export information about current environment for
### the next jobs to utilise.
Expand Down Expand Up @@ -86,14 +62,13 @@ jobs:
matrix:
os-name: [ubuntu-latest]
java-version:
- 17 # LTS
- 21 # LTS
- 25 # LTS
include:
- os-name: windows-11-arm
java-version: 23 # Latest Temurin for ARM
- os-name: macos-latest
java-version: 25 # LTS
java-version: 21

steps:
- name: Checkout repository
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/codeql.yml

This file was deleted.

82 changes: 37 additions & 45 deletions java-compiler-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>java-compiler-testing-parent</artifactId>
<version>6.0.2-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -115,13 +115,47 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths combine.children="append" />
<compilerArgs combine.children="append">
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<!-- Override what Maven is pulling in. This is fine during compilation as our
code doesn't use Guava at all. This is needed for ErrorProne to not crash
on startup. -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>[33,)</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>

<compilerArgs>
<!--
Disable warnings about modules. We cannot do much about some of these due to how Maven
works with modules with Surefire.
-->
<arg>-Xlint:-module</arg>
<!-- ErrorProne configuration -->
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
<compilerArg>
-Xplugin:ErrorProne
-XepDisableWarningsInGeneratedCode
-XepExcludedPaths:.*/target/generated.*?/.*
-XepOpt:NullAway:AnnotatedPackages=io.github.ascopes.jct
<!-- See https://github.com/uber/NullAway/issues/1319 -->
-XepOpt:NullAway:ExcludedFieldAnnotations=org.junit.jupiter.*,org.mockito.*
-XepOpt:NullAway:KnownInitializers=io.github.ascopes.jct.annotations.Initializer,io.github.ascopes.jct.junit.Managed
</compilerArg>
<!-- Needed for ErrorProne to be able to run -->
<compilerArg>-XDaddTypeAnnotationsToSymbol=true</compilerArg>
<compilerArg>-XDcompilePolicy=simple</compilerArg>
</compilerArgs>
</configuration>
</plugin>
Expand Down Expand Up @@ -232,48 +266,6 @@
<artifactId>maven-compiler-plugin</artifactId>

<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<!-- Override what Maven is pulling in. This is fine during compilation as our
code doesn't use Guava at all. This is needed for ErrorProne to not crash
on startup. -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>[33,)</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>

<compilerArgs>
<!--
Disable warnings about modules. We cannot do much about some of these due to how Maven
works with modules with Surefire.
-->
<arg>-Xlint:-module</arg>
<!-- ErrorProne configuration -->
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
<compilerArg>
-Xplugin:ErrorProne
-XepDisableWarningsInGeneratedCode
-XepExcludedPaths:.*/target/generated.*?/.*
-XepOpt:NullAway:AnnotatedPackages=io.github.ascopes.jct
<!-- See https://github.com/uber/NullAway/issues/1319 -->
-XepOpt:NullAway:ExcludedFieldAnnotations=org.junit.jupiter.*,org.mockito.*
-XepOpt:NullAway:KnownInitializers=io.github.ascopes.jct.annotations.Initializer,io.github.ascopes.jct.junit.Managed
</compilerArg>
<!-- Needed for ErrorProne to be able to run -->
<compilerArg>-XDaddTypeAnnotationsToSymbol=true</compilerArg>
<compilerArg>-XDcompilePolicy=simple</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class JctDogfoodTest {
.resolve("classes");

@DisplayName("JCT can compile itself as a legacy module source")
@JavacCompilerTest(minVersion = 17, configurers = JctCompilationConfigurer.class)
@JavacCompilerTest(minVersion = 21, configurers = JctCompilationConfigurer.class)
void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException {
// Given
try (var workspace = Workspaces.newWorkspace()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ default JctCompiler release(SourceVersion release) {
* Request that the compiler uses a language version that corresponds to the runtime language
* version in use on the current JVM.
*
* <p>For example, running this on JRE 19 would set the release to "19".
* <p>For example, running this on JRE 25 would set the release to "25".
*
* <p>This calls {@link #release(int)} internally.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
*/
public final class JavacJctCompilerImpl extends AbstractJctCompiler {

private static final int JAVA_8 = 8;
private static final int JAVA_9 = 9;
private static final int JAVA_20 = 20;
private static final String NAME = "JDK Compiler";

/**
Expand All @@ -60,7 +58,7 @@ public JctFlagBuilderFactory getFlagBuilderFactory() {
public Jsr199CompilerFactory getCompilerFactory() {
// RequireNonNull to ensure the return result is non-null, since the ToolProvider
// method is not annotated.
return () -> requireNonNull(ToolProvider.getSystemJavaCompiler(),
return () -> requireNonNull(ToolProvider.getSystemJavaCompiler(),
"ToolProvider.getSystemJavaCompiler()");
}

Expand All @@ -76,21 +74,10 @@ public JctFileManagerFactory getFileManagerFactory() {
* @since 1.0.0
*/
public static int getEarliestSupportedVersionInt() {
// Purposely do not hardcode members of the SourceVersion enum here other
// than utility methods, as this prevents compilation problems on various
// versions of the JDK when certain members are unavailable.

@SuppressWarnings("EnumOrdinal")
var latestSupported = SourceVersion.latestSupported().ordinal();

if (latestSupported >= JAVA_20) {
// JDK 20 marks source-version 8 as obsolete, and emits compilation
// warnings that may break tests using "fail on warnings". To avoid this,
// disallow compiling Java 8 sources under Javac in JDK 20 or newer
return JAVA_9;
}

return JAVA_8;
// JDK 20 marks source-version 8 as obsolete, and emits compilation
// warnings that may break tests using "fail on warnings". To avoid this,
// disallow compiling Java 8 sources under Javac in JDK 20 or newer
return JAVA_9;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package io.github.ascopes.jct.utils;

import io.github.ascopes.jct.annotations.DeadCodeGenerated;

/**
* Polyfill to enable supporting using the newer Thread APIs on newer platforms.
*
* <p>This specifically targets the new APIs introduced as part of Project Loom
* in Java 19.
*
* <p><strong>This class is now suitable to be removed as we only target Java 21 and
* newer.</strong>
*
* @author Ashley Scopes
* @since 0.0.1
*/
Expand All @@ -40,18 +41,9 @@ private LoomPolyfill() {
* @param thread the thread to use.
* @return the thread ID.
*/
@DeadCodeGenerated
public static long getThreadId(Thread thread) {
// Note: this test will never get 100% coverage on one JDK, because it totally depends on the
// JDK in use as to which code path runs.
try {
// Where possible, use the newer Loom API to fetch the thread ID.
var method = Thread.class.getDeclaredMethod("threadId");
return (long) method.invoke(thread);
} catch (Exception ex) {
// Fall back to the old API (which is the only method prior to Java 19).
return thread.getId();
}
// Now we baseline to Java 21, we don't have to use reflection to invoke this Java 19 API.
return thread.threadId();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions java-compiler-testing/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* <p><strong>For Java 11 support, please use version 4 of this library, which is still kept up to date.
* Version 5 of this library only supports Java 17 onwards.</strong>
*
* <p><strong>For Java 17 support, please use version 6 of this library, which is still kept up to date.
* Version 7 of this library only supports Java 17 onwards.</strong>
*
* <p>The <em>Java Compiler Testing</em> API has a number of facilities for assisting in testing
* anything related to the Java compiler. This includes Javac plugins and JSR-199 annotation
* processors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ void configureInvokesConfigurerOnTheCompiler() throws Throwable {
IllegalThreadStateException.class,
NoClassDefFoundError.class,
ClassNotFoundException.class,
ThreadDeath.class,
})
@ParameterizedTest(name = "for exception of type {0}")
void configurePropagatesAnyException(Class<? extends Exception> exceptionCls) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,13 @@ void compilersHaveNoDefaultAnnotationProcessorsSet() {
@DisplayName("the earliest supported version int has the expected value")
@CsvSource(useHeadersInDisplayName = true, value = {
"SourceVersion.latest(), expectedResult",
" 9, 8",
" 10, 8",
" 11, 8",
" 12, 8",
" 13, 8",
" 14, 8",
" 15, 8",
" 16, 8",
" 17, 8",
" 18, 8",
" 19, 8",
// JDK-20 marks Java 8 as obsolete, so we do not support it.
// We default to Java 9 regardless in this case.
" 20, 9",
" 21, 9",
" 22, 9",
" 23, 9",
" 24, 9",
" 25, 9",
" 26, 9",
" 27, 9",
})
@ParameterizedTest(name = "expect {1} when using Javac for JDK {0}")
@SuppressWarnings({"EnumOrdinal", "ResultOfMethodCallIgnored"})
Expand All @@ -166,22 +158,16 @@ void earliestSupportedVersionReturnsTheExpectedValue(int latest, int expectedRes
}
}

@DisplayName("the earliest supported version int has the expected value")
@DisplayName("the latest supported version int has the expected value")
@CsvSource(useHeadersInDisplayName = true, value = {
"SourceVersion.latest(), expectedResult",
" 9, 9",
" 10, 10",
" 11, 11",
" 12, 12",
" 13, 13",
" 14, 14",
" 15, 15",
" 16, 16",
" 17, 17",
" 18, 18",
" 19, 19",
" 20, 20",
" 21, 21",
" 22, 22",
" 23, 23",
" 24, 24",
" 25, 25",
" 26, 26",
" 27, 27",
})
@ParameterizedTest(name = "expect {1} when using Javac for JDK {0}")
@SuppressWarnings({"EnumOrdinal", "ResultOfMethodCallIgnored"})
Expand Down
Loading
Loading