Skip to content

Commit

Permalink
Wildcard targets are now tolerant of flatIncude subprojects (diffplug…
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jun 19, 2017
1 parent 3c5b541 commit 38d8882
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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,23 @@ protected FileCollection parseTarget(Object target) {
}
}

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.
*/
@Nullable
static 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

0 comments on commit 38d8882

Please sign in to comment.