You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ar...@apache.org on 2006/03/28 02:58:52 UTC

svn commit: r389336 - in /maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report: ReportTestCase.java ReportTestSuite.java SurefireReportGenerator.java SurefireReportMojo.java

Author: aramirez
Date: Mon Mar 27 16:58:50 2006
New Revision: 389336

URL: http://svn.apache.org/viewcvs?rev=389336&view=rev
Log:
PR: MSUREFIREREP-1

Link to the sources will be available if maven-jxr-plugin is declared in the reporting section.

Modified:
    maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java
    maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java
    maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportGenerator.java
    maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java

Modified: maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java?rev=389336&r1=389335&r2=389336&view=diff
==============================================================================
--- maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java (original)
+++ maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java Mon Mar 27 16:58:50 2006
@@ -20,6 +20,8 @@
 
 public class ReportTestCase
 {
+    private String fullClassName;
+    private String className;
     private String fullName;
     private String name;
     private float time;
@@ -37,6 +39,26 @@
     public void setName( String name )
     {
         this.name = name;
+    }
+
+    public String getFullClassName(  )
+    {
+        return fullClassName;
+    }
+
+    public void setFullClassName( String name )
+    {
+        this.fullClassName = name;
+    }
+
+    public String getClassName(  )
+    {
+        return className;
+    }
+
+    public void setClassName( String name )
+    {
+        this.className = name;
     }
 
     public float getTime(  )

Modified: maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java?rev=389336&r1=389335&r2=389336&view=diff
==============================================================================
--- maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java (original)
+++ maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java Mon Mar 27 16:58:50 2006
@@ -38,6 +38,7 @@
     private int numberOfFailures;
     private int numberOfTests;
     private String name;
+    private String fullClassName;
     private String packageName;
     private float timeElapsed;
     private NumberFormat numberFormat;
@@ -86,13 +87,13 @@
                 Number time = numberFormat.parse( attrs.getValue( "time" ) );
                 
                 timeElapsed = time.floatValue();
+
+                fullClassName = attrs.getValue( "name" );
     
-                String fName = attrs.getValue( "name" );
-    
-                name = fName.substring( fName.lastIndexOf( "." ) + 1,
-                                        fName.length(  ) );
+                name = fullClassName.substring( fullClassName.lastIndexOf( "." ) + 1,
+                                        fullClassName.length(  ) );
 
-                int lastDotPosition = fName.lastIndexOf( "." );
+                int lastDotPosition = fullClassName.lastIndexOf( "." );
                 if ( lastDotPosition < 0 )
                 {
                     /* no package name */
@@ -100,7 +101,7 @@
                 }
                 else
                 {
-                    packageName = fName.substring( 0, lastDotPosition );
+                    packageName = fullClassName.substring( 0, lastDotPosition );
                 }
 
                 testCases = new ArrayList(  );
@@ -109,8 +110,12 @@
                 currentElement = new StringBuffer(  );
     
                 testCase = new ReportTestCase(  );
-    
+
+                testCase.setFullClassName( fullClassName );
+
                 testCase.setName( attrs.getValue( "name" ) );
+
+                testCase.setClassName( name );
     
                 Number time = numberFormat.parse( attrs.getValue( "time" ) );
                 
@@ -225,6 +230,16 @@
     }
 
     public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public String getFName(  )
+    {
+        return name;
+    }
+
+    public void setFName( String name )
     {
         this.name = name;
     }

Modified: maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportGenerator.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportGenerator.java?rev=389336&r1=389335&r2=389336&view=diff
==============================================================================
--- maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportGenerator.java (original)
+++ maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportGenerator.java Mon Mar 27 16:58:50 2006
@@ -18,6 +18,7 @@
 
 import org.apache.maven.reporting.MavenReportException;
 import org.codehaus.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.text.NumberFormat;
@@ -27,6 +28,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.StringTokenizer;
 
 public class SurefireReportGenerator
 {
@@ -36,10 +38,14 @@
 
     private boolean showSuccess;
 
-    public SurefireReportGenerator( File reportsDirectory, Locale locale, boolean showSuccess )
+    private String xrefLocation;
+
+    public SurefireReportGenerator( File reportsDirectory, Locale locale, boolean showSuccess, String xrefLocation )
     {
         report = new SurefireReportParser( reportsDirectory, locale );
 
+        this.xrefLocation = xrefLocation;
+
         this.showSuccess = showSuccess;
     }
 
@@ -456,8 +462,11 @@
                         sink.tableCell();
                         sink.verbatim( true );
                         boolean firstLine = true;
+
+                        String techMessage = "";
                         while ( it.hasNext() )
                         {
+                            techMessage = it.next().toString();
                             if ( firstLine )
                             {
                                 firstLine = false;
@@ -466,11 +475,33 @@
                             {
                                 sink.text( "    " );
                             }
-                            sink.text( it.next().toString() + "\n" );
+                            sink.rawText( techMessage + "<br />" );
                         }
                         sink.verbatim_();
                         sink.tableCell_();
                         sink.tableRow_();
+
+                        sink.tableRow();
+                        sinkCell( sink, "" );
+
+                        sink.tableCell();
+                        if ( xrefLocation != null )
+                        {
+                            String path = tCase.getFullClassName().replace( '.', '/' );
+
+                            sink.link( xrefLocation + "/" + path + ".html#" +
+                                getErrorLineNumber( tCase.getFullName() , techMessage ));
+                        }
+                        sink.text( tCase.getFullClassName() + ":" +
+                            getErrorLineNumber( tCase.getFullName() , techMessage ) );
+
+                        if ( xrefLocation != null )
+                        {
+                            sink.link_();
+                        }
+                        sink.tableCell_();
+
+                        sink.tableRow_();
                     }
                 }
 
@@ -480,6 +511,25 @@
         }
 
         sinkLineBreak( sink );
+    }
+
+    private String getErrorLineNumber( String className, String source )
+    {
+        StringTokenizer tokenizer = new StringTokenizer( source );
+
+        String lineNo = "";
+
+        while( tokenizer.hasMoreTokens() )
+        {
+            String token = tokenizer.nextToken();
+            if( token.startsWith( className ) )
+            {
+                int idx = token.indexOf( ":" );
+                lineNo = token.substring( idx + 1, token.indexOf( ")" ) );
+                break;
+            }
+        }
+        return lineNo;
     }
 
     private void constructHotLinks( Sink sink, ResourceBundle bundle )

Modified: maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java?rev=389336&r1=389335&r2=389336&view=diff
==============================================================================
--- maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java (original)
+++ maven/plugins/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportMojo.java Mon Mar 27 16:58:50 2006
@@ -17,15 +17,22 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Locale;
 import java.util.ResourceBundle;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Collections;
 
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.AbstractMavenReport;
 import org.apache.maven.reporting.MavenReportException;
+import org.apache.maven.model.ReportPlugin;
 
 import org.codehaus.doxia.site.renderer.SiteRenderer;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.FileUtils;
 
 
 /**
@@ -61,7 +68,7 @@
      * @required @readonly
      */
     private MavenProject project;
-    
+
     /**
      * If set to <code>false</code>, only failures are shown.
      *
@@ -69,7 +76,7 @@
      * @required
      */
     private boolean showSuccess;
-    
+
     /**
      * This directory contains the XML Report files that must be parsed and rendered to HTML format.
      *
@@ -77,7 +84,7 @@
      * @required
      */
     private File reportsDirectory;
-    
+
     /**
      * The default filename to use for the report.
      *
@@ -85,20 +92,54 @@
      * @required
      */
     private String outputName;
-    
+
+    /**
+     * Location of the Xrefs to link
+     *
+     * @parameter expression="${project.build.directory}/site/xref-test"
+     */
+    private String xrefLocation;
+
+    /**
+     * @parameter expression="${linkXref}" default-value="true"
+     */
+    private boolean linkXref;
+
     public void executeReport( Locale locale )
                        throws MavenReportException
     {
-        SurefireReportGenerator report = new SurefireReportGenerator( reportsDirectory, locale, showSuccess );
+        SurefireReportGenerator report = new SurefireReportGenerator( reportsDirectory,
+                                                                      locale, showSuccess,
+                                                                      doXref() ? xrefLocation : null);
 
         try
         {
             report.doGenerateReport( getBundle( locale ),
                                      getSink(  ) );
-        } catch ( Exception e )
+        }
+        catch ( Exception e )
         {
-            e.printStackTrace(  );
+            throw new MavenReportException( "Failed to generate report", e );
+        }
+    }
+
+    private boolean doXref()
+    {
+        List reportPlugins = getProject().getReportPlugins();
+
+        boolean retValue = false;
+
+        for( Iterator iter = reportPlugins.iterator(); iter.hasNext(); )
+        {
+            ReportPlugin plugin = ( ReportPlugin ) iter.next();
+
+            if( plugin.getArtifactId().equals( "maven-jxr-plugin" ) ||
+                plugin.getArtifactId().equals( "jxr-maven-plugin" ) )
+            {
+                retValue = true;
+            }
         }
+        return retValue;
     }
 
     public String getName( Locale locale )