aboutsummaryrefslogtreecommitdiff
path: root/nailgun_launcher
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-04-02 20:19:30 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-04-02 20:20:40 -0400
commit8eae49b7b0a39f23518680b56429314db3d977e1 (patch)
treed7b3c2e4032e1a31ba2fa0e8efaf4f3d1cad64d3 /nailgun_launcher
parent107f62303794fa14b05c211d52dddc1f50f14886 (diff)
downloadcbt-8eae49b7b0a39f23518680b56429314db3d977e1.tar.gz
cbt-8eae49b7b0a39f23518680b56429314db3d977e1.tar.bz2
cbt-8eae49b7b0a39f23518680b56429314db3d977e1.zip
split launcher library functions into their own file
Diffstat (limited to 'nailgun_launcher')
-rw-r--r--nailgun_launcher/CBTUrlClassLoader.java3
-rw-r--r--nailgun_launcher/EarlyDependencies.java1
-rw-r--r--nailgun_launcher/NailgunLauncher.java114
-rw-r--r--nailgun_launcher/Stage0Lib.java123
4 files changed, 127 insertions, 114 deletions
diff --git a/nailgun_launcher/CBTUrlClassLoader.java b/nailgun_launcher/CBTUrlClassLoader.java
index a44e653..c05391b 100644
--- a/nailgun_launcher/CBTUrlClassLoader.java
+++ b/nailgun_launcher/CBTUrlClassLoader.java
@@ -2,6 +2,7 @@ package cbt;
import java.io.*;
import java.net.*;
import java.util.*;
+import static cbt.Stage0Lib.*;
class CbtURLClassLoader extends java.net.URLClassLoader{
public String toString(){
return (
@@ -9,7 +10,7 @@ class CbtURLClassLoader extends java.net.URLClassLoader{
+ "(\n "
+ Arrays.toString(getURLs())
+ ",\n "
- + NailgunLauncher.join("\n ",getParent().toString().split("\n"))
+ + join("\n ",getParent().toString().split("\n"))
+ "\n)"
);
}
diff --git a/nailgun_launcher/EarlyDependencies.java b/nailgun_launcher/EarlyDependencies.java
index 1e129c7..f4d446c 100644
--- a/nailgun_launcher/EarlyDependencies.java
+++ b/nailgun_launcher/EarlyDependencies.java
@@ -4,6 +4,7 @@ import java.io.*;
import java.nio.file.*;
import java.net.*;
import java.security.*;
+import static cbt.Stage0Lib.*;
import static cbt.NailgunLauncher.*;
class EarlyDependencies{
diff --git a/nailgun_launcher/NailgunLauncher.java b/nailgun_launcher/NailgunLauncher.java
index c94a6d2..a7d89e2 100644
--- a/nailgun_launcher/NailgunLauncher.java
+++ b/nailgun_launcher/NailgunLauncher.java
@@ -2,13 +2,10 @@ package cbt;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
-import java.nio.*;
-import java.nio.file.*;
-import static java.io.File.pathSeparator;
import java.security.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
+import static cbt.Stage0Lib.*;
/**
* This launcher allows to start the JVM without loading anything else permanently into its
@@ -110,113 +107,4 @@ public class NailgunLauncher{
throw e;
}
}
-
- public static void _assert(Boolean condition, Object msg){
- if(!condition){
- throw new AssertionError("Assertion failed: "+msg);
- }
- }
-
- public static int runMain(String cls, String[] args, ClassLoader cl) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
- try{
- System.setSecurityManager( new TrapSecurityManager() );
- cl.loadClass(cls)
- .getMethod("main", String[].class)
- .invoke( null, (Object) args);
- return 0;
- }catch( InvocationTargetException exception ){
- Throwable cause = exception.getCause();
- if(cause instanceof TrappedExitCode){
- return ((TrappedExitCode) cause).exitCode;
- }
- throw exception;
- } finally {
- System.setSecurityManager(NailgunLauncher.defaultSecurityManager);
- }
- }
-
- static int zinc( EarlyDependencies earlyDeps, List<File> sourceFiles ) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
- String cp = NAILGUN+TARGET + pathSeparator + earlyDeps.scalaXml_1_0_5_File + pathSeparator + earlyDeps.scalaLibrary_2_11_8_File;
- List<String> zincArgs = new ArrayList<String>(
- Arrays.asList(
- new String[]{
- "-scala-compiler", earlyDeps.scalaCompiler_2_11_8_File,
- "-scala-library", earlyDeps.scalaLibrary_2_11_8_File,
- "-scala-extra", earlyDeps.scalaReflect_2_11_8_File,
- "-sbt-interface", earlyDeps.sbtInterface_0_13_9_File,
- "-compiler-interface", earlyDeps.compilerInterface_0_13_9_File,
- "-cp", cp,
- "-d", STAGE1+TARGET
- }
- )
- );
-
- for( File f: sourceFiles ){
- zincArgs.add(f.toString());
- }
-
- PrintStream oldOut = System.out;
- try{
- System.setOut(System.err);
- return runMain( "com.typesafe.zinc.Main", zincArgs.toArray(new String[zincArgs.size()]), earlyDeps.zinc );
- } finally {
- System.setOut(oldOut);
- }
- }
-
- static ClassLoader classLoader( String file ) throws MalformedURLException{
- return new CbtURLClassLoader(
- new URL[]{ new URL("file:"+file) }
- );
- }
- static ClassLoader classLoader( String file, ClassLoader parent ) throws MalformedURLException{
- return new CbtURLClassLoader(
- new URL[]{ new URL("file:"+file) }, parent
- );
- }
- static ClassLoader cacheGet( String key ){
- return classLoaderCacheValues.get(
- classLoaderCacheKeys.get( key )
- );
- }
- public static ClassLoader cachePut( ClassLoader classLoader, String... jars ){
- String key = join( pathSeparator, jars );
- Object keyObject = new Object();
- classLoaderCacheKeys.put( key, keyObject );
- classLoaderCacheValues.put( keyObject, classLoader );
- return classLoader;
- }
-
- 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());
- }
-
- public static String join(String separator, String[] parts){
- String result = parts[0];
- for(int i = 1; i < parts.length; i++){
- result += separator + parts[i];
- }
- return result;
- }
}
diff --git a/nailgun_launcher/Stage0Lib.java b/nailgun_launcher/Stage0Lib.java
new file mode 100644
index 0000000..d6f33e1
--- /dev/null
+++ b/nailgun_launcher/Stage0Lib.java
@@ -0,0 +1,123 @@
+package cbt;
+import java.io.*;
+import java.lang.reflect.*;
+import java.net.*;
+import java.nio.*;
+import java.nio.file.*;
+import java.security.*;
+import java.util.*;
+import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
+import static java.io.File.pathSeparator;
+import static cbt.Stage0Lib.*;
+import static cbt.NailgunLauncher.*;
+
+public class Stage0Lib{
+ public static void _assert(Boolean condition, Object msg){
+ if(!condition){
+ throw new AssertionError("Assertion failed: "+msg);
+ }
+ }
+
+ public static int runMain(String cls, String[] args, ClassLoader cl) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+ try{
+ System.setSecurityManager( new TrapSecurityManager() );
+ cl.loadClass(cls)
+ .getMethod("main", String[].class)
+ .invoke( null, (Object) args);
+ return 0;
+ }catch( InvocationTargetException exception ){
+ Throwable cause = exception.getCause();
+ if(cause instanceof TrappedExitCode){
+ return ((TrappedExitCode) cause).exitCode;
+ }
+ throw exception;
+ } finally {
+ System.setSecurityManager(NailgunLauncher.defaultSecurityManager);
+ }
+ }
+
+ public static int zinc( EarlyDependencies earlyDeps, List<File> sourceFiles ) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+ String cp = NAILGUN+TARGET + pathSeparator + earlyDeps.scalaXml_1_0_5_File + pathSeparator + earlyDeps.scalaLibrary_2_11_8_File;
+ List<String> zincArgs = new ArrayList<String>(
+ Arrays.asList(
+ new String[]{
+ "-scala-compiler", earlyDeps.scalaCompiler_2_11_8_File,
+ "-scala-library", earlyDeps.scalaLibrary_2_11_8_File,
+ "-scala-extra", earlyDeps.scalaReflect_2_11_8_File,
+ "-sbt-interface", earlyDeps.sbtInterface_0_13_9_File,
+ "-compiler-interface", earlyDeps.compilerInterface_0_13_9_File,
+ "-cp", cp,
+ "-d", STAGE1+TARGET
+ }
+ )
+ );
+
+ for( File f: sourceFiles ){
+ zincArgs.add(f.toString());
+ }
+
+ PrintStream oldOut = System.out;
+ try{
+ System.setOut(System.err);
+ return runMain( "com.typesafe.zinc.Main", zincArgs.toArray(new String[zincArgs.size()]), earlyDeps.zinc );
+ } finally {
+ System.setOut(oldOut);
+ }
+ }
+
+ public static ClassLoader classLoader( String file ) throws MalformedURLException{
+ return new CbtURLClassLoader(
+ new URL[]{ new URL("file:"+file) }
+ );
+ }
+ public static ClassLoader classLoader( String file, ClassLoader parent ) throws MalformedURLException{
+ return new CbtURLClassLoader(
+ new URL[]{ new URL("file:"+file) }, parent
+ );
+ }
+ public static ClassLoader cacheGet( String key ){
+ return classLoaderCacheValues.get(
+ classLoaderCacheKeys.get( key )
+ );
+ }
+ public static ClassLoader cachePut( ClassLoader classLoader, String... jars ){
+ String key = join( pathSeparator, jars );
+ Object keyObject = new Object();
+ classLoaderCacheKeys.put( key, keyObject );
+ classLoaderCacheValues.put( keyObject, classLoader );
+ return classLoader;
+ }
+
+ 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());
+ }
+
+ public static String join(String separator, String[] parts){
+ String result = parts[0];
+ for(int i = 1; i < parts.length; i++){
+ result += separator + parts[i];
+ }
+ return result;
+ }
+} \ No newline at end of file