/
build.gradle
112 lines (100 loc) · 5.15 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
/*
* gcUnicorn
* Copyright (C) 2023 Martin Misiarz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
configure([ project(':core'), project(':webapp') ]) {
def keystorePropertiesFile = project.file(keystoreFile)
if (keystorePropertiesFile.exists()) {
// Load keystore properties.
def keystoreProperties = new Properties()
keystoreProperties.load(keystorePropertiesFile.newDataInputStream())
// Default Gradle signing.
if (keystoreProperties['signing.keyId'] && keystoreProperties['signing.password'] && keystoreProperties['signing.secretKeyRingFile']) {
project.ext['signing.keyId'] = keystoreProperties['signing.keyId']
project.ext['signing.password'] = keystoreProperties['signing.password']
project.ext['signing.secretKeyRingFile'] = keystoreProperties['signing.secretKeyRingFile']
project.plugins.apply('signing')
signing {
sign configurations.archives
}
}
// Custom JAR signing.
if (keystoreProperties['jarsigning.keystore'] && keystoreProperties['jarsigning.keystoreType'] && keystoreProperties['jarsigning.keystorePassword'] && keystoreProperties['jarsigning.alias'] && keystoreProperties['jarsigning.keyPassword']) {
if (project.name == 'core') {
def task = project.tasks.register('signedJar', Sign) {
group = 'build'
dependsOn = [ project.tasks.named('signArchives'), project.tasks.named('test') ]
buildDir = project.buildDir.absolutePath
archiveName = project.tasks.jar.archiveFileName
alias = keystoreProperties['jarsigning.alias']
keyStoreType = keystoreProperties['jarsigning.keystoreType']
keyStoreLocation = file(keystoreProperties['jarsigning.keystore']).absolutePath
keyStorePassword = keystoreProperties['jarsigning.keystorePassword']
keyPassword = keystoreProperties['jarsigning.keyPassword']
}
project.tasks.named('build').configure {
dependsOn += task
}
} else if (project.name == 'webapp') {
def task = project.tasks.register('signedBootJar', Sign) {
group = 'build'
dependsOn = [ project.tasks.named('bootJar') ]
buildDir = project.buildDir.absolutePath
archiveName = project.tasks.bootJar.archiveFileName
alias = keystoreProperties['jarsigning.alias']
keyStoreType = keystoreProperties['jarsigning.keystoreType']
keyStoreLocation = file(keystoreProperties['jarsigning.keystore']).absolutePath
keyStorePassword = keystoreProperties['jarsigning.keystorePassword']
keyPassword = keystoreProperties['jarsigning.keyPassword']
}
project.tasks.named('build').configure {
dependsOn += task
}
}
}
}
}
abstract class Sign extends DefaultTask {
@Input abstract Property<String> getBuildDir()
@Input abstract Property<String> getArchiveName()
@Input abstract Property<String> getAlias()
@Input abstract Property<String> getKeyStoreType()
@Input abstract Property<String> getKeyStoreLocation()
@Input abstract Property<String> getKeyStorePassword()
@Input abstract Property<String> getKeyPassword()
@TaskAction
void action() {
final String libsDir = buildDir.get() + File.separator + 'libs' + File.separator
ant.signjar(
jar: libsDir + archiveName.get(),
signedjar: libsDir + generateSignedArtifactName(archiveName.get()),
alias: alias.get(),
storetype: keyStoreType.get(),
keystore: keyStoreLocation.get(),
storepass: keyStorePassword.get(),
keypass: keyPassword.get()
)
}
/**
* Generates name with '-signed' suffix added to given artifact's name.
* @param artifactName Original artifact's name.
* @return Artifact's name with '-signed' suffix.
*/
private static String generateSignedArtifactName(String artifactName) {
final int lastDot = artifactName.lastIndexOf('.')
return artifactName.substring(0, lastDot) + '-signed' + artifactName.substring(lastDot)
}
}