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:27 UTC

[sling-maven-launchpad-plugin] 02/45: SLING.2649 : Add support for run modes

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 54bb0b0f229b4e71de80d273e3c1d30d8a156683
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Nov 13 16:46:14 2012 +0000

    SLING.2649 : Add support for run modes
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1408828 13f79535-47bb-0310-9956-ffa450edef68
---
 .../AbstractLaunchpadFrameworkMojo.java            | 39 +++++++++++++++++-----
 .../maven/projectsupport/ArtifactDefinition.java   | 20 ++++++++---
 .../maven/projectsupport/CreateBundleJarMojo.java  |  6 ++--
 .../projectsupport/PrepareTestWebAppMojo.java      |  3 +-
 src/main/mdo/bundle-list.xml                       |  5 +++
 5 files changed, 56 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java
index 401f69d..23d16d0 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadFrameworkMojo.java
@@ -18,6 +18,8 @@ package org.apache.sling.maven.projectsupport;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -48,20 +50,41 @@ public abstract class AbstractLaunchpadFrameworkMojo extends AbstractUsingBundle
     private String bundlesDirectory;
 
     /**
-     * The directory which contains the bootstraop bundle directories.
+     * The directory which contains the bootstrap bundle directories.
      *
      * @parameter
      */
     private String bootDirectory;
 
-    protected String getPathForArtifact(final int startLevel, final String artifactName) {
+    protected String getPathForArtifact(final int startLevel, final String artifactName, final String runModes) {
+        final Set<String> runModesList = new TreeSet<String>();
+        if (runModes != null ) {
+            for(final String mode : runModes.split(",")) {
+                if ( mode.trim().length() > 0 ) {
+                    runModesList.add(mode);
+                }
+            }
+        }
+        final String runModeExt;
+        if ( runModesList.size() == 0 ) {
+            runModeExt = "";
+        } else {
+            final StringBuilder sb = new StringBuilder();
+            for(final String n : runModesList ) {
+                sb.append('.');
+                sb.append(n);
+            }
+            runModeExt = sb.toString();
+        }
         if ( startLevel == -1 && bootDirectory != null ) {
-            return String.format("%s/%s/1/%s", baseDestination, bootDirectory,
+            return String.format("%s/%s%s/1/%s", baseDestination, bootDirectory,
+                    runModeExt,
                     artifactName);
         }
-        return String.format("%s/%s/%s/%s", baseDestination, bundlesDirectory,
+        return String.format("%s/%s%s/%s/%s", baseDestination, bundlesDirectory,
+                runModeExt,
                 (startLevel == -1 ? 1 : startLevel),
-                artifactName);
+                artifactName, runModeExt);
     }
 
     protected void copyBundles(BundleList bundles, File outputDirectory) throws MojoExecutionException {
@@ -74,11 +97,11 @@ public abstract class AbstractLaunchpadFrameworkMojo extends AbstractUsingBundle
 
     protected void copy(ArtifactDefinition additionalBundle, File outputDirectory) throws MojoExecutionException {
         Artifact artifact = getArtifact(additionalBundle);
-        copy(artifact.getFile(), additionalBundle.getStartLevel(), outputDirectory);
+        copy(artifact.getFile(), additionalBundle.getStartLevel(), additionalBundle.getRunModes(), outputDirectory);
     }
 
-    protected void copy(File file, int startLevel, File outputDirectory) throws MojoExecutionException {
-        File destination = new File(outputDirectory, getPathForArtifact(startLevel, file.getName().replace('/', File.separatorChar)));
+    protected void copy(File file, int startLevel, String runModes, File outputDirectory) throws MojoExecutionException {
+        File destination = new File(outputDirectory, getPathForArtifact(startLevel, file.getName().replace('/', File.separatorChar), runModes));
         if (shouldCopy(file, destination)) {
             getLog().info(String.format("Copying bundle from %s to %s", file.getPath(), destination.getPath()));
             try {
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 edb4271..2183c2e 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/ArtifactDefinition.java
@@ -16,7 +16,7 @@
  */
 package org.apache.sling.maven.projectsupport;
 
-import static org.apache.sling.maven.projectsupport.BundleListUtils.*;
+import static org.apache.sling.maven.projectsupport.BundleListUtils.nodeValue;
 
 import org.apache.maven.model.Dependency;
 import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
@@ -46,9 +46,12 @@ public class ArtifactDefinition {
     /** The artifact version */
     private String version;
 
+    /** The artifact run modes */
+    private String runModes;
+
     public ArtifactDefinition() {
     }
-    
+
     public ArtifactDefinition(Bundle bundle, int startLevel) {
         this.groupId = bundle.getGroupId();
         this.artifactId = bundle.getArtifactId();
@@ -56,6 +59,7 @@ public class ArtifactDefinition {
         this.version = bundle.getVersion();
         this.classifier = bundle.getClassifier();
         this.startLevel = startLevel;
+        this.runModes = bundle.getRunModes();
     }
 
     public ArtifactDefinition(Xpp3Dom config) {
@@ -65,6 +69,7 @@ public class ArtifactDefinition {
         this.version = nodeValue(config, "version", null);
         this.classifier = nodeValue(config, "classifier", null);
         this.startLevel = nodeValue(config, "startLevel", 0);
+        this.runModes = nodeValue(config, "runModes", null);
     }
 
     public String getArtifactId() {
@@ -91,6 +96,10 @@ public class ArtifactDefinition {
         return version;
     }
 
+    public String getRunModes() {
+        return runModes;
+    }
+
     public void setArtifactId(String artifactId) {
         this.artifactId = artifactId;
     }
@@ -119,7 +128,8 @@ public class ArtifactDefinition {
     public String toString() {
         return "ArtifactDefinition [artifactId=" + artifactId + ", classifier="
                 + classifier + ", groupId=" + groupId + ", startLevel="
-                + startLevel + ", type=" + type + ", version=" + version + "]";
+                + startLevel + ", type=" + type + ", version=" + version
+                + ", runModes=" + runModes + "]";
     }
 
     /**
@@ -198,7 +208,7 @@ public class ArtifactDefinition {
         bnd.setStartLevel(startLevel);
         return bnd;
     }
-    
+
     public Dependency toDependency(String scope) {
         Dependency dep = new Dependency();
         dep.setArtifactId(artifactId);
@@ -211,7 +221,7 @@ public class ArtifactDefinition {
         dep.setScope(scope);
         return dep;
     }
-    
+
     public static Dependency toDependency(Bundle bundle, String scope) {
         return new ArtifactDefinition(bundle, 0).toDependency(scope);
     }
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
index dc848e7..c46da9b 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/CreateBundleJarMojo.java
@@ -81,7 +81,7 @@ public class CreateBundleJarMojo extends AbstractLaunchpadFrameworkMojo {
             for (Bundle bundle : level.getBundles()) {
                 Artifact artifact = getArtifact(new ArtifactDefinition(bundle,
                         level.getStartLevel()));
-                final String destFileName = getPathForArtifact(level.getStartLevel(), artifact.getFile().getName());
+                final String destFileName = getPathForArtifact(level.getStartLevel(), bundle.getRunModes(), artifact.getFile().getName());
                 try {
                     jarArchiver.addFile(artifact.getFile(), destFileName);
                 } catch (ArchiverException e) {
@@ -168,13 +168,13 @@ public class CreateBundleJarMojo extends AbstractLaunchpadFrameworkMojo {
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir(resource.getDirectory());
         if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
-            scanner.setIncludes((String[]) resource.getIncludes().toArray(
+            scanner.setIncludes(resource.getIncludes().toArray(
                     new String[resource.getIncludes().size()]));
         } else {
             scanner.setIncludes(DEFAULT_INCLUDES);
         }
         if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
-            scanner.setExcludes((String[]) resource.getExcludes().toArray(
+            scanner.setExcludes(resource.getExcludes().toArray(
                     new String[resource.getExcludes().size()]));
         }
 
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/PrepareTestWebAppMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/PrepareTestWebAppMojo.java
index 229c894..d38d1cf 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/PrepareTestWebAppMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/PrepareTestWebAppMojo.java
@@ -60,9 +60,10 @@ public class PrepareTestWebAppMojo extends PreparePackageMojo {
      */
     private ArtifactHandlerManager artifactHandlerManager;
 
+    @Override
     public void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
         super.executeWithArtifacts();
-        copy(getPrimaryArtifact(), startLevel, getOutputDirectory());
+        copy(getPrimaryArtifact(), startLevel, null, getOutputDirectory());
     }
 
     @Override
diff --git a/src/main/mdo/bundle-list.xml b/src/main/mdo/bundle-list.xml
index dbe123a..0bb9d5c 100644
--- a/src/main/mdo/bundle-list.xml
+++ b/src/main/mdo/bundle-list.xml
@@ -107,6 +107,11 @@
                     <type>int</type>
                     <required>true</required>
                 </field>
+                <field>
+                    <name>runModes</name>
+                    <version>1.0.0</version>
+                    <type>String</type>
+                </field>
             </fields>
         </class>
     </classes>

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