-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.gradle.kts
306 lines (277 loc) · 10.3 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
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
import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort
import com.github.spotbugs.snom.SpotBugsTask
import kotlinx.serialization.serializer
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.errorprone
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.openstreetmap.josm.gradle.plugin.task.MarkdownToHtml
import java.net.URL
import kotlin.reflect.full.starProjectedType
plugins {
id("application")
id("com.diffplug.spotless") version "6.25.0"
id("com.github.ben-manes.versions") version "0.51.0"
id("com.github.spotbugs") version "6.0.17"
id("net.ltgt.errorprone") version "3.1.0"
id("org.openstreetmap.josm") version "0.8.2"
id("org.sonarqube") version "4.3.0.3225"
//id("org.checkerframework") version "0.6.14"
eclipse
jacoco
java
`maven-publish`
pmd
}
repositories {
mavenCentral()
}
// Set up ErrorProne
tasks.withType(JavaCompile::class).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-serial"))
options.errorprone {
check("ClassCanBeStatic", CheckSeverity.ERROR)
check("ConstantField", CheckSeverity.WARN)
check("DefaultCharset", CheckSeverity.ERROR)
check("FieldCanBeFinal", CheckSeverity.WARN)
check("Finally", CheckSeverity.OFF)
check("LambdaFunctionalInterface", CheckSeverity.WARN)
check("MethodCanBeStatic", CheckSeverity.WARN)
check("MultiVariableDeclaration", CheckSeverity.WARN)
check("PrivateConstructorForUtilityClass", CheckSeverity.WARN)
check("RemoveUnusedImports", CheckSeverity.WARN)
check("ReferenceEquality", CheckSeverity.ERROR)
check("UngroupedOverloads", CheckSeverity.WARN)
check("UnnecessaryLambda", CheckSeverity.OFF)
check("WildcardImport", CheckSeverity.ERROR)
}
}
java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
val versions = mapOf(
"awaitility" to "4.2.1",
"errorprone" to "2.28.0",
"jdatepicker" to "1.3.4",
"jmockit" to "1.49",
"junit" to "5.10.2",
"pmd" to "6.42.0",
"spotbugs" to "4.8.6",
"wiremock" to "3.6.0"
)
dependencies {
errorprone("com.google.errorprone:error_prone_core:${versions["errorprone"]}")
testImplementation ("org.openstreetmap.josm:josm-unittest:SNAPSHOT"){ isChanging = true }
testImplementation("org.wiremock:wiremock:${versions["wiremock"]}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${versions["junit"]}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions["junit"]}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${versions["junit"]}")
// This can be removed once JOSM drops all JUnit4 support. Nothing remaining in Mapillary uses JUnit4.
testImplementation("org.junit.vintage:junit-vintage-engine:${versions["junit"]}")
testImplementation("org.awaitility:awaitility:${versions["awaitility"]}")
testImplementation("org.jmockit:jmockit:${versions["jmockit"]}")
testImplementation("com.github.spotbugs:spotbugs-annotations:${versions["spotbugs"]}")
implementation("org.jdatepicker:jdatepicker:${versions["jdatepicker"]}")
packIntoJar("org.jdatepicker:jdatepicker:${versions["jdatepicker"]}")
}
sourceSets {
test {
java {
setSrcDirs(listOf("test/unit"))
}
resources {
setSrcDirs(listOf("test/data"))
}
}
}
val md2html by tasks.registering(MarkdownToHtml::class) {
destDir = File(buildDir, "md2html")
source(projectDir)
include("README.md", "LICENSE.md")
}
tasks {
processResources {
from(project.projectDir) {
include("LICENSE")
include("LICENSE_*")
}
from(md2html)
}
}
/**
* Get a specific property, either from gradle or from the environment
*/
fun getProperty(key: String): Any? {
if (hasProperty(key)) {
return findProperty(key)
}
return System.getenv(key)
}
tasks.register("generateApiKeyFile") {
val apiKeyFileDir = "$buildDir/resources/main"
val apiKeyFileName = "mapillary_api_keys.json"
doLast {
val jsonEncoder = kotlinx.serialization.json.Json { encodeDefaults = true }
file(apiKeyFileDir).mkdirs()
val environmentToMap = mutableMapOf<String, kotlinx.serialization.json.JsonElement>()
for (environment in listOf("MAPILLARY_CLIENT_TOKEN", "MAPILLARY_CLIENT_SECRET", "MAPILLARY_CLIENT_ID")) {
if (getProperty(environment) != null) {
val prop = getProperty(environment)
environmentToMap[environment] = jsonEncoder.encodeToJsonElement(serializer(prop!!::class.starProjectedType), prop)
} else {
logger.warn("$environment not set in environment. Some functionality may not work.")
}
}
//val apiJson = StringBuilder().append("{")
//apiJson.append("}")
file("$apiKeyFileDir/$apiKeyFileName").writeText(kotlinx.serialization.json.JsonObject(environmentToMap).toString())
}
}
if (getProperty("MAPILLARY_CLIENT_TOKEN") != null) {
tasks["processResources"].dependsOn("generateApiKeyFile")
tasks["assemble"].dependsOn("generateApiKeyFile")
} else {
logger.warn("MAPILLARY_CLIENT_TOKEN not set in the environment. Build only usable for tests.")
}
spotless {
format("misc") {
target("**/*.gradle", "**.*.md", "**/.gitignore")
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
java {
eclipse().configFile("config/format/code_format.xml")
endWithNewline()
importOrder("java", "javax", "")
indentWithSpaces(4)
licenseHeader("// License: GPL. For details, see LICENSE file.")
// Avoid large formatting commits.
ratchetFrom("origin/master")
removeUnusedImports()
trimTrailingWhitespace()
}
}
josm {
pluginName = "Mapillary"
debugPort = 7051
manifest {
// See https://floscher.gitlab.io/gradle-josm-plugin/kdoc/latest/gradle-josm-plugin/org.openstreetmap.josm.gradle.plugin.config/-josm-manifest/old-version-download-link.html
oldVersionDownloadLink(18613, "2.1.5", URL("https://github.com/JOSM/Mapillary/releases/download/v2.1.5/Mapillary.jar"));
oldVersionDownloadLink(18531, "v2.0.2", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.2/Mapillary.jar"));
oldVersionDownloadLink(17903, "v2.0.0-alpha.36", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.0-alpha.36/Mapillary.jar"))
}
i18n {
pathTransformer = getPathTransformer(project.projectDir, "gitlab.com/JOSM/plugin/Mapillary/blob")
}
}
eclipse {
project {
name = "JOSM-Mapillary"
comment = josm.manifest.description
natures("org.sonarlint.eclipse.core.sonarlintNature", "ch.acanda.eclipse.pmd.builder.PMDNature", "org.eclipse.buildship.core.gradleprojectnature")
buildCommand("org.sonarlint.eclipse.core.sonarlintBuilder")
buildCommand("ch.acanda.eclipse.pmd.builder.PMDBuilder")
buildCommand("org.eclipse.buildship.core.gradleprojectbuilder")
}
}
tasks["eclipseClasspath"].dependsOn("cleanEclipseClasspath")
tasks["eclipseProject"].dependsOn("cleanEclipseProject")
tasks["eclipse"].setDependsOn(setOf("eclipseClasspath", "eclipseProject"))
tasks.withType(JavaCompile::class) {
// Character encoding of Java files
options.encoding = "UTF-8"
}
tasks.withType(Javadoc::class) {
isFailOnError = false
}
tasks.withType(Test::class).getByName("test") {
project.afterEvaluate {
jvmArgs("-javaagent:${classpath.find { it.name.contains("jmockit") }!!.absolutePath}")
jvmArgs("-Djunit.jupiter.extensions.autodetection.enabled=true")
jvmArgs("-Djava.awt.headless=true")
}
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.FAILED, TestLogEvent.SKIPPED)
showCauses = true
info {
events = setOf(TestLogEvent.STARTED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR)
showStandardStreams = true
}
}
}
project.afterEvaluate {
publishing.publications.getByName("josmPlugin", MavenPublication::class) {
pom {
name.set("JOSM-${josm.pluginName}")
description.set("The Mapillary plugin for JOSM")
url.set("https://gitlab.com/JOSM/plugin/Mapillary")
licenses {
license {
name.set("GNU General Public License Version 2")
url.set("https://www.gnu.org/licenses/old-licenses/gpl-2.0")
}
}
scm {
connection.set("scm:git:git://gitlab.com/JOSM/plugin/Mapillary.git")
developerConnection.set("scm:git:ssh://gitlab.com/JOSM/plugin/Mapillary.git")
url.set("https://gitlab.com/JOSM/plugin/Mapillary")
}
issueManagement {
system.set("Trac")
url.set("https://josm.openstreetmap.de/query?component=Plugin+mapillary&status=assigned&status=needinfo&status=new&status=reopened")
}
}
}
}
// Spotbugs config
spotbugs {
ignoreFailures.set(true)
effort.set(Effort.MAX)
reportLevel.set(Confidence.LOW)
reportsDir = file("$buildDir/reports/spotbugs")
}
tasks.withType(SpotBugsTask::class) {
reports.create("html") {
setStylesheet("fancy-hist.xsl")
}
}
// JaCoCo config
jacoco {
toolVersion = "0.8.12"
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
html.outputLocation.set(file("$buildDir/reports/jacoco"))
}
}
tasks.test {
extensions.configure(JacocoTaskExtension::class) {
// We need to excluse ObjectDetections from coverage -- it is too large for instrumentation, which means that it will always have 0% coverage, despite having tests.
excludes = listOf("org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.class")
}
}
// PMD config
pmd {
toolVersion = versions.getValue("pmd")
isIgnoreFailures = true
ruleSetConfig = resources.text.fromFile("$projectDir/config/pmd/ruleset.xml")
ruleSets = listOf()
sourceSets = listOf(project.sourceSets.main.get(), project.sourceSets.test.get())
}
// SonarQube config
sonarqube {
properties {
property("sonar.forceAuthentication", "true")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.projectKey", "Mapillary")
property("sonar.organization", "josm")
property("sonar.projectVersion", project.version)
//property("sonar.projectDescription", "Allows the user to work with pictures hosted at mapillary.com")
findProperty("plugin.description")?.let { property("sonar.projectDescription", it) }
property("sonar.sources", listOf("src"))
}
}