continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r726475 - in /continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent: ./ action/ model/ taskqueue/ taskqueue/execution/ utils/
Date Sun, 14 Dec 2008 15:35:10 GMT
Author: ctan
Date: Sun Dec 14 07:35:09 2008
New Revision: 726475

URL: http://svn.apache.org/viewvc?rev=726475&view=rev
Log:
- added action classes
- added preparebuildtaskexecutor
- updated buildcontext
- added utility classes

Added:
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.java
  (with props)
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
  (with props)
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CleanWorkingDirectory.java
  (with props)
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/PrepareBuildTaskExecutor.java
  (with props)
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToBuildDefinition.java
  (with props)
    continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
  (contents, props changed)
      - copied, changed from r725955, continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java
Modified:
    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-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java

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=726475&r1=726474&r2=726475&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
Sun Dec 14 07:35:09 2008
@@ -7,9 +7,10 @@
 import org.apache.continuum.buildagent.configuration.ConfigurationService;
 import org.apache.continuum.buildagent.model.BuildContext;
 import org.apache.continuum.buildagent.model.Installation;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 
 public class ContinuumBuildAgentServiceImpl
-    extends AbstractContinuumBuildAgentService
+    implements ContinuumBuildAgentService
 {
     /**
      * @plexus.requirement
@@ -21,8 +22,6 @@
     {
         List<BuildContext> buildContext = initializeBuildContext( projectsBuildContext
);
 
-        prepareBuildProjects( buildContext );
-        
         try
         {
             Thread.sleep( 60000 );
@@ -71,18 +70,18 @@
         for ( Map map : projectsBuildContext )
         {
             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 ) );
-            context.setProjectGroupId( getProjectGroupId( map ) );
-            context.setScmRootAddress( getScmRootAddress( map ) );
+            context.setProjectId( ContinuumBuildAgentUtil.getProjectId( map ) );
+            context.setBuildDefinitionId( ContinuumBuildAgentUtil.getBuildDefinitionId( map
) );
+            context.setBuildFile( ContinuumBuildAgentUtil.getBuildFile( map ) );
+            context.setExecutorId( ContinuumBuildAgentUtil.getExecutorId( map ) );
+            context.setGoals( ContinuumBuildAgentUtil.getGoals( map ) );
+            context.setArguments( ContinuumBuildAgentUtil.getArguments( map ) );
+            context.setScmUrl( ContinuumBuildAgentUtil.getScmUrl( map ) );
+            context.setScmUsername( ContinuumBuildAgentUtil.getScmUsername( map ) );
+            context.setScmPassword( ContinuumBuildAgentUtil.getScmPassword( map ) );
+            context.setBuildFresh( ContinuumBuildAgentUtil.isBuildFresh( map ) );
+            context.setProjectGroupId( ContinuumBuildAgentUtil.getProjectGroupId( map ) );
+            context.setScmRootAddress( ContinuumBuildAgentUtil.getScmRootAddress( map ) );
             
             buildContext.add( context );
         }
@@ -90,23 +89,6 @@
         return buildContext;
     }
 
-    private void prepareBuildProjects( List<BuildContext> context )
-    {
-        for ( BuildContext buildContext : context )
-        {
-            if ( buildContext.isBuildFresh() )
-            {
-                // clean working directory
-                cleanWorkingDirectory( buildContext );
-            }
-        }
-    }
-
-    private void cleanWorkingDirectory( BuildContext context )
-    {
-        
-    }
-
     public ConfigurationService getConfigurationService()
     {
         return configurationService;

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.java?rev=726475&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.java
Sun Dec 14 07:35:09 2008
@@ -0,0 +1,41 @@
+package org.apache.continuum.buildagent.action;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.continuum.buildagent.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
+import org.apache.maven.continuum.model.project.Project;
+import org.codehaus.plexus.action.AbstractAction;
+
+/**
+ * @plexus.component role="org.codehaus.plexus.action.Action" role-hint="check-agent-working-directory"
+ */
+public class CheckWorkingDirectoryAction
+    extends AbstractAction
+{
+    /**
+     * @plexus.requirement
+     */    
+    ConfigurationService configurationService;
+    
+    public void execute( Map context )
+        throws Exception
+    {
+        Project project = ContinuumBuildAgentUtil.getProject( context );
+
+        File workingDirectory = configurationService.getWorkingDirectory( project.getId()
);
+
+        if ( !workingDirectory.exists() )
+        {
+            context.put( ContinuumBuildAgentUtil.KEY_WORKING_DIRECTORY_EXISTS, Boolean.FALSE
);
+
+            return;
+        }
+
+        File[] files = workingDirectory.listFiles();
+
+        context.put( ContinuumBuildAgentUtil.KEY_WORKING_DIRECTORY_EXISTS, Boolean.valueOf(
files.length > 0 ) );
+    }
+
+}

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

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckWorkingDirectoryAction.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/action/CheckoutProjectAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java?rev=726475&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
Sun Dec 14 07:35:09 2008
@@ -0,0 +1,219 @@
+package org.apache.continuum.buildagent.action;
+
+import java.io.File;
+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.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.model.BuildContext;
+import org.apache.continuum.buildagent.utils.BuildContextToBuildDefinition;
+import org.apache.continuum.buildagent.utils.BuildContextToProject;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
+import org.apache.continuum.scm.ContinuumScm;
+import org.apache.continuum.scm.ContinuumScmConfiguration;
+import org.apache.continuum.utils.ContinuumUtils;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.codehaus.plexus.action.AbstractAction;
+
+/**
+ * @plexus.requirement role="org.codehaus.plexus.action.Action" role-hint="checkout-agent-project"
+ */
+public class CheckoutProjectAction
+    extends AbstractAction
+{
+    /**
+     * @plexus.requirement
+     */
+    private BuildContextManager buildContextManager;
+
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    /**
+     * @plexus.requirement
+     */
+    private ContinuumScm scm;
+
+    public void execute( Map context )
+        throws Exception
+    {
+        BuildContext buildContext = buildContextManager.getBuildContext( ContinuumBuildAgentUtil.getProjectId(
context ) );
+        
+        Project project = BuildContextToProject.getProject( buildContext );
+        BuildDefinition buildDefinition = BuildContextToBuildDefinition.getBuildDefinition(
buildContext );
+
+        File workingDirectory = configurationService.getWorkingDirectory( project.getId()
);
+
+        // ----------------------------------------------------------------------
+        // Check out the project
+        // ----------------------------------------------------------------------
+
+        ScmResult result;
+
+        try
+        {
+            String scmUserName = ContinuumBuildAgentUtil.getString( context, ContinuumBuildAgentUtil.KEY_SCM_USERNAME,
"" );
+            String scmPassword = ContinuumBuildAgentUtil.getString( context, ContinuumBuildAgentUtil.KEY_SCM_PASSWORD,
"" );
+
+            ContinuumScmConfiguration config =
+                createScmConfiguration( project, workingDirectory, scmUserName, scmPassword
);
+
+            String tag = config.getTag();
+            getLogger().info( "Checking out project: '" + project.getName() + "', id: '"
+ project.getId() + "' " +
+                "to '" + workingDirectory + "'" + ( tag != null ? " with branch/tag " + tag
+ "." : "." ) );
+
+            CheckOutScmResult checkoutResult = scm.checkout( config );
+            //if ( StringUtils.isNotEmpty( checkoutResult.getRelativePathProjectDirectory()
) )
+            //{
+            //    context.put( AbstractContinuumAction.KEY_PROJECT_RELATIVE_PATH,
+            //                 checkoutResult.getRelativePathProjectDirectory() );
+            //}
+
+            if ( !checkoutResult.isSuccess() )
+            {
+                // TODO: is it more appropriate to return this in the converted result so
that it can be presented to
+                // the user?
+                String msg = "Error while checking out the code for project: '" + project.getName()
+ "', id: '" +
+                    project.getId() + "' to '" + workingDirectory.getAbsolutePath() + "'"
+
+                    ( tag != null ? " with branch/tag " + tag + "." : "." );
+                getLogger().warn( msg );
+
+                getLogger().warn( "Command output: " + checkoutResult.getCommandOutput()
);
+
+                getLogger().warn( "Provider message: " + checkoutResult.getProviderMessage()
);
+            }
+            else
+            {
+                getLogger().info( "Checked out " + checkoutResult.getCheckedOutFiles().size()
+ " files." );
+            }
+
+            result = convertScmResult( checkoutResult );
+        }
+        catch ( ScmRepositoryException e )
+        {
+            result = new ScmResult();
+
+            result.setSuccess( false );
+
+            result.setProviderMessage( e.getMessage() + ": " + getValidationMessages( e )
);
+
+            getLogger().error( e.getMessage(), e );
+        }
+        catch ( NoSuchScmProviderException e )
+        {
+            // TODO: this is not making it back into a result of any kind - log it at least.
Same is probably the case for ScmException
+            result = new ScmResult();
+
+            result.setSuccess( false );
+
+            result.setProviderMessage( e.getMessage() );
+
+            getLogger().error( e.getMessage(), e );
+        }
+        catch ( ScmException e )
+        {
+            result = new ScmResult();
+
+            result.setSuccess( false );
+
+            result.setException( ContinuumUtils.throwableMessagesToString( e ) );
+
+            getLogger().error( e.getMessage(), e );
+        }
+        catch ( Throwable t )
+        {
+            // TODO: do we want this here, or should it be to the logs?
+            // TODO: what throwables do we really get here that we can cope with?
+            result = new ScmResult();
+
+            result.setSuccess( false );
+
+            result.setException( ContinuumUtils.throwableMessagesToString( t ) );
+
+            getLogger().error( t.getMessage(), t );
+        }
+
+        context.put( ContinuumBuildAgentUtil.KEY_CHECKOUT_SCM_RESULT, result );
+    }
+
+    private ContinuumScmConfiguration createScmConfiguration( Project project, File workingDirectory,
+                                                              String scmUserName, String
scmPassword )
+    {
+        ContinuumScmConfiguration config = new ContinuumScmConfiguration();
+        config.setUrl( project.getScmUrl() );
+        config.setUsername( scmUserName );
+        config.setPassword( scmPassword );
+        config.setUseCredentialsCache( project.isScmUseCache() );
+        config.setWorkingDirectory( workingDirectory );
+        config.setTag( project.getScmTag() );
+        return config;
+    }
+
+    private ScmResult convertScmResult( CheckOutScmResult scmResult )
+    {
+        ScmResult result = new ScmResult();
+
+        result.setSuccess( scmResult.isSuccess() );
+
+        result.setCommandLine( maskPassword( scmResult.getCommandLine() ) );
+
+        result.setCommandOutput( scmResult.getCommandOutput() );
+
+        result.setProviderMessage( scmResult.getProviderMessage() );
+
+        return result;
+    }
+
+    // TODO: migrate to the SvnCommandLineUtils version (preferably properly encapsulated
in the provider)
+    private String maskPassword( String commandLine )
+    {
+        String cmd = commandLine;
+
+        if ( cmd != null && cmd.startsWith( "svn" ) )
+        {
+            String pwdString = "--password";
+
+            if ( cmd.indexOf( pwdString ) > 0 )
+            {
+                int index = cmd.indexOf( pwdString ) + pwdString.length() + 1;
+
+                int nextSpace = cmd.indexOf( " ", index );
+
+                cmd = cmd.substring( 0, index ) + "********" + cmd.substring( nextSpace );
+            }
+        }
+
+        return cmd;
+    }
+
+    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( (String) i.next() );
+
+                if ( i.hasNext() )
+                {
+                    message.append( System.getProperty( "line.separator" ) );
+                }
+            }
+        }
+        return message.toString();
+    }
+}

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

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.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/action/CleanWorkingDirectory.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CleanWorkingDirectory.java?rev=726475&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CleanWorkingDirectory.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/action/CleanWorkingDirectory.java
Sun Dec 14 07:35:09 2008
@@ -0,0 +1,42 @@
+package org.apache.continuum.buildagent.action;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.continuum.buildagent.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.shared.model.fileset.FileSet;
+import org.apache.maven.shared.model.fileset.util.FileSetManager;
+import org.codehaus.plexus.action.AbstractAction;
+
+/**
+ * @plexus.component role="" role-hint="clean-agent-working-directory"
+ */
+public class CleanWorkingDirectory
+    extends AbstractAction
+{
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    public void execute( Map context )
+        throws Exception
+    {
+        Project project = ContinuumBuildAgentUtil.getProject( context );
+    
+        File workingDirectory = configurationService.getWorkingDirectory( project.getId()
);
+    
+        if ( workingDirectory.exists() )
+        {
+            FileSetManager fileSetManager = new FileSetManager();
+            FileSet fileSet = new FileSet();
+            fileSet.setDirectory( workingDirectory.getPath() );
+            fileSet.addInclude( "**/**" );
+            // TODO : this with a configuration option somewhere ?
+            fileSet.setFollowSymlinks( false );
+            fileSetManager.delete( fileSet );
+        }
+    }
+}

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

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

Modified: 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=726475&r1=726474&r2=726475&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/model/BuildContext.java
Sun Dec 14 07:35:09 2008
@@ -1,5 +1,10 @@
 package org.apache.continuum.buildagent.model;
 
+import java.util.Map;
+
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.scm.ScmResult;
+
 public class BuildContext
 {
     private int projectId;
@@ -28,6 +33,12 @@
 
     private String scmRootAddress;
 
+    private Map<String, Object> actionContext;
+
+    private ScmResult scmResult;
+
+    private BuildResult buildResult;
+
     public int getProjectGroupId()
     {
         return projectGroupId;
@@ -157,4 +168,34 @@
     {
         this.buildFresh = buildFresh;
     }
+
+    public Map<String, Object> getActionContext()
+    {
+        return actionContext;
+    }
+
+    public void setActionContext( Map<String, Object> actionContext ) 
+    {
+        this.actionContext = actionContext;
+    }
+
+    public ScmResult getScmResult()
+    {
+        return scmResult;
+    }
+
+    public void setScmResult( ScmResult scmResult )
+    {
+        this.scmResult = scmResult;
+    }
+
+    public BuildResult getBuildResult()
+    {
+        return buildResult;
+    }
+
+    public void setBuildResult( BuildResult buildResult )
+    {
+        this.buildResult = buildResult;
+    }
 }

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/PrepareBuildTaskExecutor.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/execution/PrepareBuildTaskExecutor.java?rev=726475&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/PrepareBuildTaskExecutor.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/PrepareBuildTaskExecutor.java
Sun Dec 14 07:35:09 2008
@@ -0,0 +1,342 @@
+package org.apache.continuum.buildagent.taskqueue.execution;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager;
+import org.apache.continuum.buildagent.configuration.ConfigurationService;
+import org.apache.continuum.buildagent.model.BuildContext;
+import org.apache.continuum.buildagent.transportclient.MasterAgentTransportClient;
+import org.apache.continuum.buildagent.utils.BuildContextToBuildDefinition;
+import org.apache.continuum.buildagent.utils.BuildContextToProject;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
+import org.apache.continuum.utils.ContinuumUtils;
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.codehaus.plexus.action.ActionManager;
+import org.codehaus.plexus.action.ActionNotFoundException;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Maria Catherine Tan
+ * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" role-hint="prepare-build-agent"
+ */
+public class PrepareBuildTaskExecutor
+    implements TaskExecutor
+{
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
+    /**
+     * @plexus.requirement
+     */
+    private ActionManager actionManager;
+    
+    /**
+     * @plexus.requirement
+     */
+    private BuildContextManager buildContextManager;
+
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationService configurationService;
+
+    /**
+     * @plexus.requirement
+     */
+    private MasterAgentTransportClient transportClient;
+
+    // do we still need a queue for this?
+    public void executeTask( Task task )
+        throws TaskExecutionException
+    {
+        List<BuildContext> buildContexts = buildContextManager.getBuildContextList();
+
+        Map<String, Object> context = null;
+
+        try
+        {
+            for ( BuildContext buildContext : buildContexts )
+            {
+                BuildDefinition buildDef = BuildContextToBuildDefinition.getBuildDefinition(
buildContext );
+    
+                log.info( "Check scm root state" );
+                if ( !checkProjectScmRoot( buildContext ) )
+                {
+                    break;
+                }
+                
+                log.info( "Initializing prepare build" );
+                initializeActionContext( buildContext );
+                
+                log.info( "Starting prepare build" );
+                context = buildContext.getActionContext();
+
+                try
+                {
+                    if ( buildDef.isBuildFresh() )
+                    {
+                        log.info( "Clean up working directory" );
+                        cleanWorkingDirectory( buildContext );
+                    }
+        
+                    log.info( "Updating working directory" );
+                    updateWorkingDirectory( buildContext );
+                }
+                finally
+                {
+                    endProjectPrepareBuild( buildContext );
+                }
+            }
+        }
+        finally
+        {
+            endPrepareBuild( context );
+        }
+
+        
+    }
+
+    private void initializeActionContext( BuildContext buildContext )
+    {
+        Map<String, Object> actionContext = new HashMap<String, Object>();
+
+        actionContext.put( ContinuumBuildAgentUtil.KEY_PROJECT_ID, buildContext.getProjectId()
);
+        actionContext.put( ContinuumBuildAgentUtil.KEY_PROJECT, BuildContextToProject.getProject(
buildContext ) );
+        actionContext.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION, BuildContextToBuildDefinition.getBuildDefinition(
buildContext ) );
+        actionContext.put( ContinuumBuildAgentUtil.KEY_SCM_ROOT_STATE, ContinuumProjectState.UPDATING
);
+        actionContext.put( ContinuumBuildAgentUtil.KEY_PROJECT_GROUP_ID, buildContext.getProjectGroupId()
);
+        actionContext.put( ContinuumBuildAgentUtil.KEY_SCM_ROOT_ADDRESS, buildContext.getScmRootAddress()
);
+        
+        buildContext.setActionContext( actionContext );
+    }
+
+    private boolean checkProjectScmRoot( BuildContext buildContext )
+    {
+        if ( buildContext.getActionContext() != null && 
+             ContinuumBuildAgentUtil.getScmRootState( buildContext.getActionContext() ) ==
ContinuumProjectState.ERROR )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    private void cleanWorkingDirectory( BuildContext buildContext )
+        throws TaskExecutionException
+    {
+        performAction( "clean-agent-work-directory", buildContext );
+    }
+
+    private void updateWorkingDirectory( BuildContext buildContext )
+        throws TaskExecutionException
+    {
+        Map<String, Object> actionContext = buildContext.getActionContext();
+
+        performAction( "check-agent-working-directory", buildContext );
+        
+        boolean workingDirectoryExists =
+            ContinuumBuildAgentUtil.getBoolean( actionContext, ContinuumBuildAgentUtil.KEY_WORKING_DIRECTORY_EXISTS
);
+    
+        ScmResult scmResult;
+    
+        if ( workingDirectoryExists )
+        {
+            performAction( "update-agent-working-directory", buildContext );
+    
+            scmResult = ContinuumBuildAgentUtil.getUpdateScmResult( actionContext, null );
+        }
+        else
+        {
+            Project project = ContinuumBuildAgentUtil.getProject( actionContext );
+    
+            actionContext.put( ContinuumBuildAgentUtil.KEY_WORKING_DIRECTORY,
+                               configurationService.getWorkingDirectory( project.getId()
).getAbsolutePath() );
+    
+            performAction( "checkout-project", buildContext );
+    
+            scmResult = ContinuumBuildAgentUtil.getCheckoutScmResult( actionContext, null
);
+        }
+    
+        buildContext.setScmResult( scmResult );
+        actionContext.put( ContinuumBuildAgentUtil.KEY_SCM_RESULT, scmResult );
+    }
+
+    private void endProjectPrepareBuild( BuildContext buildContext )
+        throws TaskExecutionException
+    {
+        Map<String, Object> context = buildContext.getActionContext();
+
+        ScmResult scmResult = ContinuumBuildAgentUtil.getScmResult( context, null );
+        Project project = ContinuumBuildAgentUtil.getProject( context );
+
+        if ( scmResult == null || !scmResult.isSuccess() )
+        {
+            context.put( ContinuumBuildAgentUtil.KEY_SCM_ROOT_STATE, ContinuumProjectState.ERROR
);
+        }
+
+        try
+        {
+            transportClient.returnScmResult( createScmResult( buildContext ) );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Failed to return scm result", e );
+            throw new TaskExecutionException( "Failed to return scm result", e );
+        }
+    }
+
+    private void endPrepareBuild( Map context )
+        throws TaskExecutionException
+    {
+        Map<String, Object> result = new HashMap<String, Object>();
+        result.put( ContinuumBuildAgentUtil.KEY_PROJECT_GROUP_ID, new Integer( ContinuumBuildAgentUtil.getProjectGroupId(
context ) ) );
+        result.put( ContinuumBuildAgentUtil.KEY_SCM_ROOT_ADDRESS, ContinuumBuildAgentUtil.getScmRootAddress(
context ) );
+        
+        String error = convertScmResultToError( ContinuumBuildAgentUtil.getScmResult( context,
null ) );
+        if ( StringUtils.isEmpty( error ) )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_ERROR, "" );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_ERROR, error );
+        }
+
+        try
+        {
+            transportClient.prepareBuildFinished( result );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Failed to finish prepare build", e );
+            throw new TaskExecutionException( "Failed to finish prepare build", e );
+        }
+    }
+
+    private Map<String, Object> createScmResult( BuildContext buildContext )
+    {
+        Map<String, Object> result = new HashMap<String, Object>();
+        ScmResult scmResult = buildContext.getScmResult();
+
+        result.put( ContinuumBuildAgentUtil.KEY_PROJECT_ID, new Integer( buildContext.getProjectId()
) );
+        if ( StringUtils.isEmpty( scmResult.getCommandLine() ) )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_COMMAND_LINE, "" );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_COMMAND_LINE, scmResult.getCommandLine()
);
+        }
+        if ( StringUtils.isEmpty( scmResult.getCommandOutput() ) )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_COMMAND_OUTPUT, "" );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_COMMAND_OUTPUT, scmResult.getCommandOutput()
);
+        }
+        if ( StringUtils.isEmpty( scmResult.getProviderMessage() ) )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_PROVIDER_MESSAGE, "" );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_PROVIDER_MESSAGE, scmResult.getProviderMessage()
);
+        }
+        if ( StringUtils.isEmpty( scmResult.getException() ) )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_EXCEPTION, "" );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_SCM_EXCEPTION, scmResult.getException()
);
+        }
+        result.put( ContinuumBuildAgentUtil.KEY_SCM_SUCCESS, new Boolean( scmResult.isSuccess()
) );
+        
+        return result;
+    }
+
+    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 performAction( String actionName, BuildContext buildContext )
+        throws TaskExecutionException
+    {
+        TaskExecutionException exception = null;
+    
+        try
+        {
+            log.info( "Performing action " + actionName );
+            actionManager.lookup( actionName ).execute( buildContext.getActionContext() );
+            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 ) );
+
+        buildContext.setScmResult( result );
+        buildContext.getActionContext().put( ContinuumBuildAgentUtil.KEY_UPDATE_SCM_RESULT,
result );
+        
+        throw exception;
+    }
+}

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

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/PrepareBuildTaskExecutor.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/utils/BuildContextToBuildDefinition.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToBuildDefinition.java?rev=726475&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToBuildDefinition.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToBuildDefinition.java
Sun Dec 14 07:35:09 2008
@@ -0,0 +1,27 @@
+package org.apache.continuum.buildagent.utils;
+
+import org.apache.continuum.buildagent.model.BuildContext;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class BuildContextToBuildDefinition
+{
+    public static BuildDefinition getBuildDefinition( BuildContext buildContext )
+    {
+        BuildDefinition buildDefinition = new BuildDefinition();
+
+        buildDefinition.setAlwaysBuild( true );
+
+        buildDefinition.setArguments( buildContext.getArguments() );
+
+        buildDefinition.setBuildFile( buildContext.getBuildFile() );
+
+        buildDefinition.setBuildFresh( buildContext.isBuildFresh() );
+
+        buildDefinition.setGoals( buildContext.getGoals() );
+
+        return buildDefinition;
+    }
+}

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

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

Copied: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
(from r725955, 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/utils/ContinuumBuildAgentUtil.java?p2=continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java&p1=continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java&r1=725955&r2=726475&rev=726475&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
Sun Dec 14 07:35:09 2008
@@ -1,9 +1,12 @@
-package org.apache.continuum.buildagent;
+package org.apache.continuum.buildagent.utils;
 
 import java.util.Map;
 
-public abstract class AbstractContinuumBuildAgentService
-    implements ContinuumBuildAgentService
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ScmResult;
+
+public class ContinuumBuildAgentUtil
 {
     public static final String KEY_PROJECT_ID = "project-id";
 
@@ -51,6 +54,26 @@
 
     public static final String KEY_SCM_ROOT_ADDRESS = "scm-root-address";
 
+    public static final String KEY_SCM_ROOT_STATE = "scm-root-state";
+
+    public static final String KEY_CHECKOUT_SCM_RESULT = "checkout-scm-result";
+
+    public static final String KEY_UPDATE_SCM_RESULT = "update-scm-result";
+
+    public static final String KEY_WORKING_DIRECTORY_EXISTS = "working-directory-exists";
+
+    public static final String KEY_PROJECT = "project";
+
+    public static final String KEY_BUILD_DEFINITION = "build-definition";
+
+    public static final String KEY_SCM_RESULT = "scm-result";
+
+    public static final String KEY_WORKING_DIRECTORY = "working-directory";
+
+    public static final String KEY_SCM_SUCCESS = "scm-success";
+
+    public static final String KEY_SCM_ERROR = "scm-error";
+
     public static Integer getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
@@ -111,31 +134,60 @@
         return getString( context, KEY_SCM_ROOT_ADDRESS );
     }
 
+    public static int getScmRootState( Map context )
+    {
+        return getInteger( context, KEY_SCM_ROOT_STATE );
+    }
+
+    public static Project getProject( Map context )
+    {
+        return (Project) getObject( context, KEY_PROJECT );
+    }
+
+    public static BuildDefinition getBuildDefinition( Map context )
+    {
+        return (BuildDefinition) getObject( context, KEY_BUILD_DEFINITION );
+    }
+
+    public static ScmResult getCheckoutScmResult( Map context, Object defaultValue )
+    {
+        return (ScmResult) getObject( context, KEY_CHECKOUT_SCM_RESULT, defaultValue );
+    }
+
+    public static ScmResult getUpdateScmResult( Map context, Object defaultValue )
+    {
+        return (ScmResult) getObject( context, KEY_UPDATE_SCM_RESULT, defaultValue );
+    }
+
+    public static ScmResult getScmResult( Map context, Object defaultValue )
+    {
+        return (ScmResult) getObject( context, KEY_SCM_RESULT );
+    }
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
 
-    protected static String getString( Map context, String key )
+    public static String getString( Map context, String key )
     {
         return (String) getObject( context, key );
     }
 
-    protected static String getString( Map context, String key, String defaultValue )
+    public static String getString( Map context, String key, String defaultValue )
     {
         return (String) getObject( context, key, defaultValue );
     }
 
-    protected static boolean getBoolean( Map context, String key )
+    public static boolean getBoolean( Map context, String key )
     {
         return ( (Boolean) getObject( context, key ) ).booleanValue();
     }
     
-    protected static boolean getBoolean( Map context, String key, boolean defaultValue )
+    public 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 )
+    public static int getInteger( Map context, String key )
     {
         Object obj = getObject( context, key, null );
         

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sun Dec 14 07:35:09 2008
@@ -0,0 +1,2 @@
+/continuum/branches/continuum-1.2.x/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java:690684,690689-690799,698449-698533,698817-698819,699529,700250,700273,700936,705894,705910,708339,722279,722624,723119,723487,724016,724024
+/continuum/trunk/continuum-distributed-build/continuum-buildagent/src/main/java/org/apache/continuum/buildagent/AbstractContinuumBuildAgentService.java:713270-724659



Mime
View raw message