From a751f0c2190d11e39422e2f2dd33416d4e5a37e7 Mon Sep 17 00:00:00 2001 From: Henning Schmiedehausen Date: Tue, 16 Jun 2015 20:44:23 -0700 Subject: [PATCH] Fix exception matching bug This fixes a bug where an exception is ignored if more conflicts are listed in the exception than actually conflicting jars are present. --- CHANGES.md | 12 +++- pom.xml | 2 +- .../invoker.properties | 16 +++++ .../pom.xml | 68 ++++++++++++++++++ .../verify.groovy | 21 ++++++ .../invoker.properties | 16 +++++ .../pom.xml | 72 +++++++++++++++++++ .../verify.groovy | 21 ++++++ .../invoker.properties | 16 +++++ .../test-class-conflict-class-exclude/pom.xml | 68 ++++++++++++++++++ .../verify.groovy | 21 ++++++ .../ConflictingDependency.java | 11 ++- 12 files changed, 339 insertions(+), 5 deletions(-) create mode 100644 src/it/test-class-conflict-class-exclude-non-match/invoker.properties create mode 100644 src/it/test-class-conflict-class-exclude-non-match/pom.xml create mode 100644 src/it/test-class-conflict-class-exclude-non-match/verify.groovy create mode 100644 src/it/test-class-conflict-class-exclude-three-ways/invoker.properties create mode 100644 src/it/test-class-conflict-class-exclude-three-ways/pom.xml create mode 100644 src/it/test-class-conflict-class-exclude-three-ways/verify.groovy create mode 100644 src/it/test-class-conflict-class-exclude/invoker.properties create mode 100644 src/it/test-class-conflict-class-exclude/pom.xml create mode 100644 src/it/test-class-conflict-class-exclude/verify.groovy diff --git a/CHANGES.md b/CHANGES.md index 2f811037..e5decb7e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,12 +1,20 @@ # Changes +##### 1.1.2 - 2015-06-16 + +__1.1.2 will be the last release that works with JDK 6! With Maven having moved to JDK 7, there +is no reason anymore for plugins to stick to an old JDK version.__ + +* Fix a bug where an exception is ignored if more conflicts are listed in the exception than +actually conflicting jars are present. + ##### 1.1.1 - 2015-01-18 * Issue #9. Ignore project references that are not on the dependency list. Thanks @victornoel. * Add maven properties for all simple (boolean, int, string) configuration settings. * Ning Issue #44: Allow duplicate checking against elements from the boot classpath - (this includes rt.jar). -* Ning Issue #19: Report a defined message if plugin skips execution. + (this includes rt.jar). +* Ning Issue #19: Report a defined message if plugin skips execution. ##### 1.1.0 - 2014-12-27 diff --git a/pom.xml b/pom.xml index f96ed353..31b070c1 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ org.basepom basepom-standard-oss - 8 + 11 org.basepom.maven diff --git a/src/it/test-class-conflict-class-exclude-non-match/invoker.properties b/src/it/test-class-conflict-class-exclude-non-match/invoker.properties new file mode 100644 index 00000000..2d14e03d --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-non-match/invoker.properties @@ -0,0 +1,16 @@ +# +# 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. +# + +invoker.goals=clean verify +invoker.buildResult = failure diff --git a/src/it/test-class-conflict-class-exclude-non-match/pom.xml b/src/it/test-class-conflict-class-exclude-non-match/pom.xml new file mode 100644 index 00000000..ecd74250 --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-non-match/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + @project.groupId@.@project.artifactId@ + basepom + 1.0.under-test + + + test-class-conflict-class-exclude-non-match + + + + testjar + first-class-jar + 1.0.under-test + + + testjar + first-diff-jar + 1.0.under-test + + + + + + + @project.groupId@ + @project.artifactId@ + + true + + + + + testjar + first-class-jar + + + testjar + first-diff-jar + + + + diff.NotDemo + + + + + + + + diff --git a/src/it/test-class-conflict-class-exclude-non-match/verify.groovy b/src/it/test-class-conflict-class-exclude-non-match/verify.groovy new file mode 100644 index 00000000..52ce01ad --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-non-match/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +import static org.basepom.mojo.duplicatefinder.groovy.ITools.* + +def result = loadTestXml(basedir) + +overallState(CONFLICT_DIFF, 1, FAILED, result) +checkConflictResult("diff.Demo", TYPE_CLASS, CONFLICT_DIFF, NOT_EXCEPTED, PRINTED, FAILED, findConflictResult(result, FIRST_CLASS_JAR, FIRST_DIFF_JAR)) + +return true diff --git a/src/it/test-class-conflict-class-exclude-three-ways/invoker.properties b/src/it/test-class-conflict-class-exclude-three-ways/invoker.properties new file mode 100644 index 00000000..ee6fc574 --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-three-ways/invoker.properties @@ -0,0 +1,16 @@ +# +# 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. +# + +invoker.goals=clean verify +invoker.buildResult = success diff --git a/src/it/test-class-conflict-class-exclude-three-ways/pom.xml b/src/it/test-class-conflict-class-exclude-three-ways/pom.xml new file mode 100644 index 00000000..8f00ec91 --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-three-ways/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + + + @project.groupId@.@project.artifactId@ + basepom + 1.0.under-test + + + test-class-conflict-class-exclude-three-ways + + + + testjar + first-class-jar + 1.0.under-test + + + testjar + first-diff-jar + 1.0.under-test + + + + + + + @project.groupId@ + @project.artifactId@ + + true + + + + + testjar + first-class-jar + + + testjar + second-class-jar + + + testjar + first-diff-jar + + + + diff.Demo + + + + + + + + diff --git a/src/it/test-class-conflict-class-exclude-three-ways/verify.groovy b/src/it/test-class-conflict-class-exclude-three-ways/verify.groovy new file mode 100644 index 00000000..5913a3cd --- /dev/null +++ b/src/it/test-class-conflict-class-exclude-three-ways/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +import static org.basepom.mojo.duplicatefinder.groovy.ITools.* + +def result = loadTestXml(basedir) + +overallState(NO_CONFLICT, 1, NOT_FAILED, result) +checkConflictResult("diff.Demo", TYPE_CLASS, CONFLICT_DIFF, EXCEPTED, NOT_PRINTED, NOT_FAILED, findConflictResult(result, FIRST_CLASS_JAR, FIRST_DIFF_JAR)) + +return true diff --git a/src/it/test-class-conflict-class-exclude/invoker.properties b/src/it/test-class-conflict-class-exclude/invoker.properties new file mode 100644 index 00000000..ee6fc574 --- /dev/null +++ b/src/it/test-class-conflict-class-exclude/invoker.properties @@ -0,0 +1,16 @@ +# +# 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. +# + +invoker.goals=clean verify +invoker.buildResult = success diff --git a/src/it/test-class-conflict-class-exclude/pom.xml b/src/it/test-class-conflict-class-exclude/pom.xml new file mode 100644 index 00000000..b60caf0a --- /dev/null +++ b/src/it/test-class-conflict-class-exclude/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + @project.groupId@.@project.artifactId@ + basepom + 1.0.under-test + + + test-class-conflict-class-exclude + + + + testjar + first-class-jar + 1.0.under-test + + + testjar + first-diff-jar + 1.0.under-test + + + + + + + @project.groupId@ + @project.artifactId@ + + true + + + + + testjar + first-class-jar + + + testjar + first-diff-jar + + + + diff.Demo + + + + + + + + diff --git a/src/it/test-class-conflict-class-exclude/verify.groovy b/src/it/test-class-conflict-class-exclude/verify.groovy new file mode 100644 index 00000000..5913a3cd --- /dev/null +++ b/src/it/test-class-conflict-class-exclude/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +import static org.basepom.mojo.duplicatefinder.groovy.ITools.* + +def result = loadTestXml(basedir) + +overallState(NO_CONFLICT, 1, NOT_FAILED, result) +checkConflictResult("diff.Demo", TYPE_CLASS, CONFLICT_DIFF, EXCEPTED, NOT_PRINTED, NOT_FAILED, findConflictResult(result, FIRST_CLASS_JAR, FIRST_DIFF_JAR)) + +return true diff --git a/src/main/java/org/basepom/mojo/duplicatefinder/ConflictingDependency.java b/src/main/java/org/basepom/mojo/duplicatefinder/ConflictingDependency.java index 325d1166..813146d3 100644 --- a/src/main/java/org/basepom/mojo/duplicatefinder/ConflictingDependency.java +++ b/src/main/java/org/basepom/mojo/duplicatefinder/ConflictingDependency.java @@ -164,11 +164,15 @@ public boolean isForArtifacts(final boolean bootClasspathConflict, final Set conflictingDependencies.size()) { return false; } - int numMatches = conflictingDependencies.size(); + // Every artifact must be matched. + int numMatches = artifacts.size(); for (final Artifact artifact : artifacts) { for (final MavenCoordinates conflictingDependency : conflictingDependencies) { @@ -176,6 +180,9 @@ public boolean isForArtifacts(final boolean bootClasspathConflict, final Set