cabal: bump data-default dependency to 0.5.0.
[hs-java.git] / Java / JAR.hs
index 93128b2e138909551412c369992064f300e5eb97..a5614da0e5cfa8c94192a30bf9a8ebd4ce409e4c 100644 (file)
@@ -2,6 +2,7 @@
 module Java.JAR 
   (readManifest,
    readJAR,
+   readMainClass,
    addJAR
   ) where
 
@@ -33,6 +34,15 @@ readOne jarfile str = do
   where
     good name = (str `isPrefixOf` name) && (".class" `isSuffixOf` name)
 
+-- | Read MainClass Entry of a MANIFEST.MF file
+readMainClass :: FilePath -> IO (Maybe String)
+readMainClass jarfile = do
+  Zip.withArchive [] jarfile $ do
+    m <- readManifest
+    case m of
+      Nothing -> return Nothing
+      Just mf -> return $ mainClass mf
+
 -- | Read entries from JAR file, using MANIFEST.MF if it exists.
 readJAR :: FilePath -> IO [Tree CPEntry]
 readJAR jarfile = do
@@ -46,6 +56,7 @@ readJAR jarfile = do
                       return (Just forest)
   case r of
     Nothing -> readAllJAR jarfile
+    Just [] -> readAllJAR jarfile
     Just f  -> return f
 
 -- | Add given JAR file to ClassPath