forked from sweng-epfl/code-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
115 lines (98 loc) · 3.95 KB
/
build.gradle
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
// !!!!!!!!!!!!!!!!!!!!!!
// DO NOT TOUCH THIS FILE
// !!!!!!!!!!!!!!!!!!!!!!
// This file is an extensible Gradle build file for EPFL's Software Engineering course,
// designed to allow students to easily build and test their code from the command-line,
// and to allow the staff to automatically test code including coverage.
// The main tasks to use are 'build' (includes tests + coverage) and 'run'.
import org.gradle.api.JavaVersion
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.nio.file.Files
plugins {
id 'java'
id 'application'
id 'jacoco'
}
repositories {
mavenCentral()
}
dependencies {
// JUnit 5 "Jupiter"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
// Hamcrest
testImplementation 'org.hamcrest:hamcrest-library:2.2'
}
def javaVersionTarget = "17"
if (JavaVersion.current().toString() != javaVersionTarget) {
println '!!!\n!!!'
println "WARNING: This project was designed for Java ${javaVersionTarget} but you are instead using Java ${JavaVersion.current()}."
println ' If you get this message while configuring an IDE such as IntelliJ or Android Studio, feel free to ignore it as long as it does not appear when running the app or tests.'
println " Otherwise, please use Java ${javaVersionTarget}, or continue using your version at your own risk."
println '!!!\n!!!'
}
application {
mainClass = 'App'
}
run {
// Force UTF-8
systemProperty "file.encoding", "UTF-8"
// Allow users to input stuff during the 'run' task, necessary for System.in to work
standardInput = System.in
}
test {
useJUnitPlatform()
// Force UTF-8
systemProperty 'file.encoding', 'UTF-8'
testLogging {
// Always show all tests, even passed ones; also, show stdout/stderr, helps for debugging
events TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
// Always run all tests
outputs.upToDateWhen { false }
// Show detailed information about failures
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
// If a crash happens during execution, tell the user about it
afterSuite { desc, result ->
if (result.exception) {
if (result.exception.message.contains('Could not complete execution')) {
println('A crash happened while executing unit tests:')
result.exception.cause.printStackTrace()
} else {
println('An unknown error occurred while executing unit tests:')
result.exception.printStackTrace()
}
}
}
}
jacocoTestReport {
// XML report, for scripts
reports.xml.required = true
// HTML report, for humans
reports.html.destination = file("${buildDir}/reports/coverage")
}
build {
// Always generate coverage
dependsOn jacocoTestReport
// Add some help to JaCoCo reports
doLast {
def msg = '''SwEng help:
<ul>
<li>JaCoCo calls statements "instructions"</li>
<li>JaCoCo does not compute path coverage, because it is usually not helpful in real code</li>
<li>The column 'Cxty' is the <a target="_blank" href="https://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity</a></li>
</ul>'''
fileTree("${buildDir}/reports/coverage").include('**/*.html').each { f ->
Files.writeString(f.toPath(), Files.readString(f.toPath()).replace('</h1>', "</h1><p>${msg}</p>"))
}
}
// Tell the user about the report file
doLast {
println "You can view the code coverage report in ${buildDir}/reports/coverage/index.html"
}
}