From 55292a912d82f631ce921e31b588d58dbdb5b2f1 Mon Sep 17 00:00:00 2001 From: mspiller Date: Tue, 9 Feb 2016 14:21:46 +0100 Subject: [PATCH 001/153] initial checkin of m2e cs example --- .../build-tools/pom.xml | 14 ++ .../src/main/resources/PMDRules.xml | 15 ++ .../resources/checkstyle-suppressions.xml | 18 +++ .../src/main/resources/checkstyle.properties | 1 + .../src/main/resources/checkstyle.xml | 34 +++++ .../failing-checkstyle-example-core/pom.xml | 10 ++ .../pom.xml | 10 ++ .../failing-checkstyle-example/pom.xml | 129 ++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100644 test-projects/failing-checkstyle-example/build-tools/pom.xml create mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml create mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml create mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties create mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml create mode 100644 test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml create mode 100644 test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml create mode 100644 test-projects/failing-checkstyle-example/pom.xml diff --git a/test-projects/failing-checkstyle-example/build-tools/pom.xml b/test-projects/failing-checkstyle-example/build-tools/pom.xml new file mode 100644 index 00000000..14af7ba2 --- /dev/null +++ b/test-projects/failing-checkstyle-example/build-tools/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + + de.spiller.test + build-tools + jar + 0.0.1-SNAPSHOT + + Java Code Quality Resources + This project contains codestyle guidelines used by Maven and Eclipse + + diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml new file mode 100644 index 00000000..0bee5ed5 --- /dev/null +++ b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml @@ -0,0 +1,15 @@ + + + Custom PMD Ruleset + + + + + + + + + \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml new file mode 100644 index 00000000..11ce9051 --- /dev/null +++ b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties new file mode 100644 index 00000000..61ce8fa3 --- /dev/null +++ b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties @@ -0,0 +1 @@ +config_loc= \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml new file mode 100644 index 00000000..71bd2315 --- /dev/null +++ b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml b/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml new file mode 100644 index 00000000..ed22247c --- /dev/null +++ b/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + de.spiller.test + failing-checkstyle-example-parent + 0.0.1-SNAPSHOT + + failing-checkstyle-example-core + diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml b/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml new file mode 100644 index 00000000..23733470 --- /dev/null +++ b/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + de.spiller.test + failing-checkstyle-example-parent + 0.0.1-SNAPSHOT + + failing-checkstyle-example-persistence + diff --git a/test-projects/failing-checkstyle-example/pom.xml b/test-projects/failing-checkstyle-example/pom.xml new file mode 100644 index 00000000..715ae4e0 --- /dev/null +++ b/test-projects/failing-checkstyle-example/pom.xml @@ -0,0 +1,129 @@ + + 4.0.0 + + de.spiller.test + failing-checkstyle-example-parent + 0.0.1-SNAPSHOT + pom + + m2e quality example parent + Parent for a m2e quality check example + + build-tools + failing-checkstyle-example-persistence + failing-checkstyle-example-core + + + + + UTF-8 + 1.8 + true + 2 + + ${compileSource} + ${compileSource} + + ${project.version} + 2.6 + 2.17 + 3.6 + + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven.checkstyle.version} + + + org.apache.maven.plugins + maven-pmd-plugin + ${maven.pmd.version} + + + + org.apache.maven.plugins + maven-assembly-plugin + ${maven.assembly.version} + + + src + + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + ${project.groupId} + build-tools + ${build.tools.version} + + + + false + basedir=${basedir} + checkstyle.properties + checkstyle.xml + target/generated-sources/* + checkstyle-suppressions.xml + + + + compile + + checkstyle + + + ${checkstyle.failsOnError} + false + + + + + + org.apache.maven.plugins + maven-pmd-plugin + + + ${project.groupId} + build-tools + ${build.tools.version} + + + + ${compileSource} + + PMDRules.xml + + ${pmd.failurePriority} + false + true + + target/generated-sources + + + + + + check + + compile + + + + + + + From 28041524817908ea4d24683b4edab1a620726fb8 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 9 Feb 2016 18:31:35 +0100 Subject: [PATCH 002/153] Add build and reporting encoding --- test-projects/failing-checkstyle-example/build-tools/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test-projects/failing-checkstyle-example/build-tools/pom.xml b/test-projects/failing-checkstyle-example/build-tools/pom.xml index 14af7ba2..04a97719 100644 --- a/test-projects/failing-checkstyle-example/build-tools/pom.xml +++ b/test-projects/failing-checkstyle-example/build-tools/pom.xml @@ -11,4 +11,9 @@ Java Code Quality Resources This project contains codestyle guidelines used by Maven and Eclipse + + UTF-8 + UTF-8 + + From bfdf48064cb35b61a9517412837dbbaf702e1e73 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 9 Feb 2016 18:33:19 +0100 Subject: [PATCH 003/153] Add App.java with tab and syso --- .../src/main/java/App.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java b/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java new file mode 100644 index 00000000..fc81c5af --- /dev/null +++ b/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java @@ -0,0 +1,7 @@ +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} From 5a84a5572f7850c19dea7e5673f47c2953c80c60 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 9 Feb 2016 19:57:59 +0100 Subject: [PATCH 004/153] Turn failing-checkstyle-project into checkstyle-5 --- .../checkstyle-config}/pom.xml | 10 +- .../resources/checkstyle-suppressions.xml | 0 .../resources/checkstyle-suppressions2.xml | 16 +++ .../src/main/resources/checkstyle.xml | 2 +- .../project-using-checkstyle-config/pom.xml | 48 +++++++ .../src/main/java/com/generated}/App.java | 1 + .../src/main/resources/PMDRules.xml | 15 -- .../src/main/resources/checkstyle.properties | 1 - .../failing-checkstyle-example-core/pom.xml | 10 -- .../pom.xml | 10 -- .../failing-checkstyle-example/pom.xml | 129 ------------------ 11 files changed, 70 insertions(+), 172 deletions(-) rename test-projects/{failing-checkstyle-example/build-tools => checkstyle-5/checkstyle-config}/pom.xml (69%) rename test-projects/{failing-checkstyle-example/build-tools => checkstyle-5/checkstyle-config}/src/main/resources/checkstyle-suppressions.xml (100%) create mode 100644 test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml rename test-projects/{failing-checkstyle-example/build-tools => checkstyle-5/checkstyle-config}/src/main/resources/checkstyle.xml (93%) create mode 100644 test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml rename test-projects/{failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java => checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated}/App.java (81%) delete mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml delete mode 100644 test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties delete mode 100644 test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml delete mode 100644 test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml delete mode 100644 test-projects/failing-checkstyle-example/pom.xml diff --git a/test-projects/failing-checkstyle-example/build-tools/pom.xml b/test-projects/checkstyle-5/checkstyle-config/pom.xml similarity index 69% rename from test-projects/failing-checkstyle-example/build-tools/pom.xml rename to test-projects/checkstyle-5/checkstyle-config/pom.xml index 04a97719..7e4562f1 100644 --- a/test-projects/failing-checkstyle-example/build-tools/pom.xml +++ b/test-projects/checkstyle-5/checkstyle-config/pom.xml @@ -2,18 +2,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - - de.spiller.test - build-tools + com.basistech + checkstyle-5-config jar 0.0.1-SNAPSHOT - Java Code Quality Resources - This project contains codestyle guidelines used by Maven and Eclipse - UTF-8 UTF-8 + 1.8 + 1.8 diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml similarity index 100% rename from test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle-suppressions.xml rename to test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml new file mode 100644 index 00000000..6e8101e5 --- /dev/null +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml similarity index 93% rename from test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml rename to test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml index 71bd2315..d0dccbcb 100644 --- a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.xml +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml @@ -29,6 +29,6 @@ - + diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml new file mode 100644 index 00000000..061da528 --- /dev/null +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + com.basistech + checkstyle-5-project + 0.0.1-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + ${project.groupId} + checkstyle-5-config + ${project.version} + + + + true + checkstyle.xml + target/generated-sources/* + checkstyle-suppressions.xml + + + + compile + + checkstyle + + + + + + + + diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java similarity index 81% rename from test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java rename to test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java index fc81c5af..7c419419 100644 --- a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/src/main/java/App.java +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java @@ -1,3 +1,4 @@ +package com.generated; public class App { public static void main(String[] args) { diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml deleted file mode 100644 index 0bee5ed5..00000000 --- a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/PMDRules.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - Custom PMD Ruleset - - - - - - - - - \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties b/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties deleted file mode 100644 index 61ce8fa3..00000000 --- a/test-projects/failing-checkstyle-example/build-tools/src/main/resources/checkstyle.properties +++ /dev/null @@ -1 +0,0 @@ -config_loc= \ No newline at end of file diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml b/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml deleted file mode 100644 index ed22247c..00000000 --- a/test-projects/failing-checkstyle-example/failing-checkstyle-example-core/pom.xml +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - - de.spiller.test - failing-checkstyle-example-parent - 0.0.1-SNAPSHOT - - failing-checkstyle-example-core - diff --git a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml b/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml deleted file mode 100644 index 23733470..00000000 --- a/test-projects/failing-checkstyle-example/failing-checkstyle-example-persistence/pom.xml +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - - de.spiller.test - failing-checkstyle-example-parent - 0.0.1-SNAPSHOT - - failing-checkstyle-example-persistence - diff --git a/test-projects/failing-checkstyle-example/pom.xml b/test-projects/failing-checkstyle-example/pom.xml deleted file mode 100644 index 715ae4e0..00000000 --- a/test-projects/failing-checkstyle-example/pom.xml +++ /dev/null @@ -1,129 +0,0 @@ - - 4.0.0 - - de.spiller.test - failing-checkstyle-example-parent - 0.0.1-SNAPSHOT - pom - - m2e quality example parent - Parent for a m2e quality check example - - build-tools - failing-checkstyle-example-persistence - failing-checkstyle-example-core - - - - - UTF-8 - 1.8 - true - 2 - - ${compileSource} - ${compileSource} - - ${project.version} - 2.6 - 2.17 - 3.6 - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven.checkstyle.version} - - - org.apache.maven.plugins - maven-pmd-plugin - ${maven.pmd.version} - - - - org.apache.maven.plugins - maven-assembly-plugin - ${maven.assembly.version} - - - src - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - ${project.groupId} - build-tools - ${build.tools.version} - - - - false - basedir=${basedir} - checkstyle.properties - checkstyle.xml - target/generated-sources/* - checkstyle-suppressions.xml - - - - compile - - checkstyle - - - ${checkstyle.failsOnError} - false - - - - - - org.apache.maven.plugins - maven-pmd-plugin - - - ${project.groupId} - build-tools - ${build.tools.version} - - - - ${compileSource} - - PMDRules.xml - - ${pmd.failurePriority} - false - true - - target/generated-sources - - - - - - check - - compile - - - - - - - From 66b73db40d7810b2adb984767f314ac3558c58d6 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 19:25:38 +0100 Subject: [PATCH 005/153] Add App.java that should show warnings --- .../src/main/java/com/example/App.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java new file mode 100644 index 00000000..f4d31573 --- /dev/null +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java @@ -0,0 +1,8 @@ +package com.example; +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} From 44581724b85f55cc74b2e22051c2f9f384d0056f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:07:29 +0100 Subject: [PATCH 006/153] Remove checkstyle-suppressions2.xml --- .../main/resources/checkstyle-suppressions2.xml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml deleted file mode 100644 index 6e8101e5..00000000 --- a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file From 2c27cee2441a36a79b4a5fd84133e7a857f7d000 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:07:37 +0100 Subject: [PATCH 007/153] Reduce checkstyle-suppressions.xml --- .../main/resources/checkstyle-suppressions.xml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml index 11ce9051..2ad678a1 100644 --- a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml @@ -1,18 +1,7 @@ - - - - - - - - - - - \ No newline at end of file + + From 2a6f607868342f36410f61bafd86f7b1c8ff2147 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:07:53 +0100 Subject: [PATCH 008/153] Remove unnecessary excludes property --- .../checkstyle-5/project-using-checkstyle-config/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml index 061da528..86646eed 100644 --- a/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml @@ -30,7 +30,6 @@ true checkstyle.xml - target/generated-sources/* checkstyle-suppressions.xml From 1900596a16c549b2dd220a37b336d99fc114b181 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:08:19 +0100 Subject: [PATCH 009/153] Give packages verbose names --- .../java/{com/generated => iampartofthesuppressions}/App.java | 3 ++- .../main/java/{com/example => ishouldthrowanerror}/App.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) rename test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/{com/generated => iampartofthesuppressions}/App.java (73%) rename test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/{com/example => ishouldthrowanerror}/App.java (76%) diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/iampartofthesuppressions/App.java similarity index 73% rename from test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java rename to test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/iampartofthesuppressions/App.java index 7c419419..79c93b6b 100644 --- a/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/generated/App.java +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/iampartofthesuppressions/App.java @@ -1,4 +1,5 @@ -package com.generated; +package iampartofthesuppressions; + public class App { public static void main(String[] args) { diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/ishouldthrowanerror/App.java similarity index 76% rename from test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java rename to test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/ishouldthrowanerror/App.java index f4d31573..ce51bbbb 100644 --- a/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/com/example/App.java +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/src/main/java/ishouldthrowanerror/App.java @@ -1,4 +1,5 @@ -package com.example; +package ishouldthrowanerror; + public class App { public static void main(String[] args) { From 1e30959bfe1cad1b71439368818014f0cf2f5852 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:14:28 +0100 Subject: [PATCH 010/153] Format suppressions --- .../src/main/resources/checkstyle-suppressions.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml index 2ad678a1..c8ca27bd 100644 --- a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml @@ -3,5 +3,7 @@ "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> - + From c00d2ce83f95e89100ffbfb5cb638d75c15b15b7 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:20:23 +0100 Subject: [PATCH 011/153] Indent with spaces instead of tabs --- .../src/main/resources/checkstyle-suppressions.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml index c8ca27bd..caca8fa5 100644 --- a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle-suppressions.xml @@ -3,7 +3,7 @@ "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> - + From 5ba6d93540a22eeee4242c515d6808eba5dd3fe5 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:20:46 +0100 Subject: [PATCH 012/153] Reduce check style config and indent with spaces --- .../src/main/resources/checkstyle.xml | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml index d0dccbcb..9047b8be 100644 --- a/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml +++ b/test-projects/checkstyle-5/checkstyle-config/src/main/resources/checkstyle.xml @@ -1,34 +1,27 @@ - - - + "-//Puppy Crawl//DTD Check Configuration 1.3//EN" + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + From 9e4998177e3926e887daddcf7efca5f1fe05f705 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:20:54 +0100 Subject: [PATCH 013/153] Indent with spaces --- .../checkstyle-5/checkstyle-config/pom.xml | 28 ++++--- .../project-using-checkstyle-config/pom.xml | 84 ++++++++++--------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/test-projects/checkstyle-5/checkstyle-config/pom.xml b/test-projects/checkstyle-5/checkstyle-config/pom.xml index 7e4562f1..5cfae2b8 100644 --- a/test-projects/checkstyle-5/checkstyle-config/pom.xml +++ b/test-projects/checkstyle-5/checkstyle-config/pom.xml @@ -1,17 +1,19 @@ - - 4.0.0 + - com.basistech - checkstyle-5-config - jar - 0.0.1-SNAPSHOT + 4.0.0 - - UTF-8 - UTF-8 - 1.8 - 1.8 - + com.basistech + checkstyle-5-config + 0.0.1-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + diff --git a/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml index 86646eed..5a24e4cc 100644 --- a/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml +++ b/test-projects/checkstyle-5/project-using-checkstyle-config/pom.xml @@ -1,47 +1,49 @@ - + - 4.0.0 + 4.0.0 - com.basistech - checkstyle-5-project - 0.0.1-SNAPSHOT + com.basistech + checkstyle-5-project + 0.0.1-SNAPSHOT - - UTF-8 - UTF-8 - 1.8 - 1.8 - + + UTF-8 + UTF-8 + 1.8 + 1.8 + - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - ${project.groupId} - checkstyle-5-config - ${project.version} - - - - true - checkstyle.xml - checkstyle-suppressions.xml - - - - compile - - checkstyle - - - - - - + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + ${project.groupId} + checkstyle-5-config + ${project.version} + + + + true + checkstyle.xml + checkstyle-suppressions.xml + + + + compile + + checkstyle + + + + + + From 0e6ea49d367c8ad2c05e3ec3336d3f39601bfa16 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Wed, 10 Feb 2016 22:52:55 +0100 Subject: [PATCH 014/153] Add checkstyle-6 --- .../checkstyle-6-child-project/pom.xml | 16 ++++++ .../java/iampartofthesuppressions/App.java | 9 ++++ .../main/java/ishouldthrowanerror/App.java | 9 ++++ test-projects/checkstyle-6/pom.xml | 54 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 test-projects/checkstyle-6/checkstyle-6-child-project/pom.xml create mode 100644 test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/iampartofthesuppressions/App.java create mode 100644 test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/ishouldthrowanerror/App.java create mode 100644 test-projects/checkstyle-6/pom.xml diff --git a/test-projects/checkstyle-6/checkstyle-6-child-project/pom.xml b/test-projects/checkstyle-6/checkstyle-6-child-project/pom.xml new file mode 100644 index 00000000..c02066f3 --- /dev/null +++ b/test-projects/checkstyle-6/checkstyle-6-child-project/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + + com.basistech + checkstyle-6-parent-project + 0.0.1-SNAPSHOT + + + checkstyle-6-child-project + + diff --git a/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/iampartofthesuppressions/App.java b/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/iampartofthesuppressions/App.java new file mode 100644 index 00000000..79c93b6b --- /dev/null +++ b/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/iampartofthesuppressions/App.java @@ -0,0 +1,9 @@ +package iampartofthesuppressions; + +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} diff --git a/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/ishouldthrowanerror/App.java b/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/ishouldthrowanerror/App.java new file mode 100644 index 00000000..ce51bbbb --- /dev/null +++ b/test-projects/checkstyle-6/checkstyle-6-child-project/src/main/java/ishouldthrowanerror/App.java @@ -0,0 +1,9 @@ +package ishouldthrowanerror; + +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} diff --git a/test-projects/checkstyle-6/pom.xml b/test-projects/checkstyle-6/pom.xml new file mode 100644 index 00000000..b8a10b5e --- /dev/null +++ b/test-projects/checkstyle-6/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.basistech + checkstyle-6-parent-project + pom + 0.0.1-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + ${project.groupId} + checkstyle-5-config + ${project.version} + + + + true + checkstyle.xml + checkstyle-suppressions.xml + + + + compile + + checkstyle + + + + + + + + + checkstyle-6-child-project + + + From 19edbc39f3e4e7cc2f23d4036acf8f0ec9cfafcd Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Tue, 16 Feb 2016 18:23:00 +0100 Subject: [PATCH 015/153] Fixed incorrect reference and change to a link Signed-off-by: Anton Johansson --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce3ff604..f2861273 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ These Eclipse plugins are built with the Tycho Maven plugin. The marriage of OSGi, Eclipse, and Maven is imperfect. In particular, it rarely works to run a build that does not start with 'clean'. -See docs/release.md for information about how all of this is released. +See [doc/release.md](doc/release.md) for information about how all of this is released. Activity here is 'coordinated' on a mailing list: `m2e-code-quality@googlegroups.com`. From 8abb3a357a5d25313876dcb3e81069fce78f50f1 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 19 Feb 2016 18:56:45 +0100 Subject: [PATCH 016/153] Add checkstyle-7 test project --- .../checkstyle-7-child-project/pom.xml | 49 +++++++++++ .../java/iampartofthesuppressions/App.java | 9 ++ .../main/java/ishouldthrowanerror/App.java | 9 ++ test-projects/checkstyle-7/pom.xml | 82 +++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 test-projects/checkstyle-7/checkstyle-7-child-project/pom.xml create mode 100644 test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/iampartofthesuppressions/App.java create mode 100644 test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/ishouldthrowanerror/App.java create mode 100644 test-projects/checkstyle-7/pom.xml diff --git a/test-projects/checkstyle-7/checkstyle-7-child-project/pom.xml b/test-projects/checkstyle-7/checkstyle-7-child-project/pom.xml new file mode 100644 index 00000000..cd0dac60 --- /dev/null +++ b/test-projects/checkstyle-7/checkstyle-7-child-project/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + com.basistech + checkstyle-7-parent-project + 0.0.1-SNAPSHOT + + + checkstyle-7-child-project + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + [2.17,) + + checkstyle + + + + + com.basistech.m2e.code.quality.checkstyleConfigurator + + + + + + + + + + + + diff --git a/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/iampartofthesuppressions/App.java b/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/iampartofthesuppressions/App.java new file mode 100644 index 00000000..79c93b6b --- /dev/null +++ b/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/iampartofthesuppressions/App.java @@ -0,0 +1,9 @@ +package iampartofthesuppressions; + +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} diff --git a/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/ishouldthrowanerror/App.java b/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/ishouldthrowanerror/App.java new file mode 100644 index 00000000..ce51bbbb --- /dev/null +++ b/test-projects/checkstyle-7/checkstyle-7-child-project/src/main/java/ishouldthrowanerror/App.java @@ -0,0 +1,9 @@ +package ishouldthrowanerror; + +public class App { + + public static void main(String[] args) { + System.out.println("Hello"); + } + +} diff --git a/test-projects/checkstyle-7/pom.xml b/test-projects/checkstyle-7/pom.xml new file mode 100644 index 00000000..a8d57fc2 --- /dev/null +++ b/test-projects/checkstyle-7/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.basistech + checkstyle-7-parent-project + pom + 0.0.1-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + ${project.groupId} + checkstyle-5-config + ${project.version} + + + + true + checkstyle.xml + checkstyle-suppressions.xml + + + + compile + + checkstyle + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + [2.17,) + + checkstyle + + + + + + + + + + + + + + + + checkstyle-7-child-project + + + From 4cad888c95af2a7b61cdd40280ba6afb6d189ecd Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:25:51 +0100 Subject: [PATCH 017/153] Remove trailing comment --- .../basistech/m2e/code/quality/shared/MavenPluginWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java index 52ed9edf..fe92bec4 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java @@ -62,7 +62,7 @@ public static List findMojoExecutions( // I don't think we need to re-search for site. return searchExecutions(pluginGroupId, pluginArtifactId, pluginGoal, mojoExecutions); - }// + } private static List searchExecutions( final String pluginGroupId, final String pluginArtifactId, From 34685efd0026577ae569dc921307b3d604ad8efd Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:26:03 +0100 Subject: [PATCH 018/153] Remove unnecessary catch block --- .../com/basistech/m2e/code/quality/shared/ResourceResolver.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 5d8212c1..1f58d52e 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -72,8 +72,6 @@ public URL resolveLocation(final String location) { // check if valid. url.openStream(); return url; - } catch (MalformedURLException ex) { - // ignored, try next } catch (Exception ex) { // ignored, try next } From 925196748f453e69b9f6cc7a0f3c137da35bca05 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:28:27 +0100 Subject: [PATCH 019/153] Catch IOException instead of Exception --- .../basistech/m2e/code/quality/shared/ResourceResolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 1f58d52e..52986450 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -17,6 +17,7 @@ package com.basistech.m2e.code.quality.shared; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -72,7 +73,7 @@ public URL resolveLocation(final String location) { // check if valid. url.openStream(); return url; - } catch (Exception ex) { + } catch (IOException ex) { // ignored, try next } From 1463c2b1843939965c8df230572590810c6f6476 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:36:17 +0100 Subject: [PATCH 020/153] Move array declaration to type --- .../checkstyle/EclipseCheckstyleConfigManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index 0bf2cf46..e665adb9 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -65,8 +65,8 @@ private void configureNature(final IProgressMonitor monitor) final IProject project = this.csNature.getProject(); // We have to explicitly add the nature. final IProjectDescription desc = project.getDescription(); - final String natures[] = desc.getNatureIds(); - final String newNatures[] = new String[natures.length + 1]; + final String[] natures = desc.getNatureIds(); + final String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = CheckstyleNature.NATURE_ID; desc.setNatureIds(newNatures); @@ -78,7 +78,7 @@ private void deconfigureNature(final IProgressMonitor monitor) // remove the nature itself, by resetting the nature list. final IProject project = this.csNature.getProject(); final IProjectDescription desc = project.getDescription(); - final String natures[] = desc.getNatureIds(); + final String[] natures = desc.getNatureIds(); final List newNaturesList = new ArrayList<>(); for (int i = 0; i < natures.length; i++) { if (!CheckstyleNature.NATURE_ID.equals(natures[i])) { @@ -86,7 +86,7 @@ private void deconfigureNature(final IProgressMonitor monitor) } } - final String newNatures[] = + final String[] newNatures = newNaturesList.toArray(new String[newNaturesList.size()]); desc.setNatureIds(newNatures); project.setDescription(desc, monitor); From 15c4f5784860405d4f736b0b5ce7934444d8e935 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:36:34 +0100 Subject: [PATCH 021/153] Use enhanced for loop --- .../quality/checkstyle/EclipseCheckstyleConfigManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index e665adb9..ac6eabd9 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -80,9 +80,9 @@ private void deconfigureNature(final IProgressMonitor monitor) final IProjectDescription desc = project.getDescription(); final String[] natures = desc.getNatureIds(); final List newNaturesList = new ArrayList<>(); - for (int i = 0; i < natures.length; i++) { - if (!CheckstyleNature.NATURE_ID.equals(natures[i])) { - newNaturesList.add(natures[i]); + for (String nature : natures) { + if (!CheckstyleNature.NATURE_ID.equals(nature)) { + newNaturesList.add(nature); } } From 19231617e7060c51b3ffcf676bd6d9b81665fc00 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:44:00 +0100 Subject: [PATCH 022/153] Remove empty newline --- .../code/quality/checkstyle/EclipseCheckstyleConfigManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index ac6eabd9..1027bc52 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -57,7 +57,6 @@ public void deconfigure(final IProgressMonitor monitor) this.deconfigureNature(monitor); // remove all eclipse checkstyle files. this.deleteEclipseFiles(monitor); - } private void configureNature(final IProgressMonitor monitor) From f31c2ea4196df8ef8ac758ea8937c24bff259f10 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:44:29 +0100 Subject: [PATCH 023/153] Use Arrays.copyOf --- .../quality/checkstyle/EclipseCheckstyleConfigManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index 1027bc52..a36c6dd8 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -20,6 +20,7 @@ import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_PREFS_FILE; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import net.sf.eclipsecs.core.nature.CheckstyleNature; @@ -65,8 +66,7 @@ private void configureNature(final IProgressMonitor monitor) // We have to explicitly add the nature. final IProjectDescription desc = project.getDescription(); final String[] natures = desc.getNatureIds(); - final String[] newNatures = new String[natures.length + 1]; - System.arraycopy(natures, 0, newNatures, 0, natures.length); + final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = CheckstyleNature.NATURE_ID; desc.setNatureIds(newNatures); project.setDescription(desc, monitor); From 43c80fd64078304e22a8a2db78be6471be22e0ca Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:45:06 +0100 Subject: [PATCH 024/153] Directly return created object --- .../quality/checkstyle/EclipseCheckstyleConfigManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index a36c6dd8..b77dabd0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -107,8 +107,6 @@ public static EclipseCheckstyleConfigManager newInstance( Preconditions.checkNotNull(project); final CheckstyleNature csNature = new CheckstyleNature(); csNature.setProject(project); - final EclipseCheckstyleConfigManager csNatureExtended = - new EclipseCheckstyleConfigManager(csNature); - return csNatureExtended; + return new EclipseCheckstyleConfigManager(csNature); } } From 4cc97633fead6e61acc88f6977b5fe73d1851006 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 12:49:18 +0100 Subject: [PATCH 025/153] Use isEmpty instead of size --- .../quality/findbugs/MavenPluginConfigurationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 65a354ba..965966a1 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -179,7 +179,7 @@ public void setBugCatagories(final UserPreferences prefs) List availableBugCategories = new LinkedList<>(DetectorFactoryCollection.instance() .getBugCategories()); - if (addBugCatagoriesList.size() > 0) { + if (!addBugCatagoriesList.isEmpty()) { for (String removeBugCategory : availableBugCategories) { pfs.removeCategory(removeBugCategory); } From 87f7df69adb5619772c41648888dd3c342c931df Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:10:41 +0100 Subject: [PATCH 026/153] Organize imports --- .../EclipseCheckstyleConfigManager.java | 4 ++-- .../EclipseCheckstyleProjectConfigurator.java | 18 +++++++------- .../MavenPluginConfigurationTranslator.java | 12 +++++----- .../pmd/EclipsePmdProjectConfigurator.java | 24 +++++++++---------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index b77dabd0..25eb3040 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -23,8 +23,6 @@ import java.util.Arrays; import java.util.List; -import net.sf.eclipsecs.core.nature.CheckstyleNature; - import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; @@ -33,6 +31,8 @@ import com.google.common.base.Preconditions; +import net.sf.eclipsecs.core.nature.CheckstyleNature; + /** * An extension of the {@code Checkstyle} class to add missing functionality. * diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index f3954f2d..df7bf49d 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -26,6 +26,15 @@ import java.util.Map; import java.util.Properties; +import org.apache.maven.execution.MavenSession; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.m2e.core.project.IMavenProjectFacade; + +import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; +import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; + import net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy; import net.sf.eclipsecs.core.config.ICheckConfiguration; import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet; @@ -36,15 +45,6 @@ import net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy; import net.sf.eclipsecs.core.util.CheckstylePluginException; -import org.apache.maven.execution.MavenSession; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.m2e.core.project.IMavenProjectFacade; - -import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; -import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; - /** */ public class EclipseCheckstyleProjectConfigurator extends diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index c987cc05..7f31a039 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -30,12 +30,6 @@ import java.util.Properties; import java.util.Set; -import net.sf.eclipsecs.core.config.ICheckConfiguration; -import net.sf.eclipsecs.core.projectconfig.FileMatchPattern; -import net.sf.eclipsecs.core.projectconfig.FileSet; -import net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy; -import net.sf.eclipsecs.core.util.CheckstylePluginException; - import org.apache.commons.lang.StringEscapeUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Resource; @@ -51,6 +45,12 @@ import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; import com.basistech.m2e.code.quality.shared.ResourceResolver; +import net.sf.eclipsecs.core.config.ICheckConfiguration; +import net.sf.eclipsecs.core.projectconfig.FileMatchPattern; +import net.sf.eclipsecs.core.projectconfig.FileSet; +import net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy; +import net.sf.eclipsecs.core.util.CheckstylePluginException; + /** * Utility class to get checkstyle plugin configuration. */ diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 94b627cf..9aa3ba0b 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -33,18 +33,6 @@ import java.util.List; import java.util.Set; -import net.sourceforge.pmd.PMDException; -import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.RuleSetFactory; -import net.sourceforge.pmd.RuleSetNotFoundException; -import net.sourceforge.pmd.RuleSetReferenceId; -import net.sourceforge.pmd.eclipse.plugin.PMDPlugin; -import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature; -import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties; -import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager; -import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException; -import net.sourceforge.pmd.eclipse.runtime.writer.WriterException; - import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.util.StringUtils; @@ -64,6 +52,18 @@ import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; import com.basistech.m2e.code.quality.shared.ResourceResolver; +import net.sourceforge.pmd.PMDException; +import net.sourceforge.pmd.RuleSet; +import net.sourceforge.pmd.RuleSetFactory; +import net.sourceforge.pmd.RuleSetNotFoundException; +import net.sourceforge.pmd.RuleSetReferenceId; +import net.sourceforge.pmd.eclipse.plugin.PMDPlugin; +import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature; +import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties; +import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager; +import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException; +import net.sourceforge.pmd.eclipse.runtime.writer.WriterException; + public class EclipsePmdProjectConfigurator extends AbstractMavenPluginProjectConfigurator { From a7b812b67fb53e89aa591abb67ce5953e86d3b8e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:21:02 +0100 Subject: [PATCH 027/153] Add newline at EOF --- .../com/basistech/m2e/code/quality/shared/package-info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/package-info.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/package-info.java index bc3cdc90..beda0f84 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/package-info.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/package-info.java @@ -1,4 +1,4 @@ /** *

Package to house utility classes for m2e extensions project.

*/ -package com.basistech.m2e.code.quality.shared; \ No newline at end of file +package com.basistech.m2e.code.quality.shared; From dd095a8196c1ac63b5f0932829fe52a229db7819 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:24:33 +0100 Subject: [PATCH 028/153] Indent throws declarations --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 4 ++-- .../checkstyle/MavenPluginConfigurationTranslator.java | 6 +++--- .../findbugs/EclipseFindbugsProjectConfigurator.java | 4 ++-- .../code/quality/pmd/EclipsePmdProjectConfigurator.java | 8 ++++---- .../quality/pmd/MavenPluginConfigurationTranslator.java | 2 +- .../shared/AbstractMavenPluginProjectConfigurator.java | 4 ++-- .../m2e/code/quality/shared/MavenPluginWrapper.java | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index df7bf49d..e644825f 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -135,7 +135,7 @@ protected void unconfigureEclipsePlugin(final IProject project, private void buildCheckstyleConfiguration( ProjectConfigurationWorkingCopy pcWorkingCopy, final MavenPluginConfigurationTranslator cfgTranslator) - throws CheckstylePluginException, CoreException { + throws CheckstylePluginException, CoreException { // get the ruleset from configLocation final URL ruleset = cfgTranslator.getRuleset(); // build or get the checkconfig @@ -182,7 +182,7 @@ private void buildCheckstyleConfiguration( private ICheckConfiguration createOrGetCheckstyleConfig( final ProjectConfigurationWorkingCopy pcWorkingCopy, final URL ruleset, String executionId) - throws CheckstylePluginException { + throws CheckstylePluginException { final ICheckConfigurationWorkingSet workingSet = pcWorkingCopy.getLocalCheckConfigWorkingSet(); diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 7f31a039..7e297850 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -157,7 +157,7 @@ public String getSuppressionsFileExpression() public void updateCheckConfigWithIncludeExcludePatterns( final ProjectConfigurationWorkingCopy pcWorkingCopy, final ICheckConfiguration checkCfg) - throws CheckstylePluginException, CoreException { + throws CheckstylePluginException, CoreException { final FileSet fs = new FileSet("java-sources-" + getExecutionId(), checkCfg); fs.setEnabled(true); @@ -487,7 +487,7 @@ private String convertToEclipseCheckstyleRegExpPath(final String path) { private List normalizePatternsToCheckstyleFileMatchPattern( final List patterns, final String relativePath, final boolean setIsIncludePatternFlag) - throws CheckstylePluginException { + throws CheckstylePluginException { List fileMatchPatterns = new LinkedList<>(); for (String p : patterns) { @@ -645,7 +645,7 @@ public static List newInstance( final MavenProject mavenProject, final MavenPluginWrapper mavenPlugin, final IProject project, final IProgressMonitor monitor, MavenSession session) - throws CoreException { + throws CoreException { final List m2csConverters = new ArrayList<>(); for (final MojoExecution execution : mavenPlugin.getMojoExecutions()) { diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 81328b4a..739d6824 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -71,7 +71,7 @@ protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException { + throws CoreException { log.debug("entering handleProjectConfigurationChange"); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists() @@ -116,7 +116,7 @@ protected void unconfigureEclipsePlugin(final IProject project, private UserPreferences buildFindbugsPreferences( final MavenPluginConfigurationTranslator pluginCfgTranslator) - throws CoreException { + throws CoreException { log.debug("entering buildFindbugsPreferences"); final UserPreferences prefs = UserPreferences.createDefaultUserPreferences(); diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 9aa3ba0b..604e94a6 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -96,7 +96,7 @@ protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException { + throws CoreException { final MojoExecution execution = findMojoExecution(mavenPluginWrapper); MojoExecution pmdGoalExecution = @@ -182,7 +182,7 @@ private void createOrUpdateEclipsePmdConfiguration( final MavenPluginWrapper pluginWrapper, final IProject project, final MavenPluginConfigurationTranslator pluginCfgTranslator, final IProgressMonitor monitor, MavenSession session) - throws CoreException { + throws CoreException { final MojoExecution execution = findMojoExecution(pluginWrapper); ResourceResolver resourceResolver = @@ -221,7 +221,7 @@ private void createOrUpdateEclipsePmdConfiguration( private RuleSet createPmdRuleSet( final MavenPluginConfigurationTranslator pluginCfgTranslator, final ResourceResolver resourceResolver) throws CoreException, - PMDException { + PMDException { final RuleSet ruleSet = new RuleSet(); ruleSet.setName("M2Eclipse PMD RuleSet"); @@ -249,7 +249,7 @@ private RuleSet createPmdRuleSet( @Override public InputStream getInputStream(ClassLoader arg0) - throws RuleSetNotFoundException { + throws RuleSetNotFoundException { try { return resolvedLocation.openStream(); } catch (IOException e) { diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java index ae5aac56..6a38cd68 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java @@ -64,7 +64,7 @@ private MavenPluginConfigurationTranslator( final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, MojoExecution pmdGoalExecution, final IProject project, IProgressMonitor monitor) - throws CoreException { + throws CoreException { this.mavenProject = mavenProject; this.project = project; this.monitor = monitor; diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 698661fc..c03a1a40 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -141,7 +141,7 @@ protected abstract void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException; + throws CoreException; /** * Get the maven plugin {@code groupId}. @@ -195,7 +195,7 @@ protected abstract void unconfigureEclipsePlugin(final IProject project, private boolean checkUnconfigurationRequired(IProgressMonitor monitor, final IMavenProjectFacade curMavenProjectFacade, final IMavenProjectFacade oldMavenProjectFacade) - throws CoreException { + throws CoreException { Preconditions.checkNotNull(curMavenProjectFacade); if (oldMavenProjectFacade == null) { diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java index fe92bec4..451bed01 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java @@ -90,7 +90,7 @@ private static List searchExecutions( public static MavenPluginWrapper newInstance(IProgressMonitor monitor, final String pluginGroupId, final String pluginArtifactId, final String[] pluginGoal, IMavenProjectFacade mavenProjectFacade) - throws CoreException { + throws CoreException { Preconditions.checkNotNull(mavenProjectFacade); final List executions = findMojoExecutions(monitor, mavenProjectFacade, pluginGroupId, From 45ad3a1953dcb4ecf430ef9eeb25cba45f8ef4da Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:54:26 +0100 Subject: [PATCH 029/153] Use URI's resolve since all we resolve are local directories --- .../code/quality/pmd/MavenPluginConfigurationTranslator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java index 6a38cd68..09844253 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; -import org.apache.http.client.utils.URIUtils; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; @@ -275,8 +274,7 @@ private List convertFileFoldersToRelativePathStrings( String relativePath; if (!f.isAbsolute()) { relativePath = - URIUtils.resolve(this.basedirUri, f.toURI()).getPath(); - // TODO this.basedirUri.relativize(f.toURI()).getPath(); + this.basedirUri.resolve(f.toURI()).getPath(); } else { relativePath = f.getAbsolutePath(); } From 11ef84b88288180715320fab21e649c4a69cd118 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:54:47 +0100 Subject: [PATCH 030/153] Remove URIUtils --- .../META-INF/MANIFEST.MF | 3 +- .../apache/http/client/utils/URIUtils.java | 270 ------------------ 2 files changed, 1 insertion(+), 272 deletions(-) delete mode 100644 com.basistech.m2e.code.quality.shared/src/main/java/org/apache/http/client/utils/URIUtils.java diff --git a/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF b/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF index b492dc7a..5186c4ed 100644 --- a/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF +++ b/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF @@ -9,8 +9,7 @@ Bundle-Vendor: BasisTech Export-Package: com.basistech.m2e.code.quality.shared, com.google.common.annotations, com.google.common.base, - com.google.common.collect, - org.apache.http.client.utils + com.google.common.collect Bundle-ClassPath: ., lib/google-collections-1.0.jar Require-Bundle: org.eclipse.m2e.jdt;bundle-version="[1.0.0,1.8.0)", diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/org/apache/http/client/utils/URIUtils.java b/com.basistech.m2e.code.quality.shared/src/main/java/org/apache/http/client/utils/URIUtils.java deleted file mode 100644 index 1205638e..00000000 --- a/com.basistech.m2e.code.quality.shared/src/main/java/org/apache/http/client/utils/URIUtils.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * ==================================================================== - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - */ - -package org.apache.http.client.utils; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Stack; - -//import org.apache.http.annotation.Immutable; -// -//import org.apache.http.HttpHost; - -/** - * A collection of utilities for {@link URI URIs}, to workaround bugs within the - * class or for ease-of-use features. - * - * @since 4.0 - */ -// @Immutable -public class URIUtils { - - /** - * @param scheme - * Scheme name - * @param host - * Host name - * @param port - * Port number - * @param path - * Path - * @param query - * Query - * @param fragment - * Fragment - * @return a {@link URI} using all the parameters. This should be used - * instead of - * {@link URI#URI(String, String, String, int, String, String, String)} - * or any of the other URI multi-argument URI constructors. - * - * @throws URISyntaxException - * If both a scheme and a path are given but the path is - * relative, if the URI string constructed from the given - * components violates RFC 2396, or if the authority - * component of the string is present but cannot be parsed as a - * server-based authority - */ - public static URI createURI(final String scheme, final String host, - int port, final String path, final String query, - final String fragment) throws URISyntaxException { - - StringBuilder buffer = new StringBuilder(); - if (host != null) { - if (scheme != null) { - buffer.append(scheme); - buffer.append("://"); - } - buffer.append(host); - if (port > 0) { - buffer.append(':'); - buffer.append(port); - } - } - if (path == null || !path.startsWith("/")) { - buffer.append('/'); - } - if (path != null) { - buffer.append(path); - } - if (query != null) { - buffer.append('?'); - buffer.append(query); - } - if (fragment != null) { - buffer.append('#'); - buffer.append(fragment); - } - return new URI(buffer.toString()); - } - - /** - * A convenience method for creating a new {@link URI} whose scheme, host - * and port are taken from the target host, but whose path, query and - * fragment are taken from the existing URI. The fragment is only used if - * dropFragment is false. - * - * @param uri - * Contains the path, query and fragment to use. - * @param target - * Contains the scheme, host and port to use. - * @param dropFragment - * True if the fragment should not be copied. - * - * @throws URISyntaxException - * If the resulting URI is invalid. - */ - // public static URI rewriteURI( - // final URI uri, - // final HttpHost target, - // boolean dropFragment) throws URISyntaxException { - // if (uri == null) { - // throw new IllegalArgumentException("URI may nor be null"); - // } - // if (target != null) { - // return URIUtils.createURI( - // target.getSchemeName(), - // target.getHostName(), - // target.getPort(), - // uri.getRawPath(), - // uri.getRawQuery(), - // dropFragment ? null : uri.getRawFragment()); - // } else { - // return URIUtils.createURI( - // null, - // null, - // -1, - // uri.getRawPath(), - // uri.getRawQuery(), - // dropFragment ? null : uri.getRawFragment()); - // } - // } - - /** - * A convenience method for - * {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the - * fragment. - */ - // public static URI rewriteURI( - // final URI uri, - // final HttpHost target) throws URISyntaxException { - // return rewriteURI(uri, target, false); - // } - - /** - * Resolves a URI reference against a base URI. Work-around for bug in - * java.net.URI - * () - * - * @param baseURI - * the base URI - * @param reference - * the URI reference - * @return the resulting URI - */ - public static URI resolve(final URI baseURI, final String reference) { - return URIUtils.resolve(baseURI, URI.create(reference)); - } - - /** - * Resolves a URI reference against a base URI. Work-around for bugs in - * java.net.URI (e.g. - * ) - * - * @param baseURI - * the base URI - * @param reference - * the URI reference - * @return the resulting URI - */ - public static URI resolve(final URI baseURI, URI reference) { - if (baseURI == null) { - throw new IllegalArgumentException("Base URI may nor be null"); - } - if (reference == null) { - throw new IllegalArgumentException("Reference URI may nor be null"); - } - String s = reference.toString(); - if (s.startsWith("?")) { - return resolveReferenceStartingWithQueryString(baseURI, reference); - } - boolean emptyReference = s.length() == 0; - if (emptyReference) { - reference = URI.create("#"); - } - URI resolved = baseURI.resolve(reference); - if (emptyReference) { - String resolvedString = resolved.toString(); - resolved = - URI.create(resolvedString.substring(0, - resolvedString.indexOf('#'))); - } - return removeDotSegments(resolved); - } - - /** - * Resolves a reference starting with a query string. - * - * @param baseURI - * the base URI - * @param reference - * the URI reference starting with a query string - * @return the resulting URI - */ - private static URI resolveReferenceStartingWithQueryString( - final URI baseURI, final URI reference) { - String baseUri = baseURI.toString(); - baseUri = - baseUri.indexOf('?') > -1 ? baseUri.substring(0, - baseUri.indexOf('?')) : baseUri; - return URI.create(baseUri + reference.toString()); - } - - /** - * Removes dot segments according to RFC 3986, section 5.2.4 - * - * @param uri - * the original URI - * @return the URI without dot segments - */ - private static URI removeDotSegments(URI uri) { - String path = uri.getPath(); - if (path == null || path.indexOf("/.") == -1) { - // No dot segments to remove - return uri; - } - String[] inputSegments = path.split("/"); - Stack outputSegments = new Stack<>(); - for (String inputSegment : inputSegments) { - if (inputSegment.length() == 0 || ".".equals(inputSegment)) { - // Do nothing - } else if ("..".equals(inputSegment)) { - if (!outputSegments.isEmpty()) { - outputSegments.pop(); - } - } else { - outputSegments.push(inputSegment); - } - } - StringBuilder outputBuffer = new StringBuilder(); - for (String outputSegment : outputSegments) { - outputBuffer.append('/').append(outputSegment); - } - try { - return new URI(uri.getScheme(), uri.getAuthority(), - outputBuffer.toString(), uri.getQuery(), uri.getFragment()); - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e); - } - } - - /** - * This class should not be instantiated. - */ - private URIUtils() { - } - -} From 344d25c2f311cff7b6e491a0975eedc1d01a314f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:55:19 +0100 Subject: [PATCH 031/153] Remove comment --- .../basistech/m2e/code/quality/pmd/PmdEclipseConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java index 59bb7bce..526649ff 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java @@ -27,8 +27,8 @@ public final class PmdEclipseConstants { "org.apache.maven.plugins"; public static final String MAVEN_PLUGIN_ARTIFACTID = "maven-pmd-plugin"; - public static final String PMD_RULESET_FILE = ".pmdruleset.xml"; // must end - // with xml + public static final String PMD_RULESET_FILE = ".pmdruleset.xml"; + public static final String PMD_SETTINGS_FILE = ".pmd"; public static final String PLUGIN_ID = FrameworkUtil.getBundle( From 729c77bd96a00e2461d4e2fef8fa2e0429f9e495 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:55:42 +0100 Subject: [PATCH 032/153] Correct indentation --- .../quality/findbugs/EclipseFindbugsProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 739d6824..26500152 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -75,7 +75,7 @@ protected void handleProjectConfigurationChange( log.debug("entering handleProjectConfigurationChange"); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists() - || !javaProject.getProject().isOpen()) { + || !javaProject.getProject().isOpen()) { return; } final MavenPluginConfigurationTranslator mavenFindbugsConfig = From 5638850017e9b0abda29bc056f66dab6d9cf26f2 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:56:00 +0100 Subject: [PATCH 033/153] Add newline before static block --- .../java/com/basistech/m2e/code/quality/checkstyle/Messages.java | 1 + 1 file changed, 1 insertion(+) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Messages.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Messages.java index a006015e..8591dbdc 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Messages.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Messages.java @@ -7,6 +7,7 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "com.basistech.m2e.code.quality.checkstyle.messages"; //$NON-NLS-1$ public static String EclipseCheckstylereferencePage_0; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); From ffd92916dd5792e53a4cb154347eec6fd1d51b42 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:57:36 +0100 Subject: [PATCH 034/153] Replace javadoc comment with single line comment --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index e644825f..a9e984c1 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -145,9 +145,7 @@ private void buildCheckstyleConfiguration( // update filesets (include and exclude patterns) cfgTranslator.updateCheckConfigWithIncludeExcludePatterns( pcWorkingCopy, checkCfg); - /** - * 2. Load all properties - */ + // 2. Load all properties // get Properties from propertiesLocation final Properties props = cfgTranslator.getConfiguredProperties(); cfgTranslator.updatePropertiesWithPropertyExpansion(props); From 8d89b31b1c4ed2d64fb4e18239f733c50b439bd1 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 13:58:49 +0100 Subject: [PATCH 035/153] Format with line length set to 100 --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 3 ++- .../checkstyle/MavenPluginConfigurationTranslator.java | 9 ++++++--- .../quality/findbugs/EclipseFindbugsConfigManager.java | 3 ++- .../findbugs/EclipseFindbugsProjectConfigurator.java | 3 ++- .../findbugs/MavenPluginConfigurationTranslator.java | 3 ++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index a9e984c1..0eb59ad6 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -76,7 +76,8 @@ protected String[] getMavenPluginGoal() { protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, - final MavenPluginWrapper mavenPluginWrapper, MavenSession session) throws CoreException { + final MavenPluginWrapper mavenPluginWrapper, MavenSession session) + throws CoreException { final List mavenCheckstyleConfigs = MavenPluginConfigurationTranslator.newInstance(this, diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 7e297850..f090a195 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -98,7 +98,8 @@ public URL getRuleset() throws CheckstylePluginException, CoreException { this.resourceResolver.resolveLocation(this.getConfigLocation()); if (ruleset == null) { throw new CheckstylePluginException( - String.format("Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration")); + String.format( + "Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration")); } return ruleset; } @@ -291,7 +292,8 @@ private List getSourceDirectories() throws CoreException { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = configurator.getParameterValue(mavenProject, "sourceDirectories", List.class, execution, monitor); + List sourceDirectories = configurator.getParameterValue(mavenProject, + "sourceDirectories", List.class, execution, monitor); if (sourceDirectories != null) { result.addAll(sourceDirectories); } @@ -306,7 +308,8 @@ private List getTestSourceDirectories() throws CoreException { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = configurator.getParameterValue(mavenProject, "testSourceDirectories", List.class, execution, monitor); + List sourceDirectories = configurator.getParameterValue(mavenProject, + "testSourceDirectories", List.class, execution, monitor); if (sourceDirectories != null) { result.addAll(sourceDirectories); } diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index c203bdbb..193aaa30 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -42,7 +42,8 @@ public class EclipseFindbugsConfigManager { private static final Logger log = LoggerFactory - .getLogger("com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager"); + .getLogger( + "com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager"); private final FindBugsNature fbNature; diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 26500152..13e4358e 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -45,7 +45,8 @@ public class EclipseFindbugsProjectConfigurator extends private static final Logger log = LoggerFactory - .getLogger("com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator"); + .getLogger( + "com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator"); public EclipseFindbugsProjectConfigurator() { super(); diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 965966a1..76f05297 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -74,7 +74,8 @@ public class MavenPluginConfigurationTranslator { private static final Logger log = LoggerFactory - .getLogger("com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator"); + .getLogger( + "com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator"); private final IProject project; private final AbstractMavenPluginProjectConfigurator configurator; private final ResourceResolver resourceResolver; From 237030895cf451cc1f6a59c60d36cf3f899fab2e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:19:22 +0100 Subject: [PATCH 036/153] Use Preconditions instead of if-check --- .../checkstyle/MavenPluginConfigurationTranslator.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index f090a195..cbf904bc 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -44,6 +44,7 @@ import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; import com.basistech.m2e.code.quality.shared.ResourceResolver; +import com.google.common.base.Preconditions; import net.sf.eclipsecs.core.config.ICheckConfiguration; import net.sf.eclipsecs.core.projectconfig.FileMatchPattern; @@ -548,12 +549,8 @@ private List getPatterns(String elemName) throws CoreException { * @return the converted checkstyle eclipse pattern. */ private String convertAntStylePatternToCheckstylePattern(String pattern) { - if (pattern == null) { - throw new NullPointerException("pattern cannot be null"); - } - if (pattern.length() == 0) { - throw new IllegalArgumentException("pattern cannot empty"); - } + Preconditions.checkNotNull(pattern, "pattern cannot be null"); + Preconditions.checkArgument(pattern.isEmpty(), "pattern cannot empty"); pattern = pattern.replace(File.separatorChar == '/' ? '\\' : '/', From 48d8bf7013bf6260939e7bdb25c3aee3ea947200 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:25:50 +0100 Subject: [PATCH 037/153] Use uppercase LOG everywhere --- .../EclipseFindbugsConfigManager.java | 17 ++++---- .../EclipseFindbugsProjectConfigurator.java | 16 ++++---- .../MavenPluginConfigurationTranslator.java | 41 +++++++++---------- .../pmd/EclipsePmdProjectConfigurator.java | 9 ++-- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index 193aaa30..6735d50b 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -40,10 +40,7 @@ */ public class EclipseFindbugsConfigManager { - private static final Logger log = - LoggerFactory - .getLogger( - "com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager"); + private static final Logger LOG = LoggerFactory.getLogger(EclipseFindbugsConfigManager.class); private final FindBugsNature fbNature; @@ -52,7 +49,7 @@ private EclipseFindbugsConfigManager(final FindBugsNature fbNature) { } public void configure(final IProgressMonitor monitor) throws CoreException { - log.debug("entering configure"); + LOG.debug("entering configure"); // this adds the builder only. this.fbNature.configure(); this.configureNature(monitor); @@ -60,7 +57,7 @@ public void configure(final IProgressMonitor monitor) throws CoreException { public void deconfigure(final IProgressMonitor monitor) throws CoreException { - log.debug("entering deconfigure"); + LOG.debug("entering deconfigure"); // this removes the builder only. this.fbNature.deconfigure(); this.deconfigureNature(monitor); @@ -71,7 +68,7 @@ public void deconfigure(final IProgressMonitor monitor) private void configureNature(final IProgressMonitor monitor) throws CoreException { - log.debug("entering configureNature"); + LOG.debug("entering configureNature"); final IProject project = this.fbNature.getProject(); // We have to explicitly add the nature. final IProjectDescription desc = project.getDescription(); @@ -85,7 +82,7 @@ private void configureNature(final IProgressMonitor monitor) private void deconfigureNature(final IProgressMonitor monitor) throws CoreException { - log.debug("entering deconfigureNature"); + LOG.debug("entering deconfigureNature"); // remove the nature itself, by resetting the nature list. final IProject project = this.fbNature.getProject(); final IProjectDescription desc = project.getDescription(); @@ -105,7 +102,7 @@ private void deconfigureNature(final IProgressMonitor monitor) private void deleteEclipseFiles(final IProgressMonitor monitor) throws CoreException { - log.debug("entering deleteEclipseFiles"); + LOG.debug("entering deleteEclipseFiles"); final IProject project = this.fbNature.getProject(); final IResource findbugsFile = project.getFile(ECLIPSE_FB_PREFS_FILE); findbugsFile.delete(IResource.FORCE, monitor); @@ -114,7 +111,7 @@ private void deleteEclipseFiles(final IProgressMonitor monitor) public static EclipseFindbugsConfigManager newInstance( final IProject project) { - log.debug("entering newInstance"); + LOG.debug("entering newInstance"); Preconditions.checkNotNull(project); final FindBugsNature fbNature = new FindBugsNature(); fbNature.setProject(project); diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 13e4358e..f1fee324 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -43,10 +43,8 @@ public class EclipseFindbugsProjectConfigurator extends AbstractMavenPluginProjectConfigurator { - private static final Logger log = - LoggerFactory - .getLogger( - "com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator"); + private static final Logger LOG = + LoggerFactory.getLogger(EclipseFindbugsProjectConfigurator.class); public EclipseFindbugsProjectConfigurator() { super(); @@ -73,7 +71,7 @@ protected void handleProjectConfigurationChange( final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper, MavenSession session) throws CoreException { - log.debug("entering handleProjectConfigurationChange"); + LOG.debug("entering handleProjectConfigurationChange"); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists() || !javaProject.getProject().isOpen()) { @@ -89,7 +87,7 @@ protected void handleProjectConfigurationChange( final List mojoExecutions = mavenPluginWrapper.getMojoExecutions(); if (mojoExecutions.size() != 1) { - log.error("Wrong number of executions. Expected 1. Found " + LOG.error("Wrong number of executions. Expected 1. Found " + mojoExecutions.size()); return; } @@ -101,14 +99,14 @@ protected void handleProjectConfigurationChange( FindbugsPlugin.saveUserPreferences(project, prefs); FindbugsPlugin.setProjectSettingsEnabled(project, null, true); } catch (final CoreException ex) { - log.error(ex.getLocalizedMessage()); + LOG.error(ex.getLocalizedMessage()); } } @Override protected void unconfigureEclipsePlugin(final IProject project, final IProgressMonitor monitor) throws CoreException { - log.debug("entering unconfigureEclipsePlugin"); + LOG.debug("entering unconfigureEclipsePlugin"); final EclipseFindbugsConfigManager fbPluginNature = EclipseFindbugsConfigManager.newInstance(project); fbPluginNature.deconfigure(monitor); @@ -118,7 +116,7 @@ protected void unconfigureEclipsePlugin(final IProject project, private UserPreferences buildFindbugsPreferences( final MavenPluginConfigurationTranslator pluginCfgTranslator) throws CoreException { - log.debug("entering buildFindbugsPreferences"); + LOG.debug("entering buildFindbugsPreferences"); final UserPreferences prefs = UserPreferences.createDefaultUserPreferences(); pluginCfgTranslator.setIncludeFilterFiles(prefs); diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 76f05297..38614e01 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -72,10 +72,9 @@ */ public class MavenPluginConfigurationTranslator { - private static final Logger log = - LoggerFactory - .getLogger( - "com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator"); + private static final Logger LOG = + LoggerFactory.getLogger(MavenPluginConfigurationTranslator.class); + private final IProject project; private final AbstractMavenPluginProjectConfigurator configurator; private final ResourceResolver resourceResolver; @@ -103,7 +102,7 @@ public void setIncludeFilterFiles(final UserPreferences prefs) INCLUDE_FILTER_FILE, String.class, execution, monitor); // don't do anything if null if (includeFilterFile == null) { - log.debug("includeFilterFile is null"); + LOG.debug("includeFilterFile is null"); return; } this.copyUrlResourceToProject(includeFilterFile, FB_INCLUDE_FILTER_FILE); @@ -121,13 +120,13 @@ public void setIncludeFilterFiles(final UserPreferences prefs) public void setExcludeFilterFiles(final UserPreferences prefs) throws CoreException { - log.debug("entering setExcludeFilterFiles"); + LOG.debug("entering setExcludeFilterFiles"); final String excludeFilterFile = this.configurator.getParameterValue(mavenProject, EXCLUDE_FILTER_FILE, String.class, execution, monitor); // don't do anything if null if (excludeFilterFile == null) { - log.debug("excludeFilterFile is null"); + LOG.debug("excludeFilterFile is null"); return; } this.copyUrlResourceToProject(excludeFilterFile, FB_EXCLUDE_FILTER_FILE); @@ -172,7 +171,7 @@ public void setBugCatagories(final UserPreferences prefs) this.configurator.getParameterValue(mavenProject, BUG_CATEGORIES, String.class, execution, monitor); if (bugCatagories == null) { - log.debug("bugCatagories is null"); + LOG.debug("bugCatagories is null"); return; } List addBugCatagoriesList = @@ -191,7 +190,7 @@ public void setBugCatagories(final UserPreferences prefs) if (availableBugCategories.contains(bcUpper)) { pfs.addCategory(bcUpper); } else { - log.debug(String.format("[%s]: Unknown Bug Catagory [%s]", + LOG.debug(String.format("[%s]: Unknown Bug Catagory [%s]", LOG_PREFIX, bc)); } if (pfs.getActiveCategorySet().contains(bcUpper)) { @@ -210,7 +209,7 @@ public void setEffort(final UserPreferences prefs) throws CoreException { this.configurator.getParameterValue(mavenProject, EFFORT, String.class, execution, monitor); if (effort == null) { - log.debug("effort is null"); + LOG.debug("effort is null"); return; } // lowercase @@ -218,7 +217,7 @@ public void setEffort(final UserPreferences prefs) throws CoreException { try { prefs.setEffort(effort); } catch (final IllegalArgumentException ex) { - log.error(String + LOG.error(String .format("[%s]: could not set , reason [%s], setting it to default [%s]", LOG_PREFIX, effort, UserPreferences.EFFORT_DEFAULT)); } @@ -229,13 +228,13 @@ public void setMinRank(final UserPreferences prefs) throws CoreException { this.configurator.getParameterValue(mavenProject, MAX_RANK, Integer.class, execution, monitor); if (minRank == null) { - log.debug("max rank is null"); + LOG.debug("max rank is null"); return; } try { prefs.getFilterSettings().setMinRank(minRank); } catch (final IllegalArgumentException ex) { - log.error(String + LOG.error(String .format("[%s]: could not set , reason [%s], setting it to default [%s]", LOG_PREFIX, minRank, 15)); } @@ -246,13 +245,13 @@ public void setPriority(final UserPreferences prefs) throws CoreException { this.configurator.getParameterValue(mavenProject, PRIORITY, String.class, execution, monitor); if (priority == null) { - log.debug("priority is null"); + LOG.debug("priority is null"); return; } try { prefs.getFilterSettings().setMinPriority(priority); } catch (final Exception ex) { - log.error(String + LOG.error(String .format("[%s]: could not set , reason [%s], leaving it alone", LOG_PREFIX, priority)); } @@ -264,7 +263,7 @@ public void setOmitVisitors(final UserPreferences prefs) this.configurator.getParameterValue(mavenProject, OMIT_VISITORS, String.class, execution, monitor); if (omitVisitors == null) { - log.debug("omitVisitors is null"); + LOG.debug("omitVisitors is null"); return; } List detectorsList = @@ -274,7 +273,7 @@ public void setOmitVisitors(final UserPreferences prefs) for (String d : detectorsList) { final DetectorFactory df = dfc.getFactory(d); if (df == null) { - log.error(String.format("[%s]: IGNORING unknown detector [%s]", + LOG.error(String.format("[%s]: IGNORING unknown detector [%s]", LOG_PREFIX, d)); } else { prefs.enableDetector(df, false); @@ -287,13 +286,13 @@ public void setThreshold(final UserPreferences prefs) throws CoreException { this.configurator.getParameterValue(mavenProject, THRESHOLD, String.class, execution, monitor); if (threshold == null) { - log.debug("threshold is null"); + LOG.debug("threshold is null"); return; } try { prefs.getFilterSettings().setMinPriority(threshold); } catch (final Exception ex) { - log.error(String + LOG.error(String .format("[%s]: could not set , reason [%s], leaving it alone", LOG_PREFIX, threshold)); } @@ -314,7 +313,7 @@ public void setVisitors(final UserPreferences prefs) throws CoreException { for (String d : detectorsList) { final DetectorFactory df = dfc.getFactory(d); if (df == null) { - log.error(String.format("[%s]: IGNORING unknown detector [%s]", + LOG.error(String.format("[%s]: IGNORING unknown detector [%s]", LOG_PREFIX, d)); } else { prefs.enableDetector(df, true); @@ -342,7 +341,7 @@ public void setVisitors(final UserPreferences prefs) throws CoreException { */ private void copyUrlResourceToProject(final String resc, final String newLocation) { - log.debug("entering copyUrlResourceToProject"); + LOG.debug("entering copyUrlResourceToProject"); Preconditions.checkNotNull(resc); Preconditions.checkNotNull(newLocation); final URL urlResc = this.resourceResolver.resolveLocation(resc); diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 604e94a6..5dab0896 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -70,8 +70,7 @@ public class EclipsePmdProjectConfigurator extends // private static final String PMD_NATURE = // "net.sourceforge.pmd.eclipse.plugin.pmdNature"; private static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature"; - private static final Logger log = LoggerFactory - .getLogger(EclipsePmdProjectConfigurator.class); + private static final Logger LOG = LoggerFactory.getLogger(EclipsePmdProjectConfigurator.class); // create a rule set factory for instantiating rule sets private final RuleSetFactory factory = new RuleSetFactory(); @@ -140,7 +139,7 @@ private void addPMDNature(final IProject project, try { PMDNature.addPMDNature(project, monitor); } catch (CoreException pmdNatureProblem) { - log.error("PMD plugin threw exception adding PMD nature", + LOG.error("PMD plugin threw exception adding PMD nature", pmdNatureProblem); throw pmdNatureProblem; } @@ -255,7 +254,7 @@ public InputStream getInputStream(ClassLoader arg0) } catch (IOException e) { // ignore them. } - log.warn("No ruleset found for {}", loc); + LOG.warn("No ruleset found for {}", loc); return null; } }; @@ -263,7 +262,7 @@ public InputStream getInputStream(ClassLoader arg0) this.factory.createRuleSet(resolvedRuleSetReference); ruleSet.addRuleSet(ruleSetAtLocations); } catch (RuleSetNotFoundException e) { - log.error("Couldn't find ruleset {}", loc, e); + LOG.error("Couldn't find ruleset {}", loc, e); } } From 874a1454777c9a8f6c65987fae8c9e606a7fc0ea Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:30:07 +0100 Subject: [PATCH 038/153] Add slf4j api to manifest --- com.basistech.m2e.code.quality.checkstyle/META-INF/MANIFEST.MF | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/META-INF/MANIFEST.MF b/com.basistech.m2e.code.quality.checkstyle/META-INF/MANIFEST.MF index 91a90c57..f0190344 100644 --- a/com.basistech.m2e.code.quality.checkstyle/META-INF/MANIFEST.MF +++ b/com.basistech.m2e.code.quality.checkstyle/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.m2e.jdt;bundle-version="[1.0.0,1.8.0)", net.sf.eclipsecs.core;bundle-version="5.2.0", net.sf.eclipsecs.checkstyle;bundle-version="5.2.0", com.basistech.m2e.code.quality.shared;bundle-version="0.13.0", - org.apache.commons.lang;bundle-version="2.6.0" + org.apache.commons.lang;bundle-version="2.6.0", + org.slf4j.api;bundle-version="1.6.1" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Vendor: Basis Technology Corp. Import-Package: org.apache.commons.lang, From dd02669502659d60226b6cb7adff0c0e584f474d Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:32:08 +0100 Subject: [PATCH 039/153] Log exception --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 0eb59ad6..b40618d0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -31,6 +31,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; @@ -50,6 +52,9 @@ public class EclipseCheckstyleProjectConfigurator extends AbstractMavenPluginProjectConfigurator { + private static final Logger LOG = + LoggerFactory.getLogger(EclipseCheckstyleProjectConfigurator.class); + private final IConfigurationType remoteConfigurationType = ConfigurationTypes.getByInternalName("remote"); @@ -119,7 +124,7 @@ protected void handleProjectConfigurationChange( } } catch (CheckstylePluginException ex) { - // MavenLogger.log("CheckstylePluginException", ex); + LOG.error("CheckstylePluginException", ex); } } From b7ae37cb124d8fd8a3164f0881ac41073ffb6817 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:47:45 +0100 Subject: [PATCH 040/153] Move declaration to beginning of method --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index b40618d0..c3539cbe 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -187,7 +187,8 @@ private ICheckConfiguration createOrGetCheckstyleConfig( final ProjectConfigurationWorkingCopy pcWorkingCopy, final URL ruleset, String executionId) throws CheckstylePluginException { - + final String configName = + ECLIPSE_CS_PREFS_CONFIG_NAME + " " + executionId; final ICheckConfigurationWorkingSet workingSet = pcWorkingCopy.getLocalCheckConfigWorkingSet(); @@ -196,8 +197,6 @@ private ICheckConfiguration createOrGetCheckstyleConfig( // Try to retrieve an existing checkstyle configuration to be updated CheckConfigurationWorkingCopy[] workingCopies = workingSet.getWorkingCopies(); - final String configName = - ECLIPSE_CS_PREFS_CONFIG_NAME + " " + executionId; if (workingCopies != null) { for (CheckConfigurationWorkingCopy copy : workingCopies) { if (configName.equals(copy.getName())) { From f5adf9db4479ab8faf77d401d1c2e9edbb7915ad Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:48:23 +0100 Subject: [PATCH 041/153] Use ArrayUtils.nullToEmpty to reduce nesting --- .../EclipseCheckstyleProjectConfigurator.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index c3539cbe..93b18c87 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Properties; +import org.apache.commons.lang3.ArrayUtils; import org.apache.maven.execution.MavenSession; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -195,20 +196,18 @@ private ICheckConfiguration createOrGetCheckstyleConfig( CheckConfigurationWorkingCopy workingCopy = null; // Try to retrieve an existing checkstyle configuration to be updated - CheckConfigurationWorkingCopy[] workingCopies = - workingSet.getWorkingCopies(); - if (workingCopies != null) { - for (CheckConfigurationWorkingCopy copy : workingCopies) { - if (configName.equals(copy.getName())) { - if (this.remoteConfigurationType.equals(copy.getType())) { - workingCopy = copy; - break; - } - throw new CheckstylePluginException(String.format( - "A local Checkstyle configuration allready exists with name " - + " [%s] with incompatible type [%s]", - configName, copy.getType())); + CheckConfigurationWorkingCopy[] workingCopies = workingSet.getWorkingCopies(); + workingCopies = (CheckConfigurationWorkingCopy[]) ArrayUtils.nullToEmpty(workingCopies); + for (CheckConfigurationWorkingCopy copy : workingCopies) { + if (configName.equals(copy.getName())) { + if (this.remoteConfigurationType.equals(copy.getType())) { + workingCopy = copy; + break; } + throw new CheckstylePluginException(String.format( + "A local Checkstyle configuration already exists with name " + + " [%s] with incompatible type [%s]", + configName, copy.getType())); } } // Nothing exist create a brand new one. From 37478583d6ce236edee48decb5cf277e91840072 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:50:09 +0100 Subject: [PATCH 042/153] Do not reassign parameter --- .../MavenPluginConfigurationTranslator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index cbf904bc..166918b1 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -548,28 +548,28 @@ private List getPatterns(String elemName) throws CoreException { * the maven-checkstyle-plugin pattern. * @return the converted checkstyle eclipse pattern. */ - private String convertAntStylePatternToCheckstylePattern(String pattern) { + private String convertAntStylePatternToCheckstylePattern(final String pattern) { Preconditions.checkNotNull(pattern, "pattern cannot be null"); Preconditions.checkArgument(pattern.isEmpty(), "pattern cannot empty"); - pattern = + String sanitizedPattern = pattern.replace(File.separatorChar == '/' ? '\\' : '/', File.separatorChar); String dupeSeperatorChar = File.separator + File.separator; - while (pattern.contains(dupeSeperatorChar)) { - pattern = pattern.replace(dupeSeperatorChar, File.separator); + while (sanitizedPattern.contains(dupeSeperatorChar)) { + sanitizedPattern = sanitizedPattern.replace(dupeSeperatorChar, File.separator); } final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < pattern.length(); ++i) { - final char curChar = pattern.charAt(i); + for (int i = 0; i < sanitizedPattern.length(); ++i) { + final char curChar = sanitizedPattern.charAt(i); char nextChar = '\0'; char nextNextChar = '\0'; - if (i + 1 < pattern.length()) { - nextChar = pattern.charAt(i + 1); + if (i + 1 < sanitizedPattern.length()) { + nextChar = sanitizedPattern.charAt(i + 1); } - if (i + 2 < pattern.length()) { - nextNextChar = pattern.charAt(i + 2); + if (i + 2 < sanitizedPattern.length()) { + nextNextChar = sanitizedPattern.charAt(i + 2); } if (curChar == '*' && nextChar == '*' From 0e1e9c628cc8676f9b705d7862951425a16ae165 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:51:23 +0100 Subject: [PATCH 043/153] Reduce line length to 80 --- .../EclipseCheckstyleProjectConfigurator.java | 6 ++-- .../MavenPluginConfigurationTranslator.java | 31 ++++++++++++------- .../EclipseFindbugsConfigManager.java | 3 +- .../MavenPluginConfigurationTranslator.java | 9 ++++-- .../pmd/EclipsePmdProjectConfigurator.java | 6 ++-- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 93b18c87..c81bd169 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -196,8 +196,10 @@ private ICheckConfiguration createOrGetCheckstyleConfig( CheckConfigurationWorkingCopy workingCopy = null; // Try to retrieve an existing checkstyle configuration to be updated - CheckConfigurationWorkingCopy[] workingCopies = workingSet.getWorkingCopies(); - workingCopies = (CheckConfigurationWorkingCopy[]) ArrayUtils.nullToEmpty(workingCopies); + CheckConfigurationWorkingCopy[] workingCopies = + workingSet.getWorkingCopies(); + workingCopies = (CheckConfigurationWorkingCopy[]) ArrayUtils + .nullToEmpty(workingCopies); for (CheckConfigurationWorkingCopy copy : workingCopies) { if (configName.equals(copy.getName())) { if (this.remoteConfigurationType.equals(copy.getType())) { diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 166918b1..0ad735db 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -287,14 +287,16 @@ private String getSuppressionsLocation() throws CoreException { private List getSourceDirectories() throws CoreException { List result = new ArrayList<>(); - String sourceDirectory = configurator.getParameterValue(mavenProject, "sourceDirectory", - String.class, execution, monitor); + String sourceDirectory = + configurator.getParameterValue(mavenProject, "sourceDirectory", + String.class, execution, monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = configurator.getParameterValue(mavenProject, - "sourceDirectories", List.class, execution, monitor); + List sourceDirectories = + configurator.getParameterValue(mavenProject, + "sourceDirectories", List.class, execution, monitor); if (sourceDirectories != null) { result.addAll(sourceDirectories); } @@ -303,14 +305,17 @@ private List getSourceDirectories() throws CoreException { private List getTestSourceDirectories() throws CoreException { List result = new ArrayList<>(); - String sourceDirectory = configurator.getParameterValue(mavenProject, "testSourceDirectory", + String sourceDirectory = configurator.getParameterValue(mavenProject, + "testSourceDirectory", String.class, execution, monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = configurator.getParameterValue(mavenProject, - "testSourceDirectories", List.class, execution, monitor); + List sourceDirectories = + configurator.getParameterValue(mavenProject, + "testSourceDirectories", List.class, execution, + monitor); if (sourceDirectories != null) { result.addAll(sourceDirectories); } @@ -401,7 +406,8 @@ private List getIncludesExcludesFileMatchPatterns() .getPath(); patterns.addAll(this.normalizePatternsToCheckstyleFileMatchPattern( excludePatterns, - this.convertToEclipseCheckstyleRegExpPath(folderRelativePath), + this.convertToEclipseCheckstyleRegExpPath( + folderRelativePath), false)); } @@ -496,7 +502,8 @@ private List normalizePatternsToCheckstyleFileMatchPattern( new LinkedList<>(); for (String p : patterns) { final FileMatchPattern fmp = - new FileMatchPattern(String.format("%s%s", relativePath, p)); + new FileMatchPattern( + String.format("%s%s", relativePath, p)); fmp.setIsIncludePattern(setIsIncludePatternFlag); fileMatchPatterns.add(fmp); } @@ -548,7 +555,8 @@ private List getPatterns(String elemName) throws CoreException { * the maven-checkstyle-plugin pattern. * @return the converted checkstyle eclipse pattern. */ - private String convertAntStylePatternToCheckstylePattern(final String pattern) { + private String convertAntStylePatternToCheckstylePattern( + final String pattern) { Preconditions.checkNotNull(pattern, "pattern cannot be null"); Preconditions.checkArgument(pattern.isEmpty(), "pattern cannot empty"); @@ -557,7 +565,8 @@ private String convertAntStylePatternToCheckstylePattern(final String pattern) { File.separatorChar); String dupeSeperatorChar = File.separator + File.separator; while (sanitizedPattern.contains(dupeSeperatorChar)) { - sanitizedPattern = sanitizedPattern.replace(dupeSeperatorChar, File.separator); + sanitizedPattern = + sanitizedPattern.replace(dupeSeperatorChar, File.separator); } final StringBuilder sb = new StringBuilder(); diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index 6735d50b..dfd96551 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -40,7 +40,8 @@ */ public class EclipseFindbugsConfigManager { - private static final Logger LOG = LoggerFactory.getLogger(EclipseFindbugsConfigManager.class); + private static final Logger LOG = + LoggerFactory.getLogger(EclipseFindbugsConfigManager.class); private final FindBugsNature fbNature; diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 38614e01..88615729 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -105,7 +105,8 @@ public void setIncludeFilterFiles(final UserPreferences prefs) LOG.debug("includeFilterFile is null"); return; } - this.copyUrlResourceToProject(includeFilterFile, FB_INCLUDE_FILTER_FILE); + this.copyUrlResourceToProject(includeFilterFile, + FB_INCLUDE_FILTER_FILE); final Map curIncludeFilteredFiles = prefs.getIncludeFilterFiles(); final Map newIncludeFilteredFiles = @@ -129,7 +130,8 @@ public void setExcludeFilterFiles(final UserPreferences prefs) LOG.debug("excludeFilterFile is null"); return; } - this.copyUrlResourceToProject(excludeFilterFile, FB_EXCLUDE_FILTER_FILE); + this.copyUrlResourceToProject(excludeFilterFile, + FB_EXCLUDE_FILTER_FILE); final Map curExcludeFilteredFiles = prefs.getExcludeFilterFiles(); final Map newExcludeFilteredFiles = @@ -219,7 +221,8 @@ public void setEffort(final UserPreferences prefs) throws CoreException { } catch (final IllegalArgumentException ex) { LOG.error(String .format("[%s]: could not set , reason [%s], setting it to default [%s]", - LOG_PREFIX, effort, UserPreferences.EFFORT_DEFAULT)); + LOG_PREFIX, effort, + UserPreferences.EFFORT_DEFAULT)); } } diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 5dab0896..9e0dec4e 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -70,7 +70,8 @@ public class EclipsePmdProjectConfigurator extends // private static final String PMD_NATURE = // "net.sourceforge.pmd.eclipse.plugin.pmdNature"; private static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature"; - private static final Logger LOG = LoggerFactory.getLogger(EclipsePmdProjectConfigurator.class); + private static final Logger LOG = + LoggerFactory.getLogger(EclipsePmdProjectConfigurator.class); // create a rule set factory for instantiating rule sets private final RuleSetFactory factory = new RuleSetFactory(); @@ -189,7 +190,8 @@ private void createOrUpdateEclipsePmdConfiguration( project.getLocation()); try { final RuleSet ruleset = - this.createPmdRuleSet(pluginCfgTranslator, resourceResolver); + this.createPmdRuleSet(pluginCfgTranslator, + resourceResolver); this.buildAndAddPmdExcludeAndIncludePatternToRuleSet( pluginCfgTranslator, ruleset); From 7868519b8fe35b51d23cf00568da06fed0b61792 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:53:16 +0100 Subject: [PATCH 044/153] Format allowing joining existing wrapped lines --- .../EclipseCheckstyleProjectConfigurator.java | 26 +-- .../MavenPluginConfigurationTranslator.java | 197 ++++++++---------- ...lipseFindbugsProjectConfigurationTest.java | 4 +- .../EclipseFindbugsProjectConfigurator.java | 4 +- .../MavenPluginConfigurationTranslator.java | 103 ++++----- .../pmd/EclipsePmdProjectConfigurator.java | 68 +++--- .../MavenPluginConfigurationTranslator.java | 56 +++-- .../code/quality/pmd/PmdEclipseConstants.java | 4 +- ...bstractMavenPluginProjectConfigurator.java | 11 +- .../quality/shared/MavenPluginWrapper.java | 3 +- 10 files changed, 207 insertions(+), 269 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index c81bd169..ce28237e 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -50,8 +50,8 @@ /** */ -public class EclipseCheckstyleProjectConfigurator extends - AbstractMavenPluginProjectConfigurator { +public class EclipseCheckstyleProjectConfigurator + extends AbstractMavenPluginProjectConfigurator { private static final Logger LOG = LoggerFactory.getLogger(EclipseCheckstyleProjectConfigurator.class); @@ -100,12 +100,9 @@ protected void handleProjectConfigurationChange( ProjectConfigurationFactory .getConfiguration(project)); pcWorkingCopy.setUseSimpleConfig(false); - pcWorkingCopy - .setSyncFormatter(Activator - .getDefault() - .getPreferenceStore() - .getBoolean( - CheckstyleEclipseConstants.ECLIPSE_CS_GENERATE_FORMATTER_SETTINGS)); + pcWorkingCopy.setSyncFormatter( + Activator.getDefault().getPreferenceStore().getBoolean( + CheckstyleEclipseConstants.ECLIPSE_CS_GENERATE_FORMATTER_SETTINGS)); pcWorkingCopy.getFileSets().clear(); for (final MavenPluginConfigurationTranslator mavenCheckstyleConfig : mavenCheckstyleConfigs) { @@ -146,12 +143,11 @@ private void buildCheckstyleConfiguration( // get the ruleset from configLocation final URL ruleset = cfgTranslator.getRuleset(); // build or get the checkconfig - final ICheckConfiguration checkCfg = - this.createOrGetCheckstyleConfig(pcWorkingCopy, ruleset, - cfgTranslator.getExecutionId()); + final ICheckConfiguration checkCfg = this.createOrGetCheckstyleConfig( + pcWorkingCopy, ruleset, cfgTranslator.getExecutionId()); // update filesets (include and exclude patterns) - cfgTranslator.updateCheckConfigWithIncludeExcludePatterns( - pcWorkingCopy, checkCfg); + cfgTranslator.updateCheckConfigWithIncludeExcludePatterns(pcWorkingCopy, + checkCfg); // 2. Load all properties // get Properties from propertiesLocation final Properties props = cfgTranslator.getConfiguredProperties(); @@ -221,8 +217,8 @@ private ICheckConfiguration createOrGetCheckstyleConfig( workingSet.addCheckConfiguration(workingCopy); } - workingCopy.setDescription("maven-checkstyle-plugin configuration " - + executionId); + workingCopy.setDescription( + "maven-checkstyle-plugin configuration " + executionId); workingCopy.setLocation(ruleset.toExternalForm()); return workingCopy; } diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 0ad735db..9bab2db0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -62,8 +62,7 @@ public class MavenPluginConfigurationTranslator { private static final String CHECKSTYLE_DEFAULT_SUPPRESSIONS_FILE_EXPRESSION = "checkstyle.suppressions.file"; /** checkstyle maven plugin artifactId */ - private static final Map PATTERNS_CACHE = - new HashMap<>(); + private static final Map PATTERNS_CACHE = new HashMap<>(); private final MavenProject mavenProject; private final IProject project; @@ -88,9 +87,8 @@ private MavenPluginConfigurationTranslator( } public boolean isActive() throws CoreException { - Boolean isSkip = - configurator.getParameterValue(mavenProject, "skip", - Boolean.class, execution, monitor); + Boolean isSkip = configurator.getParameterValue(mavenProject, "skip", + Boolean.class, execution, monitor); return isSkip != null ? !isSkip : true; } @@ -98,15 +96,14 @@ public URL getRuleset() throws CheckstylePluginException, CoreException { final URL ruleset = this.resourceResolver.resolveLocation(this.getConfigLocation()); if (ruleset == null) { - throw new CheckstylePluginException( - String.format( - "Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration")); + throw new CheckstylePluginException(String.format( + "Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration")); } return ruleset; } - public String getHeaderFile() throws CheckstylePluginException, - CoreException { + public String getHeaderFile() + throws CheckstylePluginException, CoreException { final URL headerResource = this.resourceResolver.resolveLocation(getHeaderLocation()); if (headerResource == null) { @@ -114,16 +111,15 @@ public String getHeaderFile() throws CheckstylePluginException, } File outDir = project.getWorkingLocation(configurator.getId()).toFile(); - File headerFile = - new File(outDir, "checkstyle-header-" + getExecutionId() - + ".txt"); + File headerFile = new File(outDir, + "checkstyle-header-" + getExecutionId() + ".txt"); copyOut(headerResource, headerFile); return headerFile.getAbsolutePath(); } - public String getSuppressionsFile() throws CheckstylePluginException, - CoreException { + public String getSuppressionsFile() + throws CheckstylePluginException, CoreException { final String suppressionsLocation = getSuppressionsLocation(); if (suppressionsLocation == null) { return null; @@ -135,9 +131,8 @@ public String getSuppressionsFile() throws CheckstylePluginException, } File outDir = project.getWorkingLocation(configurator.getId()).toFile(); - File suppressionsFile = - new File(outDir, "checkstyle-suppressions-" + getExecutionId() - + ".xml"); + File suppressionsFile = new File(outDir, + "checkstyle-suppressions-" + getExecutionId() + ".xml"); copyOut(suppressionsResource, suppressionsFile); return suppressionsFile.getAbsolutePath(); @@ -145,10 +140,9 @@ public String getSuppressionsFile() throws CheckstylePluginException, public String getSuppressionsFileExpression() throws CheckstylePluginException, CoreException { - String suppressionsFileExpression = - configurator.getParameterValue(mavenProject, - "suppressionsFileExpression", String.class, execution, - monitor); + String suppressionsFileExpression = configurator.getParameterValue( + mavenProject, "suppressionsFileExpression", String.class, + execution, monitor); if (suppressionsFileExpression == null) { suppressionsFileExpression = CHECKSTYLE_DEFAULT_SUPPRESSIONS_FILE_EXPRESSION; @@ -191,8 +185,8 @@ protected String getPropertiesLocation() throws CoreException { * if an error occurs */ protected String getPropertyExpansion() throws CoreException { - return configurator.getParameterValue(mavenProject, - "propertyExpansion", String.class, execution, monitor); + return configurator.getParameterValue(mavenProject, "propertyExpansion", + String.class, execution, monitor); } /** @@ -204,10 +198,9 @@ protected String getPropertyExpansion() throws CoreException { * if an error occurs */ public boolean getIncludeTestSourceDirectory() throws CoreException { - Boolean includeTestSourceDirectory = - configurator.getParameterValue(mavenProject, - "includeTestSourceDirectory", Boolean.class, execution, - monitor); + Boolean includeTestSourceDirectory = configurator.getParameterValue( + mavenProject, "includeTestSourceDirectory", Boolean.class, + execution, monitor); if (includeTestSourceDirectory != null) { return includeTestSourceDirectory.booleanValue(); } else { @@ -217,8 +210,8 @@ public boolean getIncludeTestSourceDirectory() throws CoreException { public boolean getIncludeResourcesDirectory() throws CoreException { Boolean includeTestSourceDirectory = - configurator.getParameterValue(mavenProject, - "includeResources", Boolean.class, execution, monitor); + configurator.getParameterValue(mavenProject, "includeResources", + Boolean.class, execution, monitor); if (includeTestSourceDirectory != null) { return includeTestSourceDirectory.booleanValue(); } else { @@ -227,10 +220,9 @@ public boolean getIncludeResourcesDirectory() throws CoreException { } public boolean getIncludeTestResourcesDirectory() throws CoreException { - Boolean includeTestSourceDirectory = - configurator.getParameterValue(mavenProject, - "includeTestResources", Boolean.class, execution, - monitor); + Boolean includeTestSourceDirectory = configurator.getParameterValue( + mavenProject, "includeTestResources", Boolean.class, execution, + monitor); if (includeTestSourceDirectory != null) { return includeTestSourceDirectory.booleanValue(); } else { @@ -250,9 +242,8 @@ public String getExecutionId() { * @throws CoreException */ private String getConfigLocation() throws CoreException { - String configLocation = - configurator.getParameterValue(mavenProject, "configLocation", - String.class, execution, monitor); + String configLocation = configurator.getParameterValue(mavenProject, + "configLocation", String.class, execution, monitor); if (configLocation == null) { configLocation = CHECKSTYLE_DEFAULT_CONFIG_LOCATION; } @@ -261,9 +252,8 @@ private String getConfigLocation() throws CoreException { private String getHeaderLocation() throws CoreException { String configLocation = getConfigLocation(); - String headerLocation = - configurator.getParameterValue(mavenProject, "headerLocation", - String.class, execution, monitor); + String headerLocation = configurator.getParameterValue(mavenProject, + "headerLocation", String.class, execution, monitor); if ("config/maven_checks.xml".equals(configLocation) && "LICENSE.txt".equals(headerLocation)) { headerLocation = "config/maven-header.txt"; @@ -272,24 +262,20 @@ private String getHeaderLocation() throws CoreException { } private String getSuppressionsLocation() throws CoreException { - String suppressionsLocation = - configurator.getParameterValue(mavenProject, - "suppressionsLocation", String.class, execution, - monitor); + String suppressionsLocation = configurator.getParameterValue( + mavenProject, "suppressionsLocation", String.class, execution, + monitor); if (suppressionsLocation == null) { - suppressionsLocation = - configurator.getParameterValue(mavenProject, - "suppressionsFile", String.class, execution, - monitor); + suppressionsLocation = configurator.getParameterValue(mavenProject, + "suppressionsFile", String.class, execution, monitor); } return suppressionsLocation; } private List getSourceDirectories() throws CoreException { List result = new ArrayList<>(); - String sourceDirectory = - configurator.getParameterValue(mavenProject, "sourceDirectory", - String.class, execution, monitor); + String sourceDirectory = configurator.getParameterValue(mavenProject, + "sourceDirectory", String.class, execution, monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @@ -306,16 +292,14 @@ private List getSourceDirectories() throws CoreException { private List getTestSourceDirectories() throws CoreException { List result = new ArrayList<>(); String sourceDirectory = configurator.getParameterValue(mavenProject, - "testSourceDirectory", - String.class, execution, monitor); + "testSourceDirectory", String.class, execution, monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = - configurator.getParameterValue(mavenProject, - "testSourceDirectories", List.class, execution, - monitor); + List sourceDirectories = configurator.getParameterValue( + mavenProject, "testSourceDirectories", List.class, execution, + monitor); if (sourceDirectories != null) { result.addAll(sourceDirectories); } @@ -342,9 +326,9 @@ private void copyOut(URL src, File dest) throws CheckstylePluginException { try { FileUtils.copyURLToFile(src, dest); } catch (IOException e) { - throw new CheckstylePluginException("Failed to copy file " - + src.getFile() - + ", SKIPPING Eclipse checkstyle configuration"); + throw new CheckstylePluginException( + "Failed to copy file " + src.getFile() + + ", SKIPPING Eclipse checkstyle configuration"); } } @@ -358,8 +342,7 @@ private void copyOut(URL src, File dest) throws CheckstylePluginException { private List getIncludesExcludesFileMatchPatterns() throws CheckstylePluginException, CoreException { - final List patterns = - new LinkedList<>(); + final List patterns = new LinkedList<>(); /** * Step 1). Get all the source roots (including test sources root, if @@ -381,12 +364,11 @@ private List getIncludesExcludesFileMatchPatterns() */ final List includePatterns = this.getIncludes(); for (String folder : sourceFolders) { - final String folderRelativePath = - this.basedirUri.relativize(new File(folder).toURI()) - .getPath(); + final String folderRelativePath = this.basedirUri + .relativize(new File(folder).toURI()).getPath(); if (includePatterns.size() != 0) { - patterns.addAll(this - .normalizePatternsToCheckstyleFileMatchPattern( + patterns.addAll( + this.normalizePatternsToCheckstyleFileMatchPattern( includePatterns, folderRelativePath, true)); } else { patterns.add(new FileMatchPattern(folderRelativePath)); @@ -401,12 +383,10 @@ private List getIncludesExcludesFileMatchPatterns() */ final List excludePatterns = this.getExcludes(); for (String folder : sourceFolders) { - String folderRelativePath = - this.basedirUri.relativize(new File(folder).toURI()) - .getPath(); + String folderRelativePath = this.basedirUri + .relativize(new File(folder).toURI()).getPath(); patterns.addAll(this.normalizePatternsToCheckstyleFileMatchPattern( - excludePatterns, - this.convertToEclipseCheckstyleRegExpPath( + excludePatterns, this.convertToEclipseCheckstyleRegExpPath( folderRelativePath), false)); } @@ -416,12 +396,11 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceIncludes(); for (Resource resource : this.mavenProject.getBuild() .getResources()) { - String folderRelativePath = - this.basedirUri.relativize( - new File(resource.getDirectory()).toURI()) - .getPath(); - patterns.addAll(this - .normalizePatternsToCheckstyleFileMatchPattern( + String folderRelativePath = this.basedirUri + .relativize(new File(resource.getDirectory()).toURI()) + .getPath(); + patterns.addAll( + this.normalizePatternsToCheckstyleFileMatchPattern( resourceIncludePatterns, folderRelativePath, true)); } @@ -430,12 +409,11 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceExcludes(); for (Resource resource : this.mavenProject.getBuild() .getResources()) { - String folderRelativePath = - this.basedirUri.relativize( - new File(resource.getDirectory()).toURI()) - .getPath(); - patterns.addAll(this - .normalizePatternsToCheckstyleFileMatchPattern( + String folderRelativePath = this.basedirUri + .relativize(new File(resource.getDirectory()).toURI()) + .getPath(); + patterns.addAll( + this.normalizePatternsToCheckstyleFileMatchPattern( resourceExcludePatterns, folderRelativePath, false)); } @@ -451,12 +429,11 @@ private List getIncludesExcludesFileMatchPatterns() // ignore resources that have ex/includes for now continue; } - String folderRelativePath = - this.basedirUri.relativize( - new File(resource.getDirectory()).toURI()) - .getPath(); - patterns.addAll(this - .normalizePatternsToCheckstyleFileMatchPattern( + String folderRelativePath = this.basedirUri + .relativize(new File(resource.getDirectory()).toURI()) + .getPath(); + patterns.addAll( + this.normalizePatternsToCheckstyleFileMatchPattern( resourceIncludePatterns, folderRelativePath, true)); } @@ -470,12 +447,11 @@ private List getIncludesExcludesFileMatchPatterns() // ignore resources that have ex/includes for now continue; } - String folderRelativePath = - this.basedirUri.relativize( - new File(resource.getDirectory()).toURI()) - .getPath(); - patterns.addAll(this - .normalizePatternsToCheckstyleFileMatchPattern( + String folderRelativePath = this.basedirUri + .relativize(new File(resource.getDirectory()).toURI()) + .getPath(); + patterns.addAll( + this.normalizePatternsToCheckstyleFileMatchPattern( resourceExcludePatterns, folderRelativePath, false)); } @@ -498,12 +474,10 @@ private List normalizePatternsToCheckstyleFileMatchPattern( final List patterns, final String relativePath, final boolean setIsIncludePatternFlag) throws CheckstylePluginException { - List fileMatchPatterns = - new LinkedList<>(); + List fileMatchPatterns = new LinkedList<>(); for (String p : patterns) { - final FileMatchPattern fmp = - new FileMatchPattern( - String.format("%s%s", relativePath, p)); + final FileMatchPattern fmp = new FileMatchPattern( + String.format("%s%s", relativePath, p)); fmp.setIsIncludePattern(setIsIncludePatternFlag); fileMatchPatterns.add(fmp); } @@ -523,9 +497,8 @@ private List normalizePatternsToCheckstyleFileMatchPattern( */ private List getPatterns(String elemName) throws CoreException { List transformedPatterns = new LinkedList<>(); - final String patternsString = - configurator.getParameterValue(mavenProject, elemName, - String.class, execution, monitor); + final String patternsString = configurator.getParameterValue( + mavenProject, elemName, String.class, execution, monitor); if (patternsString == null || patternsString.length() == 0) { return transformedPatterns; } @@ -560,9 +533,8 @@ private String convertAntStylePatternToCheckstylePattern( Preconditions.checkNotNull(pattern, "pattern cannot be null"); Preconditions.checkArgument(pattern.isEmpty(), "pattern cannot empty"); - String sanitizedPattern = - pattern.replace(File.separatorChar == '/' ? '\\' : '/', - File.separatorChar); + String sanitizedPattern = pattern.replace( + File.separatorChar == '/' ? '\\' : '/', File.separatorChar); String dupeSeperatorChar = File.separator + File.separator; while (sanitizedPattern.contains(dupeSeperatorChar)) { sanitizedPattern = @@ -607,8 +579,8 @@ private String convertAntStylePatternToCheckstylePattern( return result; } - public Properties getConfiguredProperties() throws CoreException, - CheckstylePluginException { + public Properties getConfiguredProperties() + throws CoreException, CheckstylePluginException { String propertiesLocation = getPropertiesLocation(); Properties properties = new Properties(); if (propertiesLocation != null) { @@ -622,10 +594,9 @@ public Properties getConfiguredProperties() throws CoreException, try { properties.load(url.openStream()); } catch (IOException e) { - throw new CheckstylePluginException( - String.format( - "Failed to LOAD properties from propertiesLocation [%s]", - propertiesLocation)); + throw new CheckstylePluginException(String.format( + "Failed to LOAD properties from propertiesLocation [%s]", + propertiesLocation)); } } return properties; diff --git a/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java b/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java index 8321def1..bc2d8245 100644 --- a/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java +++ b/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java @@ -22,8 +22,8 @@ import de.tobject.findbugs.builder.WorkItem; @SuppressWarnings("restriction") -public class EclipseFindbugsProjectConfigurationTest extends - AbstractMavenProjectTestCase { +public class EclipseFindbugsProjectConfigurationTest + extends AbstractMavenProjectTestCase { private static final String FINDBUGS_MARKER = "edu.umd.cs.findbugs.plugin.eclipse.findbugsMarker"; diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index f1fee324..460b4cb5 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -40,8 +40,8 @@ /** */ -public class EclipseFindbugsProjectConfigurator extends - AbstractMavenPluginProjectConfigurator { +public class EclipseFindbugsProjectConfigurator + extends AbstractMavenPluginProjectConfigurator { private static final Logger LOG = LoggerFactory.getLogger(EclipseFindbugsProjectConfigurator.class); diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 88615729..26d45870 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -109,8 +109,7 @@ public void setIncludeFilterFiles(final UserPreferences prefs) FB_INCLUDE_FILTER_FILE); final Map curIncludeFilteredFiles = prefs.getIncludeFilterFiles(); - final Map newIncludeFilteredFiles = - new HashMap<>(); + final Map newIncludeFilteredFiles = new HashMap<>(); // Make sure we add it only once. if (!curIncludeFilteredFiles.containsKey(FB_INCLUDE_FILTER_FILE)) { newIncludeFilteredFiles.put(FB_INCLUDE_FILTER_FILE, Boolean.TRUE); @@ -134,8 +133,7 @@ public void setExcludeFilterFiles(final UserPreferences prefs) FB_EXCLUDE_FILTER_FILE); final Map curExcludeFilteredFiles = prefs.getExcludeFilterFiles(); - final Map newExcludeFilteredFiles = - new HashMap<>(); + final Map newExcludeFilteredFiles = new HashMap<>(); // Make sure we add it only once. if (!curExcludeFilteredFiles.containsKey(FB_EXCLUDE_FILTER_FILE)) { newExcludeFilteredFiles.put(FB_EXCLUDE_FILTER_FILE, Boolean.TRUE); @@ -169,18 +167,16 @@ public void setExcludeFilterFiles(final UserPreferences prefs) public void setBugCatagories(final UserPreferences prefs) throws CoreException { final ProjectFilterSettings pfs = prefs.getFilterSettings(); - final String bugCatagories = - this.configurator.getParameterValue(mavenProject, - BUG_CATEGORIES, String.class, execution, monitor); + final String bugCatagories = this.configurator.getParameterValue( + mavenProject, BUG_CATEGORIES, String.class, execution, monitor); if (bugCatagories == null) { LOG.debug("bugCatagories is null"); return; } List addBugCatagoriesList = Arrays.asList(StringUtils.split(bugCatagories, ",")); - List availableBugCategories = - new LinkedList<>(DetectorFactoryCollection.instance() - .getBugCategories()); + List availableBugCategories = new LinkedList<>( + DetectorFactoryCollection.instance().getBugCategories()); if (!addBugCatagoriesList.isEmpty()) { for (String removeBugCategory : availableBugCategories) { pfs.removeCategory(removeBugCategory); @@ -207,9 +203,8 @@ public boolean debugEnabled() throws CoreException { } public void setEffort(final UserPreferences prefs) throws CoreException { - String effort = - this.configurator.getParameterValue(mavenProject, EFFORT, - String.class, execution, monitor); + String effort = this.configurator.getParameterValue(mavenProject, + EFFORT, String.class, execution, monitor); if (effort == null) { LOG.debug("effort is null"); return; @@ -219,17 +214,15 @@ public void setEffort(final UserPreferences prefs) throws CoreException { try { prefs.setEffort(effort); } catch (final IllegalArgumentException ex) { - LOG.error(String - .format("[%s]: could not set , reason [%s], setting it to default [%s]", - LOG_PREFIX, effort, - UserPreferences.EFFORT_DEFAULT)); + LOG.error(String.format( + "[%s]: could not set , reason [%s], setting it to default [%s]", + LOG_PREFIX, effort, UserPreferences.EFFORT_DEFAULT)); } } public void setMinRank(final UserPreferences prefs) throws CoreException { - Integer minRank = - this.configurator.getParameterValue(mavenProject, MAX_RANK, - Integer.class, execution, monitor); + Integer minRank = this.configurator.getParameterValue(mavenProject, + MAX_RANK, Integer.class, execution, monitor); if (minRank == null) { LOG.debug("max rank is null"); return; @@ -237,16 +230,15 @@ public void setMinRank(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinRank(minRank); } catch (final IllegalArgumentException ex) { - LOG.error(String - .format("[%s]: could not set , reason [%s], setting it to default [%s]", - LOG_PREFIX, minRank, 15)); + LOG.error(String.format( + "[%s]: could not set , reason [%s], setting it to default [%s]", + LOG_PREFIX, minRank, 15)); } } public void setPriority(final UserPreferences prefs) throws CoreException { - final String priority = - this.configurator.getParameterValue(mavenProject, PRIORITY, - String.class, execution, monitor); + final String priority = this.configurator.getParameterValue( + mavenProject, PRIORITY, String.class, execution, monitor); if (priority == null) { LOG.debug("priority is null"); return; @@ -254,17 +246,16 @@ public void setPriority(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinPriority(priority); } catch (final Exception ex) { - LOG.error(String - .format("[%s]: could not set , reason [%s], leaving it alone", - LOG_PREFIX, priority)); + LOG.error(String.format( + "[%s]: could not set , reason [%s], leaving it alone", + LOG_PREFIX, priority)); } } public void setOmitVisitors(final UserPreferences prefs) throws CoreException { - final String omitVisitors = - this.configurator.getParameterValue(mavenProject, - OMIT_VISITORS, String.class, execution, monitor); + final String omitVisitors = this.configurator.getParameterValue( + mavenProject, OMIT_VISITORS, String.class, execution, monitor); if (omitVisitors == null) { LOG.debug("omitVisitors is null"); return; @@ -285,9 +276,8 @@ public void setOmitVisitors(final UserPreferences prefs) } public void setThreshold(final UserPreferences prefs) throws CoreException { - final String threshold = - this.configurator.getParameterValue(mavenProject, THRESHOLD, - String.class, execution, monitor); + final String threshold = this.configurator.getParameterValue( + mavenProject, THRESHOLD, String.class, execution, monitor); if (threshold == null) { LOG.debug("threshold is null"); return; @@ -295,16 +285,15 @@ public void setThreshold(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinPriority(threshold); } catch (final Exception ex) { - LOG.error(String - .format("[%s]: could not set , reason [%s], leaving it alone", - LOG_PREFIX, threshold)); + LOG.error(String.format( + "[%s]: could not set , reason [%s], leaving it alone", + LOG_PREFIX, threshold)); } } public void setVisitors(final UserPreferences prefs) throws CoreException { - final String visitors = - this.configurator.getParameterValue(mavenProject, VISITORS, - String.class, execution, monitor); + final String visitors = this.configurator.getParameterValue( + mavenProject, VISITORS, String.class, execution, monitor); if (visitors == null) { return; } @@ -359,11 +348,10 @@ private void copyUrlResourceToProject(final String resc, FileUtils.copyStreamToFile(new URLInputStreamFacade(urlResc), newLocationFile); } catch (IOException ex) { - throw new ConfigurationException( - String.format( - "[%s]: could not copy resource [%s] to [%s], reason [%s]", - LOG_PREFIX, resc, newLocationFile, - ex.getLocalizedMessage())); + throw new ConfigurationException(String.format( + "[%s]: could not copy resource [%s] to [%s], reason [%s]", + LOG_PREFIX, resc, newLocationFile, + ex.getLocalizedMessage())); } } @@ -376,20 +364,21 @@ public static MavenPluginConfigurationTranslator newInstance( final List mojoExecutions = mavenPlugin.getMojoExecutions(); if (mojoExecutions.size() != 1) { - throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil - .getBundle(MavenPluginConfigurationTranslator.class) - .getSymbolicName(), - "Wrong number of executions. Expected 1. Found " - + mojoExecutions.size())); + throw new CoreException( + new Status(IStatus.ERROR, + FrameworkUtil + .getBundle( + MavenPluginConfigurationTranslator.class) + .getSymbolicName(), + "Wrong number of executions. Expected 1. Found " + + mojoExecutions.size())); } MojoExecution execution = mojoExecutions.get(0); - ResourceResolver resourceResolver = - configurator.getResourceResolver(execution, session, - project.getLocation()); + ResourceResolver resourceResolver = configurator + .getResourceResolver(execution, session, project.getLocation()); final MavenPluginConfigurationTranslator m2csConverter = - new MavenPluginConfigurationTranslator(configurator, - execution, project, mavenProject, monitor, - resourceResolver); + new MavenPluginConfigurationTranslator(configurator, execution, + project, mavenProject, monitor, resourceResolver); return m2csConverter; } } diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 9e0dec4e..8f31b11b 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -64,8 +64,8 @@ import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException; import net.sourceforge.pmd.eclipse.runtime.writer.WriterException; -public class EclipsePmdProjectConfigurator extends - AbstractMavenPluginProjectConfigurator { +public class EclipsePmdProjectConfigurator + extends AbstractMavenPluginProjectConfigurator { // private static final String PMD_NATURE = // "net.sourceforge.pmd.eclipse.plugin.pmdNature"; @@ -99,9 +99,8 @@ protected void handleProjectConfigurationChange( throws CoreException { final MojoExecution execution = findMojoExecution(mavenPluginWrapper); - MojoExecution pmdGoalExecution = - findForkedExecution(execution, "org.apache.maven.plugins", - "maven-pmd-plugin", "pmd"); + MojoExecution pmdGoalExecution = findForkedExecution(execution, + "org.apache.maven.plugins", "maven-pmd-plugin", "pmd"); final MavenPluginConfigurationTranslator pluginCfgTranslator = MavenPluginConfigurationTranslator.newInstance(this, mavenProjectFacade.getMavenProject(monitor), @@ -185,21 +184,18 @@ private void createOrUpdateEclipsePmdConfiguration( throws CoreException { final MojoExecution execution = findMojoExecution(pluginWrapper); - ResourceResolver resourceResolver = - this.getResourceResolver(execution, session, - project.getLocation()); + ResourceResolver resourceResolver = this.getResourceResolver(execution, + session, project.getLocation()); try { - final RuleSet ruleset = - this.createPmdRuleSet(pluginCfgTranslator, - resourceResolver); + final RuleSet ruleset = this.createPmdRuleSet(pluginCfgTranslator, + resourceResolver); this.buildAndAddPmdExcludeAndIncludePatternToRuleSet( pluginCfgTranslator, ruleset); // persist the ruleset to a file under the project. - final File rulesetFile = - writeRuleSet(project.getFile(PMD_RULESET_FILE), ruleset, - monitor); + final File rulesetFile = writeRuleSet( + project.getFile(PMD_RULESET_FILE), ruleset, monitor); try { final IProjectPropertiesManager mgr = @@ -221,8 +217,8 @@ private void createOrUpdateEclipsePmdConfiguration( private RuleSet createPmdRuleSet( final MavenPluginConfigurationTranslator pluginCfgTranslator, - final ResourceResolver resourceResolver) throws CoreException, - PMDException { + final ResourceResolver resourceResolver) + throws CoreException, PMDException { final RuleSet ruleSet = new RuleSet(); ruleSet.setName("M2Eclipse PMD RuleSet"); @@ -232,15 +228,13 @@ private RuleSet createPmdRuleSet( for (final String loc : rulesetStringLocations) { RuleSetReferenceId ruleSetReferenceId = new RuleSetReferenceId(loc); - final URL resolvedLocation = - resourceResolver.resolveLocation(ruleSetReferenceId - .getRuleSetFileName()); + final URL resolvedLocation = resourceResolver + .resolveLocation(ruleSetReferenceId.getRuleSetFileName()); if (resolvedLocation == null) { - throw new PMDException( - String.format( - "Failed to resolve RuleSet from location [%s],SKIPPING Eclipse PMD configuration", - loc)); + throw new PMDException(String.format( + "Failed to resolve RuleSet from location [%s],SKIPPING Eclipse PMD configuration", + loc)); } RuleSet ruleSetAtLocations; @@ -288,17 +282,15 @@ private File writeRuleSet(final IFile rulesetFile, final RuleSet ruleSet, final PMDPlugin pmdPlugin = PMDPlugin.getDefault(); ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); - try (BufferedOutputStream outputStream = - new BufferedOutputStream(new FileOutputStream(rulesetFile - .getLocation().toFile()));) { + try (BufferedOutputStream outputStream = new BufferedOutputStream( + new FileOutputStream(rulesetFile.getLocation().toFile()));) { pmdPlugin.getRuleSetWriter().write(byteArrayStream, ruleSet); // ..and now we have two problems - String fixedXml = - byteArrayStream.toString("UTF-8").replaceAll( - "\\(.*)\\", - ""); + String fixedXml = byteArrayStream.toString("UTF-8").replaceAll( + "\\(.*)\\", + ""); outputStream.write(fixedXml.getBytes(Charset.forName("UTF-8"))); @@ -334,8 +326,8 @@ private void buildAndAddPmdExcludeAndIncludePatternToRuleSet( for (String ir : includeRoots) { for (String ep : excludePatterns) { String fullPattern = ".*" + ir + ep; - ruleset.addExcludePattern(StringUtils.replace(fullPattern, - ".*.*", ".*")); + ruleset.addExcludePattern( + StringUtils.replace(fullPattern, ".*.*", ".*")); } } } @@ -347,8 +339,8 @@ private void buildAndAddPmdExcludeAndIncludePatternToRuleSet( for (String ir : includeRoots) { for (String ip : includePatterns) { String fullPattern = ".*" + ir + ip; - ruleset.addIncludePattern(StringUtils.replace(fullPattern, - ".*.*", ".*")); + ruleset.addIncludePattern( + StringUtils.replace(fullPattern, ".*.*", ".*")); } } } @@ -358,10 +350,10 @@ private MojoExecution findMojoExecution( final List mojoExecutions = mavenPluginWrapper.getMojoExecutions(); if (mojoExecutions.size() != 1) { - throw new CoreException(new Status(IStatus.ERROR, - PmdEclipseConstants.PLUGIN_ID, - "Wrong number of executions. Expected 1. Found " - + mojoExecutions.size())); + throw new CoreException( + new Status(IStatus.ERROR, PmdEclipseConstants.PLUGIN_ID, + "Wrong number of executions. Expected 1. Found " + + mojoExecutions.size())); } final MojoExecution execution = mojoExecutions.get(0); return execution; diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java index 09844253..651008a0 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java @@ -41,8 +41,7 @@ */ public class MavenPluginConfigurationTranslator { - private static final Map PATTERNS_CACHE = - new HashMap<>(); + private static final Map PATTERNS_CACHE = new HashMap<>(); private final MavenProject mavenProject; private final URI basedirUri; @@ -73,9 +72,8 @@ private MavenPluginConfigurationTranslator( } public List getRulesets() throws CoreException { - String[] rulesets = - configurator.getParameterValue(mavenProject, "rulesets", - String[].class, pmdGoalExecution, monitor); + String[] rulesets = configurator.getParameterValue(mavenProject, + "rulesets", String[].class, pmdGoalExecution, monitor); if (rulesets == null) { // no special rulesets configured - use the same defaults as the // maven-pmd-plugin does @@ -87,9 +85,8 @@ public List getRulesets() throws CoreException { } private List getExcludePatterns() throws CoreException { - String[] excludes = - configurator.getParameterValue(mavenProject, "excludes", - String[].class, pmdGoalExecution, monitor); + String[] excludes = configurator.getParameterValue(mavenProject, + "excludes", String[].class, pmdGoalExecution, monitor); final List transformedPatterns = new LinkedList<>(); if (excludes != null && excludes.length > 0) { for (String p : excludes) { @@ -97,8 +94,8 @@ private List getExcludePatterns() throws CoreException { if (StringUtils.isBlank(p)) { continue; } - transformedPatterns.add(this - .getTransformedPattern(p, "EXCLUDE")); + transformedPatterns + .add(this.getTransformedPattern(p, "EXCLUDE")); } } return transformedPatterns; @@ -117,9 +114,8 @@ private List getExcludePatterns() throws CoreException { * @throws CoreException */ private List getIncludePatterns() throws CoreException { - String[] includes = - configurator.getParameterValue(mavenProject, "includes", - String[].class, pmdGoalExecution, monitor); + String[] includes = configurator.getParameterValue(mavenProject, + "includes", String[].class, pmdGoalExecution, monitor); final List transformedPatterns = new LinkedList<>(); if (includes != null && includes.length > 0) { for (String p : includes) { @@ -127,8 +123,8 @@ private List getIncludePatterns() throws CoreException { if (StringUtils.isBlank(p)) { continue; } - transformedPatterns.add(this - .getTransformedPattern(p, "INCLUDE")); + transformedPatterns + .add(this.getTransformedPattern(p, "INCLUDE")); } } return transformedPatterns; @@ -143,9 +139,8 @@ private List getIncludePatterns() throws CoreException { * if an error occurs */ public boolean getIncludeTests() throws CoreException { - Boolean tests = - configurator.getParameterValue(mavenProject, "includeTests", - Boolean.class, pmdGoalExecution, monitor); + Boolean tests = configurator.getParameterValue(mavenProject, + "includeTests", Boolean.class, pmdGoalExecution, monitor); return tests != null && tests.booleanValue(); } @@ -216,19 +211,18 @@ private void buildExcludeAndIncludeSourceRoots() throws CoreException { final List includeRoots = new ArrayList<>(); final List excludeRoots = new ArrayList<>(); - includeRoots.addAll(this - .transformResourceStringsToFiles(this.mavenProject - .getCompileSourceRoots())); + includeRoots.addAll(this.transformResourceStringsToFiles( + this.mavenProject.getCompileSourceRoots())); List targetDirectories = new ArrayList<>(); targetDirectories.add(this.mavenProject.getBuild().getDirectory()); - excludeRoots.addAll(this - .transformResourceStringsToFiles(targetDirectories)); + excludeRoots.addAll( + this.transformResourceStringsToFiles(targetDirectories)); // Get all the normalized test roots and add them to include or exclude. final List testCompileSourceRoots = - this.transformResourceStringsToFiles(this.mavenProject - .getTestCompileSourceRoots()); + this.transformResourceStringsToFiles( + this.mavenProject.getTestCompileSourceRoots()); if (this.getIncludeTests()) { includeRoots.addAll(testCompileSourceRoots); } else { @@ -237,9 +231,8 @@ private void buildExcludeAndIncludeSourceRoots() throws CoreException { // now we need to filter out any excludeRoots from plugin configurations List excludeRootsFromConfig; - File[] excludeRootsArray = - configurator.getParameterValue(mavenProject, "excludeRoots", - File[].class, pmdGoalExecution, monitor); + File[] excludeRootsArray = configurator.getParameterValue(mavenProject, + "excludeRoots", File[].class, pmdGoalExecution, monitor); if (excludeRootsArray == null) { excludeRootsFromConfig = Collections.emptyList(); } else { @@ -262,8 +255,8 @@ private void buildExcludeAndIncludeSourceRoots() throws CoreException { } this.includeSourceRoots.addAll(this .convertFileFoldersToRelativePathStrings(filteredIncludeRoots)); - this.excludeSourceRoots.addAll(this - .convertFileFoldersToRelativePathStrings(excludeRoots)); + this.excludeSourceRoots.addAll( + this.convertFileFoldersToRelativePathStrings(excludeRoots)); } private List convertFileFoldersToRelativePathStrings( @@ -273,8 +266,7 @@ private List convertFileFoldersToRelativePathStrings( for (File f : sources) { String relativePath; if (!f.isAbsolute()) { - relativePath = - this.basedirUri.resolve(f.toURI()).getPath(); + relativePath = this.basedirUri.resolve(f.toURI()).getPath(); } else { relativePath = f.getAbsolutePath(); } diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java index 526649ff..6e2d97a7 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/PmdEclipseConstants.java @@ -31,8 +31,8 @@ public final class PmdEclipseConstants { public static final String PMD_SETTINGS_FILE = ".pmd"; - public static final String PLUGIN_ID = FrameworkUtil.getBundle( - PmdEclipseConstants.class).getSymbolicName(); + public static final String PLUGIN_ID = FrameworkUtil + .getBundle(PmdEclipseConstants.class).getSymbolicName(); private PmdEclipseConstants() { // no instantiation. diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index c03a1a40..0208da08 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -44,8 +44,8 @@ * plugin configuration. * */ -public abstract class AbstractMavenPluginProjectConfigurator extends - AbstractProjectConfigurator { +public abstract class AbstractMavenPluginProjectConfigurator + extends AbstractProjectConfigurator { @Override public T getParameterValue(MavenProject project, String parameter, @@ -226,10 +226,9 @@ public ResourceResolver getResourceResolver(MojoExecution mojoExecution, private MavenPluginWrapper getMavenPlugin(IProgressMonitor monitor, final IMavenProjectFacade projectFacade) throws CoreException { - return MavenPluginWrapper - .newInstance(monitor, getMavenPluginGroupId(), - getMavenPluginArtifactId(), getMavenPluginGoal(), - projectFacade); + return MavenPluginWrapper.newInstance(monitor, getMavenPluginGroupId(), + getMavenPluginArtifactId(), getMavenPluginGoal(), + projectFacade); } } diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java index 451bed01..b8d3369e 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java @@ -67,8 +67,7 @@ public static List findMojoExecutions( private static List searchExecutions( final String pluginGroupId, final String pluginArtifactId, final String[] pluginGoal, List mojoExecutions) { - final List foundMojoExections = - new ArrayList<>(); + final List foundMojoExections = new ArrayList<>(); for (MojoExecution mojoExecution : mojoExecutions) { if (pluginGoal != null) { for (String goal : pluginGoal) { From ff398db046e81cd10bed44ef66b1fcc3e8309577 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:58:35 +0100 Subject: [PATCH 045/153] Make all local variables and parameters final where possible --- .../code/quality/checkstyle/Activator.java | 4 +- .../EclipseCheckstyleConfigManager.java | 2 +- .../EclipseCheckstyleProjectConfigurator.java | 18 +-- .../EclipseCheckstylereferencePage.java | 2 +- .../MavenPluginConfigurationTranslator.java | 106 +++++++++--------- ...lipseFindbugsProjectConfigurationTest.java | 17 +-- .../EclipseFindbugsProjectConfigurator.java | 6 +- .../MavenPluginConfigurationTranslator.java | 32 +++--- .../pmd/EclipsePmdProjectConfigurator.java | 61 +++++----- .../MavenPluginConfigurationTranslator.java | 35 +++--- ...bstractMavenPluginProjectConfigurator.java | 36 +++--- .../quality/shared/MavenPluginWrapper.java | 25 +++-- .../code/quality/shared/ResourceResolver.java | 17 +-- 13 files changed, 189 insertions(+), 172 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java index 4fb4c1ea..4e32427b 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java @@ -26,7 +26,7 @@ public Activator() { * ) */ @Override - public void start(BundleContext context) throws Exception { + public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -39,7 +39,7 @@ public void start(BundleContext context) throws Exception { * ) */ @Override - public void stop(BundleContext context) throws Exception { + public void stop(final BundleContext context) throws Exception { plugin = null; super.stop(context); } diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index 25eb3040..9b587fe9 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -79,7 +79,7 @@ private void deconfigureNature(final IProgressMonitor monitor) final IProjectDescription desc = project.getDescription(); final String[] natures = desc.getNatureIds(); final List newNaturesList = new ArrayList<>(); - for (String nature : natures) { + for (final String nature : natures) { if (!CheckstyleNature.NATURE_ID.equals(nature)) { newNaturesList.add(nature); } diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index ce28237e..92a9aa6d 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -82,8 +82,8 @@ protected String[] getMavenPluginGoal() { protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, - final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException { + final MavenPluginWrapper mavenPluginWrapper, + final MavenSession session) throws CoreException { final List mavenCheckstyleConfigs = MavenPluginConfigurationTranslator.newInstance(this, @@ -121,7 +121,7 @@ protected void handleProjectConfigurationChange( pcWorkingCopy.store(); } - } catch (CheckstylePluginException ex) { + } catch (final CheckstylePluginException ex) { LOG.error("CheckstylePluginException", ex); } } @@ -137,7 +137,7 @@ protected void unconfigureEclipsePlugin(final IProject project, } private void buildCheckstyleConfiguration( - ProjectConfigurationWorkingCopy pcWorkingCopy, + final ProjectConfigurationWorkingCopy pcWorkingCopy, final MavenPluginConfigurationTranslator cfgTranslator) throws CheckstylePluginException, CoreException { // get the ruleset from configLocation @@ -153,12 +153,12 @@ private void buildCheckstyleConfiguration( final Properties props = cfgTranslator.getConfiguredProperties(); cfgTranslator.updatePropertiesWithPropertyExpansion(props); // add the header file location to the props. - String headerFile = cfgTranslator.getHeaderFile(); + final String headerFile = cfgTranslator.getHeaderFile(); if (headerFile != null) { props.setProperty("checkstyle.header.file", headerFile); } // add the suppressions file location to the props. - String suppressionsFile = cfgTranslator.getSuppressionsFile(); + final String suppressionsFile = cfgTranslator.getSuppressionsFile(); if (suppressionsFile != null) { props.setProperty(cfgTranslator.getSuppressionsFileExpression(), suppressionsFile); @@ -169,7 +169,7 @@ private void buildCheckstyleConfiguration( final List csProps = checkCfg.getResolvableProperties(); csProps.clear(); - for (Map.Entry entry : props.entrySet()) { + for (final Map.Entry entry : props.entrySet()) { csProps.add(new ResolvableProperty((String) entry.getKey(), (String) entry.getValue())); } @@ -182,7 +182,7 @@ private void buildCheckstyleConfiguration( */ private ICheckConfiguration createOrGetCheckstyleConfig( final ProjectConfigurationWorkingCopy pcWorkingCopy, - final URL ruleset, String executionId) + final URL ruleset, final String executionId) throws CheckstylePluginException { final String configName = ECLIPSE_CS_PREFS_CONFIG_NAME + " " + executionId; @@ -196,7 +196,7 @@ private ICheckConfiguration createOrGetCheckstyleConfig( workingSet.getWorkingCopies(); workingCopies = (CheckConfigurationWorkingCopy[]) ArrayUtils .nullToEmpty(workingCopies); - for (CheckConfigurationWorkingCopy copy : workingCopies) { + for (final CheckConfigurationWorkingCopy copy : workingCopies) { if (configName.equals(copy.getName())) { if (this.remoteConfigurationType.equals(copy.getType())) { workingCopy = copy; diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstylereferencePage.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstylereferencePage.java index eaadba6b..24be8045 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstylereferencePage.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstylereferencePage.java @@ -17,7 +17,7 @@ public EclipseCheckstylereferencePage() { } @Override - public void init(IWorkbench workbench) { + public void init(final IWorkbench workbench) { } /* diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 9bab2db0..52146c03 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -76,7 +76,7 @@ private MavenPluginConfigurationTranslator( final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MojoExecution mojoExecution, final IProject project, final IProgressMonitor monitor, - ResourceResolver resourceResolver) throws CoreException { + final ResourceResolver resourceResolver) throws CoreException { this.mavenProject = mavenProject; this.project = project; this.monitor = monitor; @@ -87,8 +87,8 @@ private MavenPluginConfigurationTranslator( } public boolean isActive() throws CoreException { - Boolean isSkip = configurator.getParameterValue(mavenProject, "skip", - Boolean.class, execution, monitor); + final Boolean isSkip = configurator.getParameterValue(mavenProject, + "skip", Boolean.class, execution, monitor); return isSkip != null ? !isSkip : true; } @@ -110,8 +110,9 @@ public String getHeaderFile() return null; } - File outDir = project.getWorkingLocation(configurator.getId()).toFile(); - File headerFile = new File(outDir, + final File outDir = + project.getWorkingLocation(configurator.getId()).toFile(); + final File headerFile = new File(outDir, "checkstyle-header-" + getExecutionId() + ".txt"); copyOut(headerResource, headerFile); @@ -130,8 +131,9 @@ public String getSuppressionsFile() return null; } - File outDir = project.getWorkingLocation(configurator.getId()).toFile(); - File suppressionsFile = new File(outDir, + final File outDir = + project.getWorkingLocation(configurator.getId()).toFile(); + final File suppressionsFile = new File(outDir, "checkstyle-suppressions-" + getExecutionId() + ".xml"); copyOut(suppressionsResource, suppressionsFile); @@ -198,9 +200,9 @@ protected String getPropertyExpansion() throws CoreException { * if an error occurs */ public boolean getIncludeTestSourceDirectory() throws CoreException { - Boolean includeTestSourceDirectory = configurator.getParameterValue( - mavenProject, "includeTestSourceDirectory", Boolean.class, - execution, monitor); + final Boolean includeTestSourceDirectory = configurator + .getParameterValue(mavenProject, "includeTestSourceDirectory", + Boolean.class, execution, monitor); if (includeTestSourceDirectory != null) { return includeTestSourceDirectory.booleanValue(); } else { @@ -209,7 +211,7 @@ public boolean getIncludeTestSourceDirectory() throws CoreException { } public boolean getIncludeResourcesDirectory() throws CoreException { - Boolean includeTestSourceDirectory = + final Boolean includeTestSourceDirectory = configurator.getParameterValue(mavenProject, "includeResources", Boolean.class, execution, monitor); if (includeTestSourceDirectory != null) { @@ -220,9 +222,9 @@ public boolean getIncludeResourcesDirectory() throws CoreException { } public boolean getIncludeTestResourcesDirectory() throws CoreException { - Boolean includeTestSourceDirectory = configurator.getParameterValue( - mavenProject, "includeTestResources", Boolean.class, execution, - monitor); + final Boolean includeTestSourceDirectory = configurator + .getParameterValue(mavenProject, "includeTestResources", + Boolean.class, execution, monitor); if (includeTestSourceDirectory != null) { return includeTestSourceDirectory.booleanValue(); } else { @@ -251,7 +253,7 @@ private String getConfigLocation() throws CoreException { } private String getHeaderLocation() throws CoreException { - String configLocation = getConfigLocation(); + final String configLocation = getConfigLocation(); String headerLocation = configurator.getParameterValue(mavenProject, "headerLocation", String.class, execution, monitor); if ("config/maven_checks.xml".equals(configLocation) @@ -273,14 +275,15 @@ private String getSuppressionsLocation() throws CoreException { } private List getSourceDirectories() throws CoreException { - List result = new ArrayList<>(); - String sourceDirectory = configurator.getParameterValue(mavenProject, - "sourceDirectory", String.class, execution, monitor); + final List result = new ArrayList<>(); + final String sourceDirectory = + configurator.getParameterValue(mavenProject, "sourceDirectory", + String.class, execution, monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = + final List sourceDirectories = configurator.getParameterValue(mavenProject, "sourceDirectories", List.class, execution, monitor); if (sourceDirectories != null) { @@ -290,14 +293,15 @@ private List getSourceDirectories() throws CoreException { } private List getTestSourceDirectories() throws CoreException { - List result = new ArrayList<>(); - String sourceDirectory = configurator.getParameterValue(mavenProject, - "testSourceDirectory", String.class, execution, monitor); + final List result = new ArrayList<>(); + final String sourceDirectory = configurator.getParameterValue( + mavenProject, "testSourceDirectory", String.class, execution, + monitor); if (sourceDirectory != null) { result.add(sourceDirectory); } @SuppressWarnings("unchecked") - List sourceDirectories = configurator.getParameterValue( + final List sourceDirectories = configurator.getParameterValue( mavenProject, "testSourceDirectories", List.class, execution, monitor); if (sourceDirectories != null) { @@ -322,10 +326,11 @@ private List getResourceExcludes() throws CoreException { return this.getPatterns("resourceExcludes"); } - private void copyOut(URL src, File dest) throws CheckstylePluginException { + private void copyOut(final URL src, final File dest) + throws CheckstylePluginException { try { FileUtils.copyURLToFile(src, dest); - } catch (IOException e) { + } catch (final IOException e) { throw new CheckstylePluginException( "Failed to copy file " + src.getFile() + ", SKIPPING Eclipse checkstyle configuration"); @@ -348,7 +353,7 @@ private List getIncludesExcludesFileMatchPatterns() * Step 1). Get all the source roots (including test sources root, if * enabled). */ - Set sourceFolders = new HashSet<>(); + final Set sourceFolders = new HashSet<>(); sourceFolders.addAll(this.getSourceDirectories()); if (getIncludeTestSourceDirectory()) { @@ -363,7 +368,7 @@ private List getIncludesExcludesFileMatchPatterns() * use relative path to project root. */ final List includePatterns = this.getIncludes(); - for (String folder : sourceFolders) { + for (final String folder : sourceFolders) { final String folderRelativePath = this.basedirUri .relativize(new File(folder).toURI()).getPath(); if (includePatterns.size() != 0) { @@ -382,8 +387,8 @@ private List getIncludesExcludesFileMatchPatterns() * exclude list. */ final List excludePatterns = this.getExcludes(); - for (String folder : sourceFolders) { - String folderRelativePath = this.basedirUri + for (final String folder : sourceFolders) { + final String folderRelativePath = this.basedirUri .relativize(new File(folder).toURI()).getPath(); patterns.addAll(this.normalizePatternsToCheckstyleFileMatchPattern( excludePatterns, this.convertToEclipseCheckstyleRegExpPath( @@ -394,9 +399,9 @@ private List getIncludesExcludesFileMatchPatterns() if (this.getIncludeResourcesDirectory()) { final List resourceIncludePatterns = this.getResourceIncludes(); - for (Resource resource : this.mavenProject.getBuild() + for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - String folderRelativePath = this.basedirUri + final String folderRelativePath = this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -407,9 +412,9 @@ private List getIncludesExcludesFileMatchPatterns() final List resourceExcludePatterns = this.getResourceExcludes(); - for (Resource resource : this.mavenProject.getBuild() + for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - String folderRelativePath = this.basedirUri + final String folderRelativePath = this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -422,14 +427,14 @@ private List getIncludesExcludesFileMatchPatterns() if (this.getIncludeTestResourcesDirectory()) { final List resourceIncludePatterns = this.getResourceIncludes(); - for (Resource resource : this.mavenProject.getBuild() + for (final Resource resource : this.mavenProject.getBuild() .getTestResources()) { if (resource.getExcludes().size() > 0 || resource.getIncludes().size() > 0) { // ignore resources that have ex/includes for now continue; } - String folderRelativePath = this.basedirUri + final String folderRelativePath = this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -440,14 +445,14 @@ private List getIncludesExcludesFileMatchPatterns() final List resourceExcludePatterns = this.getResourceExcludes(); - for (Resource resource : this.mavenProject.getBuild() + for (final Resource resource : this.mavenProject.getBuild() .getTestResources()) { if (resource.getExcludes().size() > 0 || resource.getIncludes().size() > 0) { // ignore resources that have ex/includes for now continue; } - String folderRelativePath = this.basedirUri + final String folderRelativePath = this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -474,8 +479,8 @@ private List normalizePatternsToCheckstyleFileMatchPattern( final List patterns, final String relativePath, final boolean setIsIncludePatternFlag) throws CheckstylePluginException { - List fileMatchPatterns = new LinkedList<>(); - for (String p : patterns) { + final List fileMatchPatterns = new LinkedList<>(); + for (final String p : patterns) { final FileMatchPattern fmp = new FileMatchPattern( String.format("%s%s", relativePath, p)); fmp.setIsIncludePattern(setIsIncludePatternFlag); @@ -495,8 +500,9 @@ private List normalizePatternsToCheckstyleFileMatchPattern( * @return a {@code List} of include patterns. * @throws CoreException */ - private List getPatterns(String elemName) throws CoreException { - List transformedPatterns = new LinkedList<>(); + private List getPatterns(final String elemName) + throws CoreException { + final List transformedPatterns = new LinkedList<>(); final String patternsString = configurator.getParameterValue( mavenProject, elemName, String.class, execution, monitor); if (patternsString == null || patternsString.length() == 0) { @@ -535,7 +541,7 @@ private String convertAntStylePatternToCheckstylePattern( String sanitizedPattern = pattern.replace( File.separatorChar == '/' ? '\\' : '/', File.separatorChar); - String dupeSeperatorChar = File.separator + File.separator; + final String dupeSeperatorChar = File.separator + File.separator; while (sanitizedPattern.contains(dupeSeperatorChar)) { sanitizedPattern = sanitizedPattern.replace(dupeSeperatorChar, File.separator); @@ -581,8 +587,8 @@ private String convertAntStylePatternToCheckstylePattern( public Properties getConfiguredProperties() throws CoreException, CheckstylePluginException { - String propertiesLocation = getPropertiesLocation(); - Properties properties = new Properties(); + final String propertiesLocation = getPropertiesLocation(); + final Properties properties = new Properties(); if (propertiesLocation != null) { final URL url = this.resourceResolver.resolveLocation(propertiesLocation); @@ -593,7 +599,7 @@ public Properties getConfiguredProperties() } try { properties.load(url.openStream()); - } catch (IOException e) { + } catch (final IOException e) { throw new CheckstylePluginException(String.format( "Failed to LOAD properties from propertiesLocation [%s]", propertiesLocation)); @@ -602,7 +608,7 @@ public Properties getConfiguredProperties() return properties; } - public void updatePropertiesWithPropertyExpansion(Properties props) + public void updatePropertiesWithPropertyExpansion(final Properties props) throws CheckstylePluginException, CoreException { final String propertyExpansion = this.getPropertyExpansion(); if (propertyExpansion != null) { @@ -611,7 +617,7 @@ public void updatePropertiesWithPropertyExpansion(Properties props) final String escapedPropertyExpansion = StringEscapeUtils.escapeJava(propertyExpansion); props.load(new StringReader(escapedPropertyExpansion)); - } catch (IOException e) { + } catch (final IOException e) { throw new CheckstylePluginException(String.format( "[%s]: Failed to checkstyle propertyExpansion [%s]", CheckstyleEclipseConstants.LOG_PREFIX, @@ -621,15 +627,15 @@ public void updatePropertiesWithPropertyExpansion(Properties props) } public static List newInstance( - AbstractMavenPluginProjectConfigurator configurator, + final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MavenPluginWrapper mavenPlugin, final IProject project, - final IProgressMonitor monitor, MavenSession session) + final IProgressMonitor monitor, final MavenSession session) throws CoreException { final List m2csConverters = new ArrayList<>(); for (final MojoExecution execution : mavenPlugin.getMojoExecutions()) { - ResourceResolver resourceResolver = + final ResourceResolver resourceResolver = configurator.getResourceResolver(execution, session, project.getLocation()); m2csConverters.add(new MavenPluginConfigurationTranslator( diff --git a/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java b/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java index bc2d8245..f69b30fe 100644 --- a/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java +++ b/com.basistech.m2e.code.quality.findbugs.test/src/main/java/com/basistech/m2e/code/quality/findbugs/tests/EclipseFindbugsProjectConfigurationTest.java @@ -36,26 +36,27 @@ public void testFindbugsFindbugs() throws Exception { runFindBugsAndFindMarkers("projects/findbugs-findbugs/pom.xml", 2); } - private void runFindBugsAndFindMarkers(String path, int markerCount) - throws Exception { - IProject p = importProject(path); + private void runFindBugsAndFindMarkers(final String path, + final int markerCount) throws Exception { + final IProject p = importProject(path); p.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobsToComplete(); - StructuredSelection selection = new StructuredSelection(p); + final StructuredSelection selection = new StructuredSelection(p); - Map> projectMap = + final Map> projectMap = ResourceUtils.getResourcesPerProject(selection); - for (Map.Entry> e : projectMap.entrySet()) { - FindBugsWorker worker = new FindBugsWorker(p, monitor); + for (final Map.Entry> e : projectMap + .entrySet()) { + final FindBugsWorker worker = new FindBugsWorker(p, monitor); worker.work(e.getValue()); } waitForJobsToComplete(); - IMarker[] markers = + final IMarker[] markers = p.findMarkers(FINDBUGS_MARKER, true, IResource.DEPTH_INFINITE); assertEquals(markerCount, markers.length); } diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 460b4cb5..b4b3c312 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -69,10 +69,10 @@ protected String[] getMavenPluginGoal() { protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, - final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException { + final MavenPluginWrapper mavenPluginWrapper, + final MavenSession session) throws CoreException { LOG.debug("entering handleProjectConfigurationChange"); - IJavaProject javaProject = JavaCore.create(project); + final IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists() || !javaProject.getProject().isOpen()) { return; diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 26d45870..9530cf03 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -86,7 +86,7 @@ private MavenPluginConfigurationTranslator( final AbstractMavenPluginProjectConfigurator configurator, final MojoExecution execution, final IProject project, final MavenProject mavenProject, final IProgressMonitor monitor, - ResourceResolver resourceResolver) throws CoreException { + final ResourceResolver resourceResolver) throws CoreException { this.project = project; this.mavenProject = mavenProject; this.monitor = monitor; @@ -173,17 +173,17 @@ public void setBugCatagories(final UserPreferences prefs) LOG.debug("bugCatagories is null"); return; } - List addBugCatagoriesList = + final List addBugCatagoriesList = Arrays.asList(StringUtils.split(bugCatagories, ",")); - List availableBugCategories = new LinkedList<>( + final List availableBugCategories = new LinkedList<>( DetectorFactoryCollection.instance().getBugCategories()); if (!addBugCatagoriesList.isEmpty()) { - for (String removeBugCategory : availableBugCategories) { + for (final String removeBugCategory : availableBugCategories) { pfs.removeCategory(removeBugCategory); } } final Set removeBugCategoriesSet = new HashSet<>(); - for (String bc : addBugCatagoriesList) { + for (final String bc : addBugCatagoriesList) { final String bcUpper = bc.toUpperCase(); if (availableBugCategories.contains(bcUpper)) { pfs.addCategory(bcUpper); @@ -221,8 +221,8 @@ public void setEffort(final UserPreferences prefs) throws CoreException { } public void setMinRank(final UserPreferences prefs) throws CoreException { - Integer minRank = this.configurator.getParameterValue(mavenProject, - MAX_RANK, Integer.class, execution, monitor); + final Integer minRank = this.configurator.getParameterValue( + mavenProject, MAX_RANK, Integer.class, execution, monitor); if (minRank == null) { LOG.debug("max rank is null"); return; @@ -260,11 +260,11 @@ public void setOmitVisitors(final UserPreferences prefs) LOG.debug("omitVisitors is null"); return; } - List detectorsList = + final List detectorsList = Arrays.asList(StringUtils.split(omitVisitors, ",")); final DetectorFactoryCollection dfc = DetectorFactoryCollection.instance(); - for (String d : detectorsList) { + for (final String d : detectorsList) { final DetectorFactory df = dfc.getFactory(d); if (df == null) { LOG.error(String.format("[%s]: IGNORING unknown detector [%s]", @@ -297,12 +297,12 @@ public void setVisitors(final UserPreferences prefs) throws CoreException { if (visitors == null) { return; } - List detectorsList = + final List detectorsList = Arrays.asList(StringUtils.split(visitors, ",")); prefs.enableAllDetectors(false); final DetectorFactoryCollection dfc = DetectorFactoryCollection.instance(); - for (String d : detectorsList) { + for (final String d : detectorsList) { final DetectorFactory df = dfc.getFactory(d); if (df == null) { LOG.error(String.format("[%s]: IGNORING unknown detector [%s]", @@ -347,7 +347,7 @@ private void copyUrlResourceToProject(final String resc, try { FileUtils.copyStreamToFile(new URLInputStreamFacade(urlResc), newLocationFile); - } catch (IOException ex) { + } catch (final IOException ex) { throw new ConfigurationException(String.format( "[%s]: could not copy resource [%s] to [%s], reason [%s]", LOG_PREFIX, resc, newLocationFile, @@ -356,10 +356,10 @@ private void copyUrlResourceToProject(final String resc, } public static MavenPluginConfigurationTranslator newInstance( - AbstractMavenPluginProjectConfigurator configurator, + final AbstractMavenPluginProjectConfigurator configurator, final MavenPluginWrapper mavenPlugin, final IProject project, final MavenProject mavenProject, final IProgressMonitor monitor, - MavenSession session) throws CoreException { + final MavenSession session) throws CoreException { final List mojoExecutions = mavenPlugin.getMojoExecutions(); @@ -373,8 +373,8 @@ public static MavenPluginConfigurationTranslator newInstance( "Wrong number of executions. Expected 1. Found " + mojoExecutions.size())); } - MojoExecution execution = mojoExecutions.get(0); - ResourceResolver resourceResolver = configurator + final MojoExecution execution = mojoExecutions.get(0); + final ResourceResolver resourceResolver = configurator .getResourceResolver(execution, session, project.getLocation()); final MavenPluginConfigurationTranslator m2csConverter = new MavenPluginConfigurationTranslator(configurator, execution, diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 8f31b11b..68d1b77a 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -95,11 +95,11 @@ protected String[] getMavenPluginGoal() { protected void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, - final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException { + final MavenPluginWrapper mavenPluginWrapper, + final MavenSession session) throws CoreException { final MojoExecution execution = findMojoExecution(mavenPluginWrapper); - MojoExecution pmdGoalExecution = findForkedExecution(execution, + final MojoExecution pmdGoalExecution = findForkedExecution(execution, "org.apache.maven.plugins", "maven-pmd-plugin", "pmd"); final MavenPluginConfigurationTranslator pluginCfgTranslator = MavenPluginConfigurationTranslator.newInstance(this, @@ -138,7 +138,7 @@ private void addPMDNature(final IProject project, if (project.hasNature(JAVA_NATURE)) { try { PMDNature.addPMDNature(project, monitor); - } catch (CoreException pmdNatureProblem) { + } catch (final CoreException pmdNatureProblem) { LOG.error("PMD plugin threw exception adding PMD nature", pmdNatureProblem); throw pmdNatureProblem; @@ -149,15 +149,15 @@ private void addPMDNature(final IProject project, @Override protected void unconfigureEclipsePlugin(final IProject project, final IProgressMonitor monitor) throws CoreException { - IProjectPropertiesManager mgr = + final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager(); try { - IProjectProperties projectProperties = + final IProjectProperties projectProperties = mgr.loadProjectProperties(project); projectProperties.setPmdEnabled(false); projectProperties.setRuleSetStoredInProject(false); mgr.storeProjectProperties(projectProperties); - } catch (PropertiesException ex) { + } catch (final PropertiesException ex) { } PMDNature.removePMDNature(project, monitor); @@ -180,12 +180,12 @@ protected void unconfigureEclipsePlugin(final IProject project, private void createOrUpdateEclipsePmdConfiguration( final MavenPluginWrapper pluginWrapper, final IProject project, final MavenPluginConfigurationTranslator pluginCfgTranslator, - final IProgressMonitor monitor, MavenSession session) + final IProgressMonitor monitor, final MavenSession session) throws CoreException { final MojoExecution execution = findMojoExecution(pluginWrapper); - ResourceResolver resourceResolver = this.getResourceResolver(execution, - session, project.getLocation()); + final ResourceResolver resourceResolver = this + .getResourceResolver(execution, session, project.getLocation()); try { final RuleSet ruleset = this.createPmdRuleSet(pluginCfgTranslator, resourceResolver); @@ -206,11 +206,11 @@ private void createOrUpdateEclipsePmdConfiguration( projectProperties.setRuleSetFile(rulesetFile.getAbsolutePath()); projectProperties.setRuleSetStoredInProject(true); mgr.storeProjectProperties(projectProperties); - } catch (PropertiesException ex) { + } catch (final PropertiesException ex) { // remove the files this.unconfigureEclipsePlugin(project, monitor); } - } catch (PMDException ex) { + } catch (final PMDException ex) { // nothing to do, skip configuration } } @@ -227,7 +227,8 @@ private RuleSet createPmdRuleSet( pluginCfgTranslator.getRulesets(); for (final String loc : rulesetStringLocations) { - RuleSetReferenceId ruleSetReferenceId = new RuleSetReferenceId(loc); + final RuleSetReferenceId ruleSetReferenceId = + new RuleSetReferenceId(loc); final URL resolvedLocation = resourceResolver .resolveLocation(ruleSetReferenceId.getRuleSetFileName()); @@ -239,15 +240,16 @@ private RuleSet createPmdRuleSet( RuleSet ruleSetAtLocations; try { - RuleSetReferenceId resolvedRuleSetReference = + final RuleSetReferenceId resolvedRuleSetReference = new RuleSetReferenceId(loc) { @Override - public InputStream getInputStream(ClassLoader arg0) - throws RuleSetNotFoundException { + public InputStream getInputStream( + final ClassLoader arg0) + throws RuleSetNotFoundException { try { return resolvedLocation.openStream(); - } catch (IOException e) { + } catch (final IOException e) { // ignore them. } LOG.warn("No ruleset found for {}", loc); @@ -257,7 +259,7 @@ public InputStream getInputStream(ClassLoader arg0) ruleSetAtLocations = this.factory.createRuleSet(resolvedRuleSetReference); ruleSet.addRuleSet(ruleSetAtLocations); - } catch (RuleSetNotFoundException e) { + } catch (final RuleSetNotFoundException e) { LOG.error("Couldn't find ruleset {}", loc, e); } } @@ -281,16 +283,17 @@ private File writeRuleSet(final IFile rulesetFile, final RuleSet ruleSet, final IProgressMonitor monitor) throws CoreException { final PMDPlugin pmdPlugin = PMDPlugin.getDefault(); - ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); + final ByteArrayOutputStream byteArrayStream = + new ByteArrayOutputStream(); try (BufferedOutputStream outputStream = new BufferedOutputStream( new FileOutputStream(rulesetFile.getLocation().toFile()));) { pmdPlugin.getRuleSetWriter().write(byteArrayStream, ruleSet); // ..and now we have two problems - String fixedXml = byteArrayStream.toString("UTF-8").replaceAll( - "\\(.*)\\", - ""); + final String fixedXml = byteArrayStream.toString("UTF-8") + .replaceAll("\\(.*)\\", + ""); outputStream.write(fixedXml.getBytes(Charset.forName("UTF-8"))); @@ -323,22 +326,22 @@ private void buildAndAddPmdExcludeAndIncludePatternToRuleSet( final List excludePatterns = pluginCfgTranslator.getExcludes(); // 2.) As per spec. add excludes pattern to all *includeRoots*. - for (String ir : includeRoots) { - for (String ep : excludePatterns) { - String fullPattern = ".*" + ir + ep; + for (final String ir : includeRoots) { + for (final String ep : excludePatterns) { + final String fullPattern = ".*" + ir + ep; ruleset.addExcludePattern( StringUtils.replace(fullPattern, ".*.*", ".*")); } } } // 1.) Do the excludeRoots first - for (String er : excludeRootsSet) { + for (final String er : excludeRootsSet) { ruleset.addExcludePattern(".*" + er); } // 3.) Now all includes - for (String ir : includeRoots) { - for (String ip : includePatterns) { - String fullPattern = ".*" + ir + ip; + for (final String ir : includeRoots) { + for (final String ip : includePatterns) { + final String fullPattern = ".*" + ir + ip; ruleset.addIncludePattern( StringUtils.replace(fullPattern, ".*.*", ".*")); } diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java index 651008a0..1d8041bd 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java @@ -60,9 +60,9 @@ public class MavenPluginConfigurationTranslator { private MavenPluginConfigurationTranslator( final AbstractMavenPluginProjectConfigurator configurator, - final MavenProject mavenProject, MojoExecution pmdGoalExecution, - final IProject project, IProgressMonitor monitor) - throws CoreException { + final MavenProject mavenProject, + final MojoExecution pmdGoalExecution, final IProject project, + final IProgressMonitor monitor) throws CoreException { this.mavenProject = mavenProject; this.project = project; this.monitor = monitor; @@ -72,7 +72,7 @@ private MavenPluginConfigurationTranslator( } public List getRulesets() throws CoreException { - String[] rulesets = configurator.getParameterValue(mavenProject, + final String[] rulesets = configurator.getParameterValue(mavenProject, "rulesets", String[].class, pmdGoalExecution, monitor); if (rulesets == null) { // no special rulesets configured - use the same defaults as the @@ -85,7 +85,7 @@ public List getRulesets() throws CoreException { } private List getExcludePatterns() throws CoreException { - String[] excludes = configurator.getParameterValue(mavenProject, + final String[] excludes = configurator.getParameterValue(mavenProject, "excludes", String[].class, pmdGoalExecution, monitor); final List transformedPatterns = new LinkedList<>(); if (excludes != null && excludes.length > 0) { @@ -114,7 +114,7 @@ private List getExcludePatterns() throws CoreException { * @throws CoreException */ private List getIncludePatterns() throws CoreException { - String[] includes = configurator.getParameterValue(mavenProject, + final String[] includes = configurator.getParameterValue(mavenProject, "includes", String[].class, pmdGoalExecution, monitor); final List transformedPatterns = new LinkedList<>(); if (includes != null && includes.length > 0) { @@ -139,7 +139,7 @@ private List getIncludePatterns() throws CoreException { * if an error occurs */ public boolean getIncludeTests() throws CoreException { - Boolean tests = configurator.getParameterValue(mavenProject, + final Boolean tests = configurator.getParameterValue(mavenProject, "includeTests", Boolean.class, pmdGoalExecution, monitor); return tests != null && tests.booleanValue(); } @@ -214,7 +214,7 @@ private void buildExcludeAndIncludeSourceRoots() throws CoreException { includeRoots.addAll(this.transformResourceStringsToFiles( this.mavenProject.getCompileSourceRoots())); - List targetDirectories = new ArrayList<>(); + final List targetDirectories = new ArrayList<>(); targetDirectories.add(this.mavenProject.getBuild().getDirectory()); excludeRoots.addAll( this.transformResourceStringsToFiles(targetDirectories)); @@ -231,17 +231,18 @@ private void buildExcludeAndIncludeSourceRoots() throws CoreException { // now we need to filter out any excludeRoots from plugin configurations List excludeRootsFromConfig; - File[] excludeRootsArray = configurator.getParameterValue(mavenProject, - "excludeRoots", File[].class, pmdGoalExecution, monitor); + final File[] excludeRootsArray = + configurator.getParameterValue(mavenProject, "excludeRoots", + File[].class, pmdGoalExecution, monitor); if (excludeRootsArray == null) { excludeRootsFromConfig = Collections.emptyList(); } else { excludeRootsFromConfig = Arrays.asList(excludeRootsArray); } // do the filtering - List filteredIncludeRoots = new LinkedList<>(); - for (File f : includeRoots) { - int idx = excludeRootsFromConfig.indexOf(f); + final List filteredIncludeRoots = new LinkedList<>(); + for (final File f : includeRoots) { + final int idx = excludeRootsFromConfig.indexOf(f); /** * Be optimistic when adding inclusions; if the specified File does * not exist yet, then assume it will at some point and include it. @@ -263,7 +264,7 @@ private List convertFileFoldersToRelativePathStrings( final Iterable sources) { final List folders = new ArrayList<>(); // No null check as internally we *know* - for (File f : sources) { + for (final File f : sources) { String relativePath; if (!f.isAbsolute()) { relativePath = this.basedirUri.resolve(f.toURI()).getPath(); @@ -290,7 +291,7 @@ private List transformResourceStringsToFiles( final File basedir = this.mavenProject.getBasedir(); final List sourceDirectories = new ArrayList<>(); if (srcDirNames != null) { - for (String srcDirName : srcDirNames) { + for (final String srcDirName : srcDirNames) { File srcDir = new File(srcDirName); if (!srcDir.isAbsolute()) { srcDir = new File(basedir, srcDir.getPath()); @@ -313,10 +314,10 @@ private void initialize() throws CoreException { } public static MavenPluginConfigurationTranslator newInstance( - AbstractMavenPluginProjectConfigurator configurator, + final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MojoExecution pmdGoalExecution, final IProject project, - IProgressMonitor monitor) throws CoreException { + final IProgressMonitor monitor) throws CoreException { final MavenPluginConfigurationTranslator m2csConverter = new MavenPluginConfigurationTranslator(configurator, mavenProject, pmdGoalExecution, project, monitor); diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 0208da08..2662119d 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -48,21 +48,22 @@ public abstract class AbstractMavenPluginProjectConfigurator extends AbstractProjectConfigurator { @Override - public T getParameterValue(MavenProject project, String parameter, - Class asType, MojoExecution mojoExecution, - IProgressMonitor monitor) throws CoreException { + public T getParameterValue(final MavenProject project, + final String parameter, final Class asType, + final MojoExecution mojoExecution, final IProgressMonitor monitor) + throws CoreException { return super.getParameterValue(project, parameter, asType, mojoExecution, monitor); } - protected MojoExecution findForkedExecution(MojoExecution primary, - String groupId, String artifactId, String goal) { - Map> forkedExecutions = + protected MojoExecution findForkedExecution(final MojoExecution primary, + final String groupId, final String artifactId, final String goal) { + final Map> forkedExecutions = primary.getForkedExecutions(); MojoExecution goalExecution = null; - for (List possibleExecutionList : forkedExecutions + for (final List possibleExecutionList : forkedExecutions .values()) { - for (MojoExecution possibleExecution : possibleExecutionList) { + for (final MojoExecution possibleExecution : possibleExecutionList) { if (groupId.equals(possibleExecution.getGroupId()) && artifactId.equals(possibleExecution.getArtifactId()) && goal.equals(possibleExecution.getGoal())) { @@ -95,7 +96,7 @@ public void configure(final ProjectConfigurationRequest request, } @SuppressWarnings("deprecation") - MavenSession mavenSession = request.getMavenSession(); + final MavenSession mavenSession = request.getMavenSession(); this.handleProjectConfigurationChange(request.getMavenProjectFacade(), project, monitor, pluginWrapper, mavenSession); @@ -118,10 +119,10 @@ public void mavenProjectChanged( } if (pluginWrapper.isPluginConfigured()) { @SuppressWarnings("deprecation") - MavenExecutionRequest request = + final MavenExecutionRequest request = maven.createExecutionRequest(monitor); @SuppressWarnings("deprecation") - MavenSession session = + final MavenSession session = maven.createSession(request, mavenProjectChangedEvent .getMavenProject().getMavenProject(monitor)); this.handleProjectConfigurationChange(mavenProjectFacade, project, @@ -192,7 +193,7 @@ protected abstract void unconfigureEclipsePlugin(final IProject project, * deleted. * @throws CoreException */ - private boolean checkUnconfigurationRequired(IProgressMonitor monitor, + private boolean checkUnconfigurationRequired(final IProgressMonitor monitor, final IMavenProjectFacade curMavenProjectFacade, final IMavenProjectFacade oldMavenProjectFacade) throws CoreException { @@ -212,19 +213,20 @@ private boolean checkUnconfigurationRequired(IProgressMonitor monitor, return false; } - public ResourceResolver getResourceResolver(MojoExecution mojoExecution, - MavenSession session, IPath projectLocation) throws CoreException { + public ResourceResolver getResourceResolver( + final MojoExecution mojoExecution, final MavenSession session, + final IPath projectLocation) throws CoreException { // call for side effect of ensuring that the realm is set in the // descriptor. - IMaven mvn = MavenPlugin.getMaven(); - Mojo configuredMojo = + final IMaven mvn = MavenPlugin.getMaven(); + final Mojo configuredMojo = mvn.getConfiguredMojo(session, mojoExecution, Mojo.class); mvn.releaseMojo(configuredMojo, mojoExecution); return new ResourceResolver(mojoExecution.getMojoDescriptor() .getPluginDescriptor().getClassRealm(), projectLocation); } - private MavenPluginWrapper getMavenPlugin(IProgressMonitor monitor, + private MavenPluginWrapper getMavenPlugin(final IProgressMonitor monitor, final IMavenProjectFacade projectFacade) throws CoreException { return MavenPluginWrapper.newInstance(monitor, getMavenPluginGroupId(), getMavenPluginArtifactId(), getMavenPluginGoal(), diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java index b8d3369e..e11b693b 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java @@ -45,18 +45,20 @@ public List getMojoExecutions() { return executions; } - public static boolean mojoExecutionForPlugin(MojoExecution mojoExecution, - String groupId, String artifactId, String goal) { + public static boolean mojoExecutionForPlugin( + final MojoExecution mojoExecution, final String groupId, + final String artifactId, final String goal) { return groupId.equals(mojoExecution.getGroupId()) && artifactId.equals(mojoExecution.getArtifactId()) && (goal == null || goal.equals(mojoExecution.getGoal())); } public static List findMojoExecutions( - IProgressMonitor monitor, IMavenProjectFacade mavenProjectFacade, + final IProgressMonitor monitor, + final IMavenProjectFacade mavenProjectFacade, final String pluginGroupId, final String pluginArtifactId, final String[] pluginGoal) throws CoreException { - List mojoExecutions = + final List mojoExecutions = mavenProjectFacade.getMojoExecutions(pluginGroupId, pluginArtifactId, monitor, pluginGoal); // I don't think we need to re-search for site. @@ -66,11 +68,12 @@ public static List findMojoExecutions( private static List searchExecutions( final String pluginGroupId, final String pluginArtifactId, - final String[] pluginGoal, List mojoExecutions) { + final String[] pluginGoal, + final List mojoExecutions) { final List foundMojoExections = new ArrayList<>(); - for (MojoExecution mojoExecution : mojoExecutions) { + for (final MojoExecution mojoExecution : mojoExecutions) { if (pluginGoal != null) { - for (String goal : pluginGoal) { + for (final String goal : pluginGoal) { if (mojoExecutionForPlugin(mojoExecution, pluginGroupId, pluginArtifactId, goal)) { foundMojoExections.add(mojoExecution); @@ -86,15 +89,15 @@ private static List searchExecutions( return foundMojoExections; } - public static MavenPluginWrapper newInstance(IProgressMonitor monitor, + public static MavenPluginWrapper newInstance(final IProgressMonitor monitor, final String pluginGroupId, final String pluginArtifactId, - final String[] pluginGoal, IMavenProjectFacade mavenProjectFacade) - throws CoreException { + final String[] pluginGoal, + final IMavenProjectFacade mavenProjectFacade) throws CoreException { Preconditions.checkNotNull(mavenProjectFacade); final List executions = findMojoExecutions(monitor, mavenProjectFacade, pluginGroupId, pluginArtifactId, pluginGoal); - String key = pluginGroupId + ":" + pluginArtifactId; + final String key = pluginGroupId + ":" + pluginArtifactId; return new MavenPluginWrapper(key, executions); } diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 52986450..61b1572f 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -36,7 +36,8 @@ public final class ResourceResolver { private final ClassRealm pluginRealm; private final IPath projectLocation; - public ResourceResolver(ClassRealm pluginRealm, IPath projectLocation) { + public ResourceResolver(final ClassRealm pluginRealm, + final IPath projectLocation) { this.pluginRealm = pluginRealm; this.projectLocation = projectLocation; } @@ -61,7 +62,7 @@ public URL resolveLocation(final String location) { if (urlLocation.startsWith("/")) { urlLocation = urlLocation.substring(1); } - URL url = pluginRealm.getResource(urlLocation); + final URL url = pluginRealm.getResource(urlLocation); if (url != null) { return url; } @@ -69,29 +70,29 @@ public URL resolveLocation(final String location) { // 2. Try it as a remote resource. try { - URL url = new URL(location); + final URL url = new URL(location); // check if valid. url.openStream(); return url; - } catch (IOException ex) { + } catch (final IOException ex) { // ignored, try next } // 3. Try to see if it exists as a filesystem resource. - File file = new File(location); + final File file = new File(location); if (file.exists()) { try { return file.toURI().toURL(); - } catch (MalformedURLException ex) { + } catch (final MalformedURLException ex) { // ignored, try next } } - File projectFile = projectLocation.append(location).toFile(); + final File projectFile = projectLocation.append(location).toFile(); if (projectFile.exists()) { try { return projectFile.toURI().toURL(); - } catch (MalformedURLException ex) { + } catch (final MalformedURLException ex) { // ignored, try next } } From 3b30177ea69779f4bbea6b6e62b673b6707afdaa Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 14:59:44 +0100 Subject: [PATCH 046/153] Remove unused msg parameter --- .../quality/pmd/MavenPluginConfigurationTranslator.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java index 1d8041bd..44bb9a6c 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/MavenPluginConfigurationTranslator.java @@ -94,8 +94,7 @@ private List getExcludePatterns() throws CoreException { if (StringUtils.isBlank(p)) { continue; } - transformedPatterns - .add(this.getTransformedPattern(p, "EXCLUDE")); + transformedPatterns.add(this.getTransformedPattern(p)); } } return transformedPatterns; @@ -123,8 +122,7 @@ private List getIncludePatterns() throws CoreException { if (StringUtils.isBlank(p)) { continue; } - transformedPatterns - .add(this.getTransformedPattern(p, "INCLUDE")); + transformedPatterns.add(this.getTransformedPattern(p)); } } return transformedPatterns; @@ -160,8 +158,7 @@ public List getExcludes() { return ImmutableList.copyOf(this.excludePatterns); } - private String getTransformedPattern(final String antStylePattern, - final String msg) { + private String getTransformedPattern(final String antStylePattern) { String newPattern; if (PATTERNS_CACHE.containsKey(antStylePattern)) { newPattern = PATTERNS_CACHE.get(antStylePattern); From 1548e0b4d038c54d019d8e20767f98a8480fd845 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:01:37 +0100 Subject: [PATCH 047/153] Remove unnecessary usage of String.format --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 52146c03..67a4b6a2 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -96,8 +96,8 @@ public URL getRuleset() throws CheckstylePluginException, CoreException { final URL ruleset = this.resourceResolver.resolveLocation(this.getConfigLocation()); if (ruleset == null) { - throw new CheckstylePluginException(String.format( - "Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration")); + throw new CheckstylePluginException( + "Failed to resolve RuleSet from configLocation,SKIPPING Eclipse checkstyle configuration"); } return ruleset; } From cd6e29b8fcb1ed24e93fc4737eed4de1860c1751 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:03:56 +0100 Subject: [PATCH 048/153] Add logger --- .../checkstyle/MavenPluginConfigurationTranslator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 67a4b6a2..b4280be5 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -40,6 +40,8 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; @@ -57,6 +59,9 @@ */ public class MavenPluginConfigurationTranslator { + private static final Logger LOG = + LoggerFactory.getLogger(MavenPluginConfigurationTranslator.class); + private static final String CHECKSTYLE_DEFAULT_CONFIG_LOCATION = "config/sun_checks.xml"; private static final String CHECKSTYLE_DEFAULT_SUPPRESSIONS_FILE_EXPRESSION = From 170cc997566d2850b27878e416a8b39cc0bb37e1 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:04:07 +0100 Subject: [PATCH 049/153] Log IO exception --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index b4280be5..c0038d25 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -336,6 +336,7 @@ private void copyOut(final URL src, final File dest) try { FileUtils.copyURLToFile(src, dest); } catch (final IOException e) { + LOG.error("Could not copy file {}", src, e); throw new CheckstylePluginException( "Failed to copy file " + src.getFile() + ", SKIPPING Eclipse checkstyle configuration"); From e01373e4b9c7dc867afbe0906c434a1573b31606 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:04:31 +0100 Subject: [PATCH 050/153] Use isEmpty instead of size --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index c0038d25..f582ec3c 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -377,7 +377,7 @@ private List getIncludesExcludesFileMatchPatterns() for (final String folder : sourceFolders) { final String folderRelativePath = this.basedirUri .relativize(new File(folder).toURI()).getPath(); - if (includePatterns.size() != 0) { + if (!includePatterns.isEmpty()) { patterns.addAll( this.normalizePatternsToCheckstyleFileMatchPattern( includePatterns, folderRelativePath, true)); From 0c5604ef4ba52dec44aa2ab4fd025e7062407a0e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:11:17 +0100 Subject: [PATCH 051/153] Use Arrays.copyOf --- .../code/quality/findbugs/EclipseFindbugsConfigManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index dfd96551..81319bf9 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -20,6 +20,7 @@ import static com.basistech.m2e.code.quality.findbugs.FindbugsEclipseConstants.ECLIPSE_FB_PREFS_FILE; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.eclipse.core.resources.IProject; @@ -74,8 +75,7 @@ private void configureNature(final IProgressMonitor monitor) // We have to explicitly add the nature. final IProjectDescription desc = project.getDescription(); final String natures[] = desc.getNatureIds(); - final String newNatures[] = new String[natures.length + 1]; - System.arraycopy(natures, 0, newNatures, 0, natures.length); + final String newNatures[] = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = ECLIPSE_FB_NATURE_ID; desc.setNatureIds(newNatures); project.setDescription(desc, monitor); From 7cba2d1addd4a3198d925226875e1d957c618578 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:12:31 +0100 Subject: [PATCH 052/153] Move the array designator from the variable to the type --- .../quality/findbugs/EclipseFindbugsConfigManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index 81319bf9..ad89472e 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -74,8 +74,8 @@ private void configureNature(final IProgressMonitor monitor) final IProject project = this.fbNature.getProject(); // We have to explicitly add the nature. final IProjectDescription desc = project.getDescription(); - final String natures[] = desc.getNatureIds(); - final String newNatures[] = Arrays.copyOf(natures, natures.length + 1); + final String[] natures = desc.getNatureIds(); + final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = ECLIPSE_FB_NATURE_ID; desc.setNatureIds(newNatures); project.setDescription(desc, monitor); @@ -87,7 +87,7 @@ private void deconfigureNature(final IProgressMonitor monitor) // remove the nature itself, by resetting the nature list. final IProject project = this.fbNature.getProject(); final IProjectDescription desc = project.getDescription(); - final String natures[] = desc.getNatureIds(); + final String[] natures = desc.getNatureIds(); final List newNaturesList = new ArrayList<>(); for (int i = 0; i < natures.length; i++) { if (!ECLIPSE_FB_NATURE_ID.equals(natures[i])) { @@ -95,7 +95,7 @@ private void deconfigureNature(final IProgressMonitor monitor) } } - final String newNatures[] = + final String[] newNatures = newNaturesList.toArray(new String[newNaturesList.size()]); desc.setNatureIds(newNatures); project.setDescription(desc, monitor); From 3cd99abc135679ce5a0e06895b3f3c84e3c21d3f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:13:32 +0100 Subject: [PATCH 053/153] Immediately return expression --- .../code/quality/findbugs/EclipseFindbugsConfigManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java index ad89472e..a44ac5eb 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsConfigManager.java @@ -116,8 +116,6 @@ public static EclipseFindbugsConfigManager newInstance( Preconditions.checkNotNull(project); final FindBugsNature fbNature = new FindBugsNature(); fbNature.setProject(project); - final EclipseFindbugsConfigManager fbNatureExtended = - new EclipseFindbugsConfigManager(fbNature); - return fbNatureExtended; + return new EclipseFindbugsConfigManager(fbNature); } } From fe04df6961b39db50911bb9f142ff8cec888f291 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:14:15 +0100 Subject: [PATCH 054/153] Log exception --- .../quality/findbugs/EclipseFindbugsProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index b4b3c312..b0d64024 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -99,7 +99,7 @@ protected void handleProjectConfigurationChange( FindbugsPlugin.saveUserPreferences(project, prefs); FindbugsPlugin.setProjectSettingsEnabled(project, null, true); } catch (final CoreException ex) { - LOG.error(ex.getLocalizedMessage()); + LOG.error(ex.getLocalizedMessage(), ex); } } From 0f924acf3929b89b92018c90205be2c8ef943c27 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:17:56 +0100 Subject: [PATCH 055/153] Log exceptions --- .../MavenPluginConfigurationTranslator.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index 9530cf03..aa45e283 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -214,9 +214,9 @@ public void setEffort(final UserPreferences prefs) throws CoreException { try { prefs.setEffort(effort); } catch (final IllegalArgumentException ex) { - LOG.error(String.format( - "[%s]: could not set , reason [%s], setting it to default [%s]", - LOG_PREFIX, effort, UserPreferences.EFFORT_DEFAULT)); + LOG.error( + "{}: could not set , reason {}, setting it to default {}", + LOG_PREFIX, effort, UserPreferences.EFFORT_DEFAULT, ex); } } @@ -230,9 +230,9 @@ public void setMinRank(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinRank(minRank); } catch (final IllegalArgumentException ex) { - LOG.error(String.format( - "[%s]: could not set , reason [%s], setting it to default [%s]", - LOG_PREFIX, minRank, 15)); + LOG.error( + "{}: could not set , reason {}, setting it to default {}", + LOG_PREFIX, minRank, 15, ex); } } @@ -246,9 +246,9 @@ public void setPriority(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinPriority(priority); } catch (final Exception ex) { - LOG.error(String.format( - "[%s]: could not set , reason [%s], leaving it alone", - LOG_PREFIX, priority)); + LOG.error( + "{}: could not set , reason {}, leaving it alone", + LOG_PREFIX, priority, ex); } } @@ -285,9 +285,9 @@ public void setThreshold(final UserPreferences prefs) throws CoreException { try { prefs.getFilterSettings().setMinPriority(threshold); } catch (final Exception ex) { - LOG.error(String.format( - "[%s]: could not set , reason [%s], leaving it alone", - LOG_PREFIX, threshold)); + LOG.error( + "{}: could not set , reason {}, leaving it alone", + LOG_PREFIX, threshold, ex); } } From ee1f4e1e4ad699ebeb2a7439a42071362a9bdafa Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:18:41 +0100 Subject: [PATCH 056/153] Add exception as cause --- .../quality/findbugs/MavenPluginConfigurationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index aa45e283..acf151e9 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -351,7 +351,7 @@ private void copyUrlResourceToProject(final String resc, throw new ConfigurationException(String.format( "[%s]: could not copy resource [%s] to [%s], reason [%s]", LOG_PREFIX, resc, newLocationFile, - ex.getLocalizedMessage())); + ex.getLocalizedMessage()), ex); } } From 67caa3acff8afbd03f092d1841c13bc825d3193b Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 15:18:55 +0100 Subject: [PATCH 057/153] Immediately return expression --- .../findbugs/MavenPluginConfigurationTranslator.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java index acf151e9..56e644a2 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/MavenPluginConfigurationTranslator.java @@ -376,9 +376,7 @@ public static MavenPluginConfigurationTranslator newInstance( final MojoExecution execution = mojoExecutions.get(0); final ResourceResolver resourceResolver = configurator .getResourceResolver(execution, session, project.getLocation()); - final MavenPluginConfigurationTranslator m2csConverter = - new MavenPluginConfigurationTranslator(configurator, execution, - project, mavenProject, monitor, resourceResolver); - return m2csConverter; + return new MavenPluginConfigurationTranslator(configurator, execution, + project, mavenProject, monitor, resourceResolver); } } From 7dc612f27c501f90ba97150109efff2ad75079c5 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 16:09:11 +0100 Subject: [PATCH 058/153] Add slf4j to manifest --- com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF b/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF index 5186c4ed..71a3ddd4 100644 --- a/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF +++ b/com.basistech.m2e.code.quality.shared/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.m2e.jdt;bundle-version="[1.0.0,1.8.0)", org.eclipse.core.resources;bundle-version="3.4.0", org.eclipse.ui.console, org.eclipse.jdt.core;bundle-version="3.4.0", - org.eclipse.core.runtime;bundle-version="3.4.0" + org.eclipse.core.runtime;bundle-version="3.4.0", + org.slf4j.api;bundle-version="1.6.1" From 8cbd9ac767b4ed10e100207c561752c2fd5c5371 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 16:49:04 +0100 Subject: [PATCH 059/153] Add CheckstyleUtil with pattern conversion method --- .../quality/checkstyle/CheckstyleUtil.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java new file mode 100644 index 00000000..1c63af2b --- /dev/null +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java @@ -0,0 +1,71 @@ +package com.basistech.m2e.code.quality.checkstyle; + +import java.io.File; + +import com.google.common.base.Preconditions; + +public final class CheckstyleUtil { + + private CheckstyleUtil() { + } + + /** + * Helper to convert the maven-checkstyle-plugin includes/excludes pattern + * to eclipse checkstyle plugin pattern. + * + * @param pattern + * the maven-checkstyle-plugin pattern. + * @return the converted checkstyle eclipse pattern. + */ + public static String convertAntStylePatternToCheckstylePattern( + final String pattern) { + Preconditions.checkNotNull(pattern, "pattern cannot be null"); + Preconditions.checkArgument(!pattern.isEmpty(), "pattern cannot be empty"); + + String sanitizedPattern = pattern.replace( + File.separatorChar == '/' ? '\\' : '/', File.separatorChar); + final String dupeSeperatorChar = File.separator + File.separator; + while (sanitizedPattern.contains(dupeSeperatorChar)) { + sanitizedPattern = + sanitizedPattern.replace(dupeSeperatorChar, File.separator); + } + + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < sanitizedPattern.length(); ++i) { + final char curChar = sanitizedPattern.charAt(i); + char nextChar = '\0'; + char nextNextChar = '\0'; + if (i + 1 < sanitizedPattern.length()) { + nextChar = sanitizedPattern.charAt(i + 1); + } + if (i + 2 < sanitizedPattern.length()) { + nextNextChar = sanitizedPattern.charAt(i + 2); + } + + if (curChar == '*' && nextChar == '*' + && nextNextChar == File.separatorChar) { + sb.append(".*"); + ++i; + ++i; + } else if (curChar == '*') { + sb.append(".*"); + } else if (curChar == '.') { + sb.append("\\."); + } else { + sb.append(curChar); + } + } + String result = sb.toString(); + if (result.endsWith(File.separator)) { + result += ".*"; + } + + // cleanup the resulting regex pattern + while (result.contains(".*.*")) { + result = result.replace(".*.*", ".*"); + } + + return result; + } + +} From e86a9062e882eeb8710dc0ccb51b5835fcc8eb23 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 16:49:12 +0100 Subject: [PATCH 060/153] Add test for pattern conversion --- .../checkstyle/test/CheckstyleUtilTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 com.basistech.m2e.code.quality.checkstyle.test/src/main/java/com/basistech/m2e/code/quality/checkstyle/test/CheckstyleUtilTest.java diff --git a/com.basistech.m2e.code.quality.checkstyle.test/src/main/java/com/basistech/m2e/code/quality/checkstyle/test/CheckstyleUtilTest.java b/com.basistech.m2e.code.quality.checkstyle.test/src/main/java/com/basistech/m2e/code/quality/checkstyle/test/CheckstyleUtilTest.java new file mode 100644 index 00000000..bf6fc263 --- /dev/null +++ b/com.basistech.m2e.code.quality.checkstyle.test/src/main/java/com/basistech/m2e/code/quality/checkstyle/test/CheckstyleUtilTest.java @@ -0,0 +1,19 @@ +package com.basistech.m2e.code.quality.checkstyle.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.basistech.m2e.code.quality.checkstyle.CheckstyleUtil; + +public class CheckstyleUtilTest { + + @Test + public void testAntToCheckstyleConversion() throws Exception { + assertEquals(".*\\.java", CheckstyleUtil + .convertAntStylePatternToCheckstylePattern("**\\/*.java")); + assertEquals(".*\\.properties", CheckstyleUtil + .convertAntStylePatternToCheckstylePattern("**/*.properties")); + } + +} From 4a37611d2f4e769f9ed1e41a32a39b8881c86072 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 16:49:32 +0100 Subject: [PATCH 061/153] Use CheckstyleUtil --- .../MavenPluginConfigurationTranslator.java | 62 +------------------ 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index f582ec3c..ebbc2547 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -46,7 +46,6 @@ import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; import com.basistech.m2e.code.quality.shared.ResourceResolver; -import com.google.common.base.Preconditions; import net.sf.eclipsecs.core.config.ICheckConfiguration; import net.sf.eclipsecs.core.projectconfig.FileMatchPattern; @@ -524,7 +523,7 @@ private List getPatterns(final String elemName) if (PATTERNS_CACHE.containsKey(p)) { csPattern = PATTERNS_CACHE.get(p); } else { - csPattern = this.convertAntStylePatternToCheckstylePattern(p); + csPattern = CheckstyleUtil.convertAntStylePatternToCheckstylePattern(p); PATTERNS_CACHE.put(p, csPattern); } transformedPatterns.add(csPattern); @@ -532,65 +531,6 @@ private List getPatterns(final String elemName) return transformedPatterns; } - /** - * Helper to convert the maven-checkstyle-plugin includes/excludes pattern - * to eclipse checkstyle plugin pattern. - * - * @param pattern - * the maven-checkstyle-plugin pattern. - * @return the converted checkstyle eclipse pattern. - */ - private String convertAntStylePatternToCheckstylePattern( - final String pattern) { - Preconditions.checkNotNull(pattern, "pattern cannot be null"); - Preconditions.checkArgument(pattern.isEmpty(), "pattern cannot empty"); - - String sanitizedPattern = pattern.replace( - File.separatorChar == '/' ? '\\' : '/', File.separatorChar); - final String dupeSeperatorChar = File.separator + File.separator; - while (sanitizedPattern.contains(dupeSeperatorChar)) { - sanitizedPattern = - sanitizedPattern.replace(dupeSeperatorChar, File.separator); - } - - final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < sanitizedPattern.length(); ++i) { - final char curChar = sanitizedPattern.charAt(i); - char nextChar = '\0'; - char nextNextChar = '\0'; - if (i + 1 < sanitizedPattern.length()) { - nextChar = sanitizedPattern.charAt(i + 1); - } - if (i + 2 < sanitizedPattern.length()) { - nextNextChar = sanitizedPattern.charAt(i + 2); - } - - if (curChar == '*' && nextChar == '*' - && nextNextChar == File.separatorChar) { - sb.append(".*"); - ++i; - ++i; - } else if (curChar == '*') { - sb.append(".*"); - } else if (curChar == '.') { - sb.append("\\."); - } else { - sb.append(curChar); - } - } - String result = sb.toString(); - if (result.endsWith(File.separator)) { - result += ".*"; - } - - // cleanup the resulting regex pattern - while (result.contains(".*.*")) { - result = result.replace(".*.*", ".*"); - } - - return result; - } - public Properties getConfiguredProperties() throws CoreException, CheckstylePluginException { final String propertiesLocation = getPropertiesLocation(); From 3f2fd0d76617381da17ce3a724e34c40ec51a16c Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 16:50:06 +0100 Subject: [PATCH 062/153] Add some more stuff to checkstyle-2 --- .../checkstyle-2/src/main/java/App.java | 18 ++++++++++++++++++ .../checkstyle-2/src/main/javaApp.java | 18 ++++++++++++++++++ .../src/main/resources/test.properties | 1 + .../src/main/resourcestest.properties | 1 + 4 files changed, 38 insertions(+) create mode 100644 test-projects/checkstyle-2/src/main/java/App.java create mode 100644 test-projects/checkstyle-2/src/main/javaApp.java create mode 100644 test-projects/checkstyle-2/src/main/resources/test.properties create mode 100644 test-projects/checkstyle-2/src/main/resourcestest.properties diff --git a/test-projects/checkstyle-2/src/main/java/App.java b/test-projects/checkstyle-2/src/main/java/App.java new file mode 100644 index 00000000..59a6ac2a --- /dev/null +++ b/test-projects/checkstyle-2/src/main/java/App.java @@ -0,0 +1,18 @@ + + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} diff --git a/test-projects/checkstyle-2/src/main/javaApp.java b/test-projects/checkstyle-2/src/main/javaApp.java new file mode 100644 index 00000000..f40799f3 --- /dev/null +++ b/test-projects/checkstyle-2/src/main/javaApp.java @@ -0,0 +1,18 @@ +package cat; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} diff --git a/test-projects/checkstyle-2/src/main/resources/test.properties b/test-projects/checkstyle-2/src/main/resources/test.properties new file mode 100644 index 00000000..abd4b568 --- /dev/null +++ b/test-projects/checkstyle-2/src/main/resources/test.properties @@ -0,0 +1 @@ +Bla. \ No newline at end of file diff --git a/test-projects/checkstyle-2/src/main/resourcestest.properties b/test-projects/checkstyle-2/src/main/resourcestest.properties new file mode 100644 index 00000000..abd4b568 --- /dev/null +++ b/test-projects/checkstyle-2/src/main/resourcestest.properties @@ -0,0 +1 @@ +Bla. \ No newline at end of file From 8f0691ab5be739e46ac7a8c337a31bafed20fb36 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 17:02:49 +0100 Subject: [PATCH 063/153] Inline single-use constants --- .../code/quality/checkstyle/CheckstyleEclipseConstants.java | 4 ---- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleEclipseConstants.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleEclipseConstants.java index 3e5430ea..2db29ec6 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleEclipseConstants.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleEclipseConstants.java @@ -21,10 +21,6 @@ public final class CheckstyleEclipseConstants { public static final String LOG_PREFIX = "M2E-CS"; - public static final String MAVEN_PLUGIN_GROUPID = - "org.apache.maven.plugins"; - public static final String MAVEN_PLUGIN_ARTIFACTID = - "maven-checkstyle-plugin"; public static final String ECLIPSE_CS_PREFS_FILE = ".checkstyle"; public static final String ECLIPSE_CS_PREFS_CONFIG_NAME = "maven-checkstyle-plugin"; diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 92a9aa6d..57aaf30d 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -18,8 +18,6 @@ import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_CACHE_FILENAME; import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_PREFS_CONFIG_NAME; -import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.MAVEN_PLUGIN_ARTIFACTID; -import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.MAVEN_PLUGIN_GROUPID; import java.net.URL; import java.util.List; @@ -65,12 +63,12 @@ public EclipseCheckstyleProjectConfigurator() { @Override protected String getMavenPluginArtifactId() { - return MAVEN_PLUGIN_ARTIFACTID; + return "maven-checkstyle-plugin"; } @Override protected String getMavenPluginGroupId() { - return MAVEN_PLUGIN_GROUPID; + return "org.apache.maven.plugins"; } @Override From 872bfc583aa0631d4af186a4140d9558056cc883 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 17:04:59 +0100 Subject: [PATCH 064/153] Use a static for the remote type --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 57aaf30d..230d000c 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -54,7 +54,7 @@ public class EclipseCheckstyleProjectConfigurator private static final Logger LOG = LoggerFactory.getLogger(EclipseCheckstyleProjectConfigurator.class); - private final IConfigurationType remoteConfigurationType = + private static final IConfigurationType REMOTE_CONFIGURATION_TYPE = ConfigurationTypes.getByInternalName("remote"); public EclipseCheckstyleProjectConfigurator() { @@ -196,7 +196,7 @@ private ICheckConfiguration createOrGetCheckstyleConfig( .nullToEmpty(workingCopies); for (final CheckConfigurationWorkingCopy copy : workingCopies) { if (configName.equals(copy.getName())) { - if (this.remoteConfigurationType.equals(copy.getType())) { + if (REMOTE_CONFIGURATION_TYPE.equals(copy.getType())) { workingCopy = copy; break; } @@ -209,8 +209,7 @@ private ICheckConfiguration createOrGetCheckstyleConfig( // Nothing exist create a brand new one. if (workingCopy == null) { // Create a fresh check config - workingCopy = - workingSet.newWorkingCopy(this.remoteConfigurationType); + workingCopy = workingSet.newWorkingCopy(REMOTE_CONFIGURATION_TYPE); workingCopy.setName(configName); workingSet.addCheckConfiguration(workingCopy); } From dd02f7ae2c369270233bb9f7edebb8e3738c2f00 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 17:07:11 +0100 Subject: [PATCH 065/153] Make getMavenPluginGoal abstract --- .../shared/AbstractMavenPluginProjectConfigurator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 2662119d..7e4b798f 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -164,9 +164,7 @@ protected abstract void handleProjectConfigurationChange( * configurations. If more than one, this will process in order * looking for an execution. */ - protected String[] getMavenPluginGoal() { - return null; - } + protected abstract String[] getMavenPluginGoal(); /** * Unconfigure the associated Eclipse plugin. From cf50551fea49c207316cac14e633f21728dc7cbe Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 17:11:08 +0100 Subject: [PATCH 066/153] Rename getMavenPluginGoal to getMavenPluginGoals --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 2 +- .../quality/findbugs/EclipseFindbugsProjectConfigurator.java | 2 +- .../m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java | 2 +- .../shared/AbstractMavenPluginProjectConfigurator.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 230d000c..96a2c323 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -72,7 +72,7 @@ protected String getMavenPluginGroupId() { } @Override - protected String[] getMavenPluginGoal() { + protected String[] getMavenPluginGoals() { return new String[] {"checkstyle", "check"}; } diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index b0d64024..30206329 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -61,7 +61,7 @@ protected String getMavenPluginGroupId() { } @Override - protected String[] getMavenPluginGoal() { + protected String[] getMavenPluginGoals() { return new String[] {"findbugs", "check"}; } diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 68d1b77a..47b8cec4 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -87,7 +87,7 @@ protected String getMavenPluginArtifactId() { } @Override - protected String[] getMavenPluginGoal() { + protected String[] getMavenPluginGoals() { return new String[] {"check"}; } diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 7e4b798f..92262f35 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -164,7 +164,7 @@ protected abstract void handleProjectConfigurationChange( * configurations. If more than one, this will process in order * looking for an execution. */ - protected abstract String[] getMavenPluginGoal(); + protected abstract String[] getMavenPluginGoals(); /** * Unconfigure the associated Eclipse plugin. @@ -227,7 +227,7 @@ public ResourceResolver getResourceResolver( private MavenPluginWrapper getMavenPlugin(final IProgressMonitor monitor, final IMavenProjectFacade projectFacade) throws CoreException { return MavenPluginWrapper.newInstance(monitor, getMavenPluginGroupId(), - getMavenPluginArtifactId(), getMavenPluginGoal(), + getMavenPluginArtifactId(), getMavenPluginGoals(), projectFacade); } From e5de9984cf4eafe831ec6357996c64f70e028a37 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:35:43 +0100 Subject: [PATCH 067/153] Add logback to oomph setup --- m2e-code-quality.setup | 2 ++ 1 file changed, 2 insertions(+) diff --git a/m2e-code-quality.setup b/m2e-code-quality.setup index db9cb3f2..8fc23d0f 100644 --- a/m2e-code-quality.setup +++ b/m2e-code-quality.setup @@ -80,6 +80,8 @@ name="org.eclipse.m2e.sdk.feature.feature.group"/> + From e09f205eb643cbab6a8d5d0c169b31902ddfac78 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:36:55 +0100 Subject: [PATCH 068/153] Formatting --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 96a2c323..3ea44e29 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -127,11 +127,9 @@ protected void handleProjectConfigurationChange( @Override protected void unconfigureEclipsePlugin(final IProject project, final IProgressMonitor monitor) throws CoreException { - final EclipseCheckstyleConfigManager csPluginNature = EclipseCheckstyleConfigManager.newInstance(project); csPluginNature.deconfigure(monitor); - } private void buildCheckstyleConfiguration( From 8675922bb6862e8d01c5bed5c67fc762864da375 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:39:31 +0100 Subject: [PATCH 069/153] Initialize workingCopies to empty array if they're null --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 3ea44e29..0881a839 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Properties; -import org.apache.commons.lang3.ArrayUtils; import org.apache.maven.execution.MavenSession; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -190,8 +189,10 @@ private ICheckConfiguration createOrGetCheckstyleConfig( // Try to retrieve an existing checkstyle configuration to be updated CheckConfigurationWorkingCopy[] workingCopies = workingSet.getWorkingCopies(); - workingCopies = (CheckConfigurationWorkingCopy[]) ArrayUtils - .nullToEmpty(workingCopies); + if (workingCopies == null) { + LOG.error("The working copies are null"); + workingCopies = new CheckConfigurationWorkingCopy[0]; + } for (final CheckConfigurationWorkingCopy copy : workingCopies) { if (configName.equals(copy.getName())) { if (REMOTE_CONFIGURATION_TYPE.equals(copy.getType())) { From d55d102656dd7b05edcabd252856180d1cd88e89 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:40:27 +0100 Subject: [PATCH 070/153] Log events --- ...bstractMavenPluginProjectConfigurator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 92262f35..377bb153 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -34,6 +34,8 @@ import org.eclipse.m2e.core.project.MavenProjectChangedEvent; import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; @@ -47,6 +49,9 @@ public abstract class AbstractMavenPluginProjectConfigurator extends AbstractProjectConfigurator { + private static final Logger LOG = LoggerFactory + .getLogger(AbstractMavenPluginProjectConfigurator.class); + @Override public T getParameterValue(final MavenProject project, final String parameter, final Class asType, @@ -81,6 +86,7 @@ protected MojoExecution findForkedExecution(final MojoExecution primary, @Override public void configure(final ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException { + LOG.error("configure {} {}", request, monitor); final MavenProject mavenProject = request.getMavenProject(); if (mavenProject == null) { @@ -106,6 +112,25 @@ public void configure(final ProjectConfigurationRequest request, public void mavenProjectChanged( final MavenProjectChangedEvent mavenProjectChangedEvent, final IProgressMonitor monitor) throws CoreException { + if (LOG.isDebugEnabled()) { + switch (mavenProjectChangedEvent.getKind()) { + case MavenProjectChangedEvent.KIND_ADDED: + LOG.debug("mavenProjectChanged KIND_ADDED"); + break; + case MavenProjectChangedEvent.KIND_CHANGED: + LOG.debug("mavenProjectChanged KIND_CHANGED"); + break; + case MavenProjectChangedEvent.KIND_REMOVED: + LOG.debug("mavenProjectChanged KIND_REMOVED"); + break; + default: + LOG.debug("mavenProjectChanged {}", + mavenProjectChangedEvent.getKind()); + } + } + + + final IMavenProjectFacade mavenProjectFacade = mavenProjectChangedEvent.getMavenProject(); final MavenPluginWrapper pluginWrapper = From cdcf56b6de5c0637ec58c01c9da79d7d528b3c17 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:40:49 +0100 Subject: [PATCH 071/153] Whitespace removal --- .../basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java index 1c63af2b..e5c2c608 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java @@ -5,10 +5,10 @@ import com.google.common.base.Preconditions; public final class CheckstyleUtil { - + private CheckstyleUtil() { } - + /** * Helper to convert the maven-checkstyle-plugin includes/excludes pattern * to eclipse checkstyle plugin pattern. From ba1b2562c108a6aecc8f8a5cfcd33554379b3802 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:41:52 +0100 Subject: [PATCH 072/153] Add log output if we actually need additional search --- .../m2e/code/quality/shared/MavenPluginWrapper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java index e11b693b..737bb7db 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/MavenPluginWrapper.java @@ -23,11 +23,16 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; public class MavenPluginWrapper { + private static final Logger LOG = + LoggerFactory.getLogger(MavenPluginWrapper.class); + private final String key; // for toString private final List executions; @@ -86,6 +91,9 @@ private static List searchExecutions( } } } + if (foundMojoExections.size() != mojoExecutions.size()) { + LOG.debug("They are different. Additional search is necessary."); + } return foundMojoExections; } From 5e2c1f29360838309294e9d37676f8ca6ab4d160 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 18:43:03 +0100 Subject: [PATCH 073/153] Formatting --- .../basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java | 3 ++- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java index e5c2c608..f8961e4f 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/CheckstyleUtil.java @@ -20,7 +20,8 @@ private CheckstyleUtil() { public static String convertAntStylePatternToCheckstylePattern( final String pattern) { Preconditions.checkNotNull(pattern, "pattern cannot be null"); - Preconditions.checkArgument(!pattern.isEmpty(), "pattern cannot be empty"); + Preconditions.checkArgument(!pattern.isEmpty(), + "pattern cannot be empty"); String sanitizedPattern = pattern.replace( File.separatorChar == '/' ? '\\' : '/', File.separatorChar); diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index ebbc2547..e7fa9754 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -523,7 +523,8 @@ private List getPatterns(final String elemName) if (PATTERNS_CACHE.containsKey(p)) { csPattern = PATTERNS_CACHE.get(p); } else { - csPattern = CheckstyleUtil.convertAntStylePatternToCheckstylePattern(p); + csPattern = CheckstyleUtil + .convertAntStylePatternToCheckstylePattern(p); PATTERNS_CACHE.put(p, csPattern); } transformedPatterns.add(csPattern); From 07444e5e62e04500c370f736a1a5d9cf616a3fdb Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 20:52:16 +0100 Subject: [PATCH 074/153] Use eclipse-cs.sf.net as update site --- mars/mars.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mars/mars.target b/mars/mars.target index e6b353bb..10b5ad01 100644 --- a/mars/mars.target +++ b/mars/mars.target @@ -20,7 +20,7 @@ - + From eda4ebb90b73baeab9f2a4a865d92a81663140b6 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 20:52:36 +0100 Subject: [PATCH 075/153] Use latest eclipse-cs version --- mars/mars.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mars/mars.target b/mars/mars.target index 10b5ad01..2e951c7c 100644 --- a/mars/mars.target +++ b/mars/mars.target @@ -19,7 +19,7 @@ - + From 50bf15ad7c2f29e91705f39703f1e5c2eec2138d Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 26 Feb 2016 20:59:46 +0100 Subject: [PATCH 076/153] Set version of JDT --- mars/mars.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mars/mars.target b/mars/mars.target index 2e951c7c..6bc27490 100644 --- a/mars/mars.target +++ b/mars/mars.target @@ -2,7 +2,7 @@ - + From abafac980d0e8dd941cc76e9ad9646e6192c5ec9 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 10:46:43 +0100 Subject: [PATCH 077/153] Add findbugs-maven-plugin --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 97b274ff..63bf933c 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,18 @@ + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.3 + + + + findbugs + + + + From 065e1e193344f36861f809c61d28b671e2238135 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 11:01:22 +0100 Subject: [PATCH 078/153] tycho-version:0.22 -> 0.24 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 63bf933c..8f50fe58 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ mars - 0.22.0 + 0.24.0 R20140525021250 ${basedir} From 5f3d607fa04cda41c65a8c5005868e9b5992eafc Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 11:03:49 +0100 Subject: [PATCH 079/153] Orbit R20140525021250 -> R20160221192158 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f50fe58..d567e3cd 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ mars 0.24.0 - R20140525021250 + R20160221192158 ${basedir} UTF-8 From 0980d602f998de3817bc257edc7372300d3dd22a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 11:06:39 +0100 Subject: [PATCH 080/153] maven-jarsigner-plugin:1.3.2 -> 1.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d567e3cd..158bdc4f 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ org.apache.maven.plugins maven-jarsigner-plugin - 1.3.2 + 1.4 sign From fc0f03eb01bca6ad9ecdf8ed8401f9f2c2cc6955 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 11:30:41 +0100 Subject: [PATCH 081/153] Consistently indent throws declarations --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 4 ++-- .../checkstyle/MavenPluginConfigurationTranslator.java | 6 +++--- .../findbugs/EclipseFindbugsProjectConfigurator.java | 2 +- .../m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java | 6 +++--- .../shared/AbstractMavenPluginProjectConfigurator.java | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 0881a839..d8ec225a 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -134,7 +134,7 @@ protected void unconfigureEclipsePlugin(final IProject project, private void buildCheckstyleConfiguration( final ProjectConfigurationWorkingCopy pcWorkingCopy, final MavenPluginConfigurationTranslator cfgTranslator) - throws CheckstylePluginException, CoreException { + throws CheckstylePluginException, CoreException { // get the ruleset from configLocation final URL ruleset = cfgTranslator.getRuleset(); // build or get the checkconfig @@ -178,7 +178,7 @@ private void buildCheckstyleConfiguration( private ICheckConfiguration createOrGetCheckstyleConfig( final ProjectConfigurationWorkingCopy pcWorkingCopy, final URL ruleset, final String executionId) - throws CheckstylePluginException { + throws CheckstylePluginException { final String configName = ECLIPSE_CS_PREFS_CONFIG_NAME + " " + executionId; final ICheckConfigurationWorkingSet workingSet = diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index e7fa9754..b6325851 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -159,7 +159,7 @@ public String getSuppressionsFileExpression() public void updateCheckConfigWithIncludeExcludePatterns( final ProjectConfigurationWorkingCopy pcWorkingCopy, final ICheckConfiguration checkCfg) - throws CheckstylePluginException, CoreException { + throws CheckstylePluginException, CoreException { final FileSet fs = new FileSet("java-sources-" + getExecutionId(), checkCfg); fs.setEnabled(true); @@ -483,7 +483,7 @@ private String convertToEclipseCheckstyleRegExpPath(final String path) { private List normalizePatternsToCheckstyleFileMatchPattern( final List patterns, final String relativePath, final boolean setIsIncludePatternFlag) - throws CheckstylePluginException { + throws CheckstylePluginException { final List fileMatchPatterns = new LinkedList<>(); for (final String p : patterns) { final FileMatchPattern fmp = new FileMatchPattern( @@ -578,7 +578,7 @@ public static List newInstance( final MavenProject mavenProject, final MavenPluginWrapper mavenPlugin, final IProject project, final IProgressMonitor monitor, final MavenSession session) - throws CoreException { + throws CoreException { final List m2csConverters = new ArrayList<>(); for (final MojoExecution execution : mavenPlugin.getMojoExecutions()) { diff --git a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java index 30206329..cc300b4b 100644 --- a/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.findbugs/src/main/java/com/basistech/m2e/code/quality/findbugs/EclipseFindbugsProjectConfigurator.java @@ -115,7 +115,7 @@ protected void unconfigureEclipsePlugin(final IProject project, private UserPreferences buildFindbugsPreferences( final MavenPluginConfigurationTranslator pluginCfgTranslator) - throws CoreException { + throws CoreException { LOG.debug("entering buildFindbugsPreferences"); final UserPreferences prefs = UserPreferences.createDefaultUserPreferences(); diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index 47b8cec4..c05618e5 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -181,7 +181,7 @@ private void createOrUpdateEclipsePmdConfiguration( final MavenPluginWrapper pluginWrapper, final IProject project, final MavenPluginConfigurationTranslator pluginCfgTranslator, final IProgressMonitor monitor, final MavenSession session) - throws CoreException { + throws CoreException { final MojoExecution execution = findMojoExecution(pluginWrapper); final ResourceResolver resourceResolver = this @@ -218,7 +218,7 @@ private void createOrUpdateEclipsePmdConfiguration( private RuleSet createPmdRuleSet( final MavenPluginConfigurationTranslator pluginCfgTranslator, final ResourceResolver resourceResolver) - throws CoreException, PMDException { + throws CoreException, PMDException { final RuleSet ruleSet = new RuleSet(); ruleSet.setName("M2Eclipse PMD RuleSet"); @@ -246,7 +246,7 @@ private RuleSet createPmdRuleSet( @Override public InputStream getInputStream( final ClassLoader arg0) - throws RuleSetNotFoundException { + throws RuleSetNotFoundException { try { return resolvedLocation.openStream(); } catch (final IOException e) { diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 377bb153..c2d8c9ef 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -56,7 +56,7 @@ public abstract class AbstractMavenPluginProjectConfigurator public T getParameterValue(final MavenProject project, final String parameter, final Class asType, final MojoExecution mojoExecution, final IProgressMonitor monitor) - throws CoreException { + throws CoreException { return super.getParameterValue(project, parameter, asType, mojoExecution, monitor); } @@ -167,7 +167,7 @@ protected abstract void handleProjectConfigurationChange( final IMavenProjectFacade mavenProjectFacade, final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper, MavenSession session) - throws CoreException; + throws CoreException; /** * Get the maven plugin {@code groupId}. @@ -219,7 +219,7 @@ protected abstract void unconfigureEclipsePlugin(final IProject project, private boolean checkUnconfigurationRequired(final IProgressMonitor monitor, final IMavenProjectFacade curMavenProjectFacade, final IMavenProjectFacade oldMavenProjectFacade) - throws CoreException { + throws CoreException { Preconditions.checkNotNull(curMavenProjectFacade); if (oldMavenProjectFacade == null) { From f6e035cf47d5ff368942ef8c3c81de09fe495cad Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 13:01:40 +0100 Subject: [PATCH 082/153] Formatting --- .../quality/shared/AbstractMavenPluginProjectConfigurator.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index c2d8c9ef..abdce7ae 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -129,8 +129,6 @@ public void mavenProjectChanged( } } - - final IMavenProjectFacade mavenProjectFacade = mavenProjectChangedEvent.getMavenProject(); final MavenPluginWrapper pluginWrapper = From d73912dac87035d1a9176c2357374b879788b672 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 13:27:54 +0100 Subject: [PATCH 083/153] Check that pluginRealm and projectLocation are not null --- .../basistech/m2e/code/quality/shared/ResourceResolver.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 61b1572f..105f9be5 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -24,6 +24,8 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.eclipse.core.runtime.IPath; +import com.google.common.base.Preconditions; + /** * A utility class to resolve resources, which includes searching in resources * specified with the {@literal } of the Maven pluginWrapper @@ -38,6 +40,8 @@ public final class ResourceResolver { public ResourceResolver(final ClassRealm pluginRealm, final IPath projectLocation) { + Preconditions.checkNotNull(pluginRealm); + Preconditions.checkNotNull(projectLocation); this.pluginRealm = pluginRealm; this.projectLocation = projectLocation; } From e8466fdb34ff68f4f00b25cd17fb10423390741e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 13:28:57 +0100 Subject: [PATCH 084/153] Add logger --- .../basistech/m2e/code/quality/shared/ResourceResolver.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 105f9be5..19008362 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -23,6 +23,8 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.eclipse.core.runtime.IPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; @@ -35,6 +37,9 @@ */ public final class ResourceResolver { + private static final Logger LOG = + LoggerFactory.getLogger(ResourceResolver.class); + private final ClassRealm pluginRealm; private final IPath projectLocation; From 0b813a607ab6d5e74be434b157a8c40f1dbbf25f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 13:29:28 +0100 Subject: [PATCH 085/153] Split resolveLocation into multiple methods --- .../code/quality/shared/ResourceResolver.java | 85 +++++++++++-------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 19008362..65073386 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -18,8 +18,11 @@ import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.eclipse.core.runtime.IPath; @@ -64,49 +67,63 @@ public ResourceResolver(final ClassRealm pluginRealm, * @return the {@code URL} of the resolved location or {@code null}. */ public URL resolveLocation(final String location) { - // 1. Try it as a resource first. - if (pluginRealm != null) { - String urlLocation = location; - // note that class loaders don't want leading slashes. - if (urlLocation.startsWith("/")) { - urlLocation = urlLocation.substring(1); - } - final URL url = pluginRealm.getResource(urlLocation); - if (url != null) { - return url; - } + if (location == null || location.isEmpty()) { + return null; + } + URL url = getResourceFromPluginRealm(location); + if (url == null) { + url = getResourceFromRemote(location); + } + if (url == null) { + url = getResourceFromFileSystem(location); + } + if (url == null) { + url = getResourceRelativeFromProjectLocation(location); } + return url; + } + + public URL getResourceFromPluginRealm(final String resource) { + if (resource.startsWith("/")) { + // ClassLoaders don't want leading slashes + return pluginRealm.getResource(resource.substring(1)); + } else { + return pluginRealm.getResource(resource); + } + } - // 2. Try it as a remote resource. + public URL getResourceFromRemote(final String resource) { try { - final URL url = new URL(location); - // check if valid. - url.openStream(); - return url; - } catch (final IOException ex) { - // ignored, try next + return new URL(resource); + } catch (final IOException e) { + LOG.trace("Could not open resource {} from remote", resource, e); } + return null; + } - // 3. Try to see if it exists as a filesystem resource. - final File file = new File(location); - if (file.exists()) { - try { - return file.toURI().toURL(); - } catch (final MalformedURLException ex) { - // ignored, try next + public URL getResourceFromFileSystem(final String resource) { + try { + final Path path = Paths.get(resource); + if (Files.exists(path)) { + return path.toUri().toURL(); } + } catch (InvalidPathException | IOException e) { + LOG.trace("Could not open resource {} from file system", resource, + e); } + return null; + } - final File projectFile = projectLocation.append(location).toFile(); - if (projectFile.exists()) { - try { - return projectFile.toURI().toURL(); - } catch (final MalformedURLException ex) { - // ignored, try next + public URL getResourceRelativeFromProjectLocation(final String resource) { + try { + final File file = projectLocation.append(resource).toFile(); + if (file.exists()) { + return file.toURI().toURL(); } + } catch (final IOException e) { + LOG.trace("Could not open resource {} relative to project location", + resource, e); } - - // 4. null return null; } From 6e23075ae7b5b13e01acc3cfe0919dd4a78d1f17 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:12:15 +0100 Subject: [PATCH 086/153] Log the current project --- ...bstractMavenPluginProjectConfigurator.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index abdce7ae..80f72dc6 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -86,7 +86,7 @@ protected MojoExecution findForkedExecution(final MojoExecution primary, @Override public void configure(final ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException { - LOG.error("configure {} {}", request, monitor); + LOG.error("configure {}", request.getProject()); final MavenProject mavenProject = request.getMavenProject(); if (mavenProject == null) { @@ -112,29 +112,29 @@ public void configure(final ProjectConfigurationRequest request, public void mavenProjectChanged( final MavenProjectChangedEvent mavenProjectChangedEvent, final IProgressMonitor monitor) throws CoreException { + final IMavenProjectFacade mavenProjectFacade = + mavenProjectChangedEvent.getMavenProject(); + final MavenPluginWrapper pluginWrapper = + this.getMavenPlugin(monitor, mavenProjectFacade); + final IProject project = mavenProjectFacade.getProject(); + if (LOG.isDebugEnabled()) { switch (mavenProjectChangedEvent.getKind()) { case MavenProjectChangedEvent.KIND_ADDED: - LOG.debug("mavenProjectChanged KIND_ADDED"); + LOG.debug("mavenProjectChanged {}: KIND_ADDED", project); break; case MavenProjectChangedEvent.KIND_CHANGED: - LOG.debug("mavenProjectChanged KIND_CHANGED"); + LOG.debug("mavenProjectChanged {}: KIND_CHANGED", project); break; case MavenProjectChangedEvent.KIND_REMOVED: - LOG.debug("mavenProjectChanged KIND_REMOVED"); + LOG.debug("mavenProjectChanged {}: KIND_REMOVED", project); break; default: - LOG.debug("mavenProjectChanged {}", + LOG.debug("mavenProjectChanged {}: {}", project, mavenProjectChangedEvent.getKind()); } } - final IMavenProjectFacade mavenProjectFacade = - mavenProjectChangedEvent.getMavenProject(); - final MavenPluginWrapper pluginWrapper = - this.getMavenPlugin(monitor, mavenProjectFacade); - final IProject project = mavenProjectFacade.getProject(); - if (this.checkUnconfigurationRequired(monitor, mavenProjectFacade, mavenProjectChangedEvent.getOldMavenProject())) { this.unconfigureEclipsePlugin(project, monitor); From b6431ce0fb2a0fe93a8c7735069931f78586a87f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:14:34 +0100 Subject: [PATCH 087/153] Change log level to debug --- .../quality/shared/AbstractMavenPluginProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 80f72dc6..8909d951 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -86,7 +86,7 @@ protected MojoExecution findForkedExecution(final MojoExecution primary, @Override public void configure(final ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException { - LOG.error("configure {}", request.getProject()); + LOG.debug("configure {}", request.getProject()); final MavenProject mavenProject = request.getMavenProject(); if (mavenProject == null) { From 14b0f27e38e9fa884348fb7d8522e2a6decd4fa9 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:33:58 +0100 Subject: [PATCH 088/153] Use isEmpty instead of size --- .../m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java index c05618e5..1f98d8f5 100644 --- a/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.pmd/src/main/java/com/basistech/m2e/code/quality/pmd/EclipsePmdProjectConfigurator.java @@ -314,7 +314,7 @@ private void buildAndAddPmdExcludeAndIncludePatternToRuleSet( // 1. check to see if any includes are specified. If they are then // to line up with the behavior of maven-pmd-plugin, excludes // don't make any sense at all or more specifically it is (ignored). - final boolean includesSpecified = includePatterns.size() > 0; + final boolean includesSpecified = !includePatterns.isEmpty(); final Set excludeRootsSet = new HashSet<>(); excludeRootsSet.addAll(excludeRoots); From 7484c57bd7821fe41199dc87cc4e486552872533 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:36:50 +0100 Subject: [PATCH 089/153] Use addNature helper method --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index d8ec225a..aafd71b7 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -41,6 +41,7 @@ import net.sf.eclipsecs.core.config.ResolvableProperty; import net.sf.eclipsecs.core.config.configtypes.ConfigurationTypes; import net.sf.eclipsecs.core.config.configtypes.IConfigurationType; +import net.sf.eclipsecs.core.nature.CheckstyleNature; import net.sf.eclipsecs.core.projectconfig.ProjectConfigurationFactory; import net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy; import net.sf.eclipsecs.core.util.CheckstylePluginException; @@ -106,8 +107,7 @@ protected void handleProjectConfigurationChange( if (mavenCheckstyleConfig.isActive()) { this.buildCheckstyleConfiguration(pcWorkingCopy, mavenCheckstyleConfig); - // Add the builder and nature - csPluginNature.configure(monitor); + addNature(project, CheckstyleNature.NATURE_ID, monitor); } else { csPluginNature.deconfigure(monitor); } From 6799a2d5c23320e8cea90a5f178f9854e66b2638 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:37:43 +0100 Subject: [PATCH 090/153] Remove unnecessary configure method --- .../EclipseCheckstyleConfigManager.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index 9b587fe9..da0c267a 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -45,12 +45,6 @@ private EclipseCheckstyleConfigManager(final CheckstyleNature csNature) { this.csNature = csNature; } - public void configure(final IProgressMonitor monitor) throws CoreException { - // this adds the builder only. - this.csNature.configure(); - this.configureNature(monitor); - } - public void deconfigure(final IProgressMonitor monitor) throws CoreException { // this removes the builder only. @@ -60,18 +54,6 @@ public void deconfigure(final IProgressMonitor monitor) this.deleteEclipseFiles(monitor); } - private void configureNature(final IProgressMonitor monitor) - throws CoreException { - final IProject project = this.csNature.getProject(); - // We have to explicitly add the nature. - final IProjectDescription desc = project.getDescription(); - final String[] natures = desc.getNatureIds(); - final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); - newNatures[natures.length] = CheckstyleNature.NATURE_ID; - desc.setNatureIds(newNatures); - project.setDescription(desc, monitor); - } - private void deconfigureNature(final IProgressMonitor monitor) throws CoreException { // remove the nature itself, by resetting the nature list. From 9cc0b77fb4d94ff2eaae303598c107f4ce548c22 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:38:00 +0100 Subject: [PATCH 091/153] Formatting --- .../code/quality/checkstyle/EclipseCheckstyleConfigManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java index da0c267a..fd8f3ac0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java @@ -81,7 +81,6 @@ private void deleteEclipseFiles(final IProgressMonitor monitor) final IResource checkstyleCacheFileResource = project.getFile(ECLIPSE_CS_CACHE_FILENAME); checkstyleCacheFileResource.delete(IResource.FORCE, monitor); - } public static EclipseCheckstyleConfigManager newInstance( From ce837391cd837984c735cd314d98ad5345df7f20 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:52:38 +0100 Subject: [PATCH 092/153] Add removeNature helper method --- ...bstractMavenPluginProjectConfigurator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 8909d951..3330794e 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -16,6 +16,8 @@ ******************************************************************************/ package com.basistech.m2e.code.quality.shared; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -25,6 +27,8 @@ import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -52,6 +56,27 @@ public abstract class AbstractMavenPluginProjectConfigurator private static final Logger LOG = LoggerFactory .getLogger(AbstractMavenPluginProjectConfigurator.class); + public static void removeNature(final IProject project, + final String natureId, final IProgressMonitor monitor) + throws CoreException { + removeNature(project, natureId, IResource.KEEP_HISTORY, monitor); + } + + public static void removeNature(final IProject project, + final String natureId, final int updateFlags, + final IProgressMonitor monitor) throws CoreException { + if (project.hasNature(natureId)) { + final IProjectDescription description = project.getDescription(); + final String[] prevNatures = description.getNatureIds(); + final List natures = + new ArrayList<>(Arrays.asList(prevNatures)); + natures.remove(natureId); + final String[] newNatures = natures.toArray(new String[0]); + description.setNatureIds(newNatures); + project.setDescription(description, updateFlags, monitor); + } + } + @Override public T getParameterValue(final MavenProject project, final String parameter, final Class asType, From 9fcff264d7ee30389982f64e431004dc6ef9e0a3 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:53:42 +0100 Subject: [PATCH 093/153] Add deleteEclipseFiles method --- .../EclipseCheckstyleProjectConfigurator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index aafd71b7..aa205f65 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -18,6 +18,7 @@ import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_CACHE_FILENAME; import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_PREFS_CONFIG_NAME; +import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_PREFS_FILE; import java.net.URL; import java.util.List; @@ -26,6 +27,7 @@ import org.apache.maven.execution.MavenSession; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.project.IMavenProjectFacade; @@ -123,6 +125,15 @@ protected void handleProjectConfigurationChange( } } + private void deleteEclipseFiles(final IProject project, + final IProgressMonitor monitor) throws CoreException { + final IResource checkstyleFile = project.getFile(ECLIPSE_CS_PREFS_FILE); + checkstyleFile.delete(IResource.FORCE, monitor); + final IResource checkstyleCacheFileResource = + project.getFile(ECLIPSE_CS_CACHE_FILENAME); + checkstyleCacheFileResource.delete(IResource.FORCE, monitor); + } + @Override protected void unconfigureEclipsePlugin(final IProject project, final IProgressMonitor monitor) throws CoreException { From 8f18ce79df75ea8d60a138678e0cd4063fdab1c9 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:54:44 +0100 Subject: [PATCH 094/153] Call deleteEclipseFiles and removeNature directly --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index aa205f65..9a46d92d 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -111,7 +111,8 @@ protected void handleProjectConfigurationChange( mavenCheckstyleConfig); addNature(project, CheckstyleNature.NATURE_ID, monitor); } else { - csPluginNature.deconfigure(monitor); + deleteEclipseFiles(project, monitor); + removeNature(project, CheckstyleNature.NATURE_ID, monitor); } } From 95c9dae9bfd404ea66ac955ee7a89bd4aaeb09a8 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:55:37 +0100 Subject: [PATCH 095/153] Call deleteEclipseFiles and removeNature directly --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 9a46d92d..5cf895c2 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -138,9 +138,8 @@ private void deleteEclipseFiles(final IProject project, @Override protected void unconfigureEclipsePlugin(final IProject project, final IProgressMonitor monitor) throws CoreException { - final EclipseCheckstyleConfigManager csPluginNature = - EclipseCheckstyleConfigManager.newInstance(project); - csPluginNature.deconfigure(monitor); + deleteEclipseFiles(project, monitor); + removeNature(project, CheckstyleNature.NATURE_ID, monitor); } private void buildCheckstyleConfiguration( From 5e1f8d62a7a9ae4026b0d5580ea46833d3cfb13e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:56:00 +0100 Subject: [PATCH 096/153] Remove unnecessary instantiation of EclipseCheckstyleConfigManager --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index 5cf895c2..ebdda707 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -91,9 +91,6 @@ protected void handleProjectConfigurationChange( mavenPluginWrapper, project, monitor, session); try { - final EclipseCheckstyleConfigManager csPluginNature = - EclipseCheckstyleConfigManager.newInstance(project); - // construct a new working copy final ProjectConfigurationWorkingCopy pcWorkingCopy = new ProjectConfigurationWorkingCopy( From 9cb8052e9dee8639997c6091648da2360ff0e5f1 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 15:56:07 +0100 Subject: [PATCH 097/153] Remove EclipseCheckstyleConfigManager --- .../EclipseCheckstyleConfigManager.java | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java deleted file mode 100644 index fd8f3ac0..00000000 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleConfigManager.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright 2010 Mohan KR - * Copyright 2010 Basis Technology Corp. - * - * 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.basistech.m2e.code.quality.checkstyle; - -import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_CACHE_FILENAME; -import static com.basistech.m2e.code.quality.checkstyle.CheckstyleEclipseConstants.ECLIPSE_CS_PREFS_FILE; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import com.google.common.base.Preconditions; - -import net.sf.eclipsecs.core.nature.CheckstyleNature; - -/** - * An extension of the {@code Checkstyle} class to add missing functionality. - * - */ -public class EclipseCheckstyleConfigManager { - - private final CheckstyleNature csNature; - - private EclipseCheckstyleConfigManager(final CheckstyleNature csNature) { - this.csNature = csNature; - } - - public void deconfigure(final IProgressMonitor monitor) - throws CoreException { - // this removes the builder only. - this.csNature.deconfigure(); - this.deconfigureNature(monitor); - // remove all eclipse checkstyle files. - this.deleteEclipseFiles(monitor); - } - - private void deconfigureNature(final IProgressMonitor monitor) - throws CoreException { - // remove the nature itself, by resetting the nature list. - final IProject project = this.csNature.getProject(); - final IProjectDescription desc = project.getDescription(); - final String[] natures = desc.getNatureIds(); - final List newNaturesList = new ArrayList<>(); - for (final String nature : natures) { - if (!CheckstyleNature.NATURE_ID.equals(nature)) { - newNaturesList.add(nature); - } - } - - final String[] newNatures = - newNaturesList.toArray(new String[newNaturesList.size()]); - desc.setNatureIds(newNatures); - project.setDescription(desc, monitor); - } - - private void deleteEclipseFiles(final IProgressMonitor monitor) - throws CoreException { - final IProject project = this.csNature.getProject(); - final IResource checkstyleFile = project.getFile(ECLIPSE_CS_PREFS_FILE); - checkstyleFile.delete(IResource.FORCE, monitor); - final IResource checkstyleCacheFileResource = - project.getFile(ECLIPSE_CS_CACHE_FILENAME); - checkstyleCacheFileResource.delete(IResource.FORCE, monitor); - } - - public static EclipseCheckstyleConfigManager newInstance( - final IProject project) { - Preconditions.checkNotNull(project); - final CheckstyleNature csNature = new CheckstyleNature(); - csNature.setProject(project); - return new EclipseCheckstyleConfigManager(csNature); - } -} From 309614481f5a1840b2fa87a080393d0b2a89475c Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:20:47 +0100 Subject: [PATCH 098/153] Make method static --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- .../shared/AbstractMavenPluginProjectConfigurator.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index b6325851..56dc81a4 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -583,8 +583,8 @@ public static List newInstance( new ArrayList<>(); for (final MojoExecution execution : mavenPlugin.getMojoExecutions()) { final ResourceResolver resourceResolver = - configurator.getResourceResolver(execution, session, - project.getLocation()); + AbstractMavenPluginProjectConfigurator.getResourceResolver( + execution, session, project.getLocation()); m2csConverters.add(new MavenPluginConfigurationTranslator( configurator, mavenProject, execution, project, monitor, resourceResolver)); diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 3330794e..f8656bbc 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -259,7 +259,7 @@ private boolean checkUnconfigurationRequired(final IProgressMonitor monitor, return false; } - public ResourceResolver getResourceResolver( + public static ResourceResolver getResourceResolver( final MojoExecution mojoExecution, final MavenSession session, final IPath projectLocation) throws CoreException { // call for side effect of ensuring that the realm is set in the From c0922790de89e63ee721aebb44ba44cb86376848 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:27:07 +0100 Subject: [PATCH 099/153] Add AbstractMavenPluginConfigurationTranslator --- ...actMavenPluginConfigurationTranslator.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java new file mode 100644 index 00000000..b9b10e3c --- /dev/null +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java @@ -0,0 +1,46 @@ +package com.basistech.m2e.code.quality.shared; + +import org.apache.maven.model.ConfigurationContainer; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.m2e.core.embedder.IMaven; + +public class AbstractMavenPluginConfigurationTranslator { + + private final IMaven maven; + private final MavenProject project; + private final MojoExecution mojoExecution; + private final IProgressMonitor monitor; + private final ConfigurationContainer execution; + + public AbstractMavenPluginConfigurationTranslator(final IMaven maven, + final MavenProject project, final MojoExecution mojoExecution, + final IProgressMonitor monitor) { + this.maven = maven; + this.project = project; + this.mojoExecution = mojoExecution; + this.monitor = monitor; + execution = new PluginExecution(); + execution.setConfiguration(mojoExecution.getConfiguration()); + } + + public T getParameterValue(final String parameter, + final Class asType) throws CoreException { + return maven.getMojoParameterValue(project, parameter, asType, + mojoExecution.getPlugin(), execution, mojoExecution.getGoal(), + monitor); + } + + public T getParameterValue(final String parameter, + final Class asType, final T defaultValue) throws CoreException { + final T parameterValue = getParameterValue(parameter, asType); + if (parameterValue == null) { + return defaultValue; + } + return parameterValue; + } + +} From 365fa2bea28addb362f3f4dc868fe55f4cfa636b Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:28:11 +0100 Subject: [PATCH 100/153] Extend AbstractMavenPluginConfigurationTranslator --- .../MavenPluginConfigurationTranslator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 56dc81a4..32eb3b01 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -40,9 +40,11 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.m2e.core.embedder.IMaven; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.basistech.m2e.code.quality.shared.AbstractMavenPluginConfigurationTranslator; import com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator; import com.basistech.m2e.code.quality.shared.MavenPluginWrapper; import com.basistech.m2e.code.quality.shared.ResourceResolver; @@ -56,7 +58,8 @@ /** * Utility class to get checkstyle plugin configuration. */ -public class MavenPluginConfigurationTranslator { +public class MavenPluginConfigurationTranslator + extends AbstractMavenPluginConfigurationTranslator { private static final Logger LOG = LoggerFactory.getLogger(MavenPluginConfigurationTranslator.class); @@ -76,11 +79,12 @@ public class MavenPluginConfigurationTranslator { private final MojoExecution execution; private final IProgressMonitor monitor; - private MavenPluginConfigurationTranslator( + private MavenPluginConfigurationTranslator(final IMaven maven, final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MojoExecution mojoExecution, final IProject project, final IProgressMonitor monitor, final ResourceResolver resourceResolver) throws CoreException { + super(maven, mavenProject, mojoExecution, monitor); this.mavenProject = mavenProject; this.project = project; this.monitor = monitor; @@ -574,6 +578,7 @@ public void updatePropertiesWithPropertyExpansion(final Properties props) } public static List newInstance( + final IMaven maven, final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MavenPluginWrapper mavenPlugin, final IProject project, @@ -585,7 +590,7 @@ public static List newInstance( final ResourceResolver resourceResolver = AbstractMavenPluginProjectConfigurator.getResourceResolver( execution, session, project.getLocation()); - m2csConverters.add(new MavenPluginConfigurationTranslator( + m2csConverters.add(new MavenPluginConfigurationTranslator(maven, configurator, mavenProject, execution, project, monitor, resourceResolver)); } From 0f15eaa967b1ab3f7634434d075b1249052c36ea Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:28:22 +0100 Subject: [PATCH 101/153] Pass maven --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index ebdda707..bb40a95b 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -86,7 +86,7 @@ protected void handleProjectConfigurationChange( final MavenSession session) throws CoreException { final List mavenCheckstyleConfigs = - MavenPluginConfigurationTranslator.newInstance(this, + MavenPluginConfigurationTranslator.newInstance(maven, this, mavenProjectFacade.getMavenProject(monitor), mavenPluginWrapper, project, monitor, session); From cefe6a7f96796e86beaa0221827e8bc8ecf6ee91 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:28:42 +0100 Subject: [PATCH 102/153] Use superclass helper method --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 32eb3b01..6df39b34 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -182,8 +182,7 @@ public void updateCheckConfigWithIncludeExcludePatterns( * if an error occurs */ protected String getPropertiesLocation() throws CoreException { - return configurator.getParameterValue(mavenProject, - "propertiesLocation", String.class, execution, monitor); + return getParameterValue("propertiesLocation", String.class); } /** From 4c75a991d07d47ad1c6272aba30082f7f08496ae Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:29:12 +0100 Subject: [PATCH 103/153] Use superclass helper method for propertyExpansion --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 6df39b34..4d61a6a0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -194,8 +194,7 @@ protected String getPropertiesLocation() throws CoreException { * if an error occurs */ protected String getPropertyExpansion() throws CoreException { - return configurator.getParameterValue(mavenProject, "propertyExpansion", - String.class, execution, monitor); + return getParameterValue("propertyExpansion", String.class); } /** From 0475b218716ba8250cbcec836218184001d0be29 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:29:49 +0100 Subject: [PATCH 104/153] Add isSkip --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 4d61a6a0..6e8146b8 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -94,6 +94,10 @@ private MavenPluginConfigurationTranslator(final IMaven maven, this.configurator = configurator; } + public boolean isSkip() throws CoreException { + return getParameterValue("skip", Boolean.class, Boolean.FALSE); + } + public boolean isActive() throws CoreException { final Boolean isSkip = configurator.getParameterValue(mavenProject, "skip", Boolean.class, execution, monitor); From 4eab7eee03cafd6065f9ee5554b9be8309f35f05 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:30:34 +0100 Subject: [PATCH 105/153] Use superclass helper for includeTestSourceDirectory --- .../checkstyle/MavenPluginConfigurationTranslator.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 6e8146b8..bca7e8c3 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -210,14 +210,8 @@ protected String getPropertyExpansion() throws CoreException { * if an error occurs */ public boolean getIncludeTestSourceDirectory() throws CoreException { - final Boolean includeTestSourceDirectory = configurator - .getParameterValue(mavenProject, "includeTestSourceDirectory", - Boolean.class, execution, monitor); - if (includeTestSourceDirectory != null) { - return includeTestSourceDirectory.booleanValue(); - } else { - return false; - } + return getParameterValue("includeTestSourceDirectory", Boolean.class, + Boolean.FALSE); } public boolean getIncludeResourcesDirectory() throws CoreException { From c00ae2db29664667e7985fbbf2aa4a88f2e19c6e Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:30:58 +0100 Subject: [PATCH 106/153] Use superclass helper for includeResources --- .../checkstyle/MavenPluginConfigurationTranslator.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index bca7e8c3..00084c08 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -215,14 +215,8 @@ public boolean getIncludeTestSourceDirectory() throws CoreException { } public boolean getIncludeResourcesDirectory() throws CoreException { - final Boolean includeTestSourceDirectory = - configurator.getParameterValue(mavenProject, "includeResources", - Boolean.class, execution, monitor); - if (includeTestSourceDirectory != null) { - return includeTestSourceDirectory.booleanValue(); - } else { - return false; - } + return getParameterValue("includeResources", Boolean.class, + Boolean.TRUE); } public boolean getIncludeTestResourcesDirectory() throws CoreException { From 6a014c34d738e91fb48922c2128eb4259f170da0 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:32:15 +0100 Subject: [PATCH 107/153] Use superclass helper for includeTestResources --- .../checkstyle/MavenPluginConfigurationTranslator.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 00084c08..c2105499 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -220,14 +220,8 @@ public boolean getIncludeResourcesDirectory() throws CoreException { } public boolean getIncludeTestResourcesDirectory() throws CoreException { - final Boolean includeTestSourceDirectory = configurator - .getParameterValue(mavenProject, "includeTestResources", - Boolean.class, execution, monitor); - if (includeTestSourceDirectory != null) { - return includeTestSourceDirectory.booleanValue(); - } else { - return false; - } + return getParameterValue("includeTestResources", Boolean.class, + Boolean.TRUE); } public String getExecutionId() { From 810eac34ae5ab66fbc97eeffc37cd55f48e335bc Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:33:05 +0100 Subject: [PATCH 108/153] Use isSkip instead of isActive --- .../checkstyle/EclipseCheckstyleProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java index bb40a95b..f10c5c47 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/EclipseCheckstyleProjectConfigurator.java @@ -103,7 +103,7 @@ protected void handleProjectConfigurationChange( pcWorkingCopy.getFileSets().clear(); for (final MavenPluginConfigurationTranslator mavenCheckstyleConfig : mavenCheckstyleConfigs) { - if (mavenCheckstyleConfig.isActive()) { + if (!mavenCheckstyleConfig.isSkip()) { this.buildCheckstyleConfiguration(pcWorkingCopy, mavenCheckstyleConfig); addNature(project, CheckstyleNature.NATURE_ID, monitor); From feef6eb0302beac77df53c4b5dcd95650b1a30a6 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:33:16 +0100 Subject: [PATCH 109/153] Remove isActive --- .../checkstyle/MavenPluginConfigurationTranslator.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index c2105499..5ade7a98 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -98,12 +98,6 @@ public boolean isSkip() throws CoreException { return getParameterValue("skip", Boolean.class, Boolean.FALSE); } - public boolean isActive() throws CoreException { - final Boolean isSkip = configurator.getParameterValue(mavenProject, - "skip", Boolean.class, execution, monitor); - return isSkip != null ? !isSkip : true; - } - public URL getRuleset() throws CheckstylePluginException, CoreException { final URL ruleset = this.resourceResolver.resolveLocation(this.getConfigLocation()); From b51d603e30996a675b034e9f65c99583bbff9678 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:34:50 +0100 Subject: [PATCH 110/153] Rename getIncludeTestSourceDirectory to isIncludeTestSourceDirectory --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 5ade7a98..7820afdc 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -203,7 +203,7 @@ protected String getPropertyExpansion() throws CoreException { * @throws CoreException * if an error occurs */ - public boolean getIncludeTestSourceDirectory() throws CoreException { + public boolean isIncludeTestSourceDirectory() throws CoreException { return getParameterValue("includeTestSourceDirectory", Boolean.class, Boolean.FALSE); } @@ -343,7 +343,7 @@ private List getIncludesExcludesFileMatchPatterns() final Set sourceFolders = new HashSet<>(); sourceFolders.addAll(this.getSourceDirectories()); - if (getIncludeTestSourceDirectory()) { + if (isIncludeTestSourceDirectory()) { sourceFolders.addAll(this.getTestSourceDirectories()); } From 082a66ce3d80b78439705be56c07e2b3443eb46a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:35:27 +0100 Subject: [PATCH 111/153] Rename getIncludeResourcesDirectory to isIncludeResources --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 7820afdc..40f35344 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -208,7 +208,7 @@ public boolean isIncludeTestSourceDirectory() throws CoreException { Boolean.FALSE); } - public boolean getIncludeResourcesDirectory() throws CoreException { + public boolean isIncludeResources() throws CoreException { return getParameterValue("includeResources", Boolean.class, Boolean.TRUE); } @@ -383,7 +383,7 @@ private List getIncludesExcludesFileMatchPatterns() false)); } - if (this.getIncludeResourcesDirectory()) { + if (this.isIncludeResources()) { final List resourceIncludePatterns = this.getResourceIncludes(); for (final Resource resource : this.mavenProject.getBuild() From b5ecf25557b414b3130c13f0b44923096510c2e5 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:35:59 +0100 Subject: [PATCH 112/153] Rename getIncludeTestResourcesDirectory to isIncludeTestResources --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 40f35344..fdc082f7 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -213,7 +213,7 @@ public boolean isIncludeResources() throws CoreException { Boolean.TRUE); } - public boolean getIncludeTestResourcesDirectory() throws CoreException { + public boolean isIncludeTestResources() throws CoreException { return getParameterValue("includeTestResources", Boolean.class, Boolean.TRUE); } @@ -411,7 +411,7 @@ private List getIncludesExcludesFileMatchPatterns() } } - if (this.getIncludeTestResourcesDirectory()) { + if (this.isIncludeTestResources()) { final List resourceIncludePatterns = this.getResourceIncludes(); for (final Resource resource : this.mavenProject.getBuild() From 7d0d2ba66ad2910940928848db5917228a019e13 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:37:47 +0100 Subject: [PATCH 113/153] Use superclass helper for getConfigLocation --- .../checkstyle/MavenPluginConfigurationTranslator.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index fdc082f7..dfedb387 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -230,12 +230,8 @@ public String getExecutionId() { * @throws CoreException */ private String getConfigLocation() throws CoreException { - String configLocation = configurator.getParameterValue(mavenProject, - "configLocation", String.class, execution, monitor); - if (configLocation == null) { - configLocation = CHECKSTYLE_DEFAULT_CONFIG_LOCATION; - } - return configLocation; + return getParameterValue("configLocation", String.class, + CHECKSTYLE_DEFAULT_CONFIG_LOCATION); } private String getHeaderLocation() throws CoreException { From b8dc80b655f7f5f6084ceaebecfe0302a123b4eb Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:39:44 +0100 Subject: [PATCH 114/153] Use superclass helper for getHeaderLocation --- .../checkstyle/MavenPluginConfigurationTranslator.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index dfedb387..084a366d 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -235,10 +235,9 @@ private String getConfigLocation() throws CoreException { } private String getHeaderLocation() throws CoreException { - final String configLocation = getConfigLocation(); - String headerLocation = configurator.getParameterValue(mavenProject, - "headerLocation", String.class, execution, monitor); - if ("config/maven_checks.xml".equals(configLocation) + String headerLocation = getParameterValue("headerLocation", + String.class, "LICENSE.txt"); + if ("config/maven_checks.xml".equals(getConfigLocation()) && "LICENSE.txt".equals(headerLocation)) { headerLocation = "config/maven-header.txt"; } From b593a7faf7222bb4dc30fc1ffdd5016d7a694dc8 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:43:01 +0100 Subject: [PATCH 115/153] Use superclass helper for getSuppressionsFileExpression --- .../MavenPluginConfigurationTranslator.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 084a366d..6cf248a0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -66,8 +66,6 @@ public class MavenPluginConfigurationTranslator private static final String CHECKSTYLE_DEFAULT_CONFIG_LOCATION = "config/sun_checks.xml"; - private static final String CHECKSTYLE_DEFAULT_SUPPRESSIONS_FILE_EXPRESSION = - "checkstyle.suppressions.file"; /** checkstyle maven plugin artifactId */ private static final Map PATTERNS_CACHE = new HashMap<>(); @@ -146,16 +144,9 @@ public String getSuppressionsFile() return suppressionsFile.getAbsolutePath(); } - public String getSuppressionsFileExpression() - throws CheckstylePluginException, CoreException { - String suppressionsFileExpression = configurator.getParameterValue( - mavenProject, "suppressionsFileExpression", String.class, - execution, monitor); - if (suppressionsFileExpression == null) { - suppressionsFileExpression = - CHECKSTYLE_DEFAULT_SUPPRESSIONS_FILE_EXPRESSION; - } - return suppressionsFileExpression; + public String getSuppressionsFileExpression() throws CoreException { + return getParameterValue("suppressionsFileExpression", String.class, + "checkstyle.suppressions.file"); } public void updateCheckConfigWithIncludeExcludePatterns( From c7a09baee188b52e7d906e4b684775493ef5a802 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:57:41 +0100 Subject: [PATCH 116/153] Add getParameterList --- ...stractMavenPluginConfigurationTranslator.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java index b9b10e3c..039268c1 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java @@ -1,5 +1,8 @@ package com.basistech.m2e.code.quality.shared; +import java.util.Collections; +import java.util.List; + import org.apache.maven.model.ConfigurationContainer; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; @@ -43,4 +46,17 @@ public T getParameterValue(final String parameter, return parameterValue; } + @SuppressWarnings("unchecked") + public List getParameterList(final String parameter, + @SuppressWarnings("unused") final Class asType) + throws CoreException { + final List list = maven.getMojoParameterValue(project, parameter, + List.class, mojoExecution.getPlugin(), execution, + mojoExecution.getGoal(), monitor); + if (list == null) { + return Collections.emptyList(); + } + return list; + } + } From 76d9c84aa546cf80b0d8372eb8474c6e30b1d722 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:58:14 +0100 Subject: [PATCH 117/153] Use superclass helper for suppressionsLocation --- .../checkstyle/MavenPluginConfigurationTranslator.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 6cf248a0..43610078 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -236,12 +236,11 @@ private String getHeaderLocation() throws CoreException { } private String getSuppressionsLocation() throws CoreException { - String suppressionsLocation = configurator.getParameterValue( - mavenProject, "suppressionsLocation", String.class, execution, - monitor); + String suppressionsLocation = + getParameterValue("suppressionsLocation", String.class); if (suppressionsLocation == null) { - suppressionsLocation = configurator.getParameterValue(mavenProject, - "suppressionsFile", String.class, execution, monitor); + suppressionsLocation = + getParameterValue("suppressionsFile", String.class); } return suppressionsLocation; } From e6909ccdf6ea5b95c6188e01314813d580fbd41a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:59:07 +0100 Subject: [PATCH 118/153] Use superclass helper for getSourceDirectories --- .../MavenPluginConfigurationTranslator.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 43610078..15046285 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -246,21 +246,14 @@ private String getSuppressionsLocation() throws CoreException { } private List getSourceDirectories() throws CoreException { - final List result = new ArrayList<>(); + final List sourceDirectories = new ArrayList<>( + getParameterList("sourceDirectories", String.class)); final String sourceDirectory = - configurator.getParameterValue(mavenProject, "sourceDirectory", - String.class, execution, monitor); + getParameterValue("sourceDirectory", String.class); if (sourceDirectory != null) { - result.add(sourceDirectory); + sourceDirectories.add(sourceDirectory); } - @SuppressWarnings("unchecked") - final List sourceDirectories = - configurator.getParameterValue(mavenProject, - "sourceDirectories", List.class, execution, monitor); - if (sourceDirectories != null) { - result.addAll(sourceDirectories); - } - return result; + return sourceDirectories; } private List getTestSourceDirectories() throws CoreException { From 45208ca3f2a24aea06532bfb1e97004364e66a05 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 16:59:26 +0100 Subject: [PATCH 119/153] Use superclass helper for getTestSourceDirectories --- .../MavenPluginConfigurationTranslator.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 15046285..decac57b 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -257,21 +257,14 @@ private List getSourceDirectories() throws CoreException { } private List getTestSourceDirectories() throws CoreException { - final List result = new ArrayList<>(); - final String sourceDirectory = configurator.getParameterValue( - mavenProject, "testSourceDirectory", String.class, execution, - monitor); - if (sourceDirectory != null) { - result.add(sourceDirectory); - } - @SuppressWarnings("unchecked") - final List sourceDirectories = configurator.getParameterValue( - mavenProject, "testSourceDirectories", List.class, execution, - monitor); - if (sourceDirectories != null) { - result.addAll(sourceDirectories); + final List testSourceDirectories = new ArrayList<>( + getParameterList("testSourceDirectories", String.class)); + final String testSourceDirectory = + getParameterValue("testSourceDirectory", String.class); + if (testSourceDirectory != null) { + testSourceDirectories.add(testSourceDirectory); } - return result; + return testSourceDirectories; } private List getIncludes() throws CoreException { From 68de33e7841d11594dd88f9b9237b05177f7736f Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:00:35 +0100 Subject: [PATCH 120/153] Use superclass helper for getPatterns --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index decac57b..44b79db7 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -461,8 +461,7 @@ private List normalizePatternsToCheckstyleFileMatchPattern( private List getPatterns(final String elemName) throws CoreException { final List transformedPatterns = new LinkedList<>(); - final String patternsString = configurator.getParameterValue( - mavenProject, elemName, String.class, execution, monitor); + final String patternsString = getParameterValue(elemName, String.class); if (patternsString == null || patternsString.length() == 0) { return transformedPatterns; } From 224939fdc8cdacc10201c9fb75e7dde6e8ba0c66 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:00:47 +0100 Subject: [PATCH 121/153] Remove unused progress monitor --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 44b79db7..8badac2a 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -75,7 +75,6 @@ public class MavenPluginConfigurationTranslator private final AbstractMavenPluginProjectConfigurator configurator; private final ResourceResolver resourceResolver; private final MojoExecution execution; - private final IProgressMonitor monitor; private MavenPluginConfigurationTranslator(final IMaven maven, final AbstractMavenPluginProjectConfigurator configurator, @@ -85,7 +84,6 @@ private MavenPluginConfigurationTranslator(final IMaven maven, super(maven, mavenProject, mojoExecution, monitor); this.mavenProject = mavenProject; this.project = project; - this.monitor = monitor; this.basedirUri = this.project.getLocationURI(); this.resourceResolver = resourceResolver; this.execution = mojoExecution; From 3b5f3209b5682b6192d3ae711ec4e9022ff66702 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:16:03 +0100 Subject: [PATCH 122/153] Refactor handling of headerFile and suppressionsFile --- .../MavenPluginConfigurationTranslator.java | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 8badac2a..7e037a71 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -18,9 +18,13 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; import java.net.URI; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -35,7 +39,6 @@ import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -72,22 +75,22 @@ public class MavenPluginConfigurationTranslator private final MavenProject mavenProject; private final IProject project; private final URI basedirUri; - private final AbstractMavenPluginProjectConfigurator configurator; private final ResourceResolver resourceResolver; private final MojoExecution execution; + private final Path workingDirectory; private MavenPluginConfigurationTranslator(final IMaven maven, - final AbstractMavenPluginProjectConfigurator configurator, final MavenProject mavenProject, final MojoExecution mojoExecution, final IProject project, final IProgressMonitor monitor, - final ResourceResolver resourceResolver) throws CoreException { + final ResourceResolver resourceResolver, + final Path workingDirectory) throws CoreException { super(maven, mavenProject, mojoExecution, monitor); this.mavenProject = mavenProject; this.project = project; + this.workingDirectory = workingDirectory; this.basedirUri = this.project.getLocationURI(); this.resourceResolver = resourceResolver; this.execution = mojoExecution; - this.configurator = configurator; } public boolean isSkip() throws CoreException { @@ -106,40 +109,44 @@ public URL getRuleset() throws CheckstylePluginException, CoreException { public String getHeaderFile() throws CheckstylePluginException, CoreException { - final URL headerResource = - this.resourceResolver.resolveLocation(getHeaderLocation()); - if (headerResource == null) { + final URL headerLocation = + resourceResolver.resolveLocation(getHeaderLocation()); + if (headerLocation == null) { return null; } - - final File outDir = - project.getWorkingLocation(configurator.getId()).toFile(); - final File headerFile = new File(outDir, - "checkstyle-header-" + getExecutionId() + ".txt"); - copyOut(headerResource, headerFile); - - return headerFile.getAbsolutePath(); + final Path headerFile = workingDirectory + .resolve("checkstyle-header-" + getExecutionId() + ".txt"); + try (InputStream inputStream = headerLocation.openStream()) { + Files.copy(inputStream, headerFile, + StandardCopyOption.REPLACE_EXISTING); + } catch (final IOException e) { + LOG.error("Could not copy header file {}", headerLocation, e); + throw new CheckstylePluginException( + "Failed to resolve header file, SKIPPING Eclipse checkstyle configuration"); + } + return headerFile.toAbsolutePath().toString(); } public String getSuppressionsFile() throws CheckstylePluginException, CoreException { - final String suppressionsLocation = getSuppressionsLocation(); + final URL suppressionsLocation = this.resourceResolver + .resolveLocation(getSuppressionsLocation()); if (suppressionsLocation == null) { return null; } - final URL suppressionsResource = - this.resourceResolver.resolveLocation(suppressionsLocation); - if (suppressionsResource == null) { - return null; - } - final File outDir = - project.getWorkingLocation(configurator.getId()).toFile(); - final File suppressionsFile = new File(outDir, + final Path suppressionsFile = workingDirectory.resolve( "checkstyle-suppressions-" + getExecutionId() + ".xml"); - copyOut(suppressionsResource, suppressionsFile); - - return suppressionsFile.getAbsolutePath(); + try (InputStream inputStream = suppressionsLocation.openStream()) { + Files.copy(inputStream, suppressionsFile, + StandardCopyOption.REPLACE_EXISTING); + } catch (final IOException e) { + LOG.error("Could not copy suppressions file {}", + suppressionsLocation, e); + throw new CheckstylePluginException( + "Failed to resolve suppressions file, SKIPPING Eclipse checkstyle configuration"); + } + return suppressionsFile.toAbsolutePath().toString(); } public String getSuppressionsFileExpression() throws CoreException { @@ -281,18 +288,6 @@ private List getResourceExcludes() throws CoreException { return this.getPatterns("resourceExcludes"); } - private void copyOut(final URL src, final File dest) - throws CheckstylePluginException { - try { - FileUtils.copyURLToFile(src, dest); - } catch (final IOException e) { - LOG.error("Could not copy file {}", src, e); - throw new CheckstylePluginException( - "Failed to copy file " + src.getFile() - + ", SKIPPING Eclipse checkstyle configuration"); - } - } - /** * * @return A list of {@code FileMatchPattern}'s. @@ -536,9 +531,11 @@ public static List newInstance( final ResourceResolver resourceResolver = AbstractMavenPluginProjectConfigurator.getResourceResolver( execution, session, project.getLocation()); + final Path path = project.getWorkingLocation(configurator.getId()) + .toFile().toPath(); m2csConverters.add(new MavenPluginConfigurationTranslator(maven, - configurator, mavenProject, execution, project, monitor, - resourceResolver)); + mavenProject, execution, project, monitor, resourceResolver, + path)); } return m2csConverters; } From 893e595103a346ad6c0bf35c1060c1922f38136b Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:18:07 +0100 Subject: [PATCH 123/153] Immediately resolve header location --- .../checkstyle/MavenPluginConfigurationTranslator.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 7e037a71..6f7a4016 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -109,8 +109,7 @@ public URL getRuleset() throws CheckstylePluginException, CoreException { public String getHeaderFile() throws CheckstylePluginException, CoreException { - final URL headerLocation = - resourceResolver.resolveLocation(getHeaderLocation()); + final URL headerLocation = getHeaderLocation(); if (headerLocation == null) { return null; } @@ -230,14 +229,14 @@ private String getConfigLocation() throws CoreException { CHECKSTYLE_DEFAULT_CONFIG_LOCATION); } - private String getHeaderLocation() throws CoreException { + private URL getHeaderLocation() throws CoreException { String headerLocation = getParameterValue("headerLocation", String.class, "LICENSE.txt"); if ("config/maven_checks.xml".equals(getConfigLocation()) && "LICENSE.txt".equals(headerLocation)) { headerLocation = "config/maven-header.txt"; } - return headerLocation; + return resourceResolver.resolveLocation(headerLocation); } private String getSuppressionsLocation() throws CoreException { From 9941a7b99cd2e23b699df85d035751949f32b286 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:18:52 +0100 Subject: [PATCH 124/153] Immediately resolve header location --- .../checkstyle/MavenPluginConfigurationTranslator.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 6f7a4016..fd2dc778 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -128,8 +128,7 @@ public String getHeaderFile() public String getSuppressionsFile() throws CheckstylePluginException, CoreException { - final URL suppressionsLocation = this.resourceResolver - .resolveLocation(getSuppressionsLocation()); + final URL suppressionsLocation = getSuppressionsLocation(); if (suppressionsLocation == null) { return null; } @@ -239,14 +238,14 @@ private URL getHeaderLocation() throws CoreException { return resourceResolver.resolveLocation(headerLocation); } - private String getSuppressionsLocation() throws CoreException { + private URL getSuppressionsLocation() throws CoreException { String suppressionsLocation = getParameterValue("suppressionsLocation", String.class); if (suppressionsLocation == null) { suppressionsLocation = getParameterValue("suppressionsFile", String.class); } - return suppressionsLocation; + return this.resourceResolver.resolveLocation(suppressionsLocation); } private List getSourceDirectories() throws CoreException { From bde4257b5142c04bddb6c47d6b2113d91e9b812a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:20:36 +0100 Subject: [PATCH 125/153] Update exception messages --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index fd2dc778..e679b43c 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -121,7 +121,7 @@ public String getHeaderFile() } catch (final IOException e) { LOG.error("Could not copy header file {}", headerLocation, e); throw new CheckstylePluginException( - "Failed to resolve header file, SKIPPING Eclipse checkstyle configuration"); + "Failed to copy header file, SKIPPING Eclipse checkstyle configuration"); } return headerFile.toAbsolutePath().toString(); } @@ -142,7 +142,7 @@ public String getSuppressionsFile() LOG.error("Could not copy suppressions file {}", suppressionsLocation, e); throw new CheckstylePluginException( - "Failed to resolve suppressions file, SKIPPING Eclipse checkstyle configuration"); + "Failed to copy suppressions file, SKIPPING Eclipse checkstyle configuration"); } return suppressionsFile.toAbsolutePath().toString(); } From 45325d8d26075a79e488debc5f8b27ffad78f34b Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:24:50 +0100 Subject: [PATCH 126/153] Directly pass basedirUri instead of getting it from project --- .../checkstyle/MavenPluginConfigurationTranslator.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index e679b43c..440f72e3 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -73,7 +73,6 @@ public class MavenPluginConfigurationTranslator private static final Map PATTERNS_CACHE = new HashMap<>(); private final MavenProject mavenProject; - private final IProject project; private final URI basedirUri; private final ResourceResolver resourceResolver; private final MojoExecution execution; @@ -81,14 +80,13 @@ public class MavenPluginConfigurationTranslator private MavenPluginConfigurationTranslator(final IMaven maven, final MavenProject mavenProject, final MojoExecution mojoExecution, - final IProject project, final IProgressMonitor monitor, + final URI basedirUri, final IProgressMonitor monitor, final ResourceResolver resourceResolver, final Path workingDirectory) throws CoreException { super(maven, mavenProject, mojoExecution, monitor); this.mavenProject = mavenProject; - this.project = project; this.workingDirectory = workingDirectory; - this.basedirUri = this.project.getLocationURI(); + this.basedirUri = basedirUri; this.resourceResolver = resourceResolver; this.execution = mojoExecution; } @@ -532,8 +530,8 @@ public static List newInstance( final Path path = project.getWorkingLocation(configurator.getId()) .toFile().toPath(); m2csConverters.add(new MavenPluginConfigurationTranslator(maven, - mavenProject, execution, project, monitor, resourceResolver, - path)); + mavenProject, execution, project.getLocationURI(), monitor, + resourceResolver, path)); } return m2csConverters; } From 6083c8f68068f4cfd90b312b174674536782d9da Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:29:40 +0100 Subject: [PATCH 127/153] Reduce visibility to private where possible --- .../checkstyle/MavenPluginConfigurationTranslator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 440f72e3..630169b6 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -171,7 +171,7 @@ public void updateCheckConfigWithIncludeExcludePatterns( * @throws CoreException * if an error occurs */ - protected String getPropertiesLocation() throws CoreException { + private String getPropertiesLocation() throws CoreException { return getParameterValue("propertiesLocation", String.class); } @@ -183,7 +183,7 @@ protected String getPropertiesLocation() throws CoreException { * @throws CoreException * if an error occurs */ - protected String getPropertyExpansion() throws CoreException { + private String getPropertyExpansion() throws CoreException { return getParameterValue("propertyExpansion", String.class); } @@ -195,17 +195,17 @@ protected String getPropertyExpansion() throws CoreException { * @throws CoreException * if an error occurs */ - public boolean isIncludeTestSourceDirectory() throws CoreException { + private boolean isIncludeTestSourceDirectory() throws CoreException { return getParameterValue("includeTestSourceDirectory", Boolean.class, Boolean.FALSE); } - public boolean isIncludeResources() throws CoreException { + private boolean isIncludeResources() throws CoreException { return getParameterValue("includeResources", Boolean.class, Boolean.TRUE); } - public boolean isIncludeTestResources() throws CoreException { + private boolean isIncludeTestResources() throws CoreException { return getParameterValue("includeTestResources", Boolean.class, Boolean.TRUE); } From e9670db6c80e5b3153ff11b63a1e42de2079e2e4 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:35:37 +0100 Subject: [PATCH 128/153] Use isEmpty instead of size --- .../checkstyle/MavenPluginConfigurationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 630169b6..e629c102 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -451,13 +451,13 @@ private List getPatterns(final String elemName) throws CoreException { final List transformedPatterns = new LinkedList<>(); final String patternsString = getParameterValue(elemName, String.class); - if (patternsString == null || patternsString.length() == 0) { + if (patternsString == null || patternsString.isEmpty()) { return transformedPatterns; } final String[] patternsArray = StringUtils.split(patternsString, ","); for (String p : patternsArray) { p = StringUtils.strip(p); - if (p == null || p.length() == 0) { + if (p == null || p.isEmpty()) { continue; } String csPattern; From 5d64bc129e38699dfac7d69ac6974cc82d730ed5 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:41:44 +0100 Subject: [PATCH 129/153] Remove this --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index e629c102..327e52be 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -158,7 +158,7 @@ public void updateCheckConfigWithIncludeExcludePatterns( new FileSet("java-sources-" + getExecutionId(), checkCfg); fs.setEnabled(true); // add fileset includes/excludes - fs.setFileMatchPatterns(this.getIncludesExcludesFileMatchPatterns()); + fs.setFileMatchPatterns(getIncludesExcludesFileMatchPatterns()); // now add the config pcWorkingCopy.getFileSets().add(fs); } From 0af89b2717b974cf23faebbd15b52adb85f78338 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:41:54 +0100 Subject: [PATCH 130/153] Formatting --- .../quality/checkstyle/MavenPluginConfigurationTranslator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 327e52be..54906730 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -293,7 +293,6 @@ private List getResourceExcludes() throws CoreException { */ private List getIncludesExcludesFileMatchPatterns() throws CheckstylePluginException, CoreException { - final List patterns = new LinkedList<>(); /** From 97bb1623ed345a7373bbed2d5bac70fac12f7ff4 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:42:06 +0100 Subject: [PATCH 131/153] Pass list to constructor --- .../checkstyle/MavenPluginConfigurationTranslator.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 54906730..7980f4af 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -299,11 +299,9 @@ private List getIncludesExcludesFileMatchPatterns() * Step 1). Get all the source roots (including test sources root, if * enabled). */ - final Set sourceFolders = new HashSet<>(); - sourceFolders.addAll(this.getSourceDirectories()); - + final Set sourceFolders = new HashSet<>(getSourceDirectories()); if (isIncludeTestSourceDirectory()) { - sourceFolders.addAll(this.getTestSourceDirectories()); + sourceFolders.addAll(getTestSourceDirectories()); } /** From f8e36f0f6fa5fa618624ac674279a181d87834cd Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 27 Feb 2016 17:42:20 +0100 Subject: [PATCH 132/153] Use isEmpty instead of size --- .../checkstyle/MavenPluginConfigurationTranslator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 7980f4af..fd620b5b 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -373,8 +373,8 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceIncludes(); for (final Resource resource : this.mavenProject.getBuild() .getTestResources()) { - if (resource.getExcludes().size() > 0 - || resource.getIncludes().size() > 0) { + if (!resource.getExcludes().isEmpty() + || !resource.getIncludes().isEmpty()) { // ignore resources that have ex/includes for now continue; } @@ -391,8 +391,8 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceExcludes(); for (final Resource resource : this.mavenProject.getBuild() .getTestResources()) { - if (resource.getExcludes().size() > 0 - || resource.getIncludes().size() > 0) { + if (!resource.getExcludes().isEmpty() + || !resource.getIncludes().isEmpty()) { // ignore resources that have ex/includes for now continue; } From a4624928816a2152b882d1203ba5db953527d981 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Tue, 19 Apr 2016 22:31:08 +0200 Subject: [PATCH 133/153] Log warning if resolving resource from classpath location could be ambig Signed-off-by: Michael Vorburger --- .../code/quality/shared/ResourceResolver.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 65073386..b24fc0d9 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -23,6 +23,8 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.eclipse.core.runtime.IPath; @@ -84,11 +86,16 @@ public URL resolveLocation(final String location) { } public URL getResourceFromPluginRealm(final String resource) { - if (resource.startsWith("/")) { - // ClassLoaders don't want leading slashes - return pluginRealm.getResource(resource.substring(1)); - } else { - return pluginRealm.getResource(resource); + String fixedResource = resource.startsWith("/") ? resource .substring(1) : resource; + try { + List urls = Collections.list(pluginRealm.getResources(fixedResource)); + if (urls.size() > 1) { + LOG.warn("Resource appears more than once on classpath, this is dangerous because it makes resolving this resource dependant on classpath ordering; location='" + fixedResource + "', found in: " + urls.toString()); + } + return urls.get(0); + } catch (IOException e) { + LOG.warn("getResources() failed: " + fixedResource, e); + return null; } } From 103e48c48798f5c6dbc7cedb4d7203bb17d48647 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Tue, 19 Apr 2016 19:52:35 +0200 Subject: [PATCH 134/153] Document m2e-code-quality.setup --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index f2861273..19fb452b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,15 @@ These Eclipse plugins are built with the Tycho Maven plugin. The marriage of OSGi, Eclipse, and Maven is imperfect. In particular, it rarely works to run a build that does not start with 'clean'. +This project has Oomph, and you can set up an Eclipse development workspace of it in one click by: + +1. Downloading the Eclipse Installer from https://www.eclipse.org/downloads/ and starting it. +2. On the initial page, click on the *Switch to advanced mode* button in the top right. +3. On the *Product* page, select *Eclipse IDE for Java Developers*. +4. On the *Projects* page, collapse the *Eclipse Projects* to scroll down to the *Github Projects* and double-click *m2e-code-quality*. +5. Choose your preferred installation settings on the *Variables* page. +6. Finish the wizard and watch how your development environment is being assembled, courtesy of Oomph. + See [doc/release.md](doc/release.md) for information about how all of this is released. Activity here is 'coordinated' on a mailing list: From fda96099434cb61f3f70f9c546ce674c0677e1e4 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 22 Apr 2016 19:33:31 +0200 Subject: [PATCH 135/153] Use latest checkstyle version --- mars/mars.target | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mars/mars.target b/mars/mars.target index 6bc27490..ef4df5e9 100644 --- a/mars/mars.target +++ b/mars/mars.target @@ -1,5 +1,5 @@ - + @@ -19,7 +19,7 @@ - + From fdf972b796db532b6f105277b4e4cb384aa7de10 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Fri, 22 Apr 2016 19:33:49 +0200 Subject: [PATCH 136/153] Use version specific update site instead of composite site --- mars/mars.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mars/mars.target b/mars/mars.target index ef4df5e9..d9caefd9 100644 --- a/mars/mars.target +++ b/mars/mars.target @@ -20,7 +20,7 @@ - + From a9b3334602290679f04cfdc76cf0ed9f304d17e9 Mon Sep 17 00:00:00 2001 From: Arlo Louis O'Keeffe Date: Sun, 24 Apr 2016 13:23:02 +0200 Subject: [PATCH 137/153] Change eclipse product --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19fb452b..20ea5906 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ This project has Oomph, and you can set up an Eclipse development workspace of i 1. Downloading the Eclipse Installer from https://www.eclipse.org/downloads/ and starting it. 2. On the initial page, click on the *Switch to advanced mode* button in the top right. -3. On the *Product* page, select *Eclipse IDE for Java Developers*. -4. On the *Projects* page, collapse the *Eclipse Projects* to scroll down to the *Github Projects* and double-click *m2e-code-quality*. +3. On the *Product* page, select *Eclipse for RCP and RAP Developers*. +4. On the *Projects* page, collapse the *Eclipse Projects* to scroll down to the *Github Projects* and select *m2e-code-quality*. 5. Choose your preferred installation settings on the *Variables* page. 6. Finish the wizard and watch how your development environment is being assembled, courtesy of Oomph. From e5777e8118f40c2b6854b98f9dfcd8cf9cb1fa8a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 10 May 2016 18:01:47 +0200 Subject: [PATCH 138/153] Add checkstyle-8 demo project --- .../generated/src/main/java/cat/App2.java | 18 +++++ test-projects/checkstyle-8/pom.xml | 72 +++++++++++++++++++ .../checkstyle-8/src/main/java/cat/App.java | 18 +++++ 3 files changed, 108 insertions(+) create mode 100644 test-projects/checkstyle-8/generated/src/main/java/cat/App2.java create mode 100644 test-projects/checkstyle-8/pom.xml create mode 100644 test-projects/checkstyle-8/src/main/java/cat/App.java diff --git a/test-projects/checkstyle-8/generated/src/main/java/cat/App2.java b/test-projects/checkstyle-8/generated/src/main/java/cat/App2.java new file mode 100644 index 00000000..5bde03f6 --- /dev/null +++ b/test-projects/checkstyle-8/generated/src/main/java/cat/App2.java @@ -0,0 +1,18 @@ +package cat; + +/** + * Hello world! + * + */ +public class App2 +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} diff --git a/test-projects/checkstyle-8/pom.xml b/test-projects/checkstyle-8/pom.xml new file mode 100644 index 00000000..6dfa0103 --- /dev/null +++ b/test-projects/checkstyle-8/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + com.basistech + checkstyle-8 + 1.0-SNAPSHOT + + 1.8 + 1.8 + UTF-8 + + + install + + + maven-resources-plugin + 2.7 + + + copy-resources + generate-sources + + copy-resources + + + ${project.build.directory}/generated + + + generated + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.10 + + + add-source + generate-sources + + add-source + + + + ${project.build.directory}/generated/src/main/java + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.14 + + + + check + + + + + + + diff --git a/test-projects/checkstyle-8/src/main/java/cat/App.java b/test-projects/checkstyle-8/src/main/java/cat/App.java new file mode 100644 index 00000000..f40799f3 --- /dev/null +++ b/test-projects/checkstyle-8/src/main/java/cat/App.java @@ -0,0 +1,18 @@ +package cat; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} From 8e8c36965baa0540650890c1278ac3ec6a383146 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 10 May 2016 21:59:11 +0200 Subject: [PATCH 139/153] Add support for resolving resources from workspace projects --- ...bstractMavenPluginProjectConfigurator.java | 38 ++++++++++++++++++- .../code/quality/shared/ResourceResolver.java | 21 ++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index f8656bbc..f8804074 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -23,18 +23,23 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.ArtifactKey; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; import org.eclipse.m2e.core.project.MavenProjectChangedEvent; import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; @@ -265,11 +270,42 @@ public static ResourceResolver getResourceResolver( // call for side effect of ensuring that the realm is set in the // descriptor. final IMaven mvn = MavenPlugin.getMaven(); + final List projectLocations = new ArrayList<>(); + final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + final IMavenProjectRegistry mavenProjectRegistry = + MavenPlugin.getMavenProjectRegistry(); + final IMavenProjectFacade[] projects = + mavenProjectRegistry.getProjects(); + final List dependencies = + mojoExecution.getPlugin().getDependencies(); + for (final Dependency dependency : dependencies) { + for (final IMavenProjectFacade projectFacade : projects) { + final IProject project = projectFacade.getProject(); + if (!project.isAccessible()) { + LOG.debug("Project registry contains closed project {}", + project); + // this is actually a bug somewhere in registry refresh + // logic, closed projects should not be there + continue; + } + final ArtifactKey artifactKey = projectFacade.getArtifactKey(); + if (artifactKey.getGroupId().equals(dependency.getGroupId()) + && artifactKey.getArtifactId() + .equals(dependency.getArtifactId()) + && artifactKey.getVersion() + .equals(dependency.getVersion())) { + final IResource outputLocation = + root.findMember(projectFacade.getOutputLocation()); + projectLocations.add(outputLocation.getLocation()); + } + } + } final Mojo configuredMojo = mvn.getConfiguredMojo(session, mojoExecution, Mojo.class); mvn.releaseMojo(configuredMojo, mojoExecution); return new ResourceResolver(mojoExecution.getMojoDescriptor() - .getPluginDescriptor().getClassRealm(), projectLocation); + .getPluginDescriptor().getClassRealm(), projectLocation, + projectLocations); } private MavenPluginWrapper getMavenPlugin(final IProgressMonitor monitor, diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index b24fc0d9..b3976066 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -47,13 +47,16 @@ public final class ResourceResolver { private final ClassRealm pluginRealm; private final IPath projectLocation; + private final List projectLocations; public ResourceResolver(final ClassRealm pluginRealm, - final IPath projectLocation) { + final IPath projectLocation, final List projectLocations) { Preconditions.checkNotNull(pluginRealm); Preconditions.checkNotNull(projectLocation); + Preconditions.checkNotNull(projectLocations); this.pluginRealm = pluginRealm; this.projectLocation = projectLocation; + this.projectLocations = projectLocations; } /** @@ -72,7 +75,14 @@ public URL resolveLocation(final String location) { if (location == null || location.isEmpty()) { return null; } - URL url = getResourceFromPluginRealm(location); + URL url = null; + for (final IPath path : projectLocations) { + url = getResourceRelativeFromIPath(path, location); + if (url != null) { + return url; + } + } + url = getResourceFromPluginRealm(location); if (url == null) { url = getResourceFromRemote(location); } @@ -122,8 +132,13 @@ public URL getResourceFromFileSystem(final String resource) { } public URL getResourceRelativeFromProjectLocation(final String resource) { + return getResourceRelativeFromIPath(projectLocation, resource); + } + + public URL getResourceRelativeFromIPath(final IPath path, + final String resource) { try { - final File file = projectLocation.append(resource).toFile(); + final File file = path.append(resource).toFile(); if (file.exists()) { return file.toURI().toURL(); } From 777c0e86972218b8e5d4ef032f099c311f9d740a Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 10 May 2016 22:24:17 +0200 Subject: [PATCH 140/153] Formatting --- .../m2e/code/quality/shared/ResourceResolver.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index b3976066..4dba4406 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -96,11 +96,17 @@ public URL resolveLocation(final String location) { } public URL getResourceFromPluginRealm(final String resource) { - String fixedResource = resource.startsWith("/") ? resource .substring(1) : resource; + String fixedResource = + resource.startsWith("/") ? resource.substring(1) : resource; try { - List urls = Collections.list(pluginRealm.getResources(fixedResource)); + List urls = + Collections.list(pluginRealm.getResources(fixedResource)); if (urls.size() > 1) { - LOG.warn("Resource appears more than once on classpath, this is dangerous because it makes resolving this resource dependant on classpath ordering; location='" + fixedResource + "', found in: " + urls.toString()); + LOG.warn( + "Resource appears more than once on classpath, this is " + + "dangerous because it makes resolving this resource " + + "dependant on classpath ordering; location {} found in {}", + fixedResource, urls); } return urls.get(0); } catch (IOException e) { From 79b97f50306e646ee56343e93646b5a2e3c93666 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 10 May 2016 22:25:21 +0200 Subject: [PATCH 141/153] Remove unnecessary javadoc --- .../m2e/code/quality/checkstyle/Activator.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java index 4e32427b..cece4af0 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/Activator.java @@ -18,26 +18,12 @@ public class Activator extends AbstractUIPlugin { public Activator() { } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext - * ) - */ @Override public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext - * ) - */ @Override public void stop(final BundleContext context) throws Exception { plugin = null; From a093d82da0ea9376128833136a90d6ec7fb74410 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sun, 22 May 2016 14:16:51 +0200 Subject: [PATCH 142/153] Add check for empty result --- .../basistech/m2e/code/quality/shared/ResourceResolver.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 4dba4406..9efe0cf0 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -101,6 +101,9 @@ public URL getResourceFromPluginRealm(final String resource) { try { List urls = Collections.list(pluginRealm.getResources(fixedResource)); + if (urls.isEmpty()) { + return null; + } if (urls.size() > 1) { LOG.warn( "Resource appears more than once on classpath, this is " From b6f9b0f3eea49da420ec6d030fc0b8ea543f31bf Mon Sep 17 00:00:00 2001 From: Anton Smyk Date: Thu, 26 May 2016 15:57:51 +0200 Subject: [PATCH 143/153] Add test case for issue 39 -- check only sources under src/ directory --- .../generated/src/main/java/cat/App2.java | 18 +++++ test-projects/checkstyle-39/pom.xml | 80 +++++++++++++++++++ .../checkstyle-39/src/main/java/cat/App.java | 18 +++++ 3 files changed, 116 insertions(+) create mode 100644 test-projects/checkstyle-39/generated/src/main/java/cat/App2.java create mode 100644 test-projects/checkstyle-39/pom.xml create mode 100644 test-projects/checkstyle-39/src/main/java/cat/App.java diff --git a/test-projects/checkstyle-39/generated/src/main/java/cat/App2.java b/test-projects/checkstyle-39/generated/src/main/java/cat/App2.java new file mode 100644 index 00000000..5bde03f6 --- /dev/null +++ b/test-projects/checkstyle-39/generated/src/main/java/cat/App2.java @@ -0,0 +1,18 @@ +package cat; + +/** + * Hello world! + * + */ +public class App2 +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} diff --git a/test-projects/checkstyle-39/pom.xml b/test-projects/checkstyle-39/pom.xml new file mode 100644 index 00000000..43a17bf7 --- /dev/null +++ b/test-projects/checkstyle-39/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + com.basistech + checkstyle-39 + 1.0-SNAPSHOT + + 1.8 + 1.8 + UTF-8 + + + install + + + maven-resources-plugin + 2.7 + + + copy-resources + generate-sources + + copy-resources + + + ${project.build.directory}/generated + + + generated + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.10 + + + add-source + generate-sources + + add-source + + + + ${project.build.directory}/generated/src/main/java + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.14 + + + + check + + + + src/main/java + + + src/test/java + + + + + + + + diff --git a/test-projects/checkstyle-39/src/main/java/cat/App.java b/test-projects/checkstyle-39/src/main/java/cat/App.java new file mode 100644 index 00000000..f40799f3 --- /dev/null +++ b/test-projects/checkstyle-39/src/main/java/cat/App.java @@ -0,0 +1,18 @@ +package cat; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + Object[] bucket = new Object[12345]; + String y = args[0]; + Object x = bucket[ Math.abs(y.hashCode()) % bucket.length]; + System.out.println( "Hello World!" + x); + x = bucket[ y.hashCode() % bucket.length]; + System.out.println( "Hello World!" + x); + } +} From 3eba80bc079bdbad64443c315505e50af2cb41e2 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 28 May 2016 10:34:24 +0200 Subject: [PATCH 144/153] Add null check --- .../shared/AbstractMavenPluginProjectConfigurator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index f8804074..6bdba5c1 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -296,7 +296,9 @@ public static ResourceResolver getResourceResolver( .equals(dependency.getVersion())) { final IResource outputLocation = root.findMember(projectFacade.getOutputLocation()); - projectLocations.add(outputLocation.getLocation()); + if (outputLocation != null) { + projectLocations.add(outputLocation.getLocation()); + } } } } From 6008b6093e0b0143e4e17f635a48291c977a9d54 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Sat, 28 May 2016 12:42:26 +0200 Subject: [PATCH 145/153] Add ^ to beginning of all project relative path patterns --- .../MavenPluginConfigurationTranslator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index fd620b5b..769ae02c 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -313,7 +313,7 @@ private List getIncludesExcludesFileMatchPatterns() */ final List includePatterns = this.getIncludes(); for (final String folder : sourceFolders) { - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(folder).toURI()).getPath(); if (!includePatterns.isEmpty()) { patterns.addAll( @@ -332,7 +332,7 @@ private List getIncludesExcludesFileMatchPatterns() */ final List excludePatterns = this.getExcludes(); for (final String folder : sourceFolders) { - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(folder).toURI()).getPath(); patterns.addAll(this.normalizePatternsToCheckstyleFileMatchPattern( excludePatterns, this.convertToEclipseCheckstyleRegExpPath( @@ -345,7 +345,7 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceIncludes(); for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -358,7 +358,7 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceExcludes(); for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -378,7 +378,7 @@ private List getIncludesExcludesFileMatchPatterns() // ignore resources that have ex/includes for now continue; } - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( @@ -396,7 +396,7 @@ private List getIncludesExcludesFileMatchPatterns() // ignore resources that have ex/includes for now continue; } - final String folderRelativePath = this.basedirUri + final String folderRelativePath = "^" + this.basedirUri .relativize(new File(resource.getDirectory()).toURI()) .getPath(); patterns.addAll( From f964b3b0177232992193ed8202d9beef4c7a3789 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Mon, 30 May 2016 20:17:36 +0200 Subject: [PATCH 146/153] Relativize the folders only if they are absolute --- .../MavenPluginConfigurationTranslator.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java index 769ae02c..2f4c4fa5 100644 --- a/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.checkstyle/src/main/java/com/basistech/m2e/code/quality/checkstyle/MavenPluginConfigurationTranslator.java @@ -313,8 +313,7 @@ private List getIncludesExcludesFileMatchPatterns() */ final List includePatterns = this.getIncludes(); for (final String folder : sourceFolders) { - final String folderRelativePath = "^" + this.basedirUri - .relativize(new File(folder).toURI()).getPath(); + final String folderRelativePath = relativize(folder); if (!includePatterns.isEmpty()) { patterns.addAll( this.normalizePatternsToCheckstyleFileMatchPattern( @@ -332,8 +331,7 @@ private List getIncludesExcludesFileMatchPatterns() */ final List excludePatterns = this.getExcludes(); for (final String folder : sourceFolders) { - final String folderRelativePath = "^" + this.basedirUri - .relativize(new File(folder).toURI()).getPath(); + final String folderRelativePath = relativize(folder); patterns.addAll(this.normalizePatternsToCheckstyleFileMatchPattern( excludePatterns, this.convertToEclipseCheckstyleRegExpPath( folderRelativePath), @@ -345,9 +343,8 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceIncludes(); for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - final String folderRelativePath = "^" + this.basedirUri - .relativize(new File(resource.getDirectory()).toURI()) - .getPath(); + final String folderRelativePath = + relativize(resource.getDirectory()); patterns.addAll( this.normalizePatternsToCheckstyleFileMatchPattern( resourceIncludePatterns, folderRelativePath, @@ -358,9 +355,8 @@ private List getIncludesExcludesFileMatchPatterns() this.getResourceExcludes(); for (final Resource resource : this.mavenProject.getBuild() .getResources()) { - final String folderRelativePath = "^" + this.basedirUri - .relativize(new File(resource.getDirectory()).toURI()) - .getPath(); + final String folderRelativePath = + relativize(resource.getDirectory()); patterns.addAll( this.normalizePatternsToCheckstyleFileMatchPattern( resourceExcludePatterns, folderRelativePath, @@ -409,6 +405,18 @@ private List getIncludesExcludesFileMatchPatterns() return patterns; } + private String relativize(final String folder) { + String folderRelativePath = "^"; + File file = new File(folder); + if (file.isAbsolute()) { + folderRelativePath += + this.basedirUri.relativize(file.toURI()).getPath(); + } else { + folderRelativePath += folder; + } + return folderRelativePath; + } + private String convertToEclipseCheckstyleRegExpPath(final String path) { String csCompatiblePath = path; if (path.endsWith("/")) { From 3a87bd9a939c35a5d4408342d0491906769da648 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Mon, 30 May 2016 20:21:22 +0200 Subject: [PATCH 147/153] Remove the default value if the element has children --- .../AbstractMavenPluginConfigurationTranslator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java index 039268c1..05686e60 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java @@ -7,6 +7,7 @@ import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.m2e.core.embedder.IMaven; @@ -50,8 +51,15 @@ public T getParameterValue(final String parameter, public List getParameterList(final String parameter, @SuppressWarnings("unused") final Class asType) throws CoreException { + ConfigurationContainer executionClone = execution.clone(); + Xpp3Dom configuration = (Xpp3Dom) executionClone.getConfiguration(); + configuration = configuration != null + ? configuration.getChild(parameter) : null; + if (configuration.getChildCount() > 0) { + configuration.setAttribute("default-value", ""); + } final List list = maven.getMojoParameterValue(project, parameter, - List.class, mojoExecution.getPlugin(), execution, + List.class, mojoExecution.getPlugin(), executionClone, mojoExecution.getGoal(), monitor); if (list == null) { return Collections.emptyList(); From a9fe9fcc52801b5b00d899a043324ff5663dddf2 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Mon, 30 May 2016 20:25:32 +0200 Subject: [PATCH 148/153] Check for nullpointer --- .../shared/AbstractMavenPluginConfigurationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java index 05686e60..a85299ae 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginConfigurationTranslator.java @@ -55,7 +55,7 @@ public List getParameterList(final String parameter, Xpp3Dom configuration = (Xpp3Dom) executionClone.getConfiguration(); configuration = configuration != null ? configuration.getChild(parameter) : null; - if (configuration.getChildCount() > 0) { + if (configuration != null && configuration.getChildCount() > 0) { configuration.setAttribute("default-value", ""); } final List list = maven.getMojoParameterValue(project, parameter, From 7a65aba7af9562defea161acab2b7d595eb01834 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Mon, 30 May 2016 20:44:01 +0200 Subject: [PATCH 149/153] Do not require pluginRealm to be set --- .../basistech/m2e/code/quality/shared/ResourceResolver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java index 9efe0cf0..e2592133 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/ResourceResolver.java @@ -51,7 +51,6 @@ public final class ResourceResolver { public ResourceResolver(final ClassRealm pluginRealm, final IPath projectLocation, final List projectLocations) { - Preconditions.checkNotNull(pluginRealm); Preconditions.checkNotNull(projectLocation); Preconditions.checkNotNull(projectLocations); this.pluginRealm = pluginRealm; @@ -96,6 +95,9 @@ public URL resolveLocation(final String location) { } public URL getResourceFromPluginRealm(final String resource) { + if (pluginRealm == null) { + return null; + } String fixedResource = resource.startsWith("/") ? resource.substring(1) : resource; try { From f23f4503bdcf49c02c98d0729b867706dd12daa4 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Mon, 30 May 2016 20:46:29 +0200 Subject: [PATCH 150/153] Catch CoreException --- .../shared/AbstractMavenPluginProjectConfigurator.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 6bdba5c1..f03ebf32 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -302,9 +302,13 @@ public static ResourceResolver getResourceResolver( } } } - final Mojo configuredMojo = - mvn.getConfiguredMojo(session, mojoExecution, Mojo.class); - mvn.releaseMojo(configuredMojo, mojoExecution); + try { + final Mojo configuredMojo = + mvn.getConfiguredMojo(session, mojoExecution, Mojo.class); + mvn.releaseMojo(configuredMojo, mojoExecution); + } catch (CoreException e) { + LOG.error("Could not get mojo", e); + } return new ResourceResolver(mojoExecution.getMojoDescriptor() .getPluginDescriptor().getClassRealm(), projectLocation, projectLocations); From cdb0e3b9cc660cea85aa7a7945525cb32f227e28 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 31 May 2016 19:45:57 +0200 Subject: [PATCH 151/153] Rename variable --- .../shared/AbstractMavenPluginProjectConfigurator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index f03ebf32..2ab84072 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -270,7 +270,7 @@ public static ResourceResolver getResourceResolver( // call for side effect of ensuring that the realm is set in the // descriptor. final IMaven mvn = MavenPlugin.getMaven(); - final List projectLocations = new ArrayList<>(); + final List pluginDepencyProjectLocations = new ArrayList<>(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IMavenProjectRegistry mavenProjectRegistry = MavenPlugin.getMavenProjectRegistry(); @@ -297,7 +297,7 @@ public static ResourceResolver getResourceResolver( final IResource outputLocation = root.findMember(projectFacade.getOutputLocation()); if (outputLocation != null) { - projectLocations.add(outputLocation.getLocation()); + pluginDepencyProjectLocations.add(outputLocation.getLocation()); } } } @@ -311,7 +311,7 @@ public static ResourceResolver getResourceResolver( } return new ResourceResolver(mojoExecution.getMojoDescriptor() .getPluginDescriptor().getClassRealm(), projectLocation, - projectLocations); + pluginDepencyProjectLocations); } private MavenPluginWrapper getMavenPlugin(final IProgressMonitor monitor, From 464a05162869c8fcecfa65e558b7d0c43dc579f8 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 31 May 2016 19:46:30 +0200 Subject: [PATCH 152/153] Re-throw CoreException only if we couldn't find the project locations of the plugin dependencies --- .../quality/shared/AbstractMavenPluginProjectConfigurator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 2ab84072..09563197 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -307,6 +307,9 @@ public static ResourceResolver getResourceResolver( mvn.getConfiguredMojo(session, mojoExecution, Mojo.class); mvn.releaseMojo(configuredMojo, mojoExecution); } catch (CoreException e) { + if (pluginDepencyProjectLocations.isEmpty()) { + throw e; + } LOG.error("Could not get mojo", e); } return new ResourceResolver(mojoExecution.getMojoDescriptor() From 3bc2aa9410b08688877cbfe386110a3edfe98032 Mon Sep 17 00:00:00 2001 From: Arlo O'Keeffe Date: Tue, 9 Aug 2016 20:09:09 +0200 Subject: [PATCH 153/153] Reduce log level to trace --- .../quality/shared/AbstractMavenPluginProjectConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java index 09563197..02133b17 100644 --- a/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java +++ b/com.basistech.m2e.code.quality.shared/src/main/java/com/basistech/m2e/code/quality/shared/AbstractMavenPluginProjectConfigurator.java @@ -310,7 +310,7 @@ public static ResourceResolver getResourceResolver( if (pluginDepencyProjectLocations.isEmpty()) { throw e; } - LOG.error("Could not get mojo", e); + LOG.trace("Could not get mojo", e); } return new ResourceResolver(mojoExecution.getMojoDescriptor() .getPluginDescriptor().getClassRealm(), projectLocation,