continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1660654 - in /continuum/trunk/continuum-core/src/main: java/org/apache/maven/continuum/execution/ant/ java/org/apache/maven/continuum/execution/maven/m2/ java/org/apache/maven/continuum/execution/shared/ resources/META-INF/
Date Wed, 18 Feb 2015 15:26:59 GMT
Author: batkinson
Date: Wed Feb 18 15:26:58 2015
New Revision: 1660654

URL: http://svn.apache.org/r1660654
Log:
Factored test archiving out of build executors.

Added:
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/JUnitReportArchiver.java
Modified:
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
    continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java?rev=1660654&r1=1660653&r2=1660654&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java
Wed Feb 18 15:26:58 2015
@@ -26,14 +26,13 @@ import org.apache.maven.continuum.execut
 import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorException;
+import org.apache.maven.continuum.execution.shared.JUnitReportArchiver;
 import org.apache.maven.continuum.installation.InstallationService;
 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.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
@@ -64,9 +63,7 @@ public class AntBuildExecutor
 
     private ConfigurationService configurationService;
 
-    private String[] testIncludes = { };
-
-    private String[] testExcludes = { };
+    private JUnitReportArchiver testReportArchiver;
 
     // ----------------------------------------------------------------------
     //
@@ -82,14 +79,9 @@ public class AntBuildExecutor
         this.configurationService = configurationService;
     }
 
-    public void setTestIncludes( String[] testIncludes )
-    {
-        this.testIncludes = testIncludes;
-    }
-
-    public void setTestExcludes( String[] testExcludes )
+    public void setTestReportArchiver( JUnitReportArchiver testReportArchiver )
     {
-        this.testExcludes = testExcludes;
+        this.testReportArchiver = testReportArchiver;
     }
 
     // ----------------------------------------------------------------------
@@ -175,7 +167,9 @@ public class AntBuildExecutor
             {
                 backupDirectory.mkdirs();
             }
-            backupTestFiles( getWorkingDirectoryService().getWorkingDirectory( project ),
backupDirectory );
+            testReportArchiver.archiveReports(
+                getWorkingDirectory( project, projectScmRootUrl, projectsWithCommonScmRoot
),
+                backupDirectory );
         }
         catch ( ConfigurationException e )
         {
@@ -187,28 +181,5 @@ public class AntBuildExecutor
         }
     }
 
-    private void backupTestFiles( File workingDir, File backupDirectory )
-        throws IOException
-    {
-        DirectoryScanner scanner = new DirectoryScanner();
-        scanner.setBasedir( workingDir );
-        scanner.setIncludes( testIncludes );
-        scanner.setExcludes( testExcludes );
-        scanner.scan();
-
-        String[] testResultFiles = scanner.getIncludedFiles();
-        if ( testResultFiles.length > 0 )
-        {
-            log.info( "Backing up {} junit test reports", testResultFiles.length );
-        }
-        for ( String testResultFile : testResultFiles )
-        {
-            File xmlFile = new File( workingDir, testResultFile );
-            if ( backupDirectory != null )
-            {
-                FileUtils.copyFileToDirectory( xmlFile, backupDirectory );
-            }
-        }
-    }
 }
 

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java?rev=1660654&r1=1660653&r2=1660654&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
Wed Feb 18 15:26:58 2015
@@ -29,6 +29,7 @@ import org.apache.maven.continuum.execut
 import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorException;
+import org.apache.maven.continuum.execution.shared.JUnitReportArchiver;
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
@@ -85,6 +86,9 @@ public class MavenTwoBuildExecutor
     @Requirement
     private ConfigurationService configurationService;
 
+    @Requirement
+    private JUnitReportArchiver testReportArchiver;
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -124,6 +128,11 @@ public class MavenTwoBuildExecutor
         this.configurationService = configurationService;
     }
 
+    public void setTestReportArchiver( JUnitReportArchiver testReportArchiver )
+    {
+        this.testReportArchiver = testReportArchiver;
+    }
+
     // ----------------------------------------------------------------------
     // ContinuumBuilder Implementation
     // ----------------------------------------------------------------------
@@ -344,42 +353,17 @@ public class MavenTwoBuildExecutor
             {
                 backupDirectory.mkdirs();
             }
+            testReportArchiver.archiveReports(
+                getWorkingDirectory( project, projectScmRootUrl, projectsWithCommonScmRoot
),
+                backupDirectory );
         }
         catch ( ConfigurationException e )
         {
-            log.info( "error on surefire backup directory creation skip backup " + e.getMessage(),
e );
+            log.error( "failed to get backup directory", e );
         }
-        backupTestFiles( getWorkingDirectory( project, projectScmRootUrl, projectsWithCommonScmRoot
),
-                         backupDirectory );
-    }
-
-    private void backupTestFiles( File workingDir, File backupDirectory )
-    {
-        DirectoryScanner scanner = new DirectoryScanner();
-        scanner.setBasedir( workingDir );
-        scanner.setIncludes(
-            new String[] { "**/target/surefire-reports/TEST-*.xml", "**/target/surefire-it-reports/TEST-*.xml"
} );
-        scanner.scan();
-
-        String[] testResultFiles = scanner.getIncludedFiles();
-        if ( testResultFiles.length > 0 )
-        {
-            log.info( "Backup surefire files." );
-        }
-        for ( String testResultFile : testResultFiles )
+        catch ( IOException e )
         {
-            File xmlFile = new File( workingDir, testResultFile );
-            try
-            {
-                if ( backupDirectory != null )
-                {
-                    FileUtils.copyFileToDirectory( xmlFile, backupDirectory );
-                }
-            }
-            catch ( IOException e )
-            {
-                log.info( "failed to backup unit report file " + xmlFile.getPath() );
-            }
+            log.warn( "failed to copy test results to backup directory", e );
         }
     }
 

Added: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/JUnitReportArchiver.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/JUnitReportArchiver.java?rev=1660654&view=auto
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/JUnitReportArchiver.java
(added)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/shared/JUnitReportArchiver.java
Wed Feb 18 15:26:58 2015
@@ -0,0 +1,56 @@
+package org.apache.maven.continuum.execution.shared;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+
+public class JUnitReportArchiver
+{
+    private static Logger log = LoggerFactory.getLogger( JUnitReportArchiver.class );
+
+    private String[] includeFiles = { };
+
+    private String[] excludeFiles = { };
+
+    public void setIncludeFiles( String[] includeFiles )
+    {
+        this.includeFiles = includeFiles;
+    }
+
+    public void setExcludeFiles( String[] excludeFiles )
+    {
+        this.excludeFiles = excludeFiles;
+    }
+
+    public String[] findReports( File workingDir )
+    {
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setBasedir( workingDir );
+        scanner.setIncludes( includeFiles );
+        scanner.setExcludes( excludeFiles );
+        scanner.scan();
+        return scanner.getIncludedFiles();
+    }
+
+    public void archiveReports( File workingDir, File backupDir )
+        throws IOException
+    {
+        String[] testResultFiles = findReports( workingDir );
+        if ( testResultFiles.length > 0 )
+        {
+            log.info( "Backing up {} test reports", testResultFiles.length );
+        }
+        for ( String testResultFile : testResultFiles )
+        {
+            File xmlFile = new File( workingDir, testResultFile );
+            if ( backupDir != null )
+            {
+                FileUtils.copyFileToDirectory( xmlFile, backupDir );
+            }
+        }
+    }
+}

Modified: continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml?rev=1660654&r1=1660653&r2=1660654&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml (original)
+++ continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml Wed Feb
18 15:26:58 2015
@@ -27,6 +27,11 @@
     <property name="defaultExecutable" value="mvn"/>
     <property name="builderHelper" ref="mavenBuilderHelper"/>
     <property name="projectHelper" ref="mavenProjectHelper"/>
+    <property name="testReportArchiver">
+        <bean class="org.apache.maven.continuum.execution.shared.JUnitReportArchiver">
+            <property name="includeFiles" value="**/target/surefire-reports/TEST-*.xml,**/target/surefire-it-reports/TEST-*.xml"/>
+        </bean>
+    </property>
   </bean>
   <bean name="continuumBuildExecutor#maven-1"
         class="org.apache.maven.continuum.execution.maven.m1.MavenOneBuildExecutor" autowire="byName">
@@ -36,7 +41,11 @@
   <bean name="continuumBuildExecutor#ant"
         class="org.apache.maven.continuum.execution.ant.AntBuildExecutor" autowire="byName">
     <property name="defaultExecutable" value="ant"/>
-    <property name="testIncludes" value="**/TEST-*.xml"/>
+    <property name="testReportArchiver">
+      <bean class="org.apache.maven.continuum.execution.shared.JUnitReportArchiver">
+        <property name="includeFiles" value="**/TEST-*.xml"/>
+      </bean>
+    </property>
   </bean>
   <bean name="continuumBuildExecutor#shell"
         class="org.apache.maven.continuum.execution.shell.ShellBuildExecutor" autowire="byName">



Mime
View raw message