Skip to content

Commit

Permalink
fix: build inclusions
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jan 6, 2023
1 parent 0cb8929 commit d8e8ca4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public final class Selection {
public Selection(File basedir, String[] included, String[] excluded, boolean useDefaultExcludes) {
this.basedir = basedir;
this.fs = basedir.toPath().getFileSystem();
final String[] overrides = buildOverrideInclusions(useDefaultExcludes, included);
this.included = buildInclusions(included, overrides);
this.excluded = buildExclusions(useDefaultExcludes, excluded, overrides);
this.included = included.length > 0 ? included : Default.INCLUDE;
this.excluded = buildExclusions(useDefaultExcludes, excluded, included);
this.selectedFiles = new CompletableFuture<>();
}

Expand Down Expand Up @@ -103,41 +102,17 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
return selectedFiles.get(0, TimeUnit.SECONDS);
}

private static String[] buildExclusions(boolean useDefaultExcludes, String[] excludes, String[] overrides) {
private static String[] buildExclusions(boolean useDefaultExcludes, String[] excludes, String[] includes) {
final List<String> exclusions = new ArrayList<>();
if (useDefaultExcludes) {
exclusions.addAll(asList(Default.EXCLUDES));
}
// remove from the default exclusion list the patterns that have been explicitly included
for (String override : overrides) {
exclusions.remove(override);
}
if (excludes != null && excludes.length > 0) {
exclusions.addAll(asList(excludes));
}
exclusions.removeAll(asList(includes));
exclusions.addAll(asList(excludes));
return exclusions.toArray(new String[0]);
}

private static String[] buildInclusions(String[] includes, String[] overrides) {
// if we use the default exclusion list, we just remove
final List<String> inclusions = new ArrayList<>(asList(includes != null && includes.length > 0 ? includes : Default.INCLUDE));
inclusions.removeAll(asList(overrides));
if (inclusions.isEmpty()) {
inclusions.addAll(asList(Default.INCLUDE));
}
return inclusions.toArray(new String[0]);
}

private static String[] buildOverrideInclusions(boolean useDefaultExcludes, String[] includes) {
// return the list of patterns that we have explicitly included when using default exclude list
if (!useDefaultExcludes || includes == null || includes.length == 0) {
return new String[0];
}
List<String> overrides = new ArrayList<>(asList(Default.EXCLUDES));
overrides.retainAll(asList(includes));
return overrides.toArray(new String[0]);
}

private List<PathMatcher> findFolderExcludes() {
final List<String> excludes = new ArrayList<>();
for (final String exclude : excluded) {
Expand Down
5 changes: 5 additions & 0 deletions licenserc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ See the License for the specific language governing permissions and
limitations under the License.
"""

includes = [
"**/target/**",
"pom.xml"
]

excludes = [
"**/src/test/**/*.txt",
"**/src/test/**/*.xml",
Expand Down

0 comments on commit d8e8ca4

Please sign in to comment.