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.FileInputStream; 24 import java.io.InputStream; 25 import org.apache.maven.surefire.suite.RunResult; 26 27 /** 28 * The part of the booter that is unique to a forked vm. 29 * <p/> 30 * Deals with deserialization of the booter wire-level protocol 31 * <p/> 32 * Todo: Look at relationship between this class and BooterSerializer (BooterDeserializer?) 33 * 34 * @author Jason van Zyl 35 * @author Emmanuel Venisse 36 * @author Kristian Rosenvold 37 * @version $Id$ 38 */ 39 public class ForkedBooter 40 { 41 42 /** 43 * This method is invoked when Surefire is forked - this method parses and organizes the arguments passed to it and 44 * then calls the Surefire class' run method. <p/> The system exit code will be 1 if an exception is thrown. 45 * 46 * @param args Commandline arguments 47 * @throws Throwable Upon throwables 48 */ 49 public static void main( String[] args ) 50 throws Throwable 51 { 52 try 53 { 54 if ( args.length > 1 ) 55 { 56 SystemPropertyManager.setSystemProperties( new File( args[1] ) ); 57 } 58 59 File surefirePropertiesFile = new File( args[0] ); 60 InputStream stream = surefirePropertiesFile.exists() ? new FileInputStream( surefirePropertiesFile ) : null; 61 BooterDeserializer booterDeserializer = new BooterDeserializer( stream ); 62 ProviderConfiguration booterConfiguration = booterDeserializer.deserialize(); 63 final StartupConfiguration providerConfiguration = booterDeserializer.getProviderConfiguration(); 64 65 SurefireStarter starter = new SurefireStarter( providerConfiguration, booterConfiguration, null ); 66 67 TypeEncodedValue forkedTestSet = booterConfiguration.getTestForFork(); 68 final RunResult result = forkedTestSet != null 69 ? starter.runSuitesInProcessWhenForked( forkedTestSet ) 70 : starter.runSuitesInProcessWhenForked(); 71 72 // noinspection CallToSystemExit 73 System.exit( result.getBooterCode() ); 74 } 75 catch ( Throwable t ) 76 { 77 // Just throwing does getMessage() and a local trace - we want to call printStackTrace for a full trace 78 // noinspection UseOfSystemOutOrSystemErr 79 t.printStackTrace( System.err ); 80 // noinspection ProhibitedExceptionThrown,CallToSystemExit 81 System.exit( 1 ); 82 } 83 } 84 }