author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 04 Apr 2014 13:02:12 +0200 | |
changeset 3535 | f02b2535dd15 |
parent 3508 | dd0e9fe9c7e2 |
child 3548 | 265e326c3bd0 |
permissions | -rw-r--r-- |
2797 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2707 | 12 |
"{ Package: 'stx:libbasic3' }" |
13 |
||
14 |
Object subclass:#ProjectChecker |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
15 |
instanceVariableNames:'packages currentPackage currentPackageDef classes methods |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
16 |
problems phase checkExtensionsOnly' |
2967 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'System-Support-Projects' |
|
2707 | 20 |
! |
21 |
||
2797 | 22 |
!ProjectChecker class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
2707 | 36 |
! |
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
A simple project checker that can search whole projects or individual |
|
2853 | 41 |
classes or methods for various problems that may cause build problems such |
42 |
as: |
|
43 |
- inconsistent/messed up project definition class |
|
44 |
- method code problems |
|
2707 | 45 |
|
46 |
NOTE: Not yet finished. This code is meant as a single central entry for all the |
|
47 |
source code management tools like SCM Utilities, NewSystemBrowser ets. That code |
|
2797 | 48 |
will be refactored later once this tool prooves itself useful and mature enough. |
2707 | 49 |
|
50 |
[author:] |
|
51 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
52 |
||
53 |
[instance variables:] |
|
54 |
||
55 |
[class variables:] |
|
56 |
||
57 |
[see also:] |
|
2853 | 58 |
Tools::ProjectCheckerBrowser |
2707 | 59 |
|
60 |
" |
|
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
||
65 |
" |
|
66 |
ProjectChecker check: 'stx:libbasic' |
|
2797 | 67 |
ProjectChecker check: 'stx:libtool' |
68 |
ProjectChecker check: 'stx:libbasic3' |
|
2707 | 69 |
" |
70 |
! ! |
|
71 |
||
2853 | 72 |
!ProjectChecker class methodsFor:'instance creation'! |
73 |
||
74 |
forPackage: packageId |
|
75 |
^self new |
|
76 |
package: packageId; |
|
77 |
yourself. |
|
78 |
||
79 |
"Created: / 25-07-2012 / 18:00:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2910 | 80 |
! |
81 |
||
82 |
new |
|
83 |
"return an initialized instance" |
|
84 |
||
85 |
^ self basicNew initialize. |
|
2853 | 86 |
! ! |
87 |
||
2707 | 88 |
!ProjectChecker class methodsFor:'checking'! |
89 |
||
90 |
check: package |
|
91 |
||
92 |
^self new check: package |
|
93 |
||
94 |
"Created: / 11-01-2012 / 16:46:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
95 |
! ! |
|
96 |
||
97 |
!ProjectChecker methodsFor:'accessing'! |
|
98 |
||
3148 | 99 |
checkExtensionsOnly:aBoolean |
100 |
checkExtensionsOnly := aBoolean. |
|
101 |
! |
|
102 |
||
2797 | 103 |
classes: aCollection |
104 |
classes := aCollection. |
|
105 |
||
106 |
"Created: / 13-02-2012 / 17:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
107 |
! |
|
108 |
||
109 |
methods |
|
110 |
^ methods |
|
111 |
! |
|
112 |
||
113 |
methods:something |
|
114 |
methods := something. |
|
115 |
! |
|
116 |
||
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
117 |
package:packageId |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
118 |
"Adds `packageId` to set of checked packages" |
2707 | 119 |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
120 |
(packages includes: packageId) ifFalse:[ |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
121 |
packages add: packageId |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
122 |
]. |
2853 | 123 |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
124 |
"Modified (comment): / 22-02-2014 / 22:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2797 | 125 |
! |
126 |
||
127 |
problems |
|
2853 | 128 |
^ problems |
2797 | 129 |
|
130 |
"Modified: / 23-02-2012 / 15:14:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2707 | 131 |
! ! |
132 |
||
133 |
!ProjectChecker methodsFor:'checking'! |
|
134 |
||
135 |
check |
|
136 |
||
2910 | 137 |
problems removeAll. |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
138 |
packages do:[:each | |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
139 |
currentPackage := each. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
140 |
currentPackageDef := ProjectDefinition definitionClassForPackage: currentPackage. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
141 |
currentPackageDef isNil ifTrue:[ |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
142 |
self addProblem: |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
143 |
(ProjectProblem newProjectDefinitionDoesNotExist package: currentPackage). |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
144 |
^self |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
145 |
]. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
146 |
|
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
147 |
ActivityNotification raiseRequestWith:self errorString:'Checking package...'. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
148 |
self checkPackage. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
149 |
(checkExtensionsOnly ? false) ifFalse:[ |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
150 |
ActivityNotification raiseRequestWith:self errorString:'Checking classes...'. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
151 |
self checkClasses. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
152 |
]. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
153 |
ActivityNotification raiseRequestWith:self errorString:'Checking methods...'. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
154 |
self checkMethods. |
2797 | 155 |
]. |
156 |
||
2707 | 157 |
"Created: / 11-01-2012 / 16:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
158 |
"Modified: / 22-02-2014 / 21:59:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2707 | 159 |
! |
160 |
||
161 |
check: package |
|
162 |
||
163 |
self package: package. |
|
164 |
self check. |
|
165 |
||
166 |
"Created: / 11-01-2012 / 16:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
167 |
! ! |
|
168 |
||
169 |
!ProjectChecker methodsFor:'checks-individual'! |
|
170 |
||
171 |
checkClassListConsistency |
|
172 |
"Checks whether all classes listed in #classNamesAndAttributes are present |
|
173 |
and if all present classes are listed" |
|
174 |
||
2910 | 175 |
|classesInImage classesInDescription classesInDescriptionChecked onlyInDescription| |
2707 | 176 |
"WARNING: Copy/paste of ProjectDefinition>>validateDescription" |
177 |
||
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
178 |
classesInImage := Smalltalk allClasses select:[:cls | (cls package = currentPackage) and:[cls isPrivate not]]. |
2707 | 179 |
"/ classesInDescription := self classes asIdentitySet. |
2910 | 180 |
classesInDescription := OrderedCollection new. |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
181 |
( (currentPackageDef compiled_classNames_common) |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
182 |
, (currentPackageDef compiled_classNamesForPlatform:(OperatingSystem platformName)) |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
183 |
, (currentPackageDef autoloaded_classNames)) do:[:nm | |
2707 | 184 |
|cls| |
185 |
||
186 |
cls := Smalltalk at:nm asSymbol. |
|
187 |
cls isNil ifTrue:[ |
|
2797 | 188 |
self addProblem: |
189 |
(ProjectProblem newClassListedButDoesNotExist className: nm) |
|
2707 | 190 |
] ifFalse:[ |
191 |
classesInDescription add:cls. |
|
192 |
]. |
|
193 |
]. |
|
194 |
||
2910 | 195 |
classesInDescriptionChecked := OrderedCollection new. |
2707 | 196 |
classesInDescription do:[:eachClass | |
2910 | 197 |
(classesInDescriptionChecked includes: eachClass) ifTrue:[ |
198 |
self addProblem: |
|
199 |
(ProjectProblem newClassListedMultipleTimes |
|
200 |
className: eachClass name) |
|
201 |
]. |
|
202 |
||
2707 | 203 |
eachClass sharedPoolNames do:[:eachPoolName | |
204 |
|pool| |
|
205 |
||
206 |
pool := eachClass nameSpace classNamed:eachPoolName. |
|
207 |
pool isNil ifTrue:[ |
|
208 |
eachClass nameSpace ~~ Smalltalk ifTrue:[ |
|
209 |
pool := Smalltalk classNamed:eachPoolName. |
|
210 |
] |
|
211 |
]. |
|
212 |
pool isNil ifTrue:[ |
|
2797 | 213 |
self addProblem: |
214 |
(ProjectProblem newClassUsesPoolButItDoesNotExist |
|
215 |
className: eachClass name; |
|
216 |
poolName: eachPoolName). |
|
2707 | 217 |
] ifFalse:[ |
218 |
pool isSharedPool ifFalse:[ |
|
2797 | 219 |
self addProblem: |
220 |
(ProjectProblem newClassUsesPoolButItIsNotASharedPool |
|
221 |
className: eachClass name; |
|
222 |
poolName: eachPoolName). |
|
2707 | 223 |
]. |
224 |
]. |
|
225 |
]. |
|
2910 | 226 |
|
2966
bf5ea36104cd
Fix in #checkClassListConsistency - care about classes with nil superclass (Autoload/Object)
vrany
parents:
2965
diff
changeset
|
227 |
(eachClass superclass notNil "/Care about classes with nil superclass - Object & Autoload |
bf5ea36104cd
Fix in #checkClassListConsistency - care about classes with nil superclass (Autoload/Object)
vrany
parents:
2965
diff
changeset
|
228 |
and:[eachClass superclass package == eachClass package]) ifTrue:[ |
2910 | 229 |
(classesInDescriptionChecked includes: eachClass superclass) ifFalse:[ |
230 |
self addProblem: |
|
231 |
(ProjectProblem newClassListedBeforeItsSuperclass |
|
232 |
className: eachClass name; |
|
233 |
superClassName: eachClass superclass name) |
|
234 |
]. |
|
235 |
]. |
|
236 |
eachClass sharedPools do:[:eachPool| |
|
237 |
eachPool package == eachClass package ifTrue:[ |
|
238 |
(classesInDescriptionChecked includes: eachPool) ifFalse:[ |
|
239 |
self addProblem: |
|
240 |
(ProjectProblem newClassListedBeforeItsPool |
|
241 |
className: eachClass name; |
|
242 |
poolName: eachPool name) |
|
243 |
]. |
|
244 |
]. |
|
245 |
]. |
|
246 |
||
247 |
classesInDescriptionChecked add: eachClass. |
|
2707 | 248 |
]. |
249 |
||
250 |
classesInImage ~= classesInDescription ifTrue:[ |
|
2856
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
251 |
"This is done later in checkClassesListedInProjectDefinition:" |
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
252 |
"/ onlyInImage := (classesInImage reject:[:cls | classesInDescription includes:cls]). |
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
253 |
"/ onlyInImage do:[:cls| |
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
254 |
"/ self addProblem: |
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
255 |
"/ (ProjectProblem newClassNotListed className: cls name). |
a1cee28488c0
changed: #checkClassListConsistency - do not warn about not-listed classes twice
vrany
parents:
2853
diff
changeset
|
256 |
"/ ]. |
2707 | 257 |
onlyInDescription := (classesInDescription reject:[:cls | classesInImage includes:cls]). |
258 |
onlyInDescription do:[:cls| |
|
2797 | 259 |
self addProblem: |
260 |
(ProjectProblem newClassListedButDoesNotExist className: cls name) |
|
2707 | 261 |
]. |
262 |
]. |
|
263 |
||
264 |
"Created: / 11-01-2012 / 17:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
265 |
"Modified: / 22-02-2014 / 21:46:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2718 | 266 |
! |
267 |
||
3467 | 268 |
checkClassesAutoloadedSuperclasse: aCollection"of Class" |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
269 |
currentPackageDef classNamesAndAttributesDo:[:clsnm :attributes| |
3467 | 270 |
| cls | |
271 |
||
272 |
cls := Smalltalk at: clsnm. |
|
273 |
(aCollection includes: cls) ifTrue:[ |
|
274 |
(attributes includes: #autoload) ifFalse:[ |
|
275 |
"/ Care for Object!! |
|
276 |
cls superclass notNil ifTrue:[ |
|
277 |
| superDef superNm | |
|
278 |
||
279 |
superDef := ProjectDefinition definitionClassForPackage: cls superclass package. |
|
280 |
superDef isNil ifTrue:[ |
|
281 |
problems add: |
|
282 |
(ProjectProblem newClassIsCompiledButSuperclassProjectDefinitionIsMissing |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
283 |
package: currentPackage; |
3467 | 284 |
className: clsnm; |
285 |
yourself) |
|
286 |
] ifFalse:[ |
|
287 |
superNm := cls superclass name. |
|
288 |
superDef classNamesAndAttributesDo:[:clsnm2 :attributes2| |
|
289 |
clsnm2 == superNm ifTrue:[ |
|
290 |
(attributes2 includes: #autoload) ifTrue:[ |
|
291 |
problems add: |
|
292 |
(ProjectProblem newClassIsCompiledButSuperclassIsAutoloaded |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
293 |
package: currentPackage; |
3467 | 294 |
className: clsnm; |
295 |
yourself) |
|
296 |
]. |
|
297 |
]. |
|
298 |
]. |
|
299 |
] |
|
300 |
]. |
|
301 |
]. |
|
302 |
]. |
|
303 |
]. |
|
304 |
||
305 |
"Created: / 20-09-2013 / 11:08:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
306 |
"Modified: / 05-10-2013 / 12:45:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
307 |
! |
|
308 |
||
2910 | 309 |
checkClassesForMethodsInNoProject:classesToCheck |
310 |
| checker | |
|
311 |
||
312 |
checker := [:cls | |
|
313 |
cls |
|
314 |
selectorsAndMethodsDo:[:sel :mth | |
|
315 |
(mth package isNil or:[ mth package == PackageId noProjectID ]) ifTrue:[ |
|
316 |
"Sigh, special hack for Expecco" |
|
317 |
((cls name = 'Expecco::AbstractApplication class' and:[ sel = 'flags' ]) or:[ |
|
318 |
(cls name = 'Expecco::Browser class' and:[ sel = 'flags' ])]) ifFalse:[ |
|
319 |
self addProblem:(ProjectProblem newMethodInNoPackage className:cls name |
|
320 |
selector:sel). |
|
321 |
] |
|
322 |
] |
|
323 |
] |
|
324 |
]. |
|
325 |
classesToCheck do:[:class | |
|
326 |
checker value:class theMetaclass. |
|
327 |
checker value:class theNonMetaclass. |
|
328 |
] |
|
329 |
||
330 |
"Created: / 13-02-2012 / 18:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
331 |
! |
|
332 |
||
333 |
checkClassesForNonQualifiedSharedPools: classesToCheck |
|
334 |
||
335 |
classesToCheck do:[:cls| |
|
336 |
cls sharedPoolNames do:[:poolName| |
|
337 |
(Smalltalk at: poolName asSymbol) isNil ifTrue:[ |
|
338 |
| ns | |
|
339 |
||
340 |
ns := cls nameSpace. |
|
341 |
(ns ~~ Smalltalk and:[(ns at: poolName asSymbol) notNil]) ifTrue:[ |
|
342 |
self addProblem: |
|
343 |
(ProjectProblem newClassUsesPoolButItIsNotASharedPool |
|
344 |
className: cls name; |
|
345 |
poolName: poolName) |
|
346 |
] |
|
347 |
] |
|
348 |
] |
|
349 |
]. |
|
350 |
||
351 |
"Created: / 13-09-2012 / 16:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
352 |
! |
|
353 |
||
2797 | 354 |
checkClassesListedInProjectDefinition: classesToCheck |
355 |
||
356 |
| classNamesListed | |
|
357 |
||
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
358 |
classNamesListed := currentPackageDef classNames. |
2797 | 359 |
|
360 |
classesToCheck do:[:class| |
|
361 |
(class isPrivate not and:[(classNamesListed includes: class name) not]) ifTrue:[ |
|
362 |
self addProblem: |
|
363 |
(ProjectProblem newClassNotListed className: class name). |
|
364 |
] |
|
365 |
]. |
|
366 |
||
367 |
"Created: / 13-02-2012 / 18:18:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
368 |
! |
|
369 |
||
2718 | 370 |
checkExtensionsListConsistency |
371 |
"Checks whether all extensions listed in #extensionMethodNames are present |
|
372 |
and if all extension methods are listed" |
|
373 |
||
374 |
| extensionsListed extensionsPresent | |
|
375 |
||
376 |
extensionsListed := OrderedCollection new. |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
377 |
currentPackageDef extensionMethodNames pairWiseDo:[:cls :sel| |
2718 | 378 |
extensionsListed add: (Array with: cls with: sel) |
379 |
]. |
|
380 |
extensionsPresent := OrderedCollection new. |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
381 |
currentPackageDef searchForExtensions do:[:each| |
2910 | 382 |
"JV@2012-09-07: Do not take Java methods into an account, they |
383 |
should not be listed in extensionMethodNames. |
|
384 |
They are loaded lazily by JavaClassReader and if listed here, |
|
385 |
they would cause an error if the package is loaded from source. |
|
386 |
Sort of a HACK, indeed" |
|
3467 | 387 |
each mclass theNonMetaclass isJavaClass ifFalse:[ |
2910 | 388 |
extensionsPresent add: (Array with: each mclass name with: each selector) |
389 |
]. |
|
2718 | 390 |
]. |
391 |
||
392 |
(extensionsListed \ extensionsPresent) do:[:clsAndSel| |
|
3167 | 393 |
|cls clsName selector| |
394 |
||
395 |
clsName := clsAndSel first. |
|
396 |
selector := clsAndSel second. |
|
397 |
(cls := Smalltalk classNamed: clsName) isNil ifTrue:[ |
|
398 |
self addProblem: |
|
399 |
(ProjectProblem newExtensionMethodsClassDoesNotExist |
|
400 |
className: clsName selector: selector). |
|
401 |
] ifFalse:[ |
|
402 |
(cls compiledMethodAt:selector) isNil ifTrue:[ |
|
403 |
self addProblem: |
|
404 |
(ProjectProblem newExtensionMethodListedButDoesNotExist |
|
405 |
className: clsName selector: selector). |
|
406 |
] ifFalse:[ |
|
407 |
self addProblem: |
|
408 |
(ProjectProblem newExtensionMethodListedButInDifferentPackage |
|
409 |
className: clsName selector: selector). |
|
410 |
] |
|
411 |
] |
|
2718 | 412 |
]. |
413 |
||
414 |
(extensionsPresent \ extensionsListed) do:[:clsAndSel| |
|
2797 | 415 |
self addProblem: |
416 |
(ProjectProblem newExtensionMethodNotListed |
|
417 |
className: clsAndSel first selector: clsAndSel second). |
|
2718 | 418 |
]. |
419 |
||
420 |
"Created: / 12-01-2012 / 12:31:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3467 | 421 |
"Modified: / 29-03-2013 / 19:41:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2718 | 422 |
! |
423 |
||
424 |
checkExtensionsPrerequisites |
|
425 |
"Checks whether packages of all extensions method classes are listed |
|
426 |
in package prerequisites" |
|
427 |
||
3116 | 428 |
|preRequisites| |
429 |
||
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
430 |
preRequisites := currentPackageDef effectivePreRequisites. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
431 |
currentPackageDef searchForExtensions do:[:mthd| |
3116 | 432 |
(preRequisites includes: mthd mclass package) ifFalse:[ |
2797 | 433 |
"/ self problem: ('%3 required by extension method but not in prerequisites' bindWith: mthd mclass package) |
434 |
"/ 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) |
|
435 |
"/ severity: #error data: mthd |
|
2718 | 436 |
]. |
437 |
] |
|
438 |
||
439 |
"Created: / 12-01-2012 / 12:41:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2797 | 440 |
! |
441 |
||
2853 | 442 |
checkMethodCodingStyle: method |
443 |
"Checks for various coding style violations such as 'self halt' or |
|
444 |
improper indentation :-)" |
|
445 |
||
446 |
"To be implemented" |
|
447 |
||
448 |
"Created: / 11-04-2012 / 12:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
449 |
! |
|
450 |
||
3161 | 451 |
checkMethodSTCCompilability1: method into: problemIssue |
2853 | 452 |
"Checks is the method can be compiled by STC based on Parser error/warnings" |
453 |
||
3161 | 454 |
| lang compiler | |
455 |
||
2853 | 456 |
lang := method programmingLanguage. |
457 |
lang isSmalltalk ifFalse:[ ^ self ]. |
|
458 |
||
3161 | 459 |
compiler := lang compilerClass new. |
460 |
compiler |
|
2853 | 461 |
compile:method source |
462 |
forClass:method mclass |
|
463 |
inCategory:'others' |
|
3161 | 464 |
notifying:problemIssue |
2853 | 465 |
install:false |
466 |
skipIfSame:false |
|
467 |
silent:false |
|
468 |
foldConstants:true |
|
3161 | 469 |
ifFail:[ ]. |
470 |
||
471 |
compiler usedGlobals do:[:nm | |
|
472 |
(nm startsWith:Smalltalk undeclaredPrefix) ifTrue:[ |
|
473 |
problemIssue |
|
474 |
addWarning:'Contains unresolved reference to: ',(nm copyFrom:(Smalltalk undeclaredPrefix size + 1)) |
|
475 |
from:0 to:0 |
|
476 |
] |
|
477 |
]. |
|
2853 | 478 |
|
479 |
"Created: / 11-04-2012 / 15:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
480 |
! |
|
481 |
||
3161 | 482 |
checkMethodSTCCompilability2: method into: problemIssue |
2853 | 483 |
"Checks is the method can be compiled by STC based on selected lint rules" |
484 |
||
485 |
"Not yet implemented" |
|
486 |
||
487 |
"Created: / 11-04-2012 / 15:54:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
488 |
! |
|
489 |
||
490 |
checkMethodSTCCompilability: method |
|
491 |
"Checks is the method can be compiled by STC (since STC won't compile |
|
492 |
everything bytecode compiler/jit compiler does, sigh" |
|
493 |
||
494 |
| issue | |
|
495 |
||
496 |
"No need to check the method if the class is autoloaded" |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
497 |
(currentPackageDef autoloaded_classNames includes: method mclass theNonMetaclass name) ifTrue:[ |
2853 | 498 |
^ self |
499 |
]. |
|
500 |
||
501 |
issue := ProjectProblem newMethodCompilabilityIssue. |
|
502 |
issue method: method. |
|
503 |
self checkMethodSTCCompilability1: method into: issue. |
|
504 |
self checkMethodSTCCompilability2: method into: issue. |
|
505 |
issue hasIssue ifTrue:[ |
|
506 |
self addProblem: issue |
|
507 |
] |
|
508 |
||
509 |
"Created: / 11-04-2012 / 12:37:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
510 |
! |
|
511 |
||
512 |
checkMethodSourceCode: method |
|
513 |
"Checks, whether method's source code is both |
|
514 |
available and parseable. Return true if the code |
|
2966
bf5ea36104cd
Fix in #checkClassListConsistency - care about classes with nil superclass (Autoload/Object)
vrany
parents:
2965
diff
changeset
|
515 |
is syntactically correct, false otherwise" |
2853 | 516 |
|
517 |
| source | |
|
518 |
||
519 |
[ |
|
520 |
source := method source. |
|
521 |
] on: Error do:[ |
|
522 |
self addProblem: |
|
523 |
(ProjectProblem newMethodSourceNotAvailable method: method). |
|
524 |
^false |
|
525 |
]. |
|
2913 | 526 |
method programmingLanguage isSmalltalk ifFalse:[ ^ false ]. |
527 |
||
2853 | 528 |
[ |
529 |
(Parser parseMethod: method source) == #Error ifTrue:[ |
|
530 |
self addProblem: |
|
531 |
(ProjectProblem newMethodSourceCorrupted method: method). |
|
532 |
^false. |
|
533 |
] |
|
534 |
] on: Error do:[ |
|
535 |
self addProblem: |
|
536 |
(ProjectProblem newMethodSourceCorrupted method: method). |
|
537 |
^false. |
|
538 |
]. |
|
539 |
||
540 |
^true |
|
541 |
||
542 |
"Created: / 11-04-2012 / 12:29:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2707 | 543 |
! ! |
544 |
||
545 |
!ProjectChecker methodsFor:'checks-private'! |
|
546 |
||
547 |
checkClasses |
|
3535
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
548 |
| classesToCheck | |
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
549 |
|
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
550 |
classesToCheck := classes notNil ifTrue:[ classes ] ifFalse:[ Smalltalk allClasses ]. |
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
551 |
classesToCheck := classesToCheck select:[:each | each package = currentPackage ]. |
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
552 |
self checkClasses: classesToCheck. |
2707 | 553 |
|
554 |
"Created: / 11-01-2012 / 16:55:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3535
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
555 |
"Modified: / 04-04-2014 / 13:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2707 | 556 |
! |
557 |
||
2797 | 558 |
checkClasses: classesToCheck |
559 |
||
560 |
self checkClassesListedInProjectDefinition: classesToCheck. |
|
2910 | 561 |
self checkClassesForMethodsInNoProject:classesToCheck. |
562 |
self checkClassesForNonQualifiedSharedPools:classesToCheck. |
|
3467 | 563 |
self checkClassesAutoloadedSuperclasse:classesToCheck. |
2797 | 564 |
|
565 |
"Created: / 13-02-2012 / 18:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3467 | 566 |
"Modified: / 20-09-2013 / 11:08:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2797 | 567 |
! |
568 |
||
2853 | 569 |
checkMethod: method |
570 |
(self checkMethodSourceCode: method) ifTrue:[ |
|
571 |
"/OK, method's source is OK, perform further checks |
|
3233 | 572 |
"/ ActivityNotification raiseRequestWith:self errorString:'Checking stc compilability...'. |
2853 | 573 |
self checkMethodSTCCompilability: method. |
3233 | 574 |
"/ ActivityNotification raiseRequestWith:self errorString:'Checking coding style...'. |
2853 | 575 |
self checkMethodCodingStyle: method. |
576 |
] |
|
577 |
||
578 |
"Created: / 11-04-2012 / 12:27:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
579 |
! |
|
580 |
||
2707 | 581 |
checkMethods |
2853 | 582 |
methods notEmptyOrNil ifTrue:[ |
583 |
self checkMethods: methods. |
|
584 |
^self. |
|
585 |
]. |
|
586 |
||
587 |
self checkMethods: |
|
588 |
(Iterator on:[:whatToDo| |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
589 |
| classesToCheck | |
3233 | 590 |
|
591 |
classes notNil ifTrue:[ |
|
592 |
classesToCheck := classes |
|
593 |
] ifFalse:[ |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
594 |
classesToCheck := (Smalltalk allClasses select:[:cls | (cls package = currentPackage)]). |
3233 | 595 |
]. |
596 |
classesToCheck do:[:cls| |
|
597 |
cls theNonMetaclass withAllPrivateClassesDo:[:eachClass | |
|
598 |
ActivityNotification raiseRequestWith:self errorString:('Checking %1...' bindWith:eachClass name). |
|
599 |
eachClass instAndClassSelectorsAndMethodsDo:[:s :m | |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
600 |
m package = currentPackage ifTrue:[ |
3148 | 601 |
((checkExtensionsOnly ? false) not |
602 |
or:[ m package ~~ cls package "isExtension" ]) ifTrue:[ |
|
603 |
whatToDo value:m |
|
604 |
] |
|
605 |
] |
|
606 |
] |
|
2853 | 607 |
]. |
608 |
] |
|
609 |
]) |
|
2707 | 610 |
|
611 |
"Created: / 11-01-2012 / 16:55:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
612 |
"Modified: / 22-02-2014 / 21:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2707 | 613 |
! |
614 |
||
2853 | 615 |
checkMethods: methodsToCheck |
616 |
||
617 |
methodsToCheck do:[:m|self checkMethod: m]. |
|
618 |
||
619 |
"Created: / 11-04-2012 / 12:16:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
620 |
! |
|
621 |
||
2707 | 622 |
checkPackage |
3148 | 623 |
(checkExtensionsOnly ? false) ifFalse:[ |
624 |
self checkClassListConsistency. |
|
625 |
]. |
|
2718 | 626 |
self checkExtensionsListConsistency. |
627 |
self checkExtensionsPrerequisites. |
|
628 |
||
2716
9a74597bcd4b
Do not use annotations as stc crashes when compiling them
vrany
parents:
2707
diff
changeset
|
629 |
"add more here..." |
2707 | 630 |
|
631 |
"Created: / 11-01-2012 / 16:55:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
632 |
! ! |
|
633 |
||
2910 | 634 |
!ProjectChecker methodsFor:'initialization'! |
635 |
||
636 |
initialize |
|
637 |
"Invoked when a new instance is created." |
|
638 |
||
639 |
"/ please change as required (and remove this comment) |
|
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
640 |
packages := OrderedCollection new. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
641 |
"/ currentPackage := nil. |
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
642 |
"/ currentPackageDef := nil. |
2910 | 643 |
"/ classes := nil. |
644 |
"/ methods := nil. |
|
645 |
problems := List new. |
|
646 |
"/ phase := nil. |
|
647 |
||
648 |
"/ super initialize. -- commented since inherited method does nothing |
|
649 |
||
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
650 |
"Modified: / 22-02-2014 / 21:41:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2910 | 651 |
! ! |
652 |
||
2707 | 653 |
!ProjectChecker methodsFor:'reporting'! |
654 |
||
2797 | 655 |
addProblem: aProjectProblem |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
656 |
aProjectProblem package: currentPackage. |
2707 | 657 |
problems isNil ifTrue:[problems := OrderedCollection new]. |
2797 | 658 |
problems add: aProjectProblem |
2707 | 659 |
|
2797 | 660 |
"Created: / 23-02-2012 / 13:10:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3508
dd0e9fe9c7e2
Added support for checking multiple packages at once.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3467
diff
changeset
|
661 |
"Modified: / 22-02-2014 / 21:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2718 | 662 |
! ! |
663 |
||
2707 | 664 |
!ProjectChecker class methodsFor:'documentation'! |
665 |
||
666 |
version |
|
3535
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
667 |
^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.20 2014-04-04 11:02:12 vrany Exp $' |
3167 | 668 |
! |
669 |
||
670 |
version_CVS |
|
3535
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
671 |
^ '$Header: /cvs/stx/stx/libbasic3/ProjectChecker.st,v 1.20 2014-04-04 11:02:12 vrany Exp $' |
2707 | 672 |
! |
673 |
||
2797 | 674 |
version_SVN |
3535
f02b2535dd15
Fix for multi-package check.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3508
diff
changeset
|
675 |
^ '$Id: ProjectChecker.st,v 1.20 2014-04-04 11:02:12 vrany Exp $' |
2707 | 676 |
! ! |
3116 | 677 |