sparkle 0.7.2 → 0.7.2.1
raw patch · 2 files changed
+81/−8 lines, 2 files
Files
sparkle.cabal view
@@ -1,5 +1,5 @@ name: sparkle-version: 0.7.2+version: 0.7.2.1 synopsis: Distributed Apache Spark applications in Haskell description: See https://www.stackage.org/package/sparkle. homepage: http://github.com/tweag/sparkle#readme@@ -13,17 +13,18 @@ cabal-version: >=1.10 extra-source-files: cbits/io_tweag_sparkle_Sparkle.h- src/main/java/io/tweag/sparkle/Sparkle.java+ src/main/java/Helper.java src/main/java/io/tweag/sparkle/SparkMain.java- src/main/java/io/tweag/sparkle/kryo/InlineJavaRegistrator.java- src/main/java/io/tweag/sparkle/function/HaskellVoidFunction.java- src/main/java/io/tweag/sparkle/function/HaskellFunction4.java+ src/main/java/io/tweag/sparkle/Sparkle.java+ src/main/java/io/tweag/sparkle/SparkleBase.java+ src/main/java/io/tweag/sparkle/function/HaskellFlatMapFunction.java+ src/main/java/io/tweag/sparkle/function/HaskellFunction.java src/main/java/io/tweag/sparkle/function/HaskellFunction0.java src/main/java/io/tweag/sparkle/function/HaskellFunction2.java- src/main/java/io/tweag/sparkle/function/HaskellFlatMapFunction.java src/main/java/io/tweag/sparkle/function/HaskellFunction3.java- src/main/java/io/tweag/sparkle/function/HaskellFunction.java- src/main/java/Helper.java+ src/main/java/io/tweag/sparkle/function/HaskellFunction4.java+ src/main/java/io/tweag/sparkle/function/HaskellVoidFunction.java+ src/main/java/io/tweag/sparkle/kryo/InlineJavaRegistrator.java CHANGELOG.md README.md build.gradle
+ src/main/java/io/tweag/sparkle/SparkleBase.java view
@@ -0,0 +1,72 @@+package io.tweag.sparkle;++import java.io.*;+import java.net.*;+import java.nio.file.*;+import java.util.ArrayList;+import java.util.Enumeration;+import java.util.Iterator;+import java.util.zip.*;++/* The `SparkleBase` class exists to ensure that appropriate shared objects+ * (those in the 'sparkle-app.zip' archive within the JAR in which this class+ * resides) are dynamically loaded *before* attempting to access any+ * functionality provided by them. The Haskell program (named 'hsapp') is+ * also loaded.+ */+public class SparkleBase {+ static {+ try {+ InputStream in =+ Sparkle.class.getResourceAsStream("/sparkle-app.zip");+ File sparkleAppZipFile =+ File.createTempFile("sparkle-app-", ".zip");+ Files.copy(in, sparkleAppZipFile.toPath(),+ StandardCopyOption.REPLACE_EXISTING);+ in.close();+ try {+ loadApplication(sparkleAppZipFile, "hsapp");+ } finally {+ sparkleAppZipFile.delete();+ }+ } catch (Exception e) {+ System.err.println(e);+ throw new ExceptionInInitializerError(e);+ }+ }++ private static void loadApplication(File archive, String appName)+ throws IOException+ {+ // Extract all files from the .zip archive.+ //+ ZipFile zip = new ZipFile(archive);+ String tmpDir = System.getProperty("java.io.tmpdir");+ Path sparkleAppTmpDir =+ Files.createTempDirectory(Paths.get(tmpDir), "sparkle-app-");+ ArrayList<Path> pathsList = new ArrayList();+ try {+ for (Enumeration e = zip.entries(); e.hasMoreElements(); ) {+ ZipEntry entry = (ZipEntry)e.nextElement();+ InputStream in = zip.getInputStream(entry);+ Path path = sparkleAppTmpDir.resolve(entry.getName());+ pathsList.add(path);+ Files.copy(in, path);+ in.close();+ }+ zip.close();++ // Dynamically load the app.+ //+ System.load(sparkleAppTmpDir.resolve(appName).toString());+ } finally {+ // Delete the app binary and its libraries, now that they are loaded.+ //+ for (Path p : pathsList)+ p.toFile().delete();+ }+ sparkleAppTmpDir.toFile().delete();+ }++ public static native <R> R apply(byte[] cos, Object... args);+}