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