karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf] branch karaf-4.2.x updated: [KARAF-6229] Fix dual install/deploy of zip archive by the karaf-maven-plugin
Date Sun, 14 Apr 2019 05:06:18 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 328754b  [KARAF-6229] Fix dual install/deploy of zip archive by the karaf-maven-plugin
328754b is described below

commit 328754be2f5a650cd1eaa59cdcbc3f9f658577f3
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 5dacf70..9fde63e 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);
         }
     }
 


Mime
View raw message