From 4452c88b32cb15f595eaaf6ff380906afadf34ec Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Thu, 20 Nov 2014 03:17:31 +0800 Subject: [PATCH 1/2] Fix the bug of spliting strings of configuration values. --- .../java/com/github/maven_nar/Compiler.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/github/maven_nar/Compiler.java b/src/main/java/com/github/maven_nar/Compiler.java index 609119918..e6cc01b3d 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(); @@ -461,7 +460,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++ ) { @@ -479,7 +478,7 @@ public final CompilerDef getCompiler( String type, String output ) String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" ); if ( optionsProperty != null ) { - String[] option = optionsProperty.split( " " ); + String[] option = optionsProperty.split( "[\\s]+" ); for ( int i = 0; i < option.length; i++ ) { CompilerArgument arg = new CompilerArgument(); @@ -507,7 +506,7 @@ public final CompilerDef getCompiler( String type, String output ) if ( defineSet != null ) { - String[] defList = defineSet.split( "," ); + String[] defList = defineSet.split( ",[\\s]*" ); DefineSet defSet = new DefineSet(); for ( int i = 0; i < defList.length; i++ ) @@ -554,7 +553,7 @@ public final CompilerDef getCompiler( String type, String output ) if ( undefineSet != null ) { - String[] undefList = undefineSet.split( "," ); + String[] undefList = undefineSet.split( ",[\\s]*" ); DefineSet undefSet = new DefineSet(); for ( int i = 0; i < undefList.length; i++ ) @@ -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(); From fd1c7ce903b560456ad1f79ecf7ccd4f0c6f843b Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Thu, 20 Nov 2014 04:33:25 +0800 Subject: [PATCH 2/2] Change the order of setting default configuration and customized configuration, and also change the order of setting defines and undefines. --- .../java/com/github/maven_nar/Compiler.java | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/github/maven_nar/Compiler.java b/src/main/java/com/github/maven_nar/Compiler.java index e6cc01b3d..c0ac3ced4 100644 --- a/src/main/java/com/github/maven_nar/Compiler.java +++ b/src/main/java/com/github/maven_nar/Compiler.java @@ -447,31 +447,6 @@ public final CompilerDef getCompiler( String type, String output ) compiler.setOptimize( optimization ); // add options - if ( options != null ) - { - for ( Iterator 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 ) { @@ -488,54 +463,43 @@ public final CompilerDef getCompiler( String type, String output ) } } - // add defines - if ( defines != null ) + if ( options != null ) { - DefineSet ds = new DefineSet(); - for ( Iterator i = defines.iterator(); i.hasNext(); ) + for ( Iterator i = options.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 ); + CompilerArgument arg = new CompilerArgument(); + arg.setValue( (String) i.next() ); + compiler.addConfiguredCompilerArg( arg ); } - compiler.addConfiguredDefineset( ds ); } - if ( defineSet != null ) + if ( optionSet != null ) { - String[] defList = defineSet.split( ",[\\s]*" ); - DefineSet defSet = new DefineSet(); + String[] opts = optionSet.split( "[\\s]+" ); - for ( int i = 0; i < defList.length; i++ ) + for ( int i = 0; i < opts.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 ); + CompilerArgument arg = new CompilerArgument(); - defSet.addDefine( def ); + arg.setValue( opts[i] ); + compiler.addConfiguredCompilerArg( arg ); } - - compiler.addConfiguredDefineset( defSet ); } - if ( !clearDefaultDefines ) + // add undefines + if ( !clearDefaultUndefines ) { - DefineSet ds = new DefineSet(); - String defaultDefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "defines" ); - if ( defaultDefines != null ) + DefineSet us = new DefineSet(); + String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" ); + if ( defaultUndefines != null ) { - ds.setDefine( new CUtil.StringArrayBuilder( defaultDefines ) ); + us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) ); } - compiler.addConfiguredDefineset( ds ); + compiler.addConfiguredDefineset( us ); } - // add undefines if ( undefines != null ) { DefineSet us = new DefineSet(); @@ -571,15 +535,51 @@ public final CompilerDef getCompiler( String type, String output ) compiler.addConfiguredDefineset( undefSet ); } - if ( !clearDefaultUndefines ) + // add defines + if ( !clearDefaultDefines ) { - DefineSet us = new DefineSet(); - String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" ); - if ( defaultUndefines != null ) + DefineSet ds = new DefineSet(); + String defaultDefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "defines" ); + if ( defaultDefines != null ) { - us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) ); + ds.setDefine( new CUtil.StringArrayBuilder( defaultDefines ) ); } - compiler.addConfiguredDefineset( us ); + compiler.addConfiguredDefineset( ds ); + } + + if ( defines != null ) + { + DefineSet ds = new DefineSet(); + for ( Iterator 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( ",[\\s]*" ); + 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 ); } // add include path