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 e0008c40a0c1fda7888f2c8fcabed924dcb8829a
Author: Justin Edelson <[email protected]>
AuthorDate: Tue Nov 15 04:45:09 2011 +0000

    SLING-2273 - implementing a LifecycleParticipant which adds bundle list 
contents as dependencies
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1202041
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  63 +++++-
 .../projectsupport/AbstractBundleListMojo.java     |  71 +------
 .../AbstractUsingBundleListMojo.java               | 152 +++++++-------
 .../maven/projectsupport/ArtifactDefinition.java   |  29 ++-
 .../AttachPartialBundleListMojo.java               |   1 +
 .../maven/projectsupport/BundleListUtils.java      | 154 ++++++++++++++
 .../maven/projectsupport/CreateBundleJarMojo.java  |   1 -
 .../projectsupport/DisplayBundleUpdatesMojo.java   |   4 +-
 .../LaunchpadPluginLifecycleParticipant.java       | 230 +++++++++++++++++++++
 .../projectsupport/ValidateBundleListMojo.java     |   4 +-
 10 files changed, 560 insertions(+), 149 deletions(-)

diff --git a/pom.xml b/pom.xml
index d61c403..7560e23 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,20 @@
                     </filters>
                 </configuration>
             </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.plexus</groupId>
+                <artifactId>plexus-component-metadata</artifactId>
+                <version>1.5.5</version>
+                <executions>
+                    <execution>
+                        <id>generate-metadata</id>
+                        <goals>
+                            <goal>generate-metadata</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 
@@ -98,15 +112,20 @@
     </reporting>
 
     <dependencies>
+       <dependency>
+           <groupId>org.apache.maven</groupId>
+           <artifactId>maven-core</artifactId>
+           <version>3.0</version>
+       </dependency>
+       <dependency>
+           <groupId>org.apache.maven</groupId>
+           <artifactId>maven-compat</artifactId>
+           <version>3.0</version>
+       </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-plugin-api</artifactId>
-            <version>2.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.maven</groupId>
-            <artifactId>maven-archiver</artifactId>
-            <version>2.0</version>
+            <version>3.0</version>
         </dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
@@ -128,6 +147,16 @@
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-dependency-plugin</artifactId>
             <version>2.3</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>maven-project</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>maven-artifact-manager</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
@@ -164,11 +193,23 @@
             <groupId>org.apache.maven.shared</groupId>
             <artifactId>maven-filtering</artifactId>
             <version>1.0</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>maven-project</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.maven.shared</groupId>
             <artifactId>maven-osgi</artifactId>
             <version>0.2.0</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>maven-project</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.drools</groupId>
@@ -179,6 +220,16 @@
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>versions-maven-plugin</artifactId>
             <version>1.2</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>maven-project</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>maven-artifact-manager</artifactId>
+                    <groupId>org.apache.maven</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
     </dependencies>
 
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 54d402a..7119c21 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
@@ -17,11 +17,7 @@
 package org.apache.sling.maven.projectsupport;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
-import java.util.Properties;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
@@ -41,19 +37,9 @@ import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.settings.Settings;
 import 
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
-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.interpolation.InterpolationException;
-import org.codehaus.plexus.interpolation.Interpolator;
-import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
-import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
-import org.codehaus.plexus.interpolation.StringSearchInterpolator;
 import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 public abstract class AbstractBundleListMojo extends AbstractMojo {
 
@@ -178,7 +164,7 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
      * @readonly
      * @required
      */
-    private List<?> remoteRepos;
+    private List<ArtifactRepository> remoteRepos;
 
     /**
      * Used to look up Artifacts in the remote repository.
@@ -191,17 +177,6 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
         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) throws 
MojoExecutionException {
         if (includeDependencies != null) {
             for (ConfigurationStartLevel startLevel : includeDependencies) {
@@ -237,48 +212,6 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
         return artifacts;
     }
 
-    protected void interpolateProperties(BundleList bundleList) throws 
MojoExecutionException {
-        Interpolator interpolator = createInterpolator();
-        for (final StartLevel sl : bundleList.getStartLevels()) {
-            for (final Bundle bndl : sl.getBundles()) {
-                try {
-                    
bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
-                    
bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
-                    
bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
-                    
bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
-                    bndl.setType(interpolator.interpolate(bndl.getType()));
-                } catch (InterpolationException e) {
-                    throw new MojoExecutionException("Unable to interpolate 
properties for bundle " + bndl.toString(), e);
-                }
-            }
-        }
-
-    }
-
-    private Interpolator createInterpolator() {
-        StringSearchInterpolator interpolator = new StringSearchInterpolator();
-
-        final Properties props = new Properties();
-        props.putAll(project.getProperties());
-        props.putAll(mavenSession.getExecutionProperties());
-
-        interpolator.addValueSource(new PropertiesBasedValueSource(props));
-
-        // add ${project.foo}
-        interpolator.addValueSource(new 
PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
-
-        // add ${session.foo}
-        interpolator.addValueSource(new PrefixedObjectValueSource("session", 
mavenSession));
-
-        // add ${settings.foo}
-        final Settings settings = mavenSession.getSettings();
-        if (settings != null) {
-            interpolator.addValueSource(new 
PrefixedObjectValueSource("settings", settings));
-        }
-
-        return interpolator;
-    }
-
     /**
      * Get a resolved Artifact from the coordinates found in the artifact
      * definition.
@@ -318,7 +251,7 @@ public abstract class AbstractBundleListMojo extends 
AbstractMojo {
                 // This code kicks in when the version specifier is a range.
                 if (vr.getRecommendedVersion() == null) {
                     try {
-                        List<?> availVersions = 
metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
+                        List<ArtifactVersion> availVersions = 
metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
                         ArtifactVersion resolvedVersion = 
vr.matchVersion(availVersions);
                         artifact.setVersion(resolvedVersion.toString());
                     } catch (ArtifactMetadataRetrievalException e) {
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 87890da..3f242a4 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
@@ -43,6 +43,9 @@ import org.drools.builder.KnowledgeBuilderFactory;
 import org.drools.builder.ResourceType;
 import org.drools.io.ResourceFactory;
 import org.drools.runtime.StatefulKnowledgeSession;
+import 
org.apache.sling.maven.projectsupport.BundleListUtils.ArtifactDefinitionsCallback;
+import static 
org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList;
+import static 
org.apache.sling.maven.projectsupport.BundleListUtils.interpolateProperties;
 
 public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo {
 
@@ -141,6 +144,7 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
     public final void execute() throws MojoFailureException, 
MojoExecutionException {
         try {
             initBundleList();
+            extractConfigurations();
         } catch (MojoExecutionException e) {
             throw e;
         } catch (Exception e) {
@@ -183,10 +187,6 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
     protected void initBundleList(BundleList bundleList) {
     }
 
-    protected boolean isCurrentArtifact(ArtifactDefinition def) {
-        return (def.getGroupId().equals(project.getGroupId()) && 
def.getArtifactId().equals(project.getArtifactId()));
-    }
-
     /**
      * Initialize the artifact definitions using defaults inside the plugin 
JAR.
      *
@@ -195,22 +195,22 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
      * @throws MojoExecutionException
      */
     private final void initArtifactDefinitions() throws IOException {
-        Properties dependencies = new Properties();
-        dependencies.load(getClass().getResourceAsStream(
-                
"/org/apache/sling/maven/projectsupport/dependencies.properties"));
-
-        if (defaultBundleList == null) {
-            defaultBundleList = new ArtifactDefinition();
-        }
-        
defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));
+        BundleListUtils.initArtifactDefinitions(getClass().getClassLoader(), 
new ArtifactDefinitionsCallback() {
+            
+            public void initArtifactDefinitions(Properties dependencies) {
+                if (defaultBundleList == null) {
+                    defaultBundleList = new ArtifactDefinition();
+                }
+                
defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));
 
-        initArtifactDefinitions(dependencies);
+                
AbstractUsingBundleListMojo.this.initArtifactDefinitions(dependencies);
+            }
+        });
     }
 
-    @SuppressWarnings("unchecked")
     private final void initBundleList() throws IOException, 
XmlPullParserException, MojoExecutionException {
         initArtifactDefinitions();
-        if (isCurrentArtifact(defaultBundleList)) {
+        if (BundleListUtils.isCurrentArtifact(project, defaultBundleList)) {
             initializedBundleList = readBundleList(bundleListFile);
         } else {
             initializedBundleList = new BundleList();
@@ -245,70 +245,84 @@ public abstract class AbstractUsingBundleListMojo extends 
AbstractBundleListMojo
                         String.format("merging partial bundle list for 
%s:%s:%s", artifact.getGroupId(),
                                 artifact.getArtifactId(), 
artifact.getVersion()));
                 
initializedBundleList.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_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 ) {
-                            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);
-                    }
-                }
             }
         }
 
 
         initBundleList(initializedBundleList);
 
-        interpolateProperties(initializedBundleList);
+        interpolateProperties(initializedBundleList, project, mavenSession);
 
         rewriteBundleList(initializedBundleList);
     }
     
+    private final void extractConfigurations() throws MojoExecutionException, 
IOException {
+        final Set<Artifact> dependencies = project.getDependencyArtifacts();
+        for (Artifact artifact : dependencies) {
+            if (PARTIAL.equals(artifact.getType())) {
+                getLog().info(
+                        String.format("merging configuration from partial 
bundle list for %s:%s:%s", artifact.getGroupId(),
+                                artifact.getArtifactId(), 
artifact.getVersion()));
+                extractConfiguration(artifact);
+            }
+        }
+    }
+
+    private void extractConfiguration(Artifact artifact) throws 
MojoExecutionException, IOException {
+        // 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_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 ) {
+                    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);
+            }
+        }
+    }
+    
     private void rewriteBundleList(BundleList bundleList) throws 
MojoExecutionException {
         if (rewriteRuleFiles != null) {
             KnowledgeBase knowledgeBase = 
createKnowledgeBase(rewriteRuleFiles);
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 e5dab31..43b08f6 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
@@ -20,6 +20,8 @@ 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;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import static org.apache.sling.maven.projectsupport.BundleListUtils.*;
 
 /**
  * The definition of an artifact.
@@ -74,6 +76,15 @@ public class ArtifactDefinition {
         this.startLevel = startLevel;
     }
 
+    public ArtifactDefinition(Xpp3Dom config) {
+        this.groupId = nodeValue(config, "groupId", null);
+        this.artifactId = nodeValue(config, "artifactId", null);
+        this.type = nodeValue(config, "type", null);
+        this.version = nodeValue(config, "version", null);
+        this.classifier = nodeValue(config, "classifier", null);
+        this.startLevel = nodeValue(config, "startLevel", 0);
+    }
+
     public String getArtifactId() {
         return artifactId;
     }
@@ -124,7 +135,7 @@ public class ArtifactDefinition {
 
     @Override
     public String toString() {
-        return "AdditionalBundle [artifactId=" + artifactId + ", classifier="
+        return "ArtifactDefinition [artifactId=" + artifactId + ", classifier="
                 + classifier + ", groupId=" + groupId + ", startLevel="
                 + startLevel + ", type=" + type + ", version=" + version + "]";
     }
@@ -205,6 +216,18 @@ public class ArtifactDefinition {
         bnd.setStartLevel(startLevel);
         return bnd;
     }
+
+    public Dependency toDependency() {
+        Dependency dep = new Dependency();
+        dep.setArtifactId(artifactId);
+        dep.setGroupId(groupId);
+        dep.setVersion(version);
+        if (type != null) {
+            dep.setType(type);
+        }
+        dep.setClassifier(classifier);
+        return dep;
+    }
     
     public static Bundle toBundle(Artifact artifact, int startLevel) {
         return new ArtifactDefinition(artifact, startLevel).toBundle();
@@ -214,4 +237,8 @@ public class ArtifactDefinition {
         return new ArtifactDefinition(dependency, startLevel).toBundle();
     }
 
+    public static Dependency toDependency(Bundle bundle) {
+        return new ArtifactDefinition(bundle, 0).toDependency();
+    }
+
 }
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 470aef0..aff92b0 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
@@ -28,6 +28,7 @@ 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;
+import static 
org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList;
 
 /**
  * Attaches the bundle list as a project artifact.
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java 
b/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java
new file mode 100644
index 0000000..4b96313
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * 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
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.sling.maven.projectsupport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+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.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
+import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Miscellaneous helper methods for working with bundle lists.
+ */
+public class BundleListUtils {
+    
+    private BundleListUtils() {}
+    
+    /**
+     * Initialize the artifact definitions using defaults inside the plugin 
JAR.
+     *
+     * @throws IOException if the default properties can't be read
+     * @throws XmlPullParserException
+     * @throws MojoExecutionException
+     */
+    public static final void initArtifactDefinitions(ClassLoader classLoader, 
ArtifactDefinitionsCallback callback) throws IOException {
+        Properties dependencies = new Properties();
+        dependencies.load(classLoader.getResourceAsStream(
+                
"org/apache/sling/maven/projectsupport/dependencies.properties"));
+
+        callback.initArtifactDefinitions(dependencies);
+    }
+    
+    public static boolean isCurrentArtifact(MavenProject project, 
ArtifactDefinition def) {
+        return (def.getGroupId().equals(project.getGroupId()) && 
def.getArtifactId().equals(project.getArtifactId()));
+    }
+    
+    public static BundleList readBundleList(File file) throws IOException, 
XmlPullParserException {
+        BundleListXpp3Reader reader = new BundleListXpp3Reader();
+        FileInputStream fis = new FileInputStream(file);
+        try {
+            return reader.read(fis);
+        } finally {
+            fis.close();
+        }
+    }
+    
+    public static int nodeValue(Xpp3Dom config, String name, int defaultValue) 
{
+        Xpp3Dom node = config.getChild(name);
+        if (node != null) {
+            return Integer.parseInt(node.getValue());
+        } else {
+            return defaultValue;
+        }
+    }
+    
+    public static boolean nodeValue(Xpp3Dom config, String name, boolean 
defaultValue) {
+        Xpp3Dom node = config.getChild(name);
+        if (node != null) {
+            return Boolean.parseBoolean(node.getValue());
+        } else {
+            return defaultValue;
+        }
+    }
+
+    public static String nodeValue(Xpp3Dom config, String name, String 
defaultValue) {
+        Xpp3Dom node = config.getChild(name);
+        if (node != null) {
+            return node.getValue();
+        } else {
+            return defaultValue;
+        }
+    }
+    
+    public static void interpolateProperties(BundleList bundleList, 
MavenProject project, MavenSession mavenSession) throws MojoExecutionException {
+        Interpolator interpolator = createInterpolator(project, mavenSession);
+        for (final StartLevel sl : bundleList.getStartLevels()) {
+            for (final Bundle bndl : sl.getBundles()) {
+                try {
+                    
bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
+                    
bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
+                    
bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
+                    
bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
+                    bndl.setType(interpolator.interpolate(bndl.getType()));
+                } catch (InterpolationException e) {
+                    throw new MojoExecutionException("Unable to interpolate 
properties for bundle " + bndl.toString(), e);
+                }
+            }
+        }
+
+    }
+    
+    public static Interpolator createInterpolator(MavenProject project, 
MavenSession mavenSession) {
+        StringSearchInterpolator interpolator = new StringSearchInterpolator();
+
+        final Properties props = new Properties();
+        props.putAll(project.getProperties());
+        props.putAll(mavenSession.getSystemProperties());
+        props.putAll(mavenSession.getUserProperties());
+        
+        interpolator.addValueSource(new PropertiesBasedValueSource(props));
+
+        // add ${project.foo}
+        interpolator.addValueSource(new 
PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
+
+        // add ${session.foo}
+        interpolator.addValueSource(new PrefixedObjectValueSource("session", 
mavenSession));
+
+        // add ${settings.foo}
+        final Settings settings = mavenSession.getSettings();
+        if (settings != null) {
+            interpolator.addValueSource(new 
PrefixedObjectValueSource("settings", settings));
+        }
+
+        return interpolator;
+    }
+
+    /**
+     * Callback interface for use with initArtifactDefinitions.
+     */
+    public static interface ArtifactDefinitionsCallback {
+        void initArtifactDefinitions(Properties dependencies);
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java 
b/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
index a969d81..dc848e7 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
@@ -164,7 +164,6 @@ public class CreateBundleJarMojo extends 
AbstractLaunchpadFrameworkMojo {
      *            the resource to be scanned
      * @return the array of filenames, relative to the sourceDir
      */
-    @SuppressWarnings("unchecked")
     private static String[] getFilesToCopy(Resource resource) {
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir(resource.getDirectory());
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
index 2b9868f..7f11573 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
@@ -81,13 +81,13 @@ public class DisplayBundleUpdatesMojo extends AbstractMojo {
      * @parameter expression="${project.remoteArtifactRepositories}"
      * @readonly
      */
-    private List remoteArtifactRepositories;
+    private List<ArtifactRepository> remoteArtifactRepositories;
 
     /**
      * @parameter expression="${project.pluginArtifactRepositories}"
      * @readonly
      */
-    private List remotePluginRepositories;
+    private List<ArtifactRepository> remotePluginRepositories;
 
     /**
      * @parameter expression="${localRepository}"
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
new file mode 100644
index 0000000..606a6a2
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * 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
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.sling.maven.projectsupport;
+
+import static org.apache.sling.maven.projectsupport.BundleListUtils.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.MavenExecutionException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+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.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Maven lifecycle participant which adds the default bundle list, the
+ * jar web support bundle, and the contents of any local bundle list.
+ */
+@Component(role = AbstractMavenLifecycleParticipant.class)
+public class LaunchpadPluginLifecycleParticipant extends 
AbstractMavenLifecycleParticipant {
+
+    private static final String PLUGIN_ID = "maven-launchpad-plugin";
+
+    @Requirement
+    private Logger log;
+
+    @Override
+    public void afterProjectsRead(MavenSession session) throws 
MavenExecutionException {
+        try {
+            Map<String, MavenProject> projectMap = new HashMap<String, 
MavenProject>();
+            for (MavenProject project : session.getProjects()) {
+                projectMap.put(project.getGroupId() + ":" + 
project.getArtifactId() + ":" + project.getVersion(),
+                        project);
+            }
+
+            for (MavenProject project : session.getProjects()) {
+                for (Plugin plugin : project.getBuild().getPlugins()) {
+                    if (plugin.getArtifactId().equals(PLUGIN_ID)) {
+                        BundleListDependencyAdder performer = new 
BundleListDependencyAdder(session, project, plugin);
+                        performer.addDependencies();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new MavenExecutionException("Unable to determine launchpad 
plugin-based dependencies", e);
+        }
+        super.afterProjectsRead(session);
+    }
+
+    private class BundleListDependencyAdder {
+
+        private final MavenSession session;
+        private final MavenProject project;
+        private final Plugin plugin;
+        private final List<ArtifactDefinition> additionalBundles;
+
+        private ArtifactDefinition defaultBundleList;
+        private boolean includeDefaultBundles;
+        private ArtifactDefinition jarWebSupport;
+        private File bundleListFile;
+
+        public BundleListDependencyAdder(MavenSession session, MavenProject 
project, Plugin plugin) {
+            this.session = session;
+            this.project = project;
+            this.plugin = plugin;
+            this.additionalBundles = new ArrayList<ArtifactDefinition>();
+        }
+
+        void addDependencies() throws Exception {
+            readConfiguration();
+            
+            addBundleListDependencies();
+
+            if (hasPreparePackageExecution()) {
+                if (includeDefaultBundles && !isCurrentArtifact(project, 
defaultBundleList)) {
+                    log.debug(String.format("adding default bundle list (%s) 
to dependencies of project %s", defaultBundleList, project));
+                    
project.getDependencies().add(defaultBundleList.toDependency());
+                }
+
+                if (hasJarPackagingExecution()) {
+                    log.debug(String.format("adding jar web support (%s) to 
dependencies of project %s", jarWebSupport, project));
+                    
project.getDependencies().add(jarWebSupport.toDependency());
+                }
+            }
+        }
+
+        private void addBundleListDependencies() throws IOException, 
XmlPullParserException, MojoExecutionException {
+            BundleList bundleList;
+            
+            if (bundleListFile.exists()) {
+                bundleList = readBundleList(bundleListFile);
+            } else {
+                bundleList = new BundleList();
+            }
+            
+            if (additionalBundles != null) {
+                for (ArtifactDefinition def : additionalBundles) {
+                    bundleList.add(def.toBundle());
+                }
+            }
+            
+            interpolateProperties(bundleList, project, session);
+            
+            for (StartLevel startLevel : bundleList.getStartLevels()) {
+                for (Bundle bundle : startLevel.getBundles()) {
+                    log.debug(String.format("adding bundle (%s) from bundle 
list to dependencies of project %s", bundle, project));
+                    
project.getDependencies().add(ArtifactDefinition.toDependency(bundle));
+                }
+            }
+        }
+
+        private void readConfiguration() throws IOException {
+            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
+            defaultBundleList = null;
+            jarWebSupport = null;
+            includeDefaultBundles = true;
+            bundleListFile = new File(project.getBasedir(), 
"src/main/bundles/list.xml");
+            if (configuration != null) {
+                includeDefaultBundles = nodeValue(configuration, 
"includeDefaultBundles", true);
+                Xpp3Dom defaultBundleListConfig = 
configuration.getChild("defaultBundleList");
+                if (defaultBundleListConfig != null) {
+                    defaultBundleList = new 
ArtifactDefinition(defaultBundleListConfig);
+                }
+                Xpp3Dom jarWebSupportConfig = 
configuration.getChild("jarWebSupport");
+                if (jarWebSupportConfig != null) {
+                    jarWebSupport = new 
ArtifactDefinition(jarWebSupportConfig);
+                }
+                Xpp3Dom bundleListFileConfig = 
configuration.getChild("bundleListFile");
+                if (bundleListFileConfig != null) {
+                    bundleListFile = new File(project.getBasedir(), 
bundleListFileConfig.getValue());
+                }
+                
+                configureAdditionalBundles(configuration);
+            }
+            
+            for (PluginExecution execution : plugin.getExecutions()) {
+                Xpp3Dom executionConfiguration = (Xpp3Dom) 
execution.getConfiguration();
+                if (executionConfiguration != null) {
+                    configureAdditionalBundles(executionConfiguration);
+                }
+            }
+
+            initArtifactDefinitions(getClass().getClassLoader(), new 
ArtifactDefinitionsCallback() {
+
+                public void initArtifactDefinitions(Properties dependencies) {
+                    if (defaultBundleList == null) {
+                        defaultBundleList = new ArtifactDefinition();
+                    }
+                    
defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));
+
+                    if (jarWebSupport == null) {
+                        jarWebSupport = new ArtifactDefinition();
+                    }
+                    
jarWebSupport.initDefaults(dependencies.getProperty("jarWebSupport"));
+                }
+            });
+        }
+
+        private void configureAdditionalBundles(Xpp3Dom configuration) {
+            Xpp3Dom additionalBundlesConfig = 
configuration.getChild("additionalBundles");
+            if (additionalBundlesConfig != null) {
+                Xpp3Dom[] bundleConfigs = 
additionalBundlesConfig.getChildren("bundle");
+                if (bundleConfigs != null) {
+                    for (Xpp3Dom bundleConfig : bundleConfigs) {
+                        additionalBundles.add(new 
ArtifactDefinition(bundleConfig));
+                    }
+                }
+            }
+        }
+
+        private boolean hasJarPackagingExecution() {
+            if 
(AbstractUsingBundleListMojo.JAR.equals(project.getPackaging())) {
+                return true;
+            } else {
+                for (PluginExecution execution : plugin.getExecutions()) {
+                    if (execution.getGoals().contains("prepare-package")) {
+                        Xpp3Dom executionConfig = (Xpp3Dom) 
execution.getConfiguration();
+                        if (executionConfig != null) {
+                            Xpp3Dom packagingConfig = 
executionConfig.getChild("packaging");
+                            if (packagingConfig != null
+                                    && 
AbstractUsingBundleListMojo.JAR.equals(packagingConfig.getValue())) {
+                                return true;
+                            }
+                        }
+                    }
+                }
+                return false;
+            }
+        }
+
+        private boolean hasPreparePackageExecution() {
+            for (PluginExecution execution : plugin.getExecutions()) {
+                if (execution.getGoals().contains("prepare-package")) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+}
diff --git 
a/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
 
b/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
index bb12d9d..d57d2f7 100644
--- 
a/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
@@ -24,6 +24,8 @@ 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.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import static 
org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList;
+import static 
org.apache.sling.maven.projectsupport.BundleListUtils.interpolateProperties;
 
 /**
  * Validate that the artifacts listed in a bundle list are valid
@@ -51,7 +53,7 @@ public class ValidateBundleListMojo extends 
AbstractBundleListMojo {
         
         addDependencies(initializedBundleList);
 
-        interpolateProperties(initializedBundleList);
+        interpolateProperties(initializedBundleList, project, mavenSession);
         
         for (StartLevel sl : initializedBundleList.getStartLevels()) {
             for (Bundle bundle : sl.getBundles()) {

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

Reply via email to