ざる魂

真似ぶ魂、学ぶの本質。知られざる我が魂

Windowsでmisakiのデモが動かない

Clojureで書かれたブログジェネレータの misaki ですが、そのままではWindows上ではサンプルが動作しません。

C:\Users\miki\dev\misaki>lein run samples/blog
 * Compiling all templates
 * Compiling atom.xml.clj

java.io.FileNotFoundException: samples\blog\public\samples\blog\template\ato
m.xml (?w?????p?X?????????????B)
   at misaki.util.file$write_file / invoke (file.clj:
152)
   at misaki.compiler.default.core$compile_STAR_ / invoke (core.cl
j:237)
   at misaki.compiler.default.core$compile_template / invoke (core
.clj:256)
   at misaki.compiler.default.core$_compile$fn__1874 / invoke (cor
e.clj:70)
   at misaki.compiler.default.core$_compile / invoke (core.clj
:58)
   at misaki.core$call_compiler_fn / doInvoke (core.clj:
[1m55)
   at misaki.core$compile_STAR_$fn__1112 / invoke (core.clj:[
31m160)
   at misaki.util.sequence$some_with_default_value / invoke (seque
nce.clj:44)
   at misaki.core$compile_STAR_ / invoke (core.clj:16
7)
   at misaki.core$call_all_compile / invoke (core.clj:[1
m185)
   at misaki.server$do_all_compile / invoke (server.clj:
[1m52)
   at misaki.server$_main / doInvoke (server.clj:91[
22m)
   FAIL in 0.500 sec
 * Finish Compiling
 * starting server:  http://localhost:8080/
2013-05-04 01:01:50.673:INFO:oejs.Server:jetty-7.6.1.v20120215
2013-05-04 01:01:53.766:INFO:oejs.AbstractConnector:Started SelectChannelConnect
or@0.0.0.0:8080

Cygwinで動作させても同様です (ただし、Windows版のOracleJavaなのでOpenJDKをCygwin上で動かせばもしかしたら動くかもです)。

miki@miki-PC ~/dev/misaki
$ lein-cyg run samples/blog
 * Compiling all templates
 * Compiling atom.xml.clj

java.io.FileNotFoundException: samples\blog\public\samples\blog\template\atom.xml (指定されたパスが見つかりません。)
   at misaki.util.file$write_file / invoke (file.clj:152)
   at misaki.compiler.default.core$compile_STAR_ / invoke (core.clj:237)
   at misaki.compiler.default.core$compile_template / invoke (core.clj:256)
   at misaki.compiler.default.core$_compile$fn__1874 / invoke (core.clj:70)
   at misaki.compiler.default.core$_compile / invoke (core.clj:58)
   at misaki.core$call_compiler_fn / doInvoke (core.clj:55)
   at misaki.core$compile_STAR_$fn__1112 / invoke (core.clj:160)
   at misaki.util.sequence$some_with_default_value / invoke (sequence.clj:44)
   at misaki.core$compile_STAR_ / invoke (core.clj:167)
   at misaki.core$call_all_compile / invoke (core.clj:185)
   at misaki.server$do_all_compile / invoke (server.clj:52)
   at misaki.server$_main / doInvoke (server.clj:91)
   FAIL in 0.300 sec
 * Finish Compiling
 * starting server:  http://localhost:8080/
2013-05-04 01:17:16.365:INFO:oejs.Server:jetty-7.6.1.v20120215
2013-05-04 01:17:16.411:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080

付焼き刃な対処ですが、下記の修正でひとまず動作します。

$ git diff
diff --git a/src/misaki/config.clj b/src/misaki/config.clj
index 9d4b69e..7dcd9c7 100644
--- a/src/misaki/config.clj
+++ b/src/misaki/config.clj
@@ -137,7 +137,7 @@
   "Check whether file is post file or not."
   [#^File file]
   {:pre [(file? file)]}
-  (and (:post-dir *config*) (str-contains? (.getAbsolutePath file)
+  (and (:post-dir *config*) (str-contains? (str/replace (.getAbsolutePath file) #"\\" "/")
                                            (:post-dir *config*))))

 ; =index-file?
@@ -209,7 +209,7 @@
 (defn- make-regular-output-filename
   "Make regular output filename from java.io.File."
   [#^File file]
-  (let [path (.getPath file)
+  (let [path (str/replace (.getPath file) #"\\" "/")
         len  (count (:template-dir *config*))]
     (if (.startsWith path (:template-dir *config*))
       (.substring path len)

JavaはWrite Once Run Anywhereを謳ってはいるものの、 このようにパスまわりのトラブルが結構あっていつも悩まさせてくれます。。。 この問題は結構影響範囲が大きそうなので、修正される可能性は低いかもしれません。

本当はこの不具合は結構前に気づいていたのですが、 PullRequestの方法を良く知らないのと、 もうちょっと内容を調査したり整理してからのほうがいいかなと思っていたら Issue に登録されていたのでブログでまとめてみた次第です。

動作環境

OS

Windows 7 Professional 64bit

Java

C:\Users\miki\dev\misaki>java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

leiningen

C:\Users\miki\dev\misaki>lein -v
Leiningen 2.1.3 on Java 1.7.0_09 Java HotSpot(TM) 64-Bit Server VM