Coverage Report - org.apache.maven.plugin.surefire.StartupReportConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
StartupReportConfiguration
40%
20/49
4%
1/22
1,565
 
 1  
 package org.apache.maven.plugin.surefire;
 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.Properties;
 25  
 import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
 26  
 import org.apache.maven.plugin.surefire.report.ConsoleReporter;
 27  
 import org.apache.maven.plugin.surefire.report.DirectConsoleOutput;
 28  
 import org.apache.maven.plugin.surefire.report.FileReporter;
 29  
 import org.apache.maven.plugin.surefire.report.StatelessXmlReporter;
 30  
 import org.apache.maven.plugin.surefire.report.TestcycleConsoleOutputReceiver;
 31  
 import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
 32  
 
 33  
 import javax.annotation.Nonnull;
 34  
 
 35  
 /**
 36  
  * All the parameters used to construct reporters
 37  
  * <p/>
 38  
  *
 39  
  * @author Kristian Rosenvold
 40  
  */
 41  
 public class StartupReportConfiguration
 42  
 {
 43  
     private final PrintStream originalSystemOut;
 44  
 
 45  
     private final PrintStream originalSystemErr;
 46  
 
 47  
     private final boolean useFile;
 48  
 
 49  
     private final boolean printSummary;
 50  
 
 51  
     private final String reportFormat;
 52  
 
 53  
     private final String reportNameSuffix;
 54  
 
 55  
     private final String configurationHash;
 56  
 
 57  
     private final boolean requiresRunHistory;
 58  
 
 59  
     private final boolean redirectTestOutputToFile;
 60  
 
 61  
     private final boolean disableXmlReport;
 62  
 
 63  
     private final File reportsDirectory;
 64  
 
 65  
     private final boolean trimStackTrace;
 66  
 
 67  16
     private final Properties testVmSystemProperties = new Properties();
 68  
 
 69  
     public static final String BRIEF_REPORT_FORMAT = ConsoleReporter.BRIEF;
 70  
 
 71  
     public static final String PLAIN_REPORT_FORMAT = ConsoleReporter.PLAIN;
 72  
 
 73  
     public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
 74  
                                        boolean redirectTestOutputToFile, boolean disableXmlReport,
 75  
                                        @Nonnull File reportsDirectory,
 76  
                                        boolean trimStackTrace, String reportNameSuffix,
 77  
                                        String configurationHash, boolean requiresRunHistory )
 78  16
     {
 79  16
         this.useFile = useFile;
 80  16
         this.printSummary = printSummary;
 81  16
         this.reportFormat = reportFormat;
 82  16
         this.redirectTestOutputToFile = redirectTestOutputToFile;
 83  16
         this.disableXmlReport = disableXmlReport;
 84  16
         this.reportsDirectory = reportsDirectory;
 85  16
         this.trimStackTrace = trimStackTrace;
 86  16
         this.reportNameSuffix = reportNameSuffix;
 87  16
         this.configurationHash = configurationHash;
 88  16
         this.requiresRunHistory = requiresRunHistory;
 89  16
         this.originalSystemOut = System.out;
 90  16
         this.originalSystemErr = System.err;
 91  16
     }
 92  
 
 93  
     public static StartupReportConfiguration defaultValue()
 94  
     {
 95  16
         File target = new File( "./target" );
 96  16
         return new StartupReportConfiguration( true, true, "PLAIN", false, false, target, false, null, "TESTHASH",
 97  
                                                false );
 98  
     }
 99  
 
 100  
     public static StartupReportConfiguration defaultNoXml()
 101  
     {
 102  0
         File target = new File( "./target" );
 103  0
         return new StartupReportConfiguration( true, true, "PLAIN", false, true, target, false, null, "TESTHASHxXML",
 104  
                                                false );
 105  
     }
 106  
 
 107  
     public boolean isUseFile()
 108  
     {
 109  0
         return useFile;
 110  
     }
 111  
 
 112  
     public boolean isPrintSummary()
 113  
     {
 114  0
         return printSummary;
 115  
     }
 116  
 
 117  
     public String getReportFormat()
 118  
     {
 119  0
         return reportFormat;
 120  
     }
 121  
 
 122  
     public String getReportNameSuffix()
 123  
     {
 124  0
         return reportNameSuffix;
 125  
     }
 126  
 
 127  
     public boolean isRedirectTestOutputToFile()
 128  
     {
 129  0
         return redirectTestOutputToFile;
 130  
     }
 131  
 
 132  
     public boolean isDisableXmlReport()
 133  
     {
 134  0
         return disableXmlReport;
 135  
     }
 136  
 
 137  
     public File getReportsDirectory()
 138  
     {
 139  0
         return reportsDirectory;
 140  
     }
 141  
 
 142  
     public StatelessXmlReporter instantiateStatelessXmlReporter()
 143  
     {
 144  0
         if ( !isDisableXmlReport() )
 145  
         {
 146  0
             return new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace );
 147  
         }
 148  0
         return null;
 149  
     }
 150  
 
 151  
     public FileReporter instantiateFileReporter()
 152  
     {
 153  0
         if ( isUseFile() && isBriefOrPlainFormat() )
 154  
         {
 155  0
             return new FileReporter( reportsDirectory, getReportNameSuffix() );
 156  
         }
 157  0
         return null;
 158  
     }
 159  
 
 160  
     public boolean isBriefOrPlainFormat()
 161  
     {
 162  0
         String fmt = getReportFormat();
 163  0
         return BRIEF_REPORT_FORMAT.equals( fmt ) || PLAIN_REPORT_FORMAT.equals( fmt );
 164  
     }
 165  
 
 166  
     public ConsoleReporter instantiateConsoleReporter()
 167  
     {
 168  0
         return shouldReportToConsole() ? new ConsoleReporter( originalSystemOut ) : null;
 169  
     }
 170  
 
 171  
     private boolean shouldReportToConsole()
 172  
     {
 173  0
         return isUseFile() ? isPrintSummary() : isRedirectTestOutputToFile() || isBriefOrPlainFormat();
 174  
     }
 175  
 
 176  
     public TestcycleConsoleOutputReceiver instantiateConsoleOutputFileReporter()
 177  
     {
 178  0
         if ( isRedirectTestOutputToFile() )
 179  
         {
 180  0
             return new ConsoleOutputFileReporter( reportsDirectory, getReportNameSuffix() );
 181  
         }
 182  
         else
 183  
         {
 184  0
             return new DirectConsoleOutput( originalSystemOut, originalSystemErr );
 185  
         }
 186  
     }
 187  
 
 188  
     public StatisticsReporter instantiateStatisticsReporter()
 189  
     {
 190  16
         if ( requiresRunHistory )
 191  
         {
 192  0
             final File target = getStatisticsFile();
 193  0
             return new StatisticsReporter( target );
 194  
         }
 195  16
         return null;
 196  
     }
 197  
 
 198  
     public File getStatisticsFile()
 199  
     {
 200  0
         return new File( reportsDirectory.getParentFile().getParentFile(), ".surefire-" + this.configurationHash );
 201  
     }
 202  
 
 203  
 
 204  
     public Properties getTestVmSystemProperties()
 205  
     {
 206  0
         return testVmSystemProperties;
 207  
     }
 208  
 
 209  
 
 210  
     public boolean isTrimStackTrace()
 211  
     {
 212  0
         return trimStackTrace;
 213  
     }
 214  
 
 215  
     public String getConfigurationHash()
 216  
     {
 217  0
         return configurationHash;
 218  
     }
 219  
 
 220  
     public boolean isRequiresRunHistory()
 221  
     {
 222  0
         return requiresRunHistory;
 223  
     }
 224  
 
 225  
     public PrintStream getOriginalSystemOut()
 226  
     {
 227  16
         return originalSystemOut;
 228  
     }
 229  
 
 230  
 }