Skip to content

Commit 4438d18

Browse files
committed
Small fixes
1 parent 4307866 commit 4438d18

File tree

11 files changed

+41
-33
lines changed

11 files changed

+41
-33
lines changed

plugin-maven/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,8 @@ for details.
768768
```xml
769769
<configuration>
770770
<yaml>
771-
<includes> <!-- These are the default includes -->
772-
<include>**/*.yaml</include>
773-
<include>**/*.yml</include>
771+
<includes> <!-- You have to set the target manually -->
772+
<include>src/**/*.yaml</include>
774773
</includes>
775774

776775
<jackson /> <!-- has its own section below -->
@@ -785,11 +784,11 @@ Uses Jackson and YAMLFactory to pretty print objects:
785784
```xml
786785
<jackson>
787786
<version>2.13.4</version> <!-- optional: The version of 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml' to be used -->
788-
<enabledFeatures> <!-- optional: Customize the set of enabled features -->
787+
<enabledFeatures> <!-- optional: Customize the set of enabled features -->
789788
<enabledFeature>INDENT_OUTPUT<enabledFeature/>
790789
</enabledFeatures>
791-
<disabledFeatures> <!-- optional: Customize the set of disabled features -->
792-
<disabledFeature>DEFAULT_HAS_TO_DISABLED_FEATURE<disabledFeature/>
790+
<disabledFeatures> <!-- optional: Customize the set of disabled features -->
791+
<disabledFeature>DEFAULT_HAS_NO_DISABLED_FEATURE<disabledFeature/>
793792
</disabledFeatures>
794793
</jackson>
795794
```

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,13 +64,15 @@
6464
import com.diffplug.spotless.maven.incremental.UpToDateChecker;
6565
import com.diffplug.spotless.maven.incremental.UpToDateChecking;
6666
import com.diffplug.spotless.maven.java.Java;
67+
import com.diffplug.spotless.maven.json.Json;
6768
import com.diffplug.spotless.maven.kotlin.Kotlin;
6869
import com.diffplug.spotless.maven.markdown.Markdown;
6970
import com.diffplug.spotless.maven.pom.Pom;
7071
import com.diffplug.spotless.maven.python.Python;
7172
import com.diffplug.spotless.maven.scala.Scala;
7273
import com.diffplug.spotless.maven.sql.Sql;
7374
import com.diffplug.spotless.maven.typescript.Typescript;
75+
import com.diffplug.spotless.maven.yaml.Yaml;
7476

7577
public abstract class AbstractSpotlessMojo extends AbstractMojo {
7678
private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index";
@@ -167,6 +169,12 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
167169
@Parameter
168170
private Markdown markdown;
169171

172+
@Parameter
173+
private Json json;
174+
175+
@Parameter
176+
private Yaml yaml;
177+
170178
@Parameter(property = "spotlessFiles")
171179
private String filePatterns;
172180

@@ -331,7 +339,7 @@ private FileLocator getFileLocator() {
331339
}
332340

333341
private List<FormatterFactory> getFormatterFactories() {
334-
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown))
342+
return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown, json, yaml))
335343
.filter(Objects::nonNull)
336344
.collect(toList());
337345
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java renamed to plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.diffplug.spotless.maven.FormatterStepFactory;
2626
import com.diffplug.spotless.yaml.YamlJacksonStep;
2727

28-
public class JacksonYaml implements FormatterStepFactory {
28+
public class Jackson implements FormatterStepFactory {
2929

3030
@Parameter
3131
private String version = YamlJacksonStep.defaultVersion();

plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package com.diffplug.spotless.maven.yaml;
1717

18+
import java.util.Collections;
1819
import java.util.Set;
1920

20-
import com.diffplug.common.collect.Sets;
2121
import com.diffplug.spotless.maven.FormatterFactory;
2222

2323
/**
@@ -26,15 +26,15 @@
2626
public class Yaml extends FormatterFactory {
2727
@Override
2828
public Set<String> defaultIncludes() {
29-
return Sets.newHashSet("**/*.yaml", "**/*.yml");
29+
return Collections.emptySet();
3030
}
3131

3232
@Override
3333
public String licenseHeaderDelimiter() {
3434
return null;
3535
}
3636

37-
public void addJackson(JacksonYaml jackson) {
37+
public void addJackson(Jackson jackson) {
3838
addStepFactory(jackson);
3939
}
4040

plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected void writePomWithJsonSteps(String... steps) throws IOException {
161161
}
162162

163163
protected void writePomWithYamlSteps(String... steps) throws IOException {
164-
writePom(groupWithSteps("yaml", steps));
164+
writePom(groupWithSteps("yaml", including("**/*.yaml"), steps));
165165
}
166166

167167
protected void writePom(String... configuration) throws IOException {

plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class JsonTest extends MavenIntegrationHarness {
2323
@Test
2424
public void testFormatJson_WithSimple_defaultConfig() throws Exception {
25-
writePomWithJsonSteps("<json><simple/></json>");
25+
writePomWithJsonSteps("<simple/>");
2626

2727
setFile("json_test.json").toResource("json/sortByKeysBefore.json");
2828
mavenRunner().withArguments("spotless:apply").runNoError().error();
@@ -31,7 +31,7 @@ public void testFormatJson_WithSimple_defaultConfig() throws Exception {
3131

3232
@Test
3333
public void testFormatJson_WithGson_defaultConfig() throws Exception {
34-
writePomWithJsonSteps("<json><gson/></json>");
34+
writePomWithJsonSteps("<gson/>");
3535

3636
setFile("json_test.json").toResource("json/sortByKeysBefore.json");
3737
mavenRunner().withArguments("spotless:apply").runNoError().error();

plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@
2222
public class YamlTest extends MavenIntegrationHarness {
2323
@Test
2424
public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception {
25-
writePomWithJsonSteps("<yaml><jackson/></yaml>");
25+
writePomWithYamlSteps("<jackson/>");
2626

27-
setFile("yaml_test.json").toResource("yaml/separator_comments.yaml");
27+
setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml");
2828
mavenRunner().withArguments("spotless:apply").runNoError().error();
29-
assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml");
29+
assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml");
3030
}
3131

3232
@Test
3333
public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exception {
34-
writePomWithJsonSteps("<yaml><jackson/></yaml>");
34+
writePomWithYamlSteps("<jackson/>");
3535

36-
setFile("yaml_test.json").toResource("yaml/array_with_bracket.yaml");
36+
setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml");
3737
mavenRunner().withArguments("spotless:apply").runNoError().error();
38-
assertFile("yaml_test.json").sameAsResource("yaml/array_with_bracket.clean.yaml");
38+
assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml");
3939
}
4040

4141
@Test
42-
public void testFormatYaml_WithJackson_defaultConfig_multipleComments() throws Exception {
43-
writePomWithJsonSteps("<yaml><jackson/></yaml>");
42+
public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception {
43+
writePomWithYamlSteps("<jackson/>");
4444

45-
setFile("yaml_test.json").toResource("yaml/multiple_documents.yaml");
45+
setFile("yaml_test.yaml").toResource("yaml/multiple_documents.yaml");
4646
mavenRunner().withArguments("spotless:apply").runNoError().error();
47-
assertFile("yaml_test.json").sameAsResource("yaml/multiple_documents.clean.yaml");
47+
assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.yaml");
4848
}
4949
}

testlib/src/main/resources/yaml/multiple_document.clean.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
document: this is document 1
2+
---
3+
4+
document: this is document 2
5+
6+
---
7+
8+
document: this is document 3

0 commit comments

Comments
 (0)