1 17 18 package org.apache.geronimo.mavenplugins.testsuite.report; 19 20 import org.apache.maven.artifact.handler.ArtifactHandler; 21 import org.apache.maven.model.ReportPlugin; 22 import org.apache.maven.project.MavenProject; 23 import org.apache.maven.reporting.AbstractMavenReport; 24 import org.apache.maven.reporting.MavenReportException; 25 import org.codehaus.doxia.site.renderer.SiteRenderer; 26 import org.codehaus.plexus.util.PathTool; 27 import org.codehaus.plexus.util.StringUtils; 28 29 import java.io.File ; 30 import java.util.Iterator ; 31 import java.util.Locale ; 32 import java.util.ResourceBundle ; 33 34 35 42 public class SurefireReportMojo 43 extends AbstractMavenReport 44 { 45 50 private String outputDirectory; 51 52 58 private SiteRenderer siteRenderer; 59 60 66 private MavenProject project; 67 68 74 private boolean showSuccess; 75 76 82 private File reportsDirectory; 83 84 90 private String outputName; 91 92 97 private File xrefLocation; 98 99 104 private boolean linkXRef; 105 106 public void executeReport( Locale locale ) 107 throws MavenReportException 108 { 109 115 116 SurefireReportGenerator report = 117 new SurefireReportGenerator( reportsDirectory, locale, showSuccess, determineXrefLocation() ); 118 119 report.doGenerateReport( getBundle( locale ), getSink() ); 120 121 System.out.println("surefire-report.html generated."); 122 } 123 124 private String determineXrefLocation() 125 { 126 String location = null; 127 128 if ( linkXRef ) 129 { 130 String relativePath = PathTool.getRelativePath( outputDirectory, xrefLocation.getAbsolutePath() ); 131 if ( StringUtils.isEmpty( relativePath ) ) 132 { 133 relativePath = "."; 134 } 135 relativePath = relativePath + "/" + xrefLocation.getName(); 136 if ( xrefLocation.exists() ) 137 { 138 location = relativePath; 140 } 141 else 142 { 143 for ( Iterator reports = project.getReportPlugins().iterator(); reports.hasNext(); ) 145 { 146 ReportPlugin report = (ReportPlugin) reports.next(); 147 148 String artifactId = report.getArtifactId(); 149 if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) ) 150 { 151 location = relativePath; 152 } 153 } 154 } 155 156 if ( location == null ) 157 { 158 getLog().warn( "Unable to locate Test Source XRef to link to - DISABLED" ); 159 } 160 } 161 return location; 162 } 163 164 public String getName( Locale locale ) 165 { 166 return getBundle( locale ).getString( "report.surefire.name" ); 167 } 168 169 public String getDescription( Locale locale ) 170 { 171 return getBundle( locale ).getString( "report.surefire.description" ); 172 } 173 174 protected SiteRenderer getSiteRenderer() 175 { 176 return siteRenderer; 177 } 178 179 protected MavenProject getProject() 180 { 181 return project; 182 } 183 184 public String getOutputName() 185 { 186 return outputName; 187 } 188 189 protected String getOutputDirectory() 190 { 191 return outputDirectory; 192 } 193 194 private ResourceBundle getBundle( Locale locale ) 195 { 196 return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() ); 197 } 198 199 202 public boolean canGenerateReport() 203 { 204 return "pom".equalsIgnoreCase(project.getPackaging()); 206 } 207 } 208 | Popular Tags |