From f783d8466d2b15f41a7bb3936891a4f20454a33f Mon Sep 17 00:00:00 2001
From: Andras Slemmer <andras.slemmer@r3cev.com>
Date: Fri, 26 Aug 2016 12:11:23 +0100
Subject: [PATCH 1/2] build: Move definition of CanonicalizerPlugin into
 buildSrc

---
 .../main/groovy/CanonicalizerPlugin.groovy    | 48 +++++++++++++++++++
 contracts/build.gradle                        | 46 +-----------------
 contracts/isolated/build.gradle               | 46 +-----------------
 3 files changed, 50 insertions(+), 90 deletions(-)
 create mode 100644 buildSrc/src/main/groovy/CanonicalizerPlugin.groovy

diff --git a/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy b/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy
new file mode 100644
index 0000000000..0540487316
--- /dev/null
+++ b/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy
@@ -0,0 +1,48 @@
+import org.gradle.api.*
+
+import java.util.zip.ZipEntry
+import java.util.zip.ZipFile
+import java.util.zip.ZipOutputStream
+
+// 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<Project> {
+    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)
+        }
+
+    }
+}
diff --git a/contracts/build.gradle b/contracts/build.gradle
index 3cbe693a47..ab7ef1953e 100644
--- a/contracts/build.gradle
+++ b/contracts/build.gradle
@@ -18,51 +18,7 @@ buildscript {
     }
 }
 
-// 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<Project> {
-    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: 'kotlin'
-
 apply plugin: CanonicalizerPlugin
 
 repositories {
@@ -87,4 +43,4 @@ sourceSets {
             srcDir "../config/test"
         }
     }
-}
\ No newline at end of file
+}
diff --git a/contracts/isolated/build.gradle b/contracts/isolated/build.gradle
index 480fc6df48..2de6c2c765 100644
--- a/contracts/isolated/build.gradle
+++ b/contracts/isolated/build.gradle
@@ -18,51 +18,7 @@ buildscript {
     }
 }
 
-// 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<Project> {
-    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: 'kotlin'
-
 apply plugin: CanonicalizerPlugin
 
 repositories {
@@ -85,4 +41,4 @@ sourceSets {
             srcDir "../../config/test"
         }
     }
-}
\ No newline at end of file
+}

From 1f14fe0705e8b2d0a4dae54d6de5d1fd5b6e284e Mon Sep 17 00:00:00 2001
From: Andras Slemmer <andras.slemmer@r3cev.com>
Date: Fri, 26 Aug 2016 12:31:09 +0100
Subject: [PATCH 2/2] build: Fix CanonicalizerPlugin dependencies

---
 buildSrc/build.gradle                         |  7 +++++++
 .../main/groovy/CanonicalizerPlugin.groovy    |  6 +++++-
 contracts/build.gradle                        | 20 -------------------
 contracts/isolated/build.gradle               | 20 -------------------
 4 files changed, 12 insertions(+), 41 deletions(-)
 create mode 100644 buildSrc/build.gradle

diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
new file mode 100644
index 0000000000..2f036797bc
--- /dev/null
+++ b/buildSrc/build.gradle
@@ -0,0 +1,7 @@
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    compile "com.google.guava:guava:19.0"
+}
diff --git a/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy b/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy
index 0540487316..6b6b87b483 100644
--- a/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy
+++ b/buildSrc/src/main/groovy/CanonicalizerPlugin.groovy
@@ -1,8 +1,12 @@
+import com.google.common.io.ByteStreams
 import org.gradle.api.*
-
 import java.util.zip.ZipEntry
 import java.util.zip.ZipFile
 import java.util.zip.ZipOutputStream
+import java.nio.file.Files
+import java.nio.file.attribute.FileTime
+import java.nio.file.Paths
+import java.nio.file.StandardCopyOption
 
 // Custom Gradle plugin that attempts to make the resulting jar file deterministic.
 // Ie. same contract definition should result when compiled in same jar file.
diff --git a/contracts/build.gradle b/contracts/build.gradle
index ab7ef1953e..05d7bee07d 100644
--- a/contracts/build.gradle
+++ b/contracts/build.gradle
@@ -1,23 +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.ZipFile
-import java.util.zip.ZipOutputStream
-
-buildscript {
-    repositories {
-        mavenCentral()
-    }
-
-    dependencies {
-        classpath "com.google.guava:guava:19.0"
-    }
-}
-
 apply plugin: 'kotlin'
 apply plugin: CanonicalizerPlugin
 
diff --git a/contracts/isolated/build.gradle b/contracts/isolated/build.gradle
index 2de6c2c765..7e5dd359fa 100644
--- a/contracts/isolated/build.gradle
+++ b/contracts/isolated/build.gradle
@@ -1,23 +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.ZipFile
-import java.util.zip.ZipOutputStream
-
-buildscript {
-    repositories {
-        mavenCentral()
-    }
-
-    dependencies {
-        classpath "com.google.guava:guava:19.0"
-    }
-}
-
 apply plugin: 'kotlin'
 apply plugin: CanonicalizerPlugin