From a93a424687c2125c02dfb712e7c5055098dfd0c4 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Thu, 17 Jul 2025 10:36:22 +0200 Subject: [PATCH 01/14] removeWildcardImports: throw new AssertionError instead of removing --- .../spotless/generic/ReplaceRegexStep.java | 22 +++++++++++++- .../java/RemoveWildcardImportsStep.java | 14 +++++---- .../maven/MavenIntegrationHarness.java | 2 ++ .../java/RemoveWildcardImportsStepTest.java | 29 ++++++++++++++++--- .../JavaCodeNoWildcardsFormatted.test | 4 +++ .../JavaCodeNoWildcardsUnformatted.test | 4 +++ .../JavaCodeStaticWildcardsFormatted.test | 6 ++++ .../JavaCodeStaticWildcardsUnformatted.test | 6 ++++ .../JavaCodeWildcardsFormatted.test | 3 ++ .../JavaCodeWildcardsUnformatted.test | 2 -- 10 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsFormatted.test create mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test create mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test create mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index 990cf65806..e8e56861c8 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2025 DiffPlug * * 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 @@ */ package com.diffplug.spotless.generic; +import static com.diffplug.spotless.Lint.atUndefinedLine; + import java.io.Serializable; import java.util.Objects; import java.util.regex.Pattern; @@ -35,6 +37,15 @@ public static FormatterStep create(String name, String regex, String replacement State::toFormatter); } + public static FormatterStep lint(String name, String regex, String error) { + Objects.requireNonNull(name, "name"); + Objects.requireNonNull(regex, "regex"); + Objects.requireNonNull(error, "error"); + return FormatterStep.createLazy(name, + () -> new State(Pattern.compile(regex, Pattern.UNIX_LINES | Pattern.MULTILINE), error), + State::toLinter); + } + private static final class State implements Serializable { private static final long serialVersionUID = 1L; @@ -49,5 +60,14 @@ private static final class State implements Serializable { FormatterFunc toFormatter() { return raw -> regex.matcher(raw).replaceAll(replacement); } + + FormatterFunc toLinter() { + return raw -> { + if (regex.matcher(raw).find()) { + throw atUndefinedLine("", replacement).shortcut(); + } + return raw; + }; + } } } diff --git a/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java b/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java index ca513b8280..a3d3770c2b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java @@ -20,13 +20,17 @@ /** Removes any wildcard import statements. */ public final class RemoveWildcardImportsStep { + + /** + * Matches lines like 'import foo.*;' or 'import static foo.*;'. + */ + private static final String REGEX = "(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?"; + private static final String NAME = "removeWildcardImports"; + private static final String ERROR = "Do not use wildcard imports. 'spotlessApply' cannot resolve this issue."; + private RemoveWildcardImportsStep() {} public static FormatterStep create() { - // Matches lines like 'import foo.*;' or 'import static foo.*;'. - return ReplaceRegexStep.create( - "removeWildcardImports", - "(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?", - ""); + return ReplaceRegexStep.lint(NAME, REGEX, ERROR); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index f3e1f30355..a2fc252dac 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -46,6 +46,8 @@ import com.diffplug.spotless.ResourceHarness; public class MavenIntegrationHarness extends ResourceHarness { + + protected static final String PATH = "src/main/java/test.java"; /** * To run tests in the IDE, run {@code gradlew :plugin-maven:changelogPrint}, then * put the last version it prints into {@code SPOTLESS_MAVEN_VERSION_IDE}. From now diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 4d4ade94d0..9d435b0280 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -15,19 +15,40 @@ */ package com.diffplug.spotless.maven.java; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.diffplug.spotless.maven.MavenIntegrationHarness; class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { + private static final String ERROR = "Do not use wildcard imports. 'spotlessApply' cannot resolve this issue."; + + @BeforeEach + void init() throws Exception { + writePomWithJavaSteps(""); + } + @Test void testRemoveWildcardImports() throws Exception { - writePomWithJavaSteps(""); + setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); + assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); + assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR); + } - String path = "src/main/java/test.java"; - setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); + @Test + void testRemoveStaticWildcardImports() throws Exception { + setFile(PATH).toResource("java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test"); + assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test"); + assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR); + } + + @Test + void testRemoveWildcardImportsNoError() throws Exception { + setFile(PATH).toResource("java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test"); + assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); } } diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsFormatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsFormatted.test new file mode 100644 index 0000000000..85ee903fc5 --- /dev/null +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsFormatted.test @@ -0,0 +1,4 @@ +import java.util.List; +import mylib.Helper; + +public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test new file mode 100644 index 0000000000..85ee903fc5 --- /dev/null +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test @@ -0,0 +1,4 @@ +import java.util.List; +import mylib.Helper; + +public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test new file mode 100644 index 0000000000..6d1b2bd54c --- /dev/null +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test @@ -0,0 +1,6 @@ +import java.util.List; +import mylib.Helper; +import static io.quarkus.vertx.web.Route.HttpMethod.*; +import static org.springframework.web.reactive.function.BodyInserters.*; + +public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test new file mode 100644 index 0000000000..6d1b2bd54c --- /dev/null +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test @@ -0,0 +1,6 @@ +import java.util.List; +import mylib.Helper; +import static io.quarkus.vertx.web.Route.HttpMethod.*; +import static org.springframework.web.reactive.function.BodyInserters.*; + +public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test index 85ee903fc5..e6289598a5 100644 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test @@ -1,4 +1,7 @@ +import java.util.*; +import static java.util.Collections.*; import java.util.List; import mylib.Helper; +import io.quarkus.maven.dependency.*; public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test index 74646094ae..e6289598a5 100644 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test @@ -3,7 +3,5 @@ import static java.util.Collections.*; import java.util.List; import mylib.Helper; import io.quarkus.maven.dependency.*; -import static io.quarkus.vertx.web.Route.HttpMethod.*; -import static org.springframework.web.reactive.function.BodyInserters.*; public class Test {} \ No newline at end of file From b846b0bffc181f770a2e113da2fa70c0248d8128 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Thu, 17 Jul 2025 10:41:01 +0200 Subject: [PATCH 02/14] removeWildcardImports: throw new AssertionError instead of removing --- .../spotless/maven/java/RemoveWildcardImportsStepTest.java | 7 ------- .../JavaCodeStaticWildcardsFormatted.test | 6 ------ .../JavaCodeStaticWildcardsUnformatted.test | 6 ------ .../removewildcardimports/JavaCodeWildcardsFormatted.test | 2 ++ .../JavaCodeWildcardsUnformatted.test | 2 ++ 5 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test delete mode 100644 testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 9d435b0280..2261dd7c48 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -38,13 +38,6 @@ void testRemoveWildcardImports() throws Exception { assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR); } - @Test - void testRemoveStaticWildcardImports() throws Exception { - setFile(PATH).toResource("java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test"); - assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test"); - assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR); - } - @Test void testRemoveWildcardImportsNoError() throws Exception { setFile(PATH).toResource("java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test"); diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test deleted file mode 100644 index 6d1b2bd54c..0000000000 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsFormatted.test +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.List; -import mylib.Helper; -import static io.quarkus.vertx.web.Route.HttpMethod.*; -import static org.springframework.web.reactive.function.BodyInserters.*; - -public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test deleted file mode 100644 index 6d1b2bd54c..0000000000 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeStaticWildcardsUnformatted.test +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.List; -import mylib.Helper; -import static io.quarkus.vertx.web.Route.HttpMethod.*; -import static org.springframework.web.reactive.function.BodyInserters.*; - -public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test index e6289598a5..74646094ae 100644 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test @@ -3,5 +3,7 @@ import static java.util.Collections.*; import java.util.List; import mylib.Helper; import io.quarkus.maven.dependency.*; +import static io.quarkus.vertx.web.Route.HttpMethod.*; +import static org.springframework.web.reactive.function.BodyInserters.*; public class Test {} \ No newline at end of file diff --git a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test index e6289598a5..74646094ae 100644 --- a/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test +++ b/testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test @@ -3,5 +3,7 @@ import static java.util.Collections.*; import java.util.List; import mylib.Helper; import io.quarkus.maven.dependency.*; +import static io.quarkus.vertx.web.Route.HttpMethod.*; +import static org.springframework.web.reactive.function.BodyInserters.*; public class Test {} \ No newline at end of file From 730f211dce9983162466878be9d90def6461871b Mon Sep 17 00:00:00 2001 From: Vincent Potucek <8830888+Pankraz76@users.noreply.github.com> Date: Fri, 18 Jul 2025 13:30:00 +0200 Subject: [PATCH 03/14] Update lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java Co-authored-by: Owais Kazi --- .../com/diffplug/spotless/java/RemoveWildcardImportsStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java b/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java index a3d3770c2b..efb6ede93b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java @@ -26,7 +26,7 @@ public final class RemoveWildcardImportsStep { */ private static final String REGEX = "(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?"; private static final String NAME = "removeWildcardImports"; - private static final String ERROR = "Do not use wildcard imports. 'spotlessApply' cannot resolve this issue."; + private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; private RemoveWildcardImportsStep() {} From 777f4964e405033eaa2b42b291b0856bb54f4d73 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Fri, 18 Jul 2025 21:41:08 +0200 Subject: [PATCH 04/14] removeWildcardImports: throw new AssertionError instead of removing --- .../spotless/maven/java/RemoveWildcardImportsStepTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 2261dd7c48..d17ac3c47e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -24,7 +24,7 @@ class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { - private static final String ERROR = "Do not use wildcard imports. 'spotlessApply' cannot resolve this issue."; + private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; @BeforeEach void init() throws Exception { From 0956a48574aa6d480d44f180fd54647fbd77204a Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Fri, 18 Jul 2025 21:55:24 +0200 Subject: [PATCH 05/14] removeWildcardImports: throw new AssertionError instead of removing --- .../spotless/generic/ReplaceRegexStep.java | 3 ++- .../java/RemoveWildcardImportsStepTest.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index e8e56861c8..5a77752be5 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.generic; +import static com.diffplug.spotless.Lint.atLine; import static com.diffplug.spotless.Lint.atUndefinedLine; import java.io.Serializable; @@ -64,7 +65,7 @@ FormatterFunc toFormatter() { FormatterFunc toLinter() { return raw -> { if (regex.matcher(raw).find()) { - throw atUndefinedLine("", replacement).shortcut(); + throw atLine(11111,"", replacement).shortcut(); } return raw; }; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index d17ac3c47e..2f4ecd299f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -17,6 +17,13 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.diffplug.spotless.FormatterStep; + +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.kotlin.KtLintStep; + +import org.assertj.core.api.AbstractStringAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +42,16 @@ void init() throws Exception { void testRemoveWildcardImports() throws Exception { setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); - assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()).contains(ERROR); + AbstractStringAssert abstractStringAssert = assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()); + abstractStringAssert + .contains(ERROR) +// .contains("11111") + ; + + FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test", "java/removewildcardimports/JavaCodeWildcardsFormatted.test") + .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import"); } @Test From 350b8a4aa74be08e7058957a9554bfdf74d4c6cd Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Fri, 18 Jul 2025 21:57:59 +0200 Subject: [PATCH 06/14] wip --- .../spotless/maven/java/RemoveWildcardImportsStepTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 2f4ecd299f..7017e4843a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -45,7 +45,7 @@ void testRemoveWildcardImports() throws Exception { AbstractStringAssert abstractStringAssert = assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()); abstractStringAssert .contains(ERROR) -// .contains("11111") + .contains("11111") ; FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); From e13b9b07f1fe46ddddbc360fefc7cfb47c8ff0aa Mon Sep 17 00:00:00 2001 From: Deepak Date: Tue, 22 Jul 2025 22:21:29 +0530 Subject: [PATCH 07/14] Fix lint --- .../main/java/com/diffplug/spotless/Lint.java | 2 +- .../spotless/generic/ReplaceRegexStep.java | 6 +++-- .../spotless/JavaDefaultTargetTest.java | 2 +- .../java/RemoveWildcardImportsStepTest.java | 23 ++++--------------- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Lint.java b/lib/src/main/java/com/diffplug/spotless/Lint.java index b48a7bcbd2..8c65e45950 100644 --- a/lib/src/main/java/com/diffplug/spotless/Lint.java +++ b/lib/src/main/java/com/diffplug/spotless/Lint.java @@ -91,7 +91,7 @@ public ShortcutException(Lint... lints) { private final List lints; ShortcutException(Collection lints) { - super(lints.iterator().next().detail); + super(lints.iterator().next().toString()); this.lints = List.copyOf(lints); } diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index 5a77752be5..3f3452b3ea 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -64,8 +64,10 @@ FormatterFunc toFormatter() { FormatterFunc toLinter() { return raw -> { - if (regex.matcher(raw).find()) { - throw atLine(11111,"", replacement).shortcut(); + var matcher = regex.matcher(raw); + if (matcher.find()) { + int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count(); + throw atLine(line, matcher.group(0), replacement).shortcut(); } return raw; }; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java index 401e8ee330..21e372a822 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java @@ -97,7 +97,7 @@ void removeWildCardImports() throws IOException { "}"); setFile("test.java").toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); - gradleRunner().withArguments("spotlessApply").build(); + gradleRunner().withArguments("spotlessApply").buildAndFail(); assertFile("test.java").sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 7017e4843a..e145a28aba 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -17,13 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.diffplug.spotless.FormatterStep; - -import com.diffplug.spotless.StepHarnessWithFile; -import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.kotlin.KtLintStep; - -import org.assertj.core.api.AbstractStringAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,7 +24,9 @@ class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { - private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; + private static final String ERROR = + "L1: (import java.util.*;\n" + + ") Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; @BeforeEach void init() throws Exception { @@ -42,16 +37,8 @@ void init() throws Exception { void testRemoveWildcardImports() throws Exception { setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); - AbstractStringAssert abstractStringAssert = assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()); - abstractStringAssert - .contains(ERROR) - .contains("11111") - ; - - FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test", "java/removewildcardimports/JavaCodeWildcardsFormatted.test") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import"); + assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()) + .contains(ERROR); } @Test From 1cb31ddd52295656d59d0eaa8054878e39bf2b06 Mon Sep 17 00:00:00 2001 From: Deepak Date: Tue, 22 Jul 2025 22:47:28 +0530 Subject: [PATCH 08/14] spotless-apply --- .../spotless/maven/java/RemoveWildcardImportsStepTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index e145a28aba..5c77749f37 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -24,8 +24,7 @@ class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { - private static final String ERROR = - "L1: (import java.util.*;\n" + + private static final String ERROR = "L1: (import java.util.*;\n" + ") Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; @BeforeEach @@ -38,7 +37,7 @@ void testRemoveWildcardImports() throws Exception { setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()) - .contains(ERROR); + .contains(ERROR); } @Test From 0f95d2f6b01ea4cd79d69d96cf768d3d264dc01f Mon Sep 17 00:00:00 2001 From: Deepak Date: Tue, 22 Jul 2025 23:12:27 +0530 Subject: [PATCH 09/14] lib-spotless-apply --- lib/src/main/java/com/diffplug/spotless/Lint.java | 2 +- .../java/com/diffplug/spotless/generic/ReplaceRegexStep.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Lint.java b/lib/src/main/java/com/diffplug/spotless/Lint.java index 8c65e45950..b01a072905 100644 --- a/lib/src/main/java/com/diffplug/spotless/Lint.java +++ b/lib/src/main/java/com/diffplug/spotless/Lint.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 DiffPlug + * Copyright 2022-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index 3f3452b3ea..cc8932919c 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -16,7 +16,6 @@ package com.diffplug.spotless.generic; import static com.diffplug.spotless.Lint.atLine; -import static com.diffplug.spotless.Lint.atUndefinedLine; import java.io.Serializable; import java.util.Objects; From 362502aa31204fc86550047770ff7e87300ea25c Mon Sep 17 00:00:00 2001 From: Deepak Date: Wed, 23 Jul 2025 02:40:12 +0530 Subject: [PATCH 10/14] use lint-errors --- .../spotless/generic/ReplaceRegexStep.java | 25 +++++++--- .../java/RemoveWildcardImportsStepTest.java | 49 ------------------- .../generic/ReplaceRegexStepTest.java | 42 ++++++++++++++++ 3 files changed, 61 insertions(+), 55 deletions(-) delete mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java create mode 100644 testlib/src/test/java/com/diffplug/spotless/generic/ReplaceRegexStepTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index cc8932919c..309739b0fc 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -17,12 +17,16 @@ import static com.diffplug.spotless.Lint.atLine; +import java.io.File; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.regex.Pattern; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Lint; public final class ReplaceRegexStep { // prevent direct instantiation @@ -62,13 +66,22 @@ FormatterFunc toFormatter() { } FormatterFunc toLinter() { - return raw -> { - var matcher = regex.matcher(raw); - if (matcher.find()) { - int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count(); - throw atLine(line, matcher.group(0), replacement).shortcut(); + return new FormatterFunc() { + @Override + public String apply(String raw) { + return raw; + } + + @Override + public List lint(String raw, File file) { + List lints = new ArrayList<>(); + var matcher = regex.matcher(raw); + while (matcher.find()) { + int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count(); + lints.add(atLine(line, matcher.group(0), replacement)); + } + return lints; } - return raw; }; } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java deleted file mode 100644 index 5c77749f37..0000000000 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2025 DiffPlug - * - * 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 com.diffplug.spotless.maven.java; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.diffplug.spotless.maven.MavenIntegrationHarness; - -class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { - - private static final String ERROR = "L1: (import java.util.*;\n" + - ") Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this"; - - @BeforeEach - void init() throws Exception { - writePomWithJavaSteps(""); - } - - @Test - void testRemoveWildcardImports() throws Exception { - setFile(PATH).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); - assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); - assertThat(mavenRunner().withArguments("spotless:apply").runHasError().stdOutUtf8()) - .contains(ERROR); - } - - @Test - void testRemoveWildcardImportsNoError() throws Exception { - setFile(PATH).toResource("java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test"); - assertFile(PATH).sameAsResource("java/removewildcardimports/JavaCodeNoWildcardsUnformatted.test"); - mavenRunner().withArguments("spotless:apply").runNoError(); - } -} diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/ReplaceRegexStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/ReplaceRegexStepTest.java new file mode 100644 index 0000000000..909255dfd5 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/generic/ReplaceRegexStepTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2025 DiffPlug + * + * 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 com.diffplug.spotless.generic; + +import org.junit.jupiter.api.Test; + +import com.diffplug.common.base.StringPrinter; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.StepHarness; + +class ReplaceRegexStepTest { + @Test + void formatter() throws Exception { + FormatterStep step = ReplaceRegexStep.create("replace", "bad", "good"); + StepHarness.forStep(step) + .test("bad bad", "good good"); + } + + @Test + void lint() throws Exception { + FormatterStep step = ReplaceRegexStep.lint("regex", "bad", "no bad words"); + StepHarness.forStep(step) + .expectLintsOf(StringPrinter.buildStringFromLines( + "bad", + "x bad y", + "ok")) + .toBe("L1 regex(bad) no bad words\nL2 regex(bad) no bad words"); + } +} From 04e40ffc13e2d7cb58be7b8ad33822c57352d15e Mon Sep 17 00:00:00 2001 From: Deepak Date: Wed, 23 Jul 2025 02:53:13 +0530 Subject: [PATCH 11/14] no lint-errors for maven spotless-apply --- .../java/RemoveWildcardImportsStepTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java new file mode 100644 index 0000000000..4d4ade94d0 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2025 DiffPlug + * + * 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 com.diffplug.spotless.maven.java; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { + + @Test + void testRemoveWildcardImports() throws Exception { + writePomWithJavaSteps(""); + + String path = "src/main/java/test.java"; + setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); + } +} From c0cf2da3d229d34428a8f7966a137f6178d44271 Mon Sep 17 00:00:00 2001 From: Deepak Date: Fri, 25 Jul 2025 01:25:36 +0530 Subject: [PATCH 12/14] undo changes --- .../spotless/maven/MavenIntegrationHarness.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index a2fc252dac..0d0582e180 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2025 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,6 @@ import com.diffplug.spotless.ResourceHarness; public class MavenIntegrationHarness extends ResourceHarness { - - protected static final String PATH = "src/main/java/test.java"; /** * To run tests in the IDE, run {@code gradlew :plugin-maven:changelogPrint}, then * put the last version it prints into {@code SPOTLESS_MAVEN_VERSION_IDE}. From now @@ -215,15 +213,9 @@ protected void writePom(String[] executions, String[] configuration, String[] de } protected MavenRunner mavenRunner() throws IOException { - MavenRunner mavenRunner = MavenRunner.create() + return MavenRunner.create() .withProjectDir(rootFolder()) .withRunner(runner); - System.getProperties().forEach((key, value) -> { - if (key instanceof String && ((String) key).startsWith("spotless") && value instanceof String) { - mavenRunner.withSystemProperty((String) key, (String) value); - } - }); - return mavenRunner; } private static ProcessRunner runner; From 9042049c9d3e6e92643d4fc77c3abcfd47728f2c Mon Sep 17 00:00:00 2001 From: Deepak Date: Fri, 25 Jul 2025 01:32:17 +0530 Subject: [PATCH 13/14] undo changes --- .../maven/MavenIntegrationHarness.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 0d0582e180..de8bef661d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,13 +87,13 @@ void gitAttributes() throws IOException { if (Jvm.version() >= 16) { // for GJF https://github.com/diffplug/spotless/issues/834 setFile(".mvn/jvm.config").toContent( - "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" + - // this last line is for Detekt - " --add-opens java.base/java.lang=ALL-UNNAMED"); + "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" + + // this last line is for Detekt + " --add-opens java.base/java.lang=ALL-UNNAMED"); } // copy the mvnw resources copy("mvnw").setExecutable(true); @@ -213,9 +213,15 @@ protected void writePom(String[] executions, String[] configuration, String[] de } protected MavenRunner mavenRunner() throws IOException { - return MavenRunner.create() - .withProjectDir(rootFolder()) - .withRunner(runner); + MavenRunner mavenRunner = MavenRunner.create() + .withProjectDir(rootFolder()) + .withRunner(runner); + System.getProperties().forEach((key, value) -> { + if (key instanceof String && ((String) key).startsWith("spotless") && value instanceof String) { + mavenRunner.withSystemProperty((String) key, (String) value); + } + }); + return mavenRunner; } private static ProcessRunner runner; @@ -337,8 +343,8 @@ protected static String[] formats(String... formats) { protected static String[] formats(String[]... formats) { String[] formatsArray = Arrays.stream(formats) - .flatMap(Arrays::stream) - .toArray(String[]::new); + .flatMap(Arrays::stream) + .toArray(String[]::new); return formats(formatsArray); } } From 8999fb2395f87f838467de2e5f87b7d628a038d0 Mon Sep 17 00:00:00 2001 From: Deepak Date: Fri, 25 Jul 2025 01:36:08 +0530 Subject: [PATCH 14/14] undo changes --- .../maven/MavenIntegrationHarness.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index de8bef661d..f3e1f30355 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -87,13 +87,13 @@ void gitAttributes() throws IOException { if (Jvm.version() >= 16) { // for GJF https://github.com/diffplug/spotless/issues/834 setFile(".mvn/jvm.config").toContent( - "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" + - " --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" + - // this last line is for Detekt - " --add-opens java.base/java.lang=ALL-UNNAMED"); + "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" + + " --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" + + // this last line is for Detekt + " --add-opens java.base/java.lang=ALL-UNNAMED"); } // copy the mvnw resources copy("mvnw").setExecutable(true); @@ -214,8 +214,8 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { MavenRunner mavenRunner = MavenRunner.create() - .withProjectDir(rootFolder()) - .withRunner(runner); + .withProjectDir(rootFolder()) + .withRunner(runner); System.getProperties().forEach((key, value) -> { if (key instanceof String && ((String) key).startsWith("spotless") && value instanceof String) { mavenRunner.withSystemProperty((String) key, (String) value); @@ -343,8 +343,8 @@ protected static String[] formats(String... formats) { protected static String[] formats(String[]... formats) { String[] formatsArray = Arrays.stream(formats) - .flatMap(Arrays::stream) - .toArray(String[]::new); + .flatMap(Arrays::stream) + .toArray(String[]::new); return formats(formatsArray); } }