diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-02 15:55:37 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-02 15:55:37 -0400 |
commit | efe68c7e710aa8c54144715408b7faca36f52c27 (patch) | |
tree | 6a5791efedc2d297cfac1ad8bbaac0b090105149 /nailgun_launcher/NailgunLauncher.java | |
parent | 10c156d83bb24486df6c040b514d072bf6b112d5 (diff) | |
download | cbt-efe68c7e710aa8c54144715408b7faca36f52c27.tar.gz cbt-efe68c7e710aa8c54144715408b7faca36f52c27.tar.bz2 cbt-efe68c7e710aa8c54144715408b7faca36f52c27.zip |
Fix exit code trapping in NailgunLauncher
this showed exception when compile errors happened during Stage1.
Diffstat (limited to 'nailgun_launcher/NailgunLauncher.java')
-rw-r--r-- | nailgun_launcher/NailgunLauncher.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/nailgun_launcher/NailgunLauncher.java b/nailgun_launcher/NailgunLauncher.java index 5337b0a..50a3c91 100644 --- a/nailgun_launcher/NailgunLauncher.java +++ b/nailgun_launcher/NailgunLauncher.java @@ -79,7 +79,6 @@ public class NailgunLauncher{ } if(stage1SourcesChanged || stage1classLoader == null){ - System.err.println("CBT stage1 changed. Re-compiling."); EarlyDependencies earlyDeps = new EarlyDependencies(); int exitCode = zinc(earlyDeps, stage1SourceFiles); if( exitCode == 0 ){ @@ -118,10 +117,22 @@ public class NailgunLauncher{ } } - public static void runMain(String cls, String[] args, ClassLoader cl) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{ - cl.loadClass(cls) - .getMethod("main", String[].class) - .invoke( null, (Object) args); + 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{ @@ -144,17 +155,12 @@ public class NailgunLauncher{ zincArgs.add(f.toString()); } + PrintStream oldOut = System.out; try{ - System.setSecurityManager( new TrapSecurityManager() ); - PrintStream oldOut = System.out; System.setOut(System.err); - runMain( "com.typesafe.zinc.Main", zincArgs.toArray(new String[zincArgs.size()]), earlyDeps.zinc ); - System.setOut(oldOut); - return 0;//throw new RuntimeException("zinc should have thrown an exit code"); - }catch( TrappedExitCode trapped ){ - return trapped.exitCode; + return runMain( "com.typesafe.zinc.Main", zincArgs.toArray(new String[zincArgs.size()]), earlyDeps.zinc ); } finally { - System.setSecurityManager(NailgunLauncher.defaultSecurityManager); + System.setOut(oldOut); } } |