continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r721318 - in /continuum/branches/continuum-distributed-builds: continuum-api/src/main/java/org/apache/continuum/dao/ continuum-api/src/main/java/org/apache/continuum/distributed/ continuum-api/src/main/java/org/apache/continuum/distributed/...
Date Fri, 28 Nov 2008 00:48:49 GMT
Author: ctan
Date: Thu Nov 27 16:48:48 2008
New Revision: 721318

URL: http://svn.apache.org/viewvc?rev=721318&view=rev
Log:
- added distributed build manager
- more fix in buildagent


Added:
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/DistributedBuildManager.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/BuildAgent.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/ConfigurationService.java
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/DefaultConfigurationService.java
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java
Modified:
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/resources/META-INF/spring-context.xml
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
    continuum/branches/continuum-distributed-builds/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
    continuum/branches/continuum-distributed-builds/continuum-test/src/main/java/org/apache/maven/continuum/configuration/ConfigurationServiceMock.java

Modified: continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java Thu Nov 27 16:48:48 2008
@@ -79,4 +79,7 @@
 
     ProjectGroup getProjectGroupByProjectId( int projectId )
         throws ContinuumObjectNotFoundException;
+
+    Project getProjectWithDependencies( int projectId )
+        throws ContinuumStoreException;
 }

Added: continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/DistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/DistributedBuildManager.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/DistributedBuildManager.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/manager/DistributedBuildManager.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,46 @@
+package org.apache.continuum.distributed.manager;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.apache.maven.continuum.ContinuumException;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public interface DistributedBuildManager
+{
+    String ROLE = DistributedBuildManager.class.getName();
+
+    void reload();
+
+    void buildProjects( Map<Integer, Integer> projectsAndBuildDefinitionsMap, int trigger )
+        throws ContinuumException;
+
+    void buildProjectsInQueue()
+        throws ContinuumException;
+
+    void updateProjectScmRoot( Map context )
+        throws ContinuumException;
+
+    void updateBuildResult( Map context )
+        throws ContinuumException;
+}

Added: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/BuildAgent.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/BuildAgent.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/BuildAgent.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/BuildAgent.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,44 @@
+package org.apache.continuum.distributed;
+
+import java.util.List;
+
+import org.apache.maven.continuum.model.project.Project;
+
+public class BuildAgent
+{
+    String url;
+
+    boolean busy;
+
+    List<Project> projects;
+
+    public String getUrl()
+    {
+        return url;
+    }
+
+    public void setUrl( String url )
+    {
+        this.url = url;
+    }
+
+    public boolean isBusy()
+    {
+        return busy;
+    }
+
+    public void setBusy( boolean busy )
+    {
+        this.busy = busy;
+    }
+
+    public List<Project> getProjects()
+    {
+        return projects;
+    }
+
+    public void setProjects( List<Project> projects )
+    {
+        this.projects = projects;
+    }
+}

Added: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,225 @@
+package org.apache.continuum.distributed.manager;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.apache.continuum.distributed.manager.DistributedBuildManager;
+
+public abstract class AbstractDistributedBuildManager
+    implements DistributedBuildManager
+{
+    public static final String KEY_PROJECT_ID = "project-id";
+
+    public static final String KEY_BUILD_DEFINITION_ID = "builddefinition-id";
+
+    public static final String KEY_TRIGGER = "trigger";
+
+    public static final String KEY_EXECUTOR_ID = "executor-id";
+
+    public static final String KEY_SCM_URL = "scm-url";
+
+    public static final String KEY_SCM_USERNAME = "scm-username";
+
+    public static final String KEY_SCM_PASSWORD = "scm-password";
+
+    public static final String KEY_BUILD_FILE = "build-file";
+
+    public static final String KEY_GOALS = "goals";
+
+    public static final String KEY_ARGUMENTS = "arguments";
+
+    public static final String KEY_BUILD_FRESH = "build-fresh";
+
+    public static final String KEY_BUILD_START = "build-start";
+
+    public static final String KEY_BUILD_END = "build-end";
+
+    public static final String KEY_BUILD_ERROR = "build-error";
+
+    public static final String KEY_BUILD_EXIT_CODE = "build-exit-code";
+
+    public static final String KEY_BUILD_STATE = "build-state";
+
+    public static final String KEY_SCM_STATE = "scm-state";
+
+    public static final String KEY_SCM_COMMAND_OUTPUT = "scm-command-output";
+
+    public static final String KEY_SCM_COMMAND_LINE = "scm-command-line";
+
+    public static final String KEY_SCM_PROVIDER_MESSAGE = "scm-provider-message";
+
+    public static final String KEY_SCM_EXCEPTION = "scm-exception";
+
+    public static final String KEY_PREPARE_BUILD_FINISHED = "prepare-build-finished";
+
+    public static final String KEY_AGENT_URL = "agent-url";
+
+    public static int getProjectId( Map context )
+    {
+        return getInteger( context, KEY_PROJECT_ID );
+    }
+
+    public static int getBuildDefinitionId( Map context )
+    {
+        return getInteger( context, KEY_BUILD_DEFINITION_ID );
+    }
+
+    public static String getBuildError( Map context )
+    {
+        return getString( context, KEY_BUILD_ERROR );
+    }
+
+    public static int getTrigger( Map context )
+    {
+        return getInteger( context, KEY_TRIGGER );
+    }
+
+    public static long getBuildStart( Map context )
+    {
+        return getLong( context, KEY_BUILD_START );
+    }
+
+    public static long getBuildEnd( Map context )
+    {
+        return getLong( context, KEY_BUILD_END );
+    }
+
+    public static int getBuildExitCode( Map context )
+    {
+        return getInteger( context, KEY_BUILD_EXIT_CODE );
+    }
+
+    public static int getBuildState( Map context )
+    {
+        return getInteger( context, KEY_BUILD_STATE );
+    }
+
+    public static String getScmCommandLine( Map context )
+    {
+        return getString( context, KEY_SCM_COMMAND_LINE );
+    }
+
+    public static String getScmCommandOutput( Map context )
+    {
+        return getString( context, KEY_SCM_COMMAND_OUTPUT );
+    }
+
+    public static String getScmException( Map context )
+    {
+        return getString( context, KEY_SCM_EXCEPTION );
+    }
+
+    public static String getScmProviderMessage( Map context )
+    {
+        return getString( context, KEY_SCM_PROVIDER_MESSAGE );
+    }
+
+    public static boolean isPrepareBuildFinished( Map context )
+    {
+        return getBoolean( context, KEY_PREPARE_BUILD_FINISHED );
+    }
+
+    public static String getAgentUrl( Map context )
+    {
+        return getString( context, KEY_AGENT_URL );
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    protected static String getString( Map context, String key )
+    {
+        return (String) getObject( context, key );
+    }
+
+    protected static String getString( Map context, String key, String defaultValue )
+    {
+        return (String) getObject( context, key, defaultValue );
+    }
+
+    protected static boolean getBoolean( Map context, String key )
+    {
+        return ( (Boolean) getObject( context, key ) ).booleanValue();
+    }
+    
+    protected static boolean getBoolean( Map context, String key, boolean defaultValue )
+    {
+        return ( (Boolean) getObject( context, key, Boolean.valueOf( defaultValue ) ) ).booleanValue();
+    }    
+
+    protected static int getInteger( Map context, String key )
+    {
+        Object obj = getObject( context, key, null );
+        
+        if ( obj == null )
+        {
+            return 0;
+        }
+        else
+        {
+            return ( (Integer) obj ).intValue();
+        }
+    }
+
+    protected static long getLong( Map context, String key )
+    {
+        Object obj = getObject( context, key, null );
+        
+        if ( obj == null )
+        {
+            return 0;
+        }
+        else
+        {
+            return ( (Long) obj ).longValue();
+        }
+    }
+
+    protected static Object getObject( Map context, String key )
+    {
+        if ( !context.containsKey( key ) )
+        {
+            throw new RuntimeException( "Missing key '" + key + "'." );
+        }
+
+        Object value = context.get( key );
+
+        if ( value == null )
+        {
+            throw new RuntimeException( "Missing value for key '" + key + "'." );
+        }
+
+        return value;
+    }
+
+    protected static Object getObject( Map context, String key, Object defaultValue )
+    {
+        Object value = context.get( key );
+
+        if ( value == null )
+        {
+            return defaultValue;
+        }
+
+        return value;
+    }
+}

Added: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,494 @@
+package org.apache.continuum.distributed.manager;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.continuum.configuration.BuildAgentConfiguration;
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.continuum.dao.BuildResultDao;
+import org.apache.continuum.dao.ProjectDao;
+import org.apache.continuum.dao.ProjectScmRootDao;
+import org.apache.continuum.distributed.BuildAgent;
+import org.apache.continuum.model.project.ProjectScmRoot;
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.configuration.ConfigurationService;
+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.project.ProjectDependency;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.scm.queue.PrepareBuildProjectsTask;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.apache.maven.continuum.utils.ProjectSorter;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Maria Catherine Tan
+ * @plexus.component role="org.apache.continuum.distributed.DistributedBuildManager"
+ */
+public class DefaultDistributedBuildManager
+    extends AbstractDistributedBuildManager
+{
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    /**
+     * @plexus.requirement
+     */
+    private ProjectDao projectDao;
+
+    /**
+     * @plexus.requirement
+     */
+    private BuildDefinitionDao buildDefinitionDao;
+
+    /**
+     * @plexus.requirement
+     */
+    private ProjectScmRootDao projectScmRootDao;
+
+    /**
+     * @plexus.requirement
+     */
+    private BuildResultDao buildResultDao;
+
+    private List<PrepareBuildProjectsTask> projectsBuildQueue;
+    
+    private List<BuildAgent> buildAgents;
+
+    public void initialize()
+    {
+        List<BuildAgentConfiguration> agents = configurationService.getBuildAgents();
+
+        if ( buildAgents == null )
+        {
+            buildAgents = new ArrayList<BuildAgent>();
+        }
+        
+        for ( BuildAgentConfiguration agent : agents )
+        {
+            if ( agent.isEnabled() )
+            { 
+                boolean found = false;
+
+                for ( BuildAgent buildAgent : buildAgents )
+                {
+                    if ( buildAgent.getUrl().equals( agent.getUrl() ) )
+                    {
+                        found = true;
+                        break;
+                    }
+                }
+
+                if ( !found )
+                {
+                    BuildAgent buildAgent = new BuildAgent();
+                    buildAgent.setUrl( agent.getUrl() );
+                    buildAgent.setBusy( false );
+                    buildAgents.add( buildAgent );
+                }
+            }
+        }
+    }
+
+    public void buildProjects( Map<Integer, Integer> projectsAndBuildDefinitionsMap, int trigger )
+        throws ContinuumException
+    {
+        buildProjects( projectsAndBuildDefinitionsMap, trigger, false );
+    }
+
+    public void buildProjectsInQueue()
+        throws ContinuumException
+    {
+        for ( PrepareBuildProjectsTask task : projectsBuildQueue )
+        {
+            Map projectsAndBuildDefinitions = task.getProjectsBuildDefinitionsMap();
+            int trigger = task.getTrigger();
+            
+            buildProjects( projectsAndBuildDefinitions, trigger, true );
+        }
+    }
+
+    public synchronized void buildProjects( Map<Integer, Integer> projectsAndBuildDefinitionsMap, int trigger, boolean inBuildQueue )
+        throws ContinuumException
+    {
+        boolean found = false;
+        
+        for ( BuildAgent buildAgent : buildAgents )
+        {
+            if ( !buildAgent.isBusy() )
+            {
+                List buildContext = initializeBuildContext( projectsAndBuildDefinitionsMap, trigger, buildAgent );
+
+                //BuildAgentXMLRpcClient client = new BuildAgentXmlRpcClient( buildAgent.getUrl(), null, null );
+                //client.buildProjects( buildContext );
+                log.info( "dispatched build to " + buildAgent.getUrl() );
+                found = true;
+            }
+        }
+
+        if ( !found && !inBuildQueue )
+        {
+            // all build agents are busy, put into projectBuildQueue for now
+            if ( projectsBuildQueue == null )
+            {
+                projectsBuildQueue = new ArrayList<PrepareBuildProjectsTask>();
+            }
+
+            PrepareBuildProjectsTask prepareBuildTask = new PrepareBuildProjectsTask( projectsAndBuildDefinitionsMap, trigger );
+            projectsBuildQueue.add( prepareBuildTask );
+        }
+    }
+
+    public void updateProjectScmRoot( Map context )
+        throws ContinuumException
+    {
+        try
+        {
+            int projectId = getProjectId( context );
+            
+            Project project = projectDao.getProjectWithScmDetails( projectId );
+            
+            ScmResult scmResult = new ScmResult();
+            scmResult.setCommandLine( getScmCommandLine( context ) );
+            scmResult.setCommandOutput( getScmCommandOutput( context ) );
+            scmResult.setException( getScmException( context ) );
+            scmResult.setProviderMessage( getScmProviderMessage( context ) );
+
+            String error = convertScmResultToError( scmResult );
+
+            if ( error == null )
+            {
+                scmResult.setSuccess( true );
+            }
+            else
+            {
+                scmResult.setSuccess( false );
+            }
+
+            project.setScmResult( scmResult );
+            projectDao.updateProject( project );
+
+            if ( error != null || isPrepareBuildFinished( context ) )
+            {
+                List<ProjectScmRoot> scmRoots = projectScmRootDao.getProjectScmRootByProjectGroup( project.getProjectGroup().getId() );
+                
+                for ( ProjectScmRoot scmRoot : scmRoots )
+                {
+                    if ( project.getScmUrl().startsWith( scmRoot.getScmRootAddress() ) )
+                    {
+                        if ( error != null )
+                        {
+                            scmRoot.setError( error );
+                            scmRoot.setState( ContinuumProjectState.ERROR );
+                        }
+                        else
+                        {
+                            scmRoot.setState( ContinuumProjectState.UPDATED );
+                        }
+                        projectScmRootDao.updateProjectScmRoot( scmRoot );
+                    }
+                }
+            }
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumException( "Error updating project scm root", e );
+        }
+    }
+
+    public void updateBuildResult( Map context )
+        throws ContinuumException
+    {
+        try
+        {
+            int projectId = getProjectId( context );
+            int buildDefinitionId = getBuildDefinitionId( context );
+
+            Project project = projectDao.getProjectWithBuildDetails( projectId );
+            BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( buildDefinitionId );
+
+            BuildResult oldBuildResult =
+                buildResultDao.getLatestBuildResultForBuildDefinition( projectId, buildDefinitionId );
+
+            int buildNumber = project.getBuildNumber() + 1;
+
+            // ----------------------------------------------------------------------
+            // Make the buildResult
+            // ----------------------------------------------------------------------
+
+            BuildResult buildResult = new BuildResult();
+
+            buildResult.setStartTime( getBuildStart( context ) );
+            buildResult.setEndTime( getBuildEnd( context ) );
+            buildResult.setBuildDefinition( buildDefinition );
+            buildResult.setBuildNumber( buildNumber );
+            buildResult.setError( getBuildError( context ) );
+            buildResult.setExitCode( getBuildExitCode( context ) );
+            buildResult.setModifiedDependencies( getModifiedDependencies( oldBuildResult, context ) );
+            buildResult.setProject( project );
+            buildResult.setState( getBuildState( context ) );
+            buildResult.setTrigger( getTrigger( context ) );
+            
+            buildResultDao.addBuildResult( project, buildResult );
+            
+            project.setBuildNumber( buildNumber );
+            project.setLatestBuildId( buildResult.getId() );
+            project.setOldState( project.getState() );
+            project.setState( getBuildState( context ) );
+
+            projectDao.updateProject( project );
+
+            updateBuildAgent( context );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumException( "Error while updating build result for project", e );
+        }
+    }
+
+    public void reload()
+    {
+        this.initialize();
+    }
+
+    private List initializeBuildContext( Map<Integer, Integer> projectsAndBuildDefinitions, int trigger, BuildAgent buildAgent )
+        throws ContinuumException
+    {
+        List buildContext = new ArrayList();
+        List<Project> projects = new ArrayList<Project>();
+
+        try
+        {
+            for ( Integer projectId : projectsAndBuildDefinitions.keySet() )
+            {
+                Project project = projectDao.getProjectWithDependencies( projectId );
+                projects.add( project );
+            }
+
+            try
+            {
+                projects = ProjectSorter.getSortedProjects( projects, null );
+            }
+            catch ( CycleDetectedException e )
+            {
+                log.info( "Cycle Detected" );
+            }
+
+            int ctr = 0;
+            
+            for ( Project project : projects )
+            {
+                if ( ctr == 0 )
+                {
+                    List<ProjectScmRoot> scmRoots = projectScmRootDao.getProjectScmRootByProjectGroup( project.getProjectGroup().getId() );
+                    for ( ProjectScmRoot scmRoot : scmRoots )
+                    {
+                        if ( project.getScmUrl().startsWith( scmRoot.getScmRootAddress() ) )
+                        {
+                            scmRoot.setOldState( scmRoot.getState() );
+                            scmRoot.setState( ContinuumProjectState.UPDATING );
+                            projectScmRootDao.updateProjectScmRoot( scmRoot );
+                            break;
+                        }
+                    }
+                }
+                
+                int buildDefinitionId = projectsAndBuildDefinitions.get( project.getId() );
+                BuildDefinition buildDef = buildDefinitionDao.getBuildDefinition( buildDefinitionId );
+                BuildResult oldBuildResult =
+                    buildResultDao.getLatestBuildResultForBuildDefinition( project.getId(), buildDefinitionId );
+
+                Map context = new HashMap();
+                context.put( KEY_PROJECT_ID, project.getId() );
+                context.put( KEY_EXECUTOR_ID, project.getExecutorId() );
+                context.put( KEY_SCM_URL, project.getScmUrl() );
+                context.put( KEY_SCM_USERNAME, project.getScmUsername() );
+                context.put( KEY_SCM_PASSWORD, project.getScmPassword() );
+                context.put( KEY_BUILD_DEFINITION_ID, buildDefinitionId );
+                context.put( KEY_BUILD_FILE, buildDef.getBuildFile() );
+                context.put( KEY_GOALS, buildDef.getGoals() );
+                context.put( KEY_ARGUMENTS, buildDef.getArguments() );
+                context.put( KEY_TRIGGER, trigger );
+                context.put( KEY_BUILD_FRESH, buildDef.isBuildFresh() );
+                
+                buildContext.add( context );
+                ctr++;
+            }
+            
+            buildAgent.setBusy( true );
+            buildAgent.setProjects( projects );
+
+            return buildContext;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumException( "Error while initializing build context", e );
+        }
+    }
+
+    private List<ProjectDependency> getModifiedDependencies( BuildResult oldBuildResult, Map context )
+        throws ContinuumException
+    {
+        if ( oldBuildResult == null )
+        {
+            return null;
+        }
+
+        try
+        {
+            Project project = projectDao.getProjectWithAllDetails( getProjectId( context ) );
+            List<ProjectDependency> dependencies = project.getDependencies();
+
+            if ( dependencies == null )
+            {
+                dependencies = new ArrayList<ProjectDependency>();
+            }
+
+            if ( project.getParent() != null )
+            {
+                dependencies.add( project.getParent() );
+            }
+
+            if ( dependencies.isEmpty() )
+            {
+                return null;
+            }
+
+            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(),
+                                                                                           oldBuildResult.getEndTime() );
+                    if ( buildResults != null && !buildResults.isEmpty() )
+                    {
+                        log.debug( "Dependency changed: " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" +
+                            dep.getVersion() );
+                        modifiedDependencies.add( dep );
+                    }
+                    else
+                    {
+                        log.debug( "Dependency not changed: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                            ":" + dep.getVersion() );
+                    }
+                }
+                else
+                {
+                    log.debug( "Skip non Continuum project: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                        ":" + dep.getVersion() );
+                }
+            }
+
+            return modifiedDependencies;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            log.warn( "Can't get the project dependencies", e );
+        }
+
+        return null;
+    }
+
+    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 updateBuildAgent( Map context )
+        throws ContinuumException
+    {
+        for ( BuildAgent buildAgent : buildAgents )
+        {
+            if ( buildAgent.getUrl().equals( getAgentUrl( context ) ) )
+            {
+                for ( Project project : buildAgent.getProjects() )
+                {
+                    if ( project.getId() == getProjectId( context ) )
+                    {
+                        buildAgent.getProjects().remove( project );
+                        break;
+                    }
+                }
+
+                if ( buildAgent.getProjects() == null || buildAgent.getProjects().size() == 0 )
+                {
+                    buildAgent.setBusy( false );
+                    buildProjectsInQueue();
+                }
+            }
+        }
+    }
+
+}

Modified: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java Thu Nov 27 16:48:48 2008
@@ -43,6 +43,7 @@
 import org.apache.continuum.dao.ProjectGroupDao;
 import org.apache.continuum.dao.ProjectScmRootDao;
 import org.apache.continuum.dao.ScheduleDao;
+import org.apache.continuum.distributed.manager.DistributedBuildManager;
 import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.model.release.ContinuumReleaseResult;
 import org.apache.continuum.purge.ContinuumPurgeManager;
@@ -220,7 +221,6 @@
 
     private PlexusContainer container;
 
-
     /**
      * @plexus.requirement role-hint="continuumUrl"
      */
@@ -248,6 +248,11 @@
      */
     private TaskQueueManager taskQueueManager;
 
+    /**
+     * @plexus.requirement
+     */
+    private DistributedBuildManager distributedBuildManager;
+
     public DefaultContinuum()
     {
         Runtime.getRuntime().addShutdownHook( new Thread()
@@ -3354,7 +3359,7 @@
     {
         if ( configurationService.isDistributedBuildEnabled() )
         {
-            
+            distributedBuildManager.buildProjects( projectsBuildDefinitionsMap, trigger );
         }
         else
         {

Modified: continuum/branches/continuum-distributed-builds/continuum-core/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/resources/META-INF/spring-context.xml?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/resources/META-INF/spring-context.xml (original)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/resources/META-INF/spring-context.xml Thu Nov 27 16:48:48 2008
@@ -32,5 +32,13 @@
       <bean class="org.apache.maven.continuum.notification.manager.spring.NotifierFactoryBean"/>
     </property>
   </bean>
-  
+
+  <bean id="distributedBuildManager"
+    class="org.apache.continuum.distributed.manager.DefaultDistributedBuildManager" init-method="initialize">
+    <property name="configurationService" ref="configurationService"/>
+    <property name="projectDao" ref="projectDao"/>
+    <property name="buildDefinitionDao" ref="buildDefinitionDao"/>
+    <property name="buildResultDao" ref="buildResultDao"/>
+    <property name="projectScmRootDao" ref="projectScmRootDao"/>
+  </bean>
 </beans>

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,165 @@
+package org.apache.continuum.buildagent;
+
+import java.util.Map;
+
+public abstract class AbstractContinuumBuildAgentService
+    implements ContinuumBuildAgentService
+{
+    public static final String KEY_PROJECT_ID = "project-id";
+
+    public static final String KEY_BUILD_DEFINITION_ID = "builddefinition-id";
+
+    public static final String KEY_TRIGGER = "trigger";
+
+    public static final String KEY_EXECUTOR_ID = "executor-id";
+
+    public static final String KEY_SCM_URL = "scm-url";
+
+    public static final String KEY_SCM_USERNAME = "scm-username";
+
+    public static final String KEY_SCM_PASSWORD = "scm-password";
+
+    public static final String KEY_BUILD_FILE = "build-file";
+
+    public static final String KEY_GOALS = "goals";
+
+    public static final String KEY_ARGUMENTS = "arguments";
+
+    public static final String KEY_BUILD_FRESH = "build-fresh";
+
+    public static final String KEY_BUILD_START = "build-start";
+
+    public static final String KEY_BUILD_END = "build-end";
+
+    public static final String KEY_BUILD_ERROR = "build-error";
+
+    public static final String KEY_BUILD_EXIT_CODE = "build-exit-code";
+
+    public static final String KEY_BUILD_STATE = "build-state";
+
+    public static final String KEY_SCM_STATE = "scm-state";
+
+    public static final String KEY_SCM_COMMAND_OUTPUT = "scm-command-output";
+
+    public static final String KEY_SCM_COMMAND_LINE = "scm-command-line";
+
+    public static final String KEY_SCM_PROVIDER_MESSAGE = "scm-provider-message";
+
+    public static final String KEY_SCM_EXCEPTION = "scm-exception";
+
+    public static Integer getProjectId( Map context )
+    {
+        return getInteger( context, KEY_PROJECT_ID );
+    }
+
+    public static Integer getBuildDefinitionId( Map context )
+    {
+        return getInteger( context, KEY_BUILD_DEFINITION_ID );
+    }
+
+    public static String getBuildFile( Map context )
+    {
+        return getString( context, KEY_BUILD_FILE );
+    }
+
+    public static String getExecutorId( Map context )
+    {
+        return getString( context, KEY_EXECUTOR_ID );
+    }
+
+    public static String getGoals( Map context )
+    {
+        return getString( context, KEY_GOALS );
+    }
+
+    public static String getArguments( Map context )
+    {
+        return getString( context, KEY_ARGUMENTS );
+    }
+
+    public static String getScmUrl( Map context )
+    {
+        return getString( context, KEY_SCM_URL );
+    }
+
+    public static String getScmUsername( Map context )
+    {
+        return getString( context, KEY_SCM_USERNAME );
+    }
+
+    public static String getScmPassword( Map context )
+    {
+        return getString( context, KEY_SCM_PASSWORD );
+    }
+
+    public static boolean isBuildFresh( Map context )
+    {
+        return getBoolean( context, KEY_BUILD_FRESH );
+    }
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    protected static String getString( Map context, String key )
+    {
+        return (String) getObject( context, key );
+    }
+
+    protected static String getString( Map context, String key, String defaultValue )
+    {
+        return (String) getObject( context, key, defaultValue );
+    }
+
+    protected static boolean getBoolean( Map context, String key )
+    {
+        return ( (Boolean) getObject( context, key ) ).booleanValue();
+    }
+    
+    protected static boolean getBoolean( Map context, String key, boolean defaultValue )
+    {
+        return ( (Boolean) getObject( context, key, Boolean.valueOf( defaultValue ) ) ).booleanValue();
+    }    
+
+    protected static int getInteger( Map context, String key )
+    {
+        Object obj = getObject( context, key, null );
+        
+        if ( obj == null )
+        {
+            return 0;
+        }
+        else
+        {
+            return ( (Integer) obj ).intValue();
+        }
+    }
+
+    protected static Object getObject( Map context, String key )
+    {
+        if ( !context.containsKey( key ) )
+        {
+            throw new RuntimeException( "Missing key '" + key + "'." );
+        }
+
+        Object value = context.get( key );
+
+        if ( value == null )
+        {
+            throw new RuntimeException( "Missing value for key '" + key + "'." );
+        }
+
+        return value;
+    }
+
+    protected static Object getObject( Map context, String key, Object defaultValue )
+    {
+        Object value = context.get( key );
+
+        if ( value == null )
+        {
+            return defaultValue;
+        }
+
+        return value;
+    }
+}

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java Thu Nov 27 16:48:48 2008
@@ -7,7 +7,7 @@
 
 public interface ContinuumBuildAgentService
 {
-    void buildProject( List<Map> projectsBuildContext )
+    void buildProjects( List<Map> projectsBuildContext )
         throws ContinuumBuildAgentException;
 
     List<Installation> getAvailableInstallations()

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java Thu Nov 27 16:48:48 2008
@@ -1,41 +1,34 @@
 package org.apache.continuum.buildagent;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.continuum.buildagent.configuration.ContinuumBuildAgentConfiguration;
-import org.apache.continuum.buildagent.configuration.ContinuumConfiguration;
-import org.apache.continuum.buildagent.configuration.ContinuumConfigurationException;
+import org.apache.continuum.buildagent.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.model.BuildContext;
 import org.apache.continuum.buildagent.model.Installation;
 
 public class ContinuumBuildAgentServiceImpl
-    implements ContinuumBuildAgentService
+    extends AbstractContinuumBuildAgentService
 {
     /**
      * @plexus.requirement
      */
-    private ContinuumConfiguration configuration;
+    private ConfigurationService configurationService;
 
-    private ContinuumBuildAgentConfiguration buildAgentConfiguration;
-
-    public void initialize()
+    public void buildProjects( List<Map> projectsBuildContext )
         throws ContinuumBuildAgentException
     {
-        loadData();
-    }
+        List<BuildContext> buildContext = initializeBuildContext( projectsBuildContext );
 
-    public void buildProject( List<Map> projectsBuildContext )
-        throws ContinuumBuildAgentException
-    {
-        // TODO Auto-generated method stub
+        prepareBuildProjects( buildContext );
         
     }
 
     public List<Installation> getAvailableInstallations()
         throws ContinuumBuildAgentException
     {
-        // TODO Auto-generated method stub
-        return null;
+        return configurationService.getAvailableInstallations();
     }
 
     public Map getBuildResult( int projectId )
@@ -52,22 +45,50 @@
         return false;
     }
 
-    private void loadData()
-        throws ContinuumBuildAgentException
+    public int getProjectCurrentlyBuilding()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    private List<BuildContext> initializeBuildContext( List<Map> projectsBuildContext )
     {
-        try
+        List<BuildContext> buildContext = new ArrayList<BuildContext>();
+        
+        for ( Map map : projectsBuildContext )
         {
-            buildAgentConfiguration = configuration.getContinuumBuildAgentConfiguration();
+            BuildContext context = new BuildContext();
+            context.setProjectId( getProjectId( map ) );
+            context.setBuildDefinitionId( getBuildDefinitionId( map ) );
+            context.setBuildFile( getBuildFile( map ) );
+            context.setExecutorId( getExecutorId( map ) );
+            context.setGoals( getGoals( map ) );
+            context.setArguments( getArguments( map ) );
+            context.setScmUrl( getScmUrl( map ) );
+            context.setScmUsername( getScmUsername( map ) );
+            context.setScmPassword( getScmPassword( map ) );
+            context.setBuildFresh( isBuildFresh( map ) );
+
+            buildContext.add( context );
         }
-        catch ( ContinuumConfigurationException e )
+
+        return buildContext;
+    }
+
+    private void prepareBuildProjects( List<BuildContext> context )
+    {
+        for ( BuildContext buildContext : context )
         {
-            throw new ContinuumBuildAgentException( "Unable to load build agent configuration", e );
+            if ( buildContext.isBuildFresh() )
+            {
+                // clean working directory
+                cleanWorkingDirectory( buildContext );
+            }
         }
     }
 
-    public int getProjectCurrentlyBuilding()
+    private void cleanWorkingDirectory( BuildContext context )
     {
-        // TODO Auto-generated method stub
-        return 0;
+        
     }
 }

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/ConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/ConfigurationService.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/ConfigurationService.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/ConfigurationService.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,29 @@
+package org.apache.continuum.buildagent.configuration;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.continuum.buildagent.model.Installation;
+
+public interface ConfigurationService
+{
+    String ROLE = ConfigurationService.class.getName();
+
+    File getBuildOutputDirectory();
+
+    File getBuildOutputDirectory( int projectId );
+
+    File getWorkingDirectory();
+
+    File getWorkingDirectory( int projectId );
+
+    String getContinuumServerUrl();
+
+    String getBuildOutput( int projectId )
+        throws ContinuumConfigurationException;
+
+    File getBuildOutputFile( int projectId )
+        throws ContinuumConfigurationException;
+
+    List<Installation> getAvailableInstallations();
+}

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/DefaultConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/DefaultConfigurationService.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/DefaultConfigurationService.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/configuration/DefaultConfigurationService.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,123 @@
+package org.apache.continuum.buildagent.configuration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.continuum.buildagent.model.Installation;
+import org.codehaus.plexus.util.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultConfigurationService
+    implements ConfigurationService
+{
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumConfiguration configuration;
+
+    private ContinuumBuildAgentConfiguration buildAgentConfiguration;
+
+    public void initialize()
+        throws ContinuumConfigurationException
+    {
+        loadData();
+    }
+
+    public ContinuumConfiguration getConfiguration()
+    {
+        return configuration;
+    }
+
+    public void setConfiguration( ContinuumConfiguration configuration )
+    {
+        this.configuration = configuration;
+    }
+
+    public File getBuildOutputDirectory()
+    {
+        return buildAgentConfiguration.getBuildOutputDirectory();
+    }
+
+    public File getBuildOutputDirectory( int projectId )
+    {
+        File dir = new File( getBuildOutputDirectory(), Integer.toString( projectId ) );
+
+        try
+        {
+            dir = dir.getCanonicalFile();
+        }
+        catch ( IOException e )
+        {
+        }
+
+        return dir;
+    }
+
+    public File getWorkingDirectory()
+    {
+        return buildAgentConfiguration.getWorkingDirectory();
+    }
+
+    public File getWorkingDirectory( int projectId )
+    {
+        return new File( buildAgentConfiguration.getWorkingDirectory(), Integer.toString( projectId ) );
+    }
+
+    public String getBuildOutput( int projectId )
+        throws ContinuumConfigurationException
+    {
+        File file = getBuildOutputFile( projectId );
+    
+        try
+        {
+            if ( file.exists() )
+            {
+                return FileUtils.fileRead( file.getAbsolutePath() );
+            }
+            else
+            {
+                return "There are no output for this build.";
+            }
+        }
+        catch ( IOException e )
+        {
+            log.warn( "Error reading build output for project '" + projectId + "'.", e );
+    
+            return null;
+        }
+    }
+
+    public File getBuildOutputFile( int projectId )
+        throws ContinuumConfigurationException
+    {
+        File dir = getBuildOutputDirectory( projectId );
+
+        if ( !dir.exists() && !dir.mkdirs() )
+        {
+            throw new ContinuumConfigurationException( 
+                      "Could not make the build output directory: " + "'" + dir.getAbsolutePath() + "'." );
+        }
+
+        return new File( dir, "build.log.txt" );
+    }
+
+    public String getContinuumServerUrl()
+    {
+        return buildAgentConfiguration.getContinuumServerUrl();
+    }
+
+    public List<Installation> getAvailableInstallations()
+    {
+        return buildAgentConfiguration.getInstallations();
+    }
+
+    private void loadData()
+        throws ContinuumConfigurationException
+    {
+        buildAgentConfiguration = configuration.getContinuumBuildAgentConfiguration();
+    }
+}

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java?rev=721318&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java (added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java Thu Nov 27 16:48:48 2008
@@ -0,0 +1,136 @@
+package org.apache.continuum.buildagent.model;
+
+public class BuildContext
+{
+    private int projectId;
+
+    private int buildDefinitionId;
+
+    private String buildFile;
+
+    private String goals;
+
+    private String arguments;
+
+    private String executorId;
+
+    private String scmUrl;
+
+    private String scmUsername;
+
+    private String scmPassword;
+
+    private int trigger;
+
+    private boolean buildFresh;
+
+    public int getProjectId()
+    {
+        return projectId;
+    }
+
+    public void setProjectId( int projectId )
+    {
+        this.projectId = projectId;
+    }
+
+    public int getBuildDefinitionId()
+    {
+        return buildDefinitionId;
+    }
+
+    public void setBuildDefinitionId( int buildDefinitionId )
+    {
+        this.buildDefinitionId = buildDefinitionId;
+    }
+
+    public String getBuildFile()
+    {
+        return buildFile;
+    }
+
+    public void setBuildFile( String buildFile )
+    {
+        this.buildFile = buildFile;
+    }
+
+    public String getGoals()
+    {
+        return goals;
+    }
+
+    public void setGoals( String goals )
+    {
+        this.goals = goals;
+    }
+
+    public String getArguments()
+    {
+        return arguments;
+    }
+
+    public void setArguments( String arguments )
+    {
+        this.arguments = arguments;
+    }
+
+    public String getExecutorId()
+    {
+        return executorId;
+    }
+
+    public void setExecutorId( String executorId )
+    {
+        this.executorId = executorId;
+    }
+
+    public String getScmUrl()
+    {
+        return scmUrl;
+    }
+
+    public void setScmUrl( String scmUrl )
+    {
+        this.scmUrl = scmUrl;
+    }
+
+    public String getScmUsername()
+    {
+        return scmUsername;
+    }
+
+    public void setScmUsername( String scmUsername )
+    {
+        this.scmUsername = scmUsername;
+    }
+
+    public String getScmPassword()
+    {
+        return scmPassword;
+    }
+
+    public void setScmPassword( String scmPassword )
+    {
+        this.scmPassword = scmPassword;
+    }
+
+    public int getTrigger()
+    {
+        return trigger;
+    }
+
+    public void setTrigger( int trigger )
+    {
+        this.trigger = trigger;
+    }
+
+    public boolean isBuildFresh()
+    {
+        return buildFresh;
+    }
+
+    public void setBuildFresh( boolean buildFresh )
+    {
+        this.buildFresh = buildFresh;
+    }
+}

Modified: continuum/branches/continuum-distributed-builds/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java Thu Nov 27 16:48:48 2008
@@ -297,4 +297,10 @@
 
         }
     }
+
+    public Project getProjectWithDependencies( int projectId )
+        throws ContinuumStoreException
+    {
+        return (Project) getObjectById( Project.class, projectId, PROJECT_DEPENDENCIES_FETCH_GROUP );
+    }
 }

Modified: continuum/branches/continuum-distributed-builds/continuum-test/src/main/java/org/apache/maven/continuum/configuration/ConfigurationServiceMock.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-test/src/main/java/org/apache/maven/continuum/configuration/ConfigurationServiceMock.java?rev=721318&r1=721317&r2=721318&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-test/src/main/java/org/apache/maven/continuum/configuration/ConfigurationServiceMock.java (original)
+++ continuum/branches/continuum-distributed-builds/continuum-test/src/main/java/org/apache/maven/continuum/configuration/ConfigurationServiceMock.java Thu Nov 27 16:48:48 2008
@@ -19,10 +19,12 @@
  * under the License.
  */
 
+import org.apache.continuum.configuration.BuildAgentConfiguration;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 
 import java.io.File;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -240,4 +242,27 @@
         return null;
     }
 
+    public void addBuildAgent( BuildAgentConfiguration buildAgent )
+        throws ConfigurationException
+    {    
+    }
+
+    public List<BuildAgentConfiguration> getBuildAgents()
+    {
+        return null;
+    }
+
+    public boolean isDistributedBuildEnabled()
+    {
+        return false;
+    }
+
+    public void removeBuildAgent( BuildAgentConfiguration buildAgent )
+    {   
+    }
+
+    public void setDistributedBuildEnabled( boolean distributedBuildEnabled )
+    {
+    }
+
 }



Mime
View raw message