-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
210 lines (178 loc) · 5.39 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
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jruby-gradle:jruby-gradle-plugin:1.5.0'
}
}
apply plugin: "com.github.jruby-gradle.base"
apply from: 'gradle/cli.gradle'
import com.github.jrubygradle.JRubyExec
import java.util.concurrent.TimeUnit
dependencies {
jrubyExec "rubygems:asciidoctor:1.5.4"
}
repositories {
jcenter()
maven { url "http://rubygems-proxy.torquebox.org/releases/" }
}
version = project.findProperty("newVersion") ?: project.findProperty("defaultVersion")
ext {
isCommandAvailable = { String cmd ->
try {
cmd.execute()
return true
} catch (IOException e) {
}
return false
}
isShellcheckPresent = {
isCommandAvailable("shellcheck -V")
}
shellcheckFile = isShellcheckPresent() ? new File("shellcheck") :
new File(project.rootProject.buildDir, "shellcheck-${shellcheckVersion}/shellcheck")
shellcheckVersionWithoutPrefix = "${shellcheckVersion}".startsWith("v") ? "${shellcheckVersion}".substring(1) : "${shellcheckVersion}"
assertShellcheckVersion = {
String output = ""
new ByteArrayOutputStream().withStream { os ->
String cmd = shellcheckFile.path + " -V"
project.logger.lifecycle("Executing cmd [${cmd}]")
Process p = cmd.execute()
p.consumeProcessOutput(os, os)
p.waitFor(5L, TimeUnit.SECONDS)
output = os.toString()
}
project.logger.lifecycle("Checking if shellcheck version is [${shellcheckVersionWithoutPrefix}]")
boolean versionIsOk = output.contains("version: ${shellcheckVersionWithoutPrefix}")
if (!versionIsOk) {
logger.info("Shellcheck is in wrong version. The output of checking version is \n\n[${output}]")
}
}
isShellcheckDownloaded = {
shellcheckFile.exists()
}
}
subprojects {
apply plugin: 'java'
task installShellcheckIfMissing {
doLast {
boolean shellcheckInstalled = isShellcheckPresent() || isShellcheckDownloaded()
exec {
if (shellcheckInstalled) {
assertShellcheckVersion()
commandLine "echo", "Shellcheck installed in version [${shellcheckVersionWithoutPrefix}] - continuing"
} else {
logger.lifecycle("Shellcheck is missing. Will install it.")
commandLine "bash", new File(project.rootDir, "tools/build-helper.sh").path, "download-shellcheck"
}
}
}
}
task shellcheck {
doLast {
boolean shellcheckInstalled = isShellcheckPresent()
String pathToShellcheck = "shellcheck"
if (!shellcheckInstalled) {
pathToShellcheck = new File(project.rootProject.buildDir, "shellcheck-${shellcheckVersion}/shellcheck").path
}
sourceSets*.resources.srcDirs*.each { srcDir ->
fileTree(relativePath(srcDir))
.include('**/*.sh')
.exclude("**/build/**")
.each { File script ->
exec {
commandLine pathToShellcheck, script
}
}
}
}
}
task initalizeSubModules() {
doLast {
exec {
commandLine "bash", new File(project.rootDir, "tools/build-helper.sh").path, "initialize-submodules"
}
}
}
shellcheck.dependsOn("installShellcheckIfMissing")
build.dependsOn("shellcheck")
}
// DOCUMENTATION -- start
jruby {
defaultRepositories false
}
// remove::start[JENKINS]
task generateJenkinsReadme(type: JRubyExec) {
script "${projectDir}/tools/coalesce-readme.rb"
scriptArgs "-i ${projectDir}/docs-sources/src/main/asciidoc/JENKINS.adoc", "-o ${projectDir}/jenkins/README.adoc"
}
// remove::end[JENKINS]
// remove::start[CONCOURSE]
task generateConcourseReadme(type: JRubyExec) {
script "${projectDir}/tools/coalesce-readme.rb"
scriptArgs "-i ${projectDir}/docs-sources/src/main/asciidoc/CONCOURSE.adoc", "-o ${projectDir}/concourse/README.adoc"
}
//remove::end[CONCOURSE]
List<String> projects = []
//remove::start[JENKINS]
projects << "generateJenkinsReadme"
//remove::end[JENKINS]
//remove::start[CONCOURSE]
projects << "generateConcourseReadme"
//remove::end[CONCOURSE]
task setMavenVersion(dependsOn: [projects]) {
doLast {
exec {
workingDir project(":docs-sources").projectDir.path
commandLine "./mvnw", "org.codehaus.mojo:versions-maven-plugin:2.3:set", "-DnewVersion=${project.version}"
}
}
}
task generateIndex(dependsOn: [setMavenVersion]) {
doLast {
exec {
workingDir project(":docs-sources").projectDir.path
commandLine "./mvnw", "clean", "install", "-Pdocs"
}
}
}
task cleanDocs(type: Delete) {
delete project(":docs").projectDir.path
}
task copyJekyll(type: Copy) {
dependsOn(["cleanDocs"])
from new File(project(":docs-sources").projectDir, "src/main/jekyll").path
into project(":docs").projectDir.path
}
task copyGeneratedSources(type: Copy) {
dependsOn(["cleanDocs", "generateIndex"])
from(new File(project(":docs-sources").projectDir, "target/generated-docs").path) {
exclude "spring-cloud-pipelines.xml"
}
into project(":docs").projectDir.path
}
task generateDocs(dependsOn: ["copyJekyll", "copyGeneratedSources"]) {
description = "Creates documentation for the project"
}
task release(dependsOn: "generateDocs") {
description = "Pushes the generated docs to sc-static and rolls back docs pom.xml version to the default one"
onlyIf {
!project.version.toString().contains("SNAPSHOT")
}
doLast {
try {
exec {
workingDir project.rootDir
commandLine "./docs-sources/src/main/bash/release.sh", "${project.version}"
}
} finally {
exec {
workingDir project.rootDir
commandLine "./docs-sources/src/main/bash/cleanup.sh", "${project.findProperty("defaultVersion")}"
}
}
}
}
// DOCUMENTATION -- end
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
}