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 2015/06/16 19:22:26 UTC

karaf git commit: [KARAF-3669] Include resources in assembly

Repository: karaf
Updated Branches:
  refs/heads/master b8114878e -> 994b25a86


[KARAF-3669] Include resources in assembly


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/994b25a8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/994b25a8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/994b25a8

Branch: refs/heads/master
Commit: 994b25a86d1139920985bce331a043ca70156225
Parents: b811487
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Jun 16 19:21:57 2015 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Jun 16 19:21:57 2015 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/tooling/ArchiveMojo.java   | 10 ++-
 .../org/apache/karaf/tooling/AssemblyMojo.java  | 11 +++
 .../org/apache/karaf/tooling/utils/IoUtils.java | 91 +++++++++++++++++++-
 3 files changed, 104 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/994b25a8/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/ArchiveMojo.java
----------------------------------------------------------------------
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 2c24698..ab1e227 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
@@ -178,9 +178,10 @@ public class ArchiveMojo extends MojoSupport {
             TarArchiveEntry tarEntry = new TarArchiveEntry(entryName);
             tarEntry.setSize(Files.size(f));
             if (entryName.contains("/bin/")) {
-                tarEntry.setMode(0755);
                 if (entryName.endsWith(".bat")) {
-                    return;
+                    tarEntry.setMode(0644);
+                } else {
+                    tarEntry.setMode(0755);
                 }
             }
             tOut.putArchiveEntry(tarEntry);
@@ -213,9 +214,10 @@ public class ArchiveMojo extends MojoSupport {
             zipEntry.setSize(Files.size(f));
             if (entryName.contains("/bin/")) {
                 if (!entryName.endsWith(".bat")) {
-                    return;
+                    zipEntry.setUnixMode(0755);
+                } else {
+                    zipEntry.setUnixMode(0644);
                 }
-                zipEntry.setUnixMode(0755);
             }
             tOut.putArchiveEntry(zipEntry);
             Files.copy(f, tOut);

http://git-wip-us.apache.org/repos/asf/karaf/blob/994b25a8/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
index 121fdf9..9ffc96b 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
@@ -146,6 +146,12 @@ public class AssemblyMojo extends MojoSupport {
     @Parameter(defaultValue = "false")
     protected boolean useReferenceUrls;
 
+    /**
+     * Include project build output directory in the assembly
+     */
+    @Parameter(defaultValue = "true")
+    protected boolean includeBuildOutputDirectory;
+
     @Parameter
     protected boolean installAllFeaturesByDefault = true;
 
@@ -286,7 +292,12 @@ public class AssemblyMojo extends MojoSupport {
                 .bundles(toArray(installedBundles))
                 .profiles(toArray(installedProfiles));
 
+        // Generate the assembly
         builder.generateAssembly();
+
+        // Include project classes content
+        if (includeBuildOutputDirectory)
+            IoUtils.copyDirectory(new File(project.getBuild().getOutputDirectory()), workDirectory);
     }
 
     private String artifactToMvn(Artifact artifact) throws MojoExecutionException {

http://git-wip-us.apache.org/repos/asf/karaf/blob/994b25a8/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/IoUtils.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/IoUtils.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/IoUtils.java
index 3069608..dda50d7 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/IoUtils.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/IoUtils.java
@@ -1,14 +1,13 @@
 /**
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF 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
- *
+ * <p/>
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p/>
  * 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.
@@ -17,10 +16,13 @@
  */
 package org.apache.karaf.tooling.utils;
 
-import java.io.File;
+import java.io.*;
+import java.nio.channels.FileChannel;
 
 public class IoUtils {
 
+    private static final long FILE_COPY_BUFFER_SIZE = 1024 * 30;
+
     public static void deleteRecursive(File file) {
         if (file != null) {
             if (file.isDirectory()) {
@@ -35,4 +37,85 @@ public class IoUtils {
         }
     }
 
+    public static void copyDirectory(final File srcDir, final File destDir) throws IOException {
+        if (srcDir == null || !srcDir.exists())
+            return;
+        if (destDir == null || !destDir.exists())
+            destDir.mkdirs();
+        // recurse
+        final File[] srcFiles = srcDir.listFiles();
+        if (srcFiles == null) {  // null if abstract pathname does not denote a directory, or if an I/O error occurs
+            throw new IOException("Failed to list contents of " + srcDir);
+        }
+        if (destDir.exists()) {
+            if (destDir.isDirectory() == false) {
+                throw new IOException("Destination '" + destDir + "' exists but is not a directory");
+            }
+        } else {
+            if (!destDir.mkdirs() && !destDir.isDirectory()) {
+                throw new IOException("Destination '" + destDir + "' directory cannot be created");
+            }
+        }
+        if (destDir.canWrite() == false) {
+            throw new IOException("Destination '" + destDir + "' cannot be written to");
+        }
+        for (final File srcFile : srcFiles) {
+            final File dstFile = new File(destDir, srcFile.getName());
+            if (srcFile.isDirectory()) {
+                copyDirectory(srcFile, dstFile);
+            } else {
+                copyFile(srcFile, dstFile);
+            }
+        }
+    }
+
+    public static void copyFile(final File srcFile, final File destFile) throws IOException {
+        if (destFile.exists() && destFile.isDirectory()) {
+            throw new IOException("Destination '" + destFile + "' exists but is a directory");
+        }
+
+        FileInputStream fis = null;
+        FileOutputStream fos = null;
+        FileChannel input = null;
+        FileChannel output = null;
+        try {
+            fis = new FileInputStream(srcFile);
+            fos = new FileOutputStream(destFile);
+            input  = fis.getChannel();
+            output = fos.getChannel();
+            final long size = input.size(); // TODO See IO-386
+            long pos = 0;
+            long count = 0;
+            while (pos < size) {
+                final long remain = size - pos;
+                count = remain > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : remain;
+                final long bytesCopied = output.transferFrom(input, pos, count);
+                if (bytesCopied == 0) { // IO-385 - can happen if file is truncated after caching the size
+                    break; // ensure we don't loop forever
+                }
+                pos += bytesCopied;
+            }
+        } finally {
+            if (output != null) {
+                try { output.close(); } catch (Exception e) { }
+            }
+            if (fos != null) {
+                try { fos.close(); } catch (Exception e) { }
+            }
+            if (input != null) {
+                try { input.close(); } catch (Exception e) { }
+            }
+            if (fis != null) {
+                try { fis.close(); } catch (Exception e) { }
+            }
+        }
+
+        final long srcLen = srcFile.length(); // TODO See IO-386
+        final long dstLen = destFile.length(); // TODO See IO-386
+        if (srcLen != dstLen) {
+            throw new IOException("Failed to copy full contents from '" +
+                    srcFile + "' to '" + destFile + "' Expected length: " + srcLen +" Actual: " + dstLen);
+        }
+    }
+
 }