[MNG-5718] Change 'provides' from Object to Properties in toolchains.xml

This commit is contained in:
Robert Scholte 2014-11-03 23:10:06 +01:00
parent 01a879384c
commit fa4f7040ad
5 changed files with 78 additions and 137 deletions

View File

@ -19,14 +19,12 @@ 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 java.util.Properties;
import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
*
@ -130,54 +128,14 @@ public abstract class DefaultToolchain
return false;
}
Xpp3Dom thisProvides = (Xpp3Dom) this.getModel().getProvides();
Xpp3Dom otherProvides = (Xpp3Dom) other.getModel().getProvides();
Properties thisProvides = this.getModel().getProvides();
Properties otherProvides = other.getModel().getProvides();
if ( thisProvides == null ? otherProvides != null : otherProvides == null )
if ( thisProvides == null ? otherProvides != null : !thisProvides.equals( otherProvides ) )
{
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;
}
@ -188,13 +146,7 @@ public abstract class DefaultToolchain
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();
hashCode = 31 * hashCode + this.getModel().getProvides().hashCode();
}
return hashCode;
}

View File

@ -20,6 +20,8 @@ package org.apache.maven.toolchain.java;
*/
import java.io.File;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.maven.toolchain.MisconfiguredToolchainException;
import org.apache.maven.toolchain.RequirementMatcherFactory;
@ -76,13 +78,11 @@ public class DefaultJavaToolchainFactory
}
//now populate the provides section.
//TODO possibly move at least parts to a utility method or abstract implementation.
dom = (Xpp3Dom) model.getProvides();
Xpp3Dom[] provides = dom.getChildren();
for ( Xpp3Dom provide : provides )
Properties provides = model.getProvides();
for ( Entry<Object, Object> provide : provides.entrySet() )
{
String key = provide.getName();
String value = provide.getValue();
String key = (String) provide.getKey();
String value = (String) provide.getValue();
if ( value == null )
{
throw new MisconfiguredToolchainException(

View File

@ -48,49 +48,49 @@
<classes>
<class java.clone="deep">
<name>TrackableBase</name>
<version>1.1.0+</version>
<description>
common base class that contains code to track the source for
this instance (USER|GLOBAL)
</description>
<codeSegments>
<codeSegment>
<version>1.1.0+</version>
<code>
<![CDATA[
public static final String USER_LEVEL = "user-level";
public static final String GLOBAL_LEVEL = "global-level";
private String sourceLevel = USER_LEVEL;
private boolean sourceLevelSet = false;
public void setSourceLevel( String sourceLevel )
{
if ( sourceLevelSet )
{
throw new IllegalStateException( "Cannot reset sourceLevel attribute; it is already set to: " + sourceLevel );
}
else if ( !( USER_LEVEL.equals( sourceLevel ) || GLOBAL_LEVEL.equals( sourceLevel ) ) )
{
throw new IllegalArgumentException( "sourceLevel must be one of: {" + USER_LEVEL + "," + GLOBAL_LEVEL + "}" );
}
else
{
this.sourceLevel = sourceLevel;
this.sourceLevelSet = true;
}
}
public String getSourceLevel()
{
return sourceLevel;
}
]]>
</code>
</codeSegment>
</codeSegments>
</class>
<name>TrackableBase</name>
<version>1.1.0+</version>
<description>
common base class that contains code to track the source for
this instance (USER|GLOBAL)
</description>
<codeSegments>
<codeSegment>
<version>1.1.0+</version>
<code>
<![CDATA[
public static final String USER_LEVEL = "user-level";
public static final String GLOBAL_LEVEL = "global-level";
private String sourceLevel = USER_LEVEL;
private boolean sourceLevelSet = false;
public void setSourceLevel( String sourceLevel )
{
if ( sourceLevelSet )
{
throw new IllegalStateException( "Cannot reset sourceLevel attribute; it is already set to: " + sourceLevel );
}
else if ( !( USER_LEVEL.equals( sourceLevel ) || GLOBAL_LEVEL.equals( sourceLevel ) ) )
{
throw new IllegalArgumentException( "sourceLevel must be one of: {" + USER_LEVEL + "," + GLOBAL_LEVEL + "}" );
}
else
{
this.sourceLevel = sourceLevel;
this.sourceLevelSet = true;
}
}
public String getSourceLevel()
{
return sourceLevel;
}
]]>
</code>
</codeSegment>
</codeSegments>
</class>
<class rootElement="true" xml.tagName="toolchains" xsd.compositor="sequence">
<name>PersistedToolchains</name>
<superClass>TrackableBase</superClass>
@ -131,16 +131,33 @@
</field>
<field>
<name>provides</name>
<version>1.0.0+</version>
<type>DOM</type>
<version>1.0.0/1.0.99</version> <!-- fake upperbound, it's inclusive -->
<type>DOM</type> <!-- DOM for Maven 2.0.9/2.3.3 -->
<description>
<![CDATA[
<p>Toolchain identification information, which will be matched against project requirements.</p>
<p>Actual content structure is completely open: each toochain type will define its own format and semantics.</p>
<p>Actual content structure is completely open: each toolchain type will define its own format and semantics.</p>
<p>In general, this is a properties format: <code>&lt;name&gt;value&lt;/name&gt;</code> with
predefined properties names.</p>
]]></description>
</field>
<field>
<name>provides</name>
<version>1.1.0+</version>
<type>Properties</type> <!-- Properties for Maven 2.3.4+ -->
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>
<![CDATA[
<p>Toolchain identification information, which will be matched against project requirements.</p>
<p>For Maven 2.0.9/3.2.3 the actual content structure was completely open: each toolchain type would define its own format and semantics.</p>
<p>In general, this was a properties format: <code>&lt;name&gt;value&lt;/name&gt;</code> with
predefined properties names.</p>
<p>Since Maven 3.2.4 the type for this field has been changed to Properties.</p>
]]></description>
</field>
<field>
<name>configuration</name>
<version>1.0.0+</version>

View File

@ -19,7 +19,7 @@ package org.apache.maven.toolchain;
* under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
@ -51,10 +51,9 @@ public class DefaultToolchainTest
DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
// tc1{type:jdk,id:default} tc2{type:jdk} (no id, so should be considered 'default')
assertTrue( tc1.equals( tc1 ) );
assertTrue( tc1.equals( tc2 ) );
assertTrue( tc2.equals( tc1 ) );
assertFalse( tc1.equals( tc2 ) );
assertFalse( tc2.equals( tc1 ) );
assertTrue( tc2.equals( tc2 ) );
}
finally
@ -63,29 +62,4 @@ public class DefaultToolchainTest
IOUtil.close( jdksExtraIS );
}
}
@Test
public void testHashCode() throws Exception
{
InputStream jdksIS = null;
InputStream jdksExtraIS = null;
try
{
jdksIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks.xml" );
jdksExtraIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks-extra.xml" );
PersistedToolchains jdks = reader.read( jdksIS );
PersistedToolchains jdksExtra = reader.read( jdksExtraIS );
DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
assertEquals( tc1.hashCode(), tc2.hashCode() );
}
finally
{
IOUtil.close( jdksIS );
IOUtil.close( jdksExtraIS );
}
}
}

View File

@ -25,7 +25,6 @@ under the License.
<provides>
<version>1.5</version>
<vendor>sun</vendor>
<id>default</id>
</provides>
<configuration>
<jdkHome>${env.JAVA_HOME}</jdkHome>
@ -36,7 +35,6 @@ under the License.
<provides>
<version>1.6</version>
<vendor>sun</vendor>
<id>ide</id>
</provides>
<configuration>
<jdkHome>${env.JAVA_HOME}</jdkHome>