-
Notifications
You must be signed in to change notification settings - Fork 472
allow "spotlessFiles" project property in gradle plugin to only target specific files #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85c8ad6
allow "files" project property in gradle plugin to only target specif…
vmdominguez cc9342f
update gradle plugin change log
vmdominguez f28d19c
change specific files project property to "spotlessFiles" to avoid co…
vmdominguez 8c32c19
fix PR feedback
vmdominguez 29a8fc8
fix up-to-date checking bug
vmdominguez fecc1f8
more PR feedback
vmdominguez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
82 changes: 82 additions & 0 deletions
82
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpecificFilesTest.java
This file contains hidden or 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,82 @@ | ||
/* | ||
* 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 org.junit.Test; | ||
|
||
public class SpecificFilesTest extends GradleIntegrationTest { | ||
private String testFile(int number, boolean absolute) throws IOException { | ||
String rel = "src/main/java/test" + number + ".java"; | ||
if (absolute) { | ||
return rootFolder() + "/" + rel; | ||
} else { | ||
return rel; | ||
} | ||
} | ||
|
||
private String testFile(int number) throws IOException { | ||
return testFile(number, false); | ||
} | ||
|
||
private String fixture(boolean formatted) { | ||
return "java/googlejavaformat/JavaCode" + (formatted ? "F" : "Unf") + "ormatted.test"; | ||
} | ||
|
||
private void integration(String patterns, boolean firstFormatted, boolean secondFormatted, boolean thirdFormatted) | ||
throws IOException { | ||
|
||
setFile("build.gradle").toLines( | ||
"buildscript { repositories { mavenCentral() } }", | ||
"plugins {", | ||
" id 'com.diffplug.gradle.spotless'", | ||
"}", | ||
"apply plugin: 'java'", | ||
"spotless {", | ||
" java {", | ||
" googleJavaFormat('1.2')", | ||
" }", | ||
"}"); | ||
|
||
setFile(testFile(1)).toResource(fixture(false)); | ||
setFile(testFile(2)).toResource(fixture(false)); | ||
setFile(testFile(3)).toResource(fixture(false)); | ||
|
||
gradleRunner() | ||
.withArguments("spotlessApply", "-PspotlessFiles=" + patterns) | ||
.build(); | ||
|
||
assertFile(testFile(1)).sameAsResource(fixture(firstFormatted)); | ||
assertFile(testFile(2)).sameAsResource(fixture(secondFormatted)); | ||
assertFile(testFile(3)).sameAsResource(fixture(thirdFormatted)); | ||
} | ||
|
||
@Test | ||
public void singleFile() throws IOException { | ||
integration(testFile(2, true), false, true, false); | ||
} | ||
|
||
@Test | ||
public void multiFile() throws IOException { | ||
integration(testFile(1, true) + "," + testFile(3, true), true, false, true); | ||
} | ||
|
||
@Test | ||
public void regexp() throws IOException { | ||
integration(".*/src/main/java/test(1|3).java", true, false, true); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.