cantor (empty) → 0.1
raw patch · 8 files changed
+293/−0 lines, 8 filesdep +Cabaldep +QuickCheckdep +basesetup-changed
Dependencies added: Cabal, QuickCheck, base, directory, filepath, gtk, hspec, hxt, hxt-xpath, parsec
Files
- CHANGES +1/−0
- LICENSE +26/−0
- Setup.hs +2/−0
- cantor.cabal +60/−0
- src/Main.hs +88/−0
- src/Project/Maven.hs +65/−0
- src/Utils/Folder.hs +39/−0
- test-src/Spec.hs +12/−0
+ CHANGES view
@@ -0,0 +1,1 @@+Version 0.1
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) 2014 Krzysztof Langner+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cantor.cabal view
@@ -0,0 +1,60 @@+name: cantor+version: 0.1+cabal-version: >= 1.10+build-type: Simple+author: Krzysztof Langner+maintainer: klangner@gmail.com+synopsis: Analiza Java source code+homepage: https://github.com/klangner/cantor+Bug-reports: https://github.com/klangner/cantor/issues+stability: Unstable interface, incomplete features.+category: Application, source code analysis+License: BSD3+License-file: LICENSE+Extra-Source-Files:+ CHANGES+description: + Application for analyzing Java source code++source-repository head+ type: git+ location: https://github.com/klangner/cantor++executable cantor+ hs-source-dirs: src+ main-is: Main.hs+ default-language: Haskell2010+ build-depends: + base >= 4 && <4.7,+ directory >=1.2.0 && <1.3,+ hxt >= 9.3 && < 9.4,+ hxt-xpath >=9.1.2 && <9.2,+ gtk >=0.12.4 && <0.13,+ filepath >=1.3.0 && <1.4,+ parsec >=3.1.3 && <3.2++ ghc-options: -Wall+ other-modules: + Utils.Folder,+ Project.Maven++test-suite spec+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ default-language: Haskell2010+ build-depends: + base >= 4 && <4.7,+ Cabal >=1.16.0 && <1.17,+ directory >=1.2.0 && <1.3,+ filepath >=1.3.0 && <1.4,+ hspec >=1.7.2 && <1.8,+ QuickCheck >=2.6 && <2.7,+ hxt >= 9.3 && < 9.4,+ hxt-xpath >=9.1.2 && <9.2,+ parsec >=3.1.3 && <3.2++ other-modules: + hs-source-dirs: + src,+ test-src+
+ src/Main.hs view
@@ -0,0 +1,88 @@+{- |+Module : Main+Copyright : Copyright (C) 2014 Krzysztof Langner+License : BSD3++Maintainer : Krzysztof Langner <klangner@gmail.com>+Stability : alpha+Portability : portable++Main GUI application for gathering and presenting information..+-}+module Main where++import System.Environment+import System.Console.GetOpt+import System.Exit+import Project.Maven as Maven+import Project.Model+++data Flag = Version -- -v+ | Help -- --help+ deriving (Eq,Ord,Enum,Show,Bounded)+ + +main::IO ()+main = do+ argv <- getArgs+ case getOpt Permute flags argv of+ ([], cmd:src:_, []) -> commandAction cmd src+ ([], [src], []) -> analyzeAction src+ ([Version], _, []) -> printVersion + ([Help], _, []) -> printUsageInfo+ (_, _, []) -> printUsageInfo+ (_, _, errs) -> errorAction errs+ + ++-- | Command line flags+flags :: [OptDescr Flag]+flags =+ [Option "v" ["version"] (NoArg Version)+ "Print version number."+ ,Option "h" ["help"] (NoArg Help)+ "Print this help message."+ ]+++-- | Print application version number+printVersion :: IO ()+printVersion = + putStrLn "mavex version 0.1"+ + +-- | This action prints errors+errorAction :: [String] -> IO ()+errorAction errs = do + putStrLn (concat errs)+ exitWith (ExitFailure 1)+ + +-- | Print usage info+printUsageInfo :: IO ()+printUsageInfo = do+ putStrLn "Usage: mavex [command] <project_path>"+ putStrLn " commands:"+ putStrLn " create - Create maven POM file."+ putStrLn (usageInfo "" flags)+ ++-- | Print information about project+printProjectInfo :: Project -> IO ()+printProjectInfo prj = putStrLn (getProjectInfo prj) + ++-- | Print information about project+analyzeAction :: FilePath -> IO ()+analyzeAction src = do+ pom <- Maven.loadProject src+ case pom of+ Just prj -> printProjectInfo prj+ Nothing -> putStrLn "Maven POM file not found"+ ++-- | Execute command+commandAction :: String -> FilePath -> IO ()+commandAction _ _ = putStrLn "Commands not implemented yet."+
+ src/Project/Maven.hs view
@@ -0,0 +1,65 @@+{- |+Module : Project.Maven+Copyright : Copyright (C) 2014 Krzysztof Langner+License : BSD3++Maintainer : Krzysztof Langner <klangner@gmail.com>+Stability : alpha+Portability : portable++Get information about project from Maven POM file.+-}+module Project.Maven ( loadProject+ )where++import Text.XML.HXT.Core+import Data.Tree.NTree.TypeDefs+import Text.XML.HXT.XPath.XPathEval+import System.FilePath (normalise)+import System.Directory (doesFileExist)+import Project.Model+++-- | Load project information from POM file.+loadProject :: FilePath -> IO (Maybe Project) +loadProject src = do + let pomPath = normalise (src ++ "/pom.xml")+ fileExists <- doesFileExist pomPath+ xs <- if fileExists then runX (readDocument [] pomPath) else return []+ return $ if not (null xs) then Just (createFromPom src (head xs)) else Nothing+++-- | Create Project data from POM file+createFromPom :: FilePath -> XmlTree -> Project+createFromPom src xt = Project src (metadataFromPom xt)+++-- | Read metadata from pom+metadataFromPom :: XmlTree -> Metadata+metadataFromPom xt = Metadata (projectGroup xt) + (projectArtifact xt) + (projectName xt) + (projectDesc xt)+++-- | Get project group from POM. +projectGroup :: XmlTree -> String+projectGroup = getNodeText "/project/groupId/text()"++-- | Get project artifact from POM. +projectArtifact :: XmlTree -> String+projectArtifact = getNodeText "/project/artifactId/text()"++-- | Get project name from POM. +projectName :: XmlTree -> String+projectName = getNodeText "/project/name/text()"++-- | Get project description from POM. +projectDesc :: XmlTree -> String+projectDesc = getNodeText "/project/description/text()"++-- | Get text from given node +getNodeText :: String -> XmlTree -> String+getNodeText xpath dom = case getXPath xpath dom of+ [NTree (XText a) _] -> a+ _ -> ""
+ src/Utils/Folder.hs view
@@ -0,0 +1,39 @@+{- |+Module : Utils.Folder+Copyright : Copyright (C) 2014 Krzysztof Langner+License : BSD3++Helper module with functions operating on IO+-}+module Utils.Folder+ ( listFiles+ , listDirs+ )where++import System.Directory (canonicalizePath, getDirectoryContents, doesDirectoryExist)+import Data.List+import Control.Monad+++-- | list files+listFiles :: FilePath -> IO [FilePath] +listFiles p = do + contents <- list p+ filterM (fmap not . doesDirectoryExist) contents++ +-- | list subdirectories+listDirs :: FilePath -> IO [FilePath] +listDirs p = do+ contents <- list p+ filterM doesDirectoryExist contents+ +-- | list directory content+list :: FilePath -> IO [FilePath] +list p = do + ds <- getDirectoryContents p+ let filtered = filter f ds+ path <- canonicalizePath p + return $ map ((path++"/")++) filtered+ where f x = (x /= ".") && (x /= "..") && (not . isPrefixOf ".") x+
+ test-src/Spec.hs view
@@ -0,0 +1,12 @@+import Test.Hspec+import Test.QuickCheck+import qualified Utils.FolderSpec+import qualified Project.MavenSpec+import qualified AST.JavaParserSpec+++main :: IO ()+main = hspec $ do+ describe "Folder" Utils.FolderSpec.spec+ describe "Maven" Project.MavenSpec.spec+ describe "JavaParser" AST.JavaParserSpec.spec