You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by tr...@apache.org on 2005/06/13 18:45:43 UTC
svn commit: r190423 [2/2] -
/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum
/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store
/maven/continuum/trunk/continuum-core-it
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m1
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shell
/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store
/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum
/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/maven/m1
/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven
/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store
/maven/continuum/trunk/continuum-model/src/main/resources
/maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc
/maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc
Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java Mon Jun 13 09:45:42 2005
@@ -26,6 +26,7 @@
import org.apache.maven.continuum.execution.shell.ShellBuildResult;
import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
+import org.apache.maven.continuum.execution.ant.AntBuildResult;
import org.apache.maven.continuum.project.ContinuumBuild;
import org.apache.maven.continuum.project.ContinuumBuildResult;
import org.apache.maven.continuum.project.ContinuumJPoxStore;
@@ -175,8 +176,7 @@
"1.0",
"a b",
"maven2",
- "/tmp",
- configuration );
+ "/tmp" );
String projectId = store.addProject( makeProject( "Test Project",
"scm:local:src/test/repo",
@@ -184,8 +184,7 @@
"1.0",
"a b",
"maven2",
- "/tmp",
- configuration ) );
+ "/tmp" ) );
assertNotNull( "The project id is null.", projectId );
@@ -223,7 +222,6 @@
String commandLineArguments = "";
String builderId = "maven2";
String workingDirectory = "/tmp";
- Properties properties = new Properties();
String projectId = store.addProject( makeProject( name,
scmUrl,
@@ -231,8 +229,7 @@
version,
commandLineArguments,
builderId,
- workingDirectory,
- properties ) );
+ workingDirectory ) );
// ----------------------------------------------------------------------
//
@@ -269,7 +266,6 @@
String nagEmailAddress2 = "2@bar";
String version2 = "v2";
String commandLineArguments2 = "";
- Properties properties2 = new Properties();
store.updateProject( projectId,
name2,
@@ -288,7 +284,6 @@
commandLineArguments2,
builderId,
workingDirectory,
- properties2,
project );
// ----------------------------------------------------------------------
@@ -325,7 +320,6 @@
String commandLineArguments1 = "";
String builderId1 = "maven2";
String workingDirectory1 = "/tmp";
- Properties configuration1 = new Properties();
String id1 = addProject( store,
name1,
@@ -334,8 +328,7 @@
version1,
commandLineArguments1,
builderId1,
- workingDirectory1,
- configuration1 );
+ workingDirectory1 );
String name2 = "Test Project 2";
String scmUrl2 = "scm:local:src/test/repo/bar";
@@ -344,7 +337,6 @@
String commandLineArguments2 = "";
String builderId2 = "maven2";
String workingDirectory2 = "/tmp";
- Properties configuration2 = new Properties();
String id2 = addProject( store,
name2,
@@ -353,8 +345,7 @@
version2,
commandLineArguments2,
builderId2,
- workingDirectory2,
- configuration2 );
+ workingDirectory2 );
Map projects = new HashMap();
@@ -379,7 +370,6 @@
commandLineArguments1,
builderId1,
workingDirectory1,
- configuration1,
project1 );
ContinuumProject project2 = (ContinuumProject) projects.get( name2 );
@@ -392,41 +382,40 @@
commandLineArguments2,
builderId2,
workingDirectory2,
- configuration2,
project2 );
}
- public void testUpdateProjectConfiguration()
- throws Exception
- {
- ContinuumStore store = (ContinuumStore) lookup( ContinuumStore.ROLE );
-
- String projectId = addProject( "Update Test Project", "scm:update-project" );
-
- ContinuumProject project = store.getProject( projectId );
-
- assertEquals( 0, project.getConfiguration().size() );
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- Properties expected = new Properties();
-
- expected.put( "key", "value" );
-
- store.updateProjectConfiguration( projectId, expected );
-
- Properties actual = store.getProject( projectId ).getConfiguration();
-
- assertNotNull( "The configuration is null", actual );
-
- assertEquals( expected.size(), actual.size() );
-
- assertTrue( actual.containsKey( "key" ) );
-
- assertEquals( "value", actual.getProperty( "key" ) );
- }
+// public void testUpdateProjectConfiguration()
+// throws Exception
+// {
+// ContinuumStore store = (ContinuumStore) lookup( ContinuumStore.ROLE );
+//
+// String projectId = addProject( "Update Test Project", "scm:update-project" );
+//
+// ContinuumProject project = store.getProject( projectId );
+//
+// assertEquals( 0, project.getConfiguration().size() );
+//
+// // ----------------------------------------------------------------------
+// //
+// // ----------------------------------------------------------------------
+//
+// Properties expected = new Properties();
+//
+// expected.put( "key", "value" );
+//
+// store.updateProjectConfiguration( projectId, expected );
+//
+// Properties actual = store.getProject( projectId ).getConfiguration();
+//
+// assertNotNull( "The configuration is null", actual );
+//
+// assertEquals( expected.size(), actual.size() );
+//
+// assertTrue( actual.containsKey( "key" ) );
+//
+// assertEquals( "value", actual.getProperty( "key" ) );
+// }
public void testRemoveProject()
throws Exception
@@ -473,8 +462,40 @@
store.setUpdateDone( projectId );
+ // ----------------------------------------------------------------------
+ // Construct a build object
+ // ----------------------------------------------------------------------
+
String buildId = store.createBuild( projectId, false );
+ UpdateScmResult updateScmResult = new UpdateScmResult();
+
+ updateScmResult.setCommandOutput( "commandOutput" );
+
+ updateScmResult.setProviderMessage( "providerMessage" );
+
+ updateScmResult.setSuccess( true );
+
+ ScmFile scmFile = new ScmFile();
+
+ scmFile.setPath( "/foo" );
+
+ updateScmResult.getUpdatedFiles().add( scmFile );
+
+ AntBuildResult buildResult = new AntBuildResult();
+
+ buildResult.setExitCode( 10 );
+
+ buildResult.setStandardError( "stderr" );
+
+ buildResult.setStandardOutput( "stdout" );
+
+ store.setBuildComplete( buildId, updateScmResult, buildResult );
+
+ // ----------------------------------------------------------------------
+ // Store and check the build object
+ // ----------------------------------------------------------------------
+
Collection builds = store.getBuildsForProject( projectId, 0, 0 );
assertNotNull( "The collection with all builds was null.", builds );
@@ -589,6 +610,8 @@
assertEquals( build.getId(), (String) expectedBuilds.get( 9 ) );
Collection actualBuilds = store.getBuildsForProject( projectId, 0, 0 );
+
+ assertEquals( 10, actualBuilds.size() );
}
public void testBuildResult()
@@ -718,8 +741,7 @@
"1.0",
"",
ContinuumBuildExecutor.MAVEN_TWO_EXECUTOR_ID,
- "/tmp",
- new Properties() );
+ "/tmp" );
}
public static ContinuumProject makeProject( String name,
@@ -728,8 +750,7 @@
String version,
String commandLineArguments,
String executorId,
- String workingDirectory,
- Properties configuration )
+ String workingDirectory )
{
ContinuumProject project = new MavenTwoProject();
@@ -740,7 +761,6 @@
project.setCommandLineArguments( commandLineArguments );
project.setExecutorId( executorId );
project.setWorkingDirectory( workingDirectory );
- project.setConfiguration( configuration );
return project;
}
@@ -754,6 +774,16 @@
checkOutScmResult.setSuccess( true );
+ checkOutScmResult.setCommandOutput( "commandOutput" );
+
+ checkOutScmResult.setProviderMessage( "providerMessage" );
+
+ ScmFile scmFile = new ScmFile();
+
+ scmFile.setPath( "/foo" );
+
+ checkOutScmResult.addCheckedOutFile( scmFile );
+
store.setCheckoutDone( projectId, checkOutScmResult, null, null );
project = store.getProject( projectId );
@@ -784,8 +814,7 @@
String version,
String commandLineArguments,
String executorId,
- String workingDirectory,
- Properties configuration )
+ String workingDirectory )
throws Exception
{
// String projectId = store.addProject( name,
@@ -802,8 +831,7 @@
version,
commandLineArguments,
executorId,
- workingDirectory,
- configuration ) );
+ workingDirectory ) );
CheckOutScmResult checkOutScmResult = new CheckOutScmResult();
@@ -851,7 +879,6 @@
expected.getCommandLineArguments(),
expected.getExecutorId(),
expected.getWorkingDirectory(),
- expected.getConfiguration(),
actual );
}
@@ -863,7 +890,6 @@
String commandLineArguments,
String builderId,
String workingDirectory,
- Properties configuration,
ContinuumProject actual )
{
assertEquals( "project.id", projectId, actual.getId() );
@@ -882,15 +908,15 @@
assertEquals( "project.workingDirectory", workingDirectory, actual.getWorkingDirectory() );
- for ( Iterator it = configuration.keySet().iterator(); it.hasNext(); )
- {
- String key = (String) it.next();
-
- String value = actual.getConfiguration().getProperty( key );
-
- assertNotNull( "Value for key '" + key + "' was null.", value );
-
- assertEquals( "The values for '" + key + "' doesn't match.", configuration.getProperty( key ), value );
- }
+// for ( Iterator it = configuration.keySet().iterator(); it.hasNext(); )
+// {
+// String key = (String) it.next();
+//
+// String value = actual.getConfiguration().getProperty( key );
+//
+// assertNotNull( "Value for key '" + key + "' was null.", value );
+//
+// assertEquals( "The values for '" + key + "' doesn't match.", configuration.getProperty( key ), value );
+// }
}
}
Modified: maven/continuum/trunk/continuum-model/src/main/resources/continuum.mdo
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-model/src/main/resources/continuum.mdo?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-model/src/main/resources/continuum.mdo (original)
+++ maven/continuum/trunk/continuum-model/src/main/resources/continuum.mdo Mon Jun 13 09:45:42 2005
@@ -65,6 +65,7 @@
<version>1.0.0</version>
<type>String</type>
</field>
+<!--
<field>
<name>configuration</name>
<version>1.0.0</version>
@@ -74,6 +75,7 @@
<multiplicity>*</multiplicity>
</association>
</field>
+-->
<field>
<name>builds</name>
<version>1.0.0</version>
Modified: maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpc.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpc.java?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpc.java (original)
+++ maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpc.java Mon Jun 13 09:45:42 2005
@@ -37,8 +37,8 @@
Hashtable removeProject( String projectId );
- Hashtable updateProjectConfiguration( String projectId,
- Hashtable configuration );
+// Hashtable updateProjectConfiguration( String projectId,
+// Hashtable configuration );
Hashtable getProject( String projectId );
@@ -87,15 +87,21 @@
Hashtable addMavenOneProject( Hashtable mavenOneProject );
+ Hashtable updateMavenOneProject( Hashtable mavenOneProject );
+
// ----------------------------------------------------------------------
// Ant projects
// ----------------------------------------------------------------------
Hashtable addAntProject( Hashtable antProject );
+ Hashtable updateAntProject( Hashtable antProject );
+
// ----------------------------------------------------------------------
// Shell projects
// ----------------------------------------------------------------------
Hashtable addShellProject( Hashtable shellProject );
+
+ Hashtable updateShellProject( Hashtable shellProject );
}
Modified: maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultContinuumXmlRpc.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultContinuumXmlRpc.java?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultContinuumXmlRpc.java (original)
+++ maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultContinuumXmlRpc.java Mon Jun 13 09:45:42 2005
@@ -24,8 +24,6 @@
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.Vector;
@@ -83,30 +81,30 @@
}
}
- public Hashtable updateProjectConfiguration( String projectId,
- Hashtable configuration )
- {
- try
- {
- Properties configurationProperties = new Properties();
-
- for ( Iterator it = configuration.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- configurationProperties.put( entry.getKey().toString(), entry.getValue().toString() );
- }
-
- continuum.updateProjectConfiguration( projectId, configurationProperties );
-
- return makeHashtable();
- }
- catch ( Throwable e )
- {
- return handleException( "ContinuumXmlRpc.updateProjectConfiguration()",
- "Project id: '" + projectId + "'.", e );
- }
- }
+// public Hashtable updateProjectConfiguration( String projectId,
+// Hashtable configuration )
+// {
+// try
+// {
+// Properties configurationProperties = new Properties();
+//
+// for ( Iterator it = configuration.entrySet().iterator(); it.hasNext(); )
+// {
+// Map.Entry entry = (Map.Entry) it.next();
+//
+// configurationProperties.put( entry.getKey().toString(), entry.getValue().toString() );
+// }
+//
+// continuum.updateProjectConfiguration( projectId, configurationProperties );
+//
+// return makeHashtable();
+// }
+// catch ( Throwable e )
+// {
+// return handleException( "ContinuumXmlRpc.updateProjectConfiguration()",
+// "Project id: '" + projectId + "'.", e );
+// }
+// }
public Hashtable getProject( String projectId )
{
@@ -277,6 +275,83 @@
}
// ----------------------------------------------------------------------
+ // Maven 2.x projects
+ // ----------------------------------------------------------------------
+
+ public Hashtable addMavenTwoProject( String url )
+ {
+ try
+ {
+ // TODO: Get the added projects and return the IDs
+ ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( url );
+
+ Collection projects = result.getProjects();
+
+ Collection projectIds = new Vector( projects.size() );
+
+ for ( Iterator it = projects.iterator(); it.hasNext(); )
+ {
+ ContinuumProject project = (ContinuumProject) it.next();
+
+ projectIds.add( project.getId() );
+
+ getLogger().info( "project id: " + project.getId() );
+ }
+
+ return makeHashtable( "projectIds", xmlRpcHelper.collectionToVector( projectIds, false ) );
+ }
+ catch ( Throwable e )
+ {
+ return handleException( "ContinuumXmlRpc.addMavenTwoProject()",
+ "URL: '" + url + "'.", e );
+ }
+ }
+
+ public Hashtable addMavenTwoProject( Hashtable mavenTwoProject )
+ {
+ try
+ {
+ MavenTwoProject project = new MavenTwoProject();
+
+ xmlRpcHelper.hashtableToObject( mavenTwoProject, project );
+
+ String projectId = continuum.addMavenTwoProject( project );
+
+ // TODO: Get the added projects and return the IDs
+ Collection projectIds = new Vector();
+
+ projectIds.add( projectId );
+
+ getLogger().info( "project id: " + projectId );
+
+ return makeHashtable( "projectIds", xmlRpcHelper.collectionToVector( projectIds, false ) );
+ }
+ catch ( Throwable e )
+ {
+ return handleException( "ContinuumXmlRpc.addMavenTwoProject()", null, e );
+ }
+ }
+
+ public Hashtable updateMavenTwoProject( Hashtable mavenTwoProject )
+ {
+ MavenTwoProject project = new MavenTwoProject();
+
+ try
+ {
+ xmlRpcHelper.hashtableToObject( mavenTwoProject, project );
+
+ continuum.updateMavenTwoProject( project );
+
+ return makeHashtable();
+ }
+ catch ( Throwable e )
+ {
+ return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
+ "Project id: " + project.getId(), e );
+ }
+ }
+
+ // ----------------------------------------------------------------------
// Maven 1.x projects
// ----------------------------------------------------------------------
@@ -331,6 +406,30 @@
}
}
+ public Hashtable updateMavenOneProject( Hashtable mavenOneProject )
+ {
+ MavenOneProject project = new MavenOneProject();
+
+ try
+ {
+ xmlRpcHelper.hashtableToObject( mavenOneProject, project );
+
+ continuum.updateMavenOneProject( project );
+
+ return makeHashtable();
+ }
+ catch ( Throwable e )
+ {
+ return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
+ "Project id: " + project.getId(), e );
+ }
+
+ }
+
+ // ----------------------------------------------------------------------
+ // Ant Projects
+ // ----------------------------------------------------------------------
+
public Hashtable addAntProject( Hashtable antProject )
{
try
@@ -354,94 +453,71 @@
}
}
- public Hashtable addShellProject( Hashtable shellProject )
+ public Hashtable updateAntProject( Hashtable antProject )
{
+ AntProject project = new AntProject();
+
try
{
- ShellProject project = new ShellProject();
-
- xmlRpcHelper.hashtableToObject( shellProject, project );
-
- String projectId = continuum.addShellProject( project );
+ xmlRpcHelper.hashtableToObject( antProject, project );
- Collection projectIds = new ArrayList();
+ continuum.updateAntProject( project );
- projectIds.add( projectId );
-
- return makeHashtable( "projectIds", xmlRpcHelper.collectionToVector( projectIds, false ) );
+ return makeHashtable();
}
catch ( Throwable e )
{
- return handleException( "ContinuumXmlRpc.ShellProject()",
- null, e );
+ return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
+ "Project id: " + project.getId(), e );
}
}
// ----------------------------------------------------------------------
- // Maven 2.x projects
+ // Shell Projects
// ----------------------------------------------------------------------
- public Hashtable addMavenTwoProject( String url )
+ public Hashtable addShellProject( Hashtable shellProject )
{
- getLogger().info( "addMavenTwoProject( String url )" );
try
{
- // TODO: Get the added projects and return the IDs
- ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( url );
-
- Collection projects = result.getProjects();
+ ShellProject project = new ShellProject();
- Collection projectIds = new Vector( projects.size() );
+ xmlRpcHelper.hashtableToObject( shellProject, project );
- for ( Iterator it = projects.iterator(); it.hasNext(); )
- {
- ContinuumProject project = (ContinuumProject) it.next();
+ String projectId = continuum.addShellProject( project );
- projectIds.add( project.getId() );
+ Collection projectIds = new ArrayList();
- getLogger().info( "project id: " + project.getId() );
- }
+ projectIds.add( projectId );
return makeHashtable( "projectIds", xmlRpcHelper.collectionToVector( projectIds, false ) );
}
catch ( Throwable e )
{
- return handleException( "ContinuumXmlRpc.addMavenTwoProject()",
- "URL: '" + url + "'.", e );
+ return handleException( "ContinuumXmlRpc.ShellProject()",
+ null, e );
}
}
- public Hashtable addMavenTwoProject( Hashtable mavenTwoProject )
+ public Hashtable updateShellProject( Hashtable shellProject )
{
- getLogger().info( "addMavenTwoProject( Hashtable mavenTwoProject )" );
+ ShellProject project = new ShellProject();
+
try
{
- MavenTwoProject project = new MavenTwoProject();
-
- xmlRpcHelper.hashtableToObject( mavenTwoProject, project );
-
- String projectId = continuum.addMavenTwoProject( project );
-
- // TODO: Get the added projects and return the IDs
- Collection projectIds = new Vector();
-
- projectIds.add( projectId );
+ xmlRpcHelper.hashtableToObject( shellProject, project );
- getLogger().info( "project id: " + projectId );
+ continuum.updateShellProject( project );
- return makeHashtable( "projectIds", xmlRpcHelper.collectionToVector( projectIds, false ) );
+ return makeHashtable();
}
catch ( Throwable e )
{
- return handleException( "ContinuumXmlRpc.addMavenTwoProject()", null, e );
+ return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
+ "Project id: " + project.getId(), e );
}
}
- public Hashtable updateMavenTwoProject( Hashtable mavenTwoProject )
- {
- throw new RuntimeException( "NOT IMPLEMENTED" );
- }
-
// ----------------------------------------------------------------------
// Object to Hashtable converters
// ----------------------------------------------------------------------
@@ -461,18 +537,18 @@
Hashtable hashtable = xmlRpcHelper.objectToHashtable( project, excludedProperties );
- Properties configuration = project.getConfiguration();
-
- Hashtable configurationHashtable = new Hashtable();
-
- for ( Iterator it = configuration.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- configurationHashtable.put( entry.getKey().toString(), entry.getValue().toString() );
- }
-
- hashtable.put( "configuration", configurationHashtable );
+// Properties configuration = project.getConfiguration();
+//
+// Hashtable configurationHashtable = new Hashtable();
+//
+// for ( Iterator it = configuration.entrySet().iterator(); it.hasNext(); )
+// {
+// Map.Entry entry = (Map.Entry) it.next();
+//
+// configurationHashtable.put( entry.getKey().toString(), entry.getValue().toString() );
+// }
+//
+// hashtable.put( "configuration", configurationHashtable );
return hashtable;
}
Modified: maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultXmlRpcHelper.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultXmlRpcHelper.java?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultXmlRpcHelper.java (original)
+++ maven/continuum/trunk/continuum-xmlrpc/src/main/java/org/apache/maven/continuum/xmlrpc/DefaultXmlRpcHelper.java Mon Jun 13 09:45:42 2005
@@ -122,6 +122,14 @@
// {
// }
+ value = convertValueToSetterType( setter.getParameterTypes()[ 0 ], value );
+
+ if ( value == null )
+ {
+ continue;
+ }
+
+ getLogger().info( "Invoking " + setter.toString() + " with " + value.getClass().getName() );
setter.invoke( target, new Object[]{value} );
}
}
@@ -302,6 +310,8 @@
{
getLogger().warn( "No setter for field '" + key + "' on the class '" + clazz.getName() + "'. " +
"The class has multiple setters for the field." );
+
+ return null;
}
return setter;
@@ -335,5 +345,48 @@
}
return map;
+ }
+
+ private Object convertValueToSetterType( Class type, Object value )
+ {
+ if ( value.equals( type.getClass() ) )
+ {
+ return value;
+ }
+
+ if ( type == String.class )
+ {
+ return value;
+ }
+
+ if ( type.getClass().equals( Integer.class ) || type.equals( int.class ) )
+ {
+ if ( value.getClass().equals( String.class ) )
+ {
+ return new Integer( (String) value );
+ }
+
+ if ( value.getClass().equals( Integer.class ) || value.getClass().equals( int.class ) )
+ {
+ return value;
+ }
+ }
+
+ if ( type.getClass().equals( Boolean.class ) || type.equals( boolean.class ) )
+ {
+ if ( value.getClass().equals( String.class ) )
+ {
+ return new Boolean( (String) value );
+ }
+
+ if ( value.getClass().equals( Boolean.class ) || value.getClass().equals( boolean.class ) )
+ {
+ return value;
+ }
+ }
+
+ getLogger().error( "Could not convert a " + value.getClass().getName() + " to a " + type.getName() );
+
+ return null;
}
}
Modified: maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/XmlRpcHelperTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/XmlRpcHelperTest.java?rev=190423&r1=190422&r2=190423&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/XmlRpcHelperTest.java (original)
+++ maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/XmlRpcHelperTest.java Mon Jun 13 09:45:42 2005
@@ -17,6 +17,7 @@
*/
import java.util.Hashtable;
+import java.util.Date;
import org.codehaus.plexus.PlexusTestCase;
@@ -121,6 +122,10 @@
public void getBar( int value )
{
}
+
+ public void setNonConvertableField( Date date )
+ {
+ }
}
public void testSimpleBean()
@@ -229,6 +234,34 @@
xmlRpcHelper.hashtableToObject( hashtable, bean );
assertEquals( "foo", bean.getFoo() );
+
+ assertEquals( 17, bean.getBar() );
+
+ assertEquals( true, bean.isBool() );
+ }
+
+ public void testHashtableToObjectWithStringArguments()
+ throws Exception
+ {
+ XmlRpcHelper xmlRpcHelper = (XmlRpcHelper) lookup( XmlRpcHelper.ROLE );
+
+ SimleBean bean = new SimleBean();
+
+ Hashtable hashtable = new Hashtable();
+
+ hashtable.put( "foo", "foo" );
+
+ hashtable.put( "bar", new Integer( 17 ).toString() );
+
+ hashtable.put( "bool", Boolean.TRUE.toString() );
+
+ xmlRpcHelper.hashtableToObject( hashtable, bean );
+
+ assertEquals( "foo", bean.getFoo() );
+
+ assertEquals( 17, bean.getBar() );
+
+ assertEquals( true, bean.isBool() );
}
// ----------------------------------------------------------------------