incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1202041 - in /sling/trunk: launchpad/builder/ launchpad/testing/ maven/maven-launchpad-plugin/ maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/
Date Tue, 15 Nov 2011 04:45:09 GMT
Author: justin
Date: Tue Nov 15 04:45:09 2011
New Revision: 1202041

URL: http://svn.apache.org/viewvc?rev=1202041&view=rev
Log:
SLING-2273 - implementing a LifecycleParticipant which adds bundle list contents as dependencies

Added:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
Modified:
    sling/trunk/launchpad/builder/pom.xml
    sling/trunk/launchpad/testing/pom.xml
    sling/trunk/maven/maven-launchpad-plugin/pom.xml
    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/ArtifactDefinition.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/CreateBundleJarMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java

Modified: sling/trunk/launchpad/builder/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/pom.xml?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/pom.xml (original)
+++ sling/trunk/launchpad/builder/pom.xml Tue Nov 15 04:45:09 2011
@@ -91,7 +91,8 @@
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>maven-launchpad-plugin</artifactId>
-                <version>2.0.10</version>
+                <version>2.1.1-SNAPSHOT</version>
+                <extensions>true</extensions>
                 <executions>
                     <execution>
                         <id>prepare-package-war</id>

Modified: sling/trunk/launchpad/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/pom.xml?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/pom.xml (original)
+++ sling/trunk/launchpad/testing/pom.xml Tue Nov 15 04:45:09 2011
@@ -133,7 +133,7 @@
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>maven-launchpad-plugin</artifactId>
-                <version>2.1.0</version>
+                <version>2.1.1-SNAPSHOT</version>
                 <extensions>true</extensions>
                 <executions>
                     <execution>

Modified: sling/trunk/maven/maven-launchpad-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/pom.xml?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/pom.xml (original)
+++ sling/trunk/maven/maven-launchpad-plugin/pom.xml Tue Nov 15 04:45:09 2011
@@ -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>
 

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=1202041&r1=1202040&r2=1202041&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 Tue Nov 15 04:45:09 2011
@@ -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.AbstractM
 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 AbstractBundleList
      * @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 AbstractBundleList
         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 AbstractBundleList
         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 AbstractBundleList
                 // 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) {

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=1202041&r1=1202040&r2=1202041&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 Tue Nov 15 04:45:09 2011
@@ -43,6 +43,9 @@ import org.drools.builder.KnowledgeBuild
 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 AbstractUsingBundl
     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 AbstractUsingBundl
     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 AbstractUsingBundl
      * @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 AbstractUsingBundl
                         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);

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java Tue Nov 15 04:45:09 2011
@@ -20,6 +20,8 @@ import org.apache.maven.artifact.Artifac
 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();
+    }
+
 }

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=1202041&r1=1202040&r2=1202041&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 Tue Nov 15 04:45:09 2011
@@ -28,6 +28,7 @@ import org.codehaus.plexus.archiver.Arch
 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.

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java?rev=1202041&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListUtils.java Tue Nov 15 04:45:09 2011
@@ -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);
+    }
+
+}

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java Tue Nov 15 04:45:09 2011
@@ -164,7 +164,6 @@ public class CreateBundleJarMojo extends
      *            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());

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/DisplayBundleUpdatesMojo.java Tue Nov 15 04:45:09 2011
@@ -81,13 +81,13 @@ public class DisplayBundleUpdatesMojo ex
      * @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}"

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java?rev=1202041&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java Tue Nov 15 04:45:09 2011
@@ -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;
+        }
+    }
+}

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java?rev=1202041&r1=1202040&r2=1202041&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ValidateBundleListMojo.java Tue Nov 15 04:45:09 2011
@@ -24,6 +24,8 @@ import org.apache.sling.maven.projectsup
 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 exte
         
         addDependencies(initializedBundleList);
 
-        interpolateProperties(initializedBundleList);
+        interpolateProperties(initializedBundleList, project, mavenSession);
         
         for (StartLevel sl : initializedBundleList.getStartLevels()) {
             for (Bundle bundle : sl.getBundles()) {



Mime
View raw message