forked from wala/WALA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
202 lines (168 loc) · 6.78 KB
/
build.gradle.kts
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
////////////////////////////////////////////////////////////////////////
//
// plugin configuration must precede everything else
//
import com.diffplug.gradle.pde.EclipseRelease
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
buildscript { dependencies.classpath(libs.commons.io) }
plugins {
idea
java
alias(libs.plugins.file.lister)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.shellcheck)
alias(libs.plugins.task.tree)
alias(libs.plugins.versions)
id("com.ibm.wala.gradle.javadoc")
id("com.ibm.wala.gradle.eclipse-maven-central")
id("com.ibm.wala.gradle.maven-eclipse-jsdt")
id("com.ibm.wala.gradle.project")
}
repositories {
// to get the google-java-format jar and dependencies
mavenCentral()
}
val osName: String by extra(System.getProperty("os.name"))
val archName: String by extra(System.getProperty("os.arch"))
val isWindows by extra(osName.startsWith("Windows "))
JavaVersion.current().let {
if (!it.isJava11Compatible) {
logger.error(
"Gradle is running on a Java $it JVM, which is not compatible with Java 11. Build failures are likely. For advice on changing JVMs, visit <https://docs.gradle.org/current/userguide/build_environment.html> and look for discussion of the `org.gradle.java.home` Gradle property or the `JAVA_HOME` environment variable.")
}
}
////////////////////////////////////////////////////////////////////////
//
// common Java setup shared by multiple projects
//
group = name
version = property("VERSION_NAME") as String
// version of Eclipse JARs to use for Eclipse-integrated WALA components.
val eclipseVersion: EclipseRelease by extra {
EclipseRelease.official(libs.versions.eclipse.asProvider().get())
}
///////////////////////////////////////////////////////////////////////
//
// Javadoc documentation
//
val aggregatedJavadocClasspath: Configuration by configurations.creating { isCanBeConsumed = false }
val aggregatedJavadocSource: Configuration by configurations.creating { isCanBeConsumed = false }
dependencies {
subprojects {
pluginManager.withPlugin("java-base") {
aggregatedJavadocClasspath(
project(mapOf("path" to path, "configuration" to "javadocClasspath")))
aggregatedJavadocSource(project(mapOf("path" to path, "configuration" to "javadocSource")))
}
}
}
tasks.register<Javadoc>("aggregatedJavadocs") {
description = "Generate javadocs from all child projects as if they were a single project"
group = "Documentation"
setDestinationDir(layout.buildDirectory.dir("docs/javadoc").get().asFile)
title = "${project.name} $version API"
(options as StandardJavadocDocletOptions).author(true)
classpath = aggregatedJavadocClasspath
source(aggregatedJavadocSource)
}
////////////////////////////////////////////////////////////////////////
//
// linters for various specific languages or file formats
//
// shell scripts, provided they have ".sh" extension
shellcheck {
isUseDocker = false
shellcheckBinary = "shellcheck"
sourceFiles =
fileTree(".") {
exclude("**/build")
include("**/*.sh")
}
}
tasks.named("shellcheck") { group = "verification" }
// install Java reformatter as git pre-commit hook
tasks.register<Copy>("installGitHooks") {
from("config/hooks/pre-commit-stub")
rename { "pre-commit" }
into(".git/hooks")
fileMode = 0b111_111_111
}
listOf("check", "spotlessCheck", "spotlessApply").forEach {
tasks.named(it) { dependsOn(gradle.includedBuild("build-logic").task(":$it")) }
}
////////////////////////////////////////////////////////////////////////
//
// Run IntelliJ IDEA inspections on entire project tree
//
// We don"t make `check` depend on `checkInspectionResults` for two
// reasons. First, `runInspections` is quite slow. Second,
// `runInspections` cannot run while the same user account is running a
// regular, graphical instance of IntelliJ IDEA. These limitations
// make `runInspections` and `checkInspectionResults` more suitable for
// use in CI/CD pipelines than for daily use by live WALA developers.
//
val runInspections by
tasks.registering(Exec::class) {
group = "intellij-idea"
description = "Run all enabled IntelliJ IDEA inspections on the entire WALA project"
val ideaDir = file("$rootDir/.idea")
inputs.dir("$ideaDir/scopes")
val inspectionProfile = file("$ideaDir/inspectionProfiles/No_Back_Sliding.xml")
inputs.file(inspectionProfile)
val textResultsFile = layout.buildDirectory.file("$name.txt").get().asFile
outputs.file(textResultsFile)
// Inspections examine a wide variety of files, not just Java
// sources, so this task is out-of-date if nearly any other file has
// changed.
inputs.files(fileLister.obtainPartialFileTree())
executable = findProperty("runInspections.IntelliJ-IDEA.command") as String? ?: "idea"
args("inspect", rootDir, inspectionProfile, textResultsFile, "-v1", "-format", "plain")
// The `idea` command above always fails with an
// `IllegalArgumentException` arising from
// `PlainTextFormatter.getPath`. Fortunately, this only happens
// *after* `idea` has already written out the results file. So we
// should ignore that command"s exit value, and only fail this task
// if the results file is missing.
isIgnoreExitValue = true
doLast {
if (!textResultsFile.exists()) {
throw GradleException("IntelliJ IDEA command failed without creating $textResultsFile.")
}
}
}
tasks.register("checkInspectionResults") {
group = "intellij-idea"
description = "Fail if any IntelliJ IDEA inspections produced errors or warnings"
inputs.files(runInspections)
doFirst {
var failed = false
val problemPattern = "\\[(ERROR|WARNING)]".toRegex()
inputs.files.singleFile.forEachLine {
if (problemPattern.matches(it)) {
failed = true
println(it)
}
}
if (failed) {
throw GradleException(
"One or more IntelliJ IDEA inspections failed. See logged problems above, or \"${inputs.files.singleFile}\" for full details. WEAK WARNINGs are allowed, but all ERRORs and WARNINGs must be corrected.")
}
}
val stampFile = layout.buildDirectory.file("$name.stamp")
outputs.file(stampFile)
doLast { stampFile.get().asFile.createNewFile() }
}
////////////////////////////////////////////////////////////////////////
//
// Check for updated dependencies
//
tasks.withType<DependencyUpdatesTask>().configureEach {
gradleReleaseChannel = "current"
rejectVersionIf {
candidate.run {
// Apache Commons IO snapshot releases have timestamped versions like `20030203.000550`. We
// don't want these. We only want stable releases, which have versions like `2.11.0`.
group == "commons-io" && module == "commons-io" && version.matches("\\d+\\.\\d+".toRegex())
}
}
}