2 * Copyright 2004-2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Gant script which generates stats for a Grails project.
24 import org
.codehaus
.groovy
.grails
.commons
.GrailsClassUtils as GCU
25 import groovy
.text
.SimpleTemplateEngine
27 Ant
.property(environment
:"env")
28 grailsHome
= Ant
.antProject
.properties
."env.GRAILS_HOME"
30 includeTargets
<< new File ( "${grailsHome}/scripts/Init.groovy" )
32 target ('default': "Generates basic stats for a Grails project") {
36 new Expando(name
: "Controllers", filetype
: ".groovy", path
: "controllers"),
37 new Expando(name
: "Domain Classes", filetype
: ".groovy", path
: "domain"),
38 new Expando(name
: "Jobs", filetype
: ".groovy", path
: "jobs"),
39 new Expando(name
: "Services", filetype
: ".groovy", path
: "services"),
40 new Expando(name
: "Tag Libraries", filetype
: ".groovy", path
: "taglib"),
41 new Expando(name
: "Groovy Helpers", filetype
: ".groovy", path
: "src.groovy"),
42 new Expando(name
: "Java Helpers", filetype
: ".java", path
: "src.java"),
43 new Expando(name
: "Unit Tests", filetype
: ".groovy", path
: "test.unit"),
44 new Expando(name
: "Integration Tests", filetype
: ".groovy", path
: "test.integration"),
48 new File(basedir
).eachFileRecurse
{ file
->
50 def match
= pathToInfo
.find
{ expando
->
51 file
.path
=~ expando
.path
&&
52 file
.path
.endsWith(expando
.filetype
)
54 if (match
&& file
.isFile() ) {
56 if (file
.path
.toLowerCase() =~
/web
-inf
/ || file
.path
.toLowerCase() =~
/plugins
/) {
57 // println "Skipping $file.path in WEB-INF or plugins dir"
59 match
.filecount
= match
.filecount ? match
.filecount
+1 : 1
61 def loc
= file
.readLines().findAll
{ line
-> !(line
==~
/^
\s*$
/) }.size()
62 match
.loc
= match
.loc ? match
.loc
+ loc
: loc
73 +----------------------+-------+-------+
74 | Name | Files | LOC |
75 +----------------------+-------+-------+'''
78 pathToInfo
.each
{ info
->
82 info
.name
.padRight(20," ") + " | " +
83 info
.filecount
.toString().padLeft(5, " ") + " | " +
84 info
.loc
.toString().padLeft(5," ") + " | "
85 totalFiles
+= info
.filecount
92 println
" +----------------------+-------+-------+"
93 println
" | Totals | " + totalFiles
.toString().padLeft(5, " ") + " | " + totalLOC
.toString().padLeft(5, " ") + " | "
94 println
" +----------------------+-------+-------+\n"