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.io.File;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.util.List;
26  import org.apache.maven.surefire.report.ReporterConfiguration;
27  import org.apache.maven.surefire.testset.DirectoryScannerParameters;
28  import org.apache.maven.surefire.testset.RunOrderParameters;
29  import org.apache.maven.surefire.testset.TestArtifactInfo;
30  import org.apache.maven.surefire.testset.TestRequest;
31  
32  // CHECKSTYLE_OFF: imports
33  import static org.apache.maven.surefire.booter.BooterConstants.*;
34  
35  /**
36   * Knows how to serialize and deserialize the booter configuration.
37   * <p/>
38   * The internal serialization format is through a properties file. The long-term goal of this
39   * class is not to expose this implementation information to its clients. This still leaks somewhat,
40   * and there are some cases where properties are being accessed as "Properties" instead of
41   * more representative domain objects.
42   * <p/>
43   *
44   * @author Jason van Zyl
45   * @author Emmanuel Venisse
46   * @author Kristian Rosenvold
47   */
48  public class BooterDeserializer
49  {
50  
51  
52      private final PropertiesWrapper properties;
53  
54      public BooterDeserializer( InputStream inputStream )
55          throws IOException
56      {
57          properties = SystemPropertyManager.loadProperties( inputStream );
58      }
59  
60      public ProviderConfiguration deserialize()
61      {
62          final File reportsDirectory = new File( properties.getProperty( REPORTSDIRECTORY ) );
63          final String testNgVersion = properties.getProperty( TESTARTIFACT_VERSION );
64          final String testArtifactClassifier = properties.getProperty( TESTARTIFACT_CLASSIFIER );
65  
66          final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue( FORKTESTSET );
67          final boolean preferTestsFromInStream =
68              properties.getBooleanProperty( FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM );
69  
70          final String requestedTest = properties.getProperty( REQUESTEDTEST );
71          final String requestedTestMethod = properties.getProperty( REQUESTEDTESTMETHOD );
72          final File sourceDirectory = properties.getFileProperty( SOURCE_DIRECTORY );
73  
74          final List excludesList = properties.getStringList( EXCLUDES_PROPERTY_PREFIX );
75          final List includesList = properties.getStringList( INCLUDES_PROPERTY_PREFIX );
76          final List specificTestsList = properties.getStringList( SPECIFIC_TEST_PROPERTY_PREFIX );
77  
78          final List testSuiteXmlFiles = properties.getStringList( TEST_SUITE_XML_FILES );
79          final File testClassesDirectory = properties.getFileProperty( TEST_CLASSES_DIRECTORY );
80          final String runOrder = properties.getProperty( RUN_ORDER );
81          final String runStatisticsFile = properties.getProperty( RUN_STATISTICS_FILE );
82  
83          final int rerunFailingTestsCount = properties.getIntProperty( RERUN_FAILING_TESTS_COUNT );
84  
85          DirectoryScannerParameters dirScannerParams =
86              new DirectoryScannerParameters( testClassesDirectory, includesList, excludesList, specificTestsList,
87                                              properties.getBooleanObjectProperty( FAILIFNOTESTS ), runOrder );
88  
89          RunOrderParameters runOrderParameters = new RunOrderParameters( runOrder, runStatisticsFile );
90  
91          TestArtifactInfo testNg = new TestArtifactInfo( testNgVersion, testArtifactClassifier );
92          TestRequest testSuiteDefinition =
93              new TestRequest( testSuiteXmlFiles, sourceDirectory, requestedTest, requestedTestMethod,
94                               rerunFailingTestsCount );
95  
96          ReporterConfiguration reporterConfiguration =
97              new ReporterConfiguration( reportsDirectory, properties.getBooleanObjectProperty( ISTRIMSTACKTRACE ) );
98  
99          return new ProviderConfiguration( dirScannerParams, runOrderParameters,
100                                           properties.getBooleanProperty( FAILIFNOTESTS ), reporterConfiguration, testNg,
101                                           testSuiteDefinition, properties.getProperties(), typeEncodedTestForFork,
102                                           preferTestsFromInStream );
103     }
104 
105     public StartupConfiguration getProviderConfiguration()
106     {
107         boolean useSystemClassLoader = properties.getBooleanProperty( USESYSTEMCLASSLOADER );
108         boolean useManifestOnlyJar = properties.getBooleanProperty( USEMANIFESTONLYJAR );
109         String providerConfiguration = properties.getProperty( PROVIDER_CONFIGURATION );
110 
111         ClassLoaderConfiguration classLoaderConfiguration =
112             new ClassLoaderConfiguration( useSystemClassLoader, useManifestOnlyJar );
113 
114         ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( properties );
115 
116         return StartupConfiguration.inForkedVm( providerConfiguration, classpathConfiguration,
117                                                 classLoaderConfiguration );
118     }
119 }