-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecute.pl
More file actions
6554 lines (5867 loc) · 210 KB
/
Copy pathexecute.pl
File metadata and controls
6554 lines (5867 loc) · 210 KB
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#=============================================================================
# Web-CAT: execute script for Java submissions
#
# usage:
# execute.pl <properties-file>
#=============================================================================
use Class::Struct;
use strict;
no warnings 'utf8';
use Carp qw(carp croak);
use Config::Properties::Simple;
use File::Basename;
use File::Copy;
use File::Spec;
use File::stat;
use File::Glob qw (bsd_glob);
use Proc::Background;
use Web_CAT::Beautifier;
use Web_CAT::Clover::Reformatter;
use Web_CAT::FeedbackGenerator;
use Web_CAT::JUnitResultsReader;
use XML::Smart;
use Data::Dump qw(dump);
#=============================================================================
# Load properties files given on command line
#=============================================================================
my $propfile = $ARGV[0]; # property file name
my $cfg = Config::Properties::Simple->new(file => $propfile);
$cfg->{wrap} = 0;
my $pluginHome = $cfg->getProperty('pluginHome');
{
# scriptHome is deprecated, but may still be used on older servers
if (! defined $pluginHome)
{
$pluginHome = $cfg->getProperty('scriptHome');
}
}
#=============================================================================
# Import local libs
#=============================================================================
use lib dirname(__FILE__) . '/perllib';
use JavaTddPlugin;
use Web_CAT::Utilities qw(
confirmExists
filePattern
copyHere
htmlEscape
smartHtmlEscape
addReportFile
scanTo
scanThrough
linesFromFile
addReportFileWithStyle
);
use Web_CAT::ExpandedFeedbackUtil qw(
extractAboveBelowLinesOfCode
checkForPatternInFile
negateValueZeroToOneAndOneToZero
extractLineOfCode
);
use Web_CAT::ErrorMapper qw(
compilerErrorHintKey
runtimeErrorHintKey
compilerErrorEnhancedMessage
setResultDir
codingStyleMessageValue
findBugsMessage
);
use Web_CAT::Indicators::ProgressTracker;
use Web_CAT::Indicators::ProgressCommenter;
use Web_CAT::Indicators::DailyMissionGenerator;
use Web_CAT::Maria;
#=============================================================================
# Bring config properties into local variables for easy reference
#=============================================================================
my $pid = $cfg->getProperty('userName');
my $workingDir = $cfg->getProperty('workingDir');
my $resultDir = $cfg->getProperty('resultDir');
#Using ResultDir in ErrorMapper file and we set the value here
setResultDir($resultDir);
my $useEnhancedFeedback = $cfg->getProperty('useEnhancedFeedback', 0);
$useEnhancedFeedback = ($useEnhancedFeedback =~ m/^(true|on|yes|y|1)$/i);
my $useIndicatorFeedback = $cfg->getProperty('useIndicatorFeedback', 0);
$useIndicatorFeedback = ($useIndicatorFeedback =~ m/^(true|on|yes|y|1)$/i);
my $useMaria = $cfg->getProperty('useMaria', 0);
$useMaria = ($useMaria =~ m/^(true|on|yes|y|1)$/i);
my $useMariaExplanations = $cfg->getProperty('useMariaExplanations', 0);
$useMariaExplanations = ($useMariaExplanations =~ m/^(true|on|yes|y|1)$/i);
my $useDailyMissions = $cfg->getProperty('useDailyMissions', 0);
$useDailyMissions = ($useDailyMissions =~ m/^(true|on|yes|y|1)$/i);
if ($useDailyMissions) { $useIndicatorFeedback = 1; }
my $showAllTestOutcomes = $cfg->getProperty('showAllTestOutcomes', 0);
$showAllTestOutcomes = ($showAllTestOutcomes =~ m/^(true|on|yes|y|1)$/i);
my $useFindBugs = $cfg->getProperty('useFindBugs', 0);
$useFindBugs = ($useFindBugs =~ m/^(true|on|yes|y|1)$/i);
if ($useFindBugs) { $cfg->setProperty('enableFindBugs', 'true'); }
my $usePit = $cfg->getProperty('usePit', 0);
$usePit = ($usePit =~ m/^(true|on|yes|y|1)$/i);
if ($usePit) { $cfg->setProperty('enablePit', 'true'); }
my $useEMRN = $cfg->getProperty('useEMRN', 0);
$useEMRN = ($useEMRN =~ m/^(true|on|yes|y|1)$/i);
my $useEMRNManual = $cfg->getProperty('useEMRNManual', 0);
$useEMRNManual = ($useEMRNManual =~ m/^(true|on|yes|y|1)$/i);
my $emrnExcellent = $cfg->getProperty('emrnExcellent', 100);
my $emrnMeetsExpectations = $cfg->getProperty('emrnMeetsExpectations', 100);
my $emrnRevisionNeeded = $cfg->getProperty('emrnRevisionNeeded', 100);
my $useJdk11 = $cfg->getProperty('useJdk11', 0);
$useJdk11 = ($useJdk11 =~ m/^(true|on|yes|y|1)$/i);
my $allTestOutcomeResults = '';
my $allTestOutcomesLeader = '';
my $progressTracker = new Web_CAT::Indicators::ProgressTracker($cfg);
my $progressCommenter =
new Web_CAT::Indicators::ProgressCommenter($progressTracker);
my @beautifierIgnoreFiles = ();
my $timeout = $cfg->getProperty('timeout', 45);
my $publicDir = "$resultDir/public";
my $maxToolScore = $cfg->getProperty('max.score.tools', 20);
my $maxCorrectnessScore = $cfg->getProperty('max.score.correctness',
100 - $maxToolScore);
#my $instructorCases = 0;
#my $instructorCasesPassed = undef;
my $instructorCasesPercent = 0;
my $studentCasesPercent = 0;
my $codeCoveragePercent = 0;
#my $studentTestMsgs;
my $hasJUnitErrors = 0;
my %status = (
'antTimeout' => 0,
'studentHasSrcs' => 0,
'studentTestResults' => undef,
'instrTestResults' => undef,
'toolDeductions' => 0,
'compileMsgs' => "",
'compileErrs' => 0,
'feedback' =>
new Web_CAT::FeedbackGenerator($resultDir, 'feedback.html'),
'instrFeedback' =>
new Web_CAT::FeedbackGenerator($resultDir, 'staffFeedback.html')
);
# To mark components in each module(in WebCat-java submission) based on
# whether all the errors of a subsection are passed or not. For instance,
# "1" in compilerErrors implies: no compilerErrors
# If there are no compiler errors or warnings or signature errors then
# firstHalfRadialBar = 50; otherwise zero. Likewise secondHalfRadialBar
# corresponds to codingFlaws and junitTests
my %codingSectionStatus = (
'compilerErrors' => 1,
'compilerWarnings' => 1,
'signatureErrors' => 1,
'codingFlaws' => 1,
'junitTests' => 1,
'firstHalfRadialBar' => 50,
'secondHalfRadialBar' => 50
);
my %styleSectionStatus = (
'javadoc' => 1,
'indentation' => 1,
'whitespace' => 1,
'lineLength' => 1,
'other' => 1,
'pointsGainedPercent' => 100
);
my %testingSectionStatus = (
'errors' => 1,
'failures' => 1,
'methodsUncovered' => 1,
'statementsUncovered' => 1,
'conditionsUncovered' => 1,
'resultsPercent' => 100,
'codeCoveragePercent' => 100
);
my %behaviorSectionStatus = (
'errors' => 1,
'stackOverflowErrors' => 1,
'testsTakeTooLong' => 1,
'failures' => 1,
'outOfMemoryErrors' => 1,
'problemCoveragePercent' => 100
);
# A limit for number of errors in a subcategory in the feedback.
# Example: codingFlaws is a subcategory.
my $maxErrorsPerSubcategory = 8;
# A limit for number of lines above assertion failure in Testing section.
my $linesAboveAssertionFailure = 5;
# To know which among the above four sections should be expanded-
# Based on which one first contains errors in the following order:
# Coding(1), Testing(2), Behavior(3), Style (4).
my $expandSectionId = -1;
# Traverse over the expanded section hashmaps using the order from below
# arrays.
my @codingSectionOrder = (
'compilerErrors',
'compilerWarnings',
'signatureErrors',
'codingFlaws',
'junitTests');
my @styleSectionOrder = (
'javadoc',
'indentation',
'whitespace',
'lineLength',
'other');
my @testingSectionOrder = (
'errors',
'failures',
'methodsUncovered',
'statementsUncovered',
'conditionsUncovered');
my @behaviorSectionOrder = (
'errors',
'stackOverflowErrors',
'testsTakeTooLong',
'failures',
'outOfMemoryErrors');
my %codingSectionTitles = (
'compilerErrors' => 'Compiler Errors',
'compilerWarnings' => 'Compiler Warnings',
'signatureErrors' => 'Signature Errors',
'codingFlaws' => 'Potential Coding Bugs',
'junitTests' => 'Unit Test Coding Problems'
);
my %styleSectionTitles = (
'javadoc' => 'JavaDoc',
'indentation' => 'Indentation Problems',
'whitespace' => 'Whitespace Problems',
'lineLength' => 'Line Length Problems',
'other' => 'Other Style Problems'
);
my %testingSectionTitles = (
'errors' => 'Unit Test Errors',
'failures' => 'Unit Test Failures',
'methodsUncovered' => 'Unexecuted Methods',
'statementsUncovered' => 'Unexecuted Statements',
'conditionsUncovered' => 'Unexecuted Conditions'
);
my %behaviorSectionTitles = (
'errors' => 'Unexpected Exceptions',
'stackOverflowErrors' => 'Infinite Recursion Problems',
'testsTakeTooLong' => 'Infinite Looping Problems',
'failures' => 'Behavior Issues',
'outOfMemoryErrors' => 'Out of Memory Errors'
);
# expandedSection Content-each element in the hashmap is an array of structs
# (expandedMessage)
my %codingSectionExpanded = (
'compilerErrors' => undef,
'compilerWarnings' => undef,
'signatureErrors' => undef,
'codingFlaws' => undef,
'junitTests' => undef
);
my %styleSectionExpanded = (
'javadoc' => undef,
'indentation' => undef,
'whitespace' => undef,
'lineLength' => undef,
'other' => undef
);
my %testingSectionExpanded = (
'errors' => undef,
'failures' => undef,
'methodsUncovered' => undef,
'statementsUncovered' => undef,
'conditionsUncovered' => undef
);
my %behaviorSectionExpanded = (
'errors' => undef,
'stackOverflowErrors' => undef,
'testsTakeTooLong' => undef,
'failures' => undef,
'outOfMemoryErrors' => undef
);
# Temporary hashes to hold structs per file (for compiler errors and warnings)
# or rule (for all others) for expanded section.
# This is a multidimensional hash of the following form:
# 'compilerErrors'---'count'--'file or rule name'--count value
# 'compilerErrors'---'data'--'file or rule name'--array of structs
my %perFileRuleStruct = (
'compilerErrors' => undef,
'compilerWarnings' => undef,
'signatureErrors' => undef,
'codingFlaws' => undef,
'junitTests' => undef,
'javadoc' => undef,
'indentation' => undef,
'whitespace' => undef,
'lineLength' => undef,
'other' => undef,
'errors' => undef,
'failures' => undef,
'methodsUncovered' => undef,
'statementsUncovered' => undef,
'conditionsUncovered' => undef,
'behaviorErrors' => undef,
'stackOverflowErrors' => undef,
'testsTakeTooLong' => undef,
'behaviorFailures' => undef,
'outOfMemoryErrors' => undef
);
#-------------------------------------------------------
# In addition, some local definitions within this script
#-------------------------------------------------------
if ($useJdk11)
{
# $ENV{JAVA_HOME} = '/usr/java/jdk-11';
$ENV{JAVA_HOME} = '/usr/lib/jvm/java-11';
}
Web_CAT::Utilities::initFromConfig($cfg);
if (defined($ENV{JAVA_HOME}))
{
# Make sure selected Java is at the head of the path ...
$ENV{PATH} =
"$ENV{JAVA_HOME}" . $Web_CAT::Utilities::FILE_SEPARATOR . "bin"
. $Web_CAT::Utilities::PATH_SEPARATOR . $ENV{PATH};
}
# overide TMPDIR to keep temp files local
$ENV{TMPDIR} = "${workingDir}/local_tmp";
if (! -d "$ENV{TMPDIR}") { mkdir("$ENV{TMPDIR}"); }
die "ANT_HOME environment variable is not set! (Should come from ANTForPlugins)"
if !defined($ENV{ANT_HOME});
$ENV{PATH} =
"$ENV{ANT_HOME}" . $Web_CAT::Utilities::FILE_SEPARATOR . "bin"
. $Web_CAT::Utilities::PATH_SEPARATOR . $ENV{PATH};
my $ANT = "ant";
my $callAnt = 1;
my $antLogRelative = "ant.log";
my $antLog = "$resultDir/$antLogRelative";
my $scriptLogRelative = "script.log";
my $scriptLog = "$resultDir/$scriptLogRelative";
my $markupPropFile = "$pluginHome/markup.properties";
my $pdfPrintoutRelative = "$pid.pdf";
my $pdfPrintout = "$resultDir/$pdfPrintoutRelative";
my $diagramsRelative = "diagrams";
my $diagrams = "$publicDir/$diagramsRelative";
my $can_proceed = 1;
my $buildFailed = 0;
my $antLogOpen = 0;
my $postProcessingTime = 20;
#-------------------------------------------------------
# In the future, these could be set via parameters set in Web-CAT's
# interface
#-------------------------------------------------------
my $debug = $cfg->getProperty('debug', 0);
my $hintsLimit = $cfg->getProperty('hintsLimit', 3);
my $maxRuleDeduction = $cfg->getProperty('maxRuleDeduction', $maxToolScore);
my $expSectionId = $cfg->getProperty('expSectionId', 0);
my $defaultMaxBeforeCollapsing = 100000;
my $toolDeductionScaleFactor =
$cfg->getProperty('toolDeductionScaleFactor', 1);
my $coverageMetric = $cfg->getProperty('coverageMetric', 0);
my $minCoverageLevel =
$cfg->getProperty('minCoverageLevel', 0.0);
my $coverageGoal =
$cfg->getProperty('coverageGoal', 100.0);
if ($coverageGoal <= 0) { $coverageGoal = 100; }
my $printableCoverageGoal = $coverageGoal;
if ($coverageGoal >= 1) { $coverageGoal /= 100.0; }
my $useXvfb =
$cfg->getProperty('useXvfb', 0);
$useXvfb = ($useXvfb =~ m/^(true|on|yes|y|1)$/i);
if ($useXvfb)
{
$ANT = 'xvfb-run -a -s "-c -screen 0 1280x1024x24" ' . $ANT;
}
my $allStudentTestsMustPass =
$cfg->getProperty('allStudentTestsMustPass', 0);
$allStudentTestsMustPass =
($allStudentTestsMustPass =~ m/^(true|on|yes|y|1)$/i);
my $includeStudentTestsInGrading =
$cfg->getProperty('includeStudentTestsInGrading', 0);
$includeStudentTestsInGrading =
($includeStudentTestsInGrading =~ m/^(true|on|yes|y|1)$/i);
my $studentsMustSubmitTests =
$cfg->getProperty('studentsMustSubmitTests', 0);
$studentsMustSubmitTests =
($studentsMustSubmitTests =~ m/^(true|on|yes|y|1)$/i);
if (!$studentsMustSubmitTests)
{
$allStudentTestsMustPass = 0;
$includeStudentTestsInGrading = 0;
}
my $includeTestSuitesInCoverage =
$cfg->getProperty('includeTestSuitesInCoverage', 0);
$includeTestSuitesInCoverage =
($includeTestSuitesInCoverage =~ m/^(true|on|yes|y|1)$/i);
my $requireSimpleExceptionCoverage =
$cfg->getProperty('requireSimpleExceptionCoverage', 0);
$requireSimpleExceptionCoverage =
($requireSimpleExceptionCoverage =~ m/^(true|on|yes|y|1)$/i);
my $requireSimpleGetterSetterCoverage =
$cfg->getProperty('requireSimpleGetterSetterCoverage', 0);
$requireSimpleGetterSetterCoverage =
($requireSimpleGetterSetterCoverage =~ m/^(true|on|yes|y|1)$/i);
my $junitErrorsHideHints =
$cfg->getProperty('junitErrorsHideHints', 0);
$junitErrorsHideHints =
($junitErrorsHideHints =~ m/^(true|on|yes|y|1)$/i)
&& $studentsMustSubmitTests;
{
# Suppress hints if another plug-in in the pipeline will be handling them
my $hintProcessor = $cfg->getProperty('pipeline.hintProcessor');
if (defined $hintProcessor &&
$hintProcessor ne $cfg->getProperty('pluginName', 'JavaTddPlugin'))
{
$hintsLimit = 0;
}
}
#=============================================================================
# Adjust hints limit, if needed
#=============================================================================
my $extraHintMsg = "";
if ($hintsLimit)
{
my $hideHintsWithin = $cfg->getProperty('hideHintsWithin', 0);
if ($hideHintsWithin > 0)
{
my $daysBeforeDeadline =
($cfg->getProperty('dueDateTimestamp', 0)
- $cfg->getProperty('submissionTimestamp', 0))
/ (1000 * 60 * 60 * 24);
if ($daysBeforeDeadline > 0 && $daysBeforeDeadline < $hideHintsWithin)
{
# Then we're within X days of deadline. Check to see if we're
# within the re-enable window
my $showHintsWithin = $cfg->getProperty('showHintsWithin', 0);
if ($daysBeforeDeadline > $showHintsWithin)
{
$hintsLimit = 0;
my $days = "day";
if ($hideHintsWithin != 1)
{
$days .= "s";
}
$extraHintMsg = "Hints are not available within "
. "$hideHintsWithin $days of the deadline.";
if ($showHintsWithin > 0)
{
$days = "day";
if ($showHintsWithin != 1)
{
$days .= "s";
}
$extraHintMsg .= " Hints will be available again "
. "$showHintsWithin $days before the deadline.";
}
}
}
}
}
#=============================================================================
# Transform simple java file patterns to
#=============================================================================
sub setClassPatternIfNeeded
{
my $inProperty = shift || carp "incoming property name required";
my $outProperty = shift || carp "outgoing property name required";
my $useJavaExtension = shift;
if (!defined $useJavaExtension)
{
$useJavaExtension = 0;
}
my $inExtension = $useJavaExtension ? ".class" : ".java";
my $outExtension = $useJavaExtension ? ".java" : ".class";
my $value = $cfg->getProperty($inProperty);
if (defined $value && $value ne '')
{
my $pattern = undef;
foreach my $include (split(/[,\s]+/, $value))
{
# print "processing class pattern: '$include'\n";
if (defined($include) && $include ne '')
{
if ($include !~ m/^none$/io)
{
$include =~ s,\\,/,go;
if ($include =~ /\./)
{
$include =~ s/\Q$inExtension\E$/$outExtension/i;
}
else
{
$include .= $outExtension;
}
if ($include !~ m,^\*\*/,o)
{
$include = "**/$include";
}
}
if (defined $pattern)
{
$pattern .= " $include";
}
else
{
$pattern = $include;
}
}
# print "new pattern: '$pattern'\n";
}
if (defined $pattern)
{
$cfg->setProperty($outProperty, $pattern);
}
}
}
#=============================================================================
# Turn include/exclude class names into file patterns
#=============================================================================
{
my $cloverIncludes = $cfg->getProperty('clover.includes', '**');
my @files = split(/[,\s]+/, $cloverIncludes);
for (my $i = 0; $i <= $#files; $i++)
{
if ($files[$i] !~ /\*/)
{
$files[$i] = '**/' . $files[$i] . '.*';
}
}
$cloverIncludes = join(' ', @files);
$cfg->setProperty('clover.includes', $cloverIncludes);
}
{
my $cloverExcludes = $cfg->getProperty('clover.excludes', '**');
my @files = split(/[,\s]+/, $cloverExcludes);
for (my $i = 0; $i <= $#files; $i++)
{
if ($files[$i] !~ /\*/)
{
$files[$i] = '**/' . $files[$i] . '.*';
}
}
$cloverExcludes = join(' ', @files);
$cfg->setProperty('clover.excludes', $cloverExcludes);
}
#=============================================================================
# Generate derived properties for ANT
#=============================================================================
# testCases
my $scriptData = $cfg->getProperty('scriptData', '.');
$scriptData =~ s,/$,,;
# testCases (reference test location and/or file name).
# This first var needs to be visible for later pattern matching to remove
# internal path names from student messages.
my $testCasePathPattern;
{
my $testCasePath = "${pluginHome}/tests";
my $testCaseFileOrDir = $cfg->getProperty('testCases');
if (defined $testCaseFileOrDir && $testCaseFileOrDir ne "")
{
my $target = confirmExists($scriptData, $testCaseFileOrDir);
if (-d $target)
{
$cfg->setProperty('testCasePath', $target);
}
else
{
$cfg->setProperty('testCasePath', dirname($target));
$cfg->setProperty('testCasePattern', basename($target));
$cfg->setProperty('justOneTestClass', 'true');
}
$testCasePath = $target;
}
$testCasePathPattern = filePattern($testCasePath);
}
# Set up other test case filtering patterns
setClassPatternIfNeeded('refTestInclude', 'refTestClassPattern');
setClassPatternIfNeeded('refTestExclude', 'refTestClassExclusionPattern');
setClassPatternIfNeeded('studentTestInclude', 'studentTestClassPattern');
setClassPatternIfNeeded('studentTestExclude',
'studentTestClassExclusionPattern');
setClassPatternIfNeeded('staticAnalysisInclude', 'staticAnalysisSrcPattern', 1);
setClassPatternIfNeeded('staticAnalysisExclude',
'staticAnalysisSrcExclusionPattern', 1);
setClassPatternIfNeeded('staticAnalysisExclude',
'instrumentExclusionPattern');
# useDefaultJar
{
my $useDefaultJar = $cfg->getProperty('useDefaultJar');
if (defined $useDefaultJar && $useDefaultJar =~ /false|\b0\b/i)
{
$cfg->setProperty('defaultJars', "$pluginHome/empty");
}
}
# assignmentJar
{
my $jarFileOrDir = $cfg->getProperty('assignmentJar');
if (defined $jarFileOrDir && $jarFileOrDir ne "")
{
my $path = confirmExists($scriptData, $jarFileOrDir);
$cfg->setProperty('assignmentClassFiles', $path);
if (-d $path)
{
$cfg->setProperty('assignmentClassDir', $path);
}
}
}
# classpathJar
{
my $jarFileOrDir = $cfg->getProperty('classpathJar');
if (defined $jarFileOrDir && $jarFileOrDir ne "")
{
my $path = confirmExists($scriptData, $jarFileOrDir);
$cfg->setProperty('instructorClassFiles', $path);
if (-d $path)
{
$cfg->setProperty('instructorClassDir', $path);
}
}
}
# useAssertions
{
my $useAssertions = $cfg->getProperty('useAssertions');
if (defined $useAssertions && $useAssertions !~ m/^(true|yes|1|on)$/i)
{
$cfg->setProperty('enableAssertions', '-da');
}
}
# checkstyleConfig
{
my $checkstyle = $cfg->getProperty('checkstyleConfig');
if (defined $checkstyle && $checkstyle ne "")
{
$cfg->setProperty(
'checkstyleConfigFile', confirmExists($scriptData, $checkstyle));
}
}
# pmdConfig
{
my $pmd = $cfg->getProperty('pmdConfig');
if (defined $pmd && $pmd ne "")
{
$cfg->setProperty(
'pmdConfigFile', confirmExists($scriptData, $pmd));
}
}
# policyFile
{
my $policy = $cfg->getProperty('policyFile');
if (defined $policy && $policy ne "")
{
$cfg->setProperty(
'javaPolicyFile', confirmExists($scriptData, $policy));
}
}
# security.manager
{
if ($debug >= 5)
{
$cfg->setProperty(
'security.manager',
'java.security.manager=net.sf.webcat.plugins.javatddplugin.'
. 'ProfilingSecurityManager');
}
}
# markupProperties
{
my $markup = $cfg->getProperty('markupProperties');
if (defined $markup && $markup ne "")
{
$markupPropFile = confirmExists($scriptData, $markup);
}
}
# wantPDF
{
my $p = $cfg->getProperty('wantPDF');
if (defined $p && $p !~ /false/i)
{
$cfg->setProperty('generatePDF', '1');
$cfg->setProperty('PDF.dest', $pdfPrintout);
}
}
# timeout
my $timeoutForOneRun = $cfg->getProperty('timeoutForOneRun', 30);
$cfg->setProperty('exec.timeout', $timeoutForOneRun * 1000);
$cfg->save();
#=============================================================================
# Script Startup
#=============================================================================
# Change to specified working directory and set up log directory
chdir($workingDir);
# try to deduce whether or not there is an extra level of subdirs
# around this assignment
{
# Get a listing of all file/dir names, including those starting with
# dot, then strip out . and ..
my @dirContents = grep(!/^(\.{1,2}|META-INF|__MACOSX)$/,
(bsd_glob("*"), bsd_glob(".*")));
# if this list contains only one entry that is a dir name != src, then
# assume that the submission has been "wrapped" with an outter
# dir that isn't actually part of the project structure.
if ($#dirContents == 0 && -d $dirContents[0] && $dirContents[0] ne "src")
{
# Strip non-alphanumeric symbols from dir name
my $dir = $dirContents[0];
if ($dir =~ s/[^a-zA-Z0-9_]//g)
{
if ($dir eq "")
{
$dir = "dir";
}
rename($dirContents[0], $dir);
}
$workingDir .= "/$dir";
chdir($workingDir);
}
}
# Screen out any temporary files left around by BlueJ
{
my @javaSrcs = < __SHELL*.java >;
foreach my $tempFile (@javaSrcs)
{
unlink($tempFile);
}
}
if ($debug)
{
print "working dir set to $workingDir\n";
print "JAVA_HOME = ", $ENV{JAVA_HOME}, "\n";
print "ANT_HOME = ", $ENV{ANT_HOME}, "\n";
print "PATH = ", $ENV{PATH}, "\n\n";
}
# localFiles
{
my $localFiles = $cfg->getProperty('localFiles');
if (defined $localFiles && $localFiles ne "")
{
my $lf = confirmExists($scriptData, $localFiles);
print "localFiles = $lf\n" if $debug;
mkdir($resultDir . "/studentbin.raw");
if (-d $lf)
{
print "localFiles is a directory\n" if $debug;
copyHere($lf, $lf);
copyHere($lf, $lf, \@beautifierIgnoreFiles,
$resultDir . "/studentbin.raw");
}
else
{
print "localFiles is a single file\n" if $debug;
$lf =~ tr/\\/\//;
my $base = $lf;
$base =~ s,/[^/]*$,,;
copyHere($lf, $base);
copyHere($lf, $base, \@beautifierIgnoreFiles,
$resultDir . "/studentbin.raw");
}
}
}
#=============================================================================
# Run the ANT build file to get all the results
#=============================================================================
my $time1 = time;
#my $studentResults = new Web_CAT::JUnitResultsReader();
#my $instructorResults = new Web_CAT::JUnitResultsReader();
#my $testsRun = 0; #0
#my $testsFailed = 0;
#my $testsErrored = 0;
#my $testsPassed = 0;
if ($callAnt)
{
# $ANT .= " -listener net.sf.antcontrib.perf.AntPerformanceListener";
if ($debug > 2)
{
$ANT .= " -d -v";
if ($debug > 5)
{
$ANT .= " -logger org.apache.tools.ant.listener.ProfileLogger";
}
}
my $cmdline = $Web_CAT::Utilities::SHELL
. "$ANT -f \"$pluginHome/build.xml\" -l \"$antLog\" "
. "-propertyfile \"$propfile\" \"-Dbasedir=$workingDir\" "
. "2>&1 > " . File::Spec->devnull;
print $cmdline, "\n" if ($debug);
my ($exitcode, $timeout_status) = Proc::Background::timeout_system(
$timeout - $postProcessingTime, $cmdline);
if ($timeout_status)
{
# Mark Behavior Section-tests taking too long
$behaviorSectionStatus{'testsTakeTooLong'} = 0;
$can_proceed = 0;
$status{'antTimeout'} = 1;
$buildFailed = 1;
# FIXME: Move to end of $status{'feedback'} ...
$status{'feedback'}->startFeedbackSection(
"Errors During Testing", ++$expSectionId);
$status{'feedback'}->print(<<EOF);
<p><b class="warn">Testing your solution exceeded the allowable time
limit for this assignment.</b></p>
<p>Most frequently, this is the result of <b>infinite recursion</b>--when
a recursive method fails to stop calling itself--or <b>infinite
looping</b>--when a while loop or for loop fails to stop repeating.
</p>
<p>
As a result, no time remained for further analysis of your code.</p>
EOF
$status{'feedback'}->endFeedbackSection;
}
}
my $time2 = time;
if ($debug)
{
print "\n", ($time2 - $time1), " seconds\n";
}
my $time3 = time;
#=============================================================================
# check for compiler error (or warnings)
# report only the first file causing errors
#=============================================================================
#-----------------------------------------------
# Generate a script warning
sub adminLog
{
open(SCRIPTLOG, ">>$scriptLog") ||
die "Cannot open file for output '$scriptLog': $!";
print SCRIPTLOG join("\n", @_), "\n";
close(SCRIPTLOG);
}
my $cannotFindSymbolStruct;
# generate compilerError and compilerWarning Structs.
# We pick only the first occurring error or warning in a file.
sub generateCompilerErrorWarningStruct
{
my $messageString = shift;
my $key = shift;
my $splitString;
my $errorStruct;
if (index(lc($key), 'error') != -1)
{
$splitString = 'error:';
}
else
{
$splitString = 'warning:';
}
my @messageContents = split($splitString, $messageString);
my @fileDetails = split(':', $messageContents[0]);
#trim the message
$messageContents[1] =~ s/^\s+|\s+$//g;
my $fileName = $fileDetails[0];
$fileName =~ s,\\,/,go;
my $lineNum = $fileDetails[1];
my $codeLines = extractAboveBelowLinesOfCode($fileName, $lineNum);
$fileName =~ s,^.*\Q$workingDir/\E,,i;
# For compiler warning we dont have enhanced messages
# For "cannot find symbol" errors, "addCannotFindSymbolStruct" computes
# the enhaced message
if ($splitString eq 'warning:'
|| $messageContents[1] eq 'cannot find symbol')
{
$errorStruct = expandedMessage->new(
entityName => $fileName,
lineNum => $lineNum,
errorMessage => $messageContents[1],
linesOfCode => $codeLines,
enhancedMessage => '',
);
}
else
{
$errorStruct = expandedMessage->new(
entityName => $fileName,
lineNum => $lineNum,
errorMessage => $messageContents[1],
linesOfCode => $codeLines,
enhancedMessage =>
compilerErrorEnhancedMessage($messageContents[1]),
);
}
# If the struct contains only "cannot find symbol" then we look for the
# next line in the ant.log to obtain symbol name and add the struct later
if ($errorStruct->errorMessage eq 'cannot find symbol')
{
$cannotFindSymbolStruct = $errorStruct;
return;
}
if (defined $perFileRuleStruct{$key}{'data'}{$fileName})
{
$perFileRuleStruct{$key}{'count'}{$fileName}++;
}
else
{
$perFileRuleStruct{$key}{'data'}{$fileName} = $errorStruct;
$perFileRuleStruct{$key}{'count'}{$fileName} = 1;
}
}
sub addCannotFindSymbolStruct
{
if (not defined $cannotFindSymbolStruct)
{
return;
}