This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag maven-launchpad-plugin-2.1.0
in repository 
https://gitbox.apache.org/repos/asf/sling-maven-launchpad-plugin.git

commit 97dac9a60146fd01b6bf0d67d693d14d76a05277
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Thu Aug 18 13:35:36 2011 +0000

    SLING-2183 : Bundle configurations and sling files with bundlelist
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1159213
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../projectsupport/AbstractBundleListMojo.java     |  21 +++
 .../AbstractLaunchpadStartingMojo.java             |   6 +-
 .../AbstractUsingBundleListMojo.java               | 153 ++++++++++++++++-----
 .../AttachPartialBundleListMojo.java               |  88 +++++++++++-
 .../maven/projectsupport/PreparePackageMojo.java   |   2 +-
 5 files changed, 232 insertions(+), 38 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
index 6ec799a..050c653 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
@@ -48,4 +48,25 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
      */
     protected MavenProjectHelper projectHelper;
 
+    /**
+     * @parameter expression="${configDirectory}"
+     *            default-value="src/main/config"
+     */
+    private File configDirectory;
+
+    /**
+     * @parameter expression="${additionalSlingProps}"
+     *            default-value="src/main/sling/additional.properties"
+     */
+    protected File additionalSlingProps;
+
+    /**
+     * @parameter expression="${additionalSlingBootstrap}"
+     *            default-value="src/main/sling/bootstrap.txt"
+     */
+    protected File additionalSlingBootstrap;
+
+    protected File getConfigDirectory() {
+        return this.configDirectory;
+    }
 }
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
index 3904aed..9da0201 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
@@ -135,8 +135,8 @@ public abstract class AbstractLaunchpadStartingMojo extends 
AbstractUsingBundleL
                 List<String> empty = Collections.emptyList();
                 return empty.iterator();
             } else if (path.equals(CONFIG_PATH_PREFIX)) {
-                if (configDirectory.exists() && configDirectory.isDirectory()) 
{
-                    File[] configFiles = configDirectory.listFiles(new 
FileFilter() {
+                if (getConfigDirectory().exists() && 
getConfigDirectory().isDirectory()) {
+                    File[] configFiles = getConfigDirectory().listFiles(new 
FileFilter() {
 
                         public boolean accept(File file) {
                             return file.isFile();
@@ -188,7 +188,7 @@ public abstract class AbstractLaunchpadStartingMojo extends 
AbstractUsingBundleL
 
         public URL getResource(String path) {
             if (path.startsWith(CONFIG_PATH_PREFIX)) {
-                File configFile = new File(configDirectory, 
path.substring(CONFIG_PATH_PREFIX.length() + 1));
+                File configFile = new File(getConfigDirectory(), 
path.substring(CONFIG_PATH_PREFIX.length() + 1));
                 if (configFile.exists()) {
                     try {
                         return configFile.toURI().toURL();
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
index be08450..7eac40f 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
@@ -44,6 +45,9 @@ 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.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.drools.KnowledgeBase;
@@ -58,24 +62,6 @@ import org.drools.runtime.StatefulKnowledgeSession;
 public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo {
 
     /**
-     * @parameter expression="${configDirectory}"
-     *            default-value="src/main/config"
-     */
-    protected File configDirectory;
-
-    /**
-     * @parameter expression="${additionalSlingProps}"
-     *            default-value="src/main/sling/additional.properties"
-     */
-    private File additionalSlingProps;
-
-    /**
-     * @parameter expression="${additionalSlingBootstrap}"
-     *            default-value="src/main/sling/bootstrap.txt"
-     */
-    private File additionalSlingBootstrap;
-
-    /**
      * JAR Packaging type.
      */
     protected static final String JAR = "jar";
@@ -182,6 +168,29 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
      */
     private MavenFileFilter mavenFileFilter;
 
+    /**
+     * The zip unarchiver.
+     *
+     * @component role="org.codehaus.plexus.archiver.UnArchiver" roleHint="zip"
+     */
+    private ZipUnArchiver zipUnarchiver;
+
+    private Properties slingProperties;
+
+    private String slingBootstrapCommand;
+
+    /**
+     * @parameter 
default-value="${project.build.directory}/tmpBundleListconfig"
+     */
+    private File tmpOutputDir;
+
+    /**
+     * @parameter default-value="${project.build.directory}/tmpConfigDir"
+     */
+    private File tempConfigDir;
+
+    private File overlayConfigDir;
+
     public final void execute() throws MojoFailureException, 
MojoExecutionException {
         try {
             initBundleList();
@@ -194,6 +203,14 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
 
     }
 
+    @Override
+    protected File getConfigDirectory() {
+        if ( this.overlayConfigDir != null ) {
+            return this.overlayConfigDir;
+        }
+        return super.getConfigDirectory();
+    }
+
     /**
      * Execute the logic of the plugin after the default artifacts have been
      * initialized.
@@ -331,13 +348,62 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
             }
         }
 
-        Set<Artifact> dependencies = project.getDependencyArtifacts();
+        final Set<Artifact> dependencies = project.getDependencyArtifacts();
         for (Artifact artifact : dependencies) {
             if (PARTIAL.equals(artifact.getType())) {
                 getLog().info(
                         String.format("merging partial bundle list for 
%s:%s:%s", artifact.getGroupId(),
                                 artifact.getArtifactId(), 
artifact.getVersion()));
                 bundleList.merge(readBundleList(artifact.getFile()));
+
+                // check for configuration artifact
+                Artifact cfgArtifact = null;
+                try {
+                    cfgArtifact = getArtifact(artifact.getGroupId(),
+                            artifact.getArtifactId(),
+                            artifact.getVersion(),
+                            AttachPartialBundleListMojo.CONFIG_TYPE,
+                            AttachPartialBundleListMojo.CONFIG_CLASSIFIER);
+                } catch (final MojoExecutionException ignore) {
+                    // we just ignore this
+                }
+                if ( cfgArtifact != null ) {
+                    getLog().info(
+                            String.format("merging partial bundle list 
configuration for %s:%s:%s", cfgArtifact.getGroupId(),
+                                    cfgArtifact.getArtifactId(), 
cfgArtifact.getVersion()));
+
+                    // extract
+                    zipUnarchiver.setSourceFile(cfgArtifact.getFile());
+                    try {
+                        this.tmpOutputDir.mkdirs();
+                        zipUnarchiver.setDestDirectory(this.tmpOutputDir);
+                        zipUnarchiver.extract();
+
+                        final File slingDir = new File(this.tmpOutputDir, 
"sling");
+                        this.readSlingProperties(new File(slingDir, 
AttachPartialBundleListMojo.SLING_ADDITIONAL_PROPS));
+                        this.readSlingBootstrap(new File(slingDir, 
AttachPartialBundleListMojo.SLING_BOOTSTRAP));
+
+                        // and now configurations
+                        if ( this.overlayConfigDir == null ) {
+                            this.tempConfigDir.mkdirs();
+                            if ( this.getConfigDirectory().exists() ) {
+                                
FileUtils.copyDirectory(this.getConfigDirectory(), this.tempConfigDir,
+                                        null, 
FileUtils.getDefaultExcludesAsString());
+                            }
+                            this.overlayConfigDir = this.tempConfigDir;
+                        }
+                        final File configDir = new File(this.tmpOutputDir, 
"config");
+                        if ( configDir.exists() ) {
+                            FileUtils.copyDirectory(configDir, 
this.tempConfigDir,
+                                    null, 
FileUtils.getDefaultExcludesAsString());
+                        }
+                    } catch (final ArchiverException ae) {
+                        throw new MojoExecutionException("Unable to extract 
configuration archive.",ae);
+                    } finally {
+                        // and delete at the end
+                        FileUtils.deleteDirectory(this.tmpOutputDir);
+                    }
+                }
             }
         }
 
@@ -392,15 +458,23 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
         }
     }
 
-    protected Properties getSlingProperties() throws MojoExecutionException {
-        if (this.additionalSlingProps.exists()) {
+    private void readSlingProperties(final File propsFile) throws 
MojoExecutionException {
+        if (propsFile.exists()) {
             File tmp = null;
             try {
                 tmp = File.createTempFile("sling", "props");
-                mavenFileFilter.copyFile(this.additionalSlingProps, tmp, true, 
project, null, true,
+                mavenFileFilter.copyFile(propsFile, tmp, true, project, null, 
true,
                         System.getProperty("file.encoding"), mavenSession);
                 final Properties loadedProps = 
PropertyUtils.loadPropertyFile(tmp, null);
-                return loadedProps;
+                if ( this.slingProperties == null ) {
+                    this.slingProperties = loadedProps;
+                } else {
+                    final Enumeration<Object> keys = loadedProps.keys();
+                    while ( keys.hasMoreElements() ) {
+                        final Object key = keys.nextElement();
+                        this.slingProperties.put(key, loadedProps.get(key));
+                    }
+                }
             } catch (IOException e) {
                 throw new MojoExecutionException("Unable to create filtered 
properties file", e);
             } catch (MavenFilteringException e) {
@@ -411,32 +485,38 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
                 }
             }
         }
-        return null;
+    }
+
+    protected Properties getSlingProperties() throws MojoExecutionException {
+        readSlingProperties(this.additionalSlingProps);
+        return this.slingProperties;
     }
 
     /**
-     * Try to read the bootstrap command file and return its content
+     * Try to read the bootstrap command file
      * The filter is copied to a tmp location to apply filtering.
-     * @return The contents are <code>null</code>
      * @throws MojoExecutionException
      */
-    protected String getSlingBootstrap() throws MojoExecutionException {
-        if (this.additionalSlingBootstrap.exists()) {
+    private void readSlingBootstrap(final File bootstrapFile) throws 
MojoExecutionException {
+        if (bootstrapFile.exists()) {
             File tmp = null;
             Reader reader = null;
             try {
                 tmp = File.createTempFile("sling", "bootstrap");
-                mavenFileFilter.copyFile(this.additionalSlingBootstrap, tmp, 
true, project, null, true,
+                mavenFileFilter.copyFile(bootstrapFile, tmp, true, project, 
null, true,
                         System.getProperty("file.encoding"), mavenSession);
                 reader = new FileReader(tmp);
                 final StringBuilder sb = new StringBuilder();
+                if ( this.slingBootstrapCommand != null ) {
+                    sb.append(this.slingBootstrapCommand);
+                }
                 final char[] buffer = new char[2048];
                 int l;
                 while ( (l = reader.read(buffer, 0, buffer.length) ) != -1 ) {
                     sb.append(buffer, 0, l);
                 }
 
-                return sb.toString();
+                this.slingBootstrapCommand = sb.toString();
             } catch (IOException e) {
                 throw new MojoExecutionException("Unable to create filtered 
bootstrap file", e);
             } catch (MavenFilteringException e) {
@@ -452,6 +532,17 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
                 }
             }
         }
-        return null;
+    }
+
+    /**
+     * Try to read the bootstrap command file and return its content
+     * The filter is copied to a tmp location to apply filtering.
+     * @return The contents are <code>null</code>
+     * @throws MojoExecutionException
+     */
+    protected String getSlingBootstrap() throws MojoExecutionException {
+        this.readSlingBootstrap(this.additionalSlingBootstrap);
+
+        return this.slingBootstrapCommand;
     }
 }
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
index 79b1cc0..a890ec1 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
@@ -5,9 +5,9 @@
  * licenses this file to You 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. See the
@@ -16,20 +16,102 @@
  */
 package org.apache.sling.maven.projectsupport;
 
+import java.io.File;
+import java.io.IOException;
+
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipArchiver;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * Attaches the bundle list as a project artifact.
- * 
+ *
  * @goal attach-partial-bundle-list
  * @phase package
  * @description attach the partial bundle list as a project artifact
  */
 public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
 
+    public static final String CONFIG_CLASSIFIER = "bundlelistconfig";
+
+    public static final String CONFIG_TYPE = "zip";
+
+    public static final String SLING_ADDITIONAL_PROPS = 
"additional.properties";
+
+    public static final String SLING_BOOTSTRAP = "bootstrap.txt";
+
+    /**
+     * @parameter default-value="${project.build.directory}/bundleListconfig"
+     */
+    private File configOutputDir;
+
+    /**
+     * @parameter expression="${ignoreBundleListConfig}"
+     *            default-value="false"
+     */
+    private boolean ignoreBundleListConfig;
+
+    /**
+     * The zip archiver.
+     *
+     * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="zip"
+     */
+    private ZipArchiver zipArchiver;
+
     public void execute() throws MojoExecutionException, MojoFailureException {
         project.getArtifact().setFile(bundleListFile);
+        this.getLog().info("Attaching bundle list configuration");
+        try {
+            this.attachConfigurations();
+        } catch (final IOException ioe) {
+            throw new MojoExecutionException("Unable to attach 
configuration.", ioe);
+        } catch (final ArchiverException ioe) {
+            throw new MojoExecutionException("Unable to attach 
configuration.", ioe);
+        }
+    }
+
+    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.");
+            return;
+        }
+        // check if we have configurations
+        boolean hasConfigs = this.checkFile(this.getConfigDirectory());
+        hasConfigs |= this.checkFile(this.additionalSlingBootstrap);
+        hasConfigs |= this.checkFile(this.additionalSlingProps);
+
+        if ( !hasConfigs ) {
+            this.getLog().debug("No configurations to attach.");
+            return;
+        }
+        // copy configuration, as this project might use different names we 
have to copy everything!
+        this.configOutputDir.mkdirs();
+        if ( this.checkFile(this.additionalSlingBootstrap) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.additionalSlingBootstrap, new 
File(slingDir, SLING_BOOTSTRAP));
+        }
+        if ( this.checkFile(this.additionalSlingProps) ) {
+            final File slingDir = new File(this.configOutputDir, "sling");
+            slingDir.mkdirs();
+            FileUtils.copyFile(this.additionalSlingProps, new File(slingDir, 
SLING_ADDITIONAL_PROPS));
+        }
+        if ( this.checkFile(this.getConfigDirectory()) ) {
+            final File configDir = new File(this.configOutputDir, "config");
+            configDir.mkdirs();
+            FileUtils.copyDirectory(this.getConfigDirectory(), configDir,
+                    null, FileUtils.getDefaultExcludesAsString());
+        }
+        final File destFile = new File(this.configOutputDir.getParent(), 
this.configOutputDir.getName() + ".zip");
+        zipArchiver.setDestFile(destFile);
+        zipArchiver.addDirectory(this.configOutputDir);
+        zipArchiver.createArchive();
 
+        projectHelper.attachArtifact(project, CONFIG_TYPE, CONFIG_CLASSIFIER, 
destFile);
+    }
 }
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java 
b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
index 67d83c0..dee24c4 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
@@ -303,7 +303,7 @@ public class PreparePackageMojo extends 
AbstractLaunchpadFrameworkMojo {
 
     private void copyConfigurationFiles() throws MojoExecutionException {
         try {
-            FileUtils.copyDirectory(configDirectory, new 
File(getOutputDirectory(), CONFIG_PATH_PREFIX), null, 
FileUtils.getDefaultExcludesAsString());
+            FileUtils.copyDirectory(this.getConfigDirectory(), new 
File(getOutputDirectory(), CONFIG_PATH_PREFIX), null, 
FileUtils.getDefaultExcludesAsString());
         } catch (IOException e) {
             throw new MojoExecutionException("Unable to copy configuration 
files", e);
         }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to