-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
250 lines (222 loc) · 9.38 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
import java.util.regex.Matcher
import java.util.regex.Pattern
/*
* Copyright (c) 2016-2019, Leftshift One
* __________________
* [2019] Leftshift One
* All Rights Reserved.
* NOTICE: All information contained herein is, and remains
* the property of Leftshift One and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Leftshift One
* and its suppliers and may be covered by Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Leftshift One.
*/
buildscript {
ext {
kotlinVersion = "1.4.32"
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "one.leftshift.asteria:asteria-code-analytics:latest.release"
classpath "one.leftshift.asteria:asteria-dependency:latest.release"
classpath "one.leftshift.asteria:asteria-docs:latest.release"
classpath "one.leftshift.asteria:asteria-email:latest.release"
classpath "one.leftshift.asteria:asteria-publish:latest.release"
classpath "one.leftshift.asteria:asteria-report:latest.release"
classpath "one.leftshift.asteria:asteria-version:latest.release"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
}
}
apply plugin: "antlr"
apply plugin: "one.leftshift.asteria-email"
apply plugin: "one.leftshift.asteria-report"
apply plugin: "one.leftshift.asteria-dependency"
apply plugin: "one.leftshift.asteria-version"
apply plugin: "io.codearte.nexus-staging"
asteriaEmail {
smtpHost = System.getenv("ASTERIA_EMAIL_SMTP_HOST")
if (System.getenv("ASTERIA_EMAIL_SMTP_PORT")) {
smtpPort = System.getenv("ASTERIA_EMAIL_SMTP_PORT").toInteger()
}
smptUser = System.getenv("ASTERIA_EMAIL_SMTP_USER")
smptPassword = System.getenv("ASTERIA_EMAIL_SMTP_PASSWORD")
sender = System.getenv("ASTERIA_EMAIL_SENDER")
}
asteriaReport {
reportingUrl = System.getenv("ASTERIA_REPORT_URL")
depsJsonResult = file("${rootProject.buildDir}/dependencyUpdates/report.json")
junitXmlResults = fileTree(rootProject.projectDir) {
include("**/test-results/*/TEST-*.xml")
}
junitBinaryResults = files(["test"].collect {
"${project.buildDir}/test-results/${it}/binary"
})
}
nexusStaging {
packageGroup = "one.leftshift"
serverUrl = "https://s01.oss.sonatype.org/service/local/"
stagingProfileId = System.getenv("OSSRH_STAGING_PROFILE_ID")
username = System.getenv("OSSRH_LOGIN_NAME")
password = System.getenv("OSSRH_LOGIN_PASSWORD")
}
allprojects {
apply plugin: "one.leftshift.asteria-dependency"
apply plugin: "one.leftshift.asteria-version"
repositories {
jcenter()
mavenCentral()
}
asteriaDependency {
enableBranchSnapshotRepositories = true
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.4.5") {
bomProperty("kotlin.version", kotlinVersion)
}
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "org.jetbrains.kotlin") {
details.useVersion kotlinVersion
}
}
}
if (System.getenv("CI")) {
afterEvaluate { rootProject.tasks.postRelease.finalizedBy rootProject.tasks.sendReleaseEmail }
if (tasks.findByName("publish")) {
afterEvaluate { rootProject.tasks.postRelease.dependsOn tasks.publish }
}
}
}
subprojects {
apply plugin: "one.leftshift.asteria-code-analytics"
asteriaCodeAnalytics {
sonarUrl = System.getenv("SONAR_HOST_URL")
sonarLoginToken = System.getenv("SONAR_LOGIN")
xmlCoverageReportEnabled = true
sonarProperties = [
"sonar.test.inclusions" : "**/*Test.*,**/*.test.ts,**/tests/test_*.py",
//"sonar.javascript.lcov.reportPaths": "${project(":dynabuffers-javascript").projectDir}/coverage/lcov.info",
//"sonar.typescript.lcov.reportPaths": "${project(":dynabuffers-javascript").projectDir}/coverage/lcov.info",
"sonar.python.coverage.reportPath": "${project(":dynabuffers-python").projectDir}/build/coverage/coverage.xml",
]
coverageExcludes = ["**/*Kt.class"]
}
}
dependencies {
antlr "org.antlr:antlr4:4.7"
}
task generateGrammarSourceJava(type: AntlrTask) {
source = project.sourceSets.main.antlr
outputDirectory = file("${project(":dynabuffers-java").buildDir}/generated-src/antlr/dynabuffers/antlr")
arguments += ["-visitor", "-package", "dynabuffers.antlr"]
}
task generateGrammarSourcePython(type: AntlrTask) {
source = project.sourceSets.main.antlr
outputDirectory = file("${project(":dynabuffers-python").projectDir}/dynabuffers/antlr")
arguments += ["-visitor", "-Dlanguage=Python3"]
}
generateGrammarSource.dependsOn generateGrammarSourceJava
generateGrammarSource.dependsOn generateGrammarSourcePython
def versionClassDirPython = "${project(":dynabuffers-python").projectDir}/dynabuffers/header" as String
def versionClassNamePython = "DynabuffersVersion.py" as String
def versionClassPython = "$versionClassDirPython/$versionClassNamePython" as String
def versionClassDirJava = "${project(":dynabuffers-java").projectDir}/src/main/kotlin/dynabuffers/header" as String
def versionClassNameJava = "DynabuffersVersion.kt" as String
def versionClassJava = "$versionClassDirJava/$versionClassNameJava" as String
task generateVersionClassJava(type: Copy) {
from "${project(":dynabuffers-java").projectDir}/src/main/resources/templates"
into versionClassDirJava
include "DynabuffersVersion.vm"
rename("DynabuffersVersion.vm", versionClassNameJava)
doLast {
replaceVersionInTemplate(versionClassJava)
}
}
task generateVersionClassPython(type: Copy) {
from "${project(":dynabuffers-python").projectDir}/resources/templates"
into versionClassDirPython
include "DynabuffersVersion.vm"
rename("DynabuffersVersion.vm", versionClassNamePython)
doLast {
replaceVersionInTemplate(versionClassPython)
}
}
def replaceVersionInTemplate(String path) {
ant.replace(
file: path,
token: "@VERSION@",
value: project.version.toString()
)
}
task setVersionPython() {
doLast {
String pyprojectTomlPath = project(":dynabuffers-python").projectDir.toString() + "/pyproject.toml"
File pyprojectTomlFile = file(pyprojectTomlPath)
String pyprojectTomlContent = pyprojectTomlFile.text
Pattern regex = Pattern.compile("^version\\s?=\\s?[\"'].*[\"']\\s?\$", Pattern.MULTILINE)
Matcher matcher = regex.matcher(pyprojectTomlContent)
List<String> matches = []
while (matcher.find()) {
matches.add(matcher.group(0))
}
if (matches.size() > 1)
throw new RuntimeException("More than one version found in ${pyprojectTomlPath}")
if (matches.isEmpty() || matches.first().trim().isEmpty())
throw new RuntimeException("No version found in ${pyprojectTomlPath}")
pyprojectTomlFile.text = pyprojectTomlContent.replaceAll(matches.first(), "version = \"${version.toString()}\"")
logger.quiet("Updated version in ${pyprojectTomlPath} to ${version.toString()}")
}
}
task commitVersions() {
doLast {
// python
String pyprojectTomlPath = "${project(":dynabuffers-python").projectDir}/pyproject.toml"
executeAssertExitCode(["git", "add", pyprojectTomlPath])
executeAssertExitCode(["git", "add", versionClassPython])
executeAssertExitCode(["git", "add", versionClassJava])
String commitMessage = "set version to ${version.toString()}"
executeWarnExitCode(["git", "commit", "-m", "'$commitMessage'".toString()])
}
}
commitVersions.dependsOn setVersionPython, generateVersionClassPython, generateVersionClassJava
task pushVersions() {
doLast {
executeAssertExitCode(["git", "push"])
}
}
pushVersions.dependsOn commitVersions
if (System.getenv("CI") == null || System.getenv("CI") != "true") {
afterEvaluate { rootProject.tasks.release.dependsOn rootProject.tasks.pushVersions }
}
private void executeAssertExitCode(List<String> command) {
int exitCode = execute(command)
if (exitCode != 0) throw new RuntimeException("Command '${command.join(" ")}' failed with code ${exitCode}")
logger.debug("Executed command '${command.join(" ")}'")
}
private void executeWarnExitCode(List<String> command) {
int exitCode = execute(command)
if (exitCode != 0) logger.warn("Command failed with code ${exitCode}")
logger.debug("Executed command '${command.join(" ")}'")
}
private int execute(List<String> command) {
logger.debug("Executing command '${command.join(" ")}'")
def process = new ProcessBuilder(command).directory(projectDir).start()
process.consumeProcessOutput(System.out, System.err)
process.waitFor()
logger.debug("Executed command '${command.join(" ")}'")
return process.exitValue()
}