cantor 0.3 → 0.4
raw patch · 4 files changed
+62/−43 lines, 4 filesdep ~basedep ~hspec
Dependency ranges changed: base, hspec
Files
- CHANGES +4/−2
- cantor.cabal +8/−8
- src/Main.hs +45/−22
- test-src/Spec.hs +5/−11
CHANGES view
@@ -1,11 +1,13 @@-Version 03.+Version 0.4 -----------+* Refactored for application for analkysis any application instead of just Java. +Version 0.3+----------- * Produces minimal report as HTML file Version 0.2 ------------ * Added default command to scan project for class paths. Works only with Java projects * Added LOC metric
cantor.cabal view
@@ -1,5 +1,5 @@ name: cantor-version: 0.3+version: 0.4 cabal-version: >= 1.10 build-type: Simple author: Krzysztof Langner@@ -14,11 +14,12 @@ Extra-Source-Files: CHANGES description: - Application for analyzing Java source code.+ Cantor is application for analyzing software projects.+ The goal of this application is to help developer understand source code of unknown project. . Currently implemented: .- * Package dependency analysis+ * Find language the application is written in . * Line Of Code metric. @@ -31,7 +32,7 @@ main-is: Main.hs default-language: Haskell2010 build-depends: - base >= 4 && <4.7,+ base >= 4 && <5, directory >=1.2.0 && <1.3, hxt >= 9.3 && < 9.4, hxt-xpath >=9.1.2 && <9.2,@@ -49,11 +50,11 @@ main-is: Spec.hs default-language: Haskell2010 build-depends: - base >= 4 && <4.7,+ base >= 4 && <5, Cabal >=1.16 && <1.19, directory >=1.2.0 && <1.3, filepath >=1.3.0 && <1.4,- hspec >=1.8 && <1.9,+ hspec >= 2 && <3, QuickCheck >=2.6 && <2.7, hxt >= 9.3 && < 9.4, hxt-xpath >=9.1.2 && <9.2,@@ -62,8 +63,7 @@ bytestring >=0.10.0 && <0.11, split >=0.2.2 && <0.3 - other-modules: - hs-source-dirs: + hs-source-dirs: src, test-src
src/Main.hs view
@@ -12,17 +12,20 @@ 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.Java-import Report.Builder (buildReport)+import Cantor.Project (Project, scanProject)+import Cantor.KnowledgeDB (KnowledgeDB, conceptUrl, loadKDB)+import Cantor.Analysis.Language (countSourceFiles) data Flag = Version -- -v | Help -- --help+ | Build -- --build+ | Lang -- --languages+ | Modules -- --modules deriving (Eq,Ord,Enum,Show,Bounded) @@ -30,9 +33,10 @@ main = do argv <- getArgs case getOpt Permute flags argv of- ([], [src], []) -> analyzeProject src ([Version], _, []) -> printVersion ([Help], _, []) -> printUsageInfo+ ([], [src], []) -> analyzeProject [Lang] src+ (xs, [src], []) -> analyzeProject xs src (_, _, []) -> printUsageInfo (_, _, errs) -> errorAction errs @@ -41,10 +45,16 @@ -- | Command line flags flags :: [OptDescr Flag] flags =- [Option "v" ["version"] (NoArg Version)- "Print version number."- ,Option "h" ["help"] (NoArg Help)+ [ Option "b" ["build"] (NoArg Build)+ "Check what build system is used by project."+ , Option "h" ["help"] (NoArg Help) "Print this help message."+ , Option "l" ["languages"] (NoArg Lang)+ "Check what languages is this application written in."+ , Option "m" ["modules"] (NoArg Modules)+ "Find independed modules in the project."+ , Option "v" ["version"] (NoArg Version)+ "Print version number." ] @@ -68,20 +78,33 @@ putStrLn (usageInfo "" flags) --- | 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+-- | Analize project and create report+-- What is analyzed depends on passed flags+analyzeProject :: [Flag] -> FilePath -> IO ()+analyzeProject xs src = do+ let db = loadKDB+ prj <- scanProject src+ mapM_ (\x -> (f x) db prj) xs+ return ()+ where f Build = analyzeBuildSystem+ f _ = analyzeLanguages --- | Create folder for report data-createReportFolder :: IO FilePath-createReportFolder = do- createDirectoryIfMissing False path- return path- where path = "./cantor-report"- ++-- | Analize langauge used in project+analyzeLanguages :: KnowledgeDB -> Project -> IO ()+analyzeLanguages db prj = do+ putStrLn "Found source files:"+ let lc = countSourceFiles db prj+ mapM_ (\(l, n) -> putStrLn (l ++ ": " ++ show n)) lc+ let (lang, _) = foldl (\(l0, n0) (l, n) -> if(n > n0) then (l,n) else (l0,n0)) ("",0) lc+ putStrLn $ "This application is written in " ++ lang+ putStrLn $ "Check more about " ++ lang ++ " at:"+ putStrLn $ (conceptUrl db lang)+ return ()++-- | Analize build system used by project+analyzeBuildSystem :: KnowledgeDB -> Project -> IO ()+analyzeBuildSystem _ _ = do+ putStrLn $ "Build system used by project: " ++ "Unknown"+ return ()
test-src/Spec.hs view
@@ -1,17 +1,11 @@ import Test.Hspec import Test.QuickCheck-import qualified Utils.FolderSpec-import qualified Project.MavenSpec-import qualified AST.JavaParserSpec-import qualified Project.JavaSpec-import qualified Metric.BasicSpec+import qualified Cantor.Utils.FolderSpec+import qualified Cantor.Parser.JavaSpec main :: IO () main = hspec $ do- describe "Folder utilities" Utils.FolderSpec.spec- describe "Project.Maven" Project.MavenSpec.spec- describe "Project sources" Project.JavaSpec.spec- describe "Java AST Parser" AST.JavaParserSpec.spec- describe "Basic metrics" Metric.BasicSpec.spec- + describe "Folder utilities" Cantor.Utils.FolderSpec.spec+ describe "Java AST Parser" Cantor.Parser.JavaSpec.spec+