// ----------------------------------------------------------------------
// Create the compiler configuration
// ----------------------------------------------------------------------
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.setOutputLocation( getOutputDirectory().getAbsolutePath() );
compilerConfiguration.setClasspathEntries( getClasspathElements() );
compilerConfiguration.setSourceLocations( compileSourceRoots );
compilerConfiguration.setOptimize( optimize );
compilerConfiguration.setDebug( debug );
compilerConfiguration.setVerbose( verbose );
compilerConfiguration.setShowWarnings( showWarnings );
compilerConfiguration.setShowDeprecation( showDeprecation );
compilerConfiguration.setSourceVersion( source );
compilerConfiguration.setTargetVersion( target );
compilerConfiguration.setSourceEncoding( encoding );
if (( compilerArguments != null ) || ( compilerArgument != null ))
{
LinkedHashMap cplrArgsCopy = new LinkedHashMap();
if ( compilerArguments != null )
{
for ( Iterator i = compilerArguments.entrySet().iterator(); i.hasNext(); )
{
Map.Entry me = (Map.Entry) i.next();
String key = (String) me.getKey();
String value = (String) me.getValue();
if ( !key.startsWith( "-" ))
{
key = "-" + key;
}
cplrArgsCopy.put( key, value );
}
}
if ( !StringUtils.isEmpty( compilerArgument) )
{
cplrArgsCopy.put( compilerArgument, null );
}
compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
}
compilerConfiguration.setFork( fork );
if( fork )
{
if ( !StringUtils.isEmpty( meminitial ) )
{
String value = getMemoryValue( meminitial );
if ( value != null )
{
compilerConfiguration.setMeminitial( value );
}
else
{
getLog().info( "Invalid value for meminitial '" + meminitial + "'. Ignoring this option." );
}
}
if ( !StringUtils.isEmpty( maxmem ) )
{
String value = getMemoryValue( maxmem );
if ( value != null )
{
compilerConfiguration.setMaxmem( value );
}
else
{
getLog().info( "Invalid value for maxmem '" + maxmem + "'. Ignoring this option." );
}
}
}
compilerConfiguration.setExecutable( executable );
compilerConfiguration.setWorkingDirectory( basedir );
compilerConfiguration.setCompilerVersion( compilerVersion );
compilerConfiguration.setBuildDirectory( buildDirectory );
compilerConfiguration.setOutputFileName( outputFileName );
// TODO: have an option to always compile (without need to clean)
Set staleSources;
boolean canUpdateTarget;
try
{
staleSources =
computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) );
canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration );
if ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) &&
!canUpdateTarget )
{
getLog().info( "RESCANNING!" );
// TODO: This second scan for source files is sub-optimal
String inputFileEnding = compiler.getInputFileEnding( compilerConfiguration );
Set sources = computeStaleSources( compilerConfiguration, compiler,
getSourceInclusionScanner( inputFileEnding ) );
compilerConfiguration.setSourceFiles( sources );
}
else
{
compilerConfiguration.setSourceFiles( staleSources );
}
}
catch ( CompilerException e )
{
throw new MojoExecutionException( "Error while computing stale sources.", e );
}
if ( staleSources.isEmpty() )
{
getLog().info( "Nothing to compile - all classes are up to date" );
return;
}
// ----------------------------------------------------------------------
// Dump configuration
// ----------------------------------------------------------------------
if ( getLog().isDebugEnabled() )
{
getLog().debug( "Classpath:" );
for ( Iterator it = getClasspathElements().iterator(); it.hasNext(); )
{
String s = (String) it.next();
getLog().debug( " " + s );
}
getLog().debug( "Source roots:" );
for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); )
{
String root = (String) it.next();
getLog().debug( " " + root );
}
if ( fork )
{
try
{
if ( compilerConfiguration.getExecutable() != null )
{
getLog().debug( "Excutable: " );
getLog().debug( " " + compilerConfiguration.getExecutable() );
}
String[] cl = compiler.createCommandLine( compilerConfiguration );
if ( cl != null && cl.length > 0 )
{