Skip to content
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

Wildcard targets are now tolerant of flatIncude subprojects (#121). #122

Merged
merged 2 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Version 3.5.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/))

* Default eclipse version for `EclipseFormatterStep` bumped to `4.6.3` from `4.6.1`. ([#116](https://github.com/diffplug/spotless/issues/116))
* Fixed wildcard targets for `includeFlat` subprojects ([#121](https://github.com/diffplug/spotless/issues/121))

### Version 3.4.0 - May 21st 2017 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.4.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.4.0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ protected FileCollection parseTarget(Object target) {
if (getProject() == getProject().getRootProject()) {
excludes.add(".gradle");
}
// no build folders
excludes.add(relativize(dir, getProject().getBuildDir()));
// no build folders (flatInclude means that subproject might not be subfolders, see https://github.com/diffplug/spotless/issues/121)
relativizeIfSubdir(excludes, dir, getProject().getBuildDir());
for (Project subproject : getProject().getSubprojects()) {
excludes.add(relativize(dir, subproject.getBuildDir()));
relativizeIfSubdir(excludes, dir, subproject.getBuildDir());
}
if (target instanceof String) {
return (FileCollection) getProject().fileTree(dir).include((String) target).exclude(excludes);
Expand All @@ -185,11 +185,22 @@ protected FileCollection parseTarget(Object target) {
}
}

static String relativize(File root, File dest) {
private static void relativizeIfSubdir(List<String> relativePaths, File root, File dest) {
String relativized = relativize(root, dest);
if (relativized != null) {
relativePaths.add(relativized);
}
}

/**
* Returns the relative path between root and dest,
* or null if dest is not a child of root.
*/
static @Nullable String relativize(File root, File dest) {
String rootPath = root.getAbsolutePath();
String destPath = dest.getAbsolutePath();
if (!destPath.startsWith(rootPath)) {
throw new IllegalArgumentException(dest + " is not a child of " + root);
return null;
} else {
return destPath.substring(rootPath.length());
}
Expand Down