8 import Control.Monad.Trans (liftIO)
9 import qualified Control.Monad.State as St
11 import qualified Codec.Archive.LibZip as Zip
14 import Java.JAR.Archive
17 readManifest :: Zip.Archive (Maybe Manifest)
19 let manifestPath = "META-INF/MANIFEST.MF"
20 files <- Zip.fileNames []
21 if manifestPath `elem` files
23 content <- Zip.fileContents [] manifestPath
24 case parseMeta content of
25 Left e -> fail $ show e
26 Right meta -> return $ Just (loadSpec meta)
29 readOne :: FilePath -> String -> Zip.Archive [Tree CPEntry]
30 readOne jarfile str = do
31 files <- Zip.fileNames []
32 return $ mapF (NotLoadedJAR jarfile) (buildTree $ filter good files)
34 good name = (str `isPrefixOf` name) && (".class" `isSuffixOf` name)
36 -- | Read entries from JAR file, using MANIFEST.MF if it exists.
37 readJAR :: FilePath -> IO [Tree CPEntry]
39 r <- Zip.withArchive [] jarfile $ do
42 Nothing -> return Nothing
44 trees <- mapM (readOne jarfile) (map meName $ manifestEntries mf)
45 let forest = merge (concat trees)
48 Nothing -> readAllJAR jarfile
49 Just [] -> readAllJAR jarfile
52 -- | Add given JAR file to ClassPath
53 addJAR :: FilePath -> ClassPath ()
55 classes <- liftIO $ readJAR jarfile
57 let cp' = merge $ cp ++ classes