incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1165337 - in /sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport: AbstractBundleListMojo.java AbstractUsingBundleListMojo.java AttachPartialBundleListMojo.java PreparePackageMojo.java
Date Mon, 05 Sep 2011 15:31:42 GMT
Author: cziegeler
Date: Mon Sep  5 15:31:41 2011
New Revision: 1165337

URL: http://svn.apache.org/viewvc?rev=1165337&view=rev
Log:
SLING-2207 : Support different properties and bootstrap commands for standalone and webapp

Modified:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
    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/AttachPartialBundleListMojo.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/AbstractBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java?rev=1165337&r1=1165336&r2=1165337&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
(original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
Mon Sep  5 15:31:41 2011
@@ -66,6 +66,30 @@ public abstract class AbstractBundleList
      */
     protected File commonSlingBootstrap;
 
+    /**
+     * @parameter expression="${webappSlingProps}"
+     *            default-value="src/main/sling/webapp.properties"
+     */
+    protected File webappSlingProps;
+
+    /**
+     * @parameter expression="${webappSlingBootstrap}"
+     *            default-value="src/main/sling/webapp.bootstrap.txt"
+     */
+    protected File webappSlingBootstrap;
+
+    /**
+     * @parameter expression="${standaloneSlingProps}"
+     *            default-value="src/main/sling/standalone.properties"
+     */
+    protected File standaloneSlingProps;
+
+    /**
+     * @parameter expression="${standaloneSlingBootstrap}"
+     *            default-value="src/main/sling/standalone.bootstrap.txt"
+     */
+    protected File standaloneSlingBootstrap;
+
     protected File getConfigDirectory() {
         return this.configDirectory;
     }

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=1165337&r1=1165336&r2=1165337&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
Mon Sep  5 15:31:41 2011
@@ -177,8 +177,16 @@ public abstract class AbstractUsingBundl
 
     private Properties slingProperties;
 
+    private Properties slingWebappProperties;
+
+    private Properties slingStandaloneProperties;
+
     private String slingBootstrapCommand;
 
+    private String slingWebappBootstrapCommand;
+
+    private String slingStandaloneBootstrapCommand;
+
     /**
      * @parameter default-value="${project.build.directory}/tmpBundleListconfig"
      */
@@ -380,8 +388,12 @@ public abstract class AbstractUsingBundl
                         zipUnarchiver.extract();
 
                         final File slingDir = new File(this.tmpOutputDir, "sling");
-                        this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_PROPS));
-                        this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_BOOTSTRAP));
+                        this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_PROPS),
0);
+                        this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_PROPS),
1);
+                        this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_PROPS),
2);
+                        this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_BOOTSTRAP),
0);
+                        this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_BOOTSTRAP),
1);
+                        this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_BOOTSTRAP),
2);
 
                         // and now configurations
                         if ( this.overlayConfigDir == null ) {
@@ -458,7 +470,15 @@ public abstract class AbstractUsingBundl
         }
     }
 
-    private void readSlingProperties(final File propsFile) throws MojoExecutionException
{
+    private void copyProperties(final Properties source, final Properties dest) {
+        final Enumeration<Object> keys = source.keys();
+        while ( keys.hasMoreElements() ) {
+            final Object key = keys.nextElement();
+            dest.put(key, source.get(key));
+        }
+    }
+
+    private void readSlingProperties(final File propsFile, final int mode) throws MojoExecutionException
{
         if (propsFile.exists()) {
             File tmp = null;
             try {
@@ -466,13 +486,23 @@ public abstract class AbstractUsingBundl
                 mavenFileFilter.copyFile(propsFile, tmp, true, project, null, true,
                         System.getProperty("file.encoding"), mavenSession);
                 final Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
-                if ( this.slingProperties == null ) {
-                    this.slingProperties = loadedProps;
+                if ( mode == 0 ) {
+                    if ( this.slingProperties == null ) {
+                        this.slingProperties = loadedProps;
+                    } else {
+                        this.copyProperties(loadedProps, this.slingProperties);
+                    }
+                } else if ( mode == 1 ) {
+                    if ( this.slingWebappProperties == null ) {
+                        this.slingWebappProperties = loadedProps;
+                    } else {
+                        this.copyProperties(loadedProps, this.slingWebappProperties);
+                    }
                 } else {
-                    final Enumeration<Object> keys = loadedProps.keys();
-                    while ( keys.hasMoreElements() ) {
-                        final Object key = keys.nextElement();
-                        this.slingProperties.put(key, loadedProps.get(key));
+                    if ( this.slingStandaloneProperties == null ) {
+                        this.slingStandaloneProperties = loadedProps;
+                    } else {
+                        this.copyProperties(loadedProps, this.slingStandaloneProperties);
                     }
                 }
             } catch (IOException e) {
@@ -487,8 +517,18 @@ public abstract class AbstractUsingBundl
         }
     }
 
-    protected Properties getSlingProperties() throws MojoExecutionException {
-        readSlingProperties(this.commonSlingProps);
+    protected Properties getSlingProperties(final boolean standalone) throws MojoExecutionException
{
+        readSlingProperties(this.commonSlingProps, 0);
+        final Properties additionalProps = (standalone ? this.slingStandaloneProperties :
this.slingWebappProperties);
+        if ( this.slingProperties == null) {
+            return additionalProps;
+        }
+        if ( additionalProps != null ) {
+            final Properties combinedProps = new Properties();
+            this.copyProperties(this.slingProperties, combinedProps);
+            this.copyProperties(additionalProps, combinedProps);
+            return combinedProps;
+        }
         return this.slingProperties;
     }
 
@@ -497,7 +537,7 @@ public abstract class AbstractUsingBundl
      * The filter is copied to a tmp location to apply filtering.
      * @throws MojoExecutionException
      */
-    private void readSlingBootstrap(final File bootstrapFile) throws MojoExecutionException
{
+    private void readSlingBootstrap(final File bootstrapFile, final int mode) throws MojoExecutionException
{
         if (bootstrapFile.exists()) {
             File tmp = null;
             Reader reader = null;
@@ -507,19 +547,34 @@ public abstract class AbstractUsingBundl
                         System.getProperty("file.encoding"), mavenSession);
                 reader = new FileReader(tmp);
                 final StringBuilder sb = new StringBuilder();
-                if ( this.slingBootstrapCommand != null ) {
-                    sb.append(this.slingBootstrapCommand);
+                if ( mode == 0 ) {
+                    if ( this.slingBootstrapCommand != null ) {
+                        sb.append(this.slingBootstrapCommand);
+                    }
+                } else if ( mode == 1 ) {
+                    if ( this.slingWebappBootstrapCommand != null ) {
+                        sb.append(this.slingWebappBootstrapCommand);
+                    }
+                } else {
+                    if ( this.slingStandaloneBootstrapCommand != null ) {
+                        sb.append(this.slingStandaloneBootstrapCommand);
+                    }
                 }
                 final char[] buffer = new char[2048];
                 int l;
                 while ( (l = reader.read(buffer, 0, buffer.length) ) != -1 ) {
                     sb.append(buffer, 0, l);
                 }
-
-                this.slingBootstrapCommand = sb.toString();
-            } catch (IOException e) {
+                if ( mode == 0 ) {
+                    this.slingBootstrapCommand = sb.toString();
+                } else if ( mode == 1 ) {
+                    this.slingWebappBootstrapCommand = sb.toString();
+                } else {
+                    this.slingStandaloneBootstrapCommand = sb.toString();
+                }
+            } catch (final IOException e) {
                 throw new MojoExecutionException("Unable to create filtered bootstrap file",
e);
-            } catch (MavenFilteringException e) {
+            } catch (final MavenFilteringException e) {
                 throw new MojoExecutionException("Unable to create filtered bootstrap file",
e);
             } finally {
                 if (tmp != null) {
@@ -540,9 +595,17 @@ public abstract class AbstractUsingBundl
      * @return The contents are <code>null</code>
      * @throws MojoExecutionException
      */
-    protected String getSlingBootstrap() throws MojoExecutionException {
-        this.readSlingBootstrap(this.commonSlingBootstrap);
-
+    protected String getSlingBootstrap(final boolean standalone) throws MojoExecutionException
{
+        this.readSlingBootstrap(this.commonSlingBootstrap, 0);
+        final String addCmds = (standalone ? this.slingStandaloneBootstrapCommand : this.slingWebappBootstrapCommand);
+        if ( this.slingBootstrapCommand == null ) {
+            return addCmds;
+        }
+        if ( addCmds != null ) {
+            final StringBuilder builder = new StringBuilder(this.slingBootstrapCommand);
+            builder.append(addCmds);
+            return builder.toString();
+        }
         return this.slingBootstrapCommand;
     }
 }

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java?rev=1165337&r1=1165336&r2=1165337&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
(original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
Mon Sep  5 15:31:41 2011
@@ -42,6 +42,14 @@ public class AttachPartialBundleListMojo
 
     public static final String SLING_COMMON_BOOTSTRAP = "common.bootstrap.txt";
 
+    public static final String SLING_WEBAPP_PROPS = "webapp.properties";
+
+    public static final String SLING_WEBAPP_BOOTSTRAP = "webapp.bootstrap.txt";
+
+    public static final String SLING_STANDALONE_PROPS = "standalone.properties";
+
+    public static final String SLING_STANDALONE_BOOTSTRAP = "standalone.bootstrap.txt";
+
     /**
      * @parameter default-value="${project.build.directory}/bundleListconfig"
      */
@@ -75,6 +83,7 @@ public class AttachPartialBundleListMojo
     private boolean checkFile(final File f) {
         return f != null && f.exists();
     }
+
     private void attachConfigurations() throws MojoExecutionException, IOException, ArchiverException
{
         if ( this.ignoreBundleListConfig ) {
             this.getLog().debug("ignoreBundleListConfig is set to true, therefore not attaching
configurations.");
@@ -84,6 +93,10 @@ public class AttachPartialBundleListMojo
         boolean hasConfigs = this.checkFile(this.getConfigDirectory());
         hasConfigs |= this.checkFile(this.commonSlingBootstrap);
         hasConfigs |= this.checkFile(this.commonSlingProps);
+        hasConfigs |= this.checkFile(this.webappSlingBootstrap);
+        hasConfigs |= this.checkFile(this.webappSlingProps);
+        hasConfigs |= this.checkFile(this.standaloneSlingBootstrap);
+        hasConfigs |= this.checkFile(this.standaloneSlingProps);
 
         if ( !hasConfigs ) {
             this.getLog().debug("No configurations to attach.");
@@ -101,6 +114,26 @@ public class AttachPartialBundleListMojo
             slingDir.mkdirs();
             FileUtils.copyFile(this.commonSlingProps, new File(slingDir, SLING_COMMON_PROPS));
         }
+        if ( this.checkFile(this.webappSlingBootstrap) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.webappSlingBootstrap, new File(slingDir, SLING_WEBAPP_BOOTSTRAP));
+        }
+        if ( this.checkFile(this.webappSlingProps) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.webappSlingProps, new File(slingDir, SLING_WEBAPP_PROPS));
+        }
+        if ( this.checkFile(this.standaloneSlingBootstrap) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.standaloneSlingBootstrap, new File(slingDir, SLING_STANDALONE_BOOTSTRAP));
+        }
+        if ( this.checkFile(this.standaloneSlingProps) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.standaloneSlingProps, new File(slingDir, SLING_STANDALONE_PROPS));
+        }
         if ( this.checkFile(this.getConfigDirectory()) ) {
             final File configDir = new File(this.configOutputDir, "config");
             configDir.mkdirs();

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=1165337&r1=1165336&r2=1165337&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
Mon Sep  5 15:31:41 2011
@@ -222,8 +222,8 @@ public class PreparePackageMojo extends 
 				+ "." + artifact.getArtifactHandler().getExtension());
 
 		// check if custom sling.properties file or bootstrap command exists
-		final Properties additionalProps = this.getSlingProperties();
-		final String bootstrapCmd = this.getSlingBootstrap();
+		final Properties additionalProps = this.getSlingProperties(JAR.equals(this.packaging));
+		final String bootstrapCmd = this.getSlingBootstrap(JAR.equals(this.packaging));
 		if ( additionalProps != null || bootstrapCmd != null ) {
     		// unpack to a temp destination
 		    final File dest = new File(this.tempDirectory, "basejar");



Mime
View raw message