-
Notifications
You must be signed in to change notification settings - Fork 76
/
build.gradle
385 lines (324 loc) · 10.2 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
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
import java.nio.file.Paths
import java.text.SimpleDateFormat
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
id 'org.jetbrains.intellij' version '0.7.3'
id 'com.palantir.git-version' version '0.12.3'
id 'ch.netzwerg.release' version '1.2.5'
id 'org.jlleitschuh.gradle.ktlint' version '10.0.0'
}
repositories {
mavenCentral()
}
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'idea'
apply plugin: "java"
apply plugin: "kotlin"
project.ext {
branchNameProperty = 'branch.name'
versionPropertiesFilePath = 'version.properties'
}
def javaVersion = JavaVersion.VERSION_11
def kotlinJvmTarget = '11'
def encoding = 'UTF-8'
def vendor = 'Lukasz Zielinski'
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
boolean ci = Boolean.valueOf(System.getenv('CI'))
boolean publish = Boolean.valueOf(String.valueOf(findProperty('publish')))
configurations {
testAgent {
transitive = false
}
}
def ideaCacheDir = Paths.get(System.getProperty('user.home')).resolve('intellij-gradle-cache').toAbsolutePath().toString()
println("Idea cache dir: $ideaCacheDir")
def details = versionDetails()
def branchName = details.branchName
def gitHash = details.gitHash
println("Build type: " + buildType(branchName, ci))
println("CI build: $ci")
intellij {
version = ideaVersion
type = ideaType
updateSinceUntilBuild = false
downloadSources = !ci
plugins = [
'java',
'android',
'gradle',
'git4idea',
'gr.jchrist.gitextender:0.6.0',
'org.jetbrains.plugins.github'
]
ideaDependencyCachePath = ideaCacheDir
instrumentCode = true
}
runPluginVerifier {
ideVersions = [
ideaVerifier_2020_2_4, //is not compatible ATM with 203 plugin line
ideaVerifier_2020_3_2,
ideaVerifier_2021_1
]
verifierPath = "pluginVerifierBin/verifier-all.jar" //download from https://github.com/JetBrains/intellij-plugin-verifier
}
compileJava.options.encoding = encoding
compileTestJava.options.encoding = encoding
compileKotlin {
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = [
"-Xjvm-default=enable"
]
useIR = true
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = [
"-Xjvm-default=enable"
]
useIR = true
}
}
patchPluginXml {
changeNotes "${file('change-notes.html').getText(encoding)}"
pluginDescription "${file('description.html').getText(encoding)}"
.replace("RELEASE_DATETIME", buildTime())
.replace("RELEASE_TYPE", buildType(branchName, ci))
}
processResources {
from ('.') {
include 'LICENSE'
include 'README.md'
into 'META-INF'
}
}
/*
runIde {
jbrVersion jbrVersion
}
*/
/*
buildSearchableOptions {
jbrVersion jbrVersion
}
*/
if (publish) {
println('Publish')
if (!ci) {
apply from: 'publish.gradle'
}
publishPlugin {
token = getPublishToken(ci, project)
channels = publishChannels(branchName, ci)
}
}
def static getPublishToken(ci, project) {
if (ci) {
return publishTokenFromEnv()
} else {
return publishTokenFromProject(project)
}
}
def static publishTokenFromEnv() {
def systemProperty = 'PUBLISH_TOKEN'
def token = System.getenv(systemProperty)
if (token == null) {
def propertyPresent = System.getenv().containsKey(systemProperty)
println("Null token from env. Property was present: $propertyPresent")
throw new GradleException("Publish token not found in $systemProperty")
}
return token
}
def static publishTokenFromProject(project) {
def token = project.publishToken
if (token == null) {
throw new GradleException("Publish token not found in project.publishToken")
}
return token
}
jar {
manifest {
attributes(
'Name': project.name,
'Specification-Title': project.name,
'Specification-Vendor': vendor,
'Specification-Version': project.version,
'Implementation-Title': project.name,
'Implementation-Vendor': vendor,
'Implementation-Version': gitHash,
'Build-Date': buildTime()
)
}
}
apply plugin: 'jacoco'
jacoco {
toolVersion = "${jacocoVersion}"
}
// workaround for missing coverage report with JUnit 5 (https://stackoverflow.com/a/44907857)
// as 'test' task cleans generated report
jacocoTestReport {
executionData.setFrom(fileTree(dir: "${project.buildDir.name}/jacoco-junit5", include: ['*.exec']))
}
test {
jacoco {
destinationFile = file("${project.buildDir.name}/jacoco-junit5/test.exec")
}
useJUnitPlatform {
//prevent running extensions as Junit 3 tests because of naming convention with TestCase
exclude('zielu/junit5/**')
excludeTags = ['integration']
reports {
html.enabled = false
}
}
}
task integrationTest(type: Test) {
jacoco {
destinationFile = file("${project.buildDir.name}/jacoco-junit5/test-integration.exec")
}
useJUnitPlatform {
//prevent running extensions as Junit 3 tests because of naming convention with TestCase
exclude('zielu/junit5/**')
includeTags = ['integration']
reports {
html.enabled = false
}
}
}
apply plugin: 'checkstyle'
checkstyle {
toolVersion = "${checkstyleVersion}"
maxErrors = 0
maxWarnings = 0
configFile = project(':').file('config/checkstyle/checkstyle.xml')
configProperties = ["suppressionFile": project(':').file('config/checkstyle/suppressions.xml')]
}
ktlint {
version = "${ktlintVersion}"
additionalEditorconfigFile = project(':').file('config/ktlint/.editorconfig')
coloredOutput = false
reporters {
reporter "checkstyle"
}
}
task buildAll {
dependsOn check, integrationTest, buildPlugin
tasks.findByName('integrationTest').mustRunAfter 'check'
}
task buildFast {
dependsOn check, buildPlugin
}
task codeCoverage {
dependsOn check, integrationTest, jacocoTestReport
tasks.findByName('integrationTest').mustRunAfter 'check'
}
task captureReleaseBranch {
doLast {
def props = loadVersionProps()
def oldBranchName = props[project.branchNameProperty]
if (branchName != oldBranchName) {
if (branchName != null) {
props[project.branchNameProperty] = branchName
} else {
props.remove(project.branchNameProperty)
}
storeVersionProps(props)
exec {
executable 'git'
args 'add', project.versionPropertiesFilePath
}
exec {
executable 'git'
args 'commit', project.versionPropertiesFilePath, '-m', 'Update version info'
}
}
}
}
task prepareRelease {
dependsOn clean, buildAll, captureReleaseBranch
}
release {
tagPrefix = ''
dependsOn prepareRelease
}
dependencies {
checkstyle("com.puppycrawl.tools:checkstyle:${checkstyleVersion}")
testAgent("org.jacoco:org.jacoco.agent:${jacocoVersion}:runtime")
implementation("org.jodd:jodd-core:${joddVersion}")
implementation("com.google.guava:guava:${guavaVersion}")
implementation("org.apache.commons:commons-lang3:${commonsLang3Version}")
implementation("org.yaml:snakeyaml:${snakeYamlVersion}")
implementation("io.dropwizard.metrics:metrics-core:${metricsVersion}") {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
implementation("io.dropwizard.metrics:metrics-jmx:${metricsVersion}") {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
implementation("com.hrakaroo:glob:${globVersion}")
testImplementation("org.eclipse.jgit:org.eclipse.jgit:${jgitVersion}")
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
testImplementation("io.mockk:mockk:${mockkVersion}")
testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
testImplementation("org.assertj:assertj-core:${assertjCoreVersion}")
testImplementation("org.slf4j:slf4j-api:${slf4jVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}")
//testImplementation ("com.tngtech.archunit:archunit-junit5-api:${archUnitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
//testRuntimeOnly ("com.tngtech.archunit:archunit-junit5-engine:${archUnitVersion}")
//testRuntimeOnly ("org.slf4j:slf4j-simple:${slf4jVersion}")
}
def static buildTime() {
def df = new SimpleDateFormat('yyyyMMdd.HHmmss')
df.setTimeZone(TimeZone.getTimeZone('UTC'))
return df.format(new Date())
}
def static isStableBranch(branchName) {
return branchName ==~ /(master|\d+-release)/
}
def isStableBuild(branchName, ci) {
def envProp = System.getenv("stable")
if (envProp != null) {
return Boolean.valueOf(envProp)
}
if (ci) {
if (branchName != null) {
return isStableBranch(branchName)
} else {
def props = loadVersionProps()
branchName = props[project.branchNameProperty]
println("Branch name loaded from props $branchName")
if (branchName != null) {
return isStableBranch(branchName)
}
return false
}
} else {
return isStableBranch(branchName)
}
}
def buildType(branchName, ci) {
return isStableBuild(branchName, ci) ? 'Stable' : 'EAP'
}
def publishChannels(branchName, ci) {
return isStableBuild(branchName, ci) ? ['default', 'eap'] : ['eap']
}
def loadVersionProps() {
def props = new Properties()
def propsFile = file project.versionPropertiesFilePath
if (propsFile.exists()) {
props.load(propsFile.newReader('UTF-8'))
}
return props
}
def storeVersionProps(Properties props) {
def propsFile = file project.versionPropertiesFilePath
props.store(propsFile.newWriter('UTF-8'), null)
}