author | vrany |
Thu, 12 Jan 2012 14:12:35 +0100 | |
changeset 2718 | d82d91c62477 |
parent 2716 | 9a74597bcd4b |
child 2797 | ab7cc3e21a2b |
child 3011 | 1997ff6e7e55 |
permissions | -rw-r--r-- |
2707 | 1 |
"{ Package: 'stx:libbasic3' }" |
2 |
||
3 |
Object subclass:#ProjectChecker |
|
4 |
instanceVariableNames:'package packageDef classes methods problems' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'System-Support-Projects' |
|
8 |
! |
|
9 |
||
10 |
Object subclass:#Problem |
|
11 |
instanceVariableNames:'label description severity data' |
|
12 |
classVariableNames:'' |
|
13 |
poolDictionaries:'' |
|
14 |
privateIn:ProjectChecker |
|
15 |
! |
|
16 |
||
17 |
!ProjectChecker class methodsFor:'documentation'! |
|
18 |
||
19 |
documentation |
|
20 |
" |
|
21 |
A simple project checker that can search whole projects or individual |
|
22 |
classes or methods for various problems. TBW... |
|
23 |
||
24 |
NOTE: Not yet finished. This code is meant as a single central entry for all the |
|
25 |
source code management tools like SCM Utilities, NewSystemBrowser ets. That code |
|
26 |
will be refactored later once this tools prooves itself useful and mature enough. |
|
27 |
||
28 |
[author:] |
|
29 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
30 |
||
31 |
[instance variables:] |
|
32 |
||
33 |
[class variables:] |
|
34 |
||
35 |
[see also:] |
|
36 |
||
37 |
" |
|
38 |
! |
|
39 |
||
40 |
examples |
|
41 |
||
42 |
" |
|
43 |
ProjectChecker check: 'stx:libbasic' |
|
44 |
" |
|
45 |
! ! |
|
46 |
||
47 |
!ProjectChecker class methodsFor:'checking'! |
|
48 |
||
49 |
check: package |
|
50 |
||
51 |
^self new check: package |
|
52 |
||
53 |
"Created: / 11-01-2012 / 16:46:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
54 |
! ! |
|
55 |
||
56 |
!ProjectChecker methodsFor:'accessing'! |
|
57 |
||
58 |
package |
|
59 |
^ package |
|
60 |
! |
|
61 |
||
62 |
package:packageId |
|
63 |
package := packageId. |
|
64 |
! ! |
|
65 |
||
66 |
!ProjectChecker methodsFor:'checking'! |
|
67 |
||
68 |
check |
|
69 |
||
70 |
self |
|
71 |
checkPackage; |
|
72 |
checkClasses; |
|
73 |
checkMethods |
|
74 |
||
75 |
"Created: / 11-01-2012 / 16:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! |
|
77 |
||
78 |
check: package |
|
79 |
||
80 |
self package: package. |
|
81 |
self check. |
|
82 |
||
83 |
"Created: / 11-01-2012 / 16:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
84 |
! ! |
|
85 |
||
86 |
!ProjectChecker methodsFor:'checks-individual'! |
|
87 |
||
88 |
checkClassListConsistency |
|
89 |
"Checks whether all classes listed in #classNamesAndAttributes are present |
|
90 |
and if all present classes are listed" |
|
91 |
||
92 |
|classesInImage classesInDescription missingPools onlyInImage onlyInDescription| |
|
93 |
"WARNING: Copy/paste of ProjectDefinition>>validateDescription" |
|
94 |
||
95 |
classesInImage := Smalltalk allClasses select:[:cls | (cls package = self package) and:[cls isPrivate not]]. |
|
96 |
"/ classesInDescription := self classes asIdentitySet. |
|
97 |
classesInDescription := IdentitySet new. |
|
98 |
((packageDef compiled_classNamesForPlatform:(OperatingSystem platformName)) |
|
99 |
, (packageDef compiled_classNames_common) |
|
100 |
, (packageDef autoloaded_classNames)) do:[:nm | |
|
101 |
|cls| |
|
102 |
||
103 |
cls := Smalltalk at:nm asSymbol. |
|
104 |
cls isNil ifTrue:[ |
|
105 |
self problem: 'Missing class ', nm |
|
106 |
description: 'A class is listed in project definition but not present in the system' |
|
107 |
severity: #error |
|
108 |
] ifFalse:[ |
|
109 |
classesInDescription add:cls. |
|
110 |
]. |
|
111 |
]. |
|
112 |
||
113 |
missingPools := Set new. |
|
114 |
classesInDescription do:[:eachClass | |
|
115 |
eachClass sharedPoolNames do:[:eachPoolName | |
|
116 |
|pool| |
|
117 |
||
118 |
pool := eachClass nameSpace classNamed:eachPoolName. |
|
119 |
pool isNil ifTrue:[ |
|
120 |
eachClass nameSpace ~~ Smalltalk ifTrue:[ |
|
121 |
pool := Smalltalk classNamed:eachPoolName. |
|
122 |
] |
|
123 |
]. |
|
124 |
pool isNil ifTrue:[ |
|
125 |
self |
|
126 |
problem:'Missing pool: ',eachPoolName |
|
127 |
description: ('Class %1 uses a pool named %2 but it does not exists' bindWith: eachClass with: pool) |
|
128 |
severity: #error data: eachClass. |
|
129 |
missingPools add:eachPoolName. |
|
130 |
] ifFalse:[ |
|
131 |
pool isSharedPool ifFalse:[ |
|
132 |
self |
|
133 |
problem:'Missing pool: ',eachPoolName |
|
134 |
description: ('Class %1 uses a pool named %2 but it is not actually a shared pool.' bindWith: eachClass with: pool) |
|
135 |
severity: #error data: eachClass. |
|
136 |
missingPools add:eachPoolName. |
|
137 |
]. |
|
138 |
]. |
|
139 |
]. |
|
140 |
]. |
|
141 |
||
142 |
classesInImage ~= classesInDescription ifTrue:[ |
|
143 |
onlyInImage := (classesInImage reject:[:cls | classesInDescription includes:cls]). |
|
144 |
onlyInImage do:[:cls| |
|
145 |
self problem: ('Class %1 not listed in project definition' bindWith: cls) |
|
146 |
description: 'The class %1 not listed in project definition''s #classNamesAndAttributes, therefore it won''t be compiler nor autoladed next time you compile/load project.' |
|
147 |
severity: #error data: cls. |
|
148 |
]. |
|
149 |
onlyInDescription := (classesInDescription reject:[:cls | classesInImage includes:cls]). |
|
150 |
onlyInDescription do:[:cls| |
|
151 |
self problem: ('Class %1 is listed in project definition but not present in the system' bindWith: cls) |
|
152 |
description: 'The class %1 list in project definition''s but not present in the system. This leads to uncompilable package as build files may be incorrectly generated.' |
|
153 |
severity: #error data: cls. |
|
154 |
]. |
|
155 |
]. |
|
156 |
||
157 |
"Created: / 11-01-2012 / 17:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2718 | 158 |
! |
159 |
||
160 |
checkExtensionsListConsistency |
|
161 |
"Checks whether all extensions listed in #extensionMethodNames are present |
|
162 |
and if all extension methods are listed" |
|
163 |
||
164 |
| extensionsListed extensionsPresent | |
|
165 |
||
166 |
extensionsListed := OrderedCollection new. |
|
167 |
packageDef extensionMethodNames pairWiseDo:[:cls :sel| |
|
168 |
extensionsListed add: (Array with: cls with: sel) |
|
169 |
]. |
|
170 |
extensionsPresent := OrderedCollection new. |
|
171 |
packageDef searchForExtensions do:[:each| |
|
172 |
extensionsPresent add: (Array with: each mclass name with: each selector) |
|
173 |
]. |
|
174 |
||
175 |
(extensionsListed \ extensionsPresent) do:[:clsAndSel| |
|
176 |
self problem: ('Missing %1>>%2 extension method' bindWith: clsAndSel first with: clsAndSel second) |
|
177 |
description: ('An extension method %1>>%2 is listed in #extensionMethodNames but not present in image' bindWith: clsAndSel first with: clsAndSel second) |
|
178 |
severity: #warning data: clsAndSel. |
|
179 |
]. |
|
180 |
||
181 |
(extensionsPresent \ extensionsListed) do:[:clsAndSel| |
|
182 |
self problem: ('%1>>%2 extension method not in list' bindWith: clsAndSel first with: clsAndSel second) |
|
183 |
description: ('An extension method %1>>%2 present in image but not listed in #extensionMethodNames' bindWith: clsAndSel first with: clsAndSel second) |
|
184 |
severity: #warning data: clsAndSel. |
|
185 |
]. |
|
186 |
||
187 |
"Created: / 12-01-2012 / 12:31:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
188 |
! |
|
189 |
||
190 |
checkExtensionsPrerequisites |
|
191 |
"Checks whether packages of all extensions method classes are listed |
|
192 |
in package prerequisites" |
|
193 |
||
194 |
packageDef searchForExtensions do:[:mthd| |
|
195 |
(packageDef preRequisites includes: mthd mclass package) ifFalse:[ |
|
196 |
self problem: ('%3 required by extension method but not in prerequisites' bindWith: mthd mclass package) |
|
197 |
description: ('An extension method %1>>%2 extends class in package %3 but the package is not listed in package''s prerequisited. This leads into missing methods and strange bugs when application is compiled and run!!' bindWith: mthd class with: mthd selector with: mthd class package) |
|
198 |
severity: #error data: mthd |
|
199 |
]. |
|
200 |
] |
|
201 |
||
202 |
"Created: / 12-01-2012 / 12:41:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2707 | 203 |
! ! |
204 |
||
205 |
!ProjectChecker methodsFor:'checks-private'! |
|
206 |
||
207 |
checkClasses |
|
208 |
"Not yet implemented" |
|
209 |
||
210 |
"Created: / 11-01-2012 / 16:55:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 |
! |
|
212 |
||
213 |
checkMethods |
|
214 |
"Not yet implemented" |
|
215 |
||
216 |
"Created: / 11-01-2012 / 16:55:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
217 |
! |
|
218 |
||
219 |
checkPackage |
|
220 |
||
221 |
packageDef := ProjectDefinition definitionClassForPackage: package. |
|
222 |
packageDef isNil ifTrue:[ |
|
223 |
self problem: 'Project definition class for package %1 does not exist' |
|
224 |
description: nil |
|
225 |
severity: #error. |
|
226 |
^self |
|
227 |
]. |
|
2716
9a74597bcd4b
Do not use annotations as stc crashes when compiling them
vrany
parents:
2707
diff
changeset
|
228 |
self checkClassListConsistency. |
2718 | 229 |
self checkExtensionsListConsistency. |
230 |
self checkExtensionsPrerequisites. |
|
231 |
||
2716
9a74597bcd4b
Do not use annotations as stc crashes when compiling them
vrany
parents:
2707
diff
changeset
|
232 |
"add more here..." |
2707 | 233 |
|
234 |
"Created: / 11-01-2012 / 16:55:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
235 |
! ! |
|
236 |
||
237 |
!ProjectChecker methodsFor:'reporting'! |
|
238 |
||
239 |
problem: label description: description severity: severity |
|
240 |
"Reports a problem" |
|
241 |
||
242 |
^self problem: label description: description severity: severity data: nil |
|
243 |
||
244 |
"Created: / 11-01-2012 / 17:24:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
245 |
! |
|
246 |
||
247 |
problem: label description: description severity: severity data: data |
|
248 |
"Reports a problem" |
|
249 |
||
250 |
problems isNil ifTrue:[problems := OrderedCollection new]. |
|
251 |
problems add: |
|
252 |
(Problem new |
|
253 |
label: label; |
|
254 |
description: description; |
|
255 |
severity: severity; |
|
256 |
data: data) |
|
257 |
||
258 |
"Created: / 11-01-2012 / 17:17:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
259 |
! ! |
|
260 |
||
261 |
!ProjectChecker::Problem methodsFor:'accessing'! |
|
262 |
||
263 |
data |
|
264 |
^ data |
|
265 |
! |
|
266 |
||
267 |
data:something |
|
268 |
data := something. |
|
269 |
! |
|
270 |
||
271 |
description |
|
272 |
^ description |
|
273 |
! |
|
274 |
||
275 |
description:something |
|
276 |
description := something. |
|
277 |
! |
|
278 |
||
279 |
label |
|
280 |
^ label |
|
281 |
! |
|
282 |
||
283 |
label:something |
|
284 |
label := something. |
|
285 |
! |
|
286 |
||
287 |
severity |
|
288 |
^ severity |
|
289 |
! |
|
290 |
||
291 |
severity:something |
|
292 |
severity := something. |
|
293 |
! ! |
|
294 |
||
2718 | 295 |
!ProjectChecker::Problem methodsFor:'printing & storing'! |
296 |
||
297 |
printOn:aStream |
|
298 |
"append a printed representation if the receiver to the argument, aStream" |
|
299 |
||
300 |
super printOn:aStream. |
|
301 |
aStream nextPut:$(. |
|
302 |
severity printOn:aStream. |
|
303 |
aStream nextPut:$:; space. |
|
304 |
label printOn:aStream. |
|
305 |
aStream nextPut:$). |
|
306 |
||
307 |
"Modified: / 12-01-2012 / 13:09:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
308 |
! ! |
|
309 |
||
2707 | 310 |
!ProjectChecker class methodsFor:'documentation'! |
311 |
||
312 |
version |
|
2718 | 313 |
^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.3 2012-01-12 13:12:35 vrany Exp $' |
2707 | 314 |
! |
315 |
||
316 |
version_CVS |
|
2718 | 317 |
^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.3 2012-01-12 13:12:35 vrany Exp $' |
2707 | 318 |
! ! |