diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f9dc544..bb6c4ae 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -11,14 +11,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - uses: actions/checkout@v5 + - name: Set up JDK 21 + uses: actions/setup-java@v5 with: - java-version: "17" + java-version: "21" distribution: "temurin" - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b + uses: gradle/actions/wrapper-validation@v4 - name: Build run: ./gradlew build - name: Test diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 98f593f..0000000 --- a/build.gradle +++ /dev/null @@ -1,84 +0,0 @@ -plugins { - id 'java' - id 'jacoco' - id 'checkstyle' - id 'maven-publish' -} - -group 'com.maroontress' -version '1.0' - -repositories { - mavenCentral() - maven { - url = uri('https://maroontress.github.io/maven') - } -} - -dependencies { - implementation 'com.maroontress:clione:1.0' - testImplementation 'org.hamcrest:hamcrest:2.2' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' -} - -compileJava { - options.encoding = 'UTF-8' - sourceCompatibility = 11 - targetCompatibility = 11 -} - -compileTestJava { - options.encoding = 'UTF-8' - sourceCompatibility = 14 -} - -test { - useJUnitPlatform() - finalizedBy jacocoTestReport -} - -jacocoTestReport { - dependsOn test - reports { - xml.required = false - csv.required = false - html.outputLocation = layout.buildDirectory.dir('reports/jacoco-html') - } -} - -java { - withJavadocJar() - withSourcesJar() -} - -javadoc { - options.addStringOption('locale', 'en-US') - options.encoding = 'UTF-8' -} - -checkstyle { - toolVersion '9.2.1' -} - -checkstyleMain { - configFile = file("${rootDir}/config/checkstyle/main.xml") -} - -checkstyleTest { - configFile = file("${rootDir}/config/checkstyle/test.xml") -} - -publishing { - repositories { - maven { - name = 'LocalFile' - url = uri("${localMavenRepo}") - } - } - publications { - gpr(MavenPublication) { - from(components.java) - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..cf601fd --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,134 @@ +/* + This file was generated by the Gradle 'init' task. + + This generated file contains a sample Java library project to get you + started. For more details on building Java & JVM projects, please refer to + https://docs.gradle.org/9.0.0/userguide/building_java_projects.html in the + Gradle documentation. +*/ + +plugins { + // Apply the java-library plugin for API and implementation separation. + `java-library` + jacoco + checkstyle + `maven-publish` +} + +group = "com.maroontress" +version = "1.0" + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() + maven { + url = uri("https://maroontress.github.io/maven") + } +} + +dependencies { + api(libs.clione) + + // Use JUnit Jupiter for testing. + testImplementation(libs.hamcrest) + testImplementation(libs.junit.jupiter) + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +// Replace Groovy-style task config with Kotlin DSL typed configuration +tasks.named("compileJava") { + options.encoding = "UTF-8" + sourceCompatibility = "11" + targetCompatibility = "11" +} + +tasks.named("compileTestJava") { + options.encoding = "UTF-8" + sourceCompatibility = "21" +} + +tasks.named("test") { + // Use JUnit Platform for unit tests. + useJUnitPlatform() + finalizedBy("jacocoTestReport") + + outputs.upToDateWhen { false } + + testLogging { + showStandardStreams = true + + events = setOf( + org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED, + org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED, + org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT, + org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR + ) + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + showExceptions = true + showCauses = true + showStackTraces = true + displayGranularity = 2 + } +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } + withJavadocJar() + withSourcesJar() +} + +// Add/ensure jacoco toolVersion for consistent behavior +jacoco { + toolVersion = "0.8.13" +} + +tasks.named("jacocoTestReport") { + dependsOn(tasks.named("test")) + + reports { + // Ensure XML is generated (useful for CI / coverage collectors) and HTML as before + xml.required.set(true) + csv.required.set(false) + html.required.set(true) + html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco-html")) + } +} + +// Ensure the `check` lifecycle depends on the jacoco report so `./gradlew build` produces it +tasks.named("check") { + dependsOn(tasks.named("jacocoTestReport")) +} + +tasks.named("javadoc") { + (options as org.gradle.external.javadoc.StandardJavadocDocletOptions).locale = "en_US" + (options as org.gradle.external.javadoc.StandardJavadocDocletOptions).encoding = "UTF-8" +} + +checkstyle { + toolVersion = "11.0.0" +} + +tasks.checkstyleMain { + configFile = file("${rootDir}/config/checkstyle/main.xml") +} + +tasks.checkstyleTest { + configFile = file("${rootDir}/config/checkstyle/test.xml") +} + +publishing { + repositories { + maven { + name = "LocalFile" + url = uri(project.properties["localMavenRepo"] ?: "./maven") + } + } + publications { + create("gpr") { + from(components["java"]) + } + } +} diff --git a/config/checkstyle/main.xml b/config/checkstyle/main.xml index e2bc125..2736882 100644 --- a/config/checkstyle/main.xml +++ b/config/checkstyle/main.xml @@ -49,15 +49,7 @@ - - - - - - + @@ -486,9 +508,9 @@ Use suppressions.xml for suppressions, this is only example. checkFormat will prevent suppression comments from being valid. --> - - - + + + + - + @@ -610,7 +632,7 @@ - + @@ -635,6 +657,7 @@ + + - - @@ -696,7 +716,7 @@ - + @@ -736,17 +756,28 @@ - - + + + + + + + - - - + + + + + + + + + diff --git a/config/checkstyle/test.xml b/config/checkstyle/test.xml index e584f7e..e595aea 100644 --- a/config/checkstyle/test.xml +++ b/config/checkstyle/test.xml @@ -49,15 +49,7 @@ - - - - - - + + @@ -275,9 +268,11 @@ + @@ -331,7 +326,9 @@ + @@ -366,12 +363,14 @@ java.lang.StringBuffer"/> + @@ -474,7 +473,9 @@ + @@ -666,9 +667,11 @@ + @@ -710,11 +713,13 @@ + @@ -722,17 +727,28 @@ - - + + + + + + + - - - + + + + + + + + + @@ -757,7 +773,9 @@ + diff --git a/gradle.properties b/gradle.properties index a4afdd9..cb7975f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ -org.gradle.jvmargs=-Duser.language=en -Duser.country=US -file.encoding=utf-8 -localMavenRepo="${projectRoot}/maven" +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties + +org.gradle.configuration-cache=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..fc2064b --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,12 @@ +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format + +[versions] +clione = "1.3.0" +junit-jupiter = "5.13.4" +hamcrest = "3.0" + +[libraries] +clione = { module = "com.maroontress:clione", version.ref = "clione" } +junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } +hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..9bbc975 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..2a84e18 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 76ccb9c..faf9300 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright ? 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -32,10 +34,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions $var, ${var}, ${var:-default}, ${var+SET}, -# ${var#prefix}, ${var%suffix}, and $( cmd ); -# * compound commands having a testable exit status, especially case; -# * various built-in commands including command, set, and ulimit. +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +133,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +200,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +216,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index a1059e1..0000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'intexpr' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..c6063d6 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,15 @@ +/* + This file was generated by the Gradle 'init' task. + + The settings file is used to specify which projects to include in your + build. For more detailed information on multi-project builds, please refer + to https://docs.gradle.org/9.0.0/userguide/multi_project_builds.html in the + Gradle documentation. +*/ + +plugins { + // Apply the foojay-resolver plugin to allow automatic download of JDKs + id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" +} + +rootProject.name = "intexpr" diff --git a/src/main/java/com/maroontress/intexpr/impl/OperatorType.java b/src/main/java/com/maroontress/intexpr/impl/OperatorType.java index 0b990b1..20ab7a6 100644 --- a/src/main/java/com/maroontress/intexpr/impl/OperatorType.java +++ b/src/main/java/com/maroontress/intexpr/impl/OperatorType.java @@ -12,13 +12,16 @@ */ public enum OperatorType { + // CSOFF: NeedBraces /** Represents unary operators. */ UNARY(o -> s -> { var operand = s.pop(); var node = new UnaryOperatorNode(o, operand); s.push(node); }), + // CSON: NeedBraces + // CSOFF: NeedBraces /** Represents binary operators. */ BINARY(o -> s -> { var right = s.pop(); @@ -26,6 +29,7 @@ public enum OperatorType { var node = new BinaryOperatorNode(o, left, right); s.push(node); }); + // CSON: NeedBraces private final Function>> f; diff --git a/src/main/java/com/maroontress/intexpr/syntaxtree/BinaryOperatorNode.java b/src/main/java/com/maroontress/intexpr/syntaxtree/BinaryOperatorNode.java index 73486b8..bee10f7 100644 --- a/src/main/java/com/maroontress/intexpr/syntaxtree/BinaryOperatorNode.java +++ b/src/main/java/com/maroontress/intexpr/syntaxtree/BinaryOperatorNode.java @@ -25,6 +25,7 @@ public BinaryOperatorNode(Opcode opcode, SyntaxNode leftOperand, this.rightOperand = rightOperand; } + // CSOFF: AvoidEscapedUnicodeCharacters /** {@inheritDoc} */ @Override public String toString(String firstIndent, String indent) { @@ -37,4 +38,5 @@ public String toString(String firstIndent, String indent) { + leftOperand.toString(verticalRight, vertical) + lf + rightOperand.toString(upRight, blank); } + // CSON: AvoidEscapedUnicodeCharacters } diff --git a/src/main/java/com/maroontress/intexpr/syntaxtree/UnaryOperatorNode.java b/src/main/java/com/maroontress/intexpr/syntaxtree/UnaryOperatorNode.java index 338af4f..36d7451 100644 --- a/src/main/java/com/maroontress/intexpr/syntaxtree/UnaryOperatorNode.java +++ b/src/main/java/com/maroontress/intexpr/syntaxtree/UnaryOperatorNode.java @@ -24,10 +24,12 @@ public UnaryOperatorNode(Opcode opcode, SyntaxNode operand) { /** {@inheritDoc} */ @Override public String toString(String firstIndent, String indent) { + // CSOFF: AvoidEscapedUnicodeCharacters var lf = System.lineSeparator(); var upRight = indent + " \u2514 "; var blank = indent + " "; return firstIndent + opcode + lf + operand.toString(upRight, blank); + // CSON: AvoidEscapedUnicodeCharacters } }