Author: cziegeler
Date: Wed Jul 13 12:12:18 2011
New Revision: 1145965

URL: http://svn.apache.org/viewvc?rev=1145965&view=rev
Log:
SLING-2134 : Provide a way to add additional properties to sling.properties

Modified:
    
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
    
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java

Modified: 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java?rev=1145965&r1=1145964&r2=1145965&view=diff
==============================================================================
--- 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
 (original)
+++ 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
 Wed Jul 13 12:12:18 2011
@@ -37,6 +37,9 @@ import org.apache.maven.artifact.version
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.PropertyUtils;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
 import 
org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader;
 import org.codehaus.plexus.util.StringUtils;
@@ -59,6 +62,12 @@ public abstract class AbstractUsingBundl
     protected File configDirectory;
 
     /**
+     * @parameter expression="${additionalSlingProps}"
+     *            default-value="src/main/sling/additional.properties"
+     */
+    protected File additionalSlingProps;
+
+    /**
      * JAR Packaging type.
      */
     protected static final String JAR = "jar";
@@ -161,6 +170,11 @@ public abstract class AbstractUsingBundl
      */
     protected MavenSession mavenSession;
 
+    /**
+     * @component
+     */
+    private MavenFileFilter mavenFileFilter;
+
     public final void execute() throws MojoFailureException, 
MojoExecutionException {
         try {
             initBundleList();
@@ -371,11 +385,23 @@ public abstract class AbstractUsingBundl
         }
     }
 
-    protected File getSlingProperties() {
-        if ( this.configDirectory != null && this.configDirectory.exists() && 
this.configDirectory.isDirectory() ) {
-            final File slingProps = new File(this.configDirectory, 
"sling.properties");
-            if ( slingProps.exists() && slingProps.isFile() ) {
-                return slingProps;
+    protected Properties getSlingProperties() throws MojoExecutionException {
+        if (this.additionalSlingProps.exists()) {
+            File tmp = null;
+            try {
+                tmp = File.createTempFile("sling", "props");
+                mavenFileFilter.copyFile(this.additionalSlingProps, tmp, true, 
project, null, true,
+                        System.getProperty("file.encoding"), mavenSession);
+                final Properties loadedProps = 
PropertyUtils.loadPropertyFile(tmp, null);
+                return loadedProps;
+            } catch (IOException e) {
+                throw new MojoExecutionException("Unable to create filtered 
properties file", e);
+            } catch (MavenFilteringException e) {
+                throw new MojoExecutionException("Unable to create filtered 
properties file", e);
+            } finally {
+                if (tmp != null) {
+                    tmp.delete();
+                }
             }
         }
         return null;

Modified: 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java?rev=1145965&r1=1145964&r2=1145965&view=diff
==============================================================================
--- 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
 (original)
+++ 
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
 Wed Jul 13 12:12:18 2011
@@ -152,8 +152,8 @@ public class PreparePackageMojo extends 
                                + "." + 
artifact.getArtifactHandler().getExtension());
 
                // check if custom sling.properties file exists
-               final File slingProps = this.getSlingProperties();
-               if ( slingProps != null ) {
+               final Properties additionalProps = this.getSlingProperties();
+               if ( additionalProps != null ) {
                // unpack to a temp destination
                    final File dest = new File(this.tempDirectory, "basejar");
                    try {
@@ -177,27 +177,14 @@ public class PreparePackageMojo extends 
                            }
                        }
 
-                       // read additional properties
-                final Properties addProps = new Properties();
-                try {
-                    fis = new FileInputStream(slingProps);
-                    addProps.load(fis);
-                } catch (final IOException ioe) {
-                    throw new MojoExecutionException("Unable to read " + 
slingProps, ioe);
-                } finally {
-                    if ( fis != null ) {
-                        try { fis.close(); } catch (final IOException ignore) 
{}
-                    }
-                }
-
                 // patch
-                final Enumeration<Object> keys = addProps.keys();
+                final Enumeration<Object> keys = additionalProps.keys();
                 if ( keys.hasMoreElements() ) {
                     getLog().info("Patching sling.properties");
                 }
                 while ( keys.hasMoreElements() ) {
                     final Object key = keys.nextElement();
-                    orig.put(key, addProps.get(key));
+                    orig.put(key, additionalProps.get(key));
                 }
 
                 /// and save


Reply via email to