This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new fca7ec2  fix: correct inverted equality checks in WarUtils.isRelated() 
(#625)
fca7ec2 is described below

commit fca7ec27bf6b03af3c3a0a7b3a05fa3e6cda2aa6
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sun Nov 22 21:57:17 2026 +0000

    fix: correct inverted equality checks in WarUtils.isRelated() (#625)
    
    * fix: correct inverted equality checks in WarUtils.isRelated()
    
    The method returned false when version, type, classifier, or scope
    were equal between artifact and dependency — the opposite of the
    intended logic. Fixed by negating the equality checks.
    
    Fixes #619
    
    * Potential fix for pull request finding
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    
    ---------
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
---
 .../apache/maven/plugins/war/util/WarUtils.java    |   8 +-
 .../maven/plugins/war/util/WarUtilsTest.java       | 176 +++++++++++++++++++++
 2 files changed, 180 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java 
b/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
index 54d83d1..fbe4d35 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
@@ -66,16 +66,16 @@ public class WarUtils {
         if (!Objects.equals(artifact.getArtifactId(), 
dependency.getArtifactId())) {
             return false;
         }
-        if (Objects.equals(artifact.getVersion(), dependency.getVersion())) {
+        if (!Objects.equals(artifact.getVersion(), dependency.getVersion())) {
             return false;
         }
-        if (Objects.equals(artifact.getType(), dependency.getType())) {
+        if (!Objects.equals(artifact.getType(), dependency.getType())) {
             return false;
         }
-        if (Objects.equals(artifact.getClassifier(), 
dependency.getClassifier())) {
+        if (!Objects.equals(artifact.getClassifier(), 
dependency.getClassifier())) {
             return false;
         }
-        if (Objects.equals(artifact.getScope(), dependency.getScope())) {
+        if (!Objects.equals(artifact.getScope(), dependency.getScope())) {
             return false;
         }
         if (artifact.isOptional() != dependency.isOptional()) {
diff --git a/src/test/java/org/apache/maven/plugins/war/util/WarUtilsTest.java 
b/src/test/java/org/apache/maven/plugins/war/util/WarUtilsTest.java
new file mode 100644
index 0000000..daee05a
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/war/util/WarUtilsTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.war.util;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class WarUtilsTest {
+
+    private static Artifact createArtifact(
+            String groupId, String artifactId, String version, String type, 
String classifier, String scope) {
+        return new ArtifactStub() {
+            @Override
+            public String getGroupId() {
+                return groupId;
+            }
+
+            @Override
+            public String getArtifactId() {
+                return artifactId;
+            }
+
+            @Override
+            public String getVersion() {
+                return version;
+            }
+
+            @Override
+            public String getType() {
+                return type;
+            }
+
+            @Override
+            public String getClassifier() {
+                return classifier;
+            }
+
+            @Override
+            public String getScope() {
+                return scope;
+            }
+        };
+    }
+
+    private static Dependency createDependency(
+            String groupId, String artifactId, String version, String type, 
String classifier, String scope) {
+        Dependency dep = new Dependency();
+        dep.setGroupId(groupId);
+        dep.setArtifactId(artifactId);
+        dep.setVersion(version);
+        dep.setType(type);
+        dep.setClassifier(classifier);
+        dep.setScope(scope);
+        return dep;
+    }
+
+    @Test
+    void isRelatedShouldReturnTrueWhenAllAttributesMatch() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a", "1.0", "jar", null, 
"compile");
+        assertTrue(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenGroupIdDiffers() {
+        Artifact artifact = createArtifact("g1", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g2", "a", "1.0", "jar", 
null, "compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenArtifactIdDiffers() {
+        Artifact artifact = createArtifact("g", "a1", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a2", "1.0", "jar", 
null, "compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenVersionDiffers() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a", "2.0", "jar", null, 
"compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenTypeDiffers() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a", "1.0", "war", null, 
"compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenClassifierDiffers() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", "client", 
"compile");
+        Dependency dependency = createDependency("g", "a", "1.0", "jar", 
"server", "compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenScopeDiffers() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a", "1.0", "jar", null, 
"provided");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenOptionalDiffers() {
+        Artifact artifact = new ArtifactStub() {
+            @Override
+            public String getGroupId() {
+                return "g";
+            }
+
+            @Override
+            public String getArtifactId() {
+                return "a";
+            }
+
+            @Override
+            public String getVersion() {
+                return "1.0";
+            }
+
+            @Override
+            public String getType() {
+                return "jar";
+            }
+
+            @Override
+            public String getClassifier() {
+                return null;
+            }
+
+            @Override
+            public String getScope() {
+                return "compile";
+            }
+
+            @Override
+            public boolean isOptional() {
+                return true;
+            }
+        };
+        Dependency dependency = createDependency("g", "a", "1.0", "jar", null, 
"compile");
+        assertFalse(WarUtils.isRelated(artifact, dependency));
+    }
+
+    @Test
+    void isRelatedShouldReturnFalseWhenArtifactOrDependencyIsNull() {
+        Artifact artifact = createArtifact("g", "a", "1.0", "jar", null, 
"compile");
+        Dependency dependency = createDependency("g", "a", "1.0", "jar", null, 
"compile");
+        assertFalse(WarUtils.isRelated(null, dependency));
+        assertFalse(WarUtils.isRelated(artifact, null));
+    }
+}

Reply via email to