Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (96 sloc) 4.437 kb
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
1 /*
2 * Copyright 2004-2009 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.
15 */
16
17 /**
18 * Gant script which generates stats for a Grails project.
19 *
20 * @author Glen.Smith
21 * @author Andres.Almiray
22 */
23
24 // includeTargets << grailsScript("_GrailsSettings")
25 includeTargets << grailsScript("_GrailsEvents")
26
27 target (default: "Generates basic stats for a Grails project") {
28 def EMPTY = /^\s*$/
29 def SLASH_SLASH = /^\s*\/\/.*/
30 def SLASH_STAR_STAR_SLASH = /^(.*)\/\*(.*)\*\/(.*)$/
31
32 // TODO - handle slash_star comments inside strings
33 def DEFAULT_LOC_MATCHER = { file ->
34 loc = 0
35 comment = 0
36 file.eachLine { line ->
835947fb »
2010-06-22 cleanup
37 if (line ==~ EMPTY) return
38 if (line ==~ SLASH_SLASH) return
39 def m = line =~ SLASH_STAR_STAR_SLASH
40 if (m.count && m[0][1] ==~ EMPTY && m[0][3] ==~ EMPTY) return
41 int open = line.indexOf("/*")
42 int close = line.indexOf("*/")
43 if (open != -1 && (close-open) <= 1) comment++
44 else if (close != -1 && comment) comment--
3559c097 »
2010-07-12 GRAILS-6489 - fix Stats script to correctly report LOC
45 if (!comment) loc++
835947fb »
2010-06-22 cleanup
46 }
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
47 loc
48 }
835947fb »
2010-06-22 cleanup
49
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
50 // maps file path to
51 def pathToInfo = [
8872a007 »
2010-08-14 GRAILS-6600 - improve the way that artifacts are counted in the Stats…
52 [name: "Controllers", path: "^grails-app.controllers", filetype: ["Controller.groovy"]],
53 [name: "Domain Classes", path: "^grails-app.domain", filetype: [".groovy"]],
54 [name: "Jobs", path: "^grails-app.job", filetype: [".groovy"]],
55 [name: "Services", path: "^grails-app.services", filetype: ["Service.groovy"]],
56 [name: "Tag Libraries", path: "^grails-app.taglib", filetype: ["TagLib.groovy"]],
57 [name: "Groovy Helpers", path: "^src.groovy", filetype: [".groovy"]],
58 [name: "Java Helpers", path: "^src.java", filetype: [".java"]],
59 [name: "Unit Tests", path: "^test.unit", filetype: [".groovy"]],
60 [name: "Integration Tests", path: "^test.integration", filetype: [".groovy"]],
fb6fbdfe »
2011-03-04 Added functional tests to stats generation.
61 [name: "Functional Tests", path: "^test.functional", filetype: [".groovy"]],
8872a007 »
2010-08-14 GRAILS-6600 - improve the way that artifacts are counted in the Stats…
62 [name: "Scripts", path: "^scripts", filetype: [".groovy"]],
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
63 ]
64
65 event("StatsStart", [pathToInfo])
66
8872a007 »
2010-08-14 GRAILS-6600 - improve the way that artifacts are counted in the Stats…
67 def baseDirFile = new File(basedir)
68 def baseDirPathLength = baseDirFile.path.size()+1
69 baseDirFile.eachFileRecurse { file ->
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
70 def match = pathToInfo.find { info ->
8872a007 »
2010-08-14 GRAILS-6600 - improve the way that artifacts are counted in the Stats…
71 file.path.substring(baseDirPathLength) =~ info.path &&
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
72 info.filetype.any{ s -> file.path.endsWith(s) }
73 }
835947fb »
2010-06-22 cleanup
74 if (match && file.isFile()) {
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
75 match.filecount = match.filecount ? match.filecount+1 : 1
76 // strip whitespace
77 loc = match.locmatcher ? match.locmatcher(file) : DEFAULT_LOC_MATCHER(file)
78 match.loc = match.loc ? match.loc + loc : loc
79 }
80 }
81
82 def totalFiles = 0
83 def totalLOC = 0
b0fe7810 »
2011-06-11 whitespace, warnings, deprecation fixes, switched from StringBuffer t…
84
85 def sw = new StringWriter()
86 def output = new PrintWriter(sw)
87
1aa1cb0f »
2011-06-03 Enhanced terminal output, needed to support redesigned interactive mode
88 output.println '''
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
89 +----------------------+-------+-------+
90 | Name | Files | LOC |
91 +----------------------+-------+-------+'''
92
93 pathToInfo.each { info ->
94 if (info.filecount) {
1aa1cb0f »
2011-06-03 Enhanced terminal output, needed to support redesigned interactive mode
95 output.println " | " +
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
96 info.name.padRight(20," ") + " | " +
97 info.filecount.toString().padLeft(5, " ") + " | " +
98 info.loc.toString().padLeft(5," ") + " | "
99 totalFiles += info.filecount
100 totalLOC += info.loc
101 }
102 }
103
1aa1cb0f »
2011-06-03 Enhanced terminal output, needed to support redesigned interactive mode
104 output.println " +----------------------+-------+-------+"
105 output.println " | Totals | " + totalFiles.toString().padLeft(5, " ") + " | " + totalLOC.toString().padLeft(5, " ") + " | "
106 output.println " +----------------------+-------+-------+\n"
107
b0fe7810 »
2011-06-11 whitespace, warnings, deprecation fixes, switched from StringBuffer t…
108 println sw.toString()
7d707b0c »
2009-10-26 fix for GRAILS-5260 "Improvements to stats script"
109 }
Something went wrong with that request. Please try again.