From ae9ef44bc43b46ec16ac454bc62684776405646f Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Thu, 27 Dec 2018 14:07:27 +0100 Subject: [PATCH 01/28] first antlr4 dev version --- gradle/java-setup.gradle | 5 +- lib-extra/build.gradle | 3 + .../extra/antlr4/Antlr4FormatterStep.java | 109 ++++++++++++++++++ .../extra/antlr4/Antlr4FormatterStepTest.java | 31 +++++ .../gradle/spotless/Antlr4Extension.java | 49 ++++++++ .../gradle/spotless/SpotlessExtension.java | 5 + .../gradle/spotless/Antlr4ExtensionTest.java | 61 ++++++++++ .../gradle/spotless/Antlr4TaskTest.java | 74 ++++++++++++ .../main/resources/antlr4/Hello.formatted.g4 | 19 +++ .../resources/antlr4/Hello.unformatted.g4 | 5 + 10 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java create mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java create mode 100644 testlib/src/main/resources/antlr4/Hello.formatted.g4 create mode 100644 testlib/src/main/resources/antlr4/Hello.unformatted.g4 diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 3a42f18714..22b56ee493 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -6,7 +6,10 @@ buildscript { ////////// // JAVA // ////////// -repositories { jcenter() } +repositories { + mavenLocal() + jcenter() +} // setup java apply plugin: 'java' diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 45a754cded..7ab4c3c3cc 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -14,6 +14,9 @@ dependencies { // used for xml parsing in EclipseFormatter compile "org.codehaus.groovy:groovy-xml:2.4.7" + // used for antlr4 formatting + compile "com.khubla.antlr4formatter:antlr4formatter:0.1.0-SNAPSHOT" + // testing testCompile project(':testlib') testCompile "junit:junit:${VER_JUNIT}" diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java new file mode 100644 index 0000000000..83cbcd570b --- /dev/null +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java @@ -0,0 +1,109 @@ +/* + * 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.extra.antlr4; + +import com.khubla.antlr4formatter.Antlr4Formatter; + +import com.diffplug.spotless.FormatterStep; + +public class Antlr4FormatterStep { + + public static final String NAME = "antlr4"; + + private Antlr4FormatterStep() {} + + private static final String DEFAULT_VERSION = "4.7.1"; + static final String MAVEN_COORDINATE = "org.antlr:antlr4:"; + + public static FormatterStep create() { + return FormatterStep.createNeverUpToDate(NAME, Antlr4Formatter::format); + // (name, + // new State(name), + // step -> step::format); + } + + // private static final class State implements Serializable { + // private static final long serialVersionUID = 1L; + // + // private final String name; + // + // State(String name) { + // this.name = name; + // } + // + // public static String format(String raw) { + // System.out.println("formatting source ..."); + // return "asd"; + //// return Antlr4Formatter.format(raw); + // } + // } + + // static final class State implements Serializable { + // private static final long serialVersionUID = 1L; + // + // /** The jar that contains the formatter. */ + // final JarState jarState; + // + // State(String version, Provisioner provisioner) throws IOException { + // this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + // } + // + // FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException { + // ClassLoader classLoader = jarState.getClassLoader(); + // + // // String KtLint::format(String input, Iterable rules, Function2 errorCallback) + // + // // first, we get the standard rules + // Class standardRuleSetProviderClass = classLoader.loadClass("com.github.shyiko.ktlint.ruleset.standard.StandardRuleSetProvider"); + // Object standardRuleSet = standardRuleSetProviderClass.getMethod("get").invoke(standardRuleSetProviderClass.newInstance()); + // Iterable ruleSets = Collections.singletonList(standardRuleSet); + // + // // next, we create an error callback which throws an assertion error when the format is bad + // Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); + // Class lintErrorClass = classLoader.loadClass("com.github.shyiko.ktlint.core.LintError"); + // Method detailGetter = lintErrorClass.getMethod("getDetail"); + // Method lineGetter = lintErrorClass.getMethod("getLine"); + // Method colGetter = lintErrorClass.getMethod("getCol"); + // Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface}, + // (proxy, method, args) -> { + // Object lintError = args[0]; // com.github.shyiko.ktlint.core.LintError + // boolean corrected = (Boolean) args[1]; + // if (!corrected) { + // String detail = (String) detailGetter.invoke(lintError); + // int line = (Integer) lineGetter.invoke(lintError); + // int col = (Integer) colGetter.invoke(lintError); + // throw new AssertionError("Error on line: " + line + ", column: " + col + "\n" + detail); + // } + // return null; + // }); + // + // // grab the KtLint singleton + // Class ktlintClass = classLoader.loadClass("com.github.shyiko.ktlint.core.KtLint"); + // Object ktlint = ktlintClass.getDeclaredField("INSTANCE").get(null); + // // and its format method + // Method formatterMethod = ktlintClass.getMethod("", String.class, Iterable.class, Map.class, function2Interface); + // + // return input -> { + // try { + // String formatted = (String) formatterMethod.invoke(ktlint, input, ruleSets, userData, formatterCallback); + // return formatted; + // } catch (InvocationTargetException e) { + // throw ThrowingEx.unwrapCause(e); + // } + // }; + // } + // } +} diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java new file mode 100644 index 0000000000..ca81fa13d5 --- /dev/null +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java @@ -0,0 +1,31 @@ +/* + * 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.extra.antlr4; + +import org.junit.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; + +public class Antlr4FormatterStepTest extends ResourceHarness { + + @Test + public void sortImportsFromArray() throws Throwable { + FormatterStep step = Antlr4FormatterStep.create(); + assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); + } + +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java new file mode 100644 index 0000000000..3aa9246a78 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -0,0 +1,49 @@ +/* + * 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.gradle.spotless; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.extra.antlr4.Antlr4FormatterStep; + +public class Antlr4Extension extends FormatExtension { + static final String NAME = "antlr4"; + + public Antlr4Extension(SpotlessExtension rootExtension) { + super(rootExtension); + + Antlr4FormatExtension antlr4 = new Antlr4FormatExtension(); + addStep(antlr4.createStep()); + } + + public class Antlr4FormatExtension { + + Antlr4FormatExtension() {} + + private FormatterStep createStep() { + return Antlr4FormatterStep.create(); + } + } + + @Override + protected void setupTask(SpotlessTask task) { + // defaults to all antlr4 files + if (target == null) { + target = parseTarget("src/main/antlr4/**/*.g4"); + } + super.setupTask(task); + } + +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 9fa1d073d1..55bb8d6045 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -138,6 +138,11 @@ public void typescript(Action closure) { configure(TypescriptExtension.NAME, TypescriptExtension.class, closure); } + /** Configures the special antlr4-specific extension for antlr4 files. */ + public void antlr4(Action closure) { + configure(Antlr4Extension.NAME, Antlr4Extension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java new file mode 100644 index 0000000000..0cac4fcfa0 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -0,0 +1,61 @@ +/* + * 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.gradle.spotless; + +import java.io.IOException; + +import org.gradle.api.GradleException; +import org.junit.Test; + +public class Antlr4ExtensionTest extends GradleIntegrationTest { + + @Test + public void formatSingleGrammar() throws IOException, InterruptedException { + String testFile = "src/main/antlr4/Hello.g4"; + + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.gradle.spotless'", + "}", + "spotless {", + " antlr4 {", + " target 'src/main/antlr4/**/*.g4'", + " }", + "}"); + + String unformatted = "antlr4/Hello.unformatted.g4"; + String formatted = "antlr4/Hello.formatted.g4"; + setFile(testFile).toResource(unformatted); + + gradleRunner().withArguments("spotlessApply").build(); + + assertFile(testFile).sameAsResource(formatted); + } + + @Test(expected = GradleException.class) + public void missingTargetArgumentFailsFormatting() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.gradle.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " antlr4 {", + " }", + "}"); + } + +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java new file mode 100644 index 0000000000..fe1c468455 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java @@ -0,0 +1,74 @@ +/* + * 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.gradle.spotless; + +import static com.diffplug.gradle.spotless.Tasks.execute; + +import java.util.Collections; + +import org.gradle.api.GradleException; +import org.gradle.api.Project; +import org.gradle.testfixtures.ProjectBuilder; +import org.junit.Before; +import org.junit.Test; + +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.extra.antlr4.Antlr4FormatterStep; + +public class Antlr4TaskTest extends ResourceHarness { + private SpotlessTask checkTask; + private SpotlessTask applyTask; + + @Before + public void createTask() { + Project project = ProjectBuilder.builder().build(); + checkTask = project.getTasks().create("checkTaskUnderTest", SpotlessTask.class); + checkTask.setCheck(); + applyTask = project.getTasks().create("applyTaskUnderTest", SpotlessTask.class); + applyTask.setApply(); + } + + @Test(expected = GradleException.class) + public void testFormatCheckFail() throws Exception { + String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); + + checkTask.addStep(Antlr4FormatterStep.create()); + checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(unformatted))); + execute(checkTask); + } + + @Test + public void testFormatedCheckPass() throws Exception { + String formatted = getTestResource("antlr4/Hello.formatted.g4"); + + checkTask.addStep(Antlr4FormatterStep.create()); + checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(formatted))); + execute(checkTask); + } + + @Test + public void testFormatApplyPass() throws Exception { + String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); + String formatted = getTestResource("antlr4/Hello.formatted.g4"); + String testFile = "testFile.g4"; + + applyTask.addStep(Antlr4FormatterStep.create()); + applyTask.setTarget(Collections.singleton(setFile(testFile).toContent(unformatted))); + execute(applyTask); + + assertFile(testFile).hasContent(formatted); + } +} diff --git a/testlib/src/main/resources/antlr4/Hello.formatted.g4 b/testlib/src/main/resources/antlr4/Hello.formatted.g4 new file mode 100644 index 0000000000..efe3b821df --- /dev/null +++ b/testlib/src/main/resources/antlr4/Hello.formatted.g4 @@ -0,0 +1,19 @@ +// Define a grammar called Hello + +grammar Hello; + +r + : 'hello' ID + ; + +// match keyword hello followed by an identifier + +ID + : [a-z] + + ; + +// match lower-case identifiers + +WS + : [ \t\r\n] + -> skip + ; diff --git a/testlib/src/main/resources/antlr4/Hello.unformatted.g4 b/testlib/src/main/resources/antlr4/Hello.unformatted.g4 new file mode 100644 index 0000000000..a8af619185 --- /dev/null +++ b/testlib/src/main/resources/antlr4/Hello.unformatted.g4 @@ -0,0 +1,5 @@ +// Define a grammar called Hello +grammar Hello; +r : 'hello' ID ; // match keyword hello followed by an identifier +ID : [a-z]+ ; // match lower-case identifiers +WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines From 66f486a6a58820b96b4954755cb13141a35f80e4 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Thu, 27 Dec 2018 14:49:17 +0100 Subject: [PATCH 02/28] resolve antlr4 formatter lib at runtime --- lib-extra/build.gradle | 3 - .../extra/antlr4/Antlr4FormatterStep.java | 130 +++++++----------- .../extra/antlr4/Antlr4FormatterStepTest.java | 5 +- .../gradle/spotless/Antlr4Extension.java | 6 +- .../gradle/spotless/Antlr4TaskTest.java | 11 +- 5 files changed, 64 insertions(+), 91 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 7ab4c3c3cc..45a754cded 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -14,9 +14,6 @@ dependencies { // used for xml parsing in EclipseFormatter compile "org.codehaus.groovy:groovy-xml:2.4.7" - // used for antlr4 formatting - compile "com.khubla.antlr4formatter:antlr4formatter:0.1.0-SNAPSHOT" - // testing testCompile project(':testlib') testCompile "junit:junit:${VER_JUNIT}" diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java index 83cbcd570b..ec3bce59c4 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java @@ -15,9 +15,12 @@ */ package com.diffplug.spotless.extra.antlr4; -import com.khubla.antlr4formatter.Antlr4Formatter; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; -import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.*; public class Antlr4FormatterStep { @@ -25,85 +28,52 @@ public class Antlr4FormatterStep { private Antlr4FormatterStep() {} - private static final String DEFAULT_VERSION = "4.7.1"; - static final String MAVEN_COORDINATE = "org.antlr:antlr4:"; + private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4formatter:"; + private static final String DEFAULT_VERSION = "0.1.0-SNAPSHOT"; - public static FormatterStep create() { - return FormatterStep.createNeverUpToDate(NAME, Antlr4Formatter::format); - // (name, - // new State(name), - // step -> step::format); + public static FormatterStep create(Provisioner provisioner) { + return create(DEFAULT_VERSION, provisioner); } - // private static final class State implements Serializable { - // private static final long serialVersionUID = 1L; - // - // private final String name; - // - // State(String name) { - // this.name = name; - // } - // - // public static String format(String raw) { - // System.out.println("formatting source ..."); - // return "asd"; - //// return Antlr4Formatter.format(raw); - // } - // } - - // static final class State implements Serializable { - // private static final long serialVersionUID = 1L; - // - // /** The jar that contains the formatter. */ - // final JarState jarState; - // - // State(String version, Provisioner provisioner) throws IOException { - // this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); - // } - // - // FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException { - // ClassLoader classLoader = jarState.getClassLoader(); - // - // // String KtLint::format(String input, Iterable rules, Function2 errorCallback) - // - // // first, we get the standard rules - // Class standardRuleSetProviderClass = classLoader.loadClass("com.github.shyiko.ktlint.ruleset.standard.StandardRuleSetProvider"); - // Object standardRuleSet = standardRuleSetProviderClass.getMethod("get").invoke(standardRuleSetProviderClass.newInstance()); - // Iterable ruleSets = Collections.singletonList(standardRuleSet); - // - // // next, we create an error callback which throws an assertion error when the format is bad - // Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); - // Class lintErrorClass = classLoader.loadClass("com.github.shyiko.ktlint.core.LintError"); - // Method detailGetter = lintErrorClass.getMethod("getDetail"); - // Method lineGetter = lintErrorClass.getMethod("getLine"); - // Method colGetter = lintErrorClass.getMethod("getCol"); - // Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface}, - // (proxy, method, args) -> { - // Object lintError = args[0]; // com.github.shyiko.ktlint.core.LintError - // boolean corrected = (Boolean) args[1]; - // if (!corrected) { - // String detail = (String) detailGetter.invoke(lintError); - // int line = (Integer) lineGetter.invoke(lintError); - // int col = (Integer) colGetter.invoke(lintError); - // throw new AssertionError("Error on line: " + line + ", column: " + col + "\n" + detail); - // } - // return null; - // }); - // - // // grab the KtLint singleton - // Class ktlintClass = classLoader.loadClass("com.github.shyiko.ktlint.core.KtLint"); - // Object ktlint = ktlintClass.getDeclaredField("INSTANCE").get(null); - // // and its format method - // Method formatterMethod = ktlintClass.getMethod("", String.class, Iterable.class, Map.class, function2Interface); - // - // return input -> { - // try { - // String formatted = (String) formatterMethod.invoke(ktlint, input, ruleSets, userData, formatterCallback); - // return formatted; - // } catch (InvocationTargetException e) { - // throw ThrowingEx.unwrapCause(e); - // } - // }; - // } - // } + public static FormatterStep create(String version, Provisioner provisioner) { + // return FormatterStep.createNeverUpToDate(NAME, Antlr4Formatter::format); + + return FormatterStep.createLazy(NAME, () -> new State(defaultVersion(), provisioner), State::createFormat); + } + + public static String defaultVersion() { + return DEFAULT_VERSION; + } + + static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * The jar that contains the formatter. + */ + final JarState jarState; + + State(String version, Provisioner provisioner) throws IOException { + this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + } + + FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException { + ClassLoader classLoader = jarState.getClassLoader(); + + // String Antlr4Formatter::format(String input) + + Class formatter = classLoader.loadClass("com.khubla.antlr4formatter.Antlr4Formatter"); + Object formatterInstance = formatter.newInstance(); + // and its format method + Method formatterMethod = formatter.getMethod("format", String.class); + + return input -> { + try { + return (String) formatterMethod.invoke(formatterInstance, input); + } catch (InvocationTargetException e) { + throw ThrowingEx.unwrapCause(e); + } + }; + } + } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java index ca81fa13d5..a76abb7bb3 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java @@ -19,12 +19,13 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.TestProvisioner; public class Antlr4FormatterStepTest extends ResourceHarness { @Test - public void sortImportsFromArray() throws Throwable { - FormatterStep step = Antlr4FormatterStep.create(); + public void formatGrammar() throws Throwable { + FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenLocal()); assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 3aa9246a78..9cc9978aea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -25,15 +25,15 @@ public Antlr4Extension(SpotlessExtension rootExtension) { super(rootExtension); Antlr4FormatExtension antlr4 = new Antlr4FormatExtension(); - addStep(antlr4.createStep()); + addStep(antlr4.createStep(Antlr4FormatterStep.defaultVersion())); } public class Antlr4FormatExtension { Antlr4FormatExtension() {} - private FormatterStep createStep() { - return Antlr4FormatterStep.create(); + private FormatterStep createStep(String version) { + return Antlr4FormatterStep.create(version, GradleProvisioner.fromProject(getProject())); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java index fe1c468455..ffef4a149a 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java @@ -25,10 +25,15 @@ import org.junit.Before; import org.junit.Test; +import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.extra.antlr4.Antlr4FormatterStep; public class Antlr4TaskTest extends ResourceHarness { + + private Provisioner provisioner = TestProvisioner.mavenLocal(); + private SpotlessTask checkTask; private SpotlessTask applyTask; @@ -45,7 +50,7 @@ public void createTask() { public void testFormatCheckFail() throws Exception { String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); - checkTask.addStep(Antlr4FormatterStep.create()); + checkTask.addStep(Antlr4FormatterStep.create(provisioner)); checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(unformatted))); execute(checkTask); } @@ -54,7 +59,7 @@ public void testFormatCheckFail() throws Exception { public void testFormatedCheckPass() throws Exception { String formatted = getTestResource("antlr4/Hello.formatted.g4"); - checkTask.addStep(Antlr4FormatterStep.create()); + checkTask.addStep(Antlr4FormatterStep.create(provisioner)); checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(formatted))); execute(checkTask); } @@ -65,7 +70,7 @@ public void testFormatApplyPass() throws Exception { String formatted = getTestResource("antlr4/Hello.formatted.g4"); String testFile = "testFile.g4"; - applyTask.addStep(Antlr4FormatterStep.create()); + applyTask.addStep(Antlr4FormatterStep.create(provisioner)); applyTask.setTarget(Collections.singleton(setFile(testFile).toContent(unformatted))); execute(applyTask); From 40daf9abd6caef72254fa1c9082c0d4da63af45a Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 09:37:29 +0100 Subject: [PATCH 03/28] prepare for PR (#326) moved formatter to lib use formatter version available on maven central --- .../spotless}/antlr4/Antlr4FormatterStep.java | 19 +++++++------------ .../gradle/spotless/Antlr4Extension.java | 2 +- .../gradle/spotless/Antlr4ExtensionTest.java | 17 +---------------- .../gradle/spotless/Antlr4TaskTest.java | 4 ++-- .../antlr4/Antlr4FormatterStepTest.java | 4 ++-- 5 files changed, 13 insertions(+), 33 deletions(-) rename {lib-extra/src/main/java/com/diffplug/spotless/extra => lib/src/main/java/com/diffplug/spotless}/antlr4/Antlr4FormatterStep.java (76%) rename {lib-extra/src/test/java/com/diffplug/spotless/extra => testlib/src/test/java/com/diffplug/spotless}/antlr4/Antlr4FormatterStepTest.java (94%) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java similarity index 76% rename from lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java rename to lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index ec3bce59c4..994eff2d22 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.antlr4; +package com.diffplug.spotless.antlr4; import java.io.IOException; import java.io.Serializable; @@ -28,17 +28,15 @@ public class Antlr4FormatterStep { private Antlr4FormatterStep() {} - private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4formatter:"; - private static final String DEFAULT_VERSION = "0.1.0-SNAPSHOT"; + private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; + private static final String DEFAULT_VERSION = "1.1.0"; public static FormatterStep create(Provisioner provisioner) { - return create(DEFAULT_VERSION, provisioner); + return create(defaultVersion(), provisioner); } public static FormatterStep create(String version, Provisioner provisioner) { - // return FormatterStep.createNeverUpToDate(NAME, Antlr4Formatter::format); - - return FormatterStep.createLazy(NAME, () -> new State(defaultVersion(), provisioner), State::createFormat); + return FormatterStep.createLazy(NAME, () -> new State(version, provisioner), State::createFormat); } public static String defaultVersion() { @@ -57,19 +55,16 @@ static final class State implements Serializable { this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); } - FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException { + FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException { ClassLoader classLoader = jarState.getClassLoader(); // String Antlr4Formatter::format(String input) - Class formatter = classLoader.loadClass("com.khubla.antlr4formatter.Antlr4Formatter"); - Object formatterInstance = formatter.newInstance(); - // and its format method Method formatterMethod = formatter.getMethod("format", String.class); return input -> { try { - return (String) formatterMethod.invoke(formatterInstance, input); + return (String) formatterMethod.invoke(null, input); } catch (InvocationTargetException e) { throw ThrowingEx.unwrapCause(e); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 9cc9978aea..84bc334280 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -16,7 +16,7 @@ package com.diffplug.gradle.spotless; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.extra.antlr4.Antlr4FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4FormatterStep; public class Antlr4Extension extends FormatExtension { static final String NAME = "antlr4"; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 0cac4fcfa0..b66916d4f5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -17,13 +17,12 @@ import java.io.IOException; -import org.gradle.api.GradleException; import org.junit.Test; public class Antlr4ExtensionTest extends GradleIntegrationTest { @Test - public void formatSingleGrammar() throws IOException, InterruptedException { + public void formatSingleGrammar() throws IOException { String testFile = "src/main/antlr4/Hello.g4"; setFile("build.gradle").toLines( @@ -44,18 +43,4 @@ public void formatSingleGrammar() throws IOException, InterruptedException { assertFile(testFile).sameAsResource(formatted); } - - @Test(expected = GradleException.class) - public void missingTargetArgumentFailsFormatting() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.gradle.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " antlr4 {", - " }", - "}"); - } - } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java index ffef4a149a..ff22f9966f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java @@ -28,11 +28,11 @@ import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.extra.antlr4.Antlr4FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4FormatterStep; public class Antlr4TaskTest extends ResourceHarness { - private Provisioner provisioner = TestProvisioner.mavenLocal(); + private Provisioner provisioner = TestProvisioner.mavenCentral(); private SpotlessTask checkTask; private SpotlessTask applyTask; diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java similarity index 94% rename from lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java rename to testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java index a76abb7bb3..de37fcce5e 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/antlr4/Antlr4FormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.antlr4; +package com.diffplug.spotless.antlr4; import org.junit.Test; @@ -25,7 +25,7 @@ public class Antlr4FormatterStepTest extends ResourceHarness { @Test public void formatGrammar() throws Throwable { - FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenLocal()); + FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenCentral()); assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); } From 6663bba036796858ce9477fef47d9001a6707ea9 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 12:36:18 +0100 Subject: [PATCH 04/28] add option to configure Antlr4Formatter version used --- .../gradle/spotless/Antlr4Extension.java | 24 ++++++++--- .../gradle/spotless/Antlr4ExtensionTest.java | 41 +++++++++++++++++-- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 84bc334280..587de22d74 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -15,6 +15,8 @@ */ package com.diffplug.gradle.spotless; +import java.util.Objects; + import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.antlr4.Antlr4FormatterStep; @@ -23,17 +25,27 @@ public class Antlr4Extension extends FormatExtension { public Antlr4Extension(SpotlessExtension rootExtension) { super(rootExtension); + } + + public Antlr4FormatterConfig antlr4Formatter() { + return antlr4Formatter(Antlr4FormatterStep.defaultVersion()); + } - Antlr4FormatExtension antlr4 = new Antlr4FormatExtension(); - addStep(antlr4.createStep(Antlr4FormatterStep.defaultVersion())); + public Antlr4FormatterConfig antlr4Formatter(String version) { + return new Antlr4FormatterConfig(version); } - public class Antlr4FormatExtension { + public class Antlr4FormatterConfig { + + private final String version; - Antlr4FormatExtension() {} + Antlr4FormatterConfig(String version) { + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } - private FormatterStep createStep(String version) { - return Antlr4FormatterStep.create(version, GradleProvisioner.fromProject(getProject())); + private FormatterStep createStep() { + return Antlr4FormatterStep.create(this.version, GradleProvisioner.fromProject(getProject())); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index b66916d4f5..5ff90f0b88 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -22,18 +22,51 @@ public class Antlr4ExtensionTest extends GradleIntegrationTest { @Test - public void formatSingleGrammar() throws IOException { - String testFile = "src/main/antlr4/Hello.g4"; + public void applyUsingDefaultVersion() throws IOException { + String[] buildScript = { + "buildscript {", + " repositories {", + " mavenCentral()", + " }", + "}", + "plugins {", + " id 'com.diffplug.gradle.spotless'", + "}", + "spotless {", + " antlr4 {", + " target 'src/main/antlr4/**/*.g4'", + " antlr4Formatter()", + " }", + "}"}; - setFile("build.gradle").toLines( + assertAppliedFormat(buildScript); + } + + @Test + public void applyUsingCustomVersion() throws IOException { + String[] buildScript = { + "buildscript {", + " repositories {", + " mavenCentral()", + " }", + "}", "plugins {", " id 'com.diffplug.gradle.spotless'", "}", "spotless {", " antlr4 {", " target 'src/main/antlr4/**/*.g4'", + " antlr4Formatter('1.1.0')", " }", - "}"); + "}"}; + + assertAppliedFormat(buildScript); + } + + private void assertAppliedFormat(String... buildScript) throws IOException { + String testFile = "src/main/antlr4/Hello.g4"; + + setFile("build.gradle").toLines(buildScript); String unformatted = "antlr4/Hello.unformatted.g4"; String formatted = "antlr4/Hello.formatted.g4"; From deb3a76ce4e8f87711b2014b365d4555ea7d574f Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 13:13:49 +0100 Subject: [PATCH 05/28] rename step name --- .../java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 994eff2d22..8772c6f618 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -24,7 +24,7 @@ public class Antlr4FormatterStep { - public static final String NAME = "antlr4"; + public static final String NAME = "antlr4Formatter"; private Antlr4FormatterStep() {} From 84b2cb5ff7d9c06fb69166c9f0b3085c5c047912 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 13:17:14 +0100 Subject: [PATCH 06/28] add docs for gradle extension --- CHANGES.md | 1 + README.md | 2 ++ plugin-gradle/CHANGES.md | 1 + plugin-gradle/README.md | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 05fdf1aed9..ea15851e14 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ You might be looking for: - [plugin-maven/CHANGES.md](plugin-maven/CHANGES.md) ### Version 1.17.0-SNAPSHOT - TBD (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/snapshot/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/snapshot/), [snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/)) +* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)) ### Version 1.16.0 - October 30th 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.16.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.16.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) diff --git a/README.md b/README.md index f90b522738..ce21a7d857 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |', extra('wtp.WtpEclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |', +lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{no}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} |', '| Fast up-to-date checking | {{yes}} | {{no}} | {{no}} |', '| Automatic idempotency safeguard | {{yes}} | {{no}} | {{no}} |', @@ -78,6 +79,7 @@ extra('wtp.WtpEclipseFormatterStep') +'{{yes}} | {{yes}} | [`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: | | [`wtp.WtpEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: | +| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :white_large_square: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | | Fast up-to-date checking | :+1: | :white_large_square: | :white_large_square: | | Automatic idempotency safeguard | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 908ab1048a..5a4b1ecae6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,7 @@ ### Version 3.17.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/)) * Updated default eclipse-jdt from 4.7.3a to 4.9.0 ([#316](https://github.com/diffplug/spotless/pull/316)). New version addresses enum-tab formatting bug in 4.8 ([#314](https://github.com/diffplug/spotless/issues/314)). +* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)) ### Version 3.16.0 - October 30th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.16.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.16.0)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c7626d075f..5f8525f7e6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -89,6 +89,7 @@ Spotless can check and apply formatting to any plain-text file, using simple rul * [DBeaver sql format](https://dbeaver.jkiss.org/) * [Prettier: An opinionated code formatter](https://prettier.io) * [TypeScript Formatter (tsfmt)](https://github.com/vvakame/typescript-formatter) +* [Antlr4Formatter](https://github.com/antlr/Antlr4Formatter) * Any user-defined function which takes an unformatted string and outputs a formatted version. Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info. @@ -510,6 +511,26 @@ spotless { Spotless uses npm to install necessary packages locally. It runs prettier using [J2V8](https://github.com/eclipsesource/J2V8) internally after that. + + + +## Applying to ANTLR4 source + +By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` will be formatted. To change this, +set the `target` parameter as described in the [Custom rules](#custom) section. + +```gradle +spotless { + antlr4 { + // using default Antlr4Formatter version + antlr4Formatter() + + // specifiy a custom Antlr4Formatter version + antlr4Formatter('1.1.0') + } +} +``` + ## License header options From 55364f220774b48bcc62cded7fe698599a1bc8b7 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 13:26:31 +0100 Subject: [PATCH 07/28] remove mavenLocal development repository --- gradle/java-setup.gradle | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 22b56ee493..3a42f18714 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -6,10 +6,7 @@ buildscript { ////////// // JAVA // ////////// -repositories { - mavenLocal() - jcenter() -} +repositories { jcenter() } // setup java apply plugin: 'java' From f436c77b9aa02bd24ec17e71c4df0f32e59ac581 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 15:48:53 +0100 Subject: [PATCH 08/28] add antlr4 maven support --- README.md | 4 +- .../spotless/antlr4/Antlr4Defaults.java | 36 +++++++++++++ plugin-gradle/README.md | 4 +- .../gradle/spotless/Antlr4Extension.java | 15 ++++-- plugin-maven/CHANGES.md | 2 + plugin-maven/README.md | 21 ++++++++ .../spotless/maven/AbstractSpotlessMojo.java | 6 ++- .../spotless/maven/antlr4/Antlr4.java | 49 +++++++++++++++++ .../maven/antlr4/Antlr4Formatter.java | 35 ++++++++++++ .../spotless/maven/MavenIntegrationTest.java | 4 ++ .../maven/antlr4/Antlr4FormatterTest.java | 54 +++++++++++++++++++ 11 files changed, 222 insertions(+), 8 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java diff --git a/README.md b/README.md index ce21a7d857..24f66b8817 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |', extra('wtp.WtpEclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |', -lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{no}} | {{no}} |', +lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} |', '| Fast up-to-date checking | {{yes}} | {{no}} | {{no}} |', '| Automatic idempotency safeguard | {{yes}} | {{no}} | {{no}} |', @@ -79,7 +79,7 @@ lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{no}} | [`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: | | [`wtp.WtpEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: | -| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :white_large_square: | :white_large_square: | +| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :+1: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | | Fast up-to-date checking | :+1: | :white_large_square: | :white_large_square: | | Automatic idempotency safeguard | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java new file mode 100644 index 0000000000..73ebae5fa0 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -0,0 +1,36 @@ +/* + * 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.antlr4; + +import java.util.Arrays; +import java.util.List; + +public class Antlr4Defaults { + + private static final String LICENSE_HEADER_DELIMITER = "grammar "; + + private static final List defaultIncludes = Arrays.asList("src/main/antlr4/**/*.g4", "src/test/antlr4/**/*.g4"); + + private Antlr4Defaults() {} + + public static String licenseHeaderDelimiter() { + return LICENSE_HEADER_DELIMITER; + } + + public static List defaultIncludes() { + return defaultIncludes; + } +} diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index d829d098af..c7965e95e7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -522,10 +522,10 @@ set the `target` parameter as described in the [Custom rules](#custom) section. ```gradle spotless { antlr4 { - // using default Antlr4Formatter version + // use default Antlr4Formatter version antlr4Formatter() - // specifiy a custom Antlr4Formatter version + // specify a custom Antlr4Formatter version antlr4Formatter('1.1.0') } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 587de22d74..2e6f4ce7ce 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -18,9 +18,10 @@ import java.util.Objects; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4Defaults; import com.diffplug.spotless.antlr4.Antlr4FormatterStep; -public class Antlr4Extension extends FormatExtension { +public class Antlr4Extension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "antlr4"; public Antlr4Extension(SpotlessExtension rootExtension) { @@ -51,11 +52,19 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { - // defaults to all antlr4 files if (target == null) { - target = parseTarget("src/main/antlr4/**/*.g4"); + target = parseTarget(Antlr4Defaults.defaultIncludes()); } super.setupTask(task); } + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, Antlr4Defaults.licenseHeaderDelimiter()); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, Antlr4Defaults.licenseHeaderDelimiter()); + } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6e1e263727..89ce8a564b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,8 @@ ### Version 1.18.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/)) +* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)) + ### Version 1.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.17.0)) * Updated default eclipse-jdt from 4.7.3a to 4.9.0 ([#316](https://github.com/diffplug/spotless/pull/316)). New version addresses enum-tab formatting bug in 4.8 ([#314](https://github.com/diffplug/spotless/issues/314)). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d860633e6d..98678548c5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -240,6 +240,27 @@ Use Eclipse to define the *XML editor preferences* (see [Eclipse documentation]( The Eclipse WTP formatter supports DTD/XSD restrictions on white spaces. For XSD/DTD lookup, relative and absolute XSD/DTD URIs are supported. Furthermore a user catalog can be configured using the `userCatalog` property key. Add the property to the preference ``. + + +## Applying to ANTLR4 source + +By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` will be formatted. To change this, +set the `includes` parameter as described in the [File incudes and excludes](#includeExclude) section. + +```xml + + + + + + + + 1.1.0 + + + +``` + ## Applying to custom sources 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 c4047403df..109e2dd545 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 @@ -36,6 +36,7 @@ import com.diffplug.spotless.Formatter; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.maven.antlr4.Antlr4; import com.diffplug.spotless.maven.cpp.Cpp; import com.diffplug.spotless.maven.css.Css; import com.diffplug.spotless.maven.generic.Format; @@ -98,6 +99,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Css css; + @Parameter + private Antlr4 antlr4; + protected abstract void process(List files, Formatter formatter) throws MojoExecutionException; @Override @@ -156,7 +160,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp, css, xml)) + return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp, css, xml, antlr4)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java new file mode 100644 index 0000000000..16a7202478 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -0,0 +1,49 @@ +/* + * 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.antlr4; + +import java.util.Set; + +import com.diffplug.common.collect.ImmutableSet; +import com.diffplug.spotless.antlr4.Antlr4Defaults; +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 ANTLR4 source files that can execute both language agnostic (e.g. {@link LicenseHeader}) + * and anltr4-specific (e.g. {@link Antlr4Formatter}) steps. + */ +public class Antlr4 extends FormatterFactory { + + private static final Set DEFAULT_INCLUDES = ImmutableSet.copyOf(Antlr4Defaults.defaultIncludes()); + + @Override + public Set defaultIncludes() { + return DEFAULT_INCLUDES; + } + + @Override + public String licenseHeaderDelimiter() { + return Antlr4Defaults.licenseHeaderDelimiter(); + } + + public void addAntlr4Formatter(Antlr4Formatter antlr4Formatter) { + addStepFactory(antlr4Formatter); + } + +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java new file mode 100644 index 0000000000..afa92cea4c --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.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.antlr4; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.antlr4.Antlr4FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Antlr4Formatter implements FormatterStepFactory { + + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + String version = this.version == null ? Antlr4FormatterStep.defaultVersion() : this.version; + return Antlr4FormatterStep.create(version, stepConfig.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 8f0b5b2171..af7f475a3f 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 @@ -90,6 +90,10 @@ protected void writePomWithFormatSteps(String... steps) throws IOException { writePom(formats(groupWithSteps("format", including("src/**/java/**/*.java"), steps))); } + protected void writePomWithAntlr4Steps(String... steps) throws IOException { + writePom(groupWithSteps("antlr4", steps)); + } + protected void writePomWithJavaSteps(String... steps) throws IOException { writePom(groupWithSteps("java", steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java new file mode 100644 index 0000000000..dd51690791 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -0,0 +1,54 @@ +/* + * 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.antlr4; + +import org.junit.Test; + +import com.diffplug.spotless.maven.MavenIntegrationTest; + +public class Antlr4FormatterTest extends MavenIntegrationTest { + + @Test + public void applyUsingCustomVersion() throws Exception { + writePomWithAntlr4Steps( + "", + " 1.1.0", + ""); + runTest(); + } + + @Test + public void applyUsingDefaultVersion() throws Exception { + writePomWithAntlr4Steps( + "", + ""); + runTest(); + } + + @Test + public void applyUsingDefaultVersionSelfclosing() throws Exception { + writePomWithAntlr4Steps( + ""); + runTest(); + } + + private void runTest() throws Exception { + String path = "src/main/antlr4/Hello.g4"; + setFile(path).toResource("antlr4/Hello.unformatted.g4"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("antlr4/Hello.formatted.g4"); + } +} From 6dc960bf3ee17f34b5e72eff7af9f26da35135be Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 16:13:44 +0100 Subject: [PATCH 09/28] fix antlr4 includes/target docs --- plugin-gradle/README.md | 2 +- plugin-maven/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c7965e95e7..1e96d623b6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -516,7 +516,7 @@ Spotless uses npm to install necessary packages locally. It runs prettier using ## Applying to ANTLR4 source -By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` will be formatted. To change this, +By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` or `src/test/antlr4/**/*.g4` will be formatted. To change this, set the `target` parameter as described in the [Custom rules](#custom) section. ```gradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 98678548c5..873a44fdfa 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -244,7 +244,7 @@ The Eclipse WTP formatter supports DTD/XSD restrictions on white spaces. For XSD ## Applying to ANTLR4 source -By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` will be formatted. To change this, +By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` or `src/test/antlr4/**/*.g4` will be formatted. To change this, set the `includes` parameter as described in the [File incudes and excludes](#includeExclude) section. ```xml From 77a82c9ed84824b00065e0bb4ae44701c044c43e Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 16:53:06 +0100 Subject: [PATCH 10/28] fix antlr4 default license header separator --- .../main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java index 73ebae5fa0..405e063fed 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -20,7 +20,7 @@ public class Antlr4Defaults { - private static final String LICENSE_HEADER_DELIMITER = "grammar "; + private static final String LICENSE_HEADER_DELIMITER = "(grammar|lexer grammar|parser grammar)"; private static final List defaultIncludes = Arrays.asList("src/main/antlr4/**/*.g4", "src/test/antlr4/**/*.g4"); From 38e2baaa57ab9be864f996efa7081d24b27301f8 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Fri, 28 Dec 2018 16:59:22 +0100 Subject: [PATCH 11/28] add Antlr4Formatter to maven-plugin Readme --- plugin-maven/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 873a44fdfa..720a107467 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -76,6 +76,7 @@ Spotless supports the following powerful formatters: * Eclipse's [CDT](https://www.eclipse.org/cdt/) C/C++ code formatter * Eclipse's [WTP](https://www.eclipse.org/webtools/) CSS and XML code formatter * Google's [google-java-format](https://github.com/google/google-java-format) +* [Antlr4Formatter](https://github.com/antlr/Antlr4Formatter) * User-defined license enforcement, regex replacement, etc. Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info. From 341a8afa9c96ae2d47053b62029dc8965895cd40 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 12 Jun 2019 09:05:24 +0200 Subject: [PATCH 12/28] update Antlr4Formatter Version to upcoming release 1.2.1 --- .../java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java | 2 +- plugin-gradle/README.md | 2 +- .../java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java | 2 +- plugin-maven/README.md | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 8772c6f618..5643a9da88 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -29,7 +29,7 @@ public class Antlr4FormatterStep { private Antlr4FormatterStep() {} private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; - private static final String DEFAULT_VERSION = "1.1.0"; + private static final String DEFAULT_VERSION = "1.2.1"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 70eca60269..bd275408f9 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -534,7 +534,7 @@ spotless { antlr4Formatter() // specify a custom Antlr4Formatter version - antlr4Formatter('1.1.0') + antlr4Formatter('1.2.1') } } ``` diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 5ff90f0b88..2d1db932f2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -56,7 +56,7 @@ public void applyUsingCustomVersion() throws IOException { "spotless {", " antlr4 {", " target 'src/main/antlr4/**/*.g4'", - " antlr4Formatter('1.1.0')", + " antlr4Formatter('1.2.1')", " }", "}"}; diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e9d3fda326..76f0852a9a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -209,7 +209,7 @@ set the `includes` parameter as described in the [File incudes and excludes](#in - 1.1.0 + 1.2.1 diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index dd51690791..21fd1fb0eb 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -25,7 +25,7 @@ public class Antlr4FormatterTest extends MavenIntegrationTest { public void applyUsingCustomVersion() throws Exception { writePomWithAntlr4Steps( "", - " 1.1.0", + " 1.2.1", ""); runTest(); } From 642cda962f767cfdf032088e4d44c1bcce9e8d39 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 12 Jun 2019 09:34:34 +0200 Subject: [PATCH 13/28] Revert "update Antlr4Formatter Version to upcoming release 1.2.1" This reverts commit 341a8afa --- .../java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java | 2 +- plugin-gradle/README.md | 2 +- .../java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java | 2 +- plugin-maven/README.md | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 5643a9da88..8772c6f618 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -29,7 +29,7 @@ public class Antlr4FormatterStep { private Antlr4FormatterStep() {} private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; - private static final String DEFAULT_VERSION = "1.2.1"; + private static final String DEFAULT_VERSION = "1.1.0"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bd275408f9..70eca60269 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -534,7 +534,7 @@ spotless { antlr4Formatter() // specify a custom Antlr4Formatter version - antlr4Formatter('1.2.1') + antlr4Formatter('1.1.0') } } ``` diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 2d1db932f2..5ff90f0b88 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -56,7 +56,7 @@ public void applyUsingCustomVersion() throws IOException { "spotless {", " antlr4 {", " target 'src/main/antlr4/**/*.g4'", - " antlr4Formatter('1.2.1')", + " antlr4Formatter('1.1.0')", " }", "}"}; diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 76f0852a9a..e9d3fda326 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -209,7 +209,7 @@ set the `includes` parameter as described in the [File incudes and excludes](#in - 1.2.1 + 1.1.0 diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index 21fd1fb0eb..dd51690791 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -25,7 +25,7 @@ public class Antlr4FormatterTest extends MavenIntegrationTest { public void applyUsingCustomVersion() throws Exception { writePomWithAntlr4Steps( "", - " 1.2.1", + " 1.1.0", ""); runTest(); } From e5818be4abc5f33ffd79c7fab155d36d3dae4cb0 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Tue, 10 Mar 2020 19:32:55 +0100 Subject: [PATCH 14/28] removed duplicated changelog entries --- CHANGES.md | 2 -- plugin-gradle/CHANGES.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9b80eea81a..8c0ffa3e92 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,8 +18,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * We no longer publish `-SNAPSHOT` for every build to `master`, since we have good [JitPack integration](https://github.com/diffplug/spotless/blob/master/CONTRIBUTING.md#gradle---any-commit-in-a-public-github-repo-this-one-or-any-fork). ([#508](https://github.com/diffplug/spotless/pull/508)) * Improved how we use Spotless on itself. ([#509](https://github.com/diffplug/spotless/pull/509)) -* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). - ## [1.27.0] - 2020-01-01 * Ignored `KtLintStepTest`, because [gradle/gradle#11752](https://github.com/gradle/gradle/issues/11752) is causing too many CI failures. ([#499](https://github.com/diffplug/spotless/pull/499)) * Also fixed a minor problem in TestProvisioner. diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d37a6e4047..ec908a95f2 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,8 +5,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] * Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). -* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). - ## [3.27.2] - 2020-03-05 * Add tests to `SpecificFilesTest` to fix [#529](https://github.com/diffplug/spotless/issues/529) * If you applied spotless to a subproject, but not to the root project, then on Gradle 6+ you would get the deprecation warning `Using method Project#afterEvaluate(Action) when the project is already evaluated has been deprecated.` This has now been fixed. ([#506](https://github.com/diffplug/spotless/issues/506)) From 3117cb419b8cb0b3cc04cb75e54590424d2f006e Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Tue, 10 Mar 2020 19:35:21 +0100 Subject: [PATCH 15/28] fix spelling --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8c0ffa3e92..b3075a7ff9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Build * All `CHANGES.md` are now in keepachangelog format. ([#507](https://github.com/diffplug/spotless/pull/507)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ec908a95f2..873799e521 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] -* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ## [3.27.2] - 2020-03-05 * Add tests to `SpecificFilesTest` to fix [#529](https://github.com/diffplug/spotless/issues/529) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6c251af8e7..7dbaf8a7bf 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] * Fix scala and kotlin maven config documentation. -* Added Antlr4 support ([#326](https://github.com/diffplug/spotless/issues/326)). +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ## [1.27.0] - 2020-01-01 * Should be no changes whatsoever! Released only for consistency with lib and plugin-gradle. From 81c6f1c0824f0bd29f2df7c96f28b388f5e23c31 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 25 Mar 2020 13:56:01 +0100 Subject: [PATCH 16/28] update Antlr4Formatter lib to fixed version 1.2.1 --- .../java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java | 2 +- plugin-gradle/README.md | 2 +- .../java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java | 2 +- plugin-maven/README.md | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 8772c6f618..5643a9da88 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -29,7 +29,7 @@ public class Antlr4FormatterStep { private Antlr4FormatterStep() {} private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; - private static final String DEFAULT_VERSION = "1.1.0"; + private static final String DEFAULT_VERSION = "1.2.1"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 0c93111b26..40ec39c98f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -534,7 +534,7 @@ spotless { antlr4Formatter() // specify a custom Antlr4Formatter version - antlr4Formatter('1.1.0') + antlr4Formatter('1.2.1') } } ``` diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 5ff90f0b88..2d1db932f2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -56,7 +56,7 @@ public void applyUsingCustomVersion() throws IOException { "spotless {", " antlr4 {", " target 'src/main/antlr4/**/*.g4'", - " antlr4Formatter('1.1.0')", + " antlr4Formatter('1.2.1')", " }", "}"}; diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9470959ad1..6ac5cbf79b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -209,7 +209,7 @@ set the `includes` parameter as described in the [File incudes and excludes](#in - 1.1.0 + 1.2.1 diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index dd51690791..21fd1fb0eb 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -25,7 +25,7 @@ public class Antlr4FormatterTest extends MavenIntegrationTest { public void applyUsingCustomVersion() throws Exception { writePomWithAntlr4Steps( "", - " 1.1.0", + " 1.2.1", ""); runTest(); } From d5bb7a6e7a6d232170b9762cf5c8785a6dee0a04 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 24 Jun 2020 14:15:02 -0700 Subject: [PATCH 17/28] Update license headers. --- .../main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java | 2 +- .../java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java | 2 +- .../main/java/com/diffplug/gradle/spotless/Antlr4Extension.java | 2 +- .../java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java | 2 +- .../test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java | 2 +- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- .../main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java | 2 +- .../com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java index 405e063fed..d1bd01da9c 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 5643a9da88..d71182c65d 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 2e6f4ce7ce..9cbba310a5 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 2d1db932f2..012f5a6363 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java index ff22f9966f..2818a6a9e0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e83fdd166e..18efd590b0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java index 16a7202478..9dd97a2d85 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java index afa92cea4c..3a6eb61145 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index 21fd1fb0eb..64d5310312 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java index de37fcce5e..0eb4d92cd8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 83e1a028e5881e0a47728a64299b0be1b2bdf860 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 24 Jun 2020 14:17:04 -0700 Subject: [PATCH 18/28] Add the `antlr4` extension to SpotlessExtensionBase. --- .../com/diffplug/gradle/spotless/SpotlessExtensionBase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java index 1d7ed95b8a..9847a6542e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java @@ -161,6 +161,11 @@ public void typescript(Action closure) { format(TypescriptExtension.NAME, TypescriptExtension.class, closure); } + /** Configures the special antlr4-specific extension for antlr4 files. */ + public void antlr4(Action closure) { + format(Antlr4Extension.NAME, Antlr4Extension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); From 8b261b4580cb570d27aee841b99f89f670714838 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 24 Jun 2020 17:39:59 -0700 Subject: [PATCH 19/28] Move the changelog entries to their correct location at `[Unreleased]`. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e027b63516..ad663da46f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath`. ([#620](https://github.com/diffplug/spotless/pull/620)) +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ## [1.34.1] - 2020-06-17 ### Changed @@ -73,7 +74,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.28.0] - 2020-03-20 ### Added -* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). * Enable IntelliJ-compatible token `$today.year` for specifying the year in license header files. ([#542](https://github.com/diffplug/spotless/pull/542)) ### Fixed * Eclipse-WTP formatter (web tools platform, not java) could encounter errors in parallel multiproject builds [#492](https://github.com/diffplug/spotless/issues/492). Fixed for Eclipse-WTP formatter Eclipse version 4.13.0 (default version). diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cc6340bffa..29e25fc950 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config()` or `configFile()` with the option `parser` or `filepath`. ([#620](https://github.com/diffplug/spotless/pull/620)) +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ## [4.4.0] - 2020-06-19 ### Added @@ -111,7 +112,6 @@ spotless { ## [3.28.0] - 2020-03-20 ### Added -* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). * Enable IntelliJ-compatible token `$today.year` for specifying the year in license header files. ([#542](https://github.com/diffplug/spotless/pull/542)) ### Fixed * Eclipse-WTP formatter (web tools platform, not java) could encounter errors in parallel multiproject builds [#492](https://github.com/diffplug/spotless/issues/492). Fixed for Eclipse-WTP formatter Eclipse version 4.13.0 (default version). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9762bd971e..9bbfe40db5 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath`. ([#620](https://github.com/diffplug/spotless/pull/620)) +* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ## [1.31.3] - 2020-06-17 ### Changed @@ -44,7 +45,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.28.0] - 2020-03-20 ### Added -* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). * Enable IntelliJ-compatible token `$today.year` for specifying the year in license header files. ([#542](https://github.com/diffplug/spotless/pull/542)) ### Fixed * Fix scala and kotlin maven config documentation. From b4530a12609d7e22d65d704b7bff804c6e50e9b0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 24 Jun 2020 17:40:29 -0700 Subject: [PATCH 20/28] Fix the maven and gradle integration tests. --- .../com/diffplug/gradle/spotless/Antlr4ExtensionTest.java | 2 +- .../diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java index 012f5a6363..7ace7170be 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java @@ -19,7 +19,7 @@ import org.junit.Test; -public class Antlr4ExtensionTest extends GradleIntegrationTest { +public class Antlr4ExtensionTest extends GradleIntegrationHarness { @Test public void applyUsingDefaultVersion() throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index 64d5310312..4623450e38 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -17,9 +17,9 @@ import org.junit.Test; -import com.diffplug.spotless.maven.MavenIntegrationTest; +import com.diffplug.spotless.maven.MavenIntegrationHarness; -public class Antlr4FormatterTest extends MavenIntegrationTest { +public class Antlr4FormatterTest extends MavenIntegrationHarness { @Test public void applyUsingCustomVersion() throws Exception { From ecf18616820bed92cf816a99395bf8dd2e2f27a8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 24 Jun 2020 17:40:47 -0700 Subject: [PATCH 21/28] Remove the unnecessary gradle-internals test dedicated to Antlr4. --- .../gradle/spotless/Antlr4TaskTest.java | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java deleted file mode 100644 index 2818a6a9e0..0000000000 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4TaskTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016-2020 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.gradle.spotless; - -import static com.diffplug.gradle.spotless.Tasks.execute; - -import java.util.Collections; - -import org.gradle.api.GradleException; -import org.gradle.api.Project; -import org.gradle.testfixtures.ProjectBuilder; -import org.junit.Before; -import org.junit.Test; - -import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.antlr4.Antlr4FormatterStep; - -public class Antlr4TaskTest extends ResourceHarness { - - private Provisioner provisioner = TestProvisioner.mavenCentral(); - - private SpotlessTask checkTask; - private SpotlessTask applyTask; - - @Before - public void createTask() { - Project project = ProjectBuilder.builder().build(); - checkTask = project.getTasks().create("checkTaskUnderTest", SpotlessTask.class); - checkTask.setCheck(); - applyTask = project.getTasks().create("applyTaskUnderTest", SpotlessTask.class); - applyTask.setApply(); - } - - @Test(expected = GradleException.class) - public void testFormatCheckFail() throws Exception { - String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); - - checkTask.addStep(Antlr4FormatterStep.create(provisioner)); - checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(unformatted))); - execute(checkTask); - } - - @Test - public void testFormatedCheckPass() throws Exception { - String formatted = getTestResource("antlr4/Hello.formatted.g4"); - - checkTask.addStep(Antlr4FormatterStep.create(provisioner)); - checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(formatted))); - execute(checkTask); - } - - @Test - public void testFormatApplyPass() throws Exception { - String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); - String formatted = getTestResource("antlr4/Hello.formatted.g4"); - String testFile = "testFile.g4"; - - applyTask.addStep(Antlr4FormatterStep.create(provisioner)); - applyTask.setTarget(Collections.singleton(setFile(testFile).toContent(unformatted))); - execute(applyTask); - - assertFile(testFile).hasContent(formatted); - } -} From f111f2e9d1ecf3f3fc2a870b5624aaae5492efc9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Jun 2020 09:42:09 -0700 Subject: [PATCH 22/28] Fix Antlr4Extension. --- .../main/java/com/diffplug/gradle/spotless/Antlr4Extension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 9cbba310a5..ad14d2ae0c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -24,7 +24,7 @@ public class Antlr4Extension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "antlr4"; - public Antlr4Extension(SpotlessExtension rootExtension) { + public Antlr4Extension(SpotlessExtensionBase rootExtension) { super(rootExtension); } From 3887435efa2c156ecdcd3963347ba3ad61b5b620 Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 1 Jul 2020 20:25:57 +0200 Subject: [PATCH 23/28] fix expected format --- .../main/resources/antlr4/Hello.formatted.g4 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/testlib/src/main/resources/antlr4/Hello.formatted.g4 b/testlib/src/main/resources/antlr4/Hello.formatted.g4 index efe3b821df..ef05f0e8c9 100644 --- a/testlib/src/main/resources/antlr4/Hello.formatted.g4 +++ b/testlib/src/main/resources/antlr4/Hello.formatted.g4 @@ -4,16 +4,13 @@ grammar Hello; r : 'hello' ID - ; - -// match keyword hello followed by an identifier - + ; // match keyword hello followed by an identifier + ID - : [a-z] + - ; - -// match lower-case identifiers - + : [a-z]+ + ; // match lower-case identifiers + WS - : [ \t\r\n] + -> skip - ; + : [ \t\r\n]+ -> skip + ; // skip spaces, tabs, newlines + \ No newline at end of file From 289af25f47bf5e00df1ef0137356db89f5e73e7d Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 1 Jul 2020 20:38:53 +0200 Subject: [PATCH 24/28] fix expected format --- testlib/src/main/resources/antlr4/Hello.formatted.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/main/resources/antlr4/Hello.formatted.g4 b/testlib/src/main/resources/antlr4/Hello.formatted.g4 index ef05f0e8c9..5f73eb0e22 100644 --- a/testlib/src/main/resources/antlr4/Hello.formatted.g4 +++ b/testlib/src/main/resources/antlr4/Hello.formatted.g4 @@ -13,4 +13,4 @@ ID WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines - \ No newline at end of file + From d946b3f74f9b2b9998fd7df0cf7286e8874f269b Mon Sep 17 00:00:00 2001 From: Matthias Balke Date: Wed, 1 Jul 2020 21:52:55 +0200 Subject: [PATCH 25/28] use a more generic default pattern --- .../java/com/diffplug/spotless/antlr4/Antlr4Defaults.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java index d1bd01da9c..45873f51ad 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.antlr4; -import java.util.Arrays; +import java.util.Collections; import java.util.List; public class Antlr4Defaults { private static final String LICENSE_HEADER_DELIMITER = "(grammar|lexer grammar|parser grammar)"; - private static final List defaultIncludes = Arrays.asList("src/main/antlr4/**/*.g4", "src/test/antlr4/**/*.g4"); + private static final List defaultIncludes = Collections.singletonList("src/*/antlr4/**/*.g4"); private Antlr4Defaults() {} From 2bd12d70fbd9b48f4291f494e53cff9fd750fdaa Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 1 Jul 2020 13:00:30 -0700 Subject: [PATCH 26/28] Move Antlr4Extension from the deprecated `GradleProvisioner` to the new `provisioner()`. --- .../main/java/com/diffplug/gradle/spotless/Antlr4Extension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index ad14d2ae0c..65b9101062 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -46,7 +46,7 @@ public class Antlr4FormatterConfig { } private FormatterStep createStep() { - return Antlr4FormatterStep.create(this.version, GradleProvisioner.fromProject(getProject())); + return Antlr4FormatterStep.create(this.version, provisioner()); } } From 837df92d4fef3a71708e3c596dee31074fa46d53 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 1 Jul 2020 12:51:29 -0700 Subject: [PATCH 27/28] Revert all README changes - I will put them back later. --- README.md | 2 -- plugin-gradle/README.md | 20 -------------------- plugin-maven/README.md | 21 --------------------- 3 files changed, 43 deletions(-) diff --git a/README.md b/README.md index 01e52b5ae3..f0a7d9c616 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} |', -lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} |', '| Fast up-to-date checking | {{yes}} | {{no}} | {{no}} |', '| Automatic idempotency safeguard | {{yes}} | {{no}} | {{no}} |', @@ -82,7 +81,6 @@ lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | [`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: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | -| [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :+1: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | | Fast up-to-date checking | :+1: | :white_large_square: | :white_large_square: | | Automatic idempotency safeguard | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bfeaecdfbd..0a58a9ce9a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -94,7 +94,6 @@ Spotless can check and apply formatting to any plain-text file, using simple rul * [DBeaver sql format](https://dbeaver.jkiss.org/) * [Prettier: An opinionated code formatter](https://prettier.io) * [TypeScript Formatter (tsfmt)](https://github.com/vvakame/typescript-formatter) -* [Antlr4Formatter](https://github.com/antlr/Antlr4Formatter) * Any user-defined function which takes an unformatted string and outputs a formatted version. Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info. @@ -569,25 +568,6 @@ Unlike Eclipse, Spotless WTP ignores per default external URIs in schema locatio external entities. To allow the access of external URIs, set the property `resolveExternalURI` to true. - - -## Applying to ANTLR4 source - -By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` or `src/test/antlr4/**/*.g4` will be formatted. To change this, -set the `target` parameter as described in the [Custom rules](#custom) section. - -```gradle -spotless { - antlr4 { - // use default Antlr4Formatter version - antlr4Formatter() - - // specify a custom Antlr4Formatter version - antlr4Formatter('1.2.1') - } -} -``` - ## License header options diff --git a/plugin-maven/README.md b/plugin-maven/README.md index ca948bf63c..d27620abf3 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -78,7 +78,6 @@ Spotless supports the following powerful formatters: * Google's [google-java-format](https://github.com/google/google-java-format) * [Typescript Tsfmt formatter](https://github.com/vvakame/typescript-formatter) * [Prettier formatter](https://prettier.io) -* [Antlr4Formatter](https://github.com/antlr/Antlr4Formatter) * User-defined license enforcement, regex replacement, etc. Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info. @@ -218,26 +217,6 @@ By default, all files matching `src/main/cpp/**/*.` and `src/test/cpp/**/*. ``` Use the Eclipse to define the *Code Style preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). Within the preferences *Edit...* dialog, you can export your configuration as XML file, which can be used as a configuration ``. If no `` is provided, the CDT default configuration is used. - -## Applying to ANTLR4 source - -By default, all ANTLR4 sources matching `src/main/antlr4/**/*.g4` or `src/test/antlr4/**/*.g4` will be formatted. To change this, -set the `includes` parameter as described in the [File incudes and excludes](#includeExclude) section. - -```xml - - - - - - - - 1.2.1 - - - -``` - ## Applying to Typescript source From 60b9805dd5ccd05d05a4f5bbd629a5e1e89efda5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 1 Jul 2020 13:28:53 -0700 Subject: [PATCH 28/28] Minor refactor of the antlr4 defaults. --- .../com/diffplug/spotless/antlr4/Antlr4Defaults.java | 11 +++-------- .../com/diffplug/gradle/spotless/Antlr4Extension.java | 2 +- .../com/diffplug/spotless/maven/antlr4/Antlr4.java | 5 +---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java index 45873f51ad..53223c087f 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4Defaults.java @@ -15,14 +15,9 @@ */ package com.diffplug.spotless.antlr4; -import java.util.Collections; -import java.util.List; - public class Antlr4Defaults { - private static final String LICENSE_HEADER_DELIMITER = "(grammar|lexer grammar|parser grammar)"; - - private static final List defaultIncludes = Collections.singletonList("src/*/antlr4/**/*.g4"); + private static final String INCLUDES = "src/*/antlr4/**/*.g4"; private Antlr4Defaults() {} @@ -30,7 +25,7 @@ public static String licenseHeaderDelimiter() { return LICENSE_HEADER_DELIMITER; } - public static List defaultIncludes() { - return defaultIncludes; + public static String includes() { + return INCLUDES; } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java index 65b9101062..76076987e0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java @@ -53,7 +53,7 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - target = parseTarget(Antlr4Defaults.defaultIncludes()); + target = parseTarget(Antlr4Defaults.includes()); } super.setupTask(task); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java index 9dd97a2d85..bc24ebcf16 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -29,12 +29,9 @@ * and anltr4-specific (e.g. {@link Antlr4Formatter}) steps. */ public class Antlr4 extends FormatterFactory { - - private static final Set DEFAULT_INCLUDES = ImmutableSet.copyOf(Antlr4Defaults.defaultIncludes()); - @Override public Set defaultIncludes() { - return DEFAULT_INCLUDES; + return ImmutableSet.of(Antlr4Defaults.includes()); } @Override