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