-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmartest.install
582 lines (555 loc) · 15.4 KB
/
smartest.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<?php
/**
* @file
*/
use \Drupal\smartest\Analyser;
// TODO we remove the libraries dependency including directly the phploc library and adding it to the source.
// This is a bad practice and should be fixed later.
// Composer maybe?
/*function smartest_requirements($phase) {
global $base_url;
$requirements = array();
$t = 't';
$phploc = isset(libraries_get_libraries()['phploc']);
$requirements['phploc'] = array(
'title' => $t('phploc'),
'value' => $phploc ? $t('Installed') : $t('Missing'),
'severity' => $phploc ? REQUIREMENT_OK : REQUIREMENT_ERROR,
);
if (!$phploc) {
$requirements['phploc']['description'] = t('Please install the Analyser class of phploc library %url.', array('%url' => 'https://github.com/isa-group/phploc/blob/master/src/Analyser.php'));
}
return $requirements;
}*/
/**
* Implements hook_schema().
*/
function smartest_schema() {
$schema = array();
$schema['smartest_statistic'] = array(
'description' => 'Stores smartest statistic fields',
'fields' => array(
'module' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
'description' => 'Primary Key: Module name.',
),
'loc' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Lines of Code.',
),
'cc' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Ciclomatic complexity.',
),
'cloc' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Comment lines of code.',
),
'lloc' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Logical lines of code.',
),
'last_execution' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '00-00-0000 00:00',
'description' => 'Test last execution.',
),
'test_execution_time' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'Test execution test.',
),
'passes' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of test are passed.',
),
'fails' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of test are fails.',
),
'exceptions' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of test are exceptions.',
),
'methods' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of methods.',
),
'methods_call' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of call to methods.',
),
'executed' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of call to methods.',
),
'executable' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of call to methods.',
),
'coverage' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of call to methods.',
),
'git_changes' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'number of call to methods.',
),
),
'primary key' => array('module'),
);
$schema['smartest_cache'] = array(
'description' => 'Stores smartest statistic cookies',
'fields' => array(
'cookie' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => 'statistic_form_cookie',
'description' => 'Primary Key: Identifier.',
),
'modules' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'ALL',
'description' => 'Modules selected.',
),
'criteria' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'LOC',
'description' => 'Creiteria selected.',
),
'type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'column',
'description' => 'Graphical type.',
),
),
'primary key' => array('cookie'),
);
$schema['smartest'] = array(
'description' => 'Stores simpletest messages',
'fields' => array(
'message_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique simpletest message ID.',
),
'test_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Test ID, messages belonging to the same ID are reported together',
),
'test_class' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The name of the class that created this message.',
),
'status' => array(
'type' => 'varchar',
'length' => 9,
'not null' => TRUE,
'default' => '',
'description' => 'Message status. Core understands pass, fail, exception.',
),
'message' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'The message itself.',
),
'message_group' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The message group this message belongs to. For example: warning, browser, user.',
),
'function' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the assertion function or method that created this message.',
),
'line' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Line number on which the function is called.',
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the file where the function is called.',
),
),
'primary key' => array('message_id'),
'indexes' => array(
'reporter' => array('test_class', 'message_id'),
),
);
$schema['smartest_prioritization'] = array(
'description' => 'Stores test class prioritization.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => 'prioritization_test',
'description' => 'Primary Key.',
),
'last_variable' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => 'loc',
'description' => 'The last variable to priorize during testing.',
),
'last_order' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => 'DESC',
'description' => 'The last order to priorize during testing.',
),
),
'primary key' => array('id'),
);
$schema['smartest_times'] = array(
'description' => 'Stores tests class times.',
'fields' => array(
'class' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Primary Key.',
),
'test_group' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Test class group.',
),
'time' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Execution time in seconds.',
),
),
'primary key' => array('class'),
);
$schema['smartest_widget'] = array(
'description' => 'Stores widget dashboard configurations.',
'fields' => array(
'title' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Primary Key.',
),
'widget_type' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'cloud or chart.',
),
'criteria1' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Widget criteria.',
),
'criteria2' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Widget criteria.',
),
'modules' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'Widget modules.',
),
'n_element' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'number of elements to show in the widget.',
),
'type' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'line or column (if is a chart case).',
),
'dashboard_name' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
'description' => 'dashboard name associated.',
),
'order' => array(
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => 'DESC',
'description' => 'Order of variables, ASC or DESC.',
),
),
'primary key' => array('title', 'dashboard_name'),
);
return $schema;
}
/**
* Install, update and uninstall functions for the smartest module.
*/
function smartest_install() {
// Add a default entries.
$fields = array(
'cookie' => 'statistic_form_cookie',
'modules' => 'ALL',
'criteria' => 'ALL',
'type' => 'column',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields = array(
'cookie' => 'auth',
'modules' => 'ALL',
'criteria' => 'ALL',
'type' => 'false',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields = array(
'cookie' => 'permission_cookie',
'modules' => 'none',
'criteria' => 'permision',
'type' => 'default',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields = array(
'cookie' => 'git_url',
'modules' => 'none',
'criteria' => 'https://api.github.com/repos/drupal/drupal/commits',
'type' => 'none',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields = array(
'cookie' => 'client_id',
'modules' => 'none',
'criteria' => 'none',
'type' => 'none',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields = array(
'cookie' => 'secret_id',
'modules' => 'none',
'criteria' => 'none',
'type' => 'none',
);
db_insert('smartest_cache')
->fields($fields)
->execute();
$fields_time = array(
'cookie' => 'timeout',
'modules' => 'none',
'criteria' => 'none',
'type' => 'none',
);
db_insert('smartest_cache')
->fields($fields_time)
->execute();
$fields_mod = array(
'cookie' => 'modules_number',
'modules' => '5',
'criteria' => 'none',
'type' => 'none',
);
db_insert('smartest_cache')
->fields($fields_mod)
->execute();
$fields_wgt = array(
'cookie' => 'dashboard_page',
'modules' => 'none',
'criteria' => 'none',
'type' => 'default',
);
db_insert('smartest_cache')
->fields($fields_wgt)
->execute();
$fields_prior = array(
'id' => 'prioritization_test',
'last_variable' => 'loc',
'last_order' => 'DESC',
);
db_insert('smartest_prioritization')
->fields($fields_prior)
->execute();
calculate_stats();
$fields_widget1 = array(
'title' => 'loc-cc',
'widget_type' => 'cloud',
'criteria1' => 'loc',
'criteria2' => 'cc',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
$fields_widget2 = array(
'title' => 'Lines-of-code',
'widget_type' => 'chart',
'criteria1' => 'loc',
'criteria2' => 'none',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
$fields_widget3 = array(
'title' => 'Ciclomatic-complexity',
'widget_type' => 'chart',
'criteria1' => 'cc',
'criteria2' => 'none',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
$fields_widget4 = array(
'title' => 'Last-tests-executions',
'widget_type' => 'chart',
'criteria1' => 'test',
'criteria2' => 'none',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
$fields_widget5 = array(
'title' => 'Last-tests-executions-(Passed)',
'widget_type' => 'chart',
'criteria1' => 'passes',
'criteria2' => 'none',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
$fields_widget6 = array(
'title' => 'Header',
'widget_type' => 'main_header',
'criteria1' => 'none',
'criteria2' => 'none',
'modules' => 'ALL',
'n_element' => 5,
'type' => 'column',
'dashboard_name' => 'default',
);
db_insert('smartest_widget')
->fields($fields_widget1)
->execute();
db_insert('smartest_widget')
->fields($fields_widget2)
->execute();
db_insert('smartest_widget')
->fields($fields_widget3)
->execute();
db_insert('smartest_widget')
->fields($fields_widget4)
->execute();
db_insert('smartest_widget')
->fields($fields_widget5)
->execute();
db_insert('smartest_widget')
->fields($fields_widget6)
->execute();
}
function calculate_stats() {
drupal_set_time_limit( 60 * 5000 );
$moduleHandler = \Drupal::moduleHandler();
$modules = $moduleHandler->getModuleList();
$files = array();
foreach ($modules as $module => $value) {
$analyser = new Analyser;
$files = file_scan_directory(drupal_get_path("module", $module), '/.*' . $module . '.*\.inc$|.*' .
$module . '.*\.module$|.*' . $module . '.*\.php$|.*' . $module . '.*\.test$|.*' . $module . '.*\.install$/');
$files_root = array();
foreach ($files as $file => $f) {
$files_root[$file] = $file;
}
$results = $analyser->countFiles($files_root, FALSE);
$fields = array(
'module' => $module,
'loc' => $results['ncloc'],
'cc' => (is_null($results['methodCcnMax'])) ? 0 : $results['methodCcnMax'],
'cloc' => $results['cloc'],
'lloc' => $results['lloc'],
);
db_insert('smartest_statistic')
->fields($fields)
->execute();
}
}