storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptgo...@apache.org
Subject [1/2] git commit: use clojure java interop to extract resources rather than external unzip command
Date Fri, 20 Dec 2013 21:47:56 GMT
Updated Branches:
  refs/heads/master 6331d6a93 -> d3414f576


use clojure java interop to extract resources rather than external unzip command


Project: http://git-wip-us.apache.org/repos/asf/incubator-storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-storm/commit/e7545114
Tree: http://git-wip-us.apache.org/repos/asf/incubator-storm/tree/e7545114
Diff: http://git-wip-us.apache.org/repos/asf/incubator-storm/diff/e7545114

Branch: refs/heads/master
Commit: e75451140e534b5489bf7a534d303e2930f7db4a
Parents: 7e40f9f
Author: P. Taylor Goetz <ptgoetz@gmail.com>
Authored: Mon Dec 16 12:42:27 2013 -0500
Committer: P. Taylor Goetz <ptgoetz@gmail.com>
Committed: Mon Dec 16 12:42:27 2013 -0500

----------------------------------------------------------------------
 storm-core/src/clj/backtype/storm/util.clj | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/e7545114/storm-core/src/clj/backtype/storm/util.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/backtype/storm/util.clj b/storm-core/src/clj/backtype/storm/util.clj
index 5e488e0..cb788b5 100644
--- a/storm-core/src/clj/backtype/storm/util.clj
+++ b/storm-core/src/clj/backtype/storm/util.clj
@@ -24,7 +24,7 @@
   (:import [java.util.zip ZipFile])
   (:import [java.util.concurrent.locks ReentrantReadWriteLock])
   (:import [java.util.concurrent Semaphore])
-  (:import [java.io File RandomAccessFile StringWriter PrintWriter])
+  (:import [java.io File FileOutputStream StringWriter PrintWriter IOException])
   (:import [java.lang.management ManagementFactory])
   (:import [org.apache.commons.exec DefaultExecutor CommandLine])
   (:import [org.apache.commons.io FileUtils])
@@ -33,6 +33,7 @@
   (:require [clojure [string :as str]])
   (:import [clojure.lang RT])
   (:require [clojure [set :as set]])
+  (:require [clojure.java.io :as io])
   (:use [clojure walk])
   (:use [backtype.storm log])
   )
@@ -366,8 +367,13 @@
 
 (defn extract-dir-from-jar [jarpath dir destdir]
   (try-cause
-    (exec-command! (str "unzip -qq " jarpath " " dir "/** -d " destdir))
-  (catch ExecuteException e
+    (with-open [jarpath (ZipFile. jarpath)]
+      (let [entries (enumeration-seq (.entries jarpath))]
+        (doseq [file (filter (fn [entry](and (not (.isDirectory entry)) (.startsWith (.getName
entry) dir))) entries)]
+          (.mkdirs (.getParentFile (File. destdir (.getName file))))
+          (with-open [out (FileOutputStream. (File. destdir (.getName file)))]
+            (io/copy (.getInputStream jarpath file) out)))))
+  (catch IOException e
     (log-message "Could not extract " dir " from " jarpath))
   ))
 


Mime
View raw message