You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:17:46 UTC

[sling-maven-launchpad-plugin] 21/45: SLING-3401 Support multiple bundles for the jarWebSupport

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

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

commit 066b97b1ed8f453283e3693daa38b71b29dc03cb
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Thu Feb 20 11:47:18 2014 +0000

    SLING-3401 Support multiple bundles for the jarWebSupport
    
    The solution is to extend the ArtifactDefinition to internally support
    a collection of ArtifactDefinitions named "bundles".
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/maven-launchpad-plugin@1570154 13f79535-47bb-0310-9956-ffa450edef68
---
 .../AbstractLaunchpadStartingMojo.java             |   2 +-
 .../AbstractUsingBundleListMojo.java               |   4 +-
 .../maven/projectsupport/ArtifactDefinition.java   | 113 +++++++++++++--------
 .../LaunchpadPluginLifecycleParticipant.java       |  28 ++---
 .../maven/projectsupport/PreparePackageMojo.java   |   2 +-
 .../projectsupport/bundlelist/BaseBundleList.java  |  21 ++--
 6 files changed, 103 insertions(+), 67 deletions(-)

diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
index 3c5e22b..636a470 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
@@ -234,6 +234,6 @@ public abstract class AbstractLaunchpadStartingMojo extends AbstractUsingBundleL
      */
     @Override
     protected void initBundleList(BundleList bundleList) {
-        bundleList.add(jarWebSupport.toBundle());
+        bundleList.add(jarWebSupport.toBundleList());
     }
 }
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
index 146a134..ac6a0ba 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
@@ -255,7 +255,7 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
         // add additional bundles
         if (additionalBundles != null) {
             for (ArtifactDefinition def : additionalBundles) {
-                initializedBundleList.add(def.toBundle());
+                initializedBundleList.add(def.toBundleList());
             }
         }
 
@@ -273,7 +273,7 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
         // handle exclusions
         if (bundleExclusions != null) {
             for (ArtifactDefinition def : bundleExclusions) {
-                initializedBundleList.remove(def.toBundle(), false);
+                initializedBundleList.remove(def.toBundleList(), false);
             }
         }
 
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
index 2183c2e..10285dc 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
@@ -18,6 +18,9 @@ package org.apache.sling.maven.projectsupport;
 
 import static org.apache.sling.maven.projectsupport.BundleListUtils.nodeValue;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.maven.model.Dependency;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
 import org.codehaus.plexus.util.StringUtils;
@@ -49,6 +52,8 @@ public class ArtifactDefinition {
     /** The artifact run modes */
     private String runModes;
 
+    private ArtifactDefinition[] bundles;
+
     public ArtifactDefinition() {
     }
 
@@ -176,54 +181,80 @@ public class ArtifactDefinition {
      */
     public void initDefaults(String groupId, String artifactId, String version,
             String type, String classifier, int startLevel) {
-        if (this.groupId == null && StringUtils.isNotEmpty(groupId)) {
-            this.groupId = groupId;
-        }
-        if (this.artifactId == null && StringUtils.isNotEmpty(artifactId)) {
-            this.artifactId = artifactId;
-        }
-        if (this.version == null && StringUtils.isNotEmpty(version)) {
-            this.version = version;
-        }
-        if (this.type == null && StringUtils.isNotEmpty(groupId)) {
-            this.type = type;
-        }
-        if (this.classifier == null && StringUtils.isNotEmpty(classifier)) {
-            this.classifier = classifier;
-        }
-        if (this.startLevel == 0) {
-            this.startLevel = startLevel;
+        if (this.bundles == null) {
+            if (this.groupId == null && StringUtils.isNotEmpty(groupId)) {
+                this.groupId = groupId;
+            }
+            if (this.artifactId == null && StringUtils.isNotEmpty(artifactId)) {
+                this.artifactId = artifactId;
+            }
+            if (this.version == null && StringUtils.isNotEmpty(version)) {
+                this.version = version;
+            }
+            if (this.type == null && StringUtils.isNotEmpty(groupId)) {
+                this.type = type;
+            }
+            if (this.classifier == null && StringUtils.isNotEmpty(classifier)) {
+                this.classifier = classifier;
+            }
+            if (this.startLevel == 0) {
+                this.startLevel = startLevel;
+            }
+        } else {
+            for (ArtifactDefinition bundle : this.bundles) {
+                bundle.initDefaults(groupId, artifactId, version, type, classifier, startLevel);
+            }
         }
     }
 
-    public Bundle toBundle() {
-        Bundle bnd = new Bundle();
-        bnd.setArtifactId(artifactId);
-        bnd.setGroupId(groupId);
-        bnd.setVersion(version);
-        if (type != null) {
-            bnd.setType(type);
+    public List<Bundle> toBundleList() {
+        ArrayList<Bundle> bundleList = new ArrayList<Bundle>();
+
+        if (bundles == null) {
+            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);
+            bundleList.add(bnd);
+        } else {
+            for (ArtifactDefinition bundle : bundles) {
+                bundleList.addAll(bundle.toBundleList());
+            }
         }
-        bnd.setClassifier(classifier);
-        bnd.setStartLevel(startLevel);
-        return bnd;
-    }
-
-    public Dependency toDependency(String scope) {
-        Dependency dep = new Dependency();
-        dep.setArtifactId(artifactId);
-        dep.setGroupId(groupId);
-        dep.setVersion(version);
-        if (type != null) {
-            dep.setType(type);
+
+        return bundleList;
+    }
+
+    public List<Dependency> toDependencyList(String scope) {
+        ArrayList<Dependency> depList = new ArrayList<Dependency>();
+
+        if (bundles == null) {
+            Dependency dep = new Dependency();
+            dep.setArtifactId(artifactId);
+            dep.setGroupId(groupId);
+            dep.setVersion(version);
+            if (type != null) {
+                dep.setType(type);
+            }
+            dep.setClassifier(classifier);
+            dep.setScope(scope);
+            depList.add(dep);
+        } else {
+            for (ArtifactDefinition bundle : bundles) {
+                depList.addAll(bundle.toDependencyList(scope));
+            }
         }
-        dep.setClassifier(classifier);
-        dep.setScope(scope);
-        return dep;
+
+        return depList;
     }
 
-    public static Dependency toDependency(Bundle bundle, String scope) {
-        return new ArtifactDefinition(bundle, 0).toDependency(scope);
+    public static List<Dependency> toDependencyList(Bundle bundle, String scope) {
+        return new ArtifactDefinition(bundle, 0).toDependencyList(scope);
     }
 
 }
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java b/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
index 57dd147..b7dc8d1 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/LaunchpadPluginLifecycleParticipant.java
@@ -5,9 +5,9 @@
  * licenses this file to You under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -50,7 +50,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 public class LaunchpadPluginLifecycleParticipant extends AbstractMavenLifecycleParticipant {
 
     private static final String PLUGIN_ID = "maven-launchpad-plugin";
-    
+
     private static final String PROVIDED = "provided";
 
     @Requirement
@@ -100,43 +100,43 @@ public class LaunchpadPluginLifecycleParticipant extends AbstractMavenLifecycleP
 
         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(PROVIDED));
+                    project.getDependencies().addAll(defaultBundleList.toDependencyList(PROVIDED));
                 }
 
                 if (hasJarPackagingExecution()) {
                     log.debug(String.format("adding jar web support (%s) to dependencies of project %s", jarWebSupport, project));
-                    project.getDependencies().add(jarWebSupport.toDependency(PROVIDED));
+                    project.getDependencies().addAll(jarWebSupport.toDependencyList(PROVIDED));
                 }
             }
         }
 
         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());
+                    bundleList.add(def.toBundleList());
                 }
             }
-            
+
             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, PROVIDED));
+                    project.getDependencies().addAll(ArtifactDefinition.toDependencyList(bundle, PROVIDED));
                 }
             }
         }
@@ -161,10 +161,10 @@ public class LaunchpadPluginLifecycleParticipant extends AbstractMavenLifecycleP
                 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) {
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
index 521472d..e5c3612 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
@@ -136,7 +136,7 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo {
     @Override
     protected void initBundleList(BundleList bundleList) {
         if (packaging.equals(JAR)) {
-            bundleList.add(jarWebSupport.toBundle());
+            bundleList.add(jarWebSupport.toBundleList());
         }
     }
 
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java b/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java
index 1c7bc56..230aa49 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/bundlelist/BaseBundleList.java
@@ -39,16 +39,19 @@ public abstract class BaseBundleList {
         return null;
     }
 
-    public boolean remove(Bundle bundle, boolean compareVersions) {
-        for (StartLevel sl : getStartLevels()) {
-            if (sl.removeBundle(bundle, compareVersions)) {
-                return true;
+    public boolean remove(List<Bundle> bundles, boolean compareVersions) {
+        boolean result = false;
+        for (Bundle bundle : bundles) {
+            for (StartLevel sl : getStartLevels()) {
+                if (sl.removeBundle(bundle, compareVersions)) {
+                    result = true;
+                    break;
+                }
             }
         }
-        return false;
+        return result;
     }
 
-
     /**
      * Merge the current bundle list with an additional list.
      * @see #add(Bundle)
@@ -69,8 +72,10 @@ public abstract class BaseBundleList {
      *
      * @param newBnd the bundle to add
      */
-    public void add(Bundle newBnd) {
-       add(null, newBnd);
+    public void add(List<Bundle> newBnd) {
+        for (Bundle bundle : newBnd) {
+            add(null, bundle);
+        }
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.