You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ct...@apache.org on 2008/12/11 12:36:43 UTC

svn commit: r725665 [2/2] - in /continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent: ./ src/main/java/org/apache/continuum/buildagent/ src/main/java/org/apache/continuum/buildagent/action/ src/main/java/org/...

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,101 @@
+package org.apache.continuum.buildagent.continuum;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.continuum.scm.queue.PrepareBuildProjectsTask;
+import org.apache.continuum.buildagent.taskqueue.manager.TaskQueueManager;
+import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
+import org.codehaus.plexus.action.ActionManager;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.taskqueue.TaskQueueException;
+
+/**
+ * @plexus.component role="org.apache.continuum.buildagent.continuum.Continuum" role-hint="default" 
+ */
+public class DefaultContinuum
+    extends AbstractLogEnabled
+    implements Continuum//, Contextualizable, Initializable, Startable
+{
+    
+    /**
+     * @plexus.requirement role-hint="task-queue-manager-dist"
+     */
+    private TaskQueueManager taskQueueManager;
+
+    public void buildProject( int projectId, int buildDefinitionId, int trigger )
+        throws ContinuumException
+    {
+        try
+        {
+            if ( taskQueueManager.isInBuildingQueue( projectId, buildDefinitionId )
+                || taskQueueManager.isInCheckoutQueue( projectId )
+                || taskQueueManager.isInPrepareBuildQueue( projectId ) )
+            {
+                return;
+            }
+        }
+        catch ( TaskQueueManagerException e )
+        {
+            throw new ContinuumException( e.getMessage(), e );
+        }
+
+        Map<Integer, Integer> projectsBuildDefinitionsMap =
+            new HashMap<Integer, Integer>( projectId, buildDefinitionId );
+
+        prepareBuildProjects( projectsBuildDefinitionsMap, trigger );
+    }
+    
+
+    private void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, int trigger )
+        throws ContinuumException
+    {
+
+        try
+        {
+            PrepareBuildProjectsTask task = new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, trigger );
+            taskQueueManager.getPrepareBuildQueue().put( task );
+            // taskQueueManager.getPrepareBuildQueue().
+        }
+        catch ( TaskQueueException e )
+        {
+            throw logAndCreateException( "Error while creating enqueuing object.", e );
+        }
+        
+    }
+
+
+    public void buildProjectWithBuildDefinition( int projectId, int buildDefinitionId )
+        throws ContinuumException
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+
+    // ----------------------------------------------------------------------
+    // Logging
+    // ----------------------------------------------------------------------
+
+    private ContinuumException logAndCreateException( String message, Throwable cause )
+    {
+        if ( cause instanceof ContinuumObjectNotFoundException )
+        {
+            return new ContinuumException( "No such object.", cause );
+        }
+
+        getLogger().error( message, cause );
+
+        return new ContinuumException( message, cause );
+    }
+
+
+    public TaskQueueManager getTaskQueueManager()
+    {
+        return taskQueueManager;
+    }
+   
+
+}

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/continuum/DefaultContinuum.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,32 @@
+package org.apache.continuum.buildagent.controller;
+
+import org.apache.maven.continuum.buildcontroller.BuildController;
+import org.apache.maven.continuum.buildqueue.BuildProjectTask;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
+import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
+
+
+public class BuildProjectTaskExecutor
+    extends AbstractLogEnabled
+    implements TaskExecutor
+{
+    /**
+     * @plexus.requirement role-hint="distributed"
+     */
+    private BuildController controller;
+
+    // ----------------------------------------------------------------------
+    // TaskExecutor Implementation
+    // ----------------------------------------------------------------------
+
+    public void executeTask( Task task )
+        throws TaskExecutionException
+    {
+        BuildProjectTask buildProjectTask = (BuildProjectTask) task;
+
+        controller.build( buildProjectTask.getProjectId(), buildProjectTask.getBuildDefinitionId(), buildProjectTask
+            .getTrigger() );
+    }
+}

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/BuildProjectTaskExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,383 @@
+package org.apache.continuum.buildagent.controller;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager;
+import org.apache.continuum.buildagent.util.BuildContextToProject;
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.maven.continuum.buildcontroller.BuildContext;
+import org.apache.maven.continuum.buildcontroller.BuildController;
+import org.apache.maven.continuum.core.action.AbstractContinuumAction;
+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.scm.ChangeFile;
+import org.apache.maven.continuum.model.scm.ChangeSet;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.apache.maven.continuum.utils.ContinuumUtils;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.codehaus.plexus.action.ActionManager;
+import org.codehaus.plexus.action.ActionNotFoundException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
+
+/**
+ * @plexus.component role="org.apache.maven.continuum.buildcontroller.BuildController" role-hint="distributed"
+ */
+public class DistributedBuildController
+    extends AbstractLogEnabled
+    implements BuildController
+{
+    /**
+     * @plexus.requirement
+     */
+    private BuildDefinitionDao buildDefinitionDao;
+
+    /**
+     * @plexus.requirement
+     */
+    private ActionManager actionManager;
+
+    /**
+     * @plexus.requirement
+     */
+    private BuildContextManager buildContextManager;    
+    // ----------------------------------------------------------------------
+    // BuildController Implementation
+    // ----------------------------------------------------------------------
+
+    /**
+     * @param projectId
+     * @param buildDefinitionId
+     * @param trigger
+     * @throws TaskExecutionException
+     */
+    public void build( int projectId, int buildDefinitionId, int trigger )
+        throws TaskExecutionException
+    {
+        getLogger().info( "Initializing build" );
+        BuildContext context = initializeBuildContext( projectId, buildDefinitionId, trigger );
+
+        // ignore this if AlwaysBuild ?
+        /*if ( !checkScmResult( context ) )
+        {
+            getLogger().info( "Error updating from SCM, not building" );
+            return;
+        }*/
+        
+        getLogger().info( "Starting build of " + context.getProject().getName() );
+        startBuild( context );
+
+        try
+        {
+
+            Map actionContext = context.getActionContext();
+
+            try
+            {
+                performAction( "update-project-from-working-directory-dist", context );
+            }
+            catch ( TaskExecutionException e )
+            {
+                updateBuildResult( context, ContinuumUtils.throwableToString( e ) );
+
+                //just log the error but don't stop the build from progressing in order not to suppress any build result messages there
+                getLogger().error( "Error executing action update-project-from-working-directory '", e );
+            }
+
+            performAction( "execute-builder-dist", context );
+            // TODO:
+            // add the result to a manager that handles the build result
+            //
+            
+
+            //should we deploy the artifact or only after the build result?
+            //performAction( "deploy-artifact-dist", context );
+
+            context.setCancelled( (Boolean) actionContext.get( AbstractContinuumAction.KEY_CANCELLED ) );
+
+            String s = (String) actionContext.get( AbstractContinuumAction.KEY_BUILD_ID );
+
+
+        }
+        finally
+        {
+            endBuild( context );
+        }
+    }
+
+    /**
+     * Checks if the build should be marked as ERROR and notifies the end of the build.
+     *
+     * @param context
+     * @throws TaskExecutionException
+     */
+    private void endBuild( BuildContext context )
+        throws TaskExecutionException
+    {
+        
+    }
+
+    private void updateBuildResult( BuildContext context, String error )
+        throws TaskExecutionException
+    {
+
+    }
+
+    private void updateBuildResult( BuildResult build, BuildContext context )
+    {
+
+    }
+
+    private void startBuild( BuildContext context )
+        throws TaskExecutionException
+    {
+
+        Project project = context.getProject();
+
+        project.setOldState( project.getState() );
+
+        project.setState( ContinuumProjectState.BUILDING );
+
+    }
+
+    /**
+     * Initializes a BuildContext for the build.
+     *
+     * @param projectId
+     * @param buildDefinitionId
+     * @param trigger
+     * @return
+     * @throws TaskExecutionException
+     */
+    protected BuildContext initializeBuildContext( int projectId, int buildDefinitionId, int trigger )
+        throws TaskExecutionException
+    {
+        BuildContext context = new BuildContext();
+
+        context.setStartTime( System.currentTimeMillis() );
+
+        context.setTrigger( trigger );
+
+        try
+        {
+            Project project = BuildContextToProject.getProject( buildContextManager.getBuildContext( projectId ) );
+
+            context.setProject( project );
+
+            BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( buildDefinitionId );
+
+            context.setBuildDefinition( buildDefinition );
+
+            //assume null.
+            BuildResult oldBuildResult = null;
+                
+            context.setOldBuildResult( oldBuildResult );
+
+            context.setScmResult( null );
+            
+            // CONTINUUM-1871 olamy if continuum is killed during building oldBuildResult will have a endTime 0
+            // this means all changes since the project has been loaded in continuum will be in memory
+            // now we will load all BuildResult with an Id bigger or equals than the oldBuildResult one
+            //if ( oldBuildResult != null )
+            //{
+            //    context.setOldScmResult(
+            //        getOldScmResults( projectId, oldBuildResult.getBuildNumber(), oldBuildResult.getEndTime() ) );
+            //}
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new TaskExecutionException( "Error initializing the build context", e );
+        }
+
+        Map actionContext = context.getActionContext();
+
+        actionContext.put( AbstractContinuumAction.KEY_PROJECT_ID, projectId );
+
+        actionContext.put( AbstractContinuumAction.KEY_PROJECT, context.getProject() );
+
+        actionContext.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_ID, buildDefinitionId );
+
+        actionContext.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, context.getBuildDefinition() );
+
+        actionContext.put( AbstractContinuumAction.KEY_TRIGGER, trigger );
+
+        actionContext.put( AbstractContinuumAction.KEY_FIRST_RUN, context.getOldBuildResult() == null );
+
+        if ( context.getOldBuildResult() != null )
+        {
+            actionContext.put( AbstractContinuumAction.KEY_OLD_BUILD_ID, context.getOldBuildResult().getId() );
+        }
+
+        return context;
+    }
+
+
+    private void performAction( String actionName, BuildContext context )
+        throws TaskExecutionException
+    {
+        String error = null;
+        TaskExecutionException exception = null;
+
+        try
+        {
+            getLogger().info( "Performing action " + actionName );
+            actionManager.lookup( actionName ).execute( context.getActionContext() );
+            return;
+        }
+        catch ( ActionNotFoundException e )
+        {
+            error = ContinuumUtils.throwableToString( e );
+            exception = new TaskExecutionException( "Error looking up action '" + actionName + "'", e );
+        }
+        catch ( ScmRepositoryException e )
+        {
+            error = getValidationMessages( e ) + "\n" + ContinuumUtils.throwableToString( e );
+
+            exception = new TaskExecutionException( "SCM error while executing '" + actionName + "'", e );
+        }
+        catch ( ScmException e )
+        {
+            error = ContinuumUtils.throwableToString( e );
+
+            exception = new TaskExecutionException( "SCM error while executing '" + actionName + "'", e );
+        }
+        catch ( Exception e )
+        {
+            exception = new TaskExecutionException( "Error executing action '" + actionName + "'", e );
+            error = ContinuumUtils.throwableToString( exception );
+        }
+
+        // TODO: clean this up. We catch the original exception from the action, and then update the buildresult
+        // for it - we need to because of the specialized error message for SCM.
+        // If updating the buildresult fails, log the previous error and throw the new one.
+        // If updating the buildresult succeeds, throw the original exception. The build result should NOT
+        // be updated again - a TaskExecutionException is final, no further action should be taken upon it.
+
+        try
+        {
+            updateBuildResult( context, error );
+        }
+        catch ( TaskExecutionException e )
+        {
+            getLogger().error( "Error updating build result after receiving the following exception: ", exception );
+            throw e;
+        }
+
+        throw exception;
+    }
+
+
+    private boolean checkAllChangesUnknown( List<ChangeSet> changes )
+    {
+        for ( ChangeSet changeSet : changes )
+        {
+            List<ChangeFile> changeFiles = changeSet.getFiles();
+
+            for ( ChangeFile changeFile : changeFiles )
+            {
+                if ( !"unknown".equalsIgnoreCase( changeFile.getStatus() ) )
+                {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    private String getValidationMessages( ScmRepositoryException ex )
+    {
+        List<String> messages = ex.getValidationMessages();
+
+        StringBuffer message = new StringBuffer();
+
+        if ( messages != null && !messages.isEmpty() )
+        {
+            for ( Iterator<String> i = messages.iterator(); i.hasNext(); )
+            {
+                message.append( i.next() );
+
+                if ( i.hasNext() )
+                {
+                    message.append( System.getProperty( "line.separator" ) );
+                }
+            }
+        }
+        return message.toString();
+    }
+/*
+    protected void checkProjectDependencies( BuildContext context )
+    {
+        if ( context.getOldBuildResult() == null )
+        {
+            return;
+        }
+
+        try
+        {
+            Project project = projectDao.getProjectWithAllDetails( context.getProject().getId() );
+            List<ProjectDependency> dependencies = project.getDependencies();
+
+            if ( dependencies == null )
+            {
+                dependencies = new ArrayList<ProjectDependency>();
+            }
+
+            if ( project.getParent() != null )
+            {
+                dependencies.add( project.getParent() );
+            }
+
+            if ( dependencies.isEmpty() )
+            {
+                return;
+            }
+
+            List<ProjectDependency> modifiedDependencies = new ArrayList<ProjectDependency>();
+
+            for ( ProjectDependency dep : dependencies )
+            {
+                Project dependencyProject =
+                    projectDao.getProject( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() );
+
+                if ( dependencyProject != null )
+                {
+                    List buildResults = buildResultDao.getBuildResultsInSuccessForProject( dependencyProject.getId(),
+                                                                                           context.getOldBuildResult().getEndTime() );
+                    if ( buildResults != null && !buildResults.isEmpty() )
+                    {
+                        getLogger().debug( "Dependency changed: " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" +
+                            dep.getVersion() );
+                        modifiedDependencies.add( dep );
+                    }
+                    else
+                    {
+                        getLogger().debug( "Dependency not changed: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                            ":" + dep.getVersion() );
+                    }
+                }
+                else
+                {
+                    getLogger().debug( "Skip non Continuum project: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                        ":" + dep.getVersion() );
+                }
+            }
+
+            context.setModifiedDependencies( modifiedDependencies );
+            context.getActionContext().put( AbstractContinuumAction.KEY_UPDATE_DEPENDENCIES, modifiedDependencies );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            getLogger().warn( "Can't get the project dependencies", e );
+        }
+    }
+*/
+
+
+}
+

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/controller/DistributedBuildController.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,493 @@
+package org.apache.continuum.buildagent.scm.queue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.continuum.dao.ProjectDao;
+import org.apache.continuum.dao.ProjectScmRootDao;
+import org.apache.continuum.model.project.ProjectScmRoot;
+import org.apache.continuum.scm.queue.PrepareBuildProjectsTask;
+import org.apache.continuum.buildagent.action.AbstractContinuumAction;
+import org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager;
+import org.apache.continuum.buildagent.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.util.BuildContextToProject;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.model.scm.ChangeSet;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.apache.maven.continuum.utils.ContinuumUtils;
+import org.apache.maven.continuum.utils.WorkingDirectoryService;
+import org.codehaus.plexus.action.ActionManager;
+import org.codehaus.plexus.action.ActionNotFoundException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
+import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+
+/**
+ * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
+ * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor"
+ * role-hint="prepare-build-project"
+ */
+public class PrepareBuildProjectsTaskExecutor
+    extends AbstractLogEnabled
+    implements TaskExecutor
+{
+    /**
+     * @plexus.requirement
+     */
+    private ActionManager actionManager;
+    
+    /**
+     * @plexus.requirement
+     */
+    private BuildDefinitionDao buildDefinitionDao;
+    
+    
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+   // private WorkingDirectoryService workingDirectoryService;
+
+    /**
+     * @plexus.requirement
+     */    
+    private BuildContextManager buildContextManager;
+
+    public void executeTask( Task task )
+        throws TaskExecutionException
+    {
+        PrepareBuildProjectsTask prepareTask = (PrepareBuildProjectsTask) task;
+        
+        Map<Integer, Integer> projectsBuildDefinitionsMap = prepareTask.getProjectsBuildDefinitionsMap();
+        int trigger = prepareTask.getTrigger();
+        Set<Integer> projectsId = projectsBuildDefinitionsMap.keySet();
+        Map context = new HashMap();
+
+        try
+        {
+            for ( Integer projectId : projectsId )
+            {
+                int buildDefinitionId = projectsBuildDefinitionsMap.get( projectId );
+                
+                getLogger().info( "Initializing prepare build" );
+                context = initializeContext( projectId, buildDefinitionId );
+                
+                getLogger().info( "Starting prepare build of project: " + AbstractContinuumAction.getProject( context ).getName() );
+                //startPrepareBuild( context );
+                
+                //if ( !checkProjectScmRoot( context ) )
+                //{
+                //    break;
+                //}
+                
+                try
+                {
+                    if ( AbstractContinuumAction.getBuildDefinition( context ).isBuildFresh() )
+                    {
+                        getLogger().info( "Purging existing working copy" );
+                        cleanWorkingDirectory( context );
+                    }
+                    
+                    // ----------------------------------------------------------------------
+                    // TODO: Centralize the error handling from the SCM related actions.
+                    // ContinuumScmResult should return a ContinuumScmResult from all
+                    // methods, even in a case of failure.
+                    // ----------------------------------------------------------------------
+                    getLogger().info( "Updating working dir" );
+                    updateWorkingDirectory( context );
+            
+                    getLogger().info( "Merging SCM results" );
+                    //CONTINUUM-1393
+                    if ( !AbstractContinuumAction.getBuildDefinition( context ).isBuildFresh() )
+                    {
+                        mergeScmResults( context );
+                    }
+                }
+                finally
+                {
+                    getLogger().info( "Ending prepare build of project: " + AbstractContinuumAction.getProject( context).getName() );
+                    endProjectPrepareBuild( context );
+                }
+            }
+        }
+        finally
+        {
+            getLogger().info( "Ending prepare build" );
+            endPrepareBuild( context );
+        }
+
+        buildProjects( projectsBuildDefinitionsMap, trigger );
+    }
+    
+    private Map initializeContext( int projectId, int buildDefinitionId )
+        throws TaskExecutionException
+    {
+        Map context = new HashMap();
+
+        try
+        {
+            Project project = BuildContextToProject.getProject( buildContextManager.getBuildContext( projectId ) );
+            ProjectGroup projectGroup = project.getProjectGroup();
+            
+            String projectScmUrl = project.getScmUrl();
+            
+            /*
+            for ( ProjectScmRoot projectScmRoot : scmRoots )
+            {
+                if ( projectScmUrl.contains( projectScmRoot.getScmRootAddress() ) )
+                {
+                    context.put( AbstractContinuumAction.KEY_PROJECT_SCM_ROOT, projectScmRoot );
+                    break;
+                }
+            }*/
+            context.put( AbstractContinuumAction.KEY_PROJECT_SCM_ROOT, projectScmUrl );
+
+            context.put( AbstractContinuumAction.KEY_PROJECT_GROUP_ID, -1 );
+            context.put( AbstractContinuumAction.KEY_PROJECT_ID, projectId );
+            context.put( AbstractContinuumAction.KEY_PROJECT, project );
+    
+            context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_ID, buildDefinitionId );
+            context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinitionDao.getBuildDefinition( buildDefinitionId ) );
+            
+            context.put( AbstractContinuumAction.KEY_OLD_SCM_RESULT, project.getScmResult() );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new TaskExecutionException( "Error initializing pre-build context", e );
+        }
+        
+        return context;
+    }
+    
+    private void cleanWorkingDirectory( Map context )
+        throws TaskExecutionException
+    {
+        performAction( "clean-working-directory-dist", context );
+    }
+    
+    private void updateWorkingDirectory( Map context )
+        throws TaskExecutionException
+    {
+        performAction( "check-working-directory-dist", context );
+    
+        boolean workingDirectoryExists =
+            AbstractContinuumAction.getBoolean( context, AbstractContinuumAction.KEY_WORKING_DIRECTORY_EXISTS );
+    
+        ScmResult scmResult;
+    
+        if ( workingDirectoryExists )
+        {
+            performAction( "update-working-directory-from-scm-dist", context );
+    
+            scmResult = AbstractContinuumAction.getUpdateScmResult( context, null );
+        }
+        else
+        {
+            Project project = AbstractContinuumAction.getProject( context );
+    
+            context.put( AbstractContinuumAction.KEY_WORKING_DIRECTORY,                               
+                                 configurationService.getWorkingDirectory( project.getId() ));
+    
+            performAction( "checkout-project-dist", context );
+    
+            scmResult = AbstractContinuumAction.getCheckoutResult( context, null );
+        }
+    
+        context.put( AbstractContinuumAction.KEY_SCM_RESULT, scmResult );
+    }
+    
+    private boolean checkProjectScmRoot( Map context )
+        throws TaskExecutionException
+    {
+        ProjectScmRoot projectScmRoot = AbstractContinuumAction.getProjectScmRoot( context );
+        
+        // check state of scm root
+        if ( projectScmRoot.getState() == ContinuumProjectState.ERROR )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+    
+    private void startPrepareBuild( Map context )
+        throws TaskExecutionException
+    {
+ /*       ProjectScmRoot projectScmRoot = AbstractContinuumAction.getProjectScmRoot( context );
+        if ( projectScmRoot.getState() != ContinuumProjectState.UPDATING )
+        {
+            try
+            {
+                projectScmRoot.setOldState( projectScmRoot.getState() );
+                projectScmRoot.setState( ContinuumProjectState.UPDATING );
+                projectScmRootDao.updateProjectScmRoot( projectScmRoot );
+            }
+            catch ( ContinuumStoreException e )
+            {
+                throw new TaskExecutionException( "Error persisting projectScmRoot", e );
+            }
+        }
+*/        
+    }
+    
+    private void endPrepareBuild( Map context )
+        throws TaskExecutionException
+    {
+        /*
+        ProjectScmRoot projectScmRoot = AbstractContinuumAction.getProjectScmRoot( context );
+        
+        if ( projectScmRoot.getState() != ContinuumProjectState.ERROR )
+        {
+            projectScmRoot.setState( ContinuumProjectState.UPDATED );
+            projectScmRoot.setError( null );
+            
+            try
+            {
+                projectScmRootDao.updateProjectScmRoot( projectScmRoot );
+            }
+            catch ( ContinuumStoreException e )
+            {
+                throw new TaskExecutionException( "Error persisting projectScmRoot", e );
+            }
+        }
+
+        notifierDispatcher.prepareBuildComplete( projectScmRoot );
+        */
+    }
+    
+    /**
+     *  @param context
+     * @throws TaskExecutionException
+     */
+    private void endProjectPrepareBuild( Map context )
+        throws TaskExecutionException
+    {
+    /*    ScmResult scmResult = AbstractContinuumAction.getScmResult( context, null );
+        Project project = AbstractContinuumAction.getProject( context );
+        
+        if ( scmResult == null || !scmResult.isSuccess() )
+        {
+            String error = convertScmResultToError( scmResult );
+            
+            updateProjectScmRoot( context, error );
+        }
+        
+        try
+        {
+            project.setScmResult( scmResult );
+            
+            projectDao.updateProject( project );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new TaskExecutionException( "Error storing the project", e );
+        }
+        */
+    }
+    
+    /**
+     * Merges scm results so we'll have all changes since last execution of current build definition
+     *
+     * @param context The build context
+     */
+    private void mergeScmResults( Map context )
+    {
+        ScmResult oldScmResult = AbstractContinuumAction.getOldScmResult( context, null );
+        ScmResult newScmResult = AbstractContinuumAction.getScmResult( context, null );
+
+        if ( oldScmResult != null )
+        {
+            if ( newScmResult == null )
+            {
+                context.put( AbstractContinuumAction.KEY_SCM_RESULT, oldScmResult );
+            }
+            else
+            {
+                List<ChangeSet> oldChanges = oldScmResult.getChanges();
+
+                List<ChangeSet> newChanges = newScmResult.getChanges();
+
+                for ( ChangeSet change : newChanges )
+                {
+                    if ( !oldChanges.contains( change ) )
+                    {
+                        oldChanges.add( change );
+                    }
+                }
+
+                newScmResult.setChanges( oldChanges );
+            }
+        }
+    }
+    
+    private void performAction( String actionName, Map context )
+        throws TaskExecutionException
+    {
+        TaskExecutionException exception = null;
+
+        try
+        {
+            getLogger().info( "Performing action " + actionName );
+            actionManager.lookup( actionName ).execute( context );
+            return;
+        }
+        catch ( ActionNotFoundException e )
+        {
+            exception = new TaskExecutionException( "Error looking up action '" + actionName + "'", e );
+        }
+        catch ( Exception e )
+        {
+            exception = new TaskExecutionException( "Error executing action '" + actionName + "'", e );
+        }
+        
+        ScmResult result = new ScmResult();
+        
+        result.setSuccess( false );
+        
+        result.setException( ContinuumUtils.throwableToString( exception ) );
+        
+        context.put( AbstractContinuumAction.KEY_SCM_RESULT, result );
+        
+        throw exception;
+    }
+    
+    private String convertScmResultToError( ScmResult result )
+    {
+        String error = "";
+
+        if ( result == null )
+        {
+            error = "Scm result is null.";
+        }
+        else
+        {
+            if ( result.getCommandLine() != null )
+            {
+                error = "Command line: " + StringUtils.clean( result.getCommandLine() ) +
+                    System.getProperty( "line.separator" );
+            }
+
+            if ( result.getProviderMessage() != null )
+            {
+                error = "Provider message: " + StringUtils.clean( result.getProviderMessage() ) +
+                    System.getProperty( "line.separator" );
+            }
+
+            if ( result.getCommandOutput() != null )
+            {
+                error += "Command output: " + System.getProperty( "line.separator" );
+                error += "-------------------------------------------------------------------------------" +
+                    System.getProperty( "line.separator" );
+                error += StringUtils.clean( result.getCommandOutput() ) + System.getProperty( "line.separator" );
+                error += "-------------------------------------------------------------------------------" +
+                    System.getProperty( "line.separator" );
+            }
+
+            if ( result.getException() != null )
+            {
+                error += "Exception:" + System.getProperty( "line.separator" );
+                error += result.getException();
+            }
+        }
+
+        return error;
+    }
+    
+    private void updateProjectScmRoot( Map context, String error )
+        throws TaskExecutionException
+    {
+        /*
+        ProjectScmRoot projectScmRoot = AbstractContinuumAction.getProjectScmRoot( context );
+        
+        try
+        {
+            projectScmRoot.setState( ContinuumProjectState.ERROR );
+            projectScmRoot.setError( error );
+            
+            projectScmRootDao.updateProjectScmRoot( projectScmRoot );
+            
+            context.put( AbstractContinuumAction.KEY_PROJECT_SCM_ROOT, projectScmRoot );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new TaskExecutionException( "Error storing project scm root", e );
+        }
+        */
+    }
+
+    // project already sorted and checked out so pass it to build action
+    private void buildProjects(Map<Integer, Integer> projectsAndBuildDefinitionsMap, int trigger )
+        throws TaskExecutionException
+    {
+        List<Project> projectList = new ArrayList();
+        
+        Set<Integer> projectIds =  projectsAndBuildDefinitionsMap.keySet();                
+        
+        for ( Integer id : projectIds )
+        {
+            projectList.add( BuildContextToProject.getProject( buildContextManager.getBuildContext( id.intValue() ) )  ); 
+        }
+
+        for ( Project project : projectList )
+        {
+            boolean shouldBuild = false;
+            int buildDefinitionId = 0;
+            
+            if ( projectsAndBuildDefinitionsMap.get( project.getId() ) != null )
+            {
+                buildDefinitionId = projectsAndBuildDefinitionsMap.get( project.getId() );
+                shouldBuild = true;
+            }
+            /*
+            else if ( project.getState() == ContinuumProjectState.CHECKEDOUT || project.getState() == ContinuumProjectState.NEW ) //check if no build result yet for project
+            {
+                try
+                {
+                    //get default build definition for project
+                    buildDefinitionId = buildDefinitionDao.getDefaultBuildDefinition( project.getId() ).getId();
+                }
+                catch ( ContinuumStoreException e )
+                {
+                    getLogger().error( "Error while creating build object", e );
+                    throw new TaskExecutionException( "Error while creating build object", e );
+                }
+                shouldBuild = true;
+            }*/
+
+            if ( shouldBuild )
+            {
+                try
+                {
+                    Map context = new HashMap();
+                    context.put( AbstractContinuumAction.KEY_PROJECT, project );
+                    context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_ID, buildDefinitionId );
+                    context.put( AbstractContinuumAction.KEY_TRIGGER, trigger );
+                    
+                    getLogger().info( "Performing action create-build-project-task" );
+                    actionManager.lookup( "create-build-project-task" ).execute( context );
+                }
+                catch ( ActionNotFoundException e )
+                {
+                   getLogger().error( "Error looking up action 'build-project'" );
+                   throw new TaskExecutionException( "Error looking up action 'build-project'", e );
+                }
+                catch ( Exception e )
+                {
+                    getLogger().error( e.getMessage(), e );
+                    throw new TaskExecutionException( "Error executing action 'build-project'", e );
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/scm/queue/PrepareBuildProjectsTaskExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,298 @@
+package org.apache.continuum.buildagent.taskqueue.manager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.continuum.scm.queue.PrepareBuildProjectsTask;
+import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.buildqueue.BuildProjectTask;
+import org.apache.maven.continuum.scm.queue.CheckOutTask;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.TaskQueue;
+import org.codehaus.plexus.taskqueue.TaskQueueException;
+import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
+
+/**
+ * @plexus.component role="org.apache.continuum.buildagent.taskqueue.manager.TaskQueueManager"
+ *                   role-hint="task-queue-manager-dist"
+ */
+public class DefaultTaskQueueManager
+    extends AbstractLogEnabled
+    implements TaskQueueManager, Contextualizable
+{
+    /**
+     * @plexus.requirement role-hint="build-project"
+     */
+    private TaskQueue buildQueue;
+
+    /**
+     * @plexus.requirement role-hint="check-out-project"
+     */
+    private TaskQueue checkoutQueue;
+
+    /**
+     * @plexus.requirement role-hint="prepare-build-project"
+     */
+    private TaskQueue prepareBuildQueue;
+
+    private PlexusContainer container;
+
+    public boolean buildInProgress()
+        throws TaskQueueManagerException
+    {
+        Task task = getCurrentTask( "build-project" );
+
+        if ( task != null && task instanceof BuildProjectTask )
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    public void cancelBuildTask( int projectId )
+        throws TaskQueueManagerException
+    {
+        Task currentTask = getBuildTaskQueueExecutor().getCurrentTask();
+
+        if ( currentTask instanceof BuildProjectTask )
+        {
+            if ( ( (BuildProjectTask) currentTask ).getProjectId() == projectId )
+            {
+                getLogger().info( "Cancelling task for project " + projectId );
+                getBuildTaskQueueExecutor().cancelTask( currentTask );
+            }
+        }
+    }
+
+    public boolean cancelCurrentBuild()
+        throws TaskQueueManagerException
+    {
+        Task task = getBuildTaskQueueExecutor().getCurrentTask();
+
+        if ( task != null )
+        {
+            if ( task instanceof BuildProjectTask )
+            {
+                getLogger().info( "Cancelling current build task" );
+                return getBuildTaskQueueExecutor().cancelTask( task );
+            }
+            else
+            {
+                getLogger().warn( "Current task not a BuildProjectTask - not cancelling" );
+            }
+        }
+        else
+        {
+            getLogger().warn( "No task running - not cancelling" );
+        }
+        return false;
+    }
+
+    public TaskQueue getBuildQueue()
+    {
+        return buildQueue;
+    }
+
+    public TaskQueueExecutor getBuildTaskQueueExecutor()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "build-project" );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new TaskQueueManagerException( e.getMessage(), e );
+        }
+    }
+
+    public TaskQueueExecutor getCheckoutTaskQueueExecutor()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "check-out-project" );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new TaskQueueManagerException( e.getMessage(), e );
+        }
+    }
+
+    public TaskQueue getCheckoutQueue()
+    {
+        return checkoutQueue;
+    }
+
+    public List<CheckOutTask> getCheckOutTasksInQueue()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return checkoutQueue.getQueueSnapshot();
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new TaskQueueManagerException( "Error while getting the checkout queue.", e );
+        }
+    }
+
+    public int getCurrentProjectIdBuilding()
+        throws TaskQueueManagerException
+    {
+        Task task = getBuildTaskQueueExecutor().getCurrentTask();
+        if ( task != null )
+        {
+            if ( task instanceof BuildProjectTask )
+            {
+                return ( (BuildProjectTask) task ).getProjectId();
+            }
+        }
+        return -1;
+    }
+
+    public TaskQueue getPrepareBuildQueue()
+    {
+        return prepareBuildQueue;
+    }
+
+    public TaskQueueExecutor getPrepareBuildTaskQueueExecutor()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new TaskQueueManagerException( e.getMessage(), e );
+        }
+    }
+
+    public List<BuildProjectTask> getProjectsInBuildQueue()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return buildQueue.getQueueSnapshot();
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new TaskQueueManagerException( "Error while getting the building queue.", e );
+        }
+    }
+
+    private Task getCurrentTask( String task )
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            TaskQueueExecutor executor = (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, task );
+            return executor.getCurrentTask();
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new TaskQueueManagerException( "Unable to lookup current task", e );
+        }
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+    public boolean isInBuildingQueue( int projectId )
+        throws TaskQueueManagerException
+    {
+        return isInBuildingQueue( projectId, -1 );
+    }
+
+    public boolean isInBuildingQueue( int projectId, int buildDefinitionId )
+        throws TaskQueueManagerException
+    {
+        List<BuildProjectTask> queue = getProjectsInBuildQueue();
+
+        for ( BuildProjectTask task : queue )
+        {
+            if ( task != null )
+            {
+                if ( buildDefinitionId < 0 )
+                {
+                    if ( task.getProjectId() == projectId )
+                    {
+                        return true;
+                    }
+                }
+                else
+                {
+                    if ( task.getProjectId() == projectId && task.getBuildDefinitionId() == buildDefinitionId )
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public boolean isInCheckoutQueue( int projectId )
+        throws TaskQueueManagerException
+    {
+        List<CheckOutTask> queue = getCheckOutTasksInQueue();
+
+        for ( CheckOutTask task : queue )
+        {
+            if ( task != null && task.getProjectId() == projectId )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean isInPrepareBuildQueue( int projectId )
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            List<PrepareBuildProjectsTask> queue = prepareBuildQueue.getQueueSnapshot();
+
+            for ( PrepareBuildProjectsTask task : queue )
+            {
+                if ( task != null )
+                {
+                    Map<Integer, Integer> map = ( (PrepareBuildProjectsTask) task ).getProjectsBuildDefinitionsMap();
+
+                    if ( map.size() > 0 )
+                    {
+                        Set<Integer> projectIds = map.keySet();
+
+                        if ( projectIds.contains( new Integer( projectId ) ) )
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+
+            return false;
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new TaskQueueManagerException( "Error while getting the tasks in prepare build queue", e );
+        }
+    }
+
+}
\ No newline at end of file

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,58 @@
+package org.apache.continuum.buildagent.taskqueue.manager;
+
+import java.util.List;
+
+import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.buildqueue.BuildProjectTask;
+import org.codehaus.plexus.taskqueue.TaskQueue;
+import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
+
+/**
+ * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
+ */
+public interface TaskQueueManager
+{
+    String ROLE = TaskQueueManager.class.getName();
+
+    boolean buildInProgress()
+        throws TaskQueueManagerException;
+
+    void cancelBuildTask( int projectId )
+        throws TaskQueueManagerException;
+
+    boolean cancelCurrentBuild()
+        throws TaskQueueManagerException;
+
+    TaskQueue getBuildQueue();
+
+    TaskQueueExecutor getBuildTaskQueueExecutor()
+        throws TaskQueueManagerException;
+
+    TaskQueue getCheckoutQueue();
+
+    List /* CheckOutTask */getCheckOutTasksInQueue()
+        throws TaskQueueManagerException;
+
+    int getCurrentProjectIdBuilding()
+        throws TaskQueueManagerException;
+
+    TaskQueue getPrepareBuildQueue();
+
+    TaskQueueExecutor getPrepareBuildTaskQueueExecutor()
+        throws TaskQueueManagerException;
+
+    public List<BuildProjectTask> getProjectsInBuildQueue()
+        throws TaskQueueManagerException;
+    
+    boolean isInBuildingQueue( int projectId )
+        throws TaskQueueManagerException;
+
+    boolean isInBuildingQueue( int projectId, int buildDefinitionId )
+        throws TaskQueueManagerException;
+
+    boolean isInCheckoutQueue( int projectId )
+        throws TaskQueueManagerException;
+    
+    boolean isInPrepareBuildQueue( int projectId )
+    throws TaskQueueManagerException;
+}
\ No newline at end of file

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java Thu Dec 11 03:36:41 2008
@@ -0,0 +1,45 @@
+package org.apache.continuum.buildagent.util;
+
+import org.apache.continuum.buildagent.model.BuildContext;
+import org.apache.maven.continuum.model.project.Project;
+
+//stateless buildcontext to project
+public class BuildContextToProject
+{
+    
+    private BuildContext buildContext;
+    
+
+    public static Project  getProject(BuildContext buildContext)
+    {
+        Project project = new Project();       
+
+        project.setScmUrl( buildContext.getScmUrl() );
+
+        project.setScmUsername( buildContext.getScmPassword());
+
+        project.setScmPassword( buildContext.getScmPassword() );
+
+        project.setExecutorId( buildContext.getExecutorId() );
+        
+        
+        //rename ?
+        project.setName( "distributed-build-[projectId="+buildContext.getProjectId()+"]" );
+        
+        return project;
+    }
+    
+    public BuildContext getBuildContext()
+    {
+        return buildContext;
+    }
+
+    public void setBuildContext( BuildContext buildContext )
+    {
+        this.buildContext = buildContext;
+    }
+    
+    
+    
+    
+}

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/util/BuildContextToProject.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml?rev=725665&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml Thu Dec 11 03:36:41 2008
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:aop="http://www.springframework.org/schema/aop"
+    xmlns:util="http://www.springframework.org/schema/util"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
+
+  <bean id="continuumBuildAgentService"
+    class="org.apache.continuum.buildagent.ContinuumBuildAgentServiceImpl">
+  </bean>
+  
+  <bean name="continuumBuildExecutor#maven2"
+         class="org.apache.maven.continuum.execution.maven.m2.MavenTwoBuildExecutor" autowire="byName">
+    <property name="defaultExecutable" value="mvn"/>
+    <property name="builderHelper" ref="mavenBuilderHelper"/>
+    <property name="projectHelper" ref="mavenProjectHelper"/>
+  </bean>
+  <bean name="continuumBuildExecutor#maven-1"
+         class="org.apache.maven.continuum.execution.maven.m1.MavenOneBuildExecutor" autowire="byName">
+    <property name="defaultExecutable" value="maven"/>
+    <property name="metadataHelper" ref="mavenOneMetadataHelper"/>
+  </bean>
+  <bean name="continuumBuildExecutor#ant"
+         class="org.apache.maven.continuum.execution.ant.AntBuildExecutor" autowire="byName">
+    <property name="defaultExecutable" value="ant"/>
+  </bean>
+  <bean name="continuumBuildExecutor#shell"
+         class="org.apache.maven.continuum.execution.shell.ShellBuildExecutor" autowire="byName">
+  </bean>
+
+</beans>
\ No newline at end of file

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision