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.report.ReporterConfiguration;
23  import org.apache.maven.surefire.testset.DirectoryScannerParameters;
24  import org.apache.maven.surefire.testset.TestArtifactInfo;
25  import org.apache.maven.surefire.testset.TestRequest;
26  
27  import java.io.File;
28  import java.util.List;
29  import java.util.Properties;
30  
31  /**
32   * Represents the surefire configuration that passes all the way into the provider
33   * classloader and the provider.
34   * <p/>
35   *
36   * @author Jason van Zyl
37   * @author Emmanuel Venisse
38   * @author Kristian Rosenvold
39   * @version $Id$
40   */
41  public class ProviderConfiguration
42  {
43      /**
44       * @noinspection UnusedDeclaration
45       */
46      public static final int TESTS_SUCCEEDED_EXIT_CODE = 0;
47  
48      public static final int TESTS_FAILED_EXIT_CODE = 255;
49  
50      public static final int NO_TESTS_EXIT_CODE = 254;
51  
52      private final DirectoryScannerParameters dirScannerParams;
53  
54      private final ReporterConfiguration reporterConfiguration;
55  
56      private final TestArtifactInfo testArtifact;
57  
58      private final TestRequest testSuiteDefinition;
59  
60      private final Properties providerProperties;
61  
62      private final boolean failIfNoTests;
63  
64      private final Object forkTestSet;
65  
66      public ProviderConfiguration( DirectoryScannerParameters directoryScannerParameters, boolean failIfNoTests,
67                                    ReporterConfiguration reporterConfiguration, TestArtifactInfo testArtifact,
68                                    TestRequest testSuiteDefinition, Properties providerProperties, Object forkTestSet )
69      {
70          this.providerProperties = providerProperties;
71          this.reporterConfiguration = reporterConfiguration;
72          this.testArtifact = testArtifact;
73          this.testSuiteDefinition = testSuiteDefinition;
74          this.dirScannerParams = directoryScannerParameters;
75          this.failIfNoTests = failIfNoTests;
76          this.forkTestSet = forkTestSet;
77      }
78  
79  
80      public ReporterConfiguration getReporterConfiguration()
81      {
82          return reporterConfiguration;
83      }
84  
85  
86      public Boolean isFailIfNoTests()
87      {
88          return ( failIfNoTests ) ? Boolean.TRUE : Boolean.FALSE;
89      }
90  
91      public File getBaseDir()
92      {
93          return dirScannerParams.getTestClassesDirectory();
94      }
95  
96  
97      public DirectoryScannerParameters getDirScannerParams()
98      {
99          return dirScannerParams;
100     }
101 
102     public Object[] getDirScannerParamsArray()
103     {
104         if ( dirScannerParams == null )
105         {
106             return null;
107         }
108         return new Object[]{ dirScannerParams.getTestClassesDirectory(), dirScannerParams.getIncludes(),
109             dirScannerParams.getExcludes() };
110     }
111 
112     public List getIncludes()
113     {
114         return dirScannerParams.getIncludes();
115     }
116 
117     public List getExcludes()
118     {
119         return dirScannerParams.getExcludes();
120     }
121 
122     public TestArtifactInfo getTestArtifact()
123     {
124         return testArtifact;
125     }
126 
127     public TestRequest getTestSuiteDefinition()
128     {
129         return testSuiteDefinition;
130     }
131 
132     public Properties getProviderProperties()
133     {
134         return providerProperties;
135     }
136 
137     public Object getTestForFork()
138     {
139         return forkTestSet;
140     }
141 
142     public String getTestForForkString()
143     {
144         if ( forkTestSet instanceof File )
145         {
146             return forkTestSet.toString();
147         }
148         return (String) forkTestSet;
149     }
150 
151     public boolean isSurefireForkReturnCode( int returnCode )
152     {
153         return TESTS_SUCCEEDED_EXIT_CODE == returnCode ||
154                NO_TESTS_EXIT_CODE == returnCode ||
155             TESTS_FAILED_EXIT_CODE == returnCode;
156 
157     }
158 
159 
160 }