Skip to content

Commit 7ea0f3a

Browse files
committed
Add custom JDK version
1 parent cf434f2 commit 7ea0f3a

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

lib/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def NEEDS_GLUE = [
1616
'diktat',
1717
'scalafmt',
1818
'jackson',
19-
'gson'
19+
'gson',
20+
'cleanthat'
2021
]
2122
for (glue in NEEDS_GLUE) {
2223
sourceSets.register(glue) {
@@ -100,6 +101,8 @@ dependencies {
100101
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2'
101102

102103
gsonCompileOnly 'com.google.code.gson:gson:2.10.1'
104+
105+
cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.0-SNAPSHOT'
103106
}
104107

105108
// we'll hold the core lib to a high standard

lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 Solven
2+
* Copyright 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.
@@ -27,10 +27,12 @@
2727
import java.util.List;
2828

2929
public class JavaCleanthatRefactorerFunc implements FormatterFunc {
30+
private String jdkVersion;
3031
private List<String> included;
3132
private List<String> excluded;
3233

33-
public JavaCleanthatRefactorerFunc(List<String> included, List<String> excluded) {
34+
public JavaCleanthatRefactorerFunc(String jdkVersion, List<String> included, List<String> excluded) {
35+
this.jdkVersion=jdkVersion == null ? IJdkVersionsConstant.JDK8 : jdkVersion;
3436
this.included = included == null ? Collections.emptyList() : included;
3537
this.excluded = excluded == null ? Collections.emptyList() : excluded;
3638
}
@@ -41,16 +43,18 @@ public JavaCleanthatRefactorerFunc() {
4143

4244
@Override
4345
public String apply(String input) throws Exception {
46+
CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build();
47+
4448
JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties();
4549

4650
refactorerProperties.setIncluded(included);
4751
refactorerProperties.setExcluded(excluded);
4852

4953
JavaRefactorer refactorer =
50-
new JavaRefactorer(CleanthatEngineProperties.builder().build(), refactorerProperties);
54+
new JavaRefactorer(engineProperties, refactorerProperties);
5155

5256
// Spotless calls steps always with LF eol.
53-
return refactorer.doFormat(new PathAndContent(Paths.get("fake"), input), LineEnding.LF);
57+
return refactorer.doFormat(input, LineEnding.LF);
5458
}
5559

5660
}

lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public static String defaultVersion() {
8585
return JVM_SUPPORT.getRecommendedFormatterVersion();
8686
}
8787

88+
public static String defaultGroupArtifact() {
89+
return MAVEN_COORDINATE;
90+
}
91+
8892
static final class JavaRulesState implements Serializable {
8993
private static final long serialVersionUID = 1L;
9094

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2016-2021 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.maven.java;
17+
18+
import com.diffplug.spotless.FormatterStep;
19+
import com.diffplug.spotless.java.CleanthatStepFactory;
20+
import com.diffplug.spotless.java.GoogleJavaFormatStep;
21+
import com.diffplug.spotless.maven.FormatterStepConfig;
22+
import com.diffplug.spotless.maven.FormatterStepFactory;
23+
24+
import org.apache.maven.plugins.annotations.Parameter;
25+
26+
import java.util.List;
27+
28+
public class CleanthatJava implements FormatterStepFactory {
29+
@Parameter
30+
private String groupArtifact;
31+
32+
@Parameter
33+
private String version;
34+
35+
@Parameter
36+
private List<String> mutators;
37+
38+
@Parameter
39+
private List<String> excludedMutators;
40+
41+
@Override
42+
public FormatterStep newFormatterStep(FormatterStepConfig config) {
43+
String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatStepFactory.defaultGroupArtifact();
44+
String version = this.version != null ? this.version : CleanthatStepFactory.defaultVersion();
45+
46+
JavaRe
47+
boolean reflowLongStrings = this.reflowLongStrings != null ? this.reflowLongStrings : GoogleJavaFormatStep.defaultReflowLongStrings();
48+
return CleanthatStepFactory.create(groupArtifact, version, style, config.getProvisioner(), reflowLongStrings);
49+
}
50+
51+
private static String defaultVersion() {
52+
}
53+
}

0 commit comments

Comments
 (0)