* @throws CompilerException
*/
List compileOutOfProcess( CompilerConfiguration config, String executable, String[] args )
throws CompilerException
{
Commandline cli = new Commandline();
cli.setWorkingDirectory( config.getWorkingDirectory().getAbsolutePath() );
cli.setExecutable( executable );
try
{
File argumentsFile = createFileWithArguments( args, config.getOutputLocation() );
cli.addArguments( new String[] { "@" + argumentsFile.getCanonicalPath().replace( File.separatorChar, '/' ) } );
if ( !StringUtils.isEmpty( config.getMaxmem() ) )
{
cli.addArguments( new String[] { "-J-Xmx" + config.getMaxmem() } );
}
if ( !StringUtils.isEmpty( config.getMeminitial() ) )
{
cli.addArguments( new String[] { "-J-Xms" + config.getMeminitial() } );
}
}
catch ( IOException e )
{
throw new CompilerException( "Error creating file with javac arguments", e );
}
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int returnCode;
List messages;
if ( ( getLogger() != null ) && getLogger().isDebugEnabled() )
{
File commandLineFile =
new File( config.getOutputLocation(), "javac." + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? "bat" : "sh" ) );
try
{
FileUtils.fileWrite( commandLineFile.getAbsolutePath(),
cli.toString().replaceAll( "'", "" ) );
if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
{
Runtime.getRuntime().exec( new String[] { "chmod", "a+x", commandLineFile.getAbsolutePath() } );
}
}
catch ( IOException e )
{
if ( ( getLogger() != null ) && getLogger().isWarnEnabled() )
{
getLogger().warn( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
}
}
}
try
{
returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
messages = parseModernStream( returnCode, new BufferedReader( new StringReader( err.getOutput() ) ) );
}
catch ( CommandLineException e )
{
throw new CompilerException( "Error while executing the external compiler.", e );
}
catch ( IOException e )
{
throw new CompilerException( "Error while executing the external compiler.", e );
}
if ( ( returnCode != 0 ) && messages.isEmpty() )
{
if ( err.getOutput().length() == 0 )
{
throw new CompilerException( "Unknown error trying to execute the external compiler: " + EOL
+ cli.toString() );
}
else
{
messages.add( new CompilerError( "Failure executing javac, but could not parse the error:" + EOL
+ err.getOutput(), true ) );