GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / scripts / Stats.groovy
blob895ce71dbcc7276ae56e1c7e2708cd7081adde48
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
17 /**
18 * Gant script which generates stats for a Grails project.
20 * @author Glen Smith
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") {
34 // maps file path to
35 def pathToInfo = [
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"
58 } else {
59 match.filecount = match.filecount ? match.filecount+1 : 1
60 // strip whitespace
61 def loc = file.readLines().findAll { line -> !(line ==~ /^\s*$/) }.size()
62 match.loc = match.loc ? match.loc + loc : loc
69 def totalFiles = 0
70 def totalLOC = 0
72 println '''
73 +----------------------+-------+-------+
74 | Name | Files | LOC |
75 +----------------------+-------+-------+'''
78 pathToInfo.each { info ->
80 if (info.filecount) {
81 println " | " +
82 info.name.padRight(20," ") + " | " +
83 info.filecount.toString().padLeft(5, " ") + " | " +
84 info.loc.toString().padLeft(5," ") + " | "
85 totalFiles += info.filecount
86 totalLOC += info.loc
92 println " +----------------------+-------+-------+"
93 println " | Totals | " + totalFiles.toString().padLeft(5, " ") + " | " + totalLOC.toString().padLeft(5, " ") + " | "
94 println " +----------------------+-------+-------+\n"