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/21 01:43:42 UTC

svn commit: r191590 [2/2] - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-core-it/ continuum-core/src/main/java/org/apache/maven/continuum/ continuum-core/src/main/java/org/apache/maven/continuum/bui...

Modified: maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/ContinuumStateContentGenerator.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/ContinuumStateContentGenerator.java?rev=191590&r1=191589&r2=191590&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/ContinuumStateContentGenerator.java (original)
+++ maven/continuum/trunk/continuum-web/src/main/java/org/apache/maven/continuum/web/tool/ContinuumStateContentGenerator.java Mon Jun 20 16:43:40 2005
@@ -33,11 +33,12 @@
 {
     public String generate( Object item )
     {
-        int state;
+        int state = 0;
 
         if ( item instanceof ContinuumProject )
         {
-            state = ( (ContinuumProject) item ).getState();
+            getLogger().warn( "The project doesn't have any state anymore" );
+//            state = ( (ContinuumProject) item ).getState();
         }
         else
         {

Modified: maven/continuum/trunk/continuum-xmlrpc/pom.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/pom.xml?rev=191590&r1=191589&r2=191590&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/pom.xml (original)
+++ maven/continuum/trunk/continuum-xmlrpc/pom.xml Mon Jun 20 16:43:40 2005
@@ -17,6 +17,12 @@
       <groupId>org.apache.maven.continuum</groupId>
       <artifactId>continuum-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <version>1.7.3.3</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>

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=191590&r1=191589&r2=191590&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 20 16:43:40 2005
@@ -258,7 +258,6 @@
     {
         try
         {
-            // TODO: Get the added projects and return the IDs
             ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( url );
 
             Collection projects = result.getProjects();
@@ -291,7 +290,6 @@
 
             String projectId = continuum.addMavenTwoProject( project );
 
-            // TODO: Get the added projects and return the IDs
             Collection projectIds = new Vector();
 
             projectIds.add( projectId );
@@ -306,10 +304,12 @@
 
     public Hashtable updateMavenTwoProject( Hashtable mavenTwoProject )
     {
-        MavenTwoProject project = new MavenTwoProject();
+        String id = getId( mavenTwoProject );
 
         try
         {
+            MavenTwoProject project = continuum.getMavenTwoProject( id );
+
             xmlRpcHelper.hashtableToObject( mavenTwoProject, project );
 
             continuum.updateMavenTwoProject( project );
@@ -319,7 +319,7 @@
         catch ( Throwable e )
         {
             return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
-                                    "Project id: " + project.getId(), e );
+                                    "Project id: '" + id + "'.", e );
         }
     }
 
@@ -378,10 +378,12 @@
 
     public Hashtable updateMavenOneProject( Hashtable mavenOneProject )
     {
-        MavenOneProject project = new MavenOneProject();
+        String id = getId( mavenOneProject );
 
         try
         {
+            MavenOneProject project = continuum.getMavenOneProject( id );
+
             xmlRpcHelper.hashtableToObject( mavenOneProject, project );
 
             continuum.updateMavenOneProject( project );
@@ -391,9 +393,8 @@
         catch ( Throwable e )
         {
             return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
-                                    "Project id: " + project.getId(), e );
+                                    "Project id: '" + id + "'.", e );
         }
-
     }
 
     // ----------------------------------------------------------------------
@@ -425,10 +426,12 @@
 
     public Hashtable updateAntProject( Hashtable antProject )
     {
-        AntProject project = new AntProject();
+        String id = getId( antProject );
 
         try
         {
+            AntProject project = continuum.getAntProject( id );
+
             xmlRpcHelper.hashtableToObject( antProject, project );
 
             continuum.updateAntProject( project );
@@ -438,7 +441,7 @@
         catch ( Throwable e )
         {
             return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
-                                    "Project id: " + project.getId(), e );
+                                    "Project id: '" + id + "'", e );
         }
     }
 
@@ -471,12 +474,14 @@
 
     public Hashtable updateShellProject( Hashtable shellProject )
     {
-        ShellProject project = new ShellProject();
+        String id = getId( shellProject );
 
         try
         {
-            xmlRpcHelper.hashtableToObject( shellProject, project );
+            ShellProject project = continuum.getShellProject( id );
 
+            xmlRpcHelper.hashtableToObject( shellProject, project );
+    
             continuum.updateShellProject( project );
 
             return makeHashtable();
@@ -484,8 +489,17 @@
         catch ( Throwable e )
         {
             return handleException( "ContinuumXmlRpc.updateMavenTwoProject()",
-                                    "Project id: " + project.getId(), e );
+                                    "Project id: '" + id + "'", e );
         }
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private String getId( Hashtable hashtable )
+    {
+        return (String) hashtable.get( "id" );
     }
 
     // ----------------------------------------------------------------------

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=191590&r1=191589&r2=191590&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 20 16:43:40 2005
@@ -123,14 +123,13 @@
 //            {
 //            }
 
-            value = convertValueToSetterType( setter.getParameterTypes()[ 0 ], value );
+            value = convertValueToSetterType( setter.getParameterTypes()[ 0 ], value, key );
 
             if ( value == null )
             {
                 continue;
             }
 
-            getLogger().info( "Invoking " + setter.toString() + " with " + value.getClass().getName() );
             setter.invoke( target, new Object[]{value} );
         }
     }
@@ -220,35 +219,11 @@
             {
                 continue;
             }
-            else if ( value instanceof String )
-            {
-                // nothing to do after all, the object is already a string!
-            }
-            else if ( value instanceof Number )
-            {
-                value = value.toString();
-            }
-            else if ( value instanceof Boolean )
-            {
-                value = value.toString();
-            }
-            else if ( value instanceof Collection )
-            {
-                value = collectionToVector( (Collection) value,
-                                            true,
-                                            excludedProperties,
-                                            visitedObjects );
-            }
-            else if ( value instanceof Properties )
-            {
-                value = propertiesToHashtable( (Properties) value );
-            }
-            else
-            {
-                value = objectToHashtable( value,
-                                           excludedProperties,
-                                           visitedObjects );
-            }
+
+            value = convertValue( value,
+                                  true,
+                                  excludedProperties,
+                                  visitedObjects );
 
             // ----------------------------------------------------------------------
             //
@@ -263,6 +238,50 @@
         return hashtable;
     }
 
+    private Object convertValue( Object value,
+                                 boolean convertElements,
+                                 Set excludedProperties,
+                                 Set visitedObjects )
+        throws IllegalAccessException, InvocationTargetException
+    {
+        if ( value instanceof String )
+        {
+            return value;
+        }
+        else if ( value instanceof Number )
+        {
+            return value.toString();
+        }
+        else if ( value instanceof Boolean )
+        {
+            return value.toString();
+        }
+        else if ( value instanceof Collection )
+        {
+            return collectionToVector( (Collection) value,
+                                       convertElements,
+                                       excludedProperties,
+                                       visitedObjects );
+        }
+        else if ( value instanceof Properties )
+        {
+            return propertiesToHashtable( (Properties) value );
+        }
+        else if ( value instanceof Map )
+        {
+            return mapToHashtable( (Map) value,
+                                   convertElements,
+                                   excludedProperties,
+                                   visitedObjects );
+        }
+        else
+        {
+            return objectToHashtable( value,
+                                      excludedProperties,
+                                      visitedObjects );
+        }
+    }
+
     private Hashtable propertiesToHashtable( Properties value  )
     {
         Hashtable properties = new Hashtable();
@@ -277,6 +296,37 @@
         return properties;
     }
 
+    private Object mapToHashtable( Map value,
+                                   boolean convertElements,
+                                   Set excludedProperties,
+                                   Set visitedObjects )
+        throws IllegalAccessException, InvocationTargetException
+    {
+        Hashtable properties = new Hashtable();
+
+        for ( Iterator it = value.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+
+            Object object = entry.getValue();
+
+            if ( convertElements )
+            {
+                object = convertValue( object,
+                                       convertElements,
+                                       excludedProperties,
+                                       visitedObjects );
+            }
+
+            if ( object != null )
+            {
+                properties.put( entry.getKey(), object );
+            }
+        }
+
+        return properties;
+    }
+
     private Vector collectionToVector( Collection value,
                                        boolean convertElements,
                                        Set excludedProperties,
@@ -296,7 +346,10 @@
 
             if ( convertElements )
             {
-                object = objectToHashtable( object, excludedProperties, visitedObjects );
+                object = convertValue( object,
+                                       convertElements,
+                                       excludedProperties,
+                                       visitedObjects );
             }
 
             if ( object != null )
@@ -366,7 +419,7 @@
         return map;
     }
 
-    private Object convertValueToSetterType( Class type, Object value )
+    private Object convertValueToSetterType( Class type, Object value, String key )
     {
         if ( value.equals( type.getClass() ) )
         {
@@ -404,7 +457,9 @@
             }
         }
 
-        getLogger().error( "Could not convert a " + value.getClass().getName() + " to a " + type.getName() );
+        getLogger().error( "Could not convert a " + value.getClass().getName() + " " +
+                           "to a " + type.getName() + ". " +
+                           "Field name: " + key );
 
         return null;
     }

Added: maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java?rev=191590&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java (added)
+++ maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java Mon Jun 20 16:43:40 2005
@@ -0,0 +1,189 @@
+package org.apache.maven.continuum.xmlrpc;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
+import org.apache.maven.continuum.project.ContinuumNotifier;
+import org.apache.maven.continuum.project.MavenTwoProject;
+import org.apache.maven.continuum.store.ContinuumStore;
+
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id$
+ */
+public class ContinuumXmlRpcTest
+    extends PlexusTestCase
+{
+    public void testBasic()
+        throws Exception
+    {
+        ContinuumXmlRpc xmlRpc = (ContinuumXmlRpc) lookup( ContinuumXmlRpc.ROLE );
+
+        ContinuumStore store = (ContinuumStore) lookup( ContinuumStore.ROLE );
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        MavenTwoProject project = makeStubMavenTwoProject( "My Project", "scm:foo" );
+
+        String projectId = store.addProject( project );
+
+        project = (MavenTwoProject) store.getProject( projectId );
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        Hashtable hashtable = xmlRpc.getProject( projectId );
+
+//        dumpValue( 0, "result", hashtable );
+    }
+
+    public static MavenTwoProject makeStubMavenTwoProject( String name, String scmUrl )
+    {
+        return makeMavenTwoProject( name,
+                                    scmUrl,
+                                    "foo@bar.com",
+                                    "1.0",
+                                    "",
+                                    ContinuumBuildExecutor.MAVEN_TWO_EXECUTOR_ID,
+                                    "/tmp" );
+    }
+
+    public static MavenTwoProject makeMavenTwoProject( String name,
+                                                       String scmUrl,
+                                                       String emailAddress,
+                                                       String version,
+                                                       String commandLineArguments,
+                                                       String executorId,
+                                                       String workingDirectory )
+    {
+        MavenTwoProject project = new MavenTwoProject();
+
+        project.setName( name );
+        project.setScmUrl( scmUrl );
+
+        List notifiers = createNotifiers( emailAddress );
+        project.setNotifiers( notifiers );
+
+        project.setVersion( version );
+        project.setCommandLineArguments( commandLineArguments );
+        project.setExecutorId( executorId );
+        project.setWorkingDirectory( workingDirectory );
+
+        return project;
+    }
+
+    private static List createNotifiers( String emailAddress )
+    {
+        ContinuumNotifier notifier = new ContinuumNotifier();
+
+        notifier.setType( "mail" );
+
+        Properties props = new Properties();
+
+        props.put( "address", emailAddress );
+
+        notifier.setConfiguration( props );
+
+        List notifiers = new ArrayList();
+
+        notifiers.add( notifier );
+
+        return notifiers;
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private void dumpValue( int indent, String key, Object value )
+    {
+        if ( value instanceof Hashtable )
+        {
+            dumpHashtable( indent, key, (Hashtable) value );
+        }
+        else if ( value instanceof Vector )
+        {
+            dumpVector( indent, key, (Vector) value );
+        }
+        else
+        {
+            System.err.println( makeIndent( indent ) + key + "=" + value );
+        }
+    }
+
+    private void dumpHashtable( int indent, String key, Hashtable hashtable )
+    {
+        Map map = new TreeMap( hashtable );
+
+        System.err.println( makeIndent( indent ) + key + " = {" );
+
+        for ( Iterator it = map.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+
+            Object value = entry.getValue();
+
+            dumpValue( indent + 1, (String) entry.getKey(), value );
+        }
+
+        System.err.println( makeIndent( indent ) + "}" );
+    }
+
+    private void dumpVector( int indent, String key, Vector vector )
+    {
+        Iterator it;
+
+        int i;
+
+        System.err.println( makeIndent( indent ) + key + " = [");
+
+        for ( it = vector.iterator(), i = 0; it.hasNext(); i++ )
+        {
+            Object value = it.next();
+
+            dumpValue( indent + 1, "#" + i, value );
+        }
+
+        System.err.println( makeIndent( indent ) + "]" );
+    }
+
+    private String makeIndent( int size )
+    {
+        String s = "";
+
+        for ( int i = 0; i < size; i++ )
+        {
+            s += " ";
+        }
+
+        return s;
+    }
+}

Propchange: maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-xmlrpc/src/test/java/org/apache/maven/continuum/xmlrpc/ContinuumXmlRpcTest.java
------------------------------------------------------------------------------
    svn:keywords = Id