-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from benkard/mulk/feature/google-java-format-1.8
Support google-java-format 1.8+
- Loading branch information
Showing
17 changed files
with
290 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
language: java | ||
jdk: | ||
- openjdk8 | ||
- openjdk11 | ||
env: | ||
- NODE_VERSION="6.10.2" | ||
before_install: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ErrorShouldRethrowJre11.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.Test; | ||
|
||
import com.diffplug.common.base.CharMatcher; | ||
import com.diffplug.common.base.Splitter; | ||
import com.diffplug.common.base.StringPrinter; | ||
import com.diffplug.spotless.JreVersion; | ||
import com.diffplug.spotless.LineEnding; | ||
|
||
/** Tests the desired behavior from https://github.com/diffplug/spotless/issues/46. */ | ||
public class ErrorShouldRethrowJre11 extends GradleIntegrationTest { | ||
private void writeBuild(String... toInsert) throws IOException { | ||
List<String> lines = new ArrayList<>(); | ||
lines.add("plugins {"); | ||
lines.add(" id 'com.diffplug.gradle.spotless'"); | ||
lines.add(" id 'java'"); | ||
lines.add("}"); | ||
lines.add("spotless {"); | ||
lines.add(" format 'misc', {"); | ||
lines.add(" lineEndings 'UNIX'"); | ||
lines.add(" target file('README.md')"); | ||
lines.add(" custom 'no swearing', {"); | ||
lines.add(" if (it.toLowerCase(Locale.ROOT).contains('fubar')) {"); | ||
lines.add(" throw new RuntimeException('No swearing!');"); | ||
lines.add(" }"); | ||
lines.add(" }"); | ||
lines.addAll(Arrays.asList(toInsert)); | ||
setFile("build.gradle").toContent(String.join("\n", lines)); | ||
} | ||
|
||
@Test | ||
public void passesIfNoException() throws Exception { | ||
writeBuild( | ||
" } // format", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fun."); | ||
runWithSuccess("> Task :spotlessMisc"); | ||
} | ||
|
||
@Test | ||
public void anyExceptionShouldFail() throws Exception { | ||
writeBuild( | ||
" } // format", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fubar."); | ||
runWithFailure( | ||
"> Task :spotlessMisc FAILED\n" + | ||
"Step 'no swearing' found problem in 'README.md':\n" + | ||
"No swearing!\n" + | ||
"java.lang.RuntimeException: No swearing!\n"); | ||
} | ||
|
||
@Test | ||
public void unlessEnforceCheckIsFalse() throws Exception { | ||
writeBuild( | ||
" } // format", | ||
" enforceCheck false", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fubar."); | ||
runWithSuccess("> Task :compileJava NO-SOURCE"); | ||
} | ||
|
||
@Test | ||
public void unlessExemptedByStep() throws Exception { | ||
writeBuild( | ||
" ignoreErrorForStep 'no swearing'", | ||
" } // format", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fubar."); | ||
runWithSuccess("> Task :spotlessMisc\n" + | ||
"Unable to apply step 'no swearing' to 'README.md'"); | ||
} | ||
|
||
@Test | ||
public void unlessExemptedByPath() throws Exception { | ||
writeBuild( | ||
" ignoreErrorForPath 'README.md'", | ||
" } // format", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fubar."); | ||
runWithSuccess("> Task :spotlessMisc", | ||
"Unable to apply step 'no swearing' to 'README.md'"); | ||
} | ||
|
||
@Test | ||
public void failsIfNeitherStepNorFileExempted() throws Exception { | ||
writeBuild( | ||
" ignoreErrorForStep 'nope'", | ||
" ignoreErrorForPath 'nope'", | ||
" } // format", | ||
"} // spotless"); | ||
setFile("README.md").toContent("This code is fubar."); | ||
runWithFailure("> Task :spotlessMisc FAILED\n" + | ||
"Step 'no swearing' found problem in 'README.md':\n" + | ||
"No swearing!\n" + | ||
"java.lang.RuntimeException: No swearing!\n"); | ||
} | ||
|
||
private void runWithSuccess(String... messages) throws Exception { | ||
if (JreVersion.thisVm() != JreVersion._11) { | ||
return; | ||
} | ||
BuildResult result = gradleRunner().withArguments("check").build(); | ||
assertResultAndMessages(result, TaskOutcome.SUCCESS, messages); | ||
} | ||
|
||
private void runWithFailure(String... messages) throws Exception { | ||
if (JreVersion.thisVm() != JreVersion._11) { | ||
return; | ||
} | ||
BuildResult result = gradleRunner().withArguments("check").buildAndFail(); | ||
assertResultAndMessages(result, TaskOutcome.FAILED, messages); | ||
} | ||
|
||
private void assertResultAndMessages(BuildResult result, TaskOutcome outcome, String... messages) { | ||
String expectedToStartWith = StringPrinter.buildStringFromLines(messages).trim(); | ||
int numNewlines = CharMatcher.is('\n').countIn(expectedToStartWith); | ||
List<String> actualLines = Splitter.on('\n').splitToList(LineEnding.toUnix(result.getOutput().trim())); | ||
String actualStart = String.join("\n", actualLines.subList(0, numNewlines + 1)); | ||
Assertions.assertThat(actualStart).isEqualTo(expectedToStartWith); | ||
Assertions.assertThat(result.tasks(outcome).size() + result.tasks(TaskOutcome.UP_TO_DATE).size() + result.tasks(TaskOutcome.NO_SOURCE).size()) | ||
.isEqualTo(result.getTasks().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.