-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
384 lines (329 loc) · 11.4 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
* Copyright 2012-2021 Mathias Herberts
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Dependency on gradle-git to download juds to download juds
// @see https://github.com/ajoberstar/gradle-git
//
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:0.2.3'
}
}
plugins {
id 'java'
id 'eclipse'
id 'war'
id 'maven-publish'
id 'signing'
}
sourceCompatibility = 1.6
configurations {
tools
archives
ossclient
}
import org.ajoberstar.gradle.git.tasks.*;
//
// Publishing infos
//
group = 'com.geoxp.oss'
version = '1.0.1'
//
// Retrieve/Configure/Build JUDS
//
task clonejuds(type: GitClone) {
def destination = file('juds')
uri = 'https://github.com/mcfunley/juds.git'
destinationPath = destination
bare = false
enabled = !destination.exists() //to clone only once
}
task confjuds(type: Exec, dependsOn: 'clonejuds') {
workingDir './juds'
if (!new File('./juds/juds-0.94.jar').exists()) {
commandLine './configure','CFLAGS=-I' + System.getProperty('java.home') + '/include'
} else {
commandLine 'ls', 'juds-0.94.jar'
}
}
task buildjuds(type: Exec, dependsOn: 'confjuds') {
workingDir './juds'
if (!new File('./juds/juds-0.94.jar').exists()) {
commandLine 'make'
} else {
commandLine 'ls', 'juds-0.94.jar'
}
}
//
// Repositories for dependency resolution
//
repositories {
mavenCentral()
}
//
// Project dependencies
//
dependencies {
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.47'
compile group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.47'
compile group: 'org.bouncycastle', name: 'bcpg-jdk15on', version: '1.47'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.inject.extensions', name: 'guice-servlet', version: '3.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.2'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.2.5'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.5'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.6'
compile group: 'org.apache.pig', name: 'pig', version: '0.8.0', transitive: false
compile group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.3.5', transitive: false
compile group: 'org.apache.hadoop', name: 'hadoop-core', version: '0.20.2', transitive: false
compile group: 'log4j', name: 'log4j', version: '1.2.15', transitive: false
compile files('juds/juds-0.94.jar')
tools files('tools/jarjar-1.4.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
war {
ext.clspth = []
for (f in classpath) {
if (!f.toString().endsWith('juds-0.94.jar')) {
ext.clspth.add(f)
}
}
classpath = ext.clspth
}
test {
scanForTestClasses = true
//makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
//listening to test execution events
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
build.dependsOn {
'buildjuds'
}
//
// Handly tasks to interact with an OSS
//
task(OSSGenMasterSecret, dependsOn: 'build', type: JavaExec) {
doFirst {
ext.props = ['oss.url', 'oss.pubring', 'oss.keyid', 'oss.k']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL -Doss.pubring=PUBRING0,PUBRING1,... -Doss.keyid=KEYID0,KEYID1,... -Doss.k=K OSSGenMasterSecret')
}
}
}
main = 'com.geoxp.oss.client.OSSGenMasterSecret'
classpath = sourceSets.main.runtimeClasspath
args System.getProperty('oss.url',''), System.getProperty('oss.pubring',''), System.getProperty('oss.keyid',''), System.getProperty('oss.k','')
}
task(OSSInit, dependsOn: 'build') {
doFirst {
ext.props = ['oss.url']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL [-Doss.sshkey=SSH_KEY_FINGERPRINT] OSSInit\nPassing the raw init secret via stdin.')
}
}
ext.cp = ''
for(f in sourceSets.main.runtimeClasspath) {
ext.cp = ext.cp + ':' + f
}
println 'To initialize OSS run the following command:'
println ''
println 'gpg -d XXXXXXXX.oss | java -cp build/libs/oss-client.jar com.geoxp.oss.client.OSSInit ' + System.getProperty('oss.url','') + ' ' + System.getProperty('oss.sshkey','')
}
}
task(OSSPutSecret, dependsOn: 'build') {
doFirst {
ext.props = ['oss.url','oss.secret']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL -Doss.secret=SECRET_NAME [-Doss.sshkey=SSH_KEY_FINGERPRINT] OSSPutSecret\nPassing the secret to store via stdin.')
}
}
println 'To store a secret, run the following command:'
println ''
println 'cat SECRET | java -cp build/libs/oss-client.jar com.geoxp.oss.client.OSSPutSecret ' + System.getProperty('oss.url','') + ' ' + System.getProperty('oss.secret','') + ' ' + System.getProperty('oss.sshkey','')
}
}
task(OSSWrap, dependsOn: 'build') {
doFirst {
ext.props = ['oss.url','oss.secret']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL -Doss.secret=SECRET_NAME [-Doss.sshkey=SSH_KEY_FINGERPRINT] OSSWrap\nPassing data to wrap via stdin.\nSecret must be of length 128, 192 or 256 bits.')
}
}
println 'To wrap data, run the following command:'
println ''
println 'cat DATA | java -cp build/libs/oss-client.jar com.geoxp.oss.client.OSSWrap ' + System.getProperty('oss.url','') + ' ' + System.getProperty('oss.secret','') + ' ' + System.getProperty('oss.sshkey','')
}
}
task(OSSGenSecret, dependsOn: 'build', type: JavaExec) {
doFirst {
ext.props = ['oss.url', 'oss.secret']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL -Doss.secret=SECRET_NAME [-Doss.sshkey=SSH_KEY_FINGERPRINT] OSSGenSecret')
}
}
}
main = 'com.geoxp.oss.client.OSSGenSecret'
classpath = sourceSets.main.runtimeClasspath
args System.getProperty('oss.url',''), System.getProperty('oss.secret',''), System.getProperty('oss.sshkey','')
}
task(OSSGetSecret, dependsOn: 'build', type: JavaExec) {
doFirst {
ext.props = ['oss.url', 'oss.secret']
for (prop in ext.props) {
if (null == System.getProperty(prop)) {
throw new RuntimeException('Usage: gradle -Doss.url=OSS_URL -Doss.secret=SECRET_NAME [-Doss.sshkey=SSH_KEY_FINGERPRINT] OSSGetSecret')
}
}
}
main = 'com.geoxp.oss.client.OSSGetSecret'
classpath = sourceSets.main.runtimeClasspath
args System.getProperty('oss.url',''), System.getProperty('oss.secret',''), System.getProperty('oss.sshkey', '')
}
task ossClientJar(type: Jar, dependsOn: jar) {
inputs.files jar.archivePath
appendix = 'client'
doLast {
project.ant {
taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.tools.asPath
jarjar(jarfile: archivePath) {
zipfileset(src: jar.archivePath) {
exclude(name: 'com/geoxp/oss/servlet/**')
exclude(name: 'com/geoxp/oss/OSS.class')
exclude(name: 'com/geoxp/oss/OSS$*.class')
exclude(name: 'com/geoxp/oss/KeyStore.class')
exclude(name: 'com/geoxp/oss/DirectoryHierarchyKeyStore.class')
}
//sourceSets.main.allSource.findAll { file -> println 'FILE >>> ' + file }
//
// Iterate over .jar files
//
configurations.runtime.files.findAll {file ->
['log4', 'hadoop-', 'pig-', 'slf4j-', 'servlet-api', 'guice-servlet', 'guice', 'javax.inject', 'aopalliance', 'asm'].every { !file.name.startsWith(it) }
}.each {jarjarFile ->
zipfileset(src: jarjarFile) {
exclude(name: 'META-INF/**')
}
}
rule pattern: "com.geoxp.oss.**", result: "@0"
rule pattern: "com.etsy.net.**", result: '@0'
rule pattern: "org.apache.pig.**", result: "@0"
rule pattern: "org.apache.hadoop.**", result: "@0"
rule pattern: "org.w3c.**", result: "@0"
rule pattern: "org.xml.**", result: "@0"
rule pattern: "org.apache.log4j.**", result: "@0"
rule pattern: "org.**", result: "com.geoxp.oss.jarjar.@0"
rule pattern: "net.**", result: "com.geoxp.oss.jarjar.@0"
rule pattern: "com.**", result: "com.geoxp.oss.jarjar.@0"
}
}
}
}
publish {
dependsOn ossClientJar
}
task sourceJar(type: Jar) {
archiveClassifier = "sources"
}
task javadocJar(type: Jar) {
archiveClassifier = "javadoc"
}
publishing {
publications {
OSSClientPublication(MavenPublication) {
artifactId = 'oss-client'
artifact(file("${buildDir}/libs/oss-client-" + version + ".jar"))
artifact sourceJar
artifact javadocJar
pom {
name = 'Open Secret Server Client'
// optionally artifactId can be defined here
description = 'A java client for the Open Secret Server'
url = 'https://github.com/hbs/oss'
scm {
connection = 'scm:git:git://github.com/hbs/oss.git'
developerConnection = 'scm:git:git://github.com/hbs/oss.git'
url = 'https://github.com/hbs/oss'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'herberts'
name = 'Mathias Herberts'
email = '[email protected]'
}
}
}
}
}
repositories {
maven {
def stagingRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : stagingRepoUrl
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
java {
withJavadocJar()
withSourcesJar()
}
javadoc {
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options
{
setMemberLevel JavadocMemberLevel.PUBLIC
setAuthor true
links "https://docs.oracle.com/javase/8/docs/api/"
}
}
artifacts {
ossclient ossClientJar, javadocJar, sourcesJar
}
signing {
useGpgCmd()
sign publishing.publications.OSSClientPublication
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}