From e34731bad7d4e5a5596c5fcd78536495b86f56b4 Mon Sep 17 00:00:00 2001 From: Sofus Mortensen Date: Thu, 11 Feb 2016 15:55:52 +0100 Subject: [PATCH] Sorting of files. Create build.gradle in contracts. Comments. --- build.gradle | 67 -------------------------------------- contracts/build.gradle | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 67 deletions(-) create mode 100644 contracts/build.gradle diff --git a/build.gradle b/build.gradle index 470e2bfd14..6ed89c741b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,3 @@ -import com.google.common.io.ByteStreams -import java.nio.file.Files -import java.nio.file.Paths -import java.nio.file.StandardCopyOption -import java.nio.file.attribute.FileTime -import java.util.zip.ZipEntry -import java.util.zip.ZipOutputStream -import java.util.zip.ZipFile - group 'com.r3cev.prototyping' version '1.0-SNAPSHOT' @@ -36,8 +27,6 @@ buildscript { // Dokka (JavaDoc equivalent for Kotlin) download is huge so just comment this out for now. //classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.6" - - classpath "com.google.guava:guava:19.0" } } @@ -128,59 +117,3 @@ task runDemoSeller(type: JavaExec, dependsOn: ':classes') { args = ['--dir=seller', '--fake-trade-with=localhost', '--network-address=localhost:31338', '--timestamper-identity-file=buyer/identity-public', '--timestamper-address=localhost'] } -class CanonicalizerPlugin implements Plugin { - void apply(Project project) { - - project.getTasks().getByName('jar').doLast() { - - def zipPath = (String) project.jar.archivePath - def destPath = Files.createTempFile("processzip", null) - - def zeroTime = FileTime.fromMillis(0) - - def input = new ZipFile(zipPath) - def entries = input.entries() - - def output = new ZipOutputStream(new FileOutputStream(destPath.toFile())) - output.setMethod(ZipOutputStream.STORED) - - while (entries.hasMoreElements()) { - def entry = entries.nextElement() - - def newEntry = new ZipEntry( entry.name ) - - newEntry.setLastModifiedTime(zeroTime) - newEntry.setCreationTime(zeroTime) - newEntry.compressedSize = -1 - newEntry.size = entry.size - newEntry.crc = entry.crc - - output.putNextEntry(newEntry) - - ByteStreams.copy(input.getInputStream(entry), output) - - output.closeEntry() - } - output.close() - input.close() - - Files.move(destPath, Paths.get(zipPath), StandardCopyOption.REPLACE_EXISTING) - } - - } -} - -project(':contracts') { - apply plugin: 'java' - apply plugin: 'kotlin' - - apply plugin: CanonicalizerPlugin - - repositories { - mavenCentral() - } - - dependencies { - compile rootProject - } -} diff --git a/contracts/build.gradle b/contracts/build.gradle new file mode 100644 index 0000000000..7eb8280f27 --- /dev/null +++ b/contracts/build.gradle @@ -0,0 +1,74 @@ +import com.google.common.io.ByteStreams +import java.nio.file.Files +import java.nio.file.Paths +import java.nio.file.StandardCopyOption +import java.nio.file.attribute.FileTime +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream +import java.util.zip.ZipFile + +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "com.google.guava:guava:19.0" + } +} + +// Custom Gradle plugin that attempts to make the resulting jar file deterministic. +// Ie. same contract definition should result when compiled in same jar file. +// This is done by removing date time stamps from the files inside the jar. +class CanonicalizerPlugin implements Plugin { + void apply(Project project) { + + project.getTasks().getByName('jar').doLast() { + + def zipPath = (String) project.jar.archivePath + def destPath = Files.createTempFile("processzip", null) + + def zeroTime = FileTime.fromMillis(0) + + def input = new ZipFile(zipPath) + def entries = input.entries().toList().sort { it.name } + + def output = new ZipOutputStream(new FileOutputStream(destPath.toFile())) + output.setMethod(ZipOutputStream.DEFLATED) + + entries.each { + def newEntry = new ZipEntry( it.name ) + + newEntry.setLastModifiedTime(zeroTime) + newEntry.setCreationTime(zeroTime) + newEntry.compressedSize = -1 + newEntry.size = it.size + newEntry.crc = it.crc + + output.putNextEntry(newEntry) + + ByteStreams.copy(input.getInputStream(it), output) + + output.closeEntry() + } + output.close() + input.close() + + Files.move(destPath, Paths.get(zipPath), StandardCopyOption.REPLACE_EXISTING) + } + + } +} + +apply plugin: 'java' +apply plugin: 'kotlin' + +apply plugin: CanonicalizerPlugin + +repositories { + mavenCentral() +} + +dependencies { + compile rootProject +} \ No newline at end of file