-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
188 lines (168 loc) · 6.08 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
plugins {
id 'java'
id 'application'
id 'base'
id 'com.github.hierynomus.license' version '0.16.1'
}
apply plugin: 'java'
apply plugin: 'base'
apply plugin: 'com.github.hierynomus.license'
apply plugin: "application"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.slf4j:slf4j-api:2.0.13'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
implementation 'org.jasypt:jasypt:1.9.3'
runtimeOnly 'org.slf4j:slf4j-simple:2.0.13'
testImplementation "junit:junit:$junitVersion"
}
group = 'org.apereo.openequella.adminconsole'
version = System.getenv("TRAVIS_TAG") ?: artifactVersion
application {
mainClass = 'org.apereo.openequella.adminconsole.launcher.ClientLauncher'
}
license {
strictCheck
header = file('LICENSE')
}
jar {
archiveFileName = 'admin.jar'
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version,
'Main-Class': application.mainClass,
"Class-Path": configurations.runtimeClasspath.files.collect { it.getName() }.join(' '))
}
}
final buildDirectory = getLayout().getBuildDirectory()
final jreDownloadDir = buildDirectory.dir("jre-downloads").get().asFile
final jreExtractDir = {sys -> "${jreDownloadDir.absolutePath}/jre/${sys}"}
final jarDir = buildDirectory.dir("libs").get().asFile
final launcherScripts = [
windows: 'Windows-launcher.bat',
linux: 'Linux-launcher.sh',
mac: 'Mac-launcher.sh'
]
class JreProperties {
String hash
String fileName
String getDownloadUrl() {"https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.1%2B12/${fileName}"}
File getJre() {new File("build/jre-downloads/${fileName}")}
}
final jreProperties = [
windows: new JreProperties(
hash: '38bb68f9db9c85a63496570c53a1bcbac18c808677595d7e939d2f5b38e9a7aa',
fileName: 'OpenJDK21U-jre_x64_windows_hotspot_21.0.1_12.zip'),
linux: new JreProperties(
hash: '277f4084bee875f127a978253cfbaad09c08df597feaf5ccc82d2206962279a3',
fileName: 'OpenJDK21U-jre_x64_linux_hotspot_21.0.1_12.tar.gz'),
mac: new JreProperties(
hash: 'c21a2648ec21bc4701acfb6b7a1fd90aca001db1efb8454e2980d4c8dcd9e310',
fileName: 'OpenJDK21U-jre_x64_mac_hotspot_21.0.1_12.tar.gz')
]
task copyDependencies(type: Copy, description: 'Copy dependencies to /build/libs') {
from configurations.runtimeClasspath
into(jarDir)
}
copyDependencies.mustRunAfter(startScripts)
task downloadJre(description: 'Download OpenJRE of Linux, Windows and Mac') {
doFirst {
if (!jreDownloadDir.exists()) {
jreDownloadDir.mkdirs()
}
// Filter out entries that already have JRE downloaded
jreProperties.findAll {String sys, JreProperties props -> !props.jre.exists()}
.collect {String sys, JreProperties props ->
Thread.start {
println("Start downloading OpenJRE for ${sys}...")
new URI(props.downloadUrl as String).toURL().withInputStream {
props.jre.newOutputStream() << it
}
}
}*.join()
}
}
// Execute downloadJre only when any one of three JREs is missing
downloadJre.onlyIf {
jreProperties.any {sys,props ->
!props.jre.exists()
}
}
import java.security.MessageDigest
static String calculateHash(File jre) {
MessageDigest.getInstance('SHA-256').with {
jre.eachByte(1024) {buff,len ->
update(buff, 0, len)
}
digest().encodeHex() as String
}
}
task checkJre(dependsOn: downloadJre, description: 'Check if the hash of each JRE is correct') {
doFirst {
if (jreProperties.any { String sys, JreProperties props ->
props.hash != calculateHash(props.jre)
}) {
throw new GradleException("Hash mismatch for downloaded JRE. Files may have been modified.")
}
}
}
// Execute checkJre only when downloadJre was not skipped
checkJre.onlyIf {
downloadJre.didWork
}
task unzipJre(description: 'Unzip a JRE when the extract directory is missing', dependsOn: checkJre) {
doFirst {
// Find out unzipped JREs and extract them
jreProperties.findAll {String sys, JreProperties props ->
!new File(jreExtractDir(sys)).exists()
}.each {String sys, JreProperties props ->
println "Unzip JRE for ${sys}"
copy {
from props.jre.name.endsWith('zip') ? zipTree(props.jre) : tarTree(resources.gzip(props.jre))
into file(jreExtractDir(sys))
}
}
}
}
// Execute unzipJre only when any one of three JRE extract folders is missing
unzipJre.onlyIf {
jreProperties.any {String sys, JreProperties props->
!new File(jreExtractDir(sys)).exists()
}
}
distributions {
launcherScripts.each { String sys, String scriptFileName ->
String scriptFileDir = "${projectDir}/launcher-scripts/${scriptFileName}"
"${sys}Packages" {
distributionBaseName = "admin-console-package-for-${sys}"
contents {
into("libs") {
from {jarDir}
}
from {file(jreExtractDir(sys))}
from {file(scriptFileDir)}
}
}
}
}
Object[] dependentTasks = [unzipJre,copyDependencies]
build.dependsOn(dependentTasks)
// We want TAR files to be compressed by GZIP with the file extension of '.tar.gz'
tasks.withType(Tar){
compression = Compression.GZIP
archiveExtension = 'tar.gz'
}
// We do not need the default distributions that have no JRE bundled
distTar.enabled = false
distZip.enabled = false
// We do not need tar for Windows and zip for both Mac and Linux.
windowsPackagesDistTar.enabled = false
linuxPackagesDistZip.enabled = false
macPackagesDistZip.enabled = false
// These plugin-generated distribution tasks must run after JREs are downloaded and unzipped.
linuxPackagesDistTar.mustRunAfter(dependentTasks)
macPackagesDistTar.mustRunAfter(dependentTasks)
windowsPackagesDistZip.mustRunAfter(dependentTasks)