X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=Java%2FJAR%2FArchive.hs;h=0963a156eb61250a0cdfdd19c91fb7f45ec7bcc3;hb=359cf0fa124cd3bc0ffedf8ecee77022970ba562;hp=d84be49c35034b2b05d7c19e13bb7b3df8f627c3;hpb=16e599a66ff843547b005beba38923869665efe8;p=hs-java.git diff --git a/Java/JAR/Archive.hs b/Java/JAR/Archive.hs index d84be49..0963a15 100644 --- a/Java/JAR/Archive.hs +++ b/Java/JAR/Archive.hs @@ -1,8 +1,6 @@ -- | This module defines functions to read Java JAR files. module Java.JAR.Archive where -import Control.Monad.Trans -import qualified Control.Monad.State as St import qualified Codec.Archive.LibZip as Zip import Data.Binary import qualified Data.ByteString.Lazy as B @@ -12,9 +10,14 @@ import Java.ClassPath.Common import JVM.ClassFile import JVM.Converter +readJAREntry :: (Enum a) => FilePath -> String -> IO (Maybe [a]) +readJAREntry jarfile path = do + Zip.catchZipError (Just `fmap` (Zip.withArchive [] jarfile $ Zip.fileContents [] path)) + (\_ -> return Nothing) + -- | Read all entires from JAR file -readJAR :: FilePath -> IO [Tree CPEntry] -readJAR jarfile = do +readAllJAR :: FilePath -> IO [Tree CPEntry] +readAllJAR jarfile = do files <- Zip.withArchive [] jarfile $ Zip.fileNames [] return $ mapF (NotLoadedJAR jarfile) (buildTree files) @@ -25,11 +28,3 @@ readFromJAR jarfile path = do let bstr = B.pack content return $ classFile2Direct (decode bstr) --- | Add given JAR file to ClassPath -addJAR :: FilePath -> ClassPath () -addJAR jarfile = do - classes <- liftIO $ readJAR jarfile - cp <- St.get - let cp' = merge $ cp ++ classes - St.put cp' -