Repository: maven
Updated Branches:
  refs/heads/master 2252862e2 -> 2d086fde2


[MNG-5714] Add Merger for Maven Toolchain
implement equals() and hashCode() for DefaultToolchain to help the
Merger


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/a131ac8d
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/a131ac8d
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/a131ac8d

Branch: refs/heads/master
Commit: a131ac8d0a7f9563cedacc414ac15df5e717f62a
Parents: 2252862
Author: Robert Scholte <rfscho...@codehaus.org>
Authored: Sun Nov 2 13:22:12 2014 +0100
Committer: Robert Scholte <rfscho...@codehaus.org>
Committed: Sun Nov 2 20:20:23 2014 +0100

----------------------------------------------------------------------
 .../maven/toolchain/DefaultToolchain.java       | 103 ++++++++++++++++++-
 1 file changed, 101 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/a131ac8d/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java 
b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
index 11ad722..3aeb243 100644
--- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
+++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
@@ -19,11 +19,15 @@ package org.apache.maven.toolchain;
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.toolchain.java.DefaultJavaToolChain;
 import org.apache.maven.toolchain.model.ToolchainModel;
 import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  *
@@ -57,12 +61,13 @@ public abstract class DefaultToolchain
         this.type = type;
     }
 
+    @Override
     public final String getType()
     {
         return type != null ? type : model.getType();
     }
 
-
+    @Override
     public final ToolchainModel getModel()
     {
         return model;
@@ -73,7 +78,7 @@ public abstract class DefaultToolchain
         provides.put( type, matcher );
     }
 
-
+    @Override
     public boolean matchesRequirements( Map<String, String> requirements )
     {
         for ( Map.Entry<String, String> requirement : requirements.entrySet() )
@@ -100,4 +105,98 @@ public abstract class DefaultToolchain
     {
         return logger;
     }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == null )
+        {
+            return false;
+        }
+        
+        if ( this == obj )
+        {
+            return true;
+        }
+    
+        if ( !( obj instanceof DefaultToolchain ) )
+        {
+            return false;
+        }
+    
+        DefaultToolchain other = (DefaultToolchain) obj;
+
+        if ( type == null ? other.type != null : !type.equals( other.type ) )
+        {
+            return false;
+        }
+
+        Xpp3Dom thisProvides = (Xpp3Dom) this.getModel().getProvides();
+        Xpp3Dom otherProvides = (Xpp3Dom) other.getModel().getProvides();
+    
+        if ( thisProvides == null ? otherProvides != null : otherProvides == 
null )
+        {
+            return false;
+        }
+    
+        Xpp3Dom thisId = thisProvides.getChild( "id" );
+        Xpp3Dom otherId = otherProvides.getChild( "id" );
+        if ( ( thisId == null || "default".equals( thisId.getValue() ) )
+            && ( otherId == null || "default".equals( otherId.getValue() ) ) )
+        {
+            return true;
+        }
+    
+        List<String> names = new ArrayList<String>();
+    
+        // collect names of both provides, exclude id
+        for ( Xpp3Dom thisChild : thisProvides.getChildren() )
+        {
+            if ( "id".equals( thisChild.getName() ) )
+            {
+                continue;
+            }
+            names.add( thisChild.getName() );
+        }
+    
+        for ( Xpp3Dom thisChild : otherProvides.getChildren() )
+        {
+            if ( "id".equals( thisChild.getName() ) )
+            {
+                continue;
+            }
+            names.add( thisChild.getName() );
+        }
+    
+        for ( String name : names )
+        {
+            Xpp3Dom thisChild = thisProvides.getChild( name );
+            Xpp3Dom otherChild = otherProvides.getChild( name );
+    
+            if ( thisChild != null ? !thisChild.equals( otherChild ) : 
otherChild != null )
+            {
+                return false;
+            }
+        }
+    
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hashCode = ( type == null ) ? 0 : type.hashCode();
+        
+        if ( this.getModel().getProvides() != null )
+        {
+            Xpp3Dom providesElm = (Xpp3Dom) this.getModel().getProvides();
+            
+            Xpp3Dom idElm = providesElm.getChild( "id" );
+            
+            String idValue = ( idElm == null ? "default" : idElm.getValue() );
+            
+            hashCode = 31 * hashCode + idValue.hashCode();
+        }
+        return hashCode;
+    }
 }

Reply via email to