From d2e311fcd8c06b855eb1241e129716b9afdfc9c0 Mon Sep 17 00:00:00 2001 From: lutovich Date: Sat, 10 Mar 2018 12:35:29 +0100 Subject: [PATCH 1/9] Cleanup Format and FormatterFactory Moved all generic formatter methods to `FormatterFactory` so that it is a base class for every configuration element. Made `Java`, `Scala` and `Format` extend it. --- .../spotless/maven/FormatterFactory.java | 24 +++++++++++++++-- .../spotless/maven/generic/Format.java | 26 +++++-------------- .../diffplug/spotless/maven/java/Java.java | 12 +++++++-- .../diffplug/spotless/maven/scala/Scala.java | 12 +++++++-- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index 42b04e33f9..dd0cbd4959 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -32,7 +32,7 @@ import com.diffplug.spotless.Formatter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; -import com.diffplug.spotless.maven.generic.LicenseHeader; +import com.diffplug.spotless.maven.generic.*; public abstract class FormatterFactory { @Parameter @@ -87,7 +87,27 @@ public final void addLicenseHeader(LicenseHeader licenseHeader) { addStepFactory(licenseHeader); } - protected void addStepFactory(FormatterStepFactory stepFactory) { + public final void addEndWithNewline(EndWithNewline endWithNewline) { + addStepFactory(endWithNewline); + } + + public final void addIndent(Indent indent) { + addStepFactory(indent); + } + + public final void addTrimTrailingWhitespace(TrimTrailingWhitespace trimTrailingWhitespace) { + addStepFactory(trimTrailingWhitespace); + } + + public final void addReplace(Replace replace) { + addStepFactory(replace); + } + + public final void addReplaceRegex(ReplaceRegex replaceRegex) { + addStepFactory(replaceRegex); + } + + protected final void addStepFactory(FormatterStepFactory stepFactory) { Objects.requireNonNull(stepFactory); stepFactories.add(stepFactory); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index 10f1ba505c..465381fb52 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -20,6 +20,12 @@ import com.diffplug.spotless.maven.FormatterFactory; +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for custom includes/excludes that executes list of generic, language agnostic steps, + * like {@link LicenseHeader}. + */ public class Format extends FormatterFactory { @Override @@ -32,24 +38,4 @@ public String licenseHeaderDelimiter() { // do not specify a default delimiter return null; } - - public void addEndWithNewline(EndWithNewline endWithNewline) { - addStepFactory(endWithNewline); - } - - public void addIndent(Indent indent) { - addStepFactory(indent); - } - - public void addTrimTrailingWhitespace(TrimTrailingWhitespace trimTrailingWhitespace) { - addStepFactory(trimTrailingWhitespace); - } - - public void addReplace(Replace replace) { - addStepFactory(replace); - } - - public void addReplaceRegex(ReplaceRegex replaceRegex) { - addStepFactory(replaceRegex); - } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index a8c0078fb9..f26be95c65 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -20,9 +20,17 @@ import java.util.Set; -import com.diffplug.spotless.maven.generic.Format; +import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.generic.LicenseHeader; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for java source files that can execute both language agnostic (e.g. {@link LicenseHeader}) + * and java-specific (e.g. {@link Eclipse}) steps. + */ +public class Java extends FormatterFactory { -public class Java extends Format { private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/java/**/*.java", "src/test/java/**/*.java")); private static final String LICENSE_HEADER_DELIMITER = "package "; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java index dbaada1cad..6c916cedb2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java @@ -20,9 +20,17 @@ import java.util.Set; -import com.diffplug.spotless.maven.generic.Format; +import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.generic.LicenseHeader; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for scala source files that can execute both language agnostic (e.g. {@link LicenseHeader}) + * and scala-specific (e.g. {@link Scalafmt}) steps. + */ +public class Scala extends FormatterFactory { -public class Scala extends Format { private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/scala/**/*.scala", "src/test/scala/**/*.scala", "src/main/scala/**/*.sc", "src/test/scala/**/*.sc")); private static final String LICENSE_HEADER_DELIMITER = "package "; From 0bcf53b639f3597913284e82461df10e5b504568 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Mar 2018 23:33:47 +0100 Subject: [PATCH 2/9] Moved Kotlin test resources from plugin-gradle to testlib --- .../kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test | 0 .../kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test | 0 .../resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {plugin-gradle/src/test => testlib/src/main}/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test (100%) rename {plugin-gradle/src/test => testlib/src/main}/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test (100%) rename {plugin-gradle/src/test => testlib/src/main}/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test (100%) diff --git a/plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test similarity index 100% rename from plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test rename to testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test diff --git a/plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test similarity index 100% rename from plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test rename to testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test diff --git a/plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test similarity index 100% rename from plugin-gradle/src/test/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test rename to testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test From ca64af90b0a5808d6e9f0c13e09d9977e03b2646 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Mar 2018 23:40:58 +0100 Subject: [PATCH 3/9] Support for Kotlin and Ktlint in maven plugin Kotlin formatter now supports all generic formatting steps (e.g. license header) and standard Ktlint formatter with configurable version. --- .../spotless/maven/AbstractSpotlessMojo.java | 6 ++- .../spotless/maven/kotlin/Kotlin.java | 45 +++++++++++++++++++ .../spotless/maven/kotlin/Ktlint.java | 35 +++++++++++++++ .../spotless/maven/MavenIntegrationTest.java | 4 ++ .../maven/generic/LicenseHeaderTest.java | 18 ++++++++ .../spotless/maven/kotlin/KtLintTest.java | 39 ++++++++++++++++ 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 26cda7dd6f..e83f871e63 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -42,6 +42,7 @@ import com.diffplug.spotless.maven.generic.Format; import com.diffplug.spotless.maven.generic.LicenseHeader; import com.diffplug.spotless.maven.java.Java; +import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.scala.Scala; public abstract class AbstractSpotlessMojo extends AbstractMojo { @@ -85,6 +86,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Scala scala; + @Parameter + private Kotlin kotlin; + protected abstract void process(List files, Formatter formatter) throws MojoExecutionException; @Override @@ -142,7 +146,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.of(format, java, scala) + return Stream.of(format, java, scala, kotlin) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java new file mode 100644 index 0000000000..9fd0b1f8af --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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.kotlin; + +import static com.diffplug.common.collect.Sets.newHashSet; +import static java.util.Collections.unmodifiableSet; + +import java.util.Set; + +import com.diffplug.spotless.maven.FormatterFactory; + +public class Kotlin extends FormatterFactory { + + private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/kotlin/**/*.kt", + "src/test/kotlin/**/*.kt")); + + private static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; + + @Override + public Set defaultIncludes() { + return DEFAULT_INCLUDES; + } + + @Override + public String licenseHeaderDelimiter() { + return LICENSE_HEADER_DELIMITER; + } + + public void addKtlint(Ktlint ktlint) { + addStepFactory(ktlint); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java new file mode 100644 index 0000000000..796523d315 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016 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.kotlin; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.kotlin.KtLintStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Ktlint implements FormatterStepFactory { + + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); + return KtLintStep.create(ktlintVersion, config.getProvisioner()); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java index c5d8e75620..d5fcfcb4f8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java @@ -98,6 +98,10 @@ protected void writePomWithScalaSteps(String... steps) throws IOException { writePom(groupWithSteps("scala", steps)); } + protected void writePomWithKotlinSteps(String... steps) throws IOException { + writePom(groupWithSteps("kotlin", steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 957bbd2e5c..5110f84dc6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -21,6 +21,7 @@ public class LicenseHeaderTest extends MavenIntegrationTest { private static final String KEY_LICENSE = "license/TestLicense"; + private static final String KOTLIN_LICENSE_HEADER = "// Hello, I'm Kotlin license header"; @Test public void fromFileJava() throws Exception { @@ -79,6 +80,23 @@ public void fromContentFormat() throws Exception { runTest(); } + @Test + public void fromContentKotlin() throws Exception { + writePomWithKotlinSteps( + "", + " ", + KOTLIN_LICENSE_HEADER, + " ", + ""); + + String path = "src/main/kotlin/test.kt"; + String noLicenseHeader = getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); + + setFile(path).toContent(noLicenseHeader); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader); + } + private void runTest() throws Exception { String path = "src/main/java/test.java"; setFile(path).toResource("license/MissingLicense.test"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java new file mode 100644 index 0000000000..1e91049c02 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 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.kotlin; + +import org.junit.Test; + +import com.diffplug.spotless.maven.MavenIntegrationTest; + +public class KtLintTest extends MavenIntegrationTest { + + @Test + public void testKtlint() throws Exception { + writePomWithKotlinSteps(""); + + String path1 = "src/main/kotlin/main1.kt"; + String path2 = "src/main/kotlin/main2.kt"; + + setFile(path1).toResource("kotlin/ktlint/basic.dirty"); + setFile(path2).toResource("kotlin/ktlint/basic.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + assertFile(path1).sameAsResource("kotlin/ktlint/basic.clean"); + assertFile(path2).sameAsResource("kotlin/ktlint/basic.clean"); + } +} From 60ecd22cbe2e7b39afc073c7bf8f695aa17b6ae8 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Mar 2018 23:45:50 +0100 Subject: [PATCH 4/9] Common constant for Kotlin's license header delimiter To share same regex between Gradle and Maven plugins. --- .../spotless/kotlin/KotlinConstants.java | 24 +++++++++++++++++++ .../gradle/spotless/KotlinExtension.java | 4 ++-- .../spotless/maven/kotlin/Kotlin.java | 3 +-- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java new file mode 100644 index 0000000000..5df0231b8d --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 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.kotlin; + +public final class KotlinConstants { + + // '^' is prepended to the regex in LICENSE_HEADER_DELIMITER later in FormatExtension.licenseHeader(String, String) + public static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; + + private KotlinConstants() {} +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 45a81a2630..0476dec337 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -15,6 +15,8 @@ */ package com.diffplug.gradle.spotless; +import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; + import java.util.Objects; import org.gradle.api.GradleException; @@ -25,8 +27,6 @@ import com.diffplug.spotless.kotlin.KtLintStep; public class KotlinExtension extends FormatExtension { - // '^' is prepended to the regex in LICENSE_HEADER_DELIMITER later in FormatExtension.licenseHeader(String, String) - private static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; static final String NAME = "kotlin"; public KotlinExtension(SpotlessExtension rootExtension) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java index 9fd0b1f8af..a53d6bd6f1 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java @@ -16,6 +16,7 @@ package com.diffplug.spotless.maven.kotlin; import static com.diffplug.common.collect.Sets.newHashSet; +import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; import static java.util.Collections.unmodifiableSet; import java.util.Set; @@ -27,8 +28,6 @@ public class Kotlin extends FormatterFactory { private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/kotlin/**/*.kt", "src/test/kotlin/**/*.kt")); - private static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; - @Override public Set defaultIncludes() { return DEFAULT_INCLUDES; From 8085880fbe278053a0b914334fd1ea1aa5b7183f Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Mar 2018 23:50:26 +0100 Subject: [PATCH 5/9] Update maven plugin changelog --- plugin-maven/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 191a28108a..d9d696745b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ ### Version 1.10.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-maven-plugin/)) * Fixed a bug in `LicenseHeaderStep` which caused an exception with some malformed date-aware licenses. ([#222](https://github.com/diffplug/spotless/pull/222)) +* Added support for Kotlin and Ktlint in Maven plugin ([#223](https://github.com/diffplug/spotless/pull/223)). ### Version 1.0.0.BETA4 - February 27th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.0.0.BETA4/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.0.0.BETA4)) From b761c4b602aa9d9de827b0a7d02a677eb0e97386 Mon Sep 17 00:00:00 2001 From: lutovich Date: Mon, 12 Mar 2018 23:54:00 +0100 Subject: [PATCH 6/9] Update main changelog about Ktlint support in maven plugin --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46b299811e..a17340781f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}} lib('java.ImportOrderStep') +'{{yes}} | {{yes}} | {{no}} |', lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{no}} |', extra('java.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |', -lib('kotlin.KtLintStep') +'{{yes}} | {{no}} | {{no}} |', +lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{no}} |', lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |', @@ -66,7 +66,7 @@ lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | [`java.ImportOrderStep`](lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java) | :+1: | :+1: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :white_large_square: | | [`java.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: | -| [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :white_large_square: | :white_large_square: | +| [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :white_large_square: | | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: | From c058ed7e794bc41ed0abbf81d83954703368455f Mon Sep 17 00:00:00 2001 From: lutovich Date: Tue, 13 Mar 2018 20:42:57 +0100 Subject: [PATCH 7/9] Use ImmutableSet for default includes --- .../main/java/com/diffplug/spotless/maven/java/Java.java | 7 ++----- .../java/com/diffplug/spotless/maven/kotlin/Kotlin.java | 6 ++---- .../java/com/diffplug/spotless/maven/scala/Scala.java | 8 +++----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index f26be95c65..f48f2b742c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -15,11 +15,9 @@ */ package com.diffplug.spotless.maven.java; -import static com.diffplug.common.collect.Sets.newHashSet; -import static java.util.Collections.unmodifiableSet; - import java.util.Set; +import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -31,8 +29,7 @@ */ public class Java extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/java/**/*.java", - "src/test/java/**/*.java")); + private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/java/**/*.java", "src/test/java/**/*.java"); private static final String LICENSE_HEADER_DELIMITER = "package "; @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java index a53d6bd6f1..51618613a4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java @@ -15,18 +15,16 @@ */ package com.diffplug.spotless.maven.kotlin; -import static com.diffplug.common.collect.Sets.newHashSet; import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; -import static java.util.Collections.unmodifiableSet; import java.util.Set; +import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; public class Kotlin extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/kotlin/**/*.kt", - "src/test/kotlin/**/*.kt")); + private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/kotlin/**/*.kt", "src/test/kotlin/**/*.kt"); @Override public Set defaultIncludes() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java index 6c916cedb2..423ca71930 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java @@ -15,11 +15,9 @@ */ package com.diffplug.spotless.maven.scala; -import static com.diffplug.common.collect.Sets.newHashSet; -import static java.util.Collections.unmodifiableSet; - import java.util.Set; +import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -31,8 +29,8 @@ */ public class Scala extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = unmodifiableSet(newHashSet("src/main/scala/**/*.scala", - "src/test/scala/**/*.scala", "src/main/scala/**/*.sc", "src/test/scala/**/*.sc")); + private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/scala/**/*.scala", + "src/test/scala/**/*.scala", "src/main/scala/**/*.sc", "src/test/scala/**/*.sc"); private static final String LICENSE_HEADER_DELIMITER = "package "; @Override From 4d7536d6f8f90b6633ec3b6f0947f4d1d4eb7c3b Mon Sep 17 00:00:00 2001 From: lutovich Date: Tue, 13 Mar 2018 21:06:17 +0100 Subject: [PATCH 8/9] Readme entries for Scala and Kotlin in Maven plugin --- plugin-maven/README.md | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 33c093d19d..751a46c47f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -115,6 +115,55 @@ By default, all files matching `src/main/java/**/*.java` and `src/test/java/**/* ``` + + +## Applying to Scala source + +By default, all files matching `src/main/scala/**/*.scala`, `src/test/scala/**/*.scala`, `src/main/scala/**/*.sc` and `src/test/scala/**/*.sc` Ant style pattern will be formatted. Each element under `` is a step, and they will be applied in the order specified. Every step is optional. + +```xml + + + + + /* Licensed under Apache-2.0 */ + ${basedir}/license-header + + + + + ${basedir}/scalafmt.conf + + 1.1.0 + + + +``` + + + +## Applying to Kotlin source + +By default, all files matching `src/main/kotlin/**/*.kt` and `src/test/kotlin/**/*.kt` Ant style pattern will be formatted. Each element under `` is a step, and they will be applied in the order specified. Every step is optional. + +```xml + + + + + /* Licensed under Apache-2.0 */ + ${basedir}/license-header + + + + + + 0.14.0 + + + +``` + ## Applying to custom sources From 178ffad3bd5b4c0ec46876eb2aae407c77c526b0 Mon Sep 17 00:00:00 2001 From: lutovich Date: Tue, 13 Mar 2018 21:07:25 +0100 Subject: [PATCH 9/9] Renamed test to match main source --- .../spotless/maven/kotlin/{KtLintTest.java => KtlintTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/{KtLintTest.java => KtlintTest.java} (95%) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java similarity index 95% rename from plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java rename to plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 1e91049c02..eac462f71e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtLintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -19,7 +19,7 @@ import com.diffplug.spotless.maven.MavenIntegrationTest; -public class KtLintTest extends MavenIntegrationTest { +public class KtlintTest extends MavenIntegrationTest { @Test public void testKtlint() throws Exception {