incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r906180 - in /sling/trunk/maven/maven-launchpad-plugin/src: main/java/org/apache/sling/maven/projectsupport/ main/java/org/apache/sling/maven/projectsupport/bundlelist/ main/mdo/ test/java/org/apache/sling/maven/projectsupport/
Date Wed, 03 Feb 2010 19:08:37 GMT
Author: justin
Date: Wed Feb  3 19:08:36 2010
New Revision: 906180

URL: http://svn.apache.org/viewvc?rev=906180&view=rev
Log:
Unifying bundle addition / removal code (re: SLING-1321)

Added:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundle.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseStartLevel.java
Modified:
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CheckBundleListForSnapshotsMojo.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/CreateKarafFeatureDescriptorMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
    sling/trunk/maven/maven-launchpad-plugin/src/main/mdo/bundle-list.xml
    sling/trunk/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/PreparePackageMojoTest.java

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java?rev=906180&r1=906179&r2=906180&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 Wed Feb  3 19:08:36 2010
@@ -35,75 +35,72 @@
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
-import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
-import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader;
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.archiver.UnArchiver;
-import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
-import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 public abstract class AbstractBundleListMojo extends AbstractMojo {
 
     /**
-     * The name of the directory within the output directory into which the base
-     * JAR should be installed.
-     *
-     * @parameter default-value="resources"
+     * JAR Packaging type.
      */
-    protected String baseDestination;
+    protected static final String JAR = "jar";
 
     /**
-     * The directory which contains the start-level bundle directories.
-     *
-     * @parameter default-value="bundles"
+     * WAR Packaging type.
      */
-    protected String bundlesDirectory;
+    protected static final String WAR = "war";
+
+    protected static boolean shouldCopy(File source, File dest) {
+        if (!dest.exists()) {
+            return true;
+        } else {
+            return source.lastModified() > dest.lastModified();
+        }
+    }
 
     /**
-     * The definition of the defaultBundleList artifact.
-     *
-     * @parameter
+     * @parameter default-value="${basedir}/src/main/bundles/list.xml"
      */
-    private ArtifactDefinition defaultBundleList;
+    protected File bundleListFile;
 
     /**
-     * The definition of the defaultBundles package.
+     * The definition of the defaultBundleList artifact.
      *
      * @parameter
      */
-    private ArtifactDefinition defaultBundles;
+    protected ArtifactDefinition defaultBundleList;
 
     /**
-     * @parameter default-value="${basedir}/src/main/bundles/list.xml"
+     * The Maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
      */
-    protected File bundleListFile;
+    protected MavenProject project;
 
     /**
-     * To look up Archiver/UnArchiver implementations
-     *
      * @component
      */
-    private ArchiverManager archiverManager;
+    protected MavenProjectHelper projectHelper;
 
     /**
-     * @component
+     * Any additional bundles to include in the project's bundles directory.
+     *
+     * @parameter
      */
-    protected MavenProjectHelper projectHelper;
+    private ArtifactDefinition[] additionalBundles;
+
+    private BundleList bundleList;
 
     /**
-     * The Maven project.
+     * Bundles which should be removed from the project's bundles directory.
      *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
+     * @parameter
      */
-    protected MavenProject project;
+    private ArtifactDefinition[] bundleExclusions;
 
     /**
      * Used to look up Artifacts in the remote repository.
@@ -113,6 +110,13 @@
     private ArtifactFactory factory;
 
     /**
+     * If true, include the default bundles.
+     *
+     * @parameter default-value="true"
+     */
+    private boolean includeDefaultBundles;
+
+    /**
      * Location of the local repository.
      *
      * @parameter expression="${localRepository}"
@@ -122,16 +126,6 @@
     private ArtifactRepository local;
 
     /**
-     * JAR Packaging type.
-     */
-    protected static final String JAR = "jar";
-
-    /**
-     * WAR Packaging type.
-     */
-    protected static final String WAR = "war";
-
-    /**
      * List of Remote Repositories used by the resolver.
      *
      * @parameter expression="${project.remoteArtifactRepositories}"
@@ -147,31 +141,41 @@
      */
     private ArtifactResolver resolver;
 
-    public final void execute() throws MojoFailureException,
-            MojoExecutionException {
+    public final void execute() throws MojoFailureException, MojoExecutionException {
         try {
-            initArtifactDefinitions();
-        } catch (IOException e) {
-            throw new MojoExecutionException(
-                    "Unable to load dependency information from properties file.",
-                    e);
+            initBundleList();
+        } catch (Exception e) {
+            throw new MojoExecutionException("Unable to load dependency information from properties file.", e);
         }
         executeWithArtifacts();
 
     }
 
-    protected abstract void executeWithArtifacts()
-            throws MojoExecutionException, MojoFailureException;
+    /**
+     * Execute the logic of the plugin after the default artifacts have been
+     * initialized.
+     */
+    protected abstract void executeWithArtifacts() throws MojoExecutionException, MojoFailureException;
 
-    protected Artifact getArtifact(ArtifactDefinition bundle)
-            throws MojoExecutionException {
-        return getArtifact(bundle.getGroupId(), bundle.getArtifactId(), bundle
-                .getVersion(), bundle.getType() != null ? bundle.getType()
-                : JAR, bundle.getClassifier());
+    /**
+     * Get a resolved Artifact from the coordinates found in the artifact
+     * definition.
+     *
+     * @param def the artifact definition
+     * @return the artifact, which has been resolved
+     * @throws MojoExecutionException
+     */
+    protected Artifact getArtifact(ArtifactDefinition def) throws MojoExecutionException {
+        return getArtifact(def.getGroupId(), def.getArtifactId(), def.getVersion(), def.getType(), def.getClassifier());
     }
 
-    protected Artifact getArtifact(String groupId, String artifactId,
-            String version, String type, String classifier)
+    /**
+     * Get a resolved Artifact from the coordinates provided
+     *
+     * @return the artifact, which has been resolved.
+     * @throws MojoExecutionException
+     */
+    protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier)
             throws MojoExecutionException {
         Artifact artifact;
         VersionRange vr;
@@ -183,11 +187,10 @@
         }
 
         if (StringUtils.isEmpty(classifier)) {
-            artifact = factory.createDependencyArtifact(groupId, artifactId,
-                    vr, type, null, Artifact.SCOPE_COMPILE);
+            artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE);
         } else {
-            artifact = factory.createDependencyArtifact(groupId, artifactId,
-                    vr, type, classifier, Artifact.SCOPE_COMPILE);
+            artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier,
+                    Artifact.SCOPE_COMPILE);
         }
         try {
             resolver.resolve(artifact, remoteRepos, local);
@@ -199,127 +202,80 @@
         return artifact;
     }
 
-    protected final void initArtifactDefinitions() throws IOException {
-        Properties dependencies = new Properties();
-        dependencies
-                .load(getClass()
-                        .getResourceAsStream(
-                                "/org/apache/sling/maven/projectsupport/dependencies.properties"));
-
-        if (defaultBundles == null) {
-            defaultBundles = new ArtifactDefinition();
-        }
-        defaultBundles.initDefaults(dependencies.getProperty("defaultBundles"));
-
-        if (defaultBundleList == null) {
-            defaultBundleList = new ArtifactDefinition();
-        }
-        defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));
-
-        initArtifactDefinitions(dependencies);
+    protected BundleList getBundleList() {
+        return bundleList;
     }
 
+    /**
+     * Hook methods for subclasses to initialize any additional artifact
+     * definitions.
+     *
+     * @param dependencies the dependency properties loaded from the JAR file
+     */
     protected void initArtifactDefinitions(Properties dependencies) {
     }
 
-    protected void copy(ArtifactDefinition additionalBundle,
-            File outputDirectory) throws MojoExecutionException {
-        Artifact artifact = getArtifact(additionalBundle);
-        copy(artifact.getFile(), additionalBundle.getStartLevel(),
-                outputDirectory);
+    /**
+     * Hook methods for subclasses to initialize the bundle list.
+     */
+    protected void initBundleList(BundleList bundleList) {
     }
 
-    protected void copy(File file, int startLevel, File outputDirectory)
-            throws MojoExecutionException {
-        File destination = new File(outputDirectory, String.format(
-                "%s/%s/%s/%s", baseDestination, bundlesDirectory, startLevel,
-                file.getName()));
-        if (shouldCopy(file, destination)) {
-            getLog().info(
-                    String.format("Copying bundle from %s to %s", file
-                            .getPath(), destination.getPath()));
-            try {
-                FileUtils.copyFile(file, destination);
-            } catch (IOException e) {
-                throw new MojoExecutionException("Unable to copy bundle from "
-                        + file.getPath(), e);
-            }
-        }
+    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.
+     *
+     * @throws IOException if the default properties can't be read
+     * @throws XmlPullParserException
+     * @throws MojoExecutionException
+     */
+    private final void initArtifactDefinitions() throws IOException {
+        Properties dependencies = new Properties();
+        dependencies.load(getClass().getResourceAsStream(
+                "/org/apache/sling/maven/projectsupport/dependencies.properties"));
 
-    protected BundleList readBundleList() throws IOException, XmlPullParserException {
-        return readBundleList(bundleListFile);
-    }
+        if (defaultBundleList == null) {
+            defaultBundleList = new ArtifactDefinition();
+        }
+        defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));
 
+        initArtifactDefinitions(dependencies);
+    }
 
-    protected void outputBundleList(File outputDirectory)
-            throws MojoExecutionException {
-        try {
-            if (bundleListFile != null && bundleListFile.exists()) {
-                getLog().info(
-                        "Using bundle list file from "
-                                + bundleListFile.getAbsolutePath());
-                BundleList bundles = readBundleList(bundleListFile);
-                copyBundles(bundles, outputDirectory);
-                return;
+    private final void initBundleList() throws IOException, XmlPullParserException, MojoExecutionException {
+        initArtifactDefinitions();
+        if (isCurrentArtifact(defaultBundleList)) {
+            bundleList = readBundleList(bundleListFile);
+        } else {
+            bundleList = new BundleList();
+            if (includeDefaultBundles) {
+                Artifact artifact = getArtifact(defaultBundleList.getGroupId(), defaultBundleList.getArtifactId(),
+                        defaultBundleList.getVersion(), defaultBundleList.getType(), defaultBundleList.getClassifier());
+                getLog().info("Using bundle list file from " + artifact.getFile().getAbsolutePath());
+                bundleList = readBundleList(artifact.getFile());
             }
-        } catch (Exception e) {
-            getLog()
-                    .warn(
-                            String
-                                    .format(
-                                            "Unable to use bundle list from %s. Falling back to bundles artifact.",
-                                            bundleListFile), e);
-        }
 
-        if (!isCurrentArtifact(defaultBundleList)) {
-            try {
-                Artifact artifact = getArtifact(defaultBundleList.getGroupId(),
-                        defaultBundleList.getArtifactId(), defaultBundleList
-                                .getVersion(), defaultBundleList.getType(),
-                        defaultBundleList.getClassifier());
-                getLog().info(
-                        "Using bundle list file from "
-                                + artifact.getFile().getAbsolutePath());
-                BundleList bundles = readBundleList(artifact.getFile());
-                copyBundles(bundles, outputDirectory);
-                return;
-            } catch (Exception e) {
-                getLog()
-                        .warn(
-                                "Unable to load bundle list from artifact. Falling back to bundle jar",
-                                e);
+            if (bundleListFile.exists()) {
+                bundleList.merge(readBundleList(bundleListFile));
             }
         }
-
-        if (!isCurrentArtifact(defaultBundleList)) {
-            Artifact defaultBundlesArtifact = getArtifact(defaultBundles
-                    .getGroupId(), defaultBundles.getArtifactId(),
-                    defaultBundles.getVersion(), defaultBundles.getType(),
-                    defaultBundles.getClassifier());
-            unpack(defaultBundlesArtifact.getFile(), outputDirectory, null,
-                    "META-INF/**");
+        if (additionalBundles != null) {
+            for (ArtifactDefinition def : additionalBundles) {
+                bundleList.add(def.toBundle());
+            }
         }
-    }
-
-    private boolean isCurrentArtifact(ArtifactDefinition def) {
-        return (def.getGroupId().equals(project.getGroupId()) && def
-                .getArtifactId().equals(project.getArtifactId()));
-    }
-
-    private void copyBundles(BundleList bundles, File outputDirectory)
-            throws MojoExecutionException {
-        for (StartLevel startLevel : bundles.getStartLevels()) {
-            for (Bundle bundle : startLevel.getBundles()) {
-                copy(new ArtifactDefinition(bundle, startLevel.getLevel()),
-                        outputDirectory);
+        if (bundleExclusions != null) {
+            for (ArtifactDefinition def : bundleExclusions) {
+                bundleList.remove(def.toBundle(), false);
             }
         }
+        initBundleList(bundleList);
     }
 
-    protected BundleList readBundleList(File file) throws IOException,
-            XmlPullParserException {
+    private BundleList readBundleList(File file) throws IOException, XmlPullParserException {
         BundleListXpp3Reader reader = new BundleListXpp3Reader();
         FileInputStream fis = new FileInputStream(file);
         try {
@@ -329,50 +285,4 @@
         }
     }
 
-    protected boolean shouldCopy(File source, File dest) {
-        if (!dest.exists()) {
-            return true;
-        } else {
-            return source.lastModified() > dest.lastModified();
-        }
-    }
-
-    protected void unpack(File source, File destination, String includes,
-            String excludes) throws MojoExecutionException {
-        getLog().info(
-                "Unpacking " + source.getPath() + " to\n  "
-                        + destination.getPath());
-        try {
-            destination.mkdirs();
-
-            UnArchiver unArchiver = archiverManager.getUnArchiver(source);
-
-            unArchiver.setSourceFile(source);
-            unArchiver.setDestDirectory(destination);
-
-            if (StringUtils.isNotEmpty(excludes)
-                    || StringUtils.isNotEmpty(includes)) {
-                IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
-
-                if (StringUtils.isNotEmpty(excludes)) {
-                    selectors[0].setExcludes(excludes.split(","));
-                }
-
-                if (StringUtils.isNotEmpty(includes)) {
-                    selectors[0].setIncludes(includes.split(","));
-                }
-
-                unArchiver.setFileSelectors(selectors);
-            }
-
-            unArchiver.extract();
-        } catch (NoSuchArchiverException e) {
-            throw new MojoExecutionException("Unable to find archiver for "
-                    + source.getPath(), e);
-        } catch (ArchiverException e) {
-            throw new MojoExecutionException("Unable to unpack "
-                    + source.getPath(), e);
-        }
-    }
-
 }

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java?rev=906180&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java Wed Feb  3 19:08:36 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.IOException;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+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.FileUtils;
+
+/**
+ * This class contains the Launchpad-framework specific utility methods.
+ *
+ */
+public abstract class AbstractLaunchpadFrameworkMojo extends AbstractBundleListMojo {
+
+    /**
+     * The name of the directory within the output directory into which the base
+     * JAR should be installed.
+     *
+     * @parameter default-value="resources"
+     */
+    protected String baseDestination;
+
+    /**
+     * The directory which contains the start-level bundle directories.
+     *
+     * @parameter default-value="bundles"
+     */
+    protected String bundlesDirectory;
+
+    protected void copyBundles(BundleList bundles, File outputDirectory) throws MojoExecutionException {
+        for (StartLevel startLevel : bundles.getStartLevels()) {
+            for (Bundle bundle : startLevel.getBundles()) {
+                copy(new ArtifactDefinition(bundle, startLevel.getLevel()), outputDirectory);
+            }
+        }
+    }
+
+    protected void copy(ArtifactDefinition additionalBundle, File outputDirectory) throws MojoExecutionException {
+        Artifact artifact = getArtifact(additionalBundle);
+        copy(artifact.getFile(), additionalBundle.getStartLevel(), outputDirectory);
+    }
+
+    protected void copy(File file, int startLevel, File outputDirectory) throws MojoExecutionException {
+        File destination = new File(outputDirectory, String.format("%s/%s/%s/%s", baseDestination, bundlesDirectory,
+                startLevel, file.getName()));
+        if (shouldCopy(file, destination)) {
+            getLog().info(String.format("Copying bundle from %s to %s", file.getPath(), destination.getPath()));
+            try {
+                FileUtils.copyFile(file, destination);
+            } catch (IOException e) {
+                throw new MojoExecutionException("Unable to copy bundle from " + file.getPath(), e);
+            }
+        }
+    }
+
+}

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=906180&r1=906179&r2=906180&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 Wed Feb  3 19:08:36 2010
@@ -41,7 +41,7 @@
 
     /** The artifact version */
     private String version;
-    
+
     public ArtifactDefinition() {
     }
 
@@ -113,10 +113,10 @@
      * Initialize this ArtifactDefinition with a set of default values from a
      * comma-delimited string. This string must have 6 items in it:
      * [groupId],[artifactId],[version],[type],[classifier],[startLevel]
-     * 
+     *
      * The only required parameter is the last one, which must be parseable as
      * an integer.
-     * 
+     *
      * @param commaDelimitedList
      *            the comma-delimited list
      */
@@ -137,7 +137,7 @@
      * Initialize this ArtifactDefinition with a set of default values. If the
      * corresponding field in this object is null (or 0 in the case of start
      * level) and the parameter is non-null, the parameter value will be used.
-     * 
+     *
      * @param groupId
      *            the groupId
      * @param artifactId
@@ -173,4 +173,17 @@
         }
     }
 
+    public Bundle toBundle() {
+        Bundle bnd = new Bundle();
+        bnd.setArtifactId(artifactId);
+        bnd.setGroupId(groupId);
+        bnd.setVersion(version);
+        if (type != null) {
+            bnd.setType(type);
+        }
+        bnd.setClassifier(classifier);
+        bnd.setStartLevel(startLevel);
+        return bnd;
+    }
+
 }

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java Wed Feb  3 19:08:36 2010
@@ -16,33 +16,51 @@
  */
 package org.apache.sling.maven.projectsupport;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer;
 
 /**
  * Attaches the bundle list as a project artifact.
- * 
+ *
  * @goal attach-bundle-list
  * @phase package
  * @description attach the bundle list as a project artifact
  */
 public class AttachBundleListMojo extends AbstractBundleListMojo {
-    
+
     private static final String CLASSIFIER = "bundlelist";
-    
+
     private static final String TYPE = "xml";
 
+    /**
+     * @parameter default-value="${project.build.directory}/bundleList.xml"
+     */
+    private File outputFile;
+
+    private BundleListXpp3Writer writer = new BundleListXpp3Writer();
+
     @Override
-    protected void executeWithArtifacts() throws MojoExecutionException,
-            MojoFailureException {
-        if (bundleListFile != null && bundleListFile.exists()) {
-            projectHelper.attachArtifact(project, TYPE, CLASSIFIER,
-                    bundleListFile);
-        } else {
-            throw new MojoExecutionException(
-                    "The bundle list file does not exist.");
+    protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
+        FileWriter fw = null;
+        try {
+            fw = new FileWriter(outputFile);
+            writer.write(fw, getBundleList());
+            projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Unable to output effective bundle list", e);
+        } finally {
+            if (fw != null) {
+                try {
+                    fw.close();
+                } catch (IOException e) {
+                }
+            }
         }
-
     }
 
 }

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CheckBundleListForSnapshotsMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CheckBundleListForSnapshotsMojo.java?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CheckBundleListForSnapshotsMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CheckBundleListForSnapshotsMojo.java Wed Feb  3 19:08:36 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.sling.maven.projectsupport;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,60 +24,45 @@
 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;
 
 /**
  * Validate that the bundle list file (if it exists) does not contain references
  * to SNAPSHOT versions.
- * 
+ *
  * @goal check-bundle-list-for-snapshots
- * 
+ *
  */
 public class CheckBundleListForSnapshotsMojo extends AbstractBundleListMojo {
 
     /**
      * True if the build should be failed if a snapshot is found.
-     * 
+     *
      * @parameter default-value="true"
      */
     private boolean failOnSnapshot;
 
     @Override
-    protected void executeWithArtifacts() throws MojoExecutionException,
-            MojoFailureException {
-        if (bundleListFile.exists()) {
-            try {
-                List<Bundle> snapshots = new ArrayList<Bundle>();
-                BundleList bundleList = readBundleList();
-                for (StartLevel level : bundleList.getStartLevels()) {
-                    for (Bundle bundle : level.getBundles()) {
-                        if (isSnapshot(bundle)) {
-                            snapshots.add(bundle);
-                        }
-                    }
+    protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
+        List<Bundle> snapshots = new ArrayList<Bundle>();
+        BundleList bundleList = getBundleList();
+        for (StartLevel level : bundleList.getStartLevels()) {
+            for (Bundle bundle : level.getBundles()) {
+                if (isSnapshot(bundle)) {
+                    snapshots.add(bundle);
                 }
-                if (!snapshots.isEmpty()) {
-                    getLog()
-                            .error(
-                                    "The following entries in the bundle list file are SNAPSHOTs:");
-                    for (Bundle bundle : snapshots) {
-                        getLog().error(String.format("     %s:%s:%s", bundle.getGroupId(),
-                                bundle.getArtifactId(), bundle.getVersion()));
-                    }
-                    if (failOnSnapshot) {
-                        throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
-                    }
-                }
-            } catch (IOException e) {
-                throw new MojoExecutionException(
-                        "Unable to load bundle list file", e);
-            } catch (XmlPullParserException e) {
-                throw new MojoExecutionException(
-                        "Unable to load bundle list file", e);
             }
-
-        } else {
-            getLog().debug("Bundle list file does not exist. Skipping.");
+        }
+        if (!snapshots.isEmpty()) {
+            getLog().error("The following entries in the bundle list file are SNAPSHOTs:");
+            for (Bundle bundle : snapshots) {
+                getLog().error(
+                        String
+                                .format("     %s:%s:%s", bundle.getGroupId(), bundle.getArtifactId(), bundle
+                                        .getVersion()));
+            }
+            if (failOnSnapshot) {
+                throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
+            }
         }
     }
 

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=906180&r1=906179&r2=906180&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 Wed Feb  3 19:08:36 2010
@@ -29,7 +29,6 @@
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * Create and attach a JAR file containing the resolved artifacts from the
@@ -40,7 +39,7 @@
  * @phase package
  *
  */
-public class CreateBundleJarMojo extends AbstractBundleListMojo {
+public class CreateBundleJarMojo extends AbstractLaunchpadFrameworkMojo {
 
 	/**
 	 * The list of resources we want to add to the bundle JAR file.
@@ -76,16 +75,7 @@
 	public static final String[] DEFAULT_INCLUDES = { "**/**" };
 
 	private void addBundles() throws MojoExecutionException {
-		BundleList bundles = null;
-		try {
-			bundles = readBundleList(bundleListFile);
-		} catch (IOException e) {
-			throw new MojoExecutionException("Unable to read bundle list file",
-					e);
-		} catch (XmlPullParserException e) {
-			throw new MojoExecutionException("Unable to read bundle list file",
-					e);
-		}
+		BundleList bundles = getBundleList();
 
 		for (StartLevel level : bundles.getStartLevels()) {
 			for (Bundle bundle : level.getBundles()) {

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateKarafFeatureDescriptorMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateKarafFeatureDescriptorMojo.java?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateKarafFeatureDescriptorMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/CreateKarafFeatureDescriptorMojo.java Wed Feb  3 19:08:36 2010
@@ -19,16 +19,12 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 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 org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.output.Format;
@@ -36,129 +32,77 @@
 
 /**
  * Create and attach a karaf feature descriptor XML file.
- * 
+ *
  * @goal create-karaf-descriptor
  * @phase package
  * @description create a karaf feature descriptor
  */
 public class CreateKarafFeatureDescriptorMojo extends AbstractBundleListMojo {
 
-	private static final String CLASSIFIER = "features";
+    private static final String CLASSIFIER = "features";
 
-	private static final String TYPE = "xml";
+    private static final String TYPE = "xml";
 
-	/**
-	 * @parameter
-	 */
-	private String[] additionalBundles;
-
-	private Set<String> excludedArtifacts;
-	
-	/**
-	 * @parameter
-	 */
-	private String[] exclusions;
-	
-	/**
-	 * @parameter default-value="sling"
-	 */
-	private String featureName;
-	
-	/**
-	 * @parameter default-value="sling-2.0"
-	 */
-	private String featuresName;
-
-	/**
-	 * @parameter default-value="${project.version}"
-	 */
-	private String featureVersion;
-
-	/**
-	 * The output directory.
-	 * 
-	 * @parameter default-value="${project.build.directory}"
-	 */
-	private File outputDirectory;
-
-	@Override
-	protected void executeWithArtifacts() throws MojoExecutionException,
-			MojoFailureException {
-		Document doc = new Document();
-
-		Element features = new Element("features");
-		doc.setRootElement(features);
-		features.setAttribute("name", featuresName);
-
-		Element feature = new Element("feature");
-		features.addContent(feature);
-		feature.setAttribute("name", featureName);
-		feature.setAttribute("version", featureVersion);
-		
-		excludedArtifacts = new HashSet<String>();
-		if (exclusions != null) {
-			excludedArtifacts.addAll(Arrays.asList(exclusions));
-		}
-
-		try {
-			BundleList bundleList = readBundleList();
-			for (StartLevel level : bundleList.getStartLevels()) {
-				for (Bundle bundle : level.getBundles()) {
-					if (include(bundle)) {
-						String bundleRef = String.format("mvn:%s/%s/%s", bundle
-								.getGroupId(), bundle.getArtifactId(), bundle
-								.getVersion());
-						feature.addContent(new Element("bundle")
-								.setText(bundleRef));
-					}
-				}
-			}
-		} catch (IOException e) {
-			throw new MojoExecutionException("Unable to read bundle list file",
-					e);
-		} catch (XmlPullParserException e) {
-			throw new MojoExecutionException("Unable to read bundle list file",
-					e);
-		}
-
-		if (additionalBundles != null) {
-			for (String bundleRef : additionalBundles) {
-				Element bundle = new Element("bundle");
-				bundle.setText(bundleRef);
-				feature.addContent(bundle);
-			}
-		}
-
-		File outputFile = new File(outputDirectory, "features.xml");
-
-		FileOutputStream out = null;
-		try {
-			out = new FileOutputStream(outputFile);
-			new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"))
-					.output(doc, out);
-		} catch (IOException e) {
-			throw new MojoExecutionException("Unable to write features.xml", e);
-		} finally {
-			if (out != null) {
-				try {
-					out.close();
-				} catch (IOException e) {
-				}
-			}
-		}
-		projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
-
-	}
-
-	/**
-	 * Decide if the bundle should be included in the bundle list.
-	 * 
-	 * @param bundle the bundle
-	 * @return true if it should be included
-	 */
-	private boolean include(Bundle bundle) {
-		String ref = bundle.getGroupId() + ":" + bundle.getArtifactId();
-		return !excludedArtifacts.contains(ref);
-	}
+    /**
+     * @parameter default-value="sling"
+     */
+    private String featureName;
+
+    /**
+     * @parameter default-value="sling-2.0"
+     */
+    private String featuresName;
+
+    /**
+     * @parameter default-value="${project.version}"
+     */
+    private String featureVersion;
+
+    /**
+     * The output directory.
+     *
+     * @parameter default-value="${project.build.directory}/features.xml"
+     */
+    private File outputFile;
+
+    @Override
+    protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
+        Document doc = new Document();
+
+        Element features = new Element("features");
+        doc.setRootElement(features);
+        features.setAttribute("name", featuresName);
+
+        Element feature = new Element("feature");
+        features.addContent(feature);
+        feature.setAttribute("name", featureName);
+        feature.setAttribute("version", featureVersion);
+
+        BundleList bundleList = getBundleList();
+        for (StartLevel level : bundleList.getStartLevels()) {
+            for (Bundle bundle : level.getBundles()) {
+                String bundleRef = String.format("mvn:%s/%s/%s", bundle.getGroupId(), bundle.getArtifactId(), bundle
+                        .getVersion());
+                feature.addContent(new Element("bundle").setText(bundleRef));
+            }
+        }
+
+        FileOutputStream out = null;
+        try {
+            out = new FileOutputStream(outputFile);
+            new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8")).output(doc, out);
+            projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Unable to write features.xml", e);
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+
+    }
 
 }

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java Wed Feb  3 19:08:36 2010
@@ -23,8 +23,14 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.DirectoryScanner;
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Initialize a Sling application project by extracting bundles into the correct
@@ -35,28 +41,7 @@
  * @phase process-sources
  * @description initialize a Sling application project
  */
-public class PreparePackageMojo extends AbstractBundleListMojo {
-
-	/**
-	 * Any additional bundles to include in the project's bundles directory.
-	 *
-	 * @parameter
-	 */
-	private ArtifactDefinition[] additionalBundles;
-
-	/**
-	 * Bundles which should be removed from the project's bundles directory.
-	 *
-	 * @parameter
-	 */
-	private ArtifactDefinition[] bundlesToRemove;
-
-	/**
-	 * If true, install the default bundles.
-	 *
-	 * @parameter default-value="true"
-	 */
-	private boolean installDefaultBundles;
+public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo {
 
 	/**
 	 * The output directory for the default bundles in a WAR-packaged project,
@@ -97,45 +82,43 @@
 	 */
 	private File buildOutputDirectory;
 
+    /**
+     * To look up Archiver/UnArchiver implementations
+     *
+     * @component
+     */
+    private ArchiverManager archiverManager;
+
 	public void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
 		copyBaseArtifact();
-		if (installDefaultBundles) {
-			unpackDefaultBundles();
-		}
-		copyAdditionalBundles();
-		copyWebSupportBundle();
-		removeBundles();
+		copyBundles(getBundleList(), getOutputDirectory());
 		if (JAR.equals(packaging)) {
 			unpackBaseArtifact();
 		}
 	}
 
-	private void removeBundles() throws MojoExecutionException {
-	    if (bundlesToRemove != null) {
-	        File bundleBaseDir = new File(getOutputDirectory(), String.format(
-	                "%s/%s", baseDestination, bundlesDirectory));
-
-	        for (ArtifactDefinition def : bundlesToRemove) {
-	            DirectoryScanner scanner = new DirectoryScanner();
-	            scanner.setBasedir(bundleBaseDir);
-	            scanner.setIncludes(new String[] { "**/" + def.getArtifactId() + "-*.*"});
-	            scanner.scan();
-	            for (String toRemove : scanner.getIncludedFiles()) {
-	                getLog().info("Deleting " + toRemove);
-	                new File(toRemove).delete();
-	            }
-	        }
-	    }
-	}
-
-	private void copyAdditionalBundles() throws MojoExecutionException {
-		if (additionalBundles != null) {
-			for (int i = 0; i < additionalBundles.length; i++) {
-				copy(additionalBundles[i], getOutputDirectory());
-			}
+	protected void initArtifactDefinitions(Properties dependencies) {
+		if (base == null) {
+			base = new ArtifactDefinition();
+		}
+		base.initDefaults(dependencies.getProperty("base"));
+
+		if (jarWebSupport == null) {
+			jarWebSupport = new ArtifactDefinition();
 		}
+		jarWebSupport.initDefaults(dependencies.getProperty("jarWebSupport"));
 	}
 
+	/**
+     * Add the JAR Web Support bundle to the bundle list.
+     */
+    @Override
+    protected void initBundleList(BundleList bundleList) {
+        if (packaging.equals(JAR)) {
+            bundleList.add(jarWebSupport.toBundle());
+        }
+    }
+
 	private void copyBaseArtifact() throws MojoExecutionException {
 		Artifact artifact = getBaseArtifact();
 		if (artifact == null) {
@@ -166,13 +149,6 @@
 		}
 	}
 
-	private void copyWebSupportBundle() throws MojoExecutionException {
-		if (JAR.equals(packaging)) {
-			copy(jarWebSupport, getOutputDirectory());
-		}
-
-	}
-
 	private Artifact getBaseArtifact() throws MojoExecutionException {
 		Artifact baseDependency = getBaseDependency();
 		if (baseDependency == null) {
@@ -198,20 +174,6 @@
 		}
 	}
 
-
-
-	protected void initArtifactDefinitions(Properties dependencies) {
-		if (base == null) {
-			base = new ArtifactDefinition();
-		}
-		base.initDefaults(dependencies.getProperty("base"));
-
-		if (jarWebSupport == null) {
-			jarWebSupport = new ArtifactDefinition();
-		}
-		jarWebSupport.initDefaults(dependencies.getProperty("jarWebSupport"));
-	}
-
 	private void unpackBaseArtifact() throws MojoExecutionException {
 		Artifact artifact = getBaseDependency();
 		if (artifact == null) {
@@ -224,8 +186,36 @@
 		unpack(artifact.getFile(), buildOutputDirectory, null, null);
 	}
 
-	private void unpackDefaultBundles() throws MojoExecutionException {
-		outputBundleList(getOutputDirectory());
-
-	}
+    private void unpack(File source, File destination, String includes, String excludes)
+            throws MojoExecutionException {
+        getLog().info("Unpacking " + source.getPath() + " to\n  " + destination.getPath());
+        try {
+            destination.mkdirs();
+
+            UnArchiver unArchiver = archiverManager.getUnArchiver(source);
+
+            unArchiver.setSourceFile(source);
+            unArchiver.setDestDirectory(destination);
+
+            if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
+                IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
+
+                if (StringUtils.isNotEmpty(excludes)) {
+                    selectors[0].setExcludes(excludes.split(","));
+                }
+
+                if (StringUtils.isNotEmpty(includes)) {
+                    selectors[0].setIncludes(includes.split(","));
+                }
+
+                unArchiver.setFileSelectors(selectors);
+            }
+
+            unArchiver.extract();
+        } catch (NoSuchArchiverException e) {
+            throw new MojoExecutionException("Unable to find archiver for " + source.getPath(), e);
+        } catch (ArchiverException e) {
+            throw new MojoExecutionException("Unable to unpack " + source.getPath(), e);
+        }
+    }
 }

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundle.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundle.java?rev=906180&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundle.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundle.java Wed Feb  3 19:08:36 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.bundlelist;
+
+public abstract class BaseBundle {
+
+    public abstract String getArtifactId();
+
+    public abstract String getClassifier();
+
+    public abstract String getGroupId();
+
+    public abstract int getStartLevel();
+
+    public abstract String getType();
+
+    public abstract String getVersion();
+
+}

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java?rev=906180&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java Wed Feb  3 19:08:36 2010
@@ -0,0 +1,92 @@
+/*
+ * 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.bundlelist;
+
+import java.util.List;
+
+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;
+
+public abstract class BaseBundleList {
+
+    public abstract List<StartLevel> getStartLevels();
+
+    public Bundle get(Bundle bundle, boolean compareVersions) {
+        for (StartLevel sl : getStartLevels()) {
+            Bundle foundBundle = sl.getBundle(bundle, compareVersions);
+            if (foundBundle != null) {
+                return foundBundle;
+            }
+        }
+        return null;
+    }
+
+    public boolean remove(Bundle bundle, boolean compareVersions) {
+        for (StartLevel sl : getStartLevels()) {
+            if (sl.removeBundle(bundle, compareVersions)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * Merge the current bundle list with an additional list.
+     * @see add(Bundle)
+     *
+     * @param bundleList the new bundle list
+     */
+    public void merge(BundleList bundleList) {
+        for (StartLevel sl : bundleList.getStartLevels()) {
+            for (Bundle bnd : sl.getBundles()) {
+                add(bnd);
+            }
+        }
+    }
+
+    /**
+     * Add an artifact definition. If it already exists, update the version, but
+     * do not change the start level.
+     *
+     * @param newBnd the bundle to add
+     */
+    public void add(Bundle newBnd) {
+        Bundle current = get(newBnd, false);
+        if (current != null) {
+
+        } else {
+            StartLevel startLevel = getOrCreateStartLevel(newBnd.getStartLevel());
+            startLevel.getBundles().add(newBnd);
+        }
+
+    }
+
+    private StartLevel getOrCreateStartLevel(int startLevel) {
+        for (StartLevel sl : getStartLevels()) {
+            if (sl.getLevel() == startLevel) {
+                return sl;
+            }
+        }
+
+        StartLevel sl = new StartLevel();
+        sl.setLevel(startLevel);
+        return sl;
+    }
+
+}

Added: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseStartLevel.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseStartLevel.java?rev=906180&view=auto
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseStartLevel.java (added)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseStartLevel.java Wed Feb  3 19:08:36 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.bundlelist;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
+
+public abstract class BaseStartLevel {
+
+    public abstract List<Bundle> getBundles();
+
+    public boolean removeBundle(Bundle bundle, boolean compareVersions) {
+        for (ListIterator<Bundle> it = getBundles().listIterator(); it.hasNext();) {
+            if (isSameArtifact(bundle, it.next(), compareVersions)) {
+                it.remove();
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean containsBundle(Bundle bundle, boolean compareVersions) {
+        for (Bundle compare : getBundles()) {
+            return isSameArtifact(bundle, compare, compareVersions);
+        }
+        return false;
+    }
+
+    public Bundle getBundle(Bundle bundle, boolean compareVersions) {
+        for (Bundle compare : getBundles()) {
+            if (isSameArtifact(bundle, compare, compareVersions)) {
+                return compare;
+            }
+        }
+        return null;
+    }
+
+    private boolean isSameArtifact(Bundle bundle1, Bundle bundle2, boolean compareVersions) {
+        boolean result = compareVersions ? bundle1.getVersion().equals(bundle2) : true;
+        return result && bundle1.getArtifactId().equals(bundle2.getArtifactId())
+                && bundle1.getGroupId().equals(bundle2.getGroupId()) && bundle1.getType().equals(bundle2.getType());
+    }
+
+}

Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/mdo/bundle-list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/mdo/bundle-list.xml?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/mdo/bundle-list.xml (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/mdo/bundle-list.xml Wed Feb  3 19:08:36 2010
@@ -35,6 +35,7 @@
             <name>BundleList</name>
             <description>List of bundles.</description>
             <version>1.0.0</version>
+            <superClass>org.apache.sling.maven.projectsupport.bundlelist.BaseBundleList</superClass>
             <fields>
                 <field>
                     <name>startLevels</name>
@@ -49,6 +50,7 @@
         <class xml.tagName="startLevel">
         	<name>StartLevel</name>
             <version>1.0.0</version>
+            <superClass>org.apache.sling.maven.projectsupport.bundlelist.BaseStartLevel</superClass>
             <fields>
             	<field xml.attribute="true">
             		<name>level</name>
@@ -68,6 +70,7 @@
         <class xml.tagName="bundle">
             <name>Bundle</name>
             <description>A bundle.</description>
+            <superClass>org.apache.sling.maven.projectsupport.bundlelist.BaseBundle</superClass>
             <fields>
                 <field>
                     <name>groupId</name>

Modified: sling/trunk/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/PreparePackageMojoTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/PreparePackageMojoTest.java?rev=906180&r1=906179&r2=906180&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/PreparePackageMojoTest.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/PreparePackageMojoTest.java Wed Feb  3 19:08:36 2010
@@ -35,8 +35,8 @@
 		makeArtifactAssertions(mojo, "base", "org.apache.sling",
 				"org.apache.sling.launchpad.base", null, "jar", null, 0);
 
-		makeArtifactAssertions(mojo, "defaultBundles", "org.apache.sling",
-				"org.apache.sling.launchpad", "RELEASE", "jar", "bundles", 0);
+		//makeArtifactAssertions(mojo, "defaultBundles", "org.apache.sling",
+		//		"org.apache.sling.launchpad", "RELEASE", "jar", "bundles", 0);
 
         makeArtifactAssertions(mojo, "defaultBundleList", "org.apache.sling",
                 "org.apache.sling.launchpad", "RELEASE", "xml", "bundlelist", 0);



Mime
View raw message