From 88188044e43e47601c915cdbfa90356a6addb0b7 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 15 Sep 2018 13:31:43 +0200 Subject: [PATCH] XML Extension (#293) XML extension for Gradle and Maven. --- README.md | 2 + .../wtp/EclipseXmlFormatterStepImplTest.java | 40 +- .../{dtd_relative.xml => dtd_relative.test} | 0 .../{xml_space.xml => xml_space.test} | 0 .../{xsd_not_found.xml => xsd_not_found.test} | 0 .../{xsd_relative.xml => xsd_relative.test} | 0 .../{dtd_relative.xml => dtd_relative.test} | 0 .../input/{xml_space.xml => xml_space.test} | 0 .../{xsd_not_found.xml => xsd_not_found.test} | 0 .../{xsd_relative.xml => xsd_relative.test} | 0 .../resources/xml/restrictions/catalog.xml | 4 +- .../test/resources/xml/restrictions/test.xsd | 6 +- ...Step.java => EclipseWtpFormatterStep.java} | 4 +- .../wtp/EclipseWtpFormatterStepTest.java | 12 +- .../diffplug/spotless/cpp/CppDefaults.java | 5 + .../diffplug/spotless/xml/XmlDefaults.java | 38 ++ .../diffplug/spotless/xml/package-info.java | 7 + plugin-gradle/CHANGES.md | 1 + plugin-gradle/README.md | 27 + .../gradle/spotless/CppExtension.java | 3 +- .../gradle/spotless/SpotlessExtension.java | 5 + .../gradle/spotless/XmlExtension.java | 76 +++ plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 26 +- .../spotless/maven/AbstractSpotlessMojo.java | 6 +- .../com/diffplug/spotless/maven/cpp/Cpp.java | 3 +- .../diffplug/spotless/maven/xml/Eclipse.java | 47 ++ .../com/diffplug/spotless/maven/xml/Xml.java | 50 ++ .../spotless/maven/MavenIntegrationTest.java | 4 + .../maven/generic/LicenseHeaderTest.java | 15 + spotless.eclipseformat.xml | 620 +++++++++--------- spotless.xmlformat.prefs | 4 + spotlessSelf.gradle | 7 + .../properties/invalid_xml_profiles.xml | 6 +- .../invalid_xml_profiles_multiple.xml | 4 +- .../properties/invalid_xml_profiles_zero.xml | 2 +- .../properties/invalid_xml_properties.xml | 2 +- .../properties/valid_xml_profiles.xml | 16 +- .../properties/valid_xml_properties.xml | 14 +- .../main/resources/java/eclipse/formatter.xml | 522 +++++++-------- .../long_literals/spotless.eclipseformat.xml | 576 ++++++++-------- .../spotless/xml/XmlDefaultsTest.java | 50 ++ 42 files changed, 1285 insertions(+), 920 deletions(-) rename _ext/eclipse-wtp/src/test/resources/xml/expected/{dtd_relative.xml => dtd_relative.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/expected/{xml_space.xml => xml_space.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/expected/{xsd_not_found.xml => xsd_not_found.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/expected/{xsd_relative.xml => xsd_relative.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/input/{dtd_relative.xml => dtd_relative.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/input/{xml_space.xml => xml_space.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/input/{xsd_not_found.xml => xsd_not_found.test} (100%) rename _ext/eclipse-wtp/src/test/resources/xml/input/{xsd_relative.xml => xsd_relative.test} (100%) rename lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/{WtpEclipseFormatterStep.java => EclipseWtpFormatterStep.java} (98%) create mode 100644 lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java create mode 100644 lib/src/main/java/com/diffplug/spotless/xml/package-info.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java create mode 100644 spotless.xmlformat.prefs create mode 100644 testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java diff --git a/README.md b/README.md index 74958208d4..17c0600dfa 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |', +extra('wtp.WtpEclipseFormatterStep') +'{{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}} |', @@ -72,6 +73,7 @@ lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: | +| [`wtp.WtpEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.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/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java index ac159e72f5..277806def9 100644 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java +++ b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java @@ -41,43 +41,43 @@ public static void initializeStatic() throws Exception { @Test public void simpleDefaultFormat() throws Throwable { - String output = format(TEST_DATA.input("xml_space.xml"), config -> {}); + String output = format(TEST_DATA.input("xml_space.test"), config -> {}); assertEquals("Unexpected formatting with default preferences.", - TEST_DATA.expected("xml_space.xml"), output); + TEST_DATA.expected("xml_space.test"), output); } @Test public void invalidXmlFormat() throws Throwable { - String[] input = TEST_DATA.input("xml_space.xml"); + String[] input = TEST_DATA.input("xml_space.test"); input[0] += INCOMPLETE; String output = format(input, config -> {}); - String expected = TEST_DATA.expected("xml_space.xml") + LINE_DELIMITER + INCOMPLETE; + String expected = TEST_DATA.expected("xml_space.test") + LINE_DELIMITER + INCOMPLETE; assertEquals("Incomplete XML not formatted on best effort basis.", expected, output); } @Test public void illegalXmlCharater() throws Throwable { - String[] input = TEST_DATA.input("xml_space.xml"); + String[] input = TEST_DATA.input("xml_space.test"); input[0] = ILLEGAL_CHAR + input[0]; String output = format(input, config -> {}); - String expected = LINE_DELIMITER + LINE_DELIMITER + TEST_DATA.expected("xml_space.xml"); + String expected = LINE_DELIMITER + LINE_DELIMITER + TEST_DATA.expected("xml_space.test"); assertEquals("Illegal character not replaced by line delimiter.", expected, output); } @Test public void multipleConfigurations() throws Throwable { - String output = format(TEST_DATA.input("xml_space.xml"), config -> { + String output = format(TEST_DATA.input("xml_space.test"), config -> { config.setProperty(INDENTATION_SIZE, "2"); config.setProperty(INDENTATION_CHAR, SPACE); }); - String expected = TEST_DATA.expected("xml_space.xml").replace("\t", " "); + String expected = TEST_DATA.expected("xml_space.test").replace("\t", " "); assertEquals("Custom indentation configuration not applied.", expected, output); - output = format(TEST_DATA.input("xml_space.xml"), config -> { + output = format(TEST_DATA.input("xml_space.test"), config -> { config.setProperty(SPLIT_MULTI_ATTRS, Boolean.toString(true)); }); - expected = TEST_DATA.expected("xml_space.xml"); + expected = TEST_DATA.expected("xml_space.test"); expected = expected.replace(" a=", LINE_DELIMITER + "\ta="); expected = expected.replace(" b=", LINE_DELIMITER + "\tb="); assertEquals("Custom indentation configuration not reverted or custom multiple argument configuration not applied.", expected, output); @@ -85,44 +85,44 @@ public void multipleConfigurations() throws Throwable { @Test public void invalidConfiguration() throws Throwable { - String output = format(TEST_DATA.input("xml_space.xml"), config -> { + String output = format(TEST_DATA.input("xml_space.test"), config -> { config.setProperty(INDENTATION_SIZE, "Not an integer"); config.setProperty(INDENTATION_CHAR, SPACE); }); assertEquals("Invalid indentation configuration not replaced by default value (0 spaces)", - TEST_DATA.expected("xml_space.xml").replace("\t", ""), output); + TEST_DATA.expected("xml_space.test").replace("\t", ""), output); } @Test public void dtdRelativePath() throws Throwable { - String output = format(TEST_DATA.input("dtd_relative.xml"), config -> {}); + String output = format(TEST_DATA.input("dtd_relative.test"), config -> {}); assertEquals("Relative DTD not resolved. Restrictions are not applied by formatter.", - TEST_DATA.expected("dtd_relative.xml"), output); + TEST_DATA.expected("dtd_relative.test"), output); } @Test public void xsdRelativePath() throws Throwable { - String output = format(TEST_DATA.input("xsd_relative.xml"), config -> {}); + String output = format(TEST_DATA.input("xsd_relative.test"), config -> {}); assertEquals("Relative XSD not resolved. Restrictions are not applied by formatter.", - TEST_DATA.expected("xsd_relative.xml"), output); + TEST_DATA.expected("xsd_relative.test"), output); } @Test public void xsdNotFound() throws Throwable { - String output = format(TEST_DATA.input("xsd_not_found.xml"), config -> {}); + String output = format(TEST_DATA.input("xsd_not_found.test"), config -> {}); assertEquals("Unresolved XSD/DTD not silently ignored.", - TEST_DATA.expected("xsd_not_found.xml"), output); + TEST_DATA.expected("xsd_not_found.test"), output); } @Test public void catalogLookup() throws Throwable { - String output = format(TEST_DATA.input("xsd_not_found.xml"), config -> { + String output = format(TEST_DATA.input("xsd_not_found.test"), config -> { config.setProperty( SpotlessPreferences.USER_CATALOG, TEST_DATA.getRestrictionsPath("catalog.xml").toString()); }); assertEquals("XSD not resolved by catalog. Restrictions are not applied by formatter.", - TEST_DATA.expected("xsd_not_found.xml").replace(" remove spaces ", "remove spaces"), output); + TEST_DATA.expected("xsd_not_found.test").replace(" remove spaces ", "remove spaces"), output); } private static String format(final String[] input, final Consumer config) throws Exception { diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.xml b/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.xml rename to _ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.xml b/_ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.xml rename to _ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.xml b/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.xml rename to _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.xml b/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.xml rename to _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.xml b/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.xml rename to _ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xml_space.xml b/_ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/input/xml_space.xml rename to _ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.xml b/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.xml rename to _ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.xml b/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test similarity index 100% rename from _ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.xml rename to _ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test diff --git a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml index 4ebd39144a..2fba8dc2b9 100644 --- a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml +++ b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd index 30a77f23e8..6b0e3b5e00 100644 --- a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd +++ b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd @@ -6,14 +6,14 @@ - + - + - + diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java similarity index 98% rename from lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java rename to lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index 2ef228bb9f..d1e1078537 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -25,9 +25,9 @@ import com.diffplug.spotless.extra.EclipseBasedStepBuilder; /** Formatter step which calls out to the Groovy-Eclipse formatter. */ -public final class WtpEclipseFormatterStep { +public final class EclipseWtpFormatterStep { // prevent direct instantiation - private WtpEclipseFormatterStep() {} + private EclipseWtpFormatterStep() {} private static final String NAME = "eclipse wtp formatters"; private static final String FORMATTER_PACKAGE = "com.diffplug.spotless.extra.eclipse.wtp."; diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java index 4a4bd4f2a4..fb136fa8f5 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java @@ -45,18 +45,18 @@ private enum WTP { // @formatter:off CSS( "body {\na: v; b: \nv;\n} \n", "body {\n\ta: v;\n\tb: v;\n}", - WtpEclipseFormatterStep::createCssBuilder), + EclipseWtpFormatterStep::createCssBuilder), HTML( " \t \n ", "\n\n\n\n\n\n", - WtpEclipseFormatterStep::createHtmlBuilder), + EclipseWtpFormatterStep::createHtmlBuilder), JS( "function f( ) {\na.b(1,\n2);}", "function f() {\n a.b(1, 2);\n}", - WtpEclipseFormatterStep::createJsBuilder), + EclipseWtpFormatterStep::createJsBuilder), JSON( "{\"a\": \"b\", \"c\": { \"d\": \"e\",\"f\": \"g\"}}", "{\n\t\"a\": \"b\",\n\t\"c\": {\n\t\t\"d\": \"e\",\n\t\t\"f\": \"g\"\n\t}\n}", - WtpEclipseFormatterStep::createJsonBuilder), + EclipseWtpFormatterStep::createJsonBuilder), XML( " c", "\n\t c\n", - WtpEclipseFormatterStep::createXmlBuilder); + EclipseWtpFormatterStep::createXmlBuilder); // @formatter:on public final String input; @@ -132,7 +132,7 @@ private FormatterStep createStepForDefaultVersion(Consumer config) t OutputStream tempOut = new FileOutputStream(tempFile); configProps.store(tempOut, "test properties"); EclipseBasedStepBuilder builder = wtp.builderMethod.apply(TestProvisioner.mavenCentral()); - builder.setVersion(WtpEclipseFormatterStep.defaultVersion()); + builder.setVersion(EclipseWtpFormatterStep.defaultVersion()); builder.setPreferences(Arrays.asList(tempFile)); return builder.build(); } diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java b/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java index 508bc1d547..3ab34ab28b 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java @@ -25,6 +25,11 @@ public class CppDefaults { //Prevent instantiation private CppDefaults() {}; + /** Filtering based on Eclipse-CDT org.eclipse.core.contenttype.contentTypes */ + /** + * Filter based on Eclipse-CDT org.eclipse.core.contenttype.contentTypes + * extension cSource, cHeader, cxxSource and cxxHeader. + */ public static final List FILE_FILTER = Collections.unmodifiableList( Arrays.asList("c", "h", "C", "cpp", "cxx", "cc", "c++", "h", "hpp", "hh", "hxx", "inc") .stream().map(s -> { diff --git a/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java b/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java new file mode 100644 index 0000000000..50da66fc55 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java @@ -0,0 +1,38 @@ +/* + * 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.xml; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** Common utilities for XML */ +public class XmlDefaults { + //Prevent instantiation + private XmlDefaults() {}; + + /** + * Filter based on Eclipse-WTP org.eclipse.core.contenttype.contentTypes + * extension org.eclipse.wst.xml.core.xmlsource + */ + public static final List FILE_FILTER = Collections.unmodifiableList( + Arrays.asList("xml", "xsl", "xslt", "wsdl", "xsd", "exsd", "xmi") + .stream().map(s -> "**/*." + s).collect(Collectors.toList())); + + /** Delimiter covers beginning of elements and processing instructions. */ + public static final String DELIMITER_EXPR = "\\<[a-zA-Z\\?]"; +} diff --git a/lib/src/main/java/com/diffplug/spotless/xml/package-info.java b/lib/src/main/java/com/diffplug/spotless/xml/package-info.java new file mode 100644 index 0000000000..0d77d7be68 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/xml/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@ReturnValuesAreNonnullByDefault +package com.diffplug.spotless.xml; + +import javax.annotation.ParametersAreNonnullByDefault; + +import com.diffplug.spotless.annotations.ReturnValuesAreNonnullByDefault; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5c6956510a..d28af7b441 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -2,6 +2,7 @@ ### Version 3.15.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/)) +* Added `xml` support ([#140](https://github.com/diffplug/spotless/issues/140)) using formatter of Eclipse WTP 3.9.5 ([#241](https://github.com/diffplug/spotless/pull/241)). * Added C/C++ support using formatter of Eclipse CDT 9.4.3 ([#232](https://github.com/diffplug/spotless/issues/232)). * Updated default groovy-eclipse from 4.8.0 to 4.8.1 ([#288](https://github.com/diffplug/spotless/pull/288)). New version is based on [Groovy-Eclipse 3.0.0](https://github.com/groovy/groovy-eclipse/wiki/3.0.0-Release-Notes). * LicenseHeaderStep now wont attempt to add license to `module-info.java` ([#272](https://github.com/diffplug/spotless/pull/272)). diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index d6c99a898c..16fca28c84 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -79,6 +79,7 @@ Spotless can check and apply formatting to any plain-text file, using simple rul * Eclipse's [CDT](#eclipse-cdt) C/C++ code formatter * Eclipse's java code formatter (including style and import ordering) +* Eclipse's [WTP-XML](#eclipse-wtp-xml) XML code formatter * Google's [google-java-format](https://github.com/google/google-java-format) * [Groovy Eclipse](#groovy-eclipse)'s groovy code formatter * [FreshMark](https://github.com/diffplug/freshmark) (markdown with variables) @@ -317,6 +318,32 @@ spotless { 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 `configFile`. If no `configFile` is provided, the CDT default configuration is used. + + +## Applying to XML sources + +```gradle +spotless { + xml { + target '**/*.xml' // Change file filter. By default files with 'xml', 'xsl', 'xslt', 'wsdl', 'xsd', 'exsd' and 'xmi' extension are supported + eclipse().configFile './xml-formatter.prefs' // Properties file of the Eclipse WTP formatter + // Use for example eclipse('4.7.3a') to specify a specific version of Eclipse, + // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters + // also supports license headers + licenseHeader '' // License header + licenseHeaderFile './license.txt' // License header file + } +} +``` + + + +### Eclipse [WTP](https://www.eclipse.org/webtools/) XML formatter +Use Eclipse to define the *XML editor preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs`. Note that only the differences to the default configuration are stored within the file. Omit the 'configFile' entirely to use the default Eclipse configuration. + +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 file or add an additional preference or properties files as an additional argument to the `configFile`. + + ## License header options diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java index e478ddbf56..2434c99a16 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java @@ -56,14 +56,13 @@ public void configFile(Object... configFiles) { } - /** If the user hasn't specified the files yet, we'll assume he/she means all of the C/C++ files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { /* * The org.gradle.language.c and org.gradle.language.cpp source sets are seldom used. * Most Gradle C/C++ use external CMake builds (so the source location is unknown to Gradle). - * Hence file extension based filtering is used in line with the org.eclipse.core.contenttype.contentTypes + * Hence file extension based filtering is used in line with the org.eclipse.core.contenttype.contentTypes< * defined by the CDT plugin. */ target(CppDefaults.FILE_FILTER.toArray()); 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 b0663f973a..0b8409710c 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 @@ -118,6 +118,11 @@ public void sql(Action closure) { configure(SqlExtension.NAME, SqlExtension.class, closure); } + /** Configures the special xml-specific extension for XML/XSL/... files (XHTML is excluded). */ + public void xml(Action closure) { + configure(XmlExtension.NAME, XmlExtension.class, closure); + } + /** Configures the special C/C++-specific extension. */ public void cpp(Action closure) { configure(CppExtension.NAME, CppExtension.class, closure); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java new file mode 100644 index 0000000000..233d514e6f --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java @@ -0,0 +1,76 @@ +/* + * 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.PluginGradlePreconditions.requireElementsNonNull; + +import org.gradle.api.Project; + +import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; +import com.diffplug.spotless.xml.XmlDefaults; + +public class XmlExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { + static final String NAME = "xml"; + + public XmlExtension(SpotlessExtension rootExtension) { + super(rootExtension); + } + + public EclipseConfig eclipse() { + return new EclipseConfig(EclipseWtpFormatterStep.defaultVersion()); + } + + public EclipseConfig eclipse(String version) { + return new EclipseConfig(version); + } + + public class EclipseConfig { + private final EclipseBasedStepBuilder builder; + + EclipseConfig(String version) { + builder = EclipseWtpFormatterStep.createXmlBuilder(GradleProvisioner.fromProject(getProject())); + builder.setVersion(version); + addStep(builder.build()); + } + + public void configFile(Object... configFiles) { + requireElementsNonNull(configFiles); + Project project = getProject(); + builder.setPreferences(project.files(configFiles).getFiles()); + replaceStep(builder.build()); + } + + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target(XmlDefaults.FILE_FILTER.toArray()); + } + super.setupTask(task); + } + + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, XmlDefaults.DELIMITER_EXPR); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, XmlDefaults.DELIMITER_EXPR); + } +} diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2bbaccf08c..e09b2104c0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,7 @@ ### Version 1.15.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 `xml` support ([#140](https://github.com/diffplug/spotless/issues/140)) using formatter of Eclipse WTP 3.9.5 ([#241](https://github.com/diffplug/spotless/pull/241)). * Added C/C++ support using formatter of Eclipse CDT 9.4.3 ([#232](https://github.com/diffplug/spotless/issues/232)). * Skip `package-info.java` and `module-info.java` files from license header formatting. ([#273](https://github.com/diffplug/spotless/pull/273)) * Updated JSR305 annotation from 3.0.0 to 3.0.2 ([#274](https://github.com/diffplug/spotless/pull/274)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 6a0f7b1f7d..0850d19c58 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -187,10 +187,34 @@ 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 `file`. If no `file` is provided, the CDT default configuration is used. +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 XML source + +By default, all files matching `src/**/*.` Ant style pattern will be formatted, whereas the file extensions `xml`, `xsl`, `xslt`, `wsdl`, `xsd`, `exsd`, `xmi` are supported. Each element under `` is a step, and they will be applied in the order specified. Every step is optional, and they will be applied in the order specified. + +```xml + + + + + <!-- Licensed under Apache-2.0 --> + ${basedir}/license-header + + + ${basedir}/eclipse-fmt.pref + + 4.7.3a + + + +``` +Use Eclipse to define the *XML editor preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs`. Note that only the differences to the default configuration are stored within the file. If no `` is provided, the WTP default configuration is used.. + +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 custom sources By default, no Ant-Style include patterns are defined. Each element under `` is a step, and they will be applied in the order specified. Every step is optional, and they will be applied in the order specified. It is possible to define multiple custom formats. 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 d0da2f2c3e..9bad00ecac 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -42,6 +42,7 @@ import com.diffplug.spotless.maven.java.Java; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.scala.Scala; +import com.diffplug.spotless.maven.xml.Xml; public abstract class AbstractSpotlessMojo extends AbstractMojo { @@ -87,6 +88,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Kotlin kotlin; + @Parameter + private Xml xml; + @Parameter private Cpp cpp; @@ -148,7 +152,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp)) + return Stream.concat(formats.stream(), Stream.of(java, scala, kotlin, cpp, xml)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java index 44afbebc01..49bd3e84a4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java @@ -48,8 +48,7 @@ public void addEclipse(Eclipse eclipse) { @Override public String licenseHeaderDelimiter() { - // License header currently not fully supported. - return "#"; + return CppDefaults.DELIMITER_EXPR; } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java new file mode 100644 index 0000000000..9b18b3a56a --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java @@ -0,0 +1,47 @@ +/* + * 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.xml; + +import java.io.File; +import java.util.Arrays; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Eclipse implements FormatterStepFactory { + + @Parameter + private String file; + + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + EclipseBasedStepBuilder eclipseConfig = EclipseWtpFormatterStep.createXmlBuilder(stepConfig.getProvisioner()); + eclipseConfig.setVersion(version == null ? EclipseWtpFormatterStep.defaultVersion() : version); + if (null != file) { + File settingsFile = stepConfig.getFileLocator().locateFile(file); + eclipseConfig.setPreferences(Arrays.asList(settingsFile)); + } + return eclipseConfig.build(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java new file mode 100644 index 0000000000..a5a690326c --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java @@ -0,0 +1,50 @@ +/* + * 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.xml; + +import java.util.Set; +import java.util.stream.Collectors; + +import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.generic.LicenseHeader; +import com.diffplug.spotless.xml.XmlDefaults; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for XML/XSL/... source files that can execute both language agnostic (e.g. {@link LicenseHeader}) + * and xml-specific (e.g. {@link Eclipse}) steps. + */ +public class Xml extends FormatterFactory { + + private static final Set DEFAULT_INCLUDES = XmlDefaults.FILE_FILTER + .stream().map(s -> "src/" + s).collect(Collectors.toSet()); + + @Override + public Set defaultIncludes() { + return DEFAULT_INCLUDES; + } + + public void addEclipse(Eclipse eclipse) { + addStepFactory(eclipse); + } + + @Override + public String licenseHeaderDelimiter() { + return XmlDefaults.DELIMITER_EXPR; + } + +} 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 e08c9610d7..d7528e05e4 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 @@ -102,6 +102,10 @@ protected void writePomWithKotlinSteps(String... steps) throws IOException { writePom(groupWithSteps("kotlin", steps)); } + protected void writePomWithXmlSteps(String... steps) throws IOException { + writePom(groupWithSteps("xml", steps)); + } + protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 4b8ec61b11..f5ca6f1e08 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -114,6 +114,21 @@ public void fromContentKotlin() throws Exception { assertFile(path).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader); } + @Test + public void fromContentXml() throws Exception { + String license = " Licensed under Apache-2.0 "; + writePomWithXmlSteps( + "", + " ", + "<!--" + license + "-->", + " ", + ""); + String path = "src/test.xml"; + setFile(path).toContent(""); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).hasContent("\n"); + } + @Test public void unsupportedPackageInfo() throws Exception { testUnsupportedFile("package-info.java"); diff --git a/spotless.eclipseformat.xml b/spotless.eclipseformat.xml index 8dceaedb0a..ad01b94b05 100644 --- a/spotless.eclipseformat.xml +++ b/spotless.eclipseformat.xml @@ -1,313 +1,313 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spotless.xmlformat.prefs b/spotless.xmlformat.prefs new file mode 100644 index 0000000000..3bbd7ecd72 --- /dev/null +++ b/spotless.xmlformat.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +indentationChar=space +indentationSize=2 +lineWidth=999 diff --git a/spotlessSelf.gradle b/spotlessSelf.gradle index 51697de2d4..f06c5addbe 100644 --- a/spotlessSelf.gradle +++ b/spotlessSelf.gradle @@ -43,6 +43,13 @@ spotless { bumpThisNumberIfACustomStepChanges(3) greclipse().configFile('spotless.eclipseformat.xml', 'spotless.groovyformat.prefs') } + xml { + target fileTree('.') { + include com.diffplug.spotless.xml.XmlDefaults.FILE_FILTER + exclude '**/build/**' + } + eclipse().configFile 'spotless.xmlformat.prefs' + } freshmark { target '**/*.md' propertiesFile('gradle.properties') diff --git a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles.xml b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles.xml index 55d1c528d6..4bf49ba0c2 100644 --- a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles.xml +++ b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles.xml @@ -1,6 +1,6 @@ - - - + + + diff --git a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_multiple.xml b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_multiple.xml index ac57f574e3..609052a341 100644 --- a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_multiple.xml +++ b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_multiple.xml @@ -1,5 +1,5 @@ - - + + diff --git a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_zero.xml b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_zero.xml index b18d34132b..d26c3a0467 100644 --- a/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_zero.xml +++ b/testlib/src/main/resources/formatter/properties/invalid_xml_profiles_zero.xml @@ -1,2 +1,2 @@ - + diff --git a/testlib/src/main/resources/formatter/properties/invalid_xml_properties.xml b/testlib/src/main/resources/formatter/properties/invalid_xml_properties.xml index 0d2b795e3e..7b4e7a250c 100644 --- a/testlib/src/main/resources/formatter/properties/invalid_xml_properties.xml +++ b/testlib/src/main/resources/formatter/properties/invalid_xml_properties.xml @@ -1,4 +1,4 @@ - No valid entry + No valid entry diff --git a/testlib/src/main/resources/formatter/properties/valid_xml_profiles.xml b/testlib/src/main/resources/formatter/properties/valid_xml_profiles.xml index 5eed72b5dd..a57c004c31 100644 --- a/testlib/src/main/resources/formatter/properties/valid_xml_profiles.xml +++ b/testlib/src/main/resources/formatter/properties/valid_xml_profiles.xml @@ -1,11 +1,11 @@ - - - - - - - - + + + + + + + + diff --git a/testlib/src/main/resources/formatter/properties/valid_xml_properties.xml b/testlib/src/main/resources/formatter/properties/valid_xml_properties.xml index dc15d031d9..fe183e9444 100644 --- a/testlib/src/main/resources/formatter/properties/valid_xml_properties.xml +++ b/testlib/src/main/resources/formatter/properties/valid_xml_properties.xml @@ -1,11 +1,11 @@ - Some comment - string - Gets overridden by next line - true - 42 - valid_xml_properties.xml - + Some comment + string + Gets overridden by next line + true + 42 + valid_xml_properties.xml + diff --git a/testlib/src/main/resources/java/eclipse/formatter.xml b/testlib/src/main/resources/java/eclipse/formatter.xml index 365c79b2a3..37028472a3 100644 --- a/testlib/src/main/resources/java/eclipse/formatter.xml +++ b/testlib/src/main/resources/java/eclipse/formatter.xml @@ -1,264 +1,264 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testlib/src/main/resources/java/eclipse/long_literals/spotless.eclipseformat.xml b/testlib/src/main/resources/java/eclipse/long_literals/spotless.eclipseformat.xml index 97aae6916f..de0fc36c9b 100644 --- a/testlib/src/main/resources/java/eclipse/long_literals/spotless.eclipseformat.xml +++ b/testlib/src/main/resources/java/eclipse/long_literals/spotless.eclipseformat.xml @@ -1,291 +1,291 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java b/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java new file mode 100644 index 0000000000..54d8098da7 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java @@ -0,0 +1,50 @@ +/* + * 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.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.Arrays; + +import org.junit.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.generic.LicenseHeaderStep; + +public class XmlDefaultsTest extends ResourceHarness { + + @Test + public void testDelimiterExpr() throws Exception { + final String header = ""; + FormatterStep step = LicenseHeaderStep.createFromHeader(header, XmlDefaults.DELIMITER_EXPR); + final File dummyFile = setFile("src/main/file.dummy").toContent(""); + for (String testSource : Arrays.asList( + "@\n", + "@\n")) { + String output = null; + try { + output = step.format(testSource, dummyFile); + } catch (IllegalArgumentException e) { + throw new AssertionError(String.format("No delimiter found in '%s'", testSource), e); + } + String expected = testSource.replaceAll("(.*?)\\@", header); + assertThat(output).isEqualTo(expected).as("Unexpected header insertion for '$s'.", testSource); + } + } + +}