summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Donszelmann <duns@macserver.donszelmann.org>2010-10-26 00:39:07 +0200
committerMark Donszelmann <duns@macserver.donszelmann.org>2010-10-26 00:39:07 +0200
commit9af270beb1414531363aa1fcb6cba7565ca0075a (patch)
tree3f7beb686b56789c1a535f185d33b74a49b074e7
parent7482bfe33dc8db7ccc1b02d80f6c3b6dbac601ca (diff)
downloadmaven-nar-plugin-9af270beb1414531363aa1fcb6cba7565ca0075a.tar.gz
maven-nar-plugin-9af270beb1414531363aa1fcb6cba7565ca0075a.tar.bz2
maven-nar-plugin-9af270beb1414531363aa1fcb6cba7565ca0075a.tar.xz
maven-nar-plugin-9af270beb1414531363aa1fcb6cba7565ca0075a.zip
Fixed NAR-165
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractNarMojo.java13
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java2
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/Compiler.java12
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/Java.java4
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/Linker.java13
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarManager.java4
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarProperties.java77
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarUtil.java30
-rw-r--r--src/test/java/org/apache/maven/plugin/nar/test/TestLinkerVersion.java3
9 files changed, 114 insertions, 44 deletions
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractNarMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractNarMojo.java
index f2e7da4..a401d65 100644
--- a/src/main/java/org/apache/maven/plugin/nar/AbstractNarMojo.java
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractNarMojo.java
@@ -88,6 +88,12 @@ public abstract class AbstractNarMojo
private File outputDirectory;
/**
+ * @parameter expression="${project.basedir}"
+ * @readonly
+ */
+ private File baseDir;
+
+ /**
* @parameter expression="${project.build.finalName}"
* @readonly
*/
@@ -147,7 +153,7 @@ public abstract class AbstractNarMojo
architecture = NarUtil.getArchitecture( architecture );
os = NarUtil.getOS( os );
- aolId = NarUtil.getAOL( architecture, os, linker, aol );
+ aolId = NarUtil.getAOL(mavenProject, architecture, os, linker, aol );
Model model = mavenProject.getModel();
Properties properties = model.getProperties();
@@ -197,6 +203,11 @@ public abstract class AbstractNarMojo
{
return linker;
}
+
+ protected final File getBasedir()
+ {
+ return baseDir;
+ }
protected final File getOutputDirectory()
{
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
index b925d30..7ae7d51 100644
--- a/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
@@ -135,7 +135,7 @@ public abstract class AbstractResourcesMojo
// filter files for lib
String includes =
- "**/*." + NarUtil.getDefaults().getProperty( NarUtil.getAOLKey( aol ) + "." + type + ".extension" );
+ "**/*." + NarProperties.getInstance(getMavenProject()).getProperty( NarUtil.getAOLKey( aol ) + "." + type + ".extension" );
// add import lib for Windows shared libraries
if ( new AOL( aol ).getOS().equals( OS.WINDOWS ) && type.equals( Library.SHARED ) )
diff --git a/src/main/java/org/apache/maven/plugin/nar/Compiler.java b/src/main/java/org/apache/maven/plugin/nar/Compiler.java
index 59cdee2..2db3132 100644
--- a/src/main/java/org/apache/maven/plugin/nar/Compiler.java
+++ b/src/main/java/org/apache/maven/plugin/nar/Compiler.java
@@ -242,7 +242,7 @@ public abstract class Compiler
// adjust default values
if ( name == null )
{
- name = NarUtil.getDefaults().getProperty( getPrefix() + "compiler" );
+ name = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "compiler" );
}
return name;
}
@@ -352,7 +352,7 @@ public abstract class Compiler
}
else
{
- String defaultIncludes = NarUtil.getDefaults().getProperty( getPrefix() + "includes" );
+ String defaultIncludes = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "includes" );
if ( defaultIncludes != null )
{
String[] include = defaultIncludes.split( " " );
@@ -373,7 +373,7 @@ public abstract class Compiler
// add all excludes
if ( excludes.isEmpty() )
{
- String defaultExcludes = NarUtil.getDefaults().getProperty( getPrefix() + "excludes" );
+ String defaultExcludes = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "excludes" );
if ( defaultExcludes != null )
{
String[] exclude = defaultExcludes.split( " " );
@@ -448,7 +448,7 @@ public abstract class Compiler
if ( !clearDefaultOptions )
{
- String optionsProperty = NarUtil.getDefaults().getProperty( getPrefix() + "options" );
+ String optionsProperty = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "options" );
if ( optionsProperty != null )
{
String[] option = optionsProperty.split( " " );
@@ -500,7 +500,7 @@ public abstract class Compiler
if ( !clearDefaultDefines )
{
DefineSet ds = new DefineSet();
- String defaultDefines = NarUtil.getDefaults().getProperty( getPrefix() + "defines" );
+ String defaultDefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "defines" );
if ( defaultDefines != null )
{
ds.setDefine( new CUtil.StringArrayBuilder( defaultDefines ) );
@@ -547,7 +547,7 @@ public abstract class Compiler
if ( !clearDefaultUndefines )
{
DefineSet us = new DefineSet();
- String defaultUndefines = NarUtil.getDefaults().getProperty( getPrefix() + "undefines" );
+ String defaultUndefines = NarProperties.getInstance(mojo.getMavenProject()).getProperty( getPrefix() + "undefines" );
if ( defaultUndefines != null )
{
us.setUndefine( new CUtil.StringArrayBuilder( defaultUndefines ) );
diff --git a/src/main/java/org/apache/maven/plugin/nar/Java.java b/src/main/java/org/apache/maven/plugin/nar/Java.java
index 4a61a53..fe260d1 100644
--- a/src/main/java/org/apache/maven/plugin/nar/Java.java
+++ b/src/main/java/org/apache/maven/plugin/nar/Java.java
@@ -106,7 +106,7 @@ public class Java
else
{
String prefix = mojo.getAOL().getKey() + ".java.";
- String includes = NarUtil.getDefaults().getProperty( prefix + "include" );
+ String includes = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "include" );
if ( includes != null )
{
String[] path = includes.split( ";" );
@@ -145,7 +145,7 @@ public class Java
{
if ( runtimeDirectory == null )
{
- runtimeDirectory = NarUtil.getDefaults().getProperty( prefix + "runtimeDirectory" );
+ runtimeDirectory = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "runtimeDirectory" );
if ( runtimeDirectory == null )
{
throw new MojoFailureException( "NAR: Please specify a <RuntimeDirectory> as part of <Java>" );
diff --git a/src/main/java/org/apache/maven/plugin/nar/Linker.java b/src/main/java/org/apache/maven/plugin/nar/Linker.java
index 810c540..b88f67b 100644
--- a/src/main/java/org/apache/maven/plugin/nar/Linker.java
+++ b/src/main/java/org/apache/maven/plugin/nar/Linker.java
@@ -25,7 +25,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -161,12 +160,12 @@ public class Linker
return name;
}
- public final String getName( Properties defaults, String prefix )
+ public final String getName( NarProperties properties, String prefix )
throws MojoFailureException, MojoExecutionException
{
- if ( ( name == null ) && ( defaults != null ) && ( prefix != null ) )
+ if ( ( name == null ) && ( properties != null ) && ( prefix != null ) )
{
- name = defaults.getProperty( prefix + "linker" );
+ name = properties.getProperty( prefix + "linker" );
}
if ( name == null )
{
@@ -365,7 +364,7 @@ public class Linker
if ( !clearDefaultOptions )
{
- String option = NarUtil.getDefaults().getProperty( prefix + "options" );
+ String option = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "options" );
if ( option != null )
{
String[] opt = option.split( " " );
@@ -417,7 +416,7 @@ public class Linker
else
{
- String libsList = NarUtil.getDefaults().getProperty( prefix + "libs" );
+ String libsList = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "libs" );
addLibraries( libsList, linker, antProject, false );
}
@@ -445,7 +444,7 @@ public class Linker
else
{
- String sysLibsList = NarUtil.getDefaults().getProperty( prefix + "sysLibs" );
+ String sysLibsList = NarProperties.getInstance(mojo.getMavenProject()).getProperty( prefix + "sysLibs" );
addLibraries( sysLibsList, linker, antProject, true );
}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarManager.java b/src/main/java/org/apache/maven/plugin/nar/NarManager.java
index 4128b7f..41fb808 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarManager.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarManager.java
@@ -67,8 +67,8 @@ public class NarManager
this.log = log;
this.repository = repository;
this.project = project;
- this.defaultAOL = NarUtil.getAOL(architecture, os, linker, null);
- this.linkerName = NarUtil.getLinkerName(architecture, os, linker);
+ this.defaultAOL = NarUtil.getAOL(project, architecture, os, linker, null);
+ this.linkerName = NarUtil.getLinkerName(project, architecture, os, linker);
}
/**
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarProperties.java b/src/main/java/org/apache/maven/plugin/nar/NarProperties.java
new file mode 100644
index 0000000..2e4b7ba
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugin/nar/NarProperties.java
@@ -0,0 +1,77 @@
+package org.apache.maven.plugin.nar;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.PropertyUtils;
+
+public class NarProperties {
+
+ private final static String AOL_PROPERTIES = "aol.properties";
+ private Properties properties;
+ private static NarProperties instance;
+
+ private NarProperties(MavenProject project) throws MojoFailureException {
+
+ Properties defaults = PropertyUtils.loadProperties( NarUtil.class.getResourceAsStream( AOL_PROPERTIES ) );
+ if ( defaults == null )
+ {
+ throw new MojoFailureException( "NAR: Could not load default properties file: '"+AOL_PROPERTIES+"'." );
+ }
+
+ properties = new Properties(defaults);
+ FileInputStream fis = null;
+ try
+ {
+ if (project != null) {
+ fis = new FileInputStream(project.getBasedir()+File.separator+AOL_PROPERTIES);
+ properties.load( fis );
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ // ignore (FIXME)
+ }
+ catch (IOException e)
+ {
+ // ignore (FIXME)
+ }
+ finally
+ {
+ try
+ {
+ if ( fis != null )
+ {
+ fis.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+
+ }
+
+ /**
+ * Retrieve the NarProperties
+ * @param project may be null
+ * @return
+ * @throws MojoFailureException
+ */
+ public static NarProperties getInstance(MavenProject project) throws MojoFailureException {
+ if (instance == null) {
+ instance = new NarProperties(project);
+ }
+ return instance;
+ }
+
+ public String getProperty(String key) {
+ return properties.getProperty(key);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
index cb77355..b739f0e 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
@@ -30,7 +30,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
@@ -41,7 +40,6 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.PropertyUtils;
import org.codehaus.plexus.util.cli.Commandline;
/**
@@ -54,24 +52,6 @@ public final class NarUtil
// never instantiate
}
- private static Properties defaults;
-
- public static Properties getDefaults()
- throws MojoFailureException
- {
- // read properties file with defaults
- if ( defaults == null )
- {
- defaults = PropertyUtils.loadProperties( NarUtil.class.getResourceAsStream( "aol.properties" ) );
- }
- if ( defaults == null )
- {
- throw new MojoFailureException( "NAR: Could not load default properties file: 'aol.properties'." );
- }
-
- return defaults;
- }
-
public static String getOS( String defaultOs )
{
String os = defaultOs;
@@ -111,22 +91,23 @@ public final class NarUtil
return link;
}
- public static String getLinkerName( String architecture, String os, Linker linker )
+ public static String getLinkerName(MavenProject project, String architecture, String os, Linker linker )
throws MojoFailureException, MojoExecutionException
{
- return getLinker( linker ).getName( getDefaults(), getArchitecture( architecture ) + "." + getOS( os ) + "." );
+ return getLinker( linker ).getName( NarProperties.getInstance(project), getArchitecture( architecture ) + "." + getOS( os ) + "." );
}
- public static AOL getAOL( String architecture, String os, Linker linker, String aol )
+ public static AOL getAOL(MavenProject project, String architecture, String os, Linker linker, String aol )
throws MojoFailureException, MojoExecutionException
{
// adjust aol
- return aol == null ? new AOL( getArchitecture( architecture ), getOS( os ), getLinkerName( architecture, os,
+ return aol == null ? new AOL( getArchitecture( architecture ), getOS( os ), getLinkerName( project, architecture, os,
linker ) )
: new AOL( aol );
}
// FIXME, should go to AOL.
+/* NOT USED ?
public static String getAOLKey( String architecture, String os, Linker linker )
throws MojoFailureException, MojoExecutionException
{
@@ -134,6 +115,7 @@ public final class NarUtil
return getArchitecture( architecture ) + "." + getOS( os ) + "." + getLinkerName( architecture, os, linker )
+ ".";
}
+*/
public static String getAOLKey( String aol )
{
diff --git a/src/test/java/org/apache/maven/plugin/nar/test/TestLinkerVersion.java b/src/test/java/org/apache/maven/plugin/nar/test/TestLinkerVersion.java
index ee8eede..6890b59 100644
--- a/src/test/java/org/apache/maven/plugin/nar/test/TestLinkerVersion.java
+++ b/src/test/java/org/apache/maven/plugin/nar/test/TestLinkerVersion.java
@@ -20,6 +20,7 @@
package org.apache.maven.plugin.nar.test;
import org.apache.maven.plugin.nar.Linker;
+import org.apache.maven.plugin.nar.NarProperties;
import org.apache.maven.plugin.nar.NarUtil;
import junit.framework.Assert;
@@ -45,7 +46,7 @@ public class TestLinkerVersion
String architecture = System.getProperty( "os.arch" );
linker = new Linker();
// String name =
- linker.getName( NarUtil.getDefaults(), NarUtil.getArchitecture( architecture ) + "." + NarUtil.getOS( null )
+ linker.getName( NarProperties.getInstance(null), NarUtil.getArchitecture( architecture ) + "." + NarUtil.getOS( null )
+ "." );
}