From a1585ab27c4b222d51c881ca608c189cb2063795 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 17 Feb 2016 20:48:11 +0100 Subject: [PATCH] Java 6 friendliness --- .../src/main/java/coursier/Bootstrap.java | 39 ++++++++++++++----- build.sbt | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/bootstrap/src/main/java/coursier/Bootstrap.java b/bootstrap/src/main/java/coursier/Bootstrap.java index 220ed7284..b0899fd7e 100644 --- a/bootstrap/src/main/java/coursier/Bootstrap.java +++ b/bootstrap/src/main/java/coursier/Bootstrap.java @@ -51,7 +51,7 @@ public class Bootstrap { } static Map readIsolationContexts(File jarDir, String[] isolationIDs, String bootstrapProtocol, ClassLoader loader) throws IOException { - final Map perContextURLs = new LinkedHashMap<>(); + final Map perContextURLs = new LinkedHashMap(); for (String isolationID: isolationIDs) { String[] strUrls = readStringSequence("bootstrap-isolation-" + isolationID + "-jar-urls"); @@ -69,7 +69,7 @@ public class Bootstrap { // http://stackoverflow.com/questions/872272/how-to-reference-another-property-in-java-util-properties/27724276#27724276 public static Map loadPropertiesMap(InputStream s) throws IOException { - final Map ordered = new LinkedHashMap<>(); + final Map ordered = new LinkedHashMap(); //Hack to use properties class to parse but our map for preserved order Properties bp = new Properties() { @Override @@ -83,7 +83,7 @@ public class Bootstrap { final Pattern propertyRegex = Pattern.compile(Pattern.quote("${") + "[^" + Pattern.quote("{[()]}") + "]*" + Pattern.quote("}")); - final Map resolved = new LinkedHashMap<>(ordered.size()); + final Map resolved = new LinkedHashMap(ordered.size()); for (String k : ordered.keySet()) { String value = ordered.get(k); @@ -132,6 +132,25 @@ public class Bootstrap { return new File(jarDir, fileName); } + // from http://www.java2s.com/Code/Java/File-Input-Output/Readfiletobytearrayandsavebytearraytofile.htm + static void writeBytesToFile(File file, byte[] bytes) throws IOException { + BufferedOutputStream bos = null; + + try { + FileOutputStream fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + bos.write(bytes); + } finally { + if (bos != null) { + try { + // flush and close the BufferedOutputStream + bos.flush(); + bos.close(); + } catch (Exception e) {} + } + } + } + static List getLocalURLs(List urls, final File jarDir, String bootstrapProtocol) throws MalformedURLException { ThreadFactory threadFactory = new ThreadFactory() { @@ -147,10 +166,10 @@ public class Bootstrap { ExecutorService pool = Executors.newFixedThreadPool(concurrentDownloadCount, threadFactory); CompletionService completionService = - new ExecutorCompletionService<>(pool); + new ExecutorCompletionService(pool); - List localURLs = new ArrayList<>(); - List missingURLs = new ArrayList<>(); + List localURLs = new ArrayList(); + List missingURLs = new ArrayList(); for (URL url : urls) { @@ -184,7 +203,7 @@ public class Bootstrap { byte[] b = readFullySync(s); File tmpDest = new File(dest.getParentFile(), dest.getName() + "-" + random.nextInt()); tmpDest.deleteOnExit(); - Files.write(tmpDest.toPath(), b); + writeBytesToFile(tmpDest, b); Files.move(tmpDest.toPath(), dest.toPath(), StandardCopyOption.ATOMIC_MOVE); dest.setLastModified(lastModified); } catch (Exception e) { @@ -239,8 +258,8 @@ public class Bootstrap { static List getURLs(String[] rawURLs, String[] resources, String bootstrapProtocol, ClassLoader loader) throws MalformedURLException { - List errors = new ArrayList<>(); - List urls = new ArrayList<>(); + List errors = new ArrayList(); + List urls = new ArrayList(); for (String urlStr : rawURLs) { try { @@ -354,7 +373,7 @@ public class Bootstrap { exit("Error: main method not found in class " + mainClass0); } - List userArgs0 = new ArrayList<>(); + List userArgs0 = new ArrayList(); for (int i = 0; i < args.length; i++) userArgs0.add(args[i]); diff --git a/build.sbt b/build.sbt index ec33d9a9b..1816ce648 100644 --- a/build.sbt +++ b/build.sbt @@ -254,7 +254,7 @@ lazy val cli = project if (scalaVersion.value startsWith "2.10.") Seq() else - Seq("com.github.alexarchambault" %% "case-app" % "1.0.0-M2") + Seq("com.github.alexarchambault" %% "case-app" % "1.0.0-M4") }, resourceGenerators in Compile += packageBin.in(bootstrap).in(Compile).map { jar => Seq(jar)