@ SuppressForbidden ( "legitimate sysstreams." ) private Execute forkProcess ( ForkedJvmInfo slaveInfo , EventBus eventBus , CommandlineJava commandline , TailInputStream eventStream , OutputStream sysout , OutputStream syserr , RandomAccessFile streamsBuffer ) { try { String tempDir = commandline . getSystemProperties ( ) . getVariablesVector ( ) . stream ( ) . filter ( v -> v . getKey ( ) . equals ( "java.io.tmpdir" ) ) . map ( v -> v . getValue ( ) ) . findAny ( ) . orElse ( null ) ; final LocalSlaveStreamHandler streamHandler = new LocalSlaveStreamHandler ( eventBus , testsClassLoader , System . err , eventStream , sysout , syserr , heartbeat , streamsBuffer ) ; // Add certain properties to allow identification of the forked JVM from within // the subprocess. This can be used for policy files etc. final Path cwd = getWorkingDirectory ( slaveInfo , tempDir ) ; Variable v = new Variable ( ) ; v . setKey ( CHILDVM_SYSPROP_CWD ) ; v . setFile ( cwd . toAbsolutePath ( ) . normalize ( ) . toFile ( ) ) ; commandline . addSysproperty ( v ) ; v = new Variable ( ) ; v . setKey ( SYSPROP_TEMPDIR ) ; v . setFile ( getTempDir ( ) . toAbsolutePath ( ) . normalize ( ) . toFile ( ) ) ; commandline . addSysproperty ( v ) ; v = new Variable ( ) ; v . setKey ( SysGlobals . CHILDVM_SYSPROP_JVM_ID ) ; v . setValue ( Integer . toString ( slaveInfo . id ) ) ; commandline . addSysproperty ( v ) ; v = new Variable ( ) ; v . setKey ( SysGlobals . CHILDVM_SYSPROP_JVM_COUNT ) ; v . setValue ( Integer . toString ( slaveInfo . slaves ) ) ; commandline . addSysproperty ( v ) ; // Emit command line before -stdin to avoid confusion. slaveInfo . slaveCommandLine = escapeAndJoin ( commandline . getCommandline ( ) ) ; log ( "Forked child JVM at '" + cwd . toAbsolutePath ( ) . normalize ( ) + "', command (may need escape sequences for your shell):\n" + slaveInfo . slaveCommandLine , Project . MSG_VERBOSE ) ; final Execute execute = new Execute ( ) ; execute . setCommandline ( commandline . getCommandline ( ) ) ; execute . setVMLauncher ( true ) ; execute . setWorkingDirectory ( cwd . toFile ( ) ) ; execute . setStreamHandler ( streamHandler ) ; execute . setNewenvironment ( newEnvironment ) ; if ( env . getVariables ( ) != null ) execute . setEnvironment ( env . getVariables ( ) ) ; log ( "Starting JVM J" + slaveInfo . id , Project . MSG_DEBUG ) ; execute . execute ( ) ; return execute ; } catch ( IOException e ) { throw new BuildException ( "Could not start the child process. Run ant with -verbose to get" + " the execution details." , e ) ; } }
Execute a slave process . Pump events to the given event bus .