geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r344019 - in /geronimo/gbuild/trunk: ./ src/main/java/org/apache/geronimo/gbuild/agent/ src/test/java/org/apache/geronimo/gbuild/agent/
Date Mon, 14 Nov 2005 02:20:51 GMT
Author: dblevins
Date: Sun Nov 13 18:20:45 2005
New Revision: 344019

URL: http://svn.apache.org/viewcvs?rev=344019&view=rev
Log:
Working prototype

Added:
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ThreadContextContinuumStore.java
      - copied, changed from r332501, geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumStoreContext.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/CVS.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/Chmod.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/MainTest.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/SystemExecutable.java
Removed:
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/AbstractDistributedContinuumAction.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumStoreContext.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DistributedContinuumStore.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/DistrubutedBuildController.java
Modified:
    geronimo/gbuild/trunk/pom.xml
    geronimo/gbuild/trunk/project.xml
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ExecuteDistributedBuilderContinuumAction.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/Main.java
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/MapContinuumStore.java

Modified: geronimo/gbuild/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/pom.xml?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/pom.xml (original)
+++ geronimo/gbuild/trunk/pom.xml Sun Nov 13 18:20:45 2005
@@ -65,6 +65,11 @@
       <version>1.0-alpha-2</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-cvs</artifactId>
+      <version>1.0-beta-1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>geronimo-spec</groupId>
       <artifactId>geronimo-spec-j2ee</artifactId>
       <version>1.4-rc4</version>

Modified: geronimo/gbuild/trunk/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/project.xml?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/project.xml (original)
+++ geronimo/gbuild/trunk/project.xml Sun Nov 13 18:20:45 2005
@@ -46,6 +46,11 @@
         <version>1.0-alpha-6</version>
       </dependency>
       <dependency>
+	<groupId>org.apache.maven.scm</groupId>
+	<artifactId>maven-scm-provider-cvs</artifactId>
+	<version>1.0-beta-1-SNAPSHOT</version>
+      </dependency>
+      <dependency>
          <groupId>geronimo-spec</groupId>
          <artifactId>geronimo-spec-j2ee</artifactId>
          <version>1.4-rc4</version>

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
(original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
Sun Nov 13 18:20:45 2005
@@ -17,23 +17,27 @@
 package org.apache.geronimo.gbuild.agent;
 
 import org.activemq.ActiveMQConnectionFactory;
-import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.buildcontroller.BuildController;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.configuration.ConfigurationLoadingException;
 
 import javax.jms.Connection;
+import javax.jms.DeliveryMode;
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
-import javax.jms.Session;
-import javax.jms.MapMessage;
-import javax.jms.Queue;
 import javax.jms.MessageProducer;
-import javax.jms.DeliveryMode;
-import javax.jms.TextMessage;
+import javax.jms.Queue;
+import javax.jms.Session;
 import javax.jms.Topic;
+import javax.jms.ObjectMessage;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @version $Rev$ $Date$
@@ -66,6 +70,11 @@
     private BuildController controller;
 
     /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    /**
      * @plexus.configuration
      */
     private String contributor;
@@ -78,52 +87,64 @@
     /**
      * @plexus.configuration
      */
-    private String url;
+    private String coordinatorUrl;
 
     /**
      * @plexus.configuration
      */
-    private String buildQueueSubject;
+    private String buildTaskQueue;
 
     /**
      * @plexus.configuration
      */
-    private String buildResultsSubject;
+    private String buildResultsTopic;
+
+    /**
+     * @plexus.configuration
+     */
+    private String workingDirectory;
+
+    /**
+     * @plexus.configuration
+     */
+    private String buildOutputDirectory;
 
     private boolean run;
 
     public void run() {
         try {
+            init();
             run = true;
 
-            // Create a ConnectionFactory
-            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
-
-            // Create a Connection
-            Connection connection = connectionFactory.createConnection();
-
-            connection.start();
-
-            connection.setExceptionListener(this);
+            Connection connection = null;
+            try {
+                connection = createConnection(coordinatorUrl);
+            } catch (Throwable e) {
+                System.out.println("Could not create connection to: "+coordinatorUrl);
+                e.printStackTrace();
+                return;
+            }
 
             // Create a Session
             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
-            MessageConsumer buildConsumer = createQueueConsumer(session, buildQueueSubject);
+            MessageConsumer buildConsumer = createQueueConsumer(session, buildTaskQueue);
 
-            MessageProducer resultsProducer = createTopicProducer(session, buildResultsSubject);
+            MessageProducer resultsProducer = createTopicProducer(session, buildResultsTopic);
 
             while (run) {
                 // Wait for a message
                 Message message = buildConsumer.receive();
 
-                if (message instanceof MapMessage) {
+                if (message instanceof ObjectMessage) {
 
-                    MapMessage mapMessage = (MapMessage) message;
+                    ObjectMessage objectMessage = (ObjectMessage) message;
+
+                    Map mapMessage = (Map) objectMessage.getObject();
 
                     ContinuumStore store = getContinuumStore(mapMessage);
 
-                    ContinuumStoreContext.setStore(store);
+                    ThreadContextContinuumStore.setStore(store);
 
                     int projectId = getProjectId(mapMessage);
 
@@ -131,9 +152,9 @@
 
                     int trigger = getTrigger(mapMessage);
 
-                    controller.build(projectId, buildDefinitionId, trigger);
+                    build(projectId, buildDefinitionId, trigger);
 
-                    MapMessage results = session.createMapMessage();
+                    HashMap results = new HashMap();
 
                     setStore(results, store);
 
@@ -157,7 +178,9 @@
 
                     setAdminAddress(results);
 
-                    resultsProducer.send(results);
+                    ObjectMessage resultMessage = session.createObjectMessage(results);
+
+                    resultsProducer.send(resultMessage);
 
                 } else {
                     System.out.println("Incorect message type: " + message.getClass().getName());
@@ -170,65 +193,88 @@
         } catch (Exception e) {
             System.out.println("Caught: " + e);
             e.printStackTrace();
+            System.out.println("ContinuumBuildAgent.run");
         }
     }
 
-    private void setAdminAddress(MapMessage results) throws JMSException {
-        results.setString(KEY_ADMIN_ADDRESS, adminAddress);
+    public void init() throws ConfigurationLoadingException {
+        configurationService.load();
+        configurationService.setWorkingDirectory(new File(workingDirectory));
+        configurationService.setBuildOutputDirectory(new File(buildOutputDirectory));
+    }
+
+    public void build(int projectId, int buildDefinitionId, int trigger) {
+        controller.build(projectId, buildDefinitionId, trigger);
     }
 
-    private void setContributor(MapMessage results) throws JMSException {
-        results.setString(KEY_CONTRIBUTOR, contributor);
+    private Connection createConnection(String coordinatorUrl) throws JMSException {
+        // Create a ConnectionFactory
+        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(coordinatorUrl);
+
+        // Create a Connection
+        Connection connection = connectionFactory.createConnection();
+
+        connection.start();
+
+        connection.setExceptionListener(this);
+
+        return connection;
     }
 
-    private void setHostInformation(MapMessage results) throws UnknownHostException, JMSException
{
+    private void setAdminAddress(Map results) throws JMSException {
+        results.put(KEY_ADMIN_ADDRESS, adminAddress);
+    }
+
+    private void setContributor(Map results) throws JMSException {
+        results.put(KEY_CONTRIBUTOR, contributor);
+    }
+
+    private void setHostInformation(Map results) throws UnknownHostException, JMSException
{
         InetAddress localHost = InetAddress.getLocalHost();
-        results.setString(KEY_HOST_NAME, localHost.getHostName());
-        results.setString(KEY_HOST_ADDRESS, localHost.getHostAddress());
+        results.put(KEY_HOST_NAME, localHost.getHostName());
+        results.put(KEY_HOST_ADDRESS, localHost.getHostAddress());
     }
 
-    private void setSystemProperty(MapMessage results, String name) throws JMSException {
-        results.setString(name, System.getProperty(name));
+    private void setSystemProperty(Map results, String name) throws JMSException {
+        results.put(name, System.getProperty(name));
     }
 
-    private void setStore(MapMessage results, ContinuumStore store) throws JMSException {
-        results.setObject(KEY_STORE, store);
+    private void setStore(Map results, ContinuumStore store) throws JMSException {
+        results.put(KEY_STORE, store);
     }
 
-    private void setBuildDefinitionId(MapMessage results, int buildDefinitionId) throws JMSException
{
-        results.setInt(KEY_BUILD_DEFINITION_ID, buildDefinitionId);
+    private void setBuildDefinitionId(Map results, int buildDefinitionId) throws JMSException
{
+        results.put(KEY_BUILD_DEFINITION_ID, new Integer(buildDefinitionId));
     }
 
-    private void setTrigger(MapMessage results, int trigger) throws JMSException {
-        results.setInt(KEY_TRIGGER, trigger);
+    private void setTrigger(Map results, int trigger) throws JMSException {
+        results.put(KEY_TRIGGER, new Integer(trigger));
     }
 
-    private void setProjectId(MapMessage results, int projectId) throws JMSException {
-        results.setInt(KEY_PROJECT_ID, projectId);
+    private void setProjectId(Map results, int projectId) throws JMSException {
+        results.put(KEY_PROJECT_ID, new Integer(projectId));
     }
 
-    private int getTrigger(MapMessage mapMessage) throws JMSException {
-        return mapMessage.getIntProperty(KEY_TRIGGER);
+    private int getTrigger(Map mapMessage) throws JMSException {
+        return ((Integer)mapMessage.get(KEY_TRIGGER)).intValue();
     }
 
-    private int getBuildDefinitionId(MapMessage mapMessage) throws JMSException {
-        return mapMessage.getIntProperty(KEY_BUILD_DEFINITION_ID);
+    private int getBuildDefinitionId(Map mapMessage) throws JMSException {
+        return ((Integer)mapMessage.get(KEY_BUILD_DEFINITION_ID)).intValue();
     }
 
-    private int getProjectId(MapMessage mapMessage) throws JMSException {
-        return mapMessage.getIntProperty(KEY_PROJECT_ID);
+    private int getProjectId(Map mapMessage) throws JMSException {
+        return ((Integer)mapMessage.get(KEY_PROJECT_ID)).intValue();
     }
 
-    private ContinuumStore getContinuumStore(MapMessage mapMessage) throws JMSException {
-        return (ContinuumStore) mapMessage.getObject(KEY_STORE);
+    private ContinuumStore getContinuumStore(Map mapMessage) throws JMSException {
+        return (ContinuumStore) mapMessage.get(KEY_STORE);
     }
 
     private MessageConsumer createQueueConsumer(Session session, String subject) throws JMSException
{
         Queue queue = session.createQueue(subject);
 
-        MessageConsumer consumer = session.createConsumer(queue);
-
-        return consumer;
+        return session.createConsumer(queue);
     }
 
     private MessageProducer createTopicProducer(Session session, String subject) throws JMSException
{

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ExecuteDistributedBuilderContinuumAction.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ExecuteDistributedBuilderContinuumAction.java?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ExecuteDistributedBuilderContinuumAction.java
(original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ExecuteDistributedBuilderContinuumAction.java
Sun Nov 13 18:20:45 2005
@@ -27,6 +27,8 @@
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.utils.ContinuumUtils;
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.core.action.AbstractContinuumAction;
 
 import java.io.File;
 import java.util.Date;
@@ -35,13 +37,12 @@
 /**
  * @version $Rev$ $Date$
  */
-public class ExecuteDistributedBuilderContinuumAction extends AbstractDistributedContinuumAction
{
+public class ExecuteDistributedBuilderContinuumAction extends AbstractContinuumAction {
 
-    // ----------------------------------------------------------------------
-    // Keys for the values that can be in the context
-    // ----------------------------------------------------------------------
-
-    public static final String KEY_BUILD_OUTPUT_FILE = "build-output-file";
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
 
     /**
      * @plexus.requirement
@@ -65,13 +66,13 @@
         // Get parameters from the context
         // ----------------------------------------------------------------------
 
-        Project project = getProject(context);
+        Project project = store.getProjectWithBuildDetails( getProjectId( context ) );
 
-        int trigger = getTrigger(context);
+        int trigger = getTrigger( context );
 
-        ScmResult scmResult = getUpdateScmResult(context);
+        ScmResult scmResult = getUpdateScmResult( context );
 
-        ContinuumBuildExecutor buildExecutor = buildExecutorManager.getBuildExecutor(project.getExecutorId());
+        ContinuumBuildExecutor buildExecutor = buildExecutorManager.getBuildExecutor( project.getExecutorId()
);
 
         // ----------------------------------------------------------------------
         // Make the build
@@ -85,7 +86,7 @@
 
         build.setTrigger(trigger);
 
-        BuildDefinition buildDefinition = getBuildDefinition(context);
+        BuildDefinition buildDefinition = store.getBuildDefinition( getBuildDefinitionId(
context ) );
 
         build.setScmResult(scmResult);
 
@@ -98,7 +99,7 @@
         try {
             notifier.runningGoals(project, build);
 
-            File buildOutputFile = getBuildOutputFile( context );
+            File buildOutputFile = configurationService.getBuildOutputFile( build.getId(),
project.getId() );
 
             ContinuumBuildExecutionResult result = buildExecutor.build(project, buildDefinition,
buildOutputFile);
 
@@ -118,6 +119,8 @@
 
             if (build.getState() == ContinuumProjectState.OK) {
                 project.setBuildNumber(project.getBuildNumber() + 1);
+
+                project.setState(ContinuumProjectState.OK);
             }
 
             project.setLatestBuildId(build.getId());
@@ -140,13 +143,6 @@
 
             notifier.goalsCompleted(project, build);
         }
-    }
-
-    private File getBuildOutputFile(Map context) {
-
-        String fileName = getString( context, KEY_BUILD_OUTPUT_FILE );
-
-        return new File( fileName );
     }
 
 }

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/Main.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/Main.java?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/Main.java (original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/Main.java Sun Nov
13 18:20:45 2005
@@ -29,6 +29,7 @@
         BuildAgent buildAgent = (BuildAgent) embedder.lookup(BuildAgent.ROLE);
 
         Thread agentThread = new Thread(buildAgent);
+        agentThread.setDaemon(false);
         agentThread.start();
     }
 

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/MapContinuumStore.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/MapContinuumStore.java?rev=344019&r1=344018&r2=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/MapContinuumStore.java
(original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/MapContinuumStore.java
Sun Nov 13 18:20:45 2005
@@ -16,14 +16,16 @@
  */
 package org.apache.geronimo.gbuild.agent;
 
+import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.system.SystemConfiguration;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
-import java.io.Serializable;
 
 /**
  * @version $Rev$ $Date$
@@ -53,11 +55,34 @@
     }
 
     public void addBuildResult(Project project, BuildResult build) throws ContinuumStoreException,
ContinuumObjectNotFoundException {
+        updateObject(build, build.getId());
+
         project.setLatestBuildId(build.getId());
 
         project.setState(build.getState());
 
         project.addBuildResult(build);
+    }
+
+    public BuildDefinition getBuildDefinition(int buildDefinitionId)
+            throws ContinuumStoreException, ContinuumObjectNotFoundException {
+        return (BuildDefinition) getObjectById(BuildDefinition.class, buildDefinitionId);
+    }
+
+    public BuildDefinition storeBuildDefinition(BuildDefinition buildDefinition)
+            throws ContinuumStoreException {
+        updateObject(buildDefinition, buildDefinition.getId());
+
+        return buildDefinition;
+    }
+
+    public SystemConfiguration getSystemConfiguration() throws ContinuumStoreException {
+        return (SystemConfiguration) getMap(SystemConfiguration.class).get(new Integer(0));
+    }
+
+    public SystemConfiguration addSystemConfiguration(SystemConfiguration systemConf) {
+        updateObject(systemConf, 0);
+        return systemConf;
     }
 
     private void updateObject(Object object, int id) {

Copied: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ThreadContextContinuumStore.java
(from r332501, geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumStoreContext.java)
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ThreadContextContinuumStore.java?p2=geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ThreadContextContinuumStore.java&p1=geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumStoreContext.java&r1=332501&r2=344019&rev=344019&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumStoreContext.java
(original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ThreadContextContinuumStore.java
Sun Nov 13 18:20:45 2005
@@ -38,7 +38,7 @@
 /**
  * @version $Rev$ $Date$
  */
-public class ContinuumStoreContext implements ContinuumStore {
+public class ThreadContextContinuumStore implements ContinuumStore {
 
     private static ThreadLocal stores = new ThreadLocal();
 

Added: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/CVS.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/CVS.java?rev=344019&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/CVS.java (added)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/CVS.java Sun Nov
13 18:20:45 2005
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2004 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.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.util.cli.CommandLineException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CVS extends SystemExecutable {
+    private final String cmd = "cvs";
+    private final File cvsroot;
+
+    public CVS(String cvsroot) {
+        this(new File(cvsroot));
+    }
+
+    public CVS(File cvsroot) {
+        this.cvsroot = cvsroot.getAbsoluteFile();
+    }
+
+    public File getCvsroot() {
+        return cvsroot;
+    }
+
+    public void _import(File root, String artifactId) throws CommandLineException {
+        system(root, cmd, "-d " + cvsroot.getAbsolutePath() + " import -m yo_yo " + artifactId
+ " continuum_test start");
+    }
+
+    public void init() throws IOException, CommandLineException {
+        MainTest.deleteAndCreateDirectory(cvsroot);
+
+        system(cvsroot, cmd, " -d " + cvsroot.getAbsolutePath() + " init");
+    }
+}

Added: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/Chmod.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/Chmod.java?rev=344019&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/Chmod.java (added)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/Chmod.java Sun Nov
13 18:20:45 2005
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2004 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.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.util.cli.CommandLineException;
+
+import java.io.File;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Chmod extends SystemExecutable {
+    public static void exec(File root, String opts, File script) throws CommandLineException
{
+        system( root, "chmod", opts +" " + script.getAbsolutePath() );
+
+    }
+}

Added: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java?rev=344019&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
(added)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
Sun Nov 13 18:20:45 2005
@@ -0,0 +1,124 @@
+package org.apache.geronimo.gbuild.agent;
+/**
+ * @version $Rev$ $Date$
+ */
+
+import junit.framework.*;
+import org.apache.geronimo.gbuild.agent.ContinuumBuildAgent;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.execution.shell.ShellBuildExecutor;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.embed.Embedder;
+
+import java.io.File;
+import java.io.IOException;
+
+public class ContinuumBuildAgentTest extends TestCase {
+    ContinuumBuildAgent continuumBuildAgent;
+
+    private CVS cvs;
+    private File shellScript;
+
+    protected void setUp() throws Exception {
+
+        File root = new File("/Users/dblevins/work/gbuild/trunk/target/it").getCanonicalFile();
+        File cvsroot = new File(root, "cvs-root");
+        File module = new File(root, "shell");
+
+        deleteAndCreateDirectory( module );
+
+        shellScript = createScript(module);
+
+        cvs = new CVS(cvsroot);
+        cvs.init();
+        cvs._import(module, "shell");
+
+    }
+
+    public void testBuild() throws Exception {
+
+        Project project = new Project();
+        project.setId(10);
+        project.setScmUrl("scm|cvs|local|" + cvs.getCvsroot().getAbsolutePath() + "|shell");
+        project.setName("Shell Project");
+        project.setVersion("3.0");
+        project.setExecutorId(ShellBuildExecutor.ID);
+        project.setState(ContinuumProjectState.OK);
+
+        BuildDefinition bd = new BuildDefinition();
+        bd.setId(20);
+        bd.setBuildFile(shellScript.getAbsolutePath());
+        bd.setArguments("");
+
+        project.addBuildDefinition(bd);
+
+        MapContinuumStore store = new MapContinuumStore();
+
+        store.updateProject(project);
+        store.storeBuildDefinition(bd);
+
+        ThreadContextContinuumStore.setStore(store);
+
+        Embedder embedder = new Embedder();
+        embedder.start();
+        ContinuumBuildAgent buildAgent = (ContinuumBuildAgent) embedder.lookup(BuildAgent.ROLE);
+
+        buildAgent.init();
+        buildAgent.build(project.getId(), bd.getId(), 1);
+
+        int latestBuildId = project.getLatestBuildId();
+        BuildResult buildResult = store.getBuildResult(latestBuildId);
+
+        assertNotNull("buildResult",buildResult);
+        assertEquals("buildResult.getState",ContinuumProjectState.OK, buildResult.getState());
+        assertEquals("project.getState",ContinuumProjectState.OK, project.getState());
+    }
+
+    public static void deleteAndCreateDirectory(File directory)
+            throws IOException {
+        if (directory.isDirectory()) {
+            FileUtils.deleteDirectory(directory);
+        }
+
+        assertTrue("Could not make directory " + directory, directory.mkdirs());
+    }
+
+    private File createScript(File module) throws IOException, CommandLineException {
+        File script;
+
+        String EOL = System.getProperty( "line.separator" );
+
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+        boolean isCygwin = "true".equals(System.getProperty("cygwin"));
+
+        if ( isWindows && !isCygwin ) {
+
+            script = new File( module, "script.bat" );
+
+            String content = "@ECHO OFF" + EOL
+                    + "IF \"%*\" == \"\" GOTO end" + EOL
+                    + "FOR %%a IN (%*) DO ECHO %%a" + EOL
+                    + ":end" + EOL;
+
+            FileUtils.fileWrite( script.getAbsolutePath(), content );
+
+        } else {
+
+            script = new File( module, "script.sh" );
+
+            String content = "#!/bin/bash" + EOL + "for arg in \"$@\"; do echo $arg ; done"+EOL;
+
+            FileUtils.fileWrite( script.getAbsolutePath(), content );
+
+            Chmod.exec(module, "+x", script);
+        }
+
+        return script;
+    }
+
+}
\ No newline at end of file

Added: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/MainTest.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/MainTest.java?rev=344019&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/MainTest.java (added)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/MainTest.java Sun
Nov 13 18:20:45 2005
@@ -0,0 +1,204 @@
+package org.apache.geronimo.gbuild.agent;
+/**
+ * @version $Rev$ $Date$
+ */
+
+import junit.framework.TestCase;
+import org.activemq.ActiveMQConnectionFactory;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.execution.shell.ShellBuildExecutor;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.Message;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+
+public class MainTest extends TestCase {
+
+    static {
+        org.apache.log4j.BasicConfigurator.configure();
+    }
+
+    private CVS cvs;
+    private File shellScript;
+
+    public void testMain() throws Exception {
+        String[] args = new String[]{};
+
+//        thread(new ContinuumBroker(args), false);
+//
+//        Thread.sleep(5000);
+
+//        thread(new ContinuumBuildProducers(), false);
+//        Thread.sleep(5000);
+
+//        Main.main(args);
+
+        //Thread.sleep(60000);
+
+    }
+
+    protected void setUp() throws Exception {
+
+        File root = new File("/Users/dblevins/work/gbuild/trunk/target/it").getCanonicalFile();
+        File cvsroot = new File(root, "cvs-root");
+        File module = new File(root, "shell");
+
+        deleteAndCreateDirectory( module );
+
+        shellScript = createScript(module);
+
+        cvs = new CVS(cvsroot);
+        cvs.init();
+        cvs._import(module,"shell");
+
+    }
+
+    private File createScript(File module) throws IOException, CommandLineException {
+        File script;
+
+        String EOL = System.getProperty( "line.separator" );
+
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+        boolean isCygwin = "true".equals(System.getProperty("cygwin"));
+
+        if ( isWindows && !isCygwin ) {
+
+            script = new File( module, "script.bat" );
+
+            String content = "@ECHO OFF" + EOL
+                    + "IF \"%*\" == \"\" GOTO end" + EOL
+                    + "FOR %%a IN (%*) DO ECHO %%a" + EOL
+                    + ":end" + EOL;
+
+            FileUtils.fileWrite( script.getAbsolutePath(), content );
+
+        } else {
+
+            script = new File( module, "script.sh" );
+
+            String content = "#!/bin/bash" + EOL + "for arg in \"$@\"; do echo $arg ; done"+EOL;
+
+            FileUtils.fileWrite( script.getAbsolutePath(), content );
+
+            Chmod.exec(module, "+x", script);
+        }
+
+        return script;
+    }
+
+    public static void thread(Runnable runnable, boolean daemon) {
+        Thread brokerThread = new Thread(runnable);
+        brokerThread.setDaemon(daemon);
+        brokerThread.start();
+    }
+
+    public static class ContinuumBroker implements Runnable {
+        private final String[] args;
+
+        public ContinuumBroker(String[] args) {
+            this.args = args;
+        }
+
+        public void run() {
+            org.activemq.broker.impl.Main.main(args);
+        }
+
+        public static void main(String[] args) {
+            org.apache.log4j.BasicConfigurator.configure();
+            new ContinuumBroker(args).run();
+        }
+    }
+
+    public static class Producer {
+        public static void main(String[] args) throws Exception {
+            MainTest test = new MainTest();
+            test.setUp();
+            test.new ContinuumBuildProducers().run();
+        }
+    }
+
+    public class ContinuumBuildProducers implements Runnable {
+
+        public void run() {
+            try {
+                // Create a ConnectionFactory
+                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
+
+                // Create a Connection
+                Connection connection = connectionFactory.createConnection();
+                connection.start();
+
+                // Create a Session
+                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                // Create the destination (Topic or Queue)
+                Destination destination = session.createQueue("BUILD.QUEUE");
+
+                // Create a MessageProducer from the Session to the Topic or Queue
+                MessageProducer producer = session.createProducer(destination);
+                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+
+
+                Project project = new Project();
+                project.setId(10);
+                project.setScmUrl("scm|cvs|local|" + cvs.getCvsroot().getAbsolutePath() +
"|shell");
+                project.setName("Shell Project");
+                project.setVersion("3.0");
+                project.setExecutorId(ShellBuildExecutor.ID);
+
+                BuildDefinition bd = new BuildDefinition();
+                bd.setId(20);
+                bd.setBuildFile(shellScript.getAbsolutePath());
+                bd.setArguments("");
+
+                project.addBuildDefinition(bd);
+
+                MapContinuumStore store = new MapContinuumStore();
+
+                store.updateProject(project);
+
+                HashMap map = new HashMap();
+                map.put(ContinuumBuildAgent.KEY_STORE, store);
+                map.put(ContinuumBuildAgent.KEY_PROJECT_ID, new Integer(project.getId()));
+                map.put(ContinuumBuildAgent.KEY_BUILD_DEFINITION_ID, new Integer(bd.getId()));
+                map.put(ContinuumBuildAgent.KEY_TRIGGER, new Integer(0));
+
+                // Create a messages
+                Message message = session.createObjectMessage(map);
+
+                producer.send(message);
+
+                // Clean up
+                session.close();
+                connection.close();
+            }
+            catch (Exception e) {
+                System.out.println("Caught: " + e);
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+
+
+    public static void deleteAndCreateDirectory(File directory)
+            throws IOException {
+        if (directory.isDirectory()) {
+            FileUtils.deleteDirectory(directory);
+        }
+
+        assertTrue("Could not make directory " + directory, directory.mkdirs());
+    }
+}
\ No newline at end of file

Added: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/SystemExecutable.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/SystemExecutable.java?rev=344019&view=auto
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/SystemExecutable.java
(added)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/SystemExecutable.java
Sun Nov 13 18:20:45 2005
@@ -0,0 +1,78 @@
+/**
+ *
+ * Copyright 2004 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.
+ */
+package org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemExecutable {
+
+    public static void system(File workingDirectory, String cmd, String arguments)
+            throws CommandLineException {
+        system(workingDirectory, cmd, new String[]{arguments});
+    }
+
+    public static void system(File workingDirectory, String cmd, String[] arguments)
+            throws CommandLineException {
+        Commandline commandline = new Commandline();
+
+        commandline.setExecutable(cmd);
+
+        commandline.setWorkingDirectory(workingDirectory.getAbsolutePath());
+
+        for (int i = 0; i < arguments.length; i++) {
+            String argument = arguments[i];
+
+            commandline.createArgument().setLine(argument);
+        }
+
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+
+        int exitCode = CommandLineUtils.executeCommandLine(commandline, stdout, stderr);
+
+        if (exitCode != 0) {
+            System.err.println("Error while executing command: " + commandline.toString());
+            System.err.println("workingDirectory: " + workingDirectory.getAbsolutePath());
+            System.err.println("Exit code: " + exitCode);
+
+            System.err.println("Standard output:");
+            line();
+            System.err.println(stdout.getOutput());
+            line();
+            System.err.println("Standard Error:");
+            line();
+            System.err.println(stderr.getOutput());
+            line();
+
+            Assert.fail("The command failed.");
+        }
+    }
+
+    private static void line() {
+        System.err.println("-------------------------------------------------------------------------------");
+    }
+}



Mime
View raw message