-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathbuild.gradle
353 lines (290 loc) · 12 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
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
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
plugins {
id 'application'
id 'checkstyle'
id 'idea'
id 'jacoco'
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.liferay.node' version '7.2.18'
id 'com.github.psxpaul.execfork' version '0.2.0'
id 'com.palantir.git-version' version '0.13.0'
}
OperatingSystem os = DefaultNativePlatform.currentOperatingSystem;
mainClassName = 'reposense.RepoSense'
node.download = false // The Liferay Node Gradle Plugin will use the system PATH to find the Node/npm executable.
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
configurations {
systemtestImplementation.extendsFrom testImplementation
systemtestRuntime.extendsFrom testRuntime
}
dependencies {
String jUnitVersion = '5.8.2'
implementation group: 'com.google.code.gson' ,name: 'gson', version:'2.9.0'
implementation group: 'net.freeutils', name: 'jlhttp', version: '2.6'
implementation group: 'net.sourceforge.argparse4j', name: 'argparse4j', version: '0.9.0'
implementation group: 'org.apache.ant', name: 'ant', version: '1.10.12'
implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.9.0'
implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.17.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}
sourceSets {
systemtest {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
java.srcDir file('src/systemtest/java')
resources.srcDir file('src/systemtest/resources')
}
}
def installFrontend = tasks.register('installFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Installs frontend dependencies using npm ci to ensure reproducible builds.'
workingDir 'frontend/'
args = ['ci']
}
def buildFrontend = tasks.register('buildFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Builds the frontend assets for production using npm run devbuild.'
dependsOn installFrontend
workingDir 'frontend/'
args = ['run', 'devbuild']
}
def zipReport = tasks.register('zipReport', Zip) {
description 'Bundles the compiled frontend assets into a ZIP archive for inclusion in the backend resources.'
dependsOn buildFrontend
from 'frontend/build/'
archiveBaseName = 'templateZip'
destinationDirectory = file('src/main/resources')
}
def copyCypressConfig = tasks.register('copyCypressConfig', Copy) {
description 'Copies the config files used by the backend to generate the test report for Cypress testing into an isolated working directory'
from 'frontend/cypress/config'
into 'build/serveTestReport/exampleconfig'
}
def copyMainClasses = tasks.register('copyMainClasses', Copy) {
description 'Copies the backend classes used to generate the test report for Cypress testing into an isolated working directory'
dependsOn classes
from 'build/classes/java/main'
into 'build/serveTestReport/java/main'
}
def compileJava = tasks.compileJava
tasks.named("processSystemtestResources").configure {
description 'Processes system test resources, allowing duplicate files to be included.'
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.run.dependsOn(zipReport);
run {
//the second arguments indicates the default value associated with the property.
description 'Executes RepoSense with specified command-line arguments after building the frontend and packaging resources.'
tasks.compileJava.mustRunAfter(zipReport)
args System.getProperty('args', '').split()
systemProperty "version", getRepoSenseVersion()
}
checkstyle {
toolVersion = '9.3'
getConfigDirectory().set(file("$rootProject.projectDir/config/checkstyle"))
}
idea {
module {
sourceSets.systemtest.allSource.srcDirs.each { srcDir -> module.testSourceDirs += srcDir }
}
}
test {
description 'Runs unit tests with JUnit Jupiter, ensuring individual components function as expected.'
environment("REPOSENSE_ENVIRONMENT", "TEST")
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = true
}
doFirst {
deleteReposAddressDirectory()
}
useJUnitPlatform()
doLast {
deleteReposAddressDirectory()
}
}
tasks.shadowJar.dependsOn(zipReport);
shadowJar {
description 'Assembles a fat JAR including all dependencies and frontend assets for distribution.'
tasks.compileJava.mustRunAfter(zipReport)
tasks.processResources.mustRunAfter(zipReport)
archiveFileName = 'RepoSense.jar'
destinationDirectory = file("${buildDir}/jar/")
manifest {
attributes 'Implementation-Version': getRepoSenseVersion()
}
}
tasks.register('lintFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Analyzes frontend code with ESLint to enforce coding standards and identify potential issues.'
dependsOn installFrontend
workingDir 'frontend/'
args = ['run', 'lint']
}
def checkstyleMain = tasks.checkstyleMain {
description 'Applies Checkstyle code style checks to the main Java source code.'
}
def checkstyleTest = tasks.checkstyleTest {
description 'Applies Checkstyle code style checks to the test Java source code.'
}
def checkstyleSystemtest = tasks.checkstyleSystemtest {
description 'Applies Checkstyle code style checks to the system test Java source code.'
}
tasks.register('checkstyleAll', Checkstyle) {
description 'Aggregates all Checkstyle checks (main, test, systemtest) into a single task for convenience.'
dependsOn checkstyleMain, checkstyleTest, checkstyleSystemtest
tasks.checkstyleTest.mustRunAfter('checkstyleMain')
tasks.checkstyleSystemtest.mustRunAfter('checkstyleTest')
}
tasks.register('environmentalChecks', Exec) {
description 'Runs OS-specific environment checks to ensure compatibility with RepoSense build processes.'
workingDir 'config/checks/'
if (os.isWindows()){
commandLine 'cmd', '/c', 'run-checks.bat'
} else {
commandLine 'sh', './run-checks.sh'
}
}
tasks.register('systemtest', Test) {
description 'Executes system tests to validate end-to-end functionality and integration scenarios.'
testClassesDirs = sourceSets.systemtest.output.classesDirs
classpath = sourceSets.systemtest.runtimeClasspath
environment("REPOSENSE_ENVIRONMENT", "TEST")
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = true
}
doFirst {
deleteReposAddressDirectory()
}
useJUnitPlatform()
doLast {
deleteReposAddressDirectory()
}
}
def serveTestReportInBackground = tasks.register('serveTestReportInBackground', com.github.psxpaul.task.JavaExecFork) {
description 'Creates a background server process for the test report that is to be used by Cypress'
dependsOn zipReport, compileJava, processResources, copyCypressConfig, copyMainClasses
tasks.compileJava.mustRunAfter(zipReport)
tasks.processResources.mustRunAfter(zipReport)
workingDir = 'build/serveTestReport'
main = mainClassName
classpath = sourceSets.main.runtimeClasspath
args = ['--config', './exampleconfig', '--since', 'd1', '--view', '-A', '-t', 'UTC']
String versionJvmArgs = '-Dversion=' + getRepoSenseVersion()
jvmArgs = [ versionJvmArgs ]
waitForPort = 9000
}
def installCypress = tasks.register('installCypress', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Installs Cypress and its dependencies for frontend testing using npm ci.'
workingDir 'frontend/cypress/'
args = ['ci']
}
tasks.register('cypress', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Runs Cypress tests in debug mode for interactive troubleshooting and test development.'
dependsOn installCypress, serveTestReportInBackground
tasks.serveTestReportInBackground.mustRunAfter(installCypress)
workingDir = file('frontend/cypress/')
args = ["run-script", "debug"]
}
tasks.register('frontendTest', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) {
description 'Executes Cypress end-to-end tests; runs in headless CI mode if the "ci" property is specified.'
dependsOn installCypress, serveTestReportInBackground
tasks.serveTestReportInBackground.mustRunAfter(installCypress)
workingDir = file('frontend/cypress/')
args = ["run-script", "tests"]
// Run tests in CI without slow motion
if (project.hasProperty('ci')) {
args = ["run-script", "ci"]
}
}
tasks.withType(Copy) {
includeEmptyDirs = true
}
jacoco {
toolVersion = "0.8.7"
}
jacocoTestReport {
reports {
html.required = true
xml.required = true
csv.required = false
html.destination file("${buildDir}/jacocoHtml")
}
executionData systemtest, frontendTest
}
tasks.register('coverage', JacocoReport) {
description 'Consolidates coverage data from unit, system, and frontend tests into a comprehensive report.'
}
coverage.configure {
sourceDirectories.from files(sourceSets.main.allSource.srcDirs)
classDirectories.from files(sourceSets.main.output)
executionData.from files(jacocoTestReport.executionData)
afterEvaluate {
classDirectories.from files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/*.jar'])
})
}
reports {
html.required = true
xml.required = true
}
}
String getRepoSenseVersion() {
String repoSenseVersion = project.property("version")
if (repoSenseVersion.equals("unspecified")) {
repoSenseVersion = versionDetails().commitDistance == 0 ? versionDetails().lastTag : versionDetails().gitHash
}
return repoSenseVersion
}
def syncFrontendPublic = tasks.register('syncFrontendPublic', Sync) {
description 'Synchronizes generated report JSON files into the frontend public directory for development access.'
from 'reposense-report'
into 'frontend/public/'
include '**/*.json'
includeEmptyDirs = false
preserve {
include 'index.html'
include 'favicon.ico'
include 'title.md'
}
}
def macHotReloadFrontend = tasks.register('macHotReloadFrontend', Exec) {
description 'Starts the frontend development server with hot-reloading capabilities on macOS.'
dependsOn installFrontend
onlyIf {os.isMacOsX()}
workingDir 'frontend/'
commandLine 'npm', 'run', 'serveOpen'
}
def windowsHotReloadFrontend = tasks.register('windowsHotReloadFrontend', Exec) {
description 'Starts the frontend development server with hot-reloading capabilities on Windows.'
dependsOn installFrontend
onlyIf {os.isWindows()}
workingDir 'frontend/'
commandLine 'cmd','/c', 'START', '"hotreload RepoSense frontend"', 'npm', 'run', 'serveOpen'
}
def linuxHotReloadFrontend = tasks.register('linuxHotReloadFrontend', Exec) {
description 'Starts the frontend development server with hot-reloading capabilities on Linux.'
dependsOn installFrontend
onlyIf {os.isLinux()}
workingDir 'frontend/'
commandLine 'npm', 'run', 'serveOpen'
}
tasks.register('hotReloadFrontend') {
description 'Orchestrates frontend hot-reloading by syncing reports and starting the dev server based on the OS.'
dependsOn syncFrontendPublic
finalizedBy windowsHotReloadFrontend
finalizedBy macHotReloadFrontend
finalizedBy linuxHotReloadFrontend
}
// End of hot reload Tasks
void deleteReposAddressDirectory() {
final String REPOS_ADDRESS = "repos"
def reposDirectory = new File(REPOS_ADDRESS)
reposDirectory.deleteDir()
}
defaultTasks 'clean', 'build', 'systemtest', 'frontendTest', 'coverage'