packages feed

cantor 0.2 → 0.3

raw patch · 6 files changed

+47/−185 lines, 6 filesdep +splitdep −gtkdep ~Cabaldep ~hspec

Dependencies added: split

Dependencies removed: gtk

Dependency ranges changed: Cabal, hspec

Files

CHANGES view
@@ -1,3 +1,9 @@+Version 03.+-----------++* Produces minimal report as HTML file++ Version 0.2 ----------- 
cantor.cabal view
@@ -1,10 +1,10 @@ name:           cantor-version:        0.2+version:        0.3 cabal-version:  >= 1.10 build-type:     Simple author:         Krzysztof Langner maintainer:     klangner@gmail.com-synopsis:       Analiza Java source code+synopsis:       Application for analysis of java source code homepage:       https://github.com/klangner/cantor Bug-reports:    https://github.com/klangner/cantor/issues stability:      Unstable interface, incomplete features.@@ -18,11 +18,9 @@     .     Currently implemented:     .-    * Finding project class paths.+    * Package dependency analysis     .     * Line Of Code metric.-    .-    Check <https://github.com/klangner/cantor/blob/master/doc/usage.md documentation> for usage patterns.  source-repository head   type:     git@@ -37,16 +35,14 @@                     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,                     containers >=0.5.0 && <0.6,-                    bytestring >=0.10.0 && <0.11+                    bytestring >=0.10.0 && <0.11,+                    split >=0.2.2 && <0.3+                     -  ghc-options:      -Wall-  other-modules:    -                    Utils.Folder,-                    Project.Maven+  ghc-options:      -Wall -threaded  test-suite spec   type:             exitcode-stdio-1.0@@ -54,16 +50,17 @@   default-language: Haskell2010   build-depends:                        base >= 4 && <4.7,-                    Cabal >=1.16.0 && <1.17,+                    Cabal >=1.16 && <1.19,                     directory >=1.2.0 && <1.3,                     filepath >=1.3.0 && <1.4,-                    hspec >=1.7.2 && <1.8,+                    hspec >=1.8 && <1.9,                     QuickCheck >=2.6 && <2.7,                     hxt >= 9.3 && < 9.4,                     hxt-xpath >=9.1.2 && <9.2,                     parsec >=3.1.3 && <3.2,                     containers >=0.5.0 && <0.6,-                    bytestring >=0.10.0 && <0.11+                    bytestring >=0.10.0 && <0.11,+                    split >=0.2.2 && <0.3    other-modules:      hs-source-dirs:  
src/Main.hs view
@@ -12,17 +12,17 @@ module Main where  import System.Environment+import System.Directory (createDirectoryIfMissing) import System.Console.GetOpt import System.Exit import Paths_cantor (version) import Data.Version (showVersion)-import Project.Sources (findJavaClassPaths)-import Project.Model-import Metric.Basic+import Project.Java+import Report.Builder (buildReport)  -data Flag = Version             -- -v-          | Help               -- --help+data Flag = Version -- -v+          | Help -- --help           deriving (Eq,Ord,Enum,Show,Bounded)                  @@ -30,9 +30,8 @@ main = do     argv <- getArgs     case getOpt Permute flags argv of-        ([], cmd:src:_, []) -> commandAction cmd src-        ([], [src], []) -> printPathsAction src-        ([Version], _, []) -> printVersion  +        ([], [src], []) -> analyzeProject src+        ([Version], _, []) -> printVersion         ([Help], _, []) -> printUsageInfo         (_, _, []) -> printUsageInfo         (_, _, errs) -> errorAction errs@@ -51,13 +50,13 @@  -- | Print application version number printVersion :: IO ()-printVersion = +printVersion =     putStrLn $ "cantor version " ++ showVersion version           -- | This action prints errors errorAction :: [String] -> IO ()-errorAction errs = do     +errorAction errs = do     putStrLn (concat errs)     exitWith (ExitFailure 1)     @@ -65,39 +64,24 @@ -- | Print usage info printUsageInfo :: IO () printUsageInfo = do-    putStrLn "Usage: cantor [command] <project_path>"-    putStrLn "  commands:"-    putStrLn "    <none> - Print source class paths."-    putStrLn "    loc - Print Line of code metric."+    putStrLn "Usage: cantor <project_path>"     putStrLn (usageInfo "" flags)      --- | Print information about project-printProjectInfo :: Project -> IO ()-printProjectInfo prj = putStrLn (getProjectInfo prj) -    +-- | Analize Java project and create report+analyzeProject :: FilePath -> IO ()+analyzeProject src = do+    reportFolder <- createReportFolder+    putStrLn "Scanning project..." +    prj <- scanJavaProject src+    putStrLn "Build metrics"+    buildReport reportFolder prj --- | Print information about class paths-printPathsAction :: FilePath -> IO ()-printPathsAction src = do-    paths <- findJavaClassPaths src-    putStrLn (if null paths then "Can't find any valid Java files in: " ++ src -              else "Found Java class paths:")-    mapM_ putStrLn paths-     --- | Execute command-commandAction :: String -> FilePath -> IO ()-commandAction xs src | xs == "loc" = locCommand src-                     | otherwise = putStrLn "Commands not implemented yet."-                   --- | Print LOC metric-locCommand :: FilePath -> IO ()-locCommand src = do -    loc <- lineOfCode src           -    let loc1 = filter (\(_, a) -> a > 0) loc-    mapM_ f loc1          -        where f (ext, count) = putStrLn $ ext ++ " lines: " ++ fmt count-              fmt :: Int -> String-              fmt a = if a > 1000 then show (a `div` 1000) ++ "K" else show a-              +-- | Create folder for report data+createReportFolder :: IO FilePath+createReportFolder = do+    createDirectoryIfMissing False path+    return path+    where path = "./cantor-report"+    
− src/Project/Maven.hs
@@ -1,65 +0,0 @@-{- |-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
@@ -1,60 +0,0 @@-{- |-Module : Utils.Folder-Copyright : Copyright (C) 2014 Krzysztof Langner-License : BSD3--Helper module with functions operating on IO--}-module Utils.Folder-        ( isJavaFile-        , listDirs-        , listFiles-        , listFilesR-        )where--import System.Directory (canonicalizePath, getDirectoryContents, doesDirectoryExist)-import Data.List-import Control.Monad-import System.FilePath (takeExtension)----- | 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-    -    --- | List all files in given directory and all subdirectories.--- Returns files with absolute path    -listFilesR :: (FilePath -> Bool)    -- Predicate to filter files-           -> FilePath              -- Directory path-           -> IO [FilePath]         -- Found file paths-listFilesR p path = do-    files <- listFiles path-    let filtered = filter p files-    dirs <- listDirs path-    children <- mapM (listFilesR p) dirs -    return $ filtered ++ concat children---- | Predicate to check if given source is Java file-isJavaFile :: FilePath -> Bool-isJavaFile src = takeExtension src == ".java"-              -    
test-src/Spec.hs view
@@ -3,15 +3,15 @@ import qualified Utils.FolderSpec import qualified Project.MavenSpec import qualified AST.JavaParserSpec-import qualified Project.SourcesSpec+import qualified Project.JavaSpec import qualified Metric.BasicSpec   main :: IO () main = hspec $ do-  describe "Utils.Folder" Utils.FolderSpec.spec+  describe "Folder utilities" Utils.FolderSpec.spec   describe "Project.Maven" Project.MavenSpec.spec-  describe "ProjectSources" Project.SourcesSpec.spec-  describe "AST.JavaParser" AST.JavaParserSpec.spec-  describe "Metric.Basic" Metric.BasicSpec.spec+  describe "Project sources" Project.JavaSpec.spec+  describe "Java AST Parser" AST.JavaParserSpec.spec+  describe "Basic metrics" Metric.BasicSpec.spec