aboutsummaryrefslogtreecommitdiff
path: root/bootstrap_scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-03-16 02:22:01 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-03-20 22:12:06 -0400
commit2c20a0dddc70a5eee207fb1c588bfd53eaaa7841 (patch)
tree8ae901ccafdc509ebb9717b116fdfc4f0244773f /bootstrap_scala
parent450fc5d3defcdc279cfeef0ae622ebe4f90988e2 (diff)
downloadcbt-2c20a0dddc70a5eee207fb1c588bfd53eaaa7841.tar.gz
cbt-2c20a0dddc70a5eee207fb1c588bfd53eaaa7841.tar.bz2
cbt-2c20a0dddc70a5eee207fb1c588bfd53eaaa7841.zip
merged most bootstrapping logic into launcher
Diffstat (limited to 'bootstrap_scala')
-rw-r--r--bootstrap_scala/BootstrapScala.java85
-rw-r--r--bootstrap_scala/Dependency.java29
-rwxr-xr-xbootstrap_scala/bootstrap_scala27
3 files changed, 0 insertions, 141 deletions
diff --git a/bootstrap_scala/BootstrapScala.java b/bootstrap_scala/BootstrapScala.java
deleted file mode 100644
index e2d7a5a..0000000
--- a/bootstrap_scala/BootstrapScala.java
+++ /dev/null
@@ -1,85 +0,0 @@
-import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-import java.util.Iterator;
-import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
-
-/**
- * This file class allows bootstrapping out of Java into Scala. It downloads the Scala jars for the
- * version number given as the first argument into the directory given as the second argument and
- * returns a classpath String.
- */
-public class BootstrapScala {
-
- public final static Dependency[] dependencies(String target, String scalaVersion) throws MalformedURLException {
- return new Dependency[] {
- Dependency.scala(target, scalaVersion, "library", "DDD5A8BCED249BEDD86FB4578A39B9FB71480573"),
- Dependency.scala(target, scalaVersion, "compiler","FE1285C9F7B58954C5EF6D80B59063569C065E9A"),
- Dependency.scala(target, scalaVersion, "reflect", "B74530DEEBA742AB4F3134DE0C2DA0EDC49CA361"),
- new Dependency(target, "modules/scala-xml_2.11/1.0.5", "scala-xml_2.11-1.0.5", "77ac9be4033768cf03cc04fbd1fc5e5711de2459")
- };
- }
-
- public static void main(String args[]) throws IOException, NoSuchAlgorithmException {
-
- if(args.length < 2){
- System.err.println("Usage: bootstrap_scala <scala version> <download directory>");
- System.exit(1);
- }
-
- Dependency[] ds = dependencies( args[1], args[0] );
- new File(args[1]).mkdirs();
- for (Dependency d: ds) {
- download( d.url, d.path, d.hash );
- }
-
- // Join dep. paths as a classpath
- String classpath = "";
- Iterator<Dependency> depsIter = Arrays.asList(ds).iterator();
- while (depsIter.hasNext()) {
- Dependency dep = depsIter.next();
- classpath += dep.path.toString();
- if (depsIter.hasNext()) {
- classpath += File.pathSeparator;
- }
- }
-
- System.out.println(classpath);
-
- }
-
- public static void download(URL urlString, Path target, String sha1) throws IOException, NoSuchAlgorithmException {
- final Path unverified = Paths.get(target+".unverified");
- if(!Files.exists(target)) {
- new File(target.toString()).getParentFile().mkdirs();
- System.err.println("downloading " + urlString);
- System.err.println("to " + target);
- final InputStream stream = urlString.openStream();
- Files.copy(stream, unverified, StandardCopyOption.REPLACE_EXISTING);
- stream.close();
- final String checksum = sha1(Files.readAllBytes(unverified));
- if(sha1 == null || sha1.toUpperCase().equals(checksum)) {
- Files.move(unverified, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
- } else {
- System.err.println(target + " checksum does not match.\nExpected: |" + sha1 + "|\nFound: |" + checksum + "|");
- System.exit(1);
- }
- }
- }
-
- public static String sha1(byte[] bytes) throws NoSuchAlgorithmException {
- final MessageDigest sha1 = MessageDigest.getInstance("SHA1");
- sha1.update(bytes, 0, bytes.length);
- return (new HexBinaryAdapter()).marshal(sha1.digest());
- }
-
-}
diff --git a/bootstrap_scala/Dependency.java b/bootstrap_scala/Dependency.java
deleted file mode 100644
index 571047b..0000000
--- a/bootstrap_scala/Dependency.java
+++ /dev/null
@@ -1,29 +0,0 @@
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-class Dependency {
-
- final URL url;
- final Path path;
- final String hash;
-
- public Dependency(String target, String folder, String file, String hash) throws MalformedURLException {
- this.path = Paths.get(target + file + ".jar");
- this.url = new URL("https://repo1.maven.org/maven2/org/scala-lang/" + folder + "/" + file + ".jar");
- this.hash = hash;
- }
-
- // scala-lang dependency
- public static Dependency scala(String target, String scalaVersion, String scalaModule, String hash)
- throws MalformedURLException {
- return new Dependency(
- target,
- "scala-" + scalaModule + "/" + scalaVersion,
- "scala-" + scalaModule + "-" + scalaVersion,
- hash
- );
- }
-
-}
diff --git a/bootstrap_scala/bootstrap_scala b/bootstrap_scala/bootstrap_scala
deleted file mode 100755
index b004c8d..0000000
--- a/bootstrap_scala/bootstrap_scala
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-_DIR=$(dirname $(readlink "$0") 2>/dev/null || dirname "$0" 2>/dev/null )
-DIR=$(dirname $($_DIR/../realpath/realpath.sh $0))
-JAVAC="javac -Xlint:deprecation"
-TARGET=$DIR/target
-CLASSES=$TARGET/classes/
-VERSION=$1
-CACHE=$DIR/cache/$VERSION/
-
-COMPILER_JAR=scala-compiler-$VERSION.jar
-LIBRARY_JAR=scala-library-$VERSION.jar
-REFLECT_JAR=scala-reflect-$VERSION.jar
-XML_JAR=scala-xml_2.11-1.0.5.jar # this is a bit fishy, because it doesn't take version into account
-
-mkdir -p $CLASSES
-
-if [ ! -f $CACHE$COMPILER_JAR ] || [ ! -f $CACHE$LIBRARY_JAR ] || [ ! -f $CACHE$REFLECT_JAR ]\
- || [ ! -f $CACHE$XML_JAR ] || [ $DIR/BootstrapScala.java -nt $CLASSES/BootstrapScala.class ] || [ $DIR/Dependency.java -nt $CLASSES/Dependency.class ]
-then
- echo "Compiling cbt/bootstrap_scala" 1>&2
- $JAVAC -d $CLASSES $DIR/BootstrapScala.java $DIR/Dependency.java
- java -cp $CLASSES BootstrapScala $1 $CACHE
-else
- # for speedup
- echo `for f in $CACHE*; do printf "$f "; done`|tr " " ":"
-fi