/
build.gradle
102 lines (84 loc) · 3.12 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
ext {
artifactName = 'gateway-package'
pullNo = project.hasProperty("pullRequest") && project.getProperty("pullRequest") != null ? "-" + project.getProperty("pullRequest") : ""
}
configurations {
zip
}
def resourceDir = 'src/main/resources/'
task packageApiGateway(type: Zip) {
archiveFileName = artifactName + pullNo + ".zip"
includeEmptyDirs = true
into('/') {
from "$buildDir/convert/manifest.yaml"
from "../schemas/gateway-schema.json"
}
into('bin/') {
from "$resourceDir/bin/gateway-service.jar"
from "$resourceDir/bin/start.sh"
from "$resourceDir/bin/validate.sh"
}
}
task downloadFile {
doLast {
// Specify the URL of the file to download
def fileURL = 'https://zowe.jfrog.io/artifactory/libs-release/org/zowe/apiml/gateway-fat-jar/2.14.6/gateway-fat-jar-2.14.6-application.jar'
RegularFile gatewayJar = layout.projectDirectory.file("src/main/resources/bin/gateway-service.jar")
// Set the destination directory and file name
def destination = gatewayJar.asFile
if (!destination.exists()) {
// Make sure the directory exists
destination.parentFile.mkdirs()
// Download the file
new URL(fileURL).withInputStream { i ->
destination.withOutputStream {
it << i
}
}
println "Downloaded file to ${destination.absolutePath}"
} else {
println "File already exists ${destination.absolutePath}"
}
}
}
packageApiGateway.dependsOn downloadFile
// save build information to manifest
packageApiGateway.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text
def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)
manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())
Provider<Directory> output = layout.buildDirectory.dir("convert")
def scriptOutputDir = output.get().asFile
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs()
}
Provider<RegularFile> manifestOutput = layout.buildDirectory.file("convert/manifest.yaml")
File convertedManifest = manifestOutput.get().asFile
if (convertedManifest.exists()) {
convertedManifest.delete()
}
convertedManifest.createNewFile()
convertedManifest.write(manifest)
}
jar.dependsOn(packageApiGateway)
build.dependsOn(packageApiGateway)
artifacts {
zip packageApiGateway
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact("$buildDir/distributions/$artifactName" + pullNo + ".zip")
}
}
}
jar {
enabled false
}