jar: enable getter for mainclass property
authorBernhard Urban <lewurm@gmail.com>
Sat, 19 May 2012 19:20:53 +0000 (21:20 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sat, 19 May 2012 19:20:53 +0000 (21:20 +0200)
Java/JAR.hs

index 6188dd79610c7863506f50111ac49e550186c2de..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