From 0fdc3a2593bb4680deaa13f0b1adf962015298ee Mon Sep 17 00:00:00 2001 From: Chitral Verma Date: Thu, 13 Dec 2018 16:01:47 +0530 Subject: [PATCH 1/3] Added exclusions property --- .../plugin/ScalastyleViolationCheckMojo.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java b/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java index 17d52ba..f3105d5 100644 --- a/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java +++ b/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java @@ -171,6 +171,16 @@ public class ScalastyleViolationCheckMojo extends AbstractMojo { @Parameter(property = "scalastyle.input.encoding") private String inputEncoding; + /** + * Regex patterns to exclude files. Applies to all sources. + */ + @Parameter(property = "scalastyle.exclusions") + private List exclusions; + + /** + * Number of excluded files + */ + private int excludedFiles = 0; /** * The Maven Project Object. @@ -201,6 +211,7 @@ public void execute() throws MojoFailureException, MojoExecutionException { getLog().debug("outputFile=" + outputFile); getLog().debug("outputEncoding=" + outputEncoding); getLog().debug("inputEncoding=" + inputEncoding); + getLog().debug("exclusions=" + exclusions); performCheck(); } @@ -225,6 +236,7 @@ private void performCheck() throws MojoFailureException, MojoExecutionException if (!quiet) { System.out.println("Processed " + outputResult.files() + " file(s)"); + System.out.println("Excluded " + excludedFiles + " file(s)"); System.out.println("Found " + outputResult.errors() + " errors"); System.out.println("Found " + outputResult.warnings() + " warnings"); System.out.println("Found " + outputResult.infos() + " infos"); @@ -313,7 +325,26 @@ private List getFilesToProcess() { all.addAll(getFiles("sourceDirectory", sourceDirectoriesAsList(), inputEncoding)); all.addAll(getFiles("testSourceDirectory", testSourceDirectoriesAsList(), inputEncoding)); - return all; + List filteredList = new ArrayList(); + + if (exclusions != null && exclusions.size() != 0) { + for (FileSpec file : all) { + boolean check = true; + + for (String exclusion : exclusions) { + if (!check || file.name().matches(exclusion)) { + check = false; + } + } + if (check) filteredList.add(file); + } + } else { + filteredList = all; + } + + excludedFiles = all.size() - filteredList.size(); + + return filteredList; } private List getFiles(String name, List dirs, String encoding) { From ded38a110eb9fcb5e284fbb23f4dddc61bae48d6 Mon Sep 17 00:00:00 2001 From: Chitral Verma Date: Fri, 14 Dec 2018 21:21:41 +0530 Subject: [PATCH 2/3] Updated documentation --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index d648224..339dff9 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ Default phase of execution is `verify`. The following is an example of a configu ${project.basedir}/lib/scalastyle_config.xml ${project.basedir}/scalastyle-output.xml UTF-8 + + .*directory.* + @@ -55,3 +58,14 @@ You can also specify multiple source directories if necessary. Replace the element in : + +```xml + + .*testdir1.* + .*testdir2.* + +``` + +Only files that match **none** of the provided `exclusions` are processed. From a72ae9f720b7ec77dc0e66aeca360ff2a5c35ed4 Mon Sep 17 00:00:00 2001 From: Chitral Verma Date: Fri, 14 Dec 2018 22:38:36 +0530 Subject: [PATCH 3/3] Added integration test --- src/it/exclusion/invoker.properties | 2 + src/it/exclusion/pom.xml | 49 +++++++++++++++++++ src/it/exclusion/validate.groovy | 14 ++++++ .../plugin/ScalastyleViolationCheckMojo.java | 5 +- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/it/exclusion/invoker.properties create mode 100644 src/it/exclusion/pom.xml create mode 100644 src/it/exclusion/validate.groovy diff --git a/src/it/exclusion/invoker.properties b/src/it/exclusion/invoker.properties new file mode 100644 index 0000000..2623bab --- /dev/null +++ b/src/it/exclusion/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean compile +invoker.buildResult=success diff --git a/src/it/exclusion/pom.xml b/src/it/exclusion/pom.xml new file mode 100644 index 0000000..1e45a8c --- /dev/null +++ b/src/it/exclusion/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + it.scalastyle-maven-plugin + basic + 1.0-SNAPSHOT + Test for basic criteria + Test for basic criteria + pom + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + true + true + true + false + ${src.it}/testsrc + + ${src.it}/testsrc2 + + ${src.it}/scalastyle_config.xml + + .*Foobar2.* + + + + + scalastyle + compile + + check + + + + + + + diff --git a/src/it/exclusion/validate.groovy b/src/it/exclusion/validate.groovy new file mode 100644 index 0000000..cc178c5 --- /dev/null +++ b/src/it/exclusion/validate.groovy @@ -0,0 +1,14 @@ +try { + +def file = new File(basedir, 'target') +assert !file.exists() + +assert new File(basedir, "build.log").readLines().grep(~/.*excluded.*src\/it\/testsrc2\/Foobar2.scala.*/).size() == 1 +assert new File(basedir, "build.log").readLines().grep(~/.*Excluded 1 file.*/).size() == 1 + +return true + +} catch(Throwable e) { + e.printStackTrace() + return false +} diff --git a/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java b/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java index f3105d5..e73568c 100644 --- a/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java +++ b/src/main/java/org/scalastyle/maven/plugin/ScalastyleViolationCheckMojo.java @@ -336,7 +336,10 @@ private List getFilesToProcess() { check = false; } } - if (check) filteredList.add(file); + if (check) + filteredList.add(file); + else if (verbose) + getLog().info("excluded file = " + file.name()); } } else { filteredList = all;