sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r925532 - in /sling/trunk/maven/maven-launchpad-plugin: pom.xml src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java
Date Sat, 20 Mar 2010 02:22:33 GMT
Author: justin
Date: Sat Mar 20 02:22:33 2010
New Revision: 925532

URL: http://svn.apache.org/viewvc?rev=925532&view=rev
Log:
SLING-1454 - adding ability to read filtered sling properties from a file

Modified:
    sling/trunk/maven/maven-launchpad-plugin/pom.xml
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java

Modified: sling/trunk/maven/maven-launchpad-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/pom.xml?rev=925532&r1=925531&r2=925532&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/pom.xml (original)
+++ sling/trunk/maven/maven-launchpad-plugin/pom.xml Sat Mar 20 02:22:33 2010
@@ -143,5 +143,10 @@
         	<artifactId>org.osgi.core</artifactId>
         	<version>4.2.0</version>
         </dependency>
+        <dependency>
+        	<groupId>org.apache.maven.shared</groupId>
+        	<artifactId>maven-filtering</artifactId>
+        	<version>1.0-beta-4</version>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java?rev=925532&r1=925531&r2=925532&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java
(original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/RunMojo.java
Sat Mar 20 02:22:33 2010
@@ -19,10 +19,12 @@ package org.apache.sling.maven.projectsu
 import static org.apache.felix.framework.util.FelixConstants.*;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -31,8 +33,12 @@ import java.util.Properties;
 
 import org.apache.felix.framework.Logger;
 import org.apache.maven.artifact.Artifact;
+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.launchpad.base.impl.ResourceProvider;
 import org.apache.sling.launchpad.base.impl.Sling;
 import org.apache.sling.launchpad.base.shared.Notifiable;
@@ -62,6 +68,7 @@ public class RunMojo extends AbstractBun
      * listens
      */
     private static final String PROP_PORT = "org.osgi.service.http.port";
+
     /** Return the log level code for the string */
     private static int toLogLevelInt(String level, int defaultLevel) {
         for (int i = 0; i < logLevels.length; i++) {
@@ -91,6 +98,24 @@ public class RunMojo extends AbstractBun
      */
     private String logLevel;
 
+    /**
+     * @parameter expression="${propertiesFile}"
+     *            default-value="src/test/config/sling.properties"
+     */
+    private File propertiesFile;
+
+    /**
+     * @component
+     */
+    private MavenFileFilter mavenFileFilter;
+
+    /**
+     * @parameter expression="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession mavenSession;
+
     private ResourceProvider resourceProvider = new ResourceProvider() {
 
         @Override
@@ -234,6 +259,27 @@ public class RunMojo extends AbstractBun
             Logger logger = new Logger();
             logger.setLogLevel(Logger.LOG_ERROR);
 
+            if (propertiesFile.exists()) {
+                File tmp = null;
+                try {
+                    tmp = File.createTempFile("sling", "props");
+                    mavenFileFilter.copyFile(propertiesFile, tmp, true, project, null, true,
System
+                            .getProperty("file.encoding"), mavenSession);
+                    Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
+                    for (Object key : loadedProps.keySet()) {
+                        props.put((String) key, (String) loadedProps.get(key));
+                    }
+                } 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();
+                    }
+                }
+            }
+
             // creating the instance launches the framework and we are done here
             sling = new Sling(this, logger, resourceProvider, props);
 



Mime
View raw message