From 73dbd56ec4a717dff9a3a40e1b51270bf708d2ba Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 15 Feb 2024 09:12:47 +0100 Subject: [PATCH] [java] Add new java language versions 22 and 22-preview --- docs/pages/pmd/languages/java.md | 8 +++++--- docs/pages/pmd/userdocs/tools/ant.md | 2 +- .../java/net/sourceforge/pmd/it/BinaryDistributionIT.java | 1 + .../net/sourceforge/pmd/lang/java/JavaLanguageModule.java | 6 ++++-- .../sourceforge/pmd/lang/java/JavaLanguageModuleTest.java | 6 +++--- .../sourceforge/pmd/lang/java/LanguageVersionTest.java | 4 +++- .../net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt | 3 ++- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/pages/pmd/languages/java.md b/docs/pages/pmd/languages/java.md index 6354280cae..fd6397eb45 100644 --- a/docs/pages/pmd/languages/java.md +++ b/docs/pages/pmd/languages/java.md @@ -15,8 +15,10 @@ Usually the latest non-preview Java Version is the default version. | Java Version | Alias | Supported by PMD since | |--------------|-------|------------------------| +| 22-preview | | 7.0.0 | +| 22 (default) | | 7.0.0 | | 21-preview | | 7.0.0 | -| 21 (default) | | 7.0.0 | +| 21 | | 7.0.0 | | 20-preview | | 6.55.0 | | 20 | | 6.55.0 | | 19 | | 6.48.0 | @@ -40,10 +42,10 @@ Usually the latest non-preview Java Version is the default version. ## Using Java preview features In order to analyze a project with PMD that uses preview language features, you'll need to enable -it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `21-preview`: +it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `22-preview`: export PMD_JAVA_OPTS=--enable-preview - pmd check --use-version java-21-preview ... + pmd check --use-version java-22-preview ... Note: we only support preview language features for the latest two java versions. diff --git a/docs/pages/pmd/userdocs/tools/ant.md b/docs/pages/pmd/userdocs/tools/ant.md index f259bc7149..4c81ff7daf 100644 --- a/docs/pages/pmd/userdocs/tools/ant.md +++ b/docs/pages/pmd/userdocs/tools/ant.md @@ -212,7 +212,7 @@ accordingly and this rule won't be executed. The specific version of a language to be used is selected via the `sourceLanguage` nested element. Example: - + The available versions depend on the language. You can get a list of the currently supported language versions via the CLI option `--help`. diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 57c5de0638..f77532acb4 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -51,6 +51,7 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { "java-16", "java-17", "java-18", "java-19", "java-20", "java-20-preview", "java-21", "java-21-preview", + "java-22", "java-22-preview", "java-5", "java-6", "java-7", "java-8", "java-9", "jsp-2", "jsp-3", "kotlin-1.6", "kotlin-1.7", "kotlin-1.8", "modelica-3.4", "modelica-3.5", diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java index 562b6365e6..fc7a738088 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java @@ -43,8 +43,10 @@ public class JavaLanguageModule extends LanguageModuleBase implements PmdCapable .addVersion("19") .addVersion("20") .addVersion("20-preview") - .addDefaultVersion("21") // 21 is the default - .addVersion("21-preview")); + .addVersion("21") + .addVersion("21-preview") + .addDefaultVersion("22") // 22 is the default + .addVersion("22-preview")); } public static JavaLanguageModule getInstance() { diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaLanguageModuleTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaLanguageModuleTest.java index 4655032327..cdf292b34f 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaLanguageModuleTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaLanguageModuleTest.java @@ -24,10 +24,10 @@ class JavaLanguageModuleTest { @Test void previewVersionShouldBeGreaterThanNonPreview() { - LanguageVersion java20 = JavaLanguageModule.getInstance().getVersion("20"); - LanguageVersion java20p = JavaLanguageModule.getInstance().getVersion("20-preview"); + LanguageVersion java = JavaLanguageModule.getInstance().getVersion("22"); + LanguageVersion javaPreview = JavaLanguageModule.getInstance().getVersion("22-preview"); - assertTrue(java20p.compareTo(java20) > 0, "java20-preview should be greater than java20"); + assertTrue(javaPreview.compareTo(java) > 0, "java-preview should be greater than java"); } @Test diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/LanguageVersionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/LanguageVersionTest.java index 47f1619085..eea0472371 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/LanguageVersionTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/LanguageVersionTest.java @@ -40,8 +40,10 @@ class LanguageVersionTest extends AbstractLanguageVersionTest { new TestDescriptor(java, "20-preview"), new TestDescriptor(java, "21"), new TestDescriptor(java, "21-preview"), + new TestDescriptor(java, "22"), + new TestDescriptor(java, "22-preview"), - defaultVersionIs(java, "21"), + defaultVersionIs(java, "22"), // this one won't be found: case-sensitive! versionDoesNotExist("JAVA", "JAVA", "1.7"), diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt index 791df7c2a3..638f2d35bb 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt @@ -35,7 +35,8 @@ enum class JavaVersion : Comparable { J18, J19, J20, J20__PREVIEW, - J21, J21__PREVIEW; + J21, J21__PREVIEW, + J22, J22__PREVIEW; /** Name suitable for use with e.g. [JavaParsingHelper.parse] */ val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').lowercase()