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

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

commit b497a89d8584050d2e1ee4f27c5e6a35116e5774
Author: Justin Edelson <[email protected]>
AuthorDate: Wed Oct 19 19:14:54 2011 +0000

    SLING-2194 - generating bundle list content from a project's dependencies; 
refactoring testing projects to use this feature.
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1186417
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  1 -
 .../projectsupport/AbstractBundleListMojo.java     | 42 ++++++++++++++++++++
 .../AbstractUsingBundleListMojo.java               | 13 +-----
 .../maven/projectsupport/ArtifactDefinition.java   | 46 +++++++++++++++++-----
 .../AttachPartialBundleListMojo.java               | 36 ++++++++++++++---
 5 files changed, 111 insertions(+), 27 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2cb1d42..3265d3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,6 @@
         <relativePath>../../parent/pom.xml</relativePath>
     </parent>
 
-    <groupId>org.apache.sling</groupId>
     <artifactId>maven-launchpad-plugin</artifactId>
     <version>2.1.1-SNAPSHOT</version>
     <packaging>maven-plugin</packaging>
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 912fa3d..226e5fb 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
@@ -17,10 +17,17 @@
 package org.apache.sling.maven.projectsupport;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
 
+import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
+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.xml.pull.XmlPullParserException;
 
 public abstract class AbstractBundleListMojo extends AbstractMojo {
 
@@ -90,7 +97,42 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
      */
     protected File standaloneSlingBootstrap;
 
+    /**
+     * @parameter expression="${ignoreBundleListConfig}"
+     *            default-value="false"
+     */
+    protected boolean ignoreBundleListConfig;
+
+    /**
+     * The start level to be used when generating the bundle list.
+     * 
+     * @parameter default-value="-1"
+     */
+    private int dependencyStartLevel;
+
     protected File getConfigDirectory() {
         return this.configDirectory;
     }
+
+    protected BundleList readBundleList(File file) throws IOException, 
XmlPullParserException {
+        BundleListXpp3Reader reader = new BundleListXpp3Reader();
+        FileInputStream fis = new FileInputStream(file);
+        try {
+            return reader.read(fis);
+        } finally {
+            fis.close();
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void addDependencies(final BundleList bundleList) {
+        if (dependencyStartLevel >= 0) {
+            final List<Dependency> dependencies = project.getDependencies();
+            for (Dependency dependency : dependencies) {
+                if (!PARTIAL.equals(dependency.getType())) {
+                    bundleList.add(ArtifactDefinition.toBundle(dependency, 
dependencyStartLevel));
+                }
+            }
+        }
+    }
 }
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 b6fc886..6117498 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
@@ -17,7 +17,6 @@
 package org.apache.sling.maven.projectsupport;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
@@ -48,7 +47,6 @@ import org.apache.maven.shared.filtering.PropertyUtils;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
-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.interpolation.InterpolationException;
@@ -359,6 +357,7 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
                 bundleList.add(def.toBundle());
             }
         }
+        addDependencies(bundleList);
         if (bundleExclusions != null) {
             for (ArtifactDefinition def : bundleExclusions) {
                 bundleList.remove(def.toBundle(), false);
@@ -513,16 +512,6 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
         return base;
     }
 
-    private BundleList readBundleList(File file) throws IOException, 
XmlPullParserException {
-        BundleListXpp3Reader reader = new BundleListXpp3Reader();
-        FileInputStream fis = new FileInputStream(file);
-        try {
-            return reader.read(fis);
-        } finally {
-            fis.close();
-        }
-    }
-
     private void copyProperties(final Properties source, final Properties 
dest) {
         final Enumeration<Object> keys = source.keys();
         while ( keys.hasMoreElements() ) {
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java 
b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
index 801b879..e5dab31 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.maven.projectsupport;
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -45,16 +47,34 @@ public class ArtifactDefinition {
     public ArtifactDefinition() {
     }
 
+    public ArtifactDefinition(Artifact artifact, int startLevel) {
+        this.groupId = artifact.getGroupId();
+        this.artifactId = artifact.getArtifactId();
+        this.type = artifact.getType();
+        this.version = artifact.getVersion();
+        this.classifier = artifact.getClassifier();
+        this.startLevel = startLevel;
+    }
+
+    public ArtifactDefinition(Dependency dependency, int startLevel) {
+        this.groupId = dependency.getGroupId();
+        this.artifactId = dependency.getArtifactId();
+        this.type = dependency.getType();
+        this.version = dependency.getVersion();
+        this.classifier = dependency.getClassifier();
+        this.startLevel = startLevel;
+    }
+    
     public ArtifactDefinition(Bundle bundle, int startLevel) {
-               this.groupId = bundle.getGroupId();
-               this.artifactId = bundle.getArtifactId();
-               this.type = bundle.getType();
-               this.version = bundle.getVersion();
-               this.classifier = bundle.getClassifier();
-               this.startLevel = startLevel;
-       }
-
-       public String getArtifactId() {
+        this.groupId = bundle.getGroupId();
+        this.artifactId = bundle.getArtifactId();
+        this.type = bundle.getType();
+        this.version = bundle.getVersion();
+        this.classifier = bundle.getClassifier();
+        this.startLevel = startLevel;
+    }
+
+    public String getArtifactId() {
         return artifactId;
     }
 
@@ -185,5 +205,13 @@ public class ArtifactDefinition {
         bnd.setStartLevel(startLevel);
         return bnd;
     }
+    
+    public static Bundle toBundle(Artifact artifact, int startLevel) {
+        return new ArtifactDefinition(artifact, startLevel).toBundle();
+    }
+    
+    public static Bundle toBundle(Dependency dependency, int startLevel) {
+        return new ArtifactDefinition(dependency, startLevel).toBundle();
+    }
 
 }
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 40f5732..ed2c8ac 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
@@ -17,13 +17,17 @@
 package org.apache.sling.maven.projectsupport;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
+import 
org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.zip.ZipArchiver;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * Attaches the bundle list as a project artifact.
@@ -54,12 +58,11 @@ public class AttachPartialBundleListMojo extends 
AbstractBundleListMojo {
      * @parameter default-value="${project.build.directory}/bundleListconfig"
      */
     private File configOutputDir;
-
+    
     /**
-     * @parameter expression="${ignoreBundleListConfig}"
-     *            default-value="false"
+     * @parameter default-value="${project.build.directory}/list.xml"
      */
-    private boolean ignoreBundleListConfig;
+    private File bundleListOutput;
 
     /**
      * The zip archiver.
@@ -69,7 +72,30 @@ public class AttachPartialBundleListMojo extends 
AbstractBundleListMojo {
     private ZipArchiver zipArchiver;
 
     public void execute() throws MojoExecutionException, MojoFailureException {
-        project.getArtifact().setFile(bundleListFile);
+        final BundleList bundleList;
+        if (bundleListFile.exists()) {
+            try {
+                bundleList = readBundleList(bundleListFile);
+            } catch (IOException e) {
+                throw new MojoExecutionException("Unable to read bundle list 
file", e);
+            } catch (XmlPullParserException e) {
+                throw new MojoExecutionException("Unable to read bundle list 
file", e);
+            }
+        } else {
+            bundleList = new BundleList();
+        }
+        
+        addDependencies(bundleList);
+        
+        BundleListXpp3Writer writer = new BundleListXpp3Writer();
+        try {
+            writer.write(new FileWriter(bundleListOutput), bundleList);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Unable to write bundle list", e);
+        }
+        
+        project.getArtifact().setFile(bundleListOutput);
+
         this.getLog().info("Attaching bundle list configuration");
         try {
             this.attachConfigurations();

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

Reply via email to