better error reporting in commandline compiler

This commit is contained in:
Stepan Koltsov
2012-01-06 21:22:50 +04:00
parent dba41c2e88
commit 430b973458
2 changed files with 19 additions and 7 deletions
@@ -120,7 +120,7 @@ public class CompileEnvironment {
rtJar = findActiveRtJar(failOnError);
if ((rtJar == null || !rtJar.exists())) {
throw new CompileEnvironmentException("No rt.jar found under JAVA_HOME=" + javaHome);
throw new CompileEnvironmentException("No JDK rt.jar found under JAVA_HOME=" + javaHome);
}
}
return rtJar;
@@ -337,7 +337,7 @@ public class CompileEnvironment {
}
}
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
CompileSession session = new CompileSession(myEnvironment);
session.addSources(sourceFileOrDir);
session.addStdLibSources(false);
@@ -350,7 +350,7 @@ public class CompileEnvironment {
}
}
if (!session.analyze(myErrorStream)) {
return;
return false;
}
ClassFileFactory factory = session.generate();
@@ -367,6 +367,7 @@ public class CompileEnvironment {
else {
throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
}
return true;
}
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
@@ -33,9 +33,14 @@ public class KotlinCompiler {
try {
Args.parse(arguments, args);
}
catch (Throwable t) {
catch (IllegalArgumentException e) {
System.out.println("Usage: KotlinCompiler [-output <outputDir>|-jar <jarFileName>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
System.exit(1);
return;
}
catch (Throwable t) {
t.printStackTrace();
System.exit(1);
return;
}
@@ -44,7 +49,8 @@ public class KotlinCompiler {
try {
environment.setJavaRuntime(CompileEnvironment.findRtJar(true));
if (!environment.initializeKotlinRuntime()) {
System.out.println("No runtime library found");
System.err.println("No Kotlin runtime library found");
System.exit(1);
return;
}
@@ -53,10 +59,15 @@ public class KotlinCompiler {
return;
}
else {
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
if (!environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime)) {
System.exit(1);
return;
}
}
} catch (CompileEnvironmentException e) {
System.out.println(e.getMessage());
System.err.println(e.getMessage());
System.exit(1);
return;
}
}