36
|
1 |
"{ Package: 'stx:goodies/builder/codechecker' }"
|
|
2 |
|
|
3 |
Object subclass:#SmalllintReportGenerator
|
|
4 |
instanceVariableNames:'rules environment'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Refactory-Lint'
|
|
8 |
!
|
|
9 |
|
|
10 |
!SmalllintReportGenerator class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
a standalone smallint runner.
|
|
15 |
Generates an xml report compatible to pmd, to be processed by hudson.
|
|
16 |
|
|
17 |
[author:]
|
|
18 |
Claus Gittinger
|
|
19 |
"
|
|
20 |
!
|
|
21 |
|
|
22 |
examples
|
|
23 |
"
|
|
24 |
|checker|
|
|
25 |
|
|
26 |
checker := self new.
|
|
27 |
checker addPackage:'exept:workflow'.
|
|
28 |
checker performChecks.
|
|
29 |
checker generateReportAs:'checkstyle.xml'
|
|
30 |
"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!SmalllintReportGenerator class methodsFor:'instance creation'!
|
|
34 |
|
|
35 |
new
|
|
36 |
"return an initialized instance"
|
|
37 |
|
|
38 |
^ self basicNew initialize.
|
|
39 |
! !
|
|
40 |
|
|
41 |
!SmalllintReportGenerator methodsFor:'checking'!
|
|
42 |
|
|
43 |
performChecks
|
|
44 |
rules withIndexDo:[:rule :index|
|
|
45 |
Stdout showCR:('Checking: ', rule name).
|
|
46 |
(SmalllintChecker runRule: rule onEnvironment: environment)
|
|
47 |
].
|
|
48 |
|
|
49 |
"Created: / 07-08-2011 / 01:10:00 / cg"
|
|
50 |
! !
|
|
51 |
|
|
52 |
!SmalllintReportGenerator methodsFor:'initialization'!
|
|
53 |
|
|
54 |
initialize
|
|
55 |
self setupRules.
|
|
56 |
self setupEnvironment
|
|
57 |
|
|
58 |
"Modified: / 07-08-2011 / 01:14:51 / cg"
|
|
59 |
! !
|
|
60 |
|
|
61 |
!SmalllintReportGenerator methodsFor:'reporting'!
|
|
62 |
|
|
63 |
generateReportAs:aFilename
|
|
64 |
aFilename asFilename writingFileDo:[:s | self generateReportOn:s].
|
|
65 |
|
|
66 |
"Created: / 07-08-2011 / 01:17:46 / cg"
|
|
67 |
!
|
|
68 |
|
|
69 |
generateReportOn:aStream
|
|
70 |
aStream nextPutLine: '<?xml version="1.0"?>'.
|
|
71 |
aStream nextPutLine: '<pmd>'.
|
|
72 |
rules do:[:eachRule |
|
|
73 |
eachRule problemCount > 0 ifTrue:[
|
|
74 |
eachRule failedMethods do:[:method |
|
|
75 |
|class classFileName s selector fullSource
|
|
76 |
charPos lineNumber ruleName rationale|
|
|
77 |
|
|
78 |
class := method mclass.
|
|
79 |
s := class localSourceStreamFor:class theNonMetaclass classFilename.
|
|
80 |
s notNil ifTrue:[
|
|
81 |
classFileName := s pathName.
|
|
82 |
s close.
|
|
83 |
] ifFalse:[
|
|
84 |
classFileName := class sourceFilename.
|
|
85 |
].
|
|
86 |
fullSource := class source.
|
|
87 |
charPos := method sourcePosition ? 1.
|
|
88 |
"/ q&d hack - editor knows
|
|
89 |
lineNumber := (TextView new contents:fullSource)
|
|
90 |
lineOfCharacterPosition:charPos.
|
|
91 |
ruleName := eachRule name.
|
|
92 |
rationale := eachRule rationale.
|
|
93 |
|
|
94 |
aStream nextPutLine:(' <file name="%1">' bindWith:classFileName).
|
|
95 |
aStream nextPutLine:(' <violation line="%1" rule="%2">' bindWith:lineNumber with:ruleName).
|
|
96 |
aStream nextPutLine:('%1' bindWith:rationale).
|
|
97 |
aStream nextPutLine: ' </violation>'.
|
|
98 |
aStream nextPutLine: ' </file>'.
|
|
99 |
|
|
100 |
].
|
|
101 |
]
|
|
102 |
].
|
|
103 |
aStream nextPutLine: '</pmd>'.
|
|
104 |
|
|
105 |
"Created: / 07-08-2011 / 01:17:00 / cg"
|
|
106 |
! !
|
|
107 |
|
|
108 |
!SmalllintReportGenerator methodsFor:'setup'!
|
|
109 |
|
|
110 |
addClass:aClass
|
|
111 |
environment addClass: aClass.
|
|
112 |
|
|
113 |
"Created: / 07-08-2011 / 01:11:33 / cg"
|
|
114 |
!
|
|
115 |
|
|
116 |
addPackage:aPackage
|
|
117 |
Smalltalk loadPackage:aPackage.
|
|
118 |
Smalltalk allClassesInPackage:aPackage do:[:cls | self addClass:cls]
|
|
119 |
|
|
120 |
"Created: / 07-08-2011 / 01:12:31 / cg"
|
|
121 |
!
|
|
122 |
|
|
123 |
setupEnvironment
|
|
124 |
environment := ClassEnvironment new.
|
|
125 |
|
|
126 |
"Created: / 07-08-2011 / 01:10:56 / cg"
|
|
127 |
!
|
|
128 |
|
|
129 |
setupRules
|
|
130 |
| allRule checks|
|
|
131 |
|
|
132 |
allRule := RBCompositeLintRule allRules.
|
|
133 |
checks := allRule rules detect:[ :each | each name = 'Lint checks' ].
|
|
134 |
checks rules: (checks rules reject: [ :each | each name = 'Squeak bugs' ]).
|
|
135 |
|
|
136 |
rules := allRule flattened.
|
|
137 |
|
|
138 |
"Created: / 07-08-2011 / 01:08:56 / cg"
|
|
139 |
! !
|
|
140 |
|
|
141 |
!SmalllintReportGenerator class methodsFor:'documentation'!
|
|
142 |
|
|
143 |
version
|
|
144 |
^ '$Header$'
|
|
145 |
!
|
|
146 |
|
|
147 |
version_CVS
|
|
148 |
^ '$Header$'
|
|
149 |
! !
|