Skip to content

Commit 048947b

Browse files
committed
adapt more gjf format specifications
1 parent cb0fd38 commit 048947b

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static FormatterStep create(String groupArtifact, String version, String
7171

7272
static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME)
7373
.addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes
74+
.addMin(16, "1.10.0") // java 16 requires at least 1.10.0 due to jdk api changes in JavaTokenizer
7475
.add(11, "1.16.0"); // default version
7576

7677
public static String defaultGroupArtifact() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void testMultipleDependenciesExcludingTransitives() throws Exception {
3333
void testSingleDependencyIncludingTransitives() throws Exception {
3434
writePomWithJavaSteps(
3535
"<googleJavaFormat>",
36-
" <version>1.2</version>",
36+
" <version>1.10.0</version>",
3737
"</googleJavaFormat>");
3838
assertResolveDependenciesWorks();
3939
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -58,7 +58,7 @@ private void integration(String patterns, boolean firstFormatted, boolean second
5858
" <include>src/**/java/**/*.java</include>",
5959
"</includes>",
6060
"<googleJavaFormat>",
61-
" <version>1.2</version>",
61+
" <version>1.10.0</version>",
6262
"</googleJavaFormat>");
6363

6464
setFile(testFile(1)).toResource(fixture(false));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GoogleJavaFormatTest extends MavenIntegrationHarness {
2424
void specificVersionDefaultStyle() throws Exception {
2525
writePomWithJavaSteps(
2626
"<googleJavaFormat>",
27-
" <version>1.2</version>",
27+
" <version>1.10.0</version>",
2828
"</googleJavaFormat>");
2929

3030
runTest("java/googlejavaformat/JavaCodeFormatted.test");
@@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception {
3434
void specificVersionSpecificStyle() throws Exception {
3535
writePomWithJavaSteps(
3636
"<googleJavaFormat>",
37-
" <version>1.2</version>",
37+
" <version>1.10.0</version>",
3838
" <style>AOSP</style>",
3939
"</googleJavaFormat>");
4040

@@ -45,7 +45,7 @@ void specificVersionSpecificStyle() throws Exception {
4545
void specificVersionReflowLongStrings() throws Exception {
4646
writePomWithJavaSteps(
4747
"<googleJavaFormat>",
48-
" <version>1.8</version>",
48+
" <version>1.10.0</version>",
4949
" <reflowLongStrings>true</reflowLongStrings>",
5050
"</googleJavaFormat>");
5151

testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.junit.jupiter.api.condition.JRE.JAVA_13;
1919
import static org.junit.jupiter.api.condition.JRE.JAVA_15;
20+
import static org.junit.jupiter.api.condition.JRE.JAVA_16;
2021

2122
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.api.condition.EnabledForJreRange;
@@ -51,7 +52,7 @@ void behavior18() throws Exception {
5152

5253
@Test
5354
void behavior() throws Exception {
54-
FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral());
55+
FormatterStep step = GoogleJavaFormatStep.create("1.10.0", TestProvisioner.mavenCentral());
5556
StepHarness.forStep(step)
5657
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test")
5758
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test")
@@ -67,9 +68,18 @@ void versionBelowMinimumRequiredVersionIsNotAllowed() throws Exception {
6768
.contains("you are using 1.2");
6869
}
6970

71+
@Test
72+
@EnabledForJreRange(min = JAVA_16)
73+
void versionBelowOneDotTenIsNotAllowed() throws Exception {
74+
FormatterStep step = GoogleJavaFormatStep.create("1.9", "AOSP", TestProvisioner.mavenCentral());
75+
StepHarness.forStep(step)
76+
.testResourceExceptionMsg("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test")
77+
.contains("you are using 1.9");
78+
}
79+
7080
@Test
7181
void behaviorWithAospStyle() throws Exception {
72-
FormatterStep step = GoogleJavaFormatStep.create("1.8", "AOSP", TestProvisioner.mavenCentral());
82+
FormatterStep step = GoogleJavaFormatStep.create("1.10.0", "AOSP", TestProvisioner.mavenCentral());
7383
StepHarness.forStep(step)
7484
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormattedAOSP.test")
7585
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormattedAOSP.test")
@@ -91,7 +101,7 @@ void behaviorWithReflowLongStrings() throws Exception {
91101

92102
@Test
93103
void behaviorWithCustomGroupArtifact() throws Exception {
94-
FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.8", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false);
104+
FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.10.0", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false);
95105
StepHarness.forStep(step)
96106
.testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test")
97107
.testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test")
@@ -102,7 +112,7 @@ void behaviorWithCustomGroupArtifact() throws Exception {
102112
@Test
103113
void equality() throws Exception {
104114
new SerializableEqualityTester() {
105-
String version = "1.8";
115+
String version = "1.10.0";
106116
String style = "";
107117
boolean reflowLongStrings = false;
108118

@@ -111,7 +121,7 @@ protected void setupTest(API api) {
111121
// same version == same
112122
api.areDifferentThan();
113123
// change the version, and it's different
114-
version = "1.9";
124+
version = "1.11.0";
115125
api.areDifferentThan();
116126
// change the style, and it's different
117127
style = "AOSP";

0 commit comments

Comments
 (0)