forked from blackducksoftware/detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
306 lines (253 loc) · 9.88 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
import com.synopsys.integration.detect.battery.UpdateBatteryTask
import com.synopsys.integration.detect.verification.VerifyBlackDuckDetectTask
buildscript {
apply from: 'shared-version.properties'
ext {
springBootVersion = gradle.ext.springBootVersion
blackDuckCommonVersion = gradle.ext.blackDuckCommonVersion
junitPlatformCustomTestTags = 'docker, battery'
javaTargetCompatibility = 8
javaSourceCompatibility = 8
}
apply from: 'https://raw.githubusercontent.com/blackducksoftware/integration-resources/master/gradle_common/buildscript-repositories.gradle', to: buildscript
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
group = 'com.synopsys.integration'
version = '8.11.0-SNAPSHOT'
apply plugin: 'com.synopsys.integration.solution'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
final def resources = new File("${projectDir}/src/main/resources")
final def versionFile = new File(resources, "version.txt")
resources.mkdirs()
versionFile.delete()
versionFile << "version=" << version << "\n" << "builddate=" << new Date().format('yyyy-MM-dd')
// By default, starting in 2.5.0, spring boot creates an extra "plain" .jar that we don't want
jar {
enabled = false
}
def createArtifactName() {
return "${buildDir}/libs/${project.name}-${version}.jar"
}
def createBatteryPath() {
return "${buildDir}/battery/"
}
repositories {
maven { url "https://sig-repo.synopsys.com/bds-bdio-release" }
}
subprojects {
group = rootProject.group
version = rootProject.version
apply plugin: 'com.synopsys.integration.simple'
}
allprojects {
dependencies {
implementation "com.google.guava:guava:31.1-jre"
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.0'
implementation 'org.freemarker:freemarker:2.3.31'
implementation 'org.apache.httpcomponents:httpclient-osgi:4.5.14'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.4.2'
testImplementation 'org.mockito:mockito-core:2.+'
}
}
publishing {
publications {
mavenJava(MavenPublication) {
def jarName = createArtifactName()
artifact(jarName)
}
}
}
artifactory {
publish {
defaults { publications('mavenJava') }
}
}
test {
testLogging {
exceptionFormat = 'full'
}
}
dependencies {
implementation project(':common')
implementation project(':configuration')
implementation project(':detectable')
implementation project(':detector')
implementation 'ch.qos.logback:logback-classic:1.2.11'
implementation 'com.esotericsoftware.yamlbeans:yamlbeans:1.11'
implementation "com.synopsys.integration:blackduck-common:${blackDuckCommonVersion}"
implementation 'com.synopsys:method-analyzer-core:0.2.0'
implementation 'org.apache.maven.shared:maven-invoker:3.0.0'
implementation "org.springframework.boot:spring-boot"
implementation 'org.yaml:snakeyaml:2.0'
implementation 'org.zeroturnaround:zt-zip:1.13'
implementation 'org.apache.pdfbox:pdfbox:2.0.27'
// spring-boot-starter-test *can* provide these, but we choose to be more explicit about the dependencies we ACTUALLY use
testImplementation 'org.assertj:assertj-core:3.13.2'
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
testImplementation 'org.mockito:mockito-inline:2.+'
testImplementation project(':configuration').sourceSets.test.output
testImplementation project(':common-test')
testImplementation 'com.github.docker-java:docker-java-core:3.2.7'
testImplementation 'com.github.docker-java:docker-java-transport-httpclient5:3.3.0'
}
springBoot { mainClass = 'com.synopsys.integration.detect.Application' }
if (project.tasks.findByName('testBattery')) {
tasks['testBattery'].doFirst {
def batteryPath = new File(createBatteryPath())
batteryPath.mkdirs()
environment 'BATTERY_TESTS_DETECT_JAR_PATH', createArtifactName()
environment 'BATTERY_TESTS_PATH', batteryPath.getCanonicalPath()
environment 'BATTERY_TESTS_JAVA_PATH', org.gradle.internal.jvm.Jvm.current().javaExecutable.getCanonicalPath()
}
}
task updateBattery(type: UpdateBatteryTask) {}
task runDetect(type: JavaExec) {
dependsOn build
classpath = files(createArtifactName())
classpath += sourceSets.main.runtimeClasspath
main = 'com.synopsys.integration.detect.Application'
args = ['--detect.risk.report.pdf=true']
}
task verifyBlackDuckDetect(type: VerifyBlackDuckDetectTask) {
dependsOn runDetect
task verifyDetect() {
dependsOn verifyBlackDuckDetect
}
}
String parseAirGapZipPath(ByteArrayOutputStream standardOutput) {
String marker = 'Detect Air Gap Zip: '
String line = standardOutput.toString().split('\n').find { it.contains(marker) }
String path = line.substring(line.lastIndexOf(marker) + marker.length()).trim()
println "Found Air Gap Zip: ${path}"
return path
}
String findGradle() {
return System.getProperty("os.name").toLowerCase().contains("windows") ? '--detect.gradle.path=gradlew.bat' : '--detect.gradle.path=gradlew';
}
task signJar() {
dependsOn build
finalizedBy 'verifyJar'
doLast {
exec {
commandLine 'jarsigner', '-tsa', 'http://rfc3161timestamp.globalsign.com/advanced', '-storetype', 'pkcs12', '-storepass', "${jarSigningKeystorePassword}", '-keystore', "${jarSigningKeystorePath}", "${createArtifactName()}", "${jarSigningCertificateAlias}"
}
}
}
task createAirGapZip(type: JavaExec) {
dependsOn signJar
classpath = files(createArtifactName())
classpath += sourceSets.main.runtimeClasspath
main = 'com.synopsys.integration.detect.Application'
args = [findGradle(), "--detect.output.path=${buildDir}/libs/", '-z']
standardOutput = new ByteArrayOutputStream()
doLast {
createAirGapZip.ext.airGapPath = parseAirGapZipPath(standardOutput)
}
}
task publishAirGapZip() {
dependsOn createAirGapZip
doLast {
def airGapZipName = "${project.name}-${version}-air-gap.zip"
def airGapZipLocation = createAirGapZip.ext.airGapPath
exec {
commandLine 'curl', '--insecure', '-u', "${project.ext.artifactoryDeployerUsername}:${project.ext.artifactoryDeployerPassword}", '-X', 'PUT',
"${project.ext.deployArtifactoryUrl}/${project.ext.artifactoryRepo}/com/synopsys/integration/${project.name}/${version}/${airGapZipName}", '-T', "${airGapZipLocation}", '-f'
}
}
}
task createAirGapZipWithoutDocker(type: JavaExec) {
dependsOn signJar
classpath = files(createArtifactName())
classpath += sourceSets.main.runtimeClasspath
main = 'com.synopsys.integration.detect.Application'
standardOutput = new ByteArrayOutputStream()
doLast {
createAirGapZipWithoutDocker.ext.airGapPath = parseAirGapZipPath(standardOutput)
}
args = [findGradle(), '-z', 'NO_DOCKER']
}
task publishAirGapZipWithoutDocker() {
dependsOn createAirGapZipWithoutDocker
doLast {
def airGapZipName = "${project.name}-${version}-air-gap-no-docker.zip"
//MUST remain for down-stream projects until late 2022
def airGapZipLocation = createAirGapZipWithoutDocker.ext.airGapPath
exec {
commandLine 'curl', '--insecure', '-u', "${project.ext.artifactoryDeployerUsername}:${project.ext.artifactoryDeployerPassword}", '-X', 'PUT',
"${project.ext.deployArtifactoryUrl}/${project.ext.artifactoryRepo}/com/synopsys/integration/${project.name}/${version}/${airGapZipName}", '-T', "${airGapZipLocation}", '-f'
}
}
}
task verifyJar() {
dependsOn signJar
doLast {
exec {
// returns 0 if successfully verified as signed; non-0 if not
commandLine 'jarsigner', '-verify', '-strict', "${createArtifactName()}"
}
}
}
task helpJson(type: JavaExec) {
dependsOn build
classpath = files(createArtifactName())
classpath += sourceSets.main.runtimeClasspath
main = 'com.synopsys.integration.detect.Application'
args = ['--helpjson']
}
task buildPlatform1 () {
dependsOn createAirGapZip
doFirst {
copy {
from ("${projectDir}/platform-1/") {
include "*"
}
into "${buildDir}/platform-1"
}
}
doLast {
def airGapZipLocation = createAirGapZip.ext.airGapPath
exec {
workingDir "${buildDir}/platform-1"
executable = 'bash'
environment("RELEASE_VERSION", "${version}")
environment("AIR_GAP_ZIP_LOCATION", "${airGapZipLocation}")
args = ["./build.sh"]
}
}
}
task submitToPlatform1 (type: Exec, dependsOn: [buildPlatform1]){
doFirst {
copy {
from ("${projectDir}/platform-1/") {
include "*"
}
into "${buildDir}/platform-1"
}
}
def branch = System.getenv('BRANCH') ?: ''
workingDir "${buildDir}/platform-1"
if (branch.startsWith('origin/')){
branch=branch.replaceFirst('origin/', '')
}
boolean isRelease = System.getenv('RUN_RELEASE') ? System.getenv('RUN_RELEASE').toBoolean() : false
if (isRelease){
branch="update.${version}"
}
else{
def new_version = version.split('-')[0]
branch="update.${new_version}"
}
executable 'bash'
environment("RELEASE_VERSION", "${version}")
environment("BRANCH", branch)
environment("REPO1_URL", System.getenv('REPO1_ACCESS_URL'))
environment("ARTIFACTORY_USERNAME", System.getenv('ARTIFACTORY_DEPLOYER_USER'))
environment("ARTIFACTORY_PASSWORD", System.getenv('ARTIFACTORY_DEPLOYER_PASSWORD'))
environment("ARTIFACTORY_HOST", System.getenv('ARTIFACTORY_HOST'))
args = ["./submit.sh"]
}
artifactoryPublish.dependsOn ':documentation:publishDitaSource'
artifactoryPublish.dependsOn signJar