View Javadoc
1   package org.apache.maven.surefire.api.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 org.apache.maven.surefire.api.cli.CommandLineOption;
23  import org.apache.maven.surefire.api.provider.CommandChainReader;
24  import org.apache.maven.surefire.api.provider.ProviderParameters;
25  import org.apache.maven.surefire.api.report.ReporterConfiguration;
26  import org.apache.maven.surefire.api.report.ReporterFactory;
27  import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
28  import org.apache.maven.surefire.api.testset.RunOrderParameters;
29  import org.apache.maven.surefire.api.testset.TestArtifactInfo;
30  import org.apache.maven.surefire.api.testset.TestRequest;
31  import org.apache.maven.surefire.api.util.DefaultDirectoryScanner;
32  import org.apache.maven.surefire.api.util.DefaultRunOrderCalculator;
33  import org.apache.maven.surefire.api.util.DefaultScanResult;
34  import org.apache.maven.surefire.api.util.DirectoryScanner;
35  import org.apache.maven.surefire.api.util.RunOrderCalculator;
36  import org.apache.maven.surefire.api.util.ScanResult;
37  
38  import java.util.Collections;
39  import java.util.List;
40  import java.util.Map;
41  
42  import static java.util.Collections.emptyList;
43  
44  /**
45   * @author Kristian Rosenvold
46   */
47  public class BaseProviderFactory
48      implements ProviderParameters
49  {
50      private final boolean insideFork;
51  
52      private ReporterFactory reporterFactory;
53  
54      private List<CommandLineOption> mainCliOptions = emptyList();
55  
56      private Map<String, String> providerProperties;
57  
58      private DirectoryScannerParameters directoryScannerParameters;
59  
60      private ReporterConfiguration reporterConfiguration;
61  
62      private RunOrderParameters runOrderParameters;
63  
64      private ClassLoader testClassLoader;
65  
66      private TestRequest testRequest;
67  
68      private TestArtifactInfo testArtifactInfo;
69  
70      private int skipAfterFailureCount;
71  
72      private Integer systemExitTimeout;
73  
74      private CommandChainReader commandReader;
75  
76      public BaseProviderFactory( boolean insideFork )
77      {
78          this.insideFork = insideFork;
79      }
80  
81      @Override
82      public CommandChainReader getCommandReader()
83      {
84          return commandReader;
85      }
86  
87      public void setCommandReader( CommandChainReader commandReader )
88      {
89          this.commandReader = commandReader;
90      }
91  
92      @Override
93      @Deprecated
94      public DirectoryScanner getDirectoryScanner()
95      {
96          return directoryScannerParameters == null
97                  ? null : new DefaultDirectoryScanner( directoryScannerParameters.getTestClassesDirectory(),
98                                              directoryScannerParameters.getIncludes(),
99                                              directoryScannerParameters.getExcludes(),
100                                             directoryScannerParameters.getSpecificTests() );
101     }
102 
103     @Override
104     public ScanResult getScanResult()
105     {
106         return DefaultScanResult.from( providerProperties );
107     }
108 
109     private int getThreadCount()
110     {
111         final String threadcount = providerProperties.get( ProviderParameterNames.THREADCOUNT_PROP );
112         return threadcount == null ? 1 : Math.max( Integer.parseInt( threadcount ), 1 );
113     }
114 
115     @Override
116     public RunOrderCalculator getRunOrderCalculator()
117     {
118         return new DefaultRunOrderCalculator( runOrderParameters, getThreadCount() );
119     }
120 
121     public void setReporterFactory( ReporterFactory reporterFactory )
122     {
123         this.reporterFactory = reporterFactory;
124     }
125 
126     @Override
127     public ReporterFactory getReporterFactory()
128     {
129         return reporterFactory;
130     }
131 
132     public void setDirectoryScannerParameters( DirectoryScannerParameters directoryScannerParameters )
133     {
134         this.directoryScannerParameters = directoryScannerParameters;
135     }
136 
137     public void setReporterConfiguration( ReporterConfiguration reporterConfiguration )
138     {
139         this.reporterConfiguration = reporterConfiguration;
140     }
141 
142     public void setClassLoaders( ClassLoader testClassLoader )
143     {
144         this.testClassLoader = testClassLoader;
145     }
146 
147     public void setTestRequest( TestRequest testRequest )
148     {
149         this.testRequest = testRequest;
150     }
151 
152     @Override
153     public DirectoryScannerParameters getDirectoryScannerParameters()
154     {
155         return directoryScannerParameters;
156     }
157 
158     @Override
159     public ReporterConfiguration getReporterConfiguration()
160     {
161         return reporterConfiguration;
162     }
163 
164     @Override
165     public TestRequest getTestRequest()
166     {
167         return testRequest;
168     }
169 
170     @Override
171     public ClassLoader getTestClassLoader()
172     {
173         return testClassLoader;
174     }
175 
176     public void setProviderProperties( Map<String, String> providerProperties )
177     {
178         this.providerProperties = providerProperties;
179     }
180 
181     @Override
182     public Map<String, String> getProviderProperties()
183     {
184         return providerProperties;
185     }
186 
187     @Override
188     public TestArtifactInfo getTestArtifactInfo()
189     {
190         return testArtifactInfo;
191     }
192 
193     public void setTestArtifactInfo( TestArtifactInfo testArtifactInfo )
194     {
195         this.testArtifactInfo = testArtifactInfo;
196     }
197 
198     public void setRunOrderParameters( RunOrderParameters runOrderParameters )
199     {
200         this.runOrderParameters = runOrderParameters;
201     }
202 
203     @Override
204     public List<CommandLineOption> getMainCliOptions()
205     {
206         return mainCliOptions;
207     }
208 
209     /**
210      * CLI options in plugin (main) JVM process.
211      *
212      * @param mainCliOptions options
213      */
214     public void setMainCliOptions( List<CommandLineOption> mainCliOptions )
215     {
216         this.mainCliOptions = mainCliOptions == null ? Collections.<CommandLineOption>emptyList() : mainCliOptions;
217     }
218 
219     @Override
220     public int getSkipAfterFailureCount()
221     {
222         return skipAfterFailureCount;
223     }
224 
225     /**
226      * See the plugin configuration parameter "skipAfterFailureCount".
227      *
228      * @param skipAfterFailureCount the value in config parameter "skipAfterFailureCount"
229      */
230     public void setSkipAfterFailureCount( int skipAfterFailureCount )
231     {
232         this.skipAfterFailureCount = skipAfterFailureCount;
233     }
234 
235     @Override
236     public boolean isInsideFork()
237     {
238         return insideFork;
239     }
240 
241     @Override
242     public Integer getSystemExitTimeout()
243     {
244         return systemExitTimeout;
245     }
246 
247     public void setSystemExitTimeout( Integer systemExitTimeout )
248     {
249         this.systemExitTimeout = systemExitTimeout;
250     }
251 }