View Javadoc

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.util.Properties;
23  import org.apache.maven.plugin.surefire.report.FileReporterFactory;
24  import org.apache.maven.surefire.providerapi.ProviderParameters;
25  import org.apache.maven.surefire.report.ConsoleLogger;
26  import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
27  import org.apache.maven.surefire.report.ReporterConfiguration;
28  import org.apache.maven.surefire.report.ReporterFactory;
29  import org.apache.maven.surefire.testset.DirectoryScannerParameters;
30  import org.apache.maven.surefire.testset.TestArtifactInfo;
31  import org.apache.maven.surefire.testset.TestRequest;
32  import org.apache.maven.surefire.util.DefaultDirectoryScanner;
33  import org.apache.maven.surefire.util.DirectoryScanner;
34  
35  /**
36   * @author Kristian Rosenvold
37   */
38  public class BaseProviderFactory
39      implements DirectoryScannerParametersAware, ReporterConfigurationAware, SurefireClassLoadersAware, TestRequestAware,
40      ProviderPropertiesAware, ProviderParameters, TestArtifactInfoAware
41  {
42      private Properties providerProperties;
43  
44      private DirectoryScannerParameters directoryScannerParameters;
45  
46      private ReporterConfiguration reporterConfiguration;
47  
48      private ClassLoader testClassLoader;
49  
50      private TestRequest testRequest;
51  
52      private TestArtifactInfo testArtifactInfo;
53  
54      private static final Integer ROOT_CHANNEl = new Integer( 0 );
55  
56  
57      private final ReporterFactory reporterFactory;
58  
59      public BaseProviderFactory( ReporterFactory reporterFactory )
60      {
61          this.reporterFactory = reporterFactory;
62      }
63  
64      public DirectoryScanner getDirectoryScanner()
65      {
66          if ( directoryScannerParameters == null )
67          {
68              return null;
69          }
70          return new DefaultDirectoryScanner( directoryScannerParameters.getTestClassesDirectory(),
71                                              directoryScannerParameters.getIncludes(),
72                                              directoryScannerParameters.getExcludes(),
73                                              directoryScannerParameters.getRunOrder() );
74      }
75  
76      public ReporterFactory getReporterFactory()
77      {
78          return reporterFactory;
79      }
80  
81      public void setDirectoryScannerParameters( DirectoryScannerParameters directoryScannerParameters )
82      {
83          this.directoryScannerParameters = directoryScannerParameters;
84      }
85  
86      public void setReporterConfiguration( ReporterConfiguration reporterConfiguration )
87      {
88          this.reporterConfiguration = reporterConfiguration;
89      }
90  
91      public void setClassLoaders( ClassLoader surefireClassLoader, ClassLoader testClassLoader )
92      {
93          this.testClassLoader = testClassLoader;
94      }
95  
96      public ConsoleLogger getConsoleLogger()
97      {
98          // Maybe a somewhat odd way to determine if we're forking
99          if ( getReporterFactory() instanceof FileReporterFactory )
100         {
101             return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
102         }
103         return new ForkingRunListener( reporterConfiguration.getOriginalSystemOut(), ROOT_CHANNEl.intValue(),
104                                        reporterConfiguration.isTrimStackTrace().booleanValue() );
105     }
106 
107     public void setTestRequest( TestRequest testRequest )
108     {
109         this.testRequest = testRequest;
110     }
111 
112     public DirectoryScannerParameters getDirectoryScannerParameters()
113     {
114         return directoryScannerParameters;
115     }
116 
117     public ReporterConfiguration getReporterConfiguration()
118     {
119         return reporterConfiguration;
120     }
121 
122     public TestRequest getTestRequest()
123     {
124         return testRequest;
125     }
126 
127     public ClassLoader getTestClassLoader()
128     {
129         return testClassLoader;
130     }
131 
132     public void setProviderProperties( Properties providerProperties )
133     {
134         this.providerProperties = providerProperties;
135     }
136 
137     public Properties getProviderProperties()
138     {
139         return providerProperties;
140     }
141 
142     public TestArtifactInfo getTestArtifactInfo()
143     {
144         return testArtifactInfo;
145     }
146 
147     public void setTestArtifactInfo( TestArtifactInfo testArtifactInfo )
148     {
149         this.testArtifactInfo = testArtifactInfo;
150     }
151 
152 }