Skip to content

Commit 60f2bcd

Browse files
committed
Merge branch 'master' into feature/typescript-formatting-using-nodejs-in-j2v8
# Conflicts: # plugin-gradle/README.md # plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
2 parents 807bf7b + 8818804 commit 60f2bcd

File tree

64 files changed

+1952
-1003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1952
-1003
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ You might be looking for:
77

88
### Version 1.15.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/))
99

10+
* Added C/C++ support ([#232](https://github.com/diffplug/spotless/issues/232)).
11+
* Integrated Eclipse CDT formatter ([#274](https://github.com/diffplug/spotless/pull/274))
12+
* Extended dependency provisioner to exclude transitives on request ([#297](https://github.com/diffplug/spotless/pull/297)).This prevents unnecessary downloads of unused transitive dependencies for Eclipse based formatter steps.
1013
* 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).
1114
* Integrated Eclipse WTP formatter ([#290](https://github.com/diffplug/spotless/pull/290))
1215
* Updated JSR305 annotation from 3.0.0 to 3.0.2 ([#274](https://github.com/diffplug/spotless/pull/274))

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lib('generic.LicenseHeaderStep') +'{{yes}} | {{yes}}
3838
lib('generic.ReplaceRegexStep') +'{{yes}} | {{yes}} | {{no}} |',
3939
lib('generic.ReplaceStep') +'{{yes}} | {{yes}} | {{no}} |',
4040
lib('generic.TrimTrailingWhitespaceStep') +'{{yes}} | {{yes}} | {{no}} |',
41+
extra('cpp.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |',
4142
extra('groovy.GrEclipseFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
4243
lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} |',
4344
lib('java.ImportOrderStep') +'{{yes}} | {{yes}} | {{no}} |',
@@ -49,6 +50,7 @@ lib('npm.PrettierFormatterStep') +'{{yes}} | {{no}}
4950
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
5051
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |',
5152
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
53+
extra('wtp.WtpEclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |',
5254
'| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} |',
5355
'| Fast up-to-date checking | {{yes}} | {{no}} | {{no}} |',
5456
'| Automatic idempotency safeguard | {{yes}} | {{no}} | {{no}} |',
@@ -63,6 +65,7 @@ lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}}
6365
| [`generic.ReplaceRegexStep`](lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java) | :+1: | :+1: | :white_large_square: |
6466
| [`generic.ReplaceStep`](lib/src/main/java/com/diffplug/spotless/generic/ReplaceStep.java) | :+1: | :+1: | :white_large_square: |
6567
| [`generic.TrimTrailingWhitespaceStep`](lib/src/main/java/com/diffplug/spotless/generic/TrimTrailingWhitespaceStep.java) | :+1: | :+1: | :white_large_square: |
68+
| [`cpp.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: |
6669
| [`groovy.GrEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
6770
| [`java.GoogleJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java) | :+1: | :+1: | :white_large_square: |
6871
| [`java.ImportOrderStep`](lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java) | :+1: | :+1: | :white_large_square: |
@@ -74,6 +77,7 @@ lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}}
7477
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
7578
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :white_large_square: |
7679
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
80+
| [`wtp.WtpEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: |
7781
| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: |
7882
| Fast up-to-date checking | :+1: | :white_large_square: | :white_large_square: |
7983
| Automatic idempotency safeguard | :+1: | :white_large_square: | :white_large_square: |

_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,88 +41,88 @@ public static void initializeStatic() throws Exception {
4141

4242
@Test
4343
public void simpleDefaultFormat() throws Throwable {
44-
String output = format(TEST_DATA.input("xml_space.xml"), config -> {});
44+
String output = format(TEST_DATA.input("xml_space.test"), config -> {});
4545
assertEquals("Unexpected formatting with default preferences.",
46-
TEST_DATA.expected("xml_space.xml"), output);
46+
TEST_DATA.expected("xml_space.test"), output);
4747
}
4848

4949
@Test
5050
public void invalidXmlFormat() throws Throwable {
51-
String[] input = TEST_DATA.input("xml_space.xml");
51+
String[] input = TEST_DATA.input("xml_space.test");
5252
input[0] += INCOMPLETE;
5353
String output = format(input, config -> {});
54-
String expected = TEST_DATA.expected("xml_space.xml") + LINE_DELIMITER + INCOMPLETE;
54+
String expected = TEST_DATA.expected("xml_space.test") + LINE_DELIMITER + INCOMPLETE;
5555
assertEquals("Incomplete XML not formatted on best effort basis.",
5656
expected, output);
5757
}
5858

5959
@Test
6060
public void illegalXmlCharater() throws Throwable {
61-
String[] input = TEST_DATA.input("xml_space.xml");
61+
String[] input = TEST_DATA.input("xml_space.test");
6262
input[0] = ILLEGAL_CHAR + input[0];
6363
String output = format(input, config -> {});
64-
String expected = LINE_DELIMITER + LINE_DELIMITER + TEST_DATA.expected("xml_space.xml");
64+
String expected = LINE_DELIMITER + LINE_DELIMITER + TEST_DATA.expected("xml_space.test");
6565
assertEquals("Illegal character not replaced by line delimiter.", expected, output);
6666
}
6767

6868
@Test
6969
public void multipleConfigurations() throws Throwable {
70-
String output = format(TEST_DATA.input("xml_space.xml"), config -> {
70+
String output = format(TEST_DATA.input("xml_space.test"), config -> {
7171
config.setProperty(INDENTATION_SIZE, "2");
7272
config.setProperty(INDENTATION_CHAR, SPACE);
7373
});
74-
String expected = TEST_DATA.expected("xml_space.xml").replace("\t", " ");
74+
String expected = TEST_DATA.expected("xml_space.test").replace("\t", " ");
7575
assertEquals("Custom indentation configuration not applied.", expected, output);
7676

77-
output = format(TEST_DATA.input("xml_space.xml"), config -> {
77+
output = format(TEST_DATA.input("xml_space.test"), config -> {
7878
config.setProperty(SPLIT_MULTI_ATTRS, Boolean.toString(true));
7979
});
80-
expected = TEST_DATA.expected("xml_space.xml");
80+
expected = TEST_DATA.expected("xml_space.test");
8181
expected = expected.replace(" a=", LINE_DELIMITER + "\ta=");
8282
expected = expected.replace(" b=", LINE_DELIMITER + "\tb=");
8383
assertEquals("Custom indentation configuration not reverted or custom multiple argument configuration not applied.", expected, output);
8484
}
8585

8686
@Test
8787
public void invalidConfiguration() throws Throwable {
88-
String output = format(TEST_DATA.input("xml_space.xml"), config -> {
88+
String output = format(TEST_DATA.input("xml_space.test"), config -> {
8989
config.setProperty(INDENTATION_SIZE, "Not an integer");
9090
config.setProperty(INDENTATION_CHAR, SPACE);
9191
});
9292
assertEquals("Invalid indentation configuration not replaced by default value (0 spaces)",
93-
TEST_DATA.expected("xml_space.xml").replace("\t", ""), output);
93+
TEST_DATA.expected("xml_space.test").replace("\t", ""), output);
9494
}
9595

9696
@Test
9797
public void dtdRelativePath() throws Throwable {
98-
String output = format(TEST_DATA.input("dtd_relative.xml"), config -> {});
98+
String output = format(TEST_DATA.input("dtd_relative.test"), config -> {});
9999
assertEquals("Relative DTD not resolved. Restrictions are not applied by formatter.",
100-
TEST_DATA.expected("dtd_relative.xml"), output);
100+
TEST_DATA.expected("dtd_relative.test"), output);
101101
}
102102

103103
@Test
104104
public void xsdRelativePath() throws Throwable {
105-
String output = format(TEST_DATA.input("xsd_relative.xml"), config -> {});
105+
String output = format(TEST_DATA.input("xsd_relative.test"), config -> {});
106106
assertEquals("Relative XSD not resolved. Restrictions are not applied by formatter.",
107-
TEST_DATA.expected("xsd_relative.xml"), output);
107+
TEST_DATA.expected("xsd_relative.test"), output);
108108
}
109109

110110
@Test
111111
public void xsdNotFound() throws Throwable {
112-
String output = format(TEST_DATA.input("xsd_not_found.xml"), config -> {});
112+
String output = format(TEST_DATA.input("xsd_not_found.test"), config -> {});
113113
assertEquals("Unresolved XSD/DTD not silently ignored.",
114-
TEST_DATA.expected("xsd_not_found.xml"), output);
114+
TEST_DATA.expected("xsd_not_found.test"), output);
115115
}
116116

117117
@Test
118118
public void catalogLookup() throws Throwable {
119-
String output = format(TEST_DATA.input("xsd_not_found.xml"), config -> {
119+
String output = format(TEST_DATA.input("xsd_not_found.test"), config -> {
120120
config.setProperty(
121121
SpotlessPreferences.USER_CATALOG,
122122
TEST_DATA.getRestrictionsPath("catalog.xml").toString());
123123
});
124124
assertEquals("XSD not resolved by catalog. Restrictions are not applied by formatter.",
125-
TEST_DATA.expected("xsd_not_found.xml").replace(" remove spaces ", "remove spaces"), output);
125+
TEST_DATA.expected("xsd_not_found.test").replace(" remove spaces ", "remove spaces"), output);
126126
}
127127

128128
private static String format(final String[] input, final Consumer<Properties> config) throws Exception {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
3-
<!-- OASIS: If the catalog entry file is specified with a relative URI, it is relative to the base URI of the document that contains the processing instruction. -->
4-
<system systemId="http://foo.bar/test.xsd" uri="./test.xsd"/>
3+
<!-- OASIS: If the catalog entry file is specified with a relative URI, it is relative to the base URI of the document that contains the processing instruction. -->
4+
<system systemId="http://foo.bar/test.xsd" uri="./test.xsd" />
55
</catalog>

_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<xs:element name="x">
77
<xs:simpleType>
88
<xs:restriction base="xs:string">
9-
<xs:whiteSpace value="collapse"/>
9+
<xs:whiteSpace value="collapse" />
1010
</xs:restriction>
1111
</xs:simpleType>
12-
</xs:element>
12+
</xs:element>
1313
<xs:element name="y">
1414
<xs:simpleType>
1515
<xs:restriction base="xs:string">
16-
<xs:whiteSpace value="preserve"/>
16+
<xs:whiteSpace value="preserve" />
1717
</xs:restriction>
1818
</xs:simpleType>
1919
</xs:element>

lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static class State implements Serializable {
152152

153153
/** State constructor expects that all passed items are not modified afterwards */
154154
protected State(String formatterStepExt, Provisioner jarProvisioner, List<String> dependencies, Iterable<File> settingsFiles) throws IOException {
155-
this.jarState = JarState.from(dependencies, jarProvisioner);
155+
this.jarState = JarState.withoutTransitives(dependencies, jarProvisioner);
156156
this.settingsFiles = FileSignature.signAsList(settingsFiles);
157157
this.formatterStepExt = formatterStepExt;
158158
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.extra.cpp;
17+
18+
import java.lang.reflect.Method;
19+
import java.util.Properties;
20+
21+
import com.diffplug.spotless.FormatterFunc;
22+
import com.diffplug.spotless.Provisioner;
23+
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
24+
import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State;
25+
26+
/** Formatter step which calls out to the Eclipse CDT formatter. */
27+
public final class EclipseCdtFormatterStep {
28+
// prevent direct instantiation
29+
private EclipseCdtFormatterStep() {}
30+
31+
private static final String NAME = "eclipse cdt formatter";
32+
private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.cdt.EclipseCdtFormatterStepImpl";
33+
private static final String DEFAULT_VERSION = "4.7.3a";
34+
private static final String FORMATTER_METHOD = "format";
35+
36+
public static String defaultVersion() {
37+
return DEFAULT_VERSION;
38+
}
39+
40+
/** Provides default configuration */
41+
public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
42+
return new EclipseBasedStepBuilder(NAME, provisioner, EclipseCdtFormatterStep::apply);
43+
}
44+
45+
private static FormatterFunc apply(State state) throws Exception {
46+
Class<?> formatterClazz = state.loadClass(FORMATTER_CLASS);
47+
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
48+
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
49+
return input -> (String) method.invoke(formatter, input);
50+
}
51+
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ParametersAreNonnullByDefault
2+
@ReturnValuesAreNonnullByDefault
3+
package com.diffplug.spotless.extra.cpp;
4+
5+
import javax.annotation.ParametersAreNonnullByDefault;
6+
7+
import com.diffplug.spotless.annotations.ReturnValuesAreNonnullByDefault;

lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/WtpEclipseFormatterStep.java renamed to lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
2626

2727
/** Formatter step which calls out to the Groovy-Eclipse formatter. */
28-
public final class WtpEclipseFormatterStep {
28+
public final class EclipseWtpFormatterStep {
2929
// prevent direct instantiation
30-
private WtpEclipseFormatterStep() {}
30+
private EclipseWtpFormatterStep() {}
3131

3232
private static final String NAME = "eclipse wtp formatters";
3333
private static final String FORMATTER_PACKAGE = "com.diffplug.spotless.extra.eclipse.wtp.";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Spotless formatter based on CDT version 9.4.3 (see https://www.eclipse.org/cdt/)
2+
com.diffplug.spotless:spotless-eclipse-cdt:9.4.4
3+
com.diffplug.spotless:spotless-eclipse-base:3.0.0
4+
com.google.code.findbugs:annotations:3.0.0
5+
com.google.code.findbugs:jsr305:3.0.0
6+
com.ibm.icu:icu4j:61.1
7+
org.eclipse.platform:org.eclipse.core.commands:3.9.100
8+
org.eclipse.platform:org.eclipse.core.contenttype:3.7.0
9+
org.eclipse.platform:org.eclipse.core.filebuffers:3.6.200
10+
org.eclipse.platform:org.eclipse.core.filesystem:1.7.100
11+
org.eclipse.platform:org.eclipse.core.jobs:3.10.0
12+
org.eclipse.platform:org.eclipse.core.resources:3.13.0
13+
org.eclipse.platform:org.eclipse.core.runtime:3.14.0
14+
org.eclipse.platform:org.eclipse.equinox.app:1.3.500
15+
org.eclipse.platform:org.eclipse.equinox.common:3.10.0
16+
org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100
17+
org.eclipse.platform:org.eclipse.equinox.registry:3.8.0
18+
org.eclipse.platform:org.eclipse.jface.text:3.13.0
19+
org.eclipse.platform:org.eclipse.jface:3.14.0
20+
org.eclipse.platform:org.eclipse.osgi:3.13.0
21+
org.eclipse.platform:org.eclipse.text:3.6.300

lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters/v4.7.3a.lockfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ org.eclipse.platform:org.eclipse.equinox.app:1.3.500
1717
org.eclipse.platform:org.eclipse.equinox.common:3.10.0
1818
org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100
1919
org.eclipse.platform:org.eclipse.equinox.registry:3.8.0
20-
#Spotless currently loads all transitive dependencies.
21-
#jface requires platform specific JARs (not used by formatter), which are not hosted via M2.
22-
#org.eclipse.platform:org.eclipse.jface.text:3.13.0
23-
#org.eclipse.platform:org.eclipse.jface:3.14.0
20+
org.eclipse.platform:org.eclipse.jface.text:3.13.0
21+
org.eclipse.platform:org.eclipse.jface:3.14.0
2422
org.eclipse.platform:org.eclipse.osgi.services:3.7.0
2523
org.eclipse.platform:org.eclipse.osgi:3.13.0
2624
org.eclipse.platform:org.eclipse.text:3.6.300

lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter/v4.8.0.lockfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ org.eclipse.platform:org.eclipse.equinox.app:1.3.500
1212
org.eclipse.platform:org.eclipse.equinox.common:3.10.0
1313
org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100
1414
org.eclipse.platform:org.eclipse.equinox.registry:3.8.0
15-
#Spotless currently loads all transitive dependencies.
16-
#jface requires platform specific JARs (not used by formatter), which are not hosted via M2.
17-
#org.eclipse.platform:org.eclipse.jface.text:3.13.0
18-
#org.eclipse.platform:org.eclipse.jface:3.14.0
15+
org.eclipse.platform:org.eclipse.jface.text:3.13.0
16+
org.eclipse.platform:org.eclipse.jface:3.14.0
1917
org.eclipse.platform:org.eclipse.osgi:3.13.0
2018
org.eclipse.platform:org.eclipse.text:3.6.300

lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter/v4.8.1.lockfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ org.eclipse.platform:org.eclipse.equinox.app:1.3.500
1212
org.eclipse.platform:org.eclipse.equinox.common:3.10.0
1313
org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100
1414
org.eclipse.platform:org.eclipse.equinox.registry:3.8.0
15-
#Spotless currently loads all transitive dependencies.
16-
#jface requires platform specific JARs (not used by formatter), which are not hosted via M2.
17-
#org.eclipse.platform:org.eclipse.jface.text:3.13.0
18-
#org.eclipse.platform:org.eclipse.jface:3.14.0
15+
org.eclipse.platform:org.eclipse.jface.text:3.13.0
16+
org.eclipse.platform:org.eclipse.jface:3.14.0
1917
org.eclipse.platform:org.eclipse.osgi:3.13.0
2018
org.eclipse.platform:org.eclipse.text:3.6.300
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.extra.cpp;
17+
18+
import com.diffplug.spotless.FormatterStep;
19+
import com.diffplug.spotless.TestProvisioner;
20+
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
21+
import com.diffplug.spotless.extra.eclipse.EclipseCommonTests;
22+
23+
public class EclipseCdtFormatterStepTest extends EclipseCommonTests {
24+
25+
@Override
26+
protected String[] getSupportedVersions() {
27+
return new String[]{"4.7.3a"};
28+
}
29+
30+
@Override
31+
protected String getTestInput(String version) {
32+
return "#include <a.h>;\nint main(int argc, \nchar *argv[]) {}";
33+
}
34+
35+
@Override
36+
protected String getTestExpectation(String version) {
37+
return "#include <a.h>;\nint main(int argc, char *argv[]) {\n}\n";
38+
}
39+
40+
@Override
41+
protected FormatterStep createStep(String version) {
42+
EclipseBasedStepBuilder builder = EclipseCdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
43+
builder.setVersion(version);
44+
return builder.build();
45+
}
46+
47+
}

lib-extra/src/test/java/com/diffplug/spotless/extra/eclipse/EclipseCommonTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.Test;
2323

2424
import com.diffplug.spotless.FormatterStep;
25+
import com.diffplug.spotless.LineEnding;
2526
import com.diffplug.spotless.ResourceHarness;
2627

2728
/**
@@ -78,7 +79,7 @@ public void testSupportedVersions() throws Exception {
7879
}
7980
String output = null;
8081
try {
81-
output = step.format(input, inputFile);
82+
output = LineEnding.toUnix(step.format(input, inputFile));
8283
} catch (Exception e) {
8384
fail("Exception occured when formatting input with version: " + version, e);
8485
}

0 commit comments

Comments
 (0)