forked from cwgit/ximix
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
705 lines (529 loc) · 20.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.commons:commons-io:1.3.2'
}
}
configurations {
jacocoant
jacoco
antjunit
console_install
}
dependencies {
jacoco 'org.jacoco:org.jacoco.agent:0.6.2.+'
jacocoant 'org.jacoco:org.jacoco.ant:0.6.2.+'
antjunit 'org.apache.ant:ant-junit:1.8.4'
}
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
configurations {
codeCoverage
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: new File(rootDir, 'libs'), include: '*.jar')
compile 'org.jacoco:org.jacoco.agent:0.6.2.+'
codeCoverage group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.6.2.+', classifier: 'runtime'
}
test {
jvmArgs "-javaagent:${configurations.codeCoverage.singleFile}=destfile=${rootDir}/build/coverage/jacoco.exec,sessionid=HSServ,append=true",
'-Djacoco=true',
'-Xms128m',
'-Xmx512m',
'-XX:MaxPermSize=128m'
}
}
subprojects {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
version=0.9
group='com.cryptoworkshop'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
dependencies {
compile project(':common')
compile project(':node')
}
//
// Sub projects.
//
project(':client') {
dependencies {
compile project(':common')
}
jar {
baseName= rootProject.name+"-client";
}
}
project(':common') {
jar {
baseName= rootProject.name+"-common";
}
}
project(':console') {
dependencies {
compile project(':common')
compile project(':node')
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.0.4.+'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.0'
// compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.50'
// compile group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.50'
}
jar {
baseName= rootProject.name+"-console";
}
}
project(':demo') {
dependencies {
compile project(':common')
compile project(':node')
}
jar {
baseName= rootProject.name+"-demo";
}
}
project(':node') {
dependencies {
compile project(':common')
compile project(':client')
}
jar {
baseName= rootProject.name+"-node";
}
}
project(':test') {
dependencies {
compile project(':common')
compile project(':node')
}
test {
testLogging.showStandardStreams = true
}
jar {
baseName= rootProject.name+"-test";
}
}
project(':installer') {
jar {
baseName= rootProject.name+"-installer";
}
}
def apiProjects() {
subprojects.findAll { project -> (project.name == 'client' || project.name == 'common' || project.name == 'node') }
}
task apiJavadoc(type: Javadoc) {
source apiProjects().collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = new File(projectDir, 'build/docs')
}
task remove_libs << {
File root = new File(projectDir, libsJarPath);
if (root.exists()) {
org.apache.commons.io.FileUtils.deleteDirectory(root);
System.out.println(" Removed libs, use 'gradle fetch_libs' to reload.");
}
}
task fetch_libs << {
File root = new File(projectDir, libsJarPath);
if (root.exists()) {
org.apache.commons.io.FileUtils.deleteDirectory(root);
}
root.mkdirs();
fetchFile(providerRemoteUrl, root);
fetchFile(pkixRemoteUrl, root);
fetchFile(jpbcRemoteUrl1, root);
fetchFile(jpbcRemoteUrl2, root);
fetchFile(jpbcRemoteUrl3, root);
fetchFile(jpbcRemoteUrl4, root);
fetchFile(mapdbRemoteUrl, root);
// Surrey dependencies for Vote Unpacking
['commons-codec-1.7.jar',
'json-20090211.jar',
'slf4j-api-1.7.2.jar',
'slf4j-nop-1.7.2.jar',
'vVoteLibrary-20131217011536.jar',
'vVoteTableBuilding.jar'
].each { i ->
fetchFile("http://www.cryptoworkshop.com/libs/" + i, root);
}
root = new File(projectDir, "console/libs/");
if (root.exists())
{
org.apache.commons.io.FileUtils.deleteDirectory(root);
}
root.mkdirs();
['jackson-annotations-2.2.0.jar',
'jackson-core-2.2.0.jar',
'jackson-databind-2.2.0.jar',
'jetty-http-9.0.4.jar',
'jetty-io-9.0.4.jar',
'jetty-server-9.0.4.jar',
'jetty-util-9.0.4.jar',
'javax.servlet-3.0.0.jar'
].each { i ->
fetchFile(cryptoWorkshopLibsPrefix + "/" + i, root);
}
fetchFile(providerRemoteUrl, root);
fetchFile(pkixRemoteUrl, root);
// Surrey dependencies for Vote Unpacking
['commons-codec-1.7.jar',
'json-20090211.jar',
'slf4j-api-1.7.2.jar',
'vVoteLibrary-20131217011536.jar',
'vVoteTableBuilding.jar'
].each { i ->
org.apache.commons.io.FileUtils.copyFileToDirectory(new File("libs/" + i), root);
}
}
task test_foo << {
System.out.println(project(':common').file("build/lib/common.jar"));
}
task coverage_report(dependsOn: 'compileTestJava') << {
//
// Get jacoco jar.
//
File jacocoJar = null;
project(':common').configurations.compile.each { file ->
if (file.name.indexOf('jacoco') > 0) {
jacocoJar = file;
}
}
File root = new File(projectDir, "build/coverage");
root.mkdirs();
File coverageReport = new File(root, "reports");
//
// Delete old reports.
//
if (coverageReport.exists()) {
org.apache.commons.io.FileUtils.deleteDirectory(coverageReport);
}
coverageReport.mkdirs();
ant.taskdef(name: "jacocoreport", classname: "org.jacoco.ant.ReportTask", classpath: configurations.jacocoant.asPath);
ant {
jacocoreport {
executiondata {
fileset(dir: "${rootDir}/build/coverage/") {
file(file: 'jacoco.exec')
}
}
structure(name: rootProject.name) {
classfiles {
fileset dir: "${rootDir}/common/build/classes/main"
fileset dir: "${rootDir}/node/build/classes/main"
fileset dir: "${rootDir}/client/build/classes/main"
}
// this is for Windows
sourcefiles(encoding: 'UTF8') {
fileset dir: "${rootDir}/common/src/main/java"
fileset dir: "${rootDir}/node/src/main/java"
fileset dir: "${rootDir}/client/src/main/java"
}
}
xml destfile: "${coverageReport}/ximix.xml"
html destdir: "${coverageReport}"
}
}
//
// Delete source file..
//
new File("${rootDir}/build/coverage/jacoco.exe").delete();
println("\r\nCoverage Report can be found in: \r\n" + coverageReport);
}
task make_console_installer(dependsOn: 'jar') << {
if (!System.properties.containsKey("config")) {
System.err.println("No config specified run with '-Dconfig=/path/to/console.xml'");
System.exit(-1);
}
if (!System.properties.containsKey("mixnet")) {
System.err.println("No mixnet config specified run with '-Dmixnet=/path/to/mixnet.xml'");
System.exit(-1);
}
File consoleConfigFile = new File(System.properties.getProperty("config"));
if (!consoleConfigFile.exists()) {
System.err.println("Could not find console config file:" + consoleConfigFile.getCanonicalPath());
System.exit(-1);
}
File mixnetConfigFile = new File(System.properties.getProperty("mixnet"));
if (!mixnetConfigFile.exists()) {
System.err.println("Could not find mixnet config file:" + mixnetConfigFile.getCanonicalPath());
System.exit(-1);
}
println("\r\nMaking Console Installer Jar\r\n");
File root = new File(projectDir, "build/installers");
//
// Final jar will go in here.
//
if (root.exists()) {
org.apache.commons.io.FileUtils.deleteDirectory(root);
}
root.mkdirs();
//
// Stage for jar layout.
//
File installerJarStageDir = new File(root, "/stage");
installerJarStageDir.mkdirs();
//
// Setup control file.
//
FileWriter sw = new FileWriter(new File(installerJarStageDir, "install.xml"));
PrintWriter pw = new PrintWriter(sw);
pw.println('<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>');
pw.println('<installer>');
pw.println(' <installation>');
pw.println(' <name>Ximix</name>');
pw.println(' <description></description>');
pw.println(' <id>install_' + System.currentTimeMillis() + '</id>');
pw.println(' <prop name="installDir" type="file" value="./"/>');
pw.println(' <step name="askInstallLocation"/>');
pw.println(' <movements>');
pw.println(' <id>1</id>');
pw.println(' <movement src="ximix-console/" recursive="true"></movement>');
pw.println(' </movements>');
pw.println(' <!-- Make executable if in a posix environment -->');
pw.println(' <posix-exec relpath="ximix-console/bin/start.sh" perm="rwxr-xr-x"/>');
pw.println(' <posix-exec relpath="ximix-console/bin/stop.sh" perm="rwxr-xr-x"/>');
pw.println(' </installation>');
pw.println('</installer>');
pw.flush();
pw.close();
File ximixStage = new File(installerJarStageDir, "ximix-console");
File confStageDir = new File(ximixStage, "conf");
org.apache.commons.io.FileUtils.copyFileToDirectory(consoleConfigFile, confStageDir);
org.apache.commons.io.FileUtils.copyFileToDirectory(mixnetConfigFile, confStageDir);
File stagedLibs = new File(ximixStage, "/libs");
stagedLibs.mkdirs();
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':client').jar.archivePath, stagedLibs);
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':common').jar.archivePath, stagedLibs);
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':node').jar.archivePath, stagedLibs);
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':console').jar.archivePath, stagedLibs);
//
// Console dependencies..
//
org.apache.commons.io.FileUtils.copyDirectory(new File("${rootDir}/console/libs/"), stagedLibs);
//
// The other includes like shell scripts
//
org.apache.commons.io.FileUtils.copyDirectory(new File(project(':console').projectDir, "includes/ximix-console/"), ximixStage);
//
// This makes a node stand alone uses the ant jar task..
//
File jarFile = new File(root, "XimixConsoleInstaller.jar");
ant.jar(destfile: jarFile, manifest: new File(projectDir, "installer/manifest/MANIFEST.mf")) {
fileset(dir: new File(projectDir, 'installer/build/classes/main/'));
fileset(dir: installerJarStageDir);
}
println("\r\nInstaller Jar: " + jarFile.getCanonicalFile());
println("The installer jar can run using:" +
"\r\njava -jar " + jarFile.getCanonicalPath());
}
task make_node_installer(dependsOn: 'jar') << {
Console console = System.console();
boolean hasConfigs = true;
File mixnetConfigFile = null;
ArrayList<File> nodeConfigs = new ArrayList<File>();
if (System.properties.containsKey("network")) {
String[] paths = new String(System.properties["network"]).split(",");
if (paths.length < 2) {
System.err.println("\r\nThe mixnet config file and at least one node config file must be specified in the -Dnetwork property.");
System.exit(-1);
}
mixnetConfigFile = new File(paths[0].trim());
for (int t = 1; t < paths.length; t++) {
nodeConfigs.add(new File(paths[t].trim()));
}
//
// Check for file existence, structure and existence of one key node.
//
if (!mixnetConfigFile.exists() || mixnetConfigFile.isDirectory()) {
System.err.println("Mixnet config file '" + mixnetConfigFile.getAbsolutePath() + "' does not exist or is a directory.");
System.exit(-1);
}
if (!xmlFileStartsWith(mixnetConfigFile, "nodes")) {
System.err.println("Mixnet config file '" + mixnetConfigFile.getAbsolutePath() + "' must contain a 'nodes' tag.");
System.exit(-1);
}
for (File nodeFile : nodeConfigs) {
if (!nodeFile.exists() || nodeFile.isDirectory()) {
System.err.println("Node config file '" + nodeFile + "' does not exist or is a directory.");
System.exit(-1);
}
if (!xmlFileStartsWith(nodeFile, "node")) {
System.err.println("Node config file '" + nodeFile + "' must contain a 'node' tag");
System.exit(-1);
}
}
} else {
println("\r\n\r\nConfiguration files can be nominated to be included in the installation.");
println("\r\nUse:\r\ngradle make_node_installer -Dnetwork=<mixnet.xml>,<node1.xml>,<node2.xml> ... <nodeX.xml>");
println("\r\nThe network property is a comma separated list of paths to: ");
println("1. Mixnet Configuration <mixnet.xml>");
println("2. Node configuration files <nodeX.xml>");
println("\r\nExample:\r\ngradle make_node_installer -Dnetwork=mixnet.xml,node1.xml,node2.xml\r\n");
println();
println("When that property is set the task will generate an executable jar file that")
println("will create separate complete node installations for each node.xml file");
println("specified.");
println("The first file must be the mixnet.xml configuration that defines the mixnet")
println("and connection details concerning each node.\r\n");
println("See Wiki for more details.");
println();
// String l = console.readLine("\r\nConfirm, generate a single node installer with NO inbuilt configuration: Yes, [No] >");
// if (!l.toLowerCase().contains("y")) {
// println("\r\nExiting installer generation.");
// System.exit(0);
// }
hasConfigs = false;
}
println("\r\nMaking Node Installer Jar\r\n");
File root = new File(projectDir, "build/installers");
//
// Final jar will go in here.
//
if (root.exists()) {
org.apache.commons.io.FileUtils.deleteDirectory(root);
}
root.mkdirs();
//
// Stage for jar layout.
//
File installerJarStageDir = new File(root, "/stage");
installerJarStageDir.mkdirs();
//
// Setup control file.
//
FileWriter sw = new FileWriter(new File(installerJarStageDir, "install.xml"));
PrintWriter pw = new PrintWriter(sw);
pw.println('<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>');
pw.println('<installer>');
pw.println(' <installation>');
pw.println(' <name>Ximix</name>');
pw.println(' <description></description>');
pw.println(' <id>install_' + System.currentTimeMillis() + '</id>');
pw.println(' <prop name="installDir" type="file" value="./"/>');
pw.println(' <step name="askInstallLocation"/>');
pw.println(' <movements>');
pw.println(' <id>1</id>');
// if (hasConfigs) {
// for (int t = 0; t < nodeConfigs.size(); t++) {
// pw.println(' <movement src="node' + t + '/" recursive="true"></movement>');
// }
// } else {
pw.println(' <movement src="ximix/" recursive="true"></movement>');
// }
pw.println(' </movements>');
pw.println(' <!-- Make executable if in a posix environment -->');
// if (hasConfigs) {
// for (int t = 0; t < nodeConfigs.size(); t++) {
// pw.println(' <posix-exec relpath="node' + t + '/bin/start.sh" perm="rwxr-xr-x"/>');
// }
// } else {
pw.println(' <posix-exec relpath="ximix/bin/start.sh" perm="rwxr-xr-x"/>');
pw.println(' <posix-exec relpath="ximix/bin/stop.sh" perm="rwxr-xr-x"/>');
// }
pw.println(' </installation>');
pw.println('</installer>');
pw.flush();
pw.close();
// org.apache.commons.io.FileUtils.copyFile(new File(project(':installer').projectDir, "src/main/resources/install_node.xml"), new File(installerJarStageDir, "install.xml"));
//
//
//
File ximixStage = new File(installerJarStageDir, "ximix");
File stagedLibs = new File(ximixStage, "/libs");
stagedLibs.mkdirs();
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':client').jar.archivePath, stagedLibs);
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':common').jar.archivePath, stagedLibs);
org.apache.commons.io.FileUtils.copyFileToDirectory(project(':node').jar.archivePath, stagedLibs);
// The two betas.
org.apache.commons.io.FileUtils.copyDirectory(new File("${rootDir}/libs/"), stagedLibs);
//
// The other includes like shell scripts
//
org.apache.commons.io.FileUtils.copyDirectory(new File(project(':installer').projectDir, "includes/ximix/"), ximixStage);
if (hasConfigs) {
for (int t = 0; t < nodeConfigs.size(); t++) {
populateNodeStage("node" + (t + 1), ximixStage, mixnetConfigFile, nodeConfigs.get(t));
}
} else {
populateNodeStage("node", ximixStage, null, null);
}
//
// This makes a node stand alone uses the ant jar task..
//
File jarFile = new File(root, "XimixNodeInstaller.jar");
ant.jar(destfile: jarFile, manifest: new File(projectDir, "installer/manifest/MANIFEST.mf")) {
fileset(dir: new File(projectDir, 'installer/build/classes/main/'));
fileset(dir: installerJarStageDir);
}
println("\r\nInstaller Jar: " + jarFile.getCanonicalFile());
println("The installer jar can run using:" +
"\r\njava -jar " + jarFile.getCanonicalPath());
}
void populateNodeStage(String name, File installerJarStageDir, File mixnetConfig, File nodeConfig) {
File nodeStageDir = new File(installerJarStageDir, name);
//
// Add in configs.
//
File confDir = new File(nodeStageDir, "conf/");
confDir.mkdirs();
//
// Config files are copied into place and renamed to default names.
//
if (mixnetConfig != null) {
org.apache.commons.io.FileUtils.copyFile(mixnetConfig, new File(confDir, "mixnet.xml"));
}
if (nodeConfig != null) {
org.apache.commons.io.FileUtils.copyFile(nodeConfig, new File(confDir, "node.xml"));
org.apache.commons.io.FileUtils.copyFile(new File(nodeConfig.getParentFile(), "nodeCaStore.p12"), new File(confDir, "nodeCaStore.p12"));
org.apache.commons.io.FileUtils.copyFile(new File(nodeConfig.getParentFile(), "trustCa.pem"), new File(confDir, "trustCa.pem"));
}
}
/**
* Fetch a file at url and save it into the directory.
* The filename used is taken from the url.
*/
void fetchFile(String url, File directory) {
URL u = new URL(url);
String f = u.getFile();
f = f.substring(f.lastIndexOf("/") + 1);
System.out.print("Fetching '" + f + "' from '" + url + "' ... ");
org.apache.commons.io.FileUtils.copyURLToFile(u, new File(directory, f));
System.out.println("Complete");
}
boolean xmlFileStartsWith(File path, String nodename) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
Document doc = docBuilder.parse(path);
Element xmlNode = doc.getDocumentElement();
if (nodename.equals(xmlNode.getNodeName())) {
return true;
}
NodeList nl = xmlNode.getChildNodes()
for (int t = 0; t < nl.length; t++) {
if (nodename.equals(nl.item(t).getNodeName())) {
return true;
}
}
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
return false;
}