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/01/21 14:40:44 UTC

[karaf] branch master updated: KARAF-6103 - When doing a "mvn compile" the karaf-maven-plugin causes a IOException - Added a check to detect if the "file" passed in to getMetadata() is a file or a directory. - Implemented an alternate process for reading MANIFEST.MF files from directories.

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 8e8bd38  KARAF-6103 - When doing a "mvn compile" the karaf-maven-plugin causes a IOException - Added a check to detect if the "file" passed in to getMetadata() is a file or a directory. - Implemented an alternate process for reading MANIFEST.MF files from directories.
     new 15b8e03  Merge pull request #734 from chrisdutz/master
8e8bd38 is described below

commit 8e8bd387678b6d9950b6a25aa196f6ed9322b086
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Jan 21 13:18:45 2019 +0100

    KARAF-6103 - When doing a "mvn compile" the karaf-maven-plugin causes a IOException
    - Added a check to detect if the "file" passed in to getMetadata() is a file or a directory.
    - Implemented an alternate process for reading MANIFEST.MF files from directories.
---
 .../tooling/features/GenerateDescriptorMojo.java   | 60 ++++++++++++----------
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index 57b469f..3adfbe2 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -20,16 +20,7 @@ package org.apache.karaf.tooling.features;
 import static java.lang.String.format;
 import static org.apache.karaf.deployer.kar.KarArtifactInstaller.FEATURE_CLASSIFIER;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
-import java.io.StringWriter;
+import java.io.*;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -668,27 +659,44 @@ public class GenerateDescriptorMojo extends MojoSupport {
      */
 
     private Manifest getManifest(File file) {
-        final InputStream is;
-        try {
-            is = Files.newInputStream(file.toPath());
-        } catch (Exception e) {
-            getLog().warn("Error while opening artifact", e);
+        // In case of a maven build below the 'package' phase, references to the 'target/classes'
+        // directories are passed in instead of jar-file references.
+        if(file.isDirectory()) {
+            File manifestFile = new File(file, "META-INF/MANIFEST.MF");
+            if(manifestFile.exists() && manifestFile.isFile()) {
+                try {
+                    InputStream manifestInputStream = new FileInputStream(manifestFile);
+                    return new Manifest(manifestInputStream);
+                } catch (IOException e) {
+                    getLog().warn("Error while reading artifact from directory", e);
+                    return null;
+                }
+            }
+            getLog().warn("Manifest not present in the module directory " + file.getAbsolutePath());
             return null;
-        }
+        } else {
+            final InputStream is;
+            try {
+                is = Files.newInputStream(file.toPath());
+            } catch (Exception e) {
+                getLog().warn("Error while opening artifact", e);
+                return null;
+            }
 
-        try (BufferedInputStream bis = new BufferedInputStream(is)) {
-            bis.mark(256 * 1024);
+            try (BufferedInputStream bis = new BufferedInputStream(is)) {
+                bis.mark(256 * 1024);
 
-            try (JarInputStream jar = new JarInputStream(bis)) {
-                Manifest m = jar.getManifest();
-                if (m == null) {
-                    getLog().warn("Manifest not present in the first entry of the zip - " + file.getName());
+                try (JarInputStream jar = new JarInputStream(bis)) {
+                    Manifest m = jar.getManifest();
+                    if (m == null) {
+                        getLog().warn("Manifest not present in the first entry of the zip - " + file.getName());
+                    }
+                    return m;
                 }
-                return m;
+            } catch (IOException e) {
+                getLog().warn("Error while reading artifact", e);
+                return null;
             }
-        } catch (IOException e) {
-            getLog().warn("Error while reading artifact", e);
-            return null;
         }
     }