Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug of spliting strings of configuration values. #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 68 additions & 69 deletions src/main/java/com/github/maven_nar/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -46,7 +46,7 @@

/**
* Abstract Compiler class
*
*
* @author Mark Donszelmann
*/
public abstract class Compiler
Expand All @@ -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;
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand All @@ -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<String> i = options.iterator(); i.hasNext(); )
Expand All @@ -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++ )
{
Expand All @@ -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<String> i = defines.iterator(); i.hasNext(); )
DefineSet us = new DefineSet();
for ( Iterator<String> 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();
Expand All @@ -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<String> i = undefines.iterator(); i.hasNext(); )
DefineSet ds = new DefineSet();
for ( Iterator<String> 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
Expand Down Expand Up @@ -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();
Expand Down