continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r746856 - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/ continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ continuum-buildagent/continuum-buildag...
Date Mon, 23 Feb 2009 02:02:51 GMT
Author: ctan
Date: Mon Feb 23 02:02:50 2009
New Revision: 746856

URL: http://svn.apache.org/viewvc?rev=746856&view=rev
Log:
[CONTINUUM-2087] allow to view working copy from the build agent


Added:
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
  (with props)
Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/buildcontext/BuildContext.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
    continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
    continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java
    continuum/trunk/continuum-model/src/main/mdo/continuum.xml
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
Mon Feb 23 02:02:50 2009
@@ -68,4 +68,10 @@
         throws ContinuumException;
 
     boolean shouldBuild( Map context );
+
+    String generateWorkingCopyContent( int projectId, String directory, String baseUrl, String
imagesBaseUrl )
+        throws ContinuumException;
+
+    String getFileContent( int projectId, String directory, String filename )
+        throws ContinuumException;
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentService.java
Mon Feb 23 02:02:50 2009
@@ -38,4 +38,10 @@
     
     void cancelBuild()
         throws ContinuumBuildAgentException;
+
+    String generateWorkingCopyContent( int projectId, String userDirectory, String baseUrl,
String imagesBaseUrl )
+        throws ContinuumBuildAgentException;
+
+    String getProjectFileContent( int projectId, String directory, String filename )
+        throws ContinuumBuildAgentException;
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
Mon Feb 23 02:02:50 2009
@@ -20,10 +20,13 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
@@ -33,6 +36,7 @@
 import org.apache.continuum.buildagent.model.Installation;
 import org.apache.continuum.buildagent.taskqueue.manager.BuildAgentTaskQueueManager;
 import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
+import org.apache.continuum.buildagent.utils.WorkingCopyContentGenerator;
 import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.model.project.BuildResult;
@@ -73,6 +77,11 @@
      */
     private BuildContextManager buildContextManager;
 
+    /**
+     * @plexus.requirement
+     */
+    private WorkingCopyContentGenerator generator;
+
     public void buildProjects( List<Map> projectsBuildContext )
         throws ContinuumBuildAgentException
     {
@@ -230,6 +239,51 @@
         }
     }
 
+    public String generateWorkingCopyContent( int projectId, String userDirectory, String
baseUrl, String imagesBaseUrl )
+        throws ContinuumBuildAgentException
+    {
+        File workingDirectory = buildAgentConfigurationService.getWorkingDirectory( projectId
);
+
+        try
+        {
+            List<File> files = ContinuumBuildAgentUtil.getFiles( userDirectory, workingDirectory
);
+            return generator.generate( files, baseUrl, imagesBaseUrl, workingDirectory );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Failed to generate working copy content", e );
+        }
+            
+        return "";
+    }
+
+    public String getProjectFileContent( int projectId, String directory, String filename
)
+        throws ContinuumBuildAgentException
+    {
+        String relativePath = "\\.\\./"; // prevent users from using relative paths.
+        Pattern pattern = Pattern.compile( relativePath );
+        Matcher matcher = pattern.matcher( directory );
+        String filteredDirectory = matcher.replaceAll( "" );
+
+        matcher = pattern.matcher( filename );
+        String filteredFilename = matcher.replaceAll( "" );
+
+        File workingDirectory = buildAgentConfigurationService.getWorkingDirectory( projectId
);
+
+        File fileDirectory = new File( workingDirectory, filteredDirectory );
+
+        File userFile = new File( fileDirectory, filteredFilename );
+
+        try
+        {
+            return FileUtils.fileRead( userFile );
+        }
+        catch ( IOException e )
+        {
+            throw new ContinuumBuildAgentException( "Can't read file " + filename, e );
+        }
+    }
+
     private List<BuildContext> initializeBuildContext( List<Map> projectsBuildContext
)
     {
         List<BuildContext> buildContext = new ArrayList<BuildContext>();
@@ -258,6 +312,7 @@
             context.setBuildNumber( ContinuumBuildAgentUtil.getBuildNumber( map ) );
             context.setOldScmResult( getScmResult( ContinuumBuildAgentUtil.getOldScmChanges(
map ) ) );
             context.setLatestUpdateDate( ContinuumBuildAgentUtil.getLatestUpdateDate( map
) );
+            context.setBuildAgentUrl( ContinuumBuildAgentUtil.getBuildAgentUrl( map ) );
 
             buildContext.add( context );
         }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/buildcontext/BuildContext.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/buildcontext/BuildContext.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/buildcontext/BuildContext.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/buildcontext/BuildContext.java
Mon Feb 23 02:02:50 2009
@@ -77,6 +77,8 @@
 
     private Date latestUpdateDate;
 
+    private String buildAgentUrl;
+
     public int getProjectGroupId()
     {
         return projectGroupId;
@@ -326,4 +328,14 @@
     {
         return latestUpdateDate;
     }
+
+    public void setBuildAgentUrl( String buildAgentUrl )
+    {
+        this.buildAgentUrl = buildAgentUrl;
+    }
+
+    public String getBuildAgentUrl()
+    {
+        return buildAgentUrl;
+    }
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
Mon Feb 23 02:02:50 2009
@@ -238,6 +238,7 @@
         }
 
         result.put( ContinuumBuildAgentUtil.KEY_SCM_RESULT, ContinuumBuildAgentUtil.createScmResult(
buildContext ) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_AGENT_URL, buildContext.getBuildAgentUrl()
);
 
         try
         {

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
Mon Feb 23 02:02:50 2009
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.ArrayList;
@@ -28,6 +29,7 @@
 import java.util.Map;
 
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
+import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
@@ -202,6 +204,8 @@
 
     public static final String KEY_LATEST_UPDATE_DATE = "latest-update-date";
 
+    public static final String KEY_BUILD_AGENT_URL = "build-agent-url";
+
     public static Integer getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
@@ -401,6 +405,11 @@
         return getDate( context, KEY_LATEST_UPDATE_DATE );
     }
 
+    public static String getBuildAgentUrl( Map context )
+    {
+        return getString( context, KEY_BUILD_AGENT_URL );
+    }
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -679,4 +688,60 @@
 
         return files;
     }
+
+    public static List<File> getFiles( String userDirectory, File workingDirectory
)
+        throws ContinuumException
+    {
+        return getFiles( workingDirectory, null, userDirectory );
+    }
+
+    private static List<File> getFiles( File baseDirectory, String currentSubDirectory,
String userDirectory )
+    {
+        List<File> dirs = new ArrayList<File>();
+
+        File workingDirectory;
+
+        if ( currentSubDirectory != null )
+        {
+            workingDirectory = new File( baseDirectory, currentSubDirectory );
+        }
+        else
+        {
+            workingDirectory = baseDirectory;
+        }
+
+        String[] files = workingDirectory.list();
+
+        if ( files != null )
+        {
+            for ( String file : files )
+            {
+                File current = new File( workingDirectory, file );
+
+                String currentFile;
+
+                if ( currentSubDirectory == null )
+                {
+                    currentFile = file;
+                }
+                else
+                {
+                    currentFile = currentSubDirectory + "/" + file;
+                }
+
+                if ( userDirectory != null && current.isDirectory() && userDirectory.startsWith(
currentFile ) )
+                {
+                    dirs.add( current );
+
+                    dirs.addAll( getFiles( baseDirectory, currentFile, userDirectory ) );
+                }
+                else
+                {
+                    dirs.add( current );
+                }
+            }
+        }
+
+        return dirs;
+    }
 }
\ No newline at end of file

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java?rev=746856&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
(added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
Mon Feb 23 02:02:50 2009
@@ -0,0 +1,184 @@
+package org.apache.continuum.buildagent.utils;
+
+import java.io.File;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @plexus.component role="org.apache.continuum.buildagent.utils.WorkingCopyContentGenerator"
+ */
+public class WorkingCopyContentGenerator
+{
+    private File basedir;
+
+    private String urlParamSeparator;
+
+    private static DecimalFormat decFormatter = new DecimalFormat( "###.##" );
+
+    private static final long KILO = 1024;
+
+    private static final long MEGA = 1024 * KILO;
+
+    private static final long GIGA = 1024 * MEGA;
+
+    private boolean odd = false;
+
+    public String generate( List<File> files, String baseUrl, String imagesBaseUrl,
File basedir )
+    {
+        this.basedir = basedir;
+        if ( baseUrl.indexOf( "?" ) > 0 )
+        {
+            urlParamSeparator = "&";
+        }
+        else
+        {
+            urlParamSeparator = "?";
+        }
+
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( "<div class=\"eXtremeTable\" >" );
+        buf.append( "<table class=\"tableRegion\" width=\"100%\">\n" );
+
+        buf.append( "<tr class=\"odd\"><td><img src=\"" ).append( imagesBaseUrl
).append(
+            "icon_arrowfolder1_sml.gif\">&nbsp;<a href=\"" ).append( baseUrl ).append(
urlParamSeparator ).append(
+            "userDirectory=/\">/</a><br /></td><td>&nbsp;</td><td>&nbsp;</td>"
);
+
+        print( basedir, files, baseUrl, imagesBaseUrl, buf );
+
+        buf.append( "</table>\n" );
+        buf.append( "</div>\n" );
+
+        return buf.toString();
+    }
+
+    private void print( File basedir, List<File> files, String baseUrl, String imagesBaseUrl,
StringBuffer buf )
+    {
+        for ( File f : files )
+        {
+            print( f, getIndent( basedir, f ), baseUrl, imagesBaseUrl, buf );
+        }
+    }
+
+    private void print( File f, String indent, String baseUrl, String imagesBaseUrl, StringBuffer
buf )
+    {
+        String cssClass = odd ? "odd" : "even";
+
+        if ( !f.isDirectory() )
+        {
+            String fileName = f.getName();
+
+            if ( !".cvsignore".equals( fileName ) && !"vssver.scc".equals( fileName
) &&
+                !".DS_Store".equals( fileName ) && !"release.properties".equals(
fileName ) )
+            {
+                String userDirectory;
+
+                if ( f.getParentFile().getAbsolutePath().equals( basedir.getAbsolutePath()
) )
+                {
+                    userDirectory = "/";
+                }
+                else
+                {
+                    userDirectory =
+                        f.getParentFile().getAbsolutePath().substring( basedir.getAbsolutePath().length()
+ 1 );
+                }
+
+                userDirectory = StringUtils.replace( userDirectory, "\\", "/" );
+
+                buf.append( "<tr class=\"" ).append( cssClass ).append( "\">" );
+
+                buf.append( "<td width=\"98%\">" ).append( indent ).append( "&nbsp;&nbsp;<img
src=\"" ).append(
+                    imagesBaseUrl ).append( "file.gif\">&nbsp;<a href=\"" ).append(
baseUrl ).append(
+                    urlParamSeparator ).append( "userDirectory=" ).append( userDirectory
).append( "&file=" ).append(
+                    fileName ).append( "\">" ).append( fileName ).append( "</a></td><td
width=\"1%\">" ).append(
+                    getReadableFileSize( f.length() ) ).append( "</td><td width=\"1%\">"
).append(
+                    getFormattedDate( f.lastModified() ) ).append( "</td>\n" );
+                buf.append( "</tr>\n" );
+
+                odd = !odd;
+            }
+        }
+        else
+        {
+            String directoryName = f.getName();
+
+            if ( !"CVS".equals( directoryName ) && !".svn".equals( directoryName
) && !"SCCS".equals( directoryName ) )
+            {
+                String userDirectory = f.getAbsolutePath().substring( basedir.getAbsolutePath().length()
+ 1 );
+
+                userDirectory = StringUtils.replace( userDirectory, "\\", "/" );
+
+                buf.append( "<tr class=\"" ).append( cssClass ).append( "\">" );
+
+                buf.append( "<td width=\"98%\">" ).append( indent ).append( "<img
src=\"" ).append(
+                    imagesBaseUrl ).append( "icon_arrowfolder1_sml.gif\">&nbsp;<a
href =\"" ).append( baseUrl ).append(
+                    urlParamSeparator ).append( "userDirectory=" ).append( userDirectory
).append( "\">" ).append(
+                    directoryName ).append( "</a></td><td width=\"1%\">"
+ "&nbsp;" + "</td><td width=\"1%\">" ).append(
+                    getFormattedDate( f.lastModified() ) ).append( "</td>" );
+                buf.append( "</tr>\n" );
+
+                odd = !odd;
+            }
+        }
+    }
+
+    private String getFormattedDate( long timestamp )
+    {
+        Calendar cal = Calendar.getInstance();
+        cal.setTimeInMillis( timestamp );
+        Date date = cal.getTime();
+        String res = new SimpleDateFormat( "MMM dd, yyyy hh:mm:ss aaa z" ).format( date );
+        return StringUtils.replace( res, " ", "&nbsp;" );
+    }
+
+    private static String getReadableFileSize( long fileSizeInBytes )
+    {
+        if ( fileSizeInBytes >= GIGA )
+        {
+            return decFormatter.format( fileSizeInBytes / GIGA ) + "&nbsp;Gb";
+        }
+        else if ( fileSizeInBytes >= MEGA )
+        {
+            return decFormatter.format( fileSizeInBytes / MEGA ) + "&nbsp;Mb";
+        }
+        else if ( fileSizeInBytes >= KILO )
+        {
+            return decFormatter.format( fileSizeInBytes / KILO ) + "&nbsp;Kb";
+        }
+        else if ( fileSizeInBytes > 0 && fileSizeInBytes < KILO )
+        {
+            return decFormatter.format( fileSizeInBytes ) + "&nbsp;b";
+        }
+
+        return "0&nbsp;b";
+    }
+
+    private String getIndent( File basedir, File userFile )
+    {
+        String root = basedir.getAbsolutePath();
+        String userdir;
+        if ( userFile.isDirectory() )
+        {
+            userdir = userFile.getAbsolutePath();
+        }
+        else
+        {
+            userdir = userFile.getParentFile().getAbsolutePath();
+        }
+
+        userdir = userdir.substring( root.length() );
+
+        StringBuffer indent = new StringBuffer();
+        while ( userdir.indexOf( File.separator ) >= 0 )
+        {
+            indent.append( "&nbsp;&nbsp;" );
+            userdir = userdir.substring( userdir.indexOf( File.separator ) + 1 );
+        }
+        return indent.toString();
+    }
+}

Propchange: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/WorkingCopyContentGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
(original)
+++ continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
Mon Feb 23 02:02:50 2009
@@ -218,6 +218,7 @@
                 context.put( ContinuumBuildConstant.KEY_BUILD_FRESH, new Boolean( buildDef.isBuildFresh()
) );
                 context.put( ContinuumBuildConstant.KEY_ALWAYS_BUILD, new Boolean( buildDef.isAlwaysBuild()
) );
                 context.put( ContinuumBuildConstant.KEY_OLD_SCM_CHANGES, getOldScmChanges(
project.getId(), buildDefinitionId ) );
+                context.put( ContinuumBuildConstant.KEY_BUILD_AGENT_URL, buildAgentUrl );
 
                 buildContext.add( context );
             }

Modified: continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
(original)
+++ continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
Mon Feb 23 02:02:50 2009
@@ -174,6 +174,8 @@
 
     public static final String KEY_LATEST_UPDATE_DATE = "latest-update-date";
 
+    public static final String KEY_BUILD_AGENT_URL = "build-agent-url";
+
     public static int getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
@@ -478,6 +480,12 @@
     {
         return getDate( context, KEY_LATEST_UPDATE_DATE );
     }
+
+    public static String getBuildAgentUrl( Map context )
+    {
+        return getString( context, KEY_BUILD_AGENT_URL );
+    }
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
Mon Feb 23 02:02:50 2009
@@ -679,6 +679,72 @@
         }
     }
 
+    public String generateWorkingCopyContent( int projectId, String directory, String baseUrl,
String imageBaseUrl )
+        throws ContinuumException
+    {
+        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId
);
+
+        if ( buildResult != null )
+        {
+            String buildAgentUrl = buildResult.getBuildUrl();
+
+            if ( buildAgentUrl == null )
+            {
+                return "";
+            }
+
+            try
+            {
+                if ( directory == null )
+                {
+                    directory = "";
+                }
+
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient(
new URL( buildAgentUrl ) );
+                return client.generateWorkingCopyContent( projectId, directory, baseUrl,
imageBaseUrl );
+            }
+            catch ( MalformedURLException e )
+            {
+                log.error( "Invalid build agent url " + buildAgentUrl );
+            }
+            catch ( Exception e )
+            {
+                log.error( "Error while generating working copy content from build agent
" + buildAgentUrl, e );
+            }
+        }
+        return "";
+    }
+
+    public String getFileContent( int projectId, String directory, String filename )
+        throws ContinuumException
+    {
+        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId
);
+
+        if ( buildResult != null )
+        {
+            String buildAgentUrl = buildResult.getBuildUrl();
+
+            if ( buildAgentUrl == null )
+            {
+                return "";
+            }
+
+            try
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient(
new URL( buildAgentUrl ) );
+                return client.getProjectFileContent( projectId, directory, filename );
+            }
+            catch ( MalformedURLException e )
+            {
+                log.error( "Invalid build agent url " + buildAgentUrl );
+            }
+            catch ( Exception e )
+            {
+                log.error( "Error while retrieving content of " + filename, e );
+            }
+        }
+        return "";
+    }
     public boolean shouldBuild( Map context )
     {
         try
@@ -1016,6 +1082,7 @@
         buildResult.setExitCode( ContinuumBuildConstant.getBuildExitCode( context ) );
         buildResult.setState( ContinuumBuildConstant.getBuildState( context ) );
         buildResult.setTrigger( ContinuumBuildConstant.getTrigger( context ) );
+        buildResult.setBuildUrl( ContinuumBuildConstant.getBuildAgentUrl( context ) );
 
         return buildResult;
     }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java
Mon Feb 23 02:02:50 2009
@@ -41,4 +41,10 @@
     public Boolean ping() throws Exception;
 
     public Boolean cancelBuild() throws Exception;
+
+    public String generateWorkingCopyContent( int projectId, String directory, String baseUrl,
String imagesBaseUrl )
+        throws Exception;
+
+    public String getProjectFileContent( int projectId, String directory, String filename
)
+        throws Exception;
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
Mon Feb 23 02:02:50 2009
@@ -175,6 +175,44 @@
             throw new Exception( "Error cancelling build", e );
         }
 
-        return null;
+        return result;
+    }
+
+    public String generateWorkingCopyContent( int projectId, String directory, String baseUrl,
String imagesBaseUrl )
+        throws Exception
+    {
+        String result = null;
+
+        try
+        {
+            result = slave.generateWorkingCopyContent( projectId, directory, baseUrl, imagesBaseUrl
);
+            log.info( "Generated working copy content" );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Error generating working copy content", e );
+            throw new Exception( "Error generating working copy content", e );
+        }
+
+        return result;
+    }
+
+    public String getProjectFileContent( int projectId, String directory, String filename
)
+        throws Exception
+    {
+        String result = null;
+
+        try
+        {
+            result = slave.getProjectFileContent( projectId, directory, filename );
+            log.info( "Retrived project file content" );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Error retrieving project file content", e );
+            throw new Exception( "Error retrieving project file content", e );
+        }
+
+        return result;
     }
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java
Mon Feb 23 02:02:50 2009
@@ -134,8 +134,37 @@
         catch ( ContinuumBuildAgentException e )
         {
             log.error( "Failed to cancel build", e );
+            throw e;
         }
 
         return result;
     }
+
+    public String generateWorkingCopyContent( int projectId, String directory, String baseUrl,
String imagesBaseUrl )
+        throws Exception
+    {
+        try
+        {
+            return continuumBuildAgentService.generateWorkingCopyContent( projectId, directory,
baseUrl, imagesBaseUrl );
+        }
+        catch ( ContinuumBuildAgentException e )
+        {
+           log.error( "Failed to generate working copy content", e );
+           throw e;
+        }
+    }
+
+    public String getProjectFileContent( int projectId, String directory, String filename
)
+        throws Exception
+    {
+        try
+        {
+            return continuumBuildAgentService.getProjectFileContent( projectId, directory,
filename );
+        }
+        catch ( ContinuumBuildAgentException e )
+        {
+            log.error( "Failed to retrieve project file content", e );
+            throw e;
+        }
+    }
 }

Modified: continuum/trunk/continuum-model/src/main/mdo/continuum.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-model/src/main/mdo/continuum.xml?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-model/src/main/mdo/continuum.xml (original)
+++ continuum/trunk/continuum-model/src/main/mdo/continuum.xml Mon Feb 23 02:02:50 2009
@@ -607,6 +607,11 @@
           <version>1.1.4+</version>
           <type>long</type>
         </field>
+        <field>
+          <name>buildUrl</name>
+          <version>1.1.4+</version>
+          <type>String</type>
+        </field>
       </fields>
       <codeSegments>
         <codeSegment>

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java?rev=746856&r1=746855&r2=746856&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
Mon Feb 23 02:02:50 2009
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import org.apache.continuum.builder.distributed.manager.DistributedBuildManager;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
@@ -48,6 +49,11 @@
      */
     private WorkingCopyContentGenerator generator;
 
+    /**
+     * @plexus.requirement
+     */
+    private DistributedBuildManager distributedBuildManager;
+
     private Project project;
 
     private int projectId;
@@ -87,8 +93,6 @@
             throw new ContinuumException( "release.properties is not accessible." );
         }
 
-        List<File> files = getContinuum().getFiles( projectId, userDirectory );
-
         project = getContinuum().getProject( projectId );
 
         projectName = project.getName();
@@ -107,41 +111,59 @@
 
         imagesBaseUrl = imagesBaseUrl.substring( 0, imagesBaseUrl.indexOf( "/images/" ) +
"/images/".length() );
 
-        output = generator.generate( files, baseUrl, imagesBaseUrl, getContinuum().getWorkingDirectory(
projectId ) );
-
-        if ( currentFile != null && !currentFile.equals( "" ) )
+        if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
         {
-            String dir;
-
-            //TODO: maybe create a plexus component for this so that additional mimetypes
can be easily added
-            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
-            mimeTypesMap.addMimeTypes( "application/java-archive jar war ear" );
-            mimeTypesMap.addMimeTypes( "application/java-class class" );
-            mimeTypesMap.addMimeTypes( "image/png png" );
+            output = distributedBuildManager.generateWorkingCopyContent( projectId, userDirectory,
baseUrl, imagesBaseUrl );
 
-            if ( FILE_SEPARATOR.equals( userDirectory ) )
+            if ( currentFile != null && !currentFile.equals( "" ) )
             {
-                dir = userDirectory;
+                currentFileContent = distributedBuildManager.getFileContent( projectId, userDirectory,
currentFile );
             }
             else
             {
-                dir = FILE_SEPARATOR + userDirectory + FILE_SEPARATOR;
-            }
-
-            downloadFile = new File( getContinuum().getWorkingDirectory( projectId ) + dir
+ currentFile );
-            mimeType = mimeTypesMap.getContentType( downloadFile );
-
-            if ( ( mimeType.indexOf( "image" ) >= 0 ) || ( mimeType.indexOf( "java-archive"
) >= 0 ) ||
-                ( mimeType.indexOf( "java-class" ) >= 0 ) || ( downloadFile.length() >
100000 ) )
-            {
-                return "stream";
+                currentFileContent = "";
             }
-
-            currentFileContent = getContinuum().getFileContent( projectId, userDirectory,
currentFile );
         }
         else
         {
-            currentFileContent = "";
+            List<File> files = getContinuum().getFiles( projectId, userDirectory );
+
+            output = generator.generate( files, baseUrl, imagesBaseUrl, getContinuum().getWorkingDirectory(
projectId ) );
+    
+            if ( currentFile != null && !currentFile.equals( "" ) )
+            {
+                String dir;
+    
+                //TODO: maybe create a plexus component for this so that additional mimetypes
can be easily added
+                MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
+                mimeTypesMap.addMimeTypes( "application/java-archive jar war ear" );
+                mimeTypesMap.addMimeTypes( "application/java-class class" );
+                mimeTypesMap.addMimeTypes( "image/png png" );
+    
+                if ( FILE_SEPARATOR.equals( userDirectory ) )
+                {
+                    dir = userDirectory;
+                }
+                else
+                {
+                    dir = FILE_SEPARATOR + userDirectory + FILE_SEPARATOR;
+                }
+    
+                downloadFile = new File( getContinuum().getWorkingDirectory( projectId )
+ dir + currentFile );
+                mimeType = mimeTypesMap.getContentType( downloadFile );
+    
+                if ( ( mimeType.indexOf( "image" ) >= 0 ) || ( mimeType.indexOf( "java-archive"
) >= 0 ) ||
+                    ( mimeType.indexOf( "java-class" ) >= 0 ) || ( downloadFile.length()
> 100000 ) )
+                {
+                    return "stream";
+                }
+    
+                currentFileContent = getContinuum().getFileContent( projectId, userDirectory,
currentFile );
+            }
+            else
+            {
+                currentFileContent = "";
+            }
         }
 
         return SUCCESS;



Mime
View raw message