continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1236050 - 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-builda...
Date Thu, 26 Jan 2012 06:51:21 GMT
Author: ctan
Date: Thu Jan 26 06:51:21 2012
New Revision: 1236050

URL: http://svn.apache.org/viewvc?rev=1236050&view=rev
Log:
[CONTINUUM-2384] support downloading of file from a working copy with distributed builds

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-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/stubs/SlaveBuildAgentTransportClientStub.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-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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -69,7 +69,7 @@ public interface DistributedBuildManager
     String generateWorkingCopyContent( int projectId, String directory, String baseUrl, String
imagesBaseUrl )
         throws ContinuumException;
 
-    String getFileContent( int projectId, String directory, String filename )
+    Map<String, Object> getFileContent( int projectId, String directory, String filename
)
         throws ContinuumException;
 
     void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, BuildTrigger
buildTrigger, int projectGroupId,  

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -43,7 +43,7 @@ public interface ContinuumBuildAgentServ
     String generateWorkingCopyContent( int projectId, String userDirectory, String baseUrl,
String imagesBaseUrl )
         throws ContinuumBuildAgentException;
 
-    String getProjectFileContent( int projectId, String directory, String filename )
+    Map<String, Object> getProjectFile( int projectId, String directory, String filename
)
         throws ContinuumBuildAgentException;
 
     Map<String, Object> getReleasePluginParameters( int projectId, String pomFilename
)

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -20,7 +20,10 @@ package org.apache.continuum.buildagent;
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -30,6 +33,9 @@ import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.activation.MimetypesFileTypeMap;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
@@ -56,7 +62,6 @@ import org.apache.maven.continuum.projec
 import org.apache.maven.continuum.release.ContinuumReleaseException;
 import org.apache.maven.shared.release.ReleaseResult;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
-import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -69,6 +74,8 @@ public class ContinuumBuildAgentServiceI
 {
     private static final Logger log = LoggerFactory.getLogger( ContinuumBuildAgentServiceImpl.class
);
 
+    private static final String FILE_SEPARATOR = System.getProperty( "file.separator" );
+
     /**
      * @plexus.requirement
      */
@@ -299,9 +306,11 @@ public class ContinuumBuildAgentServiceI
         return "";
     }
 
-    public String getProjectFileContent( int projectId, String directory, String filename
)
+    public Map<String, Object> getProjectFile( int projectId, String directory, String
filename )
         throws ContinuumBuildAgentException
     {
+        Map<String, Object> projectFile = new HashMap<String, Object>();
+
         String relativePath = "\\.\\./"; // prevent users from using relative paths.
         Pattern pattern = Pattern.compile( relativePath );
         Matcher matcher = pattern.matcher( directory );
@@ -315,15 +324,52 @@ public class ContinuumBuildAgentServiceI
         File fileDirectory = new File( workingDirectory, filteredDirectory );
 
         File userFile = new File( fileDirectory, filteredFilename );
+        byte[] downloadFile;
 
         try
         {
-            return FileUtils.fileRead( userFile );
+            downloadFile = FileUtils.readFileToByteArray( userFile );
         }
         catch ( IOException e )
         {
-            throw new ContinuumBuildAgentException( "Can't read file " + filename, e );
+            throw new ContinuumBuildAgentException( "Can't read file: " + filename );
         }
+
+        MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
+        mimeTypesMap.addMimeTypes( "application/java-archive jar war ear" );
+        mimeTypesMap.addMimeTypes( "application/java-class class" );
+        mimeTypesMap.addMimeTypes( "image/png png" );
+
+        String mimeType = mimeTypesMap.getContentType( userFile );
+        String fileContent;
+        boolean isStream = false;
+
+        if ( ( mimeType.indexOf( "image" ) >= 0 ) || ( mimeType.indexOf( "java-archive"
) >= 0 ) ||
+             ( mimeType.indexOf( "java-class" ) >= 0 ) || ( userFile.length() > 100000
) )
+        {
+            fileContent = "";
+            isStream = true;
+        }
+        else
+        {
+            try
+            {
+                fileContent = FileUtils.readFileToString( userFile );
+            }
+            catch ( IOException e )
+            {
+                throw new ContinuumBuildAgentException( "Can't read file " + filename, e
);
+            }
+        }
+
+        projectFile.put( "downloadFileName", userFile.getName() );
+        projectFile.put( "downloadFileLength", Long.toString( userFile.length() ) );
+        projectFile.put( "downloadFile", downloadFile );
+        projectFile.put( "mimeType", mimeType );
+        projectFile.put( "fileContent", fileContent );
+        projectFile.put( "isStream", isStream );
+
+        return projectFile;
     }
 
     public Map<String, Object> getReleasePluginParameters( int projectId, String pomFilename
)
@@ -1129,7 +1175,7 @@ public class ContinuumBuildAgentServiceI
 
             if ( buildOutputFile.exists() )
             {
-                return StringEscapeUtils.escapeHtml( FileUtils.fileRead( buildOutputFile
) );
+                return StringEscapeUtils.escapeHtml( FileUtils.readFileToString( buildOutputFile
) );
             }
         }
         catch ( Exception e )

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -1063,7 +1063,7 @@ public class DefaultDistributedBuildMana
         return "";
     }
     
-    public String getFileContent( int projectId, String directory, String filename )
+    public Map<String, Object> getFileContent( int projectId, String directory, String
filename )
         throws ContinuumException
     {
         BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId
);
@@ -1075,7 +1075,7 @@ public class DefaultDistributedBuildMana
             if ( buildAgentUrl == null )
             {
                 log.debug( "Unable to determine build agent where project last built" );
-                return "";
+                return null;
             }
 
             try
@@ -1083,7 +1083,7 @@ public class DefaultDistributedBuildMana
                 if ( isAgentAvailable( buildAgentUrl ) )
                 {
                     SlaveBuildAgentTransportService client = createSlaveBuildAgentTransportClientConnection(
buildAgentUrl );
-                    return client.getProjectFileContent( projectId, directory, filename );
+                    return client.getProjectFile( projectId, directory, filename );
                 }
             }
             catch ( MalformedURLException e )
@@ -1103,7 +1103,7 @@ public class DefaultDistributedBuildMana
         // call reload in case we disable the build agent
         reload();
 
-        return "";
+        return null;
     }
 
     public void removeFromPrepareBuildQueue( String buildAgentUrl, int projectGroupId, int
scmRootId )

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/stubs/SlaveBuildAgentTransportClientStub.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/stubs/SlaveBuildAgentTransportClientStub.java?rev=1236050&r1=1236049&r2=1236050&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/stubs/SlaveBuildAgentTransportClientStub.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/stubs/SlaveBuildAgentTransportClientStub.java
Thu Jan 26 06:51:21 2012
@@ -98,7 +98,7 @@ public class SlaveBuildAgentTransportCli
         return null;
     }
 
-    public String getProjectFileContent( int projectId, String directory, String filename
)
+    public Map<String, Object> getProjectFile( int projectId, String directory, String
filename )
         throws Exception
     {
         // TODO Auto-generated method stub
@@ -294,7 +294,6 @@ public class SlaveBuildAgentTransportCli
         return null;
     }
 
-    @Override
     public void executeDirectoryPurge( String directoryType, int daysOlder, int retentionCount,
boolean deleteAll )
         throws Exception
     {

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -51,7 +51,7 @@ public interface SlaveBuildAgentTranspor
     public String generateWorkingCopyContent( int projectId, String directory, String baseUrl,
String imagesBaseUrl )
         throws Exception;
 
-    public String getProjectFileContent( int projectId, String directory, String filename
)
+    public Map<String, Object> getProjectFile( int projectId, String directory, String
filename )
         throws Exception;
 
     public Map getReleasePluginParameters( int projectId, String pomFilename )

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -211,14 +211,14 @@ public class SlaveBuildAgentTransportCli
         return result;
     }
 
-    public String getProjectFileContent( int projectId, String directory, String filename
)
+    public Map<String, Object> getProjectFile( int projectId, String directory, String
filename )
         throws Exception
     {
-        String result;
+        Map result;
 
         try
         {
-            result = slave.getProjectFileContent( projectId, directory, filename );
+            result = slave.getProjectFile( projectId, directory, filename );
             log.debug( "Retrieved project '{}' file content from build agent {}", projectId,
buildAgentUrl );
         }
         catch ( Exception e )
@@ -823,8 +823,8 @@ public class SlaveBuildAgentTransportCli
         return result;
     }
 
-    @Override
-    public void executeDirectoryPurge( String directoryType, int daysOlder, int retentionCount,
boolean deleteAll ) throws Exception
+    public void executeDirectoryPurge( String directoryType, int daysOlder, int retentionCount,
boolean deleteAll )
+        throws Exception
     {
         slave.executeDirectoryPurge( directoryType, daysOlder, retentionCount, deleteAll
);
     }

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -153,13 +153,13 @@ public class SlaveBuildAgentTransportSer
         }
     }
 
-    public String getProjectFileContent( int projectId, String directory, String filename
)
+    public Map<String, Object> getProjectFile( int projectId, String directory, String
filename )
         throws Exception
     {
         try
         {
             log.debug( "Retrieve project '{}' file content", projectId );
-            return continuumBuildAgentService.getProjectFileContent( projectId, directory,
filename );
+            return continuumBuildAgentService.getProjectFile( projectId, directory, filename
);
         }
         catch ( ContinuumBuildAgentException e )
         {
@@ -576,8 +576,8 @@ public class SlaveBuildAgentTransportSer
         return continuumBuildAgentService.getBuildAgentPlatform();
     }
     
-    @Override
-    public void executeDirectoryPurge( String directoryType, int daysOlder, int retentionCount,
boolean deleteAll ) throws Exception
+    public void executeDirectoryPurge( String directoryType, int daysOlder, int retentionCount,
boolean deleteAll )
+        throws Exception
     {
         continuumBuildAgentService.executeDirectoryPurge( directoryType, daysOlder, retentionCount,
deleteAll );
     }

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=1236050&r1=1236049&r2=1236050&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
Thu Jan 26 06:51:21 2012
@@ -19,12 +19,14 @@ package org.apache.maven.continuum.web.a
  * under the License.
  */
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.activation.MimetypesFileTypeMap;
 
@@ -77,6 +79,12 @@ public class WorkingCopyAction
 
     private String projectGroupName = "";
 
+    private String downloadFileName = "";
+
+    private String downloadFileLength = "";
+
+    private InputStream downloadFileInputStream;
+
     public String execute()
         throws ContinuumException
     {
@@ -120,7 +128,25 @@ public class WorkingCopyAction
 
             if ( currentFile != null && !currentFile.equals( "" ) )
             {
-                currentFileContent = distributedBuildManager.getFileContent( projectId, userDirectory,
currentFile );
+                Map<String, Object> projectFile = distributedBuildManager.getFileContent(
projectId, userDirectory, currentFile );
+
+                if ( projectFile == null )
+                {
+                    currentFileContent = "";
+                }
+                else
+                {
+                    downloadFileInputStream =  new ByteArrayInputStream( (byte[]) projectFile.get(
"downloadFile" ) );
+                    downloadFileLength = (String) projectFile.get( "downloadFileLength" );
+                    downloadFileName = (String) projectFile.get( "downloadFileName" );
+                    currentFileContent = (String) projectFile.get( "fileContent" );
+                    mimeType = (String) projectFile.get( "mimeType" );
+
+                    if ( (Boolean) projectFile.get( "isStream" ) ) 
+                    {
+                        return "stream";
+                    }
+                }
             }
             else
             {
@@ -155,6 +181,8 @@ public class WorkingCopyAction
 
                 downloadFile = new File( getContinuum().getWorkingDirectory( projectId )
+ dir + currentFile );
                 mimeType = mimeTypesMap.getContentType( downloadFile );
+                downloadFileLength = Long.toString( downloadFile.length() );
+                downloadFileName = downloadFile.getName();
 
                 if ( ( mimeType.indexOf( "image" ) >= 0 ) || ( mimeType.indexOf( "java-archive"
) >= 0 ) ||
                     ( mimeType.indexOf( "java-class" ) >= 0 ) || ( downloadFile.length()
> 100000 ) )
@@ -222,27 +250,34 @@ public class WorkingCopyAction
     public InputStream getInputStream()
         throws ContinuumException
     {
-        FileInputStream fis;
-        try
+        if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
         {
-            fis = new FileInputStream( downloadFile );
+            return downloadFileInputStream;
         }
-        catch ( FileNotFoundException fne )
+        else
         {
-            throw new ContinuumException( "Error accessing file.", fne );
+            FileInputStream fis;
+            try
+            {
+                fis = new FileInputStream( downloadFile );
+            }
+            catch ( FileNotFoundException fne )
+            {
+                throw new ContinuumException( "Error accessing file.", fne );
+            }
+    
+            return fis;
         }
-
-        return fis;
     }
 
     public String getFileLength()
     {
-        return Long.toString( downloadFile.length() );
+        return downloadFileLength;
     }
 
     public String getDownloadFilename()
     {
-        return downloadFile.getName();
+        return downloadFileName;
     }
 
     public String getMimeType()



Mime
View raw message