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.surefire.providerapi.ProviderParameters;
24  import org.apache.maven.surefire.report.ConsoleLogger;
25  import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
26  import org.apache.maven.surefire.report.ReporterConfiguration;
27  import org.apache.maven.surefire.report.ReporterFactory;
28  import org.apache.maven.surefire.testset.DirectoryScannerParameters;
29  import org.apache.maven.surefire.testset.RunOrderParameters;
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.DefaultRunOrderCalculator;
34  import org.apache.maven.surefire.util.DirectoryScanner;
35  import org.apache.maven.surefire.util.RunOrderCalculator;
36  
37  /**
38   * @author Kristian Rosenvold
39   */
40  public class BaseProviderFactory
41      implements DirectoryScannerParametersAware, ReporterConfigurationAware, SurefireClassLoadersAware, TestRequestAware,
42      ProviderPropertiesAware, ProviderParameters, TestArtifactInfoAware, RunOrderParametersAware
43  {
44  
45      private Properties providerProperties;
46  
47      private DirectoryScannerParameters directoryScannerParameters;
48  
49      private ReporterConfiguration reporterConfiguration;
50  
51      private RunOrderParameters runOrderParameters;
52  
53      private ClassLoader testClassLoader;
54  
55      private TestRequest testRequest;
56  
57      private TestArtifactInfo testArtifactInfo;
58  
59      private static final Integer ROOT_CHANNEl = new Integer( 0 );
60  
61  
62      private final ReporterFactory reporterFactory;
63  
64      private final boolean insideFork;
65  
66  
67      public BaseProviderFactory( ReporterFactory reporterFactory, Boolean insideFork )
68      {
69          this.reporterFactory = reporterFactory;
70          this.insideFork = insideFork.booleanValue();
71      }
72  
73      public DirectoryScanner getDirectoryScanner()
74      {
75          if ( directoryScannerParameters == null )
76          {
77              return null;
78          }
79          return new DefaultDirectoryScanner( directoryScannerParameters.getTestClassesDirectory(),
80                                              directoryScannerParameters.getIncludes(),
81                                              directoryScannerParameters.getExcludes() );
82      }
83  
84      private int getThreadCount()
85      {
86          final String threadcount = (String) providerProperties.get( "threadcount" );
87          return threadcount == null ? 1 : Integer.parseInt( threadcount );
88      }
89  
90      public RunOrderCalculator getRunOrderCalculator()
91      {
92          if ( directoryScannerParameters == null )
93          {
94              return null;
95          }
96          return new DefaultRunOrderCalculator( runOrderParameters, getThreadCount() );
97      }
98  
99      public ReporterFactory getReporterFactory()
100     {
101         return reporterFactory;
102     }
103 
104     public void setDirectoryScannerParameters( DirectoryScannerParameters directoryScannerParameters )
105     {
106         this.directoryScannerParameters = directoryScannerParameters;
107     }
108 
109     public void setReporterConfiguration( ReporterConfiguration reporterConfiguration )
110     {
111         this.reporterConfiguration = reporterConfiguration;
112     }
113 
114     public void setClassLoaders( ClassLoader surefireClassLoader, ClassLoader testClassLoader )
115     {
116         this.testClassLoader = testClassLoader;
117     }
118 
119     public ConsoleLogger getConsoleLogger()
120     {
121         if ( insideFork )
122         {
123             return new ForkingRunListener( reporterConfiguration.getOriginalSystemOut(), ROOT_CHANNEl.intValue(),
124                                            reporterConfiguration.isTrimStackTrace().booleanValue() );
125         }
126         return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
127     }
128 
129     public void setTestRequest( TestRequest testRequest )
130     {
131         this.testRequest = testRequest;
132     }
133 
134     public DirectoryScannerParameters getDirectoryScannerParameters()
135     {
136         return directoryScannerParameters;
137     }
138 
139     public ReporterConfiguration getReporterConfiguration()
140     {
141         return reporterConfiguration;
142     }
143 
144     public TestRequest getTestRequest()
145     {
146         return testRequest;
147     }
148 
149     public ClassLoader getTestClassLoader()
150     {
151         return testClassLoader;
152     }
153 
154     public void setProviderProperties( Properties providerProperties )
155     {
156         this.providerProperties = providerProperties;
157     }
158 
159     public Properties getProviderProperties()
160     {
161         return providerProperties;
162     }
163 
164     public TestArtifactInfo getTestArtifactInfo()
165     {
166         return testArtifactInfo;
167     }
168 
169     public void setTestArtifactInfo( TestArtifactInfo testArtifactInfo )
170     {
171         this.testArtifactInfo = testArtifactInfo;
172     }
173 
174     public void setRunOrderParameters( RunOrderParameters runOrderParameters )
175     {
176         this.runOrderParameters = runOrderParameters;
177     }
178 
179 }