diff --git a/src/main/java/com/github/maven_nar/Compiler.java b/src/main/java/com/github/maven_nar/Compiler.java index 609119918..c0ac3ced4 100644 --- a/src/main/java/com/github/maven_nar/Compiler.java +++ b/src/main/java/com/github/maven_nar/Compiler.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -46,7 +46,7 @@ /** * Abstract Compiler class - * + * * @author Mark Donszelmann */ public abstract class Compiler @@ -55,7 +55,6 @@ public abstract class Compiler /** * The name of the compiler. Some choices are: "msvc", "g++", "gcc", "CC", "cc", "icc", "icpc", ... Default is * Architecture-OS-Linker specific: FIXME: table missing - */ @Parameter private String name; @@ -349,7 +348,7 @@ else if ( type.equals( TEST ) && !testIncludes.isEmpty() ) String defaultIncludes = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "includes" ); if ( defaultIncludes != null ) { - String[] include = defaultIncludes.split( " " ); + String[] include = defaultIncludes.split( "[\\s]+" ); for ( int i = 0; i < include.length; i++ ) { result.add( include[i].trim() ); @@ -382,7 +381,7 @@ else if ( !excludes.isEmpty() ) String defaultExcludes = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "excludes" ); if ( defaultExcludes != null ) { - String[] exclude = defaultExcludes.split( " " ); + String[] exclude = defaultExcludes.split( "[\\s]+" ); for ( int i = 0; i < exclude.length; i++ ) { result.add( exclude[i].trim() ); @@ -423,7 +422,7 @@ public final CompilerDef getCompiler( String type, String output ) { String name = getName(); if (name == null) return null; - + CompilerDef compiler = new CompilerDef(); compiler.setProject( mojo.getAntProject() ); CompilerEnum compilerName = new CompilerEnum(); @@ -448,6 +447,22 @@ public final CompilerDef getCompiler( String type, String output ) compiler.setOptimize( optimization ); // add options + compiler.setClearDefaultOptions(clearDefaultOptions); + if ( !clearDefaultOptions ) + { + String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" ); + if ( optionsProperty != null ) + { + String[] option = optionsProperty.split( "[\\s]+" ); + for ( int i = 0; i < option.length; i++ ) + { + CompilerArgument arg = new CompilerArgument(); + arg.setValue( option[i] ); + compiler.addConfiguredCompilerArg( arg ); + } + } + } + if ( options != null ) { for ( Iterator i = options.iterator(); i.hasNext(); ) @@ -461,7 +476,7 @@ public final CompilerDef getCompiler( String type, String output ) if ( optionSet != null ) { - String[] opts = optionSet.split( "\\s" ); + String[] opts = optionSet.split( "[\\s]+" ); for ( int i = 0; i < opts.length; i++ ) { @@ -473,58 +488,54 @@ public final CompilerDef getCompiler( String type, String output ) } } - compiler.setClearDefaultOptions(clearDefaultOptions); - if ( !clearDefaultOptions ) + // add undefines + if ( !clearDefaultUndefines ) { - String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" ); - if ( optionsProperty != null ) + DefineSet us = new DefineSet(); + String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" ); + if ( defaultUndefines != null ) { - String[] option = optionsProperty.split( " " ); - for ( int i = 0; i < option.length; i++ ) - { - CompilerArgument arg = new CompilerArgument(); - arg.setValue( option[i] ); - compiler.addConfiguredCompilerArg( arg ); - } + us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) ); } + compiler.addConfiguredDefineset( us ); } - // add defines - if ( defines != null ) + if ( undefines != null ) { - DefineSet ds = new DefineSet(); - for ( Iterator i = defines.iterator(); i.hasNext(); ) + DefineSet us = new DefineSet(); + for ( Iterator i = undefines.iterator(); i.hasNext(); ) { - DefineArgument define = new DefineArgument(); + DefineArgument undefine = new DefineArgument(); String[] pair = i.next().split( "=", 2 ); - define.setName( pair[0] ); - define.setValue( pair.length > 1 ? pair[1] : null ); - ds.addDefine( define ); + undefine.setName( pair[0] ); + undefine.setValue( pair.length > 1 ? pair[1] : null ); + us.addUndefine( undefine ); } - compiler.addConfiguredDefineset( ds ); + compiler.addConfiguredDefineset( us ); } - if ( defineSet != null ) + if ( undefineSet != null ) { - String[] defList = defineSet.split( "," ); - DefineSet defSet = new DefineSet(); + String[] undefList = undefineSet.split( ",[\\s]*" ); + DefineSet undefSet = new DefineSet(); - for ( int i = 0; i < defList.length; i++ ) + for ( int i = 0; i < undefList.length; i++ ) { - String[] pair = defList[i].trim().split( "=", 2 ); - DefineArgument def = new DefineArgument(); + String[] pair = undefList[i].trim().split( "=", 2 ); + DefineArgument undef = new DefineArgument(); - def.setName( pair[0] ); - def.setValue( pair.length > 1 ? pair[1] : null ); + undef.setName( pair[0] ); + undef.setValue( pair.length > 1 ? pair[1] : null ); - defSet.addDefine( def ); + undefSet.addUndefine( undef ); } - compiler.addConfiguredDefineset( defSet ); + compiler.addConfiguredDefineset( undefSet ); } + // add defines if ( !clearDefaultDefines ) { DefineSet ds = new DefineSet(); @@ -536,51 +547,39 @@ public final CompilerDef getCompiler( String type, String output ) compiler.addConfiguredDefineset( ds ); } - // add undefines - if ( undefines != null ) + if ( defines != null ) { - DefineSet us = new DefineSet(); - for ( Iterator i = undefines.iterator(); i.hasNext(); ) + DefineSet ds = new DefineSet(); + for ( Iterator i = defines.iterator(); i.hasNext(); ) { - DefineArgument undefine = new DefineArgument(); + DefineArgument define = new DefineArgument(); String[] pair = i.next().split( "=", 2 ); - undefine.setName( pair[0] ); - undefine.setValue( pair.length > 1 ? pair[1] : null ); - us.addUndefine( undefine ); + define.setName( pair[0] ); + define.setValue( pair.length > 1 ? pair[1] : null ); + ds.addDefine( define ); } - compiler.addConfiguredDefineset( us ); + compiler.addConfiguredDefineset( ds ); } - if ( undefineSet != null ) + if ( defineSet != null ) { - String[] undefList = undefineSet.split( "," ); - DefineSet undefSet = new DefineSet(); + String[] defList = defineSet.split( ",[\\s]*" ); + DefineSet defSet = new DefineSet(); - for ( int i = 0; i < undefList.length; i++ ) + for ( int i = 0; i < defList.length; i++ ) { - String[] pair = undefList[i].trim().split( "=", 2 ); - DefineArgument undef = new DefineArgument(); + String[] pair = defList[i].trim().split( "=", 2 ); + DefineArgument def = new DefineArgument(); - undef.setName( pair[0] ); - undef.setValue( pair.length > 1 ? pair[1] : null ); + def.setName( pair[0] ); + def.setValue( pair.length > 1 ? pair[1] : null ); - undefSet.addUndefine( undef ); + defSet.addDefine( def ); } - 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 ); + compiler.addConfiguredDefineset( defSet ); } // add include path @@ -627,7 +626,7 @@ public final CompilerDef getCompiler( String type, String output ) { if ( compileOrder != null ) { - compiler.setOrder( Arrays.asList( StringUtils.split( compileOrder, ", " ) ) ); + compiler.setOrder( Arrays.asList( compileOrder.split( ",[\\s]*" ) ) ); } ConditionalFileSet fileSet = new ConditionalFileSet();