diff --git a/.github/workflows/javac-matcher-build-tools.yml b/.github/workflows/javac-matcher-build-tools.yml new file mode 100644 index 0000000..92940c0 --- /dev/null +++ b/.github/workflows/javac-matcher-build-tools.yml @@ -0,0 +1,155 @@ +name: javac problem matcher with Maven & Gradle + +# The javac problem matcher registered by setup-java (##[add-matcher] java.json) +# only understands javac's *native* diagnostic format: +# +# File.java:12: warning|error: message +# +# (matcher regex, owner=javac: ^([^:]+):(\d+): (warning|error): (.+?)$) +# +# This workflow demonstrates how the two major build tools interact with it: +# +# * Gradle passes javac diagnostics through unchanged, so they DO match the +# matcher and show up as GitHub annotations. +# * The Maven compiler plugin reformats diagnostics to +# [WARNING] /path/File.java:[line,col] message +# which does NOT match the matcher, so Maven builds are NOT annotated even +# though the compiler reports the same warnings/errors. +# +# Each job captures the build log and asserts the number of matcher-format lines, +# so the workflow is self-verifying (not just visual). Open a run and compare the +# Gradle job's Annotations panel (populated) with the Maven job's (empty). + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +env: + # Exact javac matcher regex from actions/setup-java .github/java.json, as a + # POSIX ERE for grep. [^:]+ = file (no colon), then :line:, then severity. + MATCHER_RE: '^[^:]+:[0-9]+: (warning|error): .+$' + +jobs: + gradle-is-annotated: + name: 'Gradle build IS annotated - ${{ matrix.os }}' + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Java (registers the javac problem matcher) + uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0 + with: + distribution: temurin + java-version: '21' + + - name: Gradle compile with warnings (matcher should annotate them) + working-directory: javac-matcher-gradle + shell: bash + run: | + set -euo pipefail + # compileJava emits warnings but succeeds; tee so the matcher sees the log too. + ./gradlew --no-daemon --console=plain clean compileJava 2>&1 | tee warn.log + hits=$(grep -Ec "$MATCHER_RE" warn.log || true) + echo "matcher-format lines: $hits" + if [ "$hits" -lt 1 ]; then + echo "::error::expected Gradle warnings in native javac format (matcher would annotate)" + exit 1 + fi + echo "OK: $hits Gradle warning line(s) match the javac matcher -> annotated" + + - name: Gradle compile with errors (matcher should annotate them) + id: compile + continue-on-error: true + working-directory: javac-matcher-gradle + shell: bash + run: ./gradlew --no-daemon --console=plain compileErrorsJava 2>&1 | tee err.log + + - name: Confirm Gradle errors failed the build and match the matcher + working-directory: javac-matcher-gradle + shell: bash + run: | + set -euo pipefail + echo "compile outcome: ${{ steps.compile.outcome }}" + if [ "${{ steps.compile.outcome }}" != "failure" ]; then + echo "::error::expected Gradle compileErrorsJava to fail" + exit 1 + fi + hits=$(grep -Ec "$MATCHER_RE" err.log || true) + echo "matcher-format lines: $hits" + if [ "$hits" -lt 1 ]; then + echo "::error::expected Gradle errors in native javac format (matcher would annotate)" + exit 1 + fi + echo "OK: $hits Gradle error line(s) match the javac matcher -> annotated" + + maven-is-not-annotated: + name: 'Maven build is NOT annotated - ${{ matrix.os }}' + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Java (registers the javac problem matcher) + uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0 + with: + distribution: temurin + java-version: '21' + + - name: Maven compile with warnings (matcher must NOT annotate them) + working-directory: javac-matcher-maven + shell: bash + run: | + set -euo pipefail + mvn -B clean compile 2>&1 | tee warn.log + matcher=$(grep -Ec "$MATCHER_RE" warn.log || true) + diags=$(grep -Ec '\.java:\[[0-9]+,[0-9]+\]' warn.log || true) + echo "matcher-format lines: $matcher (expect 0), maven [line,col] diagnostics: $diags (expect >0)" + if [ "$diags" -lt 1 ]; then + echo "::error::expected the Maven compiler to report warnings ([WARNING] File.java:[l,c] ...)" + exit 1 + fi + if [ "$matcher" -ne 0 ]; then + echo "::error::Maven output unexpectedly matched the javac matcher" + exit 1 + fi + echo "OK: Maven reported $diags warning(s), but 0 lines match the matcher -> not annotated" + + - name: Maven compile with errors (fails; matcher must NOT annotate them) + id: compile + continue-on-error: true + working-directory: javac-matcher-maven + shell: bash + run: mvn -B -Perrors clean compile 2>&1 | tee err.log + + - name: Confirm Maven errors failed the build but were not matcher-annotated + working-directory: javac-matcher-maven + shell: bash + run: | + set -euo pipefail + echo "compile outcome: ${{ steps.compile.outcome }}" + if [ "${{ steps.compile.outcome }}" != "failure" ]; then + echo "::error::expected Maven -Perrors compile to fail" + exit 1 + fi + matcher=$(grep -Ec "$MATCHER_RE" err.log || true) + diags=$(grep -Ec '\.java:\[[0-9]+,[0-9]+\]' err.log || true) + echo "matcher-format lines: $matcher (expect 0), maven [line,col] diagnostics: $diags (expect >0)" + if [ "$diags" -lt 1 ]; then + echo "::error::expected the Maven compiler to report errors ([ERROR] File.java:[l,c] ...)" + exit 1 + fi + if [ "$matcher" -ne 0 ]; then + echo "::error::Maven error output unexpectedly matched the javac matcher" + exit 1 + fi + echo "OK: Maven reported $diags error(s) in the log, but 0 lines match the matcher -> not annotated" diff --git a/.gitignore b/.gitignore index e97c6ee..4f011c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ target/ *.class +.gradle/ +build/ +*.log diff --git a/README.md b/README.md index ff9ae2a..cbc572f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,28 @@ Both are expected to pass: together they document exactly what changed. - `.github/workflows/` — one workflow per feature, each running on Ubuntu, Windows and macOS. - `maven-sample-project/` — a tiny Maven project with one external dependency, used by `maven-args.yml` to prove that transfer-progress logs are suppressed by default. +- `javac-matcher/` — standalone `.java` sources (warnings + errors) compiled directly with + `javac` by `javac-problem-matcher.yml`. +- `javac-matcher-maven/` / `javac-matcher-gradle/` — the same warning/error sources built + through Maven and Gradle, used by `javac-matcher-build-tools.yml` (below). + +## javac problem matcher vs build tools + +The `javac` problem matcher registered by setup-java only understands javac's **native** +diagnostic format (`File.java:12: warning|error: message`). Whether your build gets +annotated therefore depends on the build tool: + +| Build tool | Compiler output | Matched by `javac` matcher? | +|------------|-----------------|-----------------------------| +| Direct `javac` | `File.java:12: warning: …` | ✅ annotated | +| **Gradle** | `File.java:12: warning: …` (passed through) | ✅ annotated | +| **Maven** (compiler plugin) | `[WARNING] /path/File.java:[12,5] …` | ❌ not annotated | + +[`javac-matcher-build-tools.yml`](.github/workflows/javac-matcher-build-tools.yml) proves +this by capturing each build log and asserting the number of matcher-format lines (0 for +Maven, >0 for Gradle) — so it fails loudly if the behavior ever changes. ## Running + Push to `main`, open a PR, or trigger any workflow manually via **workflow_dispatch**. diff --git a/javac-matcher-gradle/build.gradle b/javac-matcher-gradle/build.gradle new file mode 100644 index 0000000..57950fa --- /dev/null +++ b/javac-matcher-gradle/build.gradle @@ -0,0 +1,33 @@ +plugins { + id 'java' +} + +// Exercises the javac problem matcher registered by setup-java when the build is +// driven by Gradle. Gradle passes javac diagnostics through in their native form +// "/path/File.java:line: warning|error: message", which the matcher regex +// ^([^:]+):(\d+): (warning|error): (.+?)$ DOES match, so Gradle builds ARE +// annotated. See .github/workflows/javac-matcher-build-tools.yml. +// +// ./gradlew compileJava -> compiles the warning sources (succeeds, warns) +// ./gradlew compileErrorsJava -> compiles the failing sources (fails) + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +sourceSets { + // Failing sources live in their own source set so they can be compiled in a + // dedicated step without breaking the (successful) warning compilation. + errors { + java { + srcDir 'src/errors/java' + } + } +} + +tasks.withType(JavaCompile).configureEach { + options.compilerArgs += ['-Xlint:all'] + options.deprecation = true +} diff --git a/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.jar b/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b1b8ef5 Binary files /dev/null and b/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.properties b/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d990f1a --- /dev/null +++ b/javac-matcher-gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,9 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/javac-matcher-gradle/gradlew b/javac-matcher-gradle/gradlew new file mode 100755 index 0000000..249efbb --- /dev/null +++ b/javac-matcher-gradle/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 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. +# You may obtain a copy of the License at +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# 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». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/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/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# 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 + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + 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 +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# 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. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/javac-matcher-gradle/gradlew.bat b/javac-matcher-gradle/gradlew.bat new file mode 100644 index 0000000..8508ef6 --- /dev/null +++ b/javac-matcher-gradle/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@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 +@rem ########################################################################## +@rem +@rem gradlew startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +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 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +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 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/javac-matcher-gradle/settings.gradle b/javac-matcher-gradle/settings.gradle new file mode 100644 index 0000000..508ca24 --- /dev/null +++ b/javac-matcher-gradle/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'javac-matcher-gradle' diff --git a/javac-matcher-gradle/src/errors/java/Broken.java b/javac-matcher-gradle/src/errors/java/Broken.java new file mode 100644 index 0000000..5bbe558 --- /dev/null +++ b/javac-matcher-gradle/src/errors/java/Broken.java @@ -0,0 +1,7 @@ +public class Broken { + public static void main(String[] args) { + int x = y + 1; // error: cannot find symbol (y is undefined) + String s = 123; // error: incompatible types + System.out.println(x + s); + } +} diff --git a/javac-matcher-gradle/src/main/java/App.java b/javac-matcher-gradle/src/main/java/App.java new file mode 100644 index 0000000..8c98c54 --- /dev/null +++ b/javac-matcher-gradle/src/main/java/App.java @@ -0,0 +1,13 @@ +import java.util.ArrayList; +import java.util.List; + +public class App { + public static void main(String[] args) { + Legacy legacy = new Legacy(); + System.out.println(legacy.oldGreeting()); // [deprecation] warning + + List raw = new ArrayList(); // [rawtypes] warning + raw.add("unchecked call"); // [unchecked] warning + System.out.println(raw); + } +} diff --git a/javac-matcher-gradle/src/main/java/Legacy.java b/javac-matcher-gradle/src/main/java/Legacy.java new file mode 100644 index 0000000..1ea3cec --- /dev/null +++ b/javac-matcher-gradle/src/main/java/Legacy.java @@ -0,0 +1,11 @@ +public class Legacy { + /** @deprecated use {@link #greeting()} instead. */ + @Deprecated + public String oldGreeting() { + return "hi"; + } + + public String greeting() { + return "hello"; + } +} diff --git a/javac-matcher-maven/pom.xml b/javac-matcher-maven/pom.xml new file mode 100644 index 0000000..861524d --- /dev/null +++ b/javac-matcher-maven/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.example + javac-matcher-maven + 1.0.0 + jar + + + + + 21 + UTF-8 + ${project.basedir}/src/main/java + + + + ${matcher.sourceDirectory} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + true + + -Xlint:all + + + + + + + + + errors + + ${project.basedir}/src/errors/java + + + + diff --git a/javac-matcher-maven/src/errors/java/Broken.java b/javac-matcher-maven/src/errors/java/Broken.java new file mode 100644 index 0000000..5bbe558 --- /dev/null +++ b/javac-matcher-maven/src/errors/java/Broken.java @@ -0,0 +1,7 @@ +public class Broken { + public static void main(String[] args) { + int x = y + 1; // error: cannot find symbol (y is undefined) + String s = 123; // error: incompatible types + System.out.println(x + s); + } +} diff --git a/javac-matcher-maven/src/main/java/App.java b/javac-matcher-maven/src/main/java/App.java new file mode 100644 index 0000000..8c98c54 --- /dev/null +++ b/javac-matcher-maven/src/main/java/App.java @@ -0,0 +1,13 @@ +import java.util.ArrayList; +import java.util.List; + +public class App { + public static void main(String[] args) { + Legacy legacy = new Legacy(); + System.out.println(legacy.oldGreeting()); // [deprecation] warning + + List raw = new ArrayList(); // [rawtypes] warning + raw.add("unchecked call"); // [unchecked] warning + System.out.println(raw); + } +} diff --git a/javac-matcher-maven/src/main/java/Legacy.java b/javac-matcher-maven/src/main/java/Legacy.java new file mode 100644 index 0000000..1ea3cec --- /dev/null +++ b/javac-matcher-maven/src/main/java/Legacy.java @@ -0,0 +1,11 @@ +public class Legacy { + /** @deprecated use {@link #greeting()} instead. */ + @Deprecated + public String oldGreeting() { + return "hi"; + } + + public String greeting() { + return "hello"; + } +}