Coverage Report - org.apache.maven.surefire.booter.StartupReportConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
StartupReportConfiguration
0%
0/80
0%
0/60
2.423
 
 1  
 package org.apache.maven.surefire.booter;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.PrintStream;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 import java.util.Properties;
 27  
 import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
 28  
 import org.apache.maven.surefire.report.AbstractConsoleReporter;
 29  
 import org.apache.maven.surefire.report.AbstractFileReporter;
 30  
 import org.apache.maven.surefire.report.BriefConsoleReporter;
 31  
 import org.apache.maven.surefire.report.BriefFileReporter;
 32  
 import org.apache.maven.surefire.report.ConsoleOutputDirectReporter;
 33  
 import org.apache.maven.surefire.report.ConsoleOutputFileReporter;
 34  
 import org.apache.maven.surefire.report.ConsoleReporter;
 35  
 import org.apache.maven.surefire.report.DetailedConsoleReporter;
 36  
 import org.apache.maven.surefire.report.FileReporter;
 37  
 import org.apache.maven.surefire.report.Reporter;
 38  
 import org.apache.maven.surefire.report.XMLReporter;
 39  
 
 40  
 /**
 41  
  * All the parameters used to construct reporters
 42  
  * <p/>
 43  
  *
 44  
  * @author Kristian Rosenvold
 45  
  */
 46  
 public class StartupReportConfiguration
 47  
 {
 48  
     private final boolean useFile;
 49  
 
 50  
     private final boolean printSummary;
 51  
 
 52  
     private final String reportFormat;
 53  
 
 54  
     private final String reportNameSuffix;
 55  
 
 56  
     private final String configurationHash;
 57  
 
 58  
     private final boolean requiresRunHistory;
 59  
 
 60  
     private final boolean redirectTestOutputToFile;
 61  
 
 62  
     private final boolean disableXmlReport;
 63  
 
 64  
     private final File reportsDirectory;
 65  
 
 66  
     private final boolean trimStackTrace;
 67  
 
 68  0
     private final Properties testVmSystemProperties = new Properties();
 69  
 
 70  
     public static final String BRIEF_REPORT_FORMAT = "brief";
 71  
 
 72  
     public static final String PLAIN_REPORT_FORMAT = "plain";
 73  
 
 74  
     public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
 75  
                                        boolean redirectTestOutputToFile, boolean disableXmlReport,
 76  
                                        File reportsDirectory, boolean trimStackTrace, String reportNameSuffix,
 77  
                                        String configurationHash, boolean requiresRunHistory )
 78  0
     {
 79  0
         this.useFile = useFile;
 80  0
         this.printSummary = printSummary;
 81  0
         this.reportFormat = reportFormat;
 82  0
         this.redirectTestOutputToFile = redirectTestOutputToFile;
 83  0
         this.disableXmlReport = disableXmlReport;
 84  0
         this.reportsDirectory = reportsDirectory;
 85  0
         this.trimStackTrace = trimStackTrace;
 86  0
         this.reportNameSuffix = reportNameSuffix;
 87  0
         this.configurationHash = configurationHash;
 88  0
         this.requiresRunHistory = requiresRunHistory;
 89  0
     }
 90  
 
 91  
     public static StartupReportConfiguration defaultValue()
 92  
     {
 93  0
         File target = new File( "./target" );
 94  0
         return new StartupReportConfiguration( true, true, "PLAIN", false, false, target, false, null, "TESTHASH",
 95  
                                                false );
 96  
     }
 97  
 
 98  
     public static StartupReportConfiguration defaultNoXml()
 99  
     {
 100  0
         File target = new File( "./target" );
 101  0
         return new StartupReportConfiguration( true, true, "PLAIN", false, true, target, false, null, "TESTHASHxXML",
 102  
                                                false );
 103  
     }
 104  
 
 105  
     public boolean isUseFile()
 106  
     {
 107  0
         return useFile;
 108  
     }
 109  
 
 110  
     public boolean isPrintSummary()
 111  
     {
 112  0
         return printSummary;
 113  
     }
 114  
 
 115  
     public String getReportFormat()
 116  
     {
 117  0
         return reportFormat;
 118  
     }
 119  
 
 120  
     public String getReportNameSuffix()
 121  
     {
 122  0
         return reportNameSuffix;
 123  
     }
 124  
 
 125  
     public boolean isRedirectTestOutputToFile()
 126  
     {
 127  0
         return redirectTestOutputToFile;
 128  
     }
 129  
 
 130  
     public boolean isDisableXmlReport()
 131  
     {
 132  0
         return disableXmlReport;
 133  
     }
 134  
 
 135  
     public File getReportsDirectory()
 136  
     {
 137  0
         return reportsDirectory;
 138  
     }
 139  
 
 140  
     public String getXmlReporterName()
 141  
     {
 142  0
         if ( !isDisableXmlReport() )
 143  
         {
 144  0
             return XMLReporter.class.getName();
 145  
         }
 146  0
         return null;
 147  
     }
 148  
 
 149  
     public XMLReporter instantiateXmlReporter()
 150  
     {
 151  0
         if ( !isDisableXmlReport() )
 152  
         {
 153  0
             return new XMLReporter( trimStackTrace, reportsDirectory, reportNameSuffix );
 154  
         }
 155  0
         return null;
 156  
     }
 157  
 
 158  
     public String getFileReporter()
 159  
     {
 160  0
         if ( isUseFile() )
 161  
         {
 162  0
             if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
 163  
             {
 164  0
                 return BriefFileReporter.class.getName();
 165  
             }
 166  0
             else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
 167  
             {
 168  0
                 return FileReporter.class.getName();
 169  
             }
 170  
         }
 171  0
         return null;
 172  
     }
 173  
 
 174  
     public AbstractFileReporter instantiateFileReporter()
 175  
     {
 176  0
         if ( isUseFile() )
 177  
         {
 178  0
             if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
 179  
             {
 180  0
                 return new BriefFileReporter( trimStackTrace, reportsDirectory, getReportNameSuffix() );
 181  
             }
 182  0
             else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
 183  
             {
 184  0
                 return new FileReporter( trimStackTrace, reportsDirectory, getReportNameSuffix() );
 185  
             }
 186  
         }
 187  0
         return null;
 188  
     }
 189  
 
 190  
 
 191  
     /**
 192  
      * Returns the reporter that will write to the console
 193  
      *
 194  
      * @return a console reporter of null if no console reporting
 195  
      */
 196  
     public String getConsoleReporter()
 197  
     {
 198  0
         if ( isUseFile() )
 199  
         {
 200  0
             return isPrintSummary() ? ConsoleReporter.class.getName() : null;
 201  
         }
 202  0
         else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
 203  
         {
 204  0
             return BriefConsoleReporter.class.getName();
 205  
         }
 206  0
         else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
 207  
         {
 208  0
             return DetailedConsoleReporter.class.getName();
 209  
         }
 210  0
         return null;
 211  
     }
 212  
 
 213  
     public AbstractConsoleReporter instantiateConsoleReporter()
 214  
     {
 215  0
         if ( isUseFile() )
 216  
         {
 217  0
             return isPrintSummary() ? new ConsoleReporter( trimStackTrace ) : null;
 218  
         }
 219  0
         else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
 220  
         {
 221  0
             return new BriefConsoleReporter( trimStackTrace );
 222  
         }
 223  0
         else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
 224  
         {
 225  0
             return new DetailedConsoleReporter( trimStackTrace );
 226  
         }
 227  0
         return null;
 228  
     }
 229  
 
 230  
     public String getConsoleOutputFileReporterName()
 231  
     {
 232  0
         if ( isRedirectTestOutputToFile() )
 233  
         {
 234  0
             return ConsoleOutputFileReporter.class.getName();
 235  
         }
 236  
         else
 237  
         {
 238  0
             return ConsoleOutputDirectReporter.class.getName();
 239  
         }
 240  
     }
 241  
 
 242  
     public Reporter instantiateConsoleOutputFileReporter( PrintStream originalSystemOut )
 243  
     {
 244  0
         if ( isRedirectTestOutputToFile() )
 245  
         {
 246  0
             return new ConsoleOutputFileReporter( reportsDirectory, getReportNameSuffix() );
 247  
         }
 248  
         else
 249  
         {
 250  0
             return new ConsoleOutputDirectReporter( originalSystemOut );
 251  
         }
 252  
     }
 253  
 
 254  
     public StatisticsReporter instantiateStatisticsReporter()
 255  
     {
 256  0
         if ( requiresRunHistory )
 257  
         {
 258  0
             final File target = getStatisticsFile();
 259  0
             return new StatisticsReporter( target );
 260  
         }
 261  0
         return null;
 262  
     }
 263  
 
 264  
     public File getStatisticsFile()
 265  
     {
 266  0
         return new File( reportsDirectory.getParentFile().getParentFile(), ".surefire-" + this.configurationHash );
 267  
     }
 268  
 
 269  
 
 270  
     /**
 271  
      * A list of classnames representing runnable reports for this test-run.
 272  
      *
 273  
      * @return A list of strings, each string is a classname of a class
 274  
      *         implementing the org.apache.maven.surefire.report.Reporter interface
 275  
      */
 276  
     public List getReports()
 277  
     {
 278  0
         ArrayList reports = new ArrayList();
 279  0
         addIfNotNull( reports, getConsoleReporter() );
 280  0
         addIfNotNull( reports, getFileReporter() );
 281  0
         addIfNotNull( reports, getXmlReporterName() );
 282  0
         addIfNotNull( reports, getConsoleOutputFileReporterName() );
 283  0
         return reports;
 284  
     }
 285  
 
 286  
     private void addIfNotNull( ArrayList reports, String reporter )
 287  
     {
 288  0
         if ( reporter != null )
 289  
         {
 290  0
             reports.add( reporter );
 291  
         }
 292  0
     }
 293  
 
 294  
     public Properties getTestVmSystemProperties()
 295  
     {
 296  0
         return testVmSystemProperties;
 297  
     }
 298  
 
 299  
 
 300  
     public boolean isTrimStackTrace()
 301  
     {
 302  0
         return trimStackTrace;
 303  
     }
 304  
 
 305  
     public String getConfigurationHash()
 306  
     {
 307  0
         return configurationHash;
 308  
     }
 309  
 
 310  
     public boolean isRequiresRunHistory()
 311  
     {
 312  0
         return requiresRunHistory;
 313  
     }
 314  
 }