mirror of https://github.com/apache/maven.git
[MNG-5714] Add Merger for Maven Toolchain
implement equals() and hashCode() for DefaultToolchain to help the Merger
This commit is contained in:
parent
2252862e2a
commit
a131ac8d0a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue