throws MojoFailureException, MojoExecutionException
{
String name = getName();
if (name == null) return null;
CompilerDef compiler = new CompilerDef();
compiler.setProject( mojo.getAntProject() );
CompilerEnum compilerName = new CompilerEnum();
compilerName.setValue( name );
compiler.setName( compilerName );
// tool path
if ( toolPath != null )
{
compiler.setToolPath( toolPath );
}
// debug, exceptions, rtti, multiThreaded
compiler.setDebug( debug );
compiler.setExceptions( exceptions );
compiler.setRtti( rtti );
compiler.setMultithreaded( mojo.getOS().equals( "Windows" ) ? true : multiThreaded );
// optimize
OptimizationEnum optimization = new OptimizationEnum();
optimization.setValue( optimize );
compiler.setOptimize( optimization );
// add options
if ( options != null )
{
for ( Iterator<String> i = options.iterator(); i.hasNext(); )
{
CompilerArgument arg = new CompilerArgument();
arg.setValue( (String) i.next() );
compiler.addConfiguredCompilerArg( arg );
}
}
if ( optionSet != null )
{
String[] opts = optionSet.split( "\\s" );
for ( int i = 0; i < opts.length; i++ )
{
CompilerArgument arg = new CompilerArgument();
arg.setValue( opts[i] );
compiler.addConfiguredCompilerArg( arg );
}
}
compiler.setClearDefaultOptions(clearDefaultOptions);
if ( !clearDefaultOptions )
{
String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" );
if ( optionsProperty != null )
{
String[] option = optionsProperty.split( " " );
for ( int i = 0; i < option.length; i++ )
{
CompilerArgument arg = new CompilerArgument();
arg.setValue( option[i] );
compiler.addConfiguredCompilerArg( arg );
}
}
}
// add defines
if ( defines != null )
{
DefineSet ds = new DefineSet();
for ( Iterator<String> i = defines.iterator(); i.hasNext(); )
{
DefineArgument define = new DefineArgument();
String[] pair = i.next().split( "=", 2 );
define.setName( pair[0] );
define.setValue( pair.length > 1 ? pair[1] : null );
ds.addDefine( define );
}
compiler.addConfiguredDefineset( ds );
}
if ( defineSet != null )
{
String[] defList = defineSet.split( "," );
DefineSet defSet = new DefineSet();
for ( int i = 0; i < defList.length; i++ )
{
String[] pair = defList[i].trim().split( "=", 2 );
DefineArgument def = new DefineArgument();
def.setName( pair[0] );
def.setValue( pair.length > 1 ? pair[1] : null );
defSet.addDefine( def );
}
compiler.addConfiguredDefineset( defSet );
}
if ( !clearDefaultDefines )
{
DefineSet ds = new DefineSet();
String defaultDefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "defines" );
if ( defaultDefines != null )
{
ds.setDefine( new CUtil.StringArrayBuilder( defaultDefines ) );
}
compiler.addConfiguredDefineset( ds );
}
// add undefines
if ( undefines != null )
{
DefineSet us = new DefineSet();
for ( Iterator<String> i = undefines.iterator(); i.hasNext(); )
{
DefineArgument undefine = new DefineArgument();
String[] pair = i.next().split( "=", 2 );
undefine.setName( pair[0] );
undefine.setValue( pair.length > 1 ? pair[1] : null );
us.addUndefine( undefine );
}
compiler.addConfiguredDefineset( us );
}
if ( undefineSet != null )
{
String[] undefList = undefineSet.split( "," );
DefineSet undefSet = new DefineSet();
for ( int i = 0; i < undefList.length; i++ )
{
String[] pair = undefList[i].trim().split( "=", 2 );
DefineArgument undef = new DefineArgument();
undef.setName( pair[0] );
undef.setValue( pair.length > 1 ? pair[1] : null );
undefSet.addUndefine( undef );
}
compiler.addConfiguredDefineset( undefSet );
}
if ( !clearDefaultUndefines )
{
DefineSet us = new DefineSet();
String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" );
if ( defaultUndefines != null )
{
us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) );
}
compiler.addConfiguredDefineset( us );
}
// add include path
for ( Iterator<IncludePath> i = getIncludePaths( type ).iterator(); i.hasNext(); )
{
IncludePath includePath = i.next();
// Darren Sargent, 30Jan2008 - fail build if invalid include path(s) specified.
if ( ! includePath.exists() ) {
throw new MojoFailureException("NAR: Include path not found: " + includePath);
}
compiler.createIncludePath().setPath( includePath.getPath() );
}
// add system include path (at the end)
if ( systemIncludePaths != null )
{
for ( Iterator<String> i = systemIncludePaths.iterator(); i.hasNext(); )
{
String path = i.next();
compiler.createSysIncludePath().setPath( path );
}
}
// Add default fileset (if exists)
List<File> srcDirs = getSourceDirectories( type );
Set<String> includeSet = getIncludes( type );
Set<String> excludeSet = getExcludes( type );
// now add all but the current test to the excludes
for ( Iterator i = mojo.getTests().iterator(); i.hasNext(); )
{
Test test = (Test) i.next();
if ( !test.getName().equals( output ) )
{
excludeSet.add( "**/" + test.getName() + ".*" );
}
}
for ( Iterator<File> i = srcDirs.iterator(); i.hasNext(); )
{
File srcDir = i.next();
mojo.getLog().debug( "Checking for existence of " + getLanguage() + " source directory: " + srcDir );
if ( srcDir.exists() )
{
if ( compileOrder != null )
{
compiler.setOrder( Arrays.asList( StringUtils.split( compileOrder, ", " ) ) );
}
ConditionalFileSet fileSet = new ConditionalFileSet();
fileSet.setProject( mojo.getAntProject() );
fileSet.setIncludes( StringUtils.join( includeSet.iterator(), "," ) );
fileSet.setExcludes( StringUtils.join( excludeSet.iterator(), "," ) );
fileSet.setDir( srcDir );
compiler.addFileset( fileSet );
}
}
return compiler;
}