Fix compiler warnings.
[hs-java.git] / Java / JAR / Archive.hs
index a4dd02669e9a09693223f3b169312c20eccca7c3..cce3d2aa4b3419430b72aa7ca8c17f02b61d95d7 100644 (file)
@@ -5,6 +5,7 @@ import qualified Codec.Archive.LibZip as Zip
 import Data.Binary
 import Data.List
 import qualified Data.ByteString.Lazy as B
+import System.FilePath
 
 import Java.ClassPath.Types
 import Java.ClassPath.Common
@@ -31,3 +32,23 @@ readFromJAR jarfile path = do
   let bstr = B.pack content
   return $ classFile2Direct (decode bstr)
 
+checkClassTree :: [Tree CPEntry] -> IO [Tree (FilePath, Class Direct)]
+checkClassTree forest = mapFMF check forest
+  where
+    check _ (NotLoaded path) = do
+       cls <- parseClassFile path
+       return (path, cls)
+    check a (Loaded path cls) = return (a </> path, cls)
+    check a (NotLoadedJAR jar path) = do
+       cls <- readFromJAR jar (a </> path)
+       return (a </> path, cls)
+    check a (LoadedJAR _ cls) =
+       return (a </> show (thisClass cls), cls)
+
+zipJAR :: [Tree (FilePath, Class Direct)] -> Zip.Archive ()
+zipJAR forest = do
+    mapFM go forest
+    return ()
+  where
+    go (path, cls) = Zip.addFile path =<< Zip.sourceBuffer (B.unpack $ encodeClass cls)
+