You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/04/14 05:05:40 UTC

[karaf] branch master updated: [KARAF-6229] Fix dual install/deploy of zip archive by the karaf-maven-plugin

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

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 7da5044  [KARAF-6229] Fix dual install/deploy of zip archive by the karaf-maven-plugin
     new c747f8e  Merge pull request #811 from jbonofre/KARAF-6229
7da5044 is described below

commit 7da50449f2eeb2b53caf530cb77a9a8761228440
Author: Jean-Baptiste Onofré <jb...@nanthrax.net>
AuthorDate: Sat Apr 13 08:08:53 2019 +0200

    [KARAF-6229] Fix dual install/deploy of zip archive by the karaf-maven-plugin
---
 .../karaf-profile-example-dynamic/pom.xml          |  1 +
 .../java/org/apache/karaf/tooling/ArchiveMojo.java | 49 ++++++++++++----------
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/examples/karaf-profile-example/karaf-profile-example-dynamic/pom.xml b/examples/karaf-profile-example/karaf-profile-example-dynamic/pom.xml
index 3528c15..7079527 100644
--- a/examples/karaf-profile-example/karaf-profile-example-dynamic/pom.xml
+++ b/examples/karaf-profile-example/karaf-profile-example-dynamic/pom.xml
@@ -30,6 +30,7 @@
 
     <artifactId>karaf-profile-example-dynamic</artifactId>
     <name>Apache Karaf :: Examples :: Profile :: Dynamic Assembly</name>
+    <packaging>pom</packaging>
 
     <dependencies>
         <dependency>
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/ArchiveMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/ArchiveMojo.java
index b3fb350..71627ae 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/ArchiveMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/ArchiveMojo.java
@@ -116,12 +116,26 @@ public class ArchiveMojo extends MojoSupport {
         org.apache.maven.artifact.Artifact artifact = project.getArtifact();
         artifact.setFile(targetFile);
         try {
-            //now pack up the server.
-            if(archiveTarGz){
-                archive("tar.gz");
+            if (project.getPackaging().equals("karaf-assembly") && !archiveTarGz && !archiveZip) {
+                throw new IllegalArgumentException("For karaf-assembly packaging, you have to specify at least one archive type (tar.gz or zip)");
             }
-            if(archiveZip) {
-                archive("zip");
+
+            if (project.getPackaging().equals("karaf-assembly")) {
+                if (archiveZip) {
+                    archive("zip", false, true);
+                    if (archiveTarGz) {
+                        archive("tar.gz", true, false);
+                    }
+                } else {
+                    archive("tar.gz", false, true);
+                }
+            } else {
+                if (archiveTarGz) {
+                    archive("tar.gz", true, false);
+                }
+                if (archiveZip) {
+                    archive("zip", true, false);
+                }
             }
         } catch (Exception e) {
             throw new MojoExecutionException("Could not archive plugin", e);
@@ -129,26 +143,17 @@ public class ArchiveMojo extends MojoSupport {
     }
 
     @SuppressWarnings("deprecation")
-	private void archive(String type) throws IOException {
-        Artifact artifact1 = factory.createArtifactWithClassifier(project.getArtifact().getGroupId(), project.getArtifact().getArtifactId(), project.getArtifact().getVersion(), type, "bin");
-        File target1 = archive(targetServerDirectory, destDir, artifact1);
+	private void archive(String type, boolean attachToProject, boolean setProjectFile) throws IOException {
+        Artifact artifact = factory.createArtifact(project.getArtifact().getGroupId(), project.getArtifact().getArtifactId(), project.getArtifact().getVersion(), project.getArtifact().getScope(), type);
+        File target = archive(targetServerDirectory, destDir, artifact);
 
-        // artifact1 is created with explicit classifier "bin", which is dropped below when attachArtifact is called
-        // which means we can't use artifact1.equals(artifact) directly with artifact1
-        Artifact artifact2 = factory.createArtifact(artifact1.getGroupId(), artifact1.getArtifactId(), artifact1.getVersion(), artifact1.getScope(), artifact1.getType());
-        for (Artifact artifact : project.getAttachedArtifacts()) {
-            if (artifact2.equals(artifact)) {
-                getLog().debug("Artifact " + artifact2 + " already attached");
-                return;
-            }
-        }
-        if (attach) {
-            projectHelper.attachArtifact(project, artifact1.getType(), classifier, target1);
+        if (attachToProject && attach) {
+            projectHelper.attachArtifact(project, artifact.getType(), classifier, target);
         }
 
-        if (!project.getPackaging().equals("pom")) {
-            artifact2.setFile(target1);
-            project.setArtifact(artifact2);
+        if (setProjectFile) {
+            artifact.setFile(target);
+            project.setArtifact(artifact);
         }
     }