BytecodeCompiler - compiler invocation wrapped with try/catch.
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.buildtools.core;
|
package org.jetbrains.jet.buildtools.core;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
||||||
import org.jetbrains.jet.compiler.CompilerPlugin;
|
import org.jetbrains.jet.compiler.CompilerPlugin;
|
||||||
@@ -64,11 +66,15 @@ public class BytecodeCompiler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves compilation error message.
|
* Retrieves compilation error message.
|
||||||
* @param source compilation source
|
*
|
||||||
|
* @param source compilation source
|
||||||
|
* @param exceptionThrown whether compilation failed due to exception thrown
|
||||||
|
*
|
||||||
* @return compilation error message
|
* @return compilation error message
|
||||||
*/
|
*/
|
||||||
private String compilationError ( String source ) {
|
private static String errorMessage( @NotNull String source, boolean exceptionThrown ) {
|
||||||
return String.format( "[%s] compilation failed, see \"ERROR:\" messages above for more details.",
|
return String.format( "[%s] compilation failed" +
|
||||||
|
( exceptionThrown ? "" : ", see \"ERROR:\" messages above for more details." ),
|
||||||
new File( source ).getAbsolutePath());
|
new File( source ).getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,10 +87,15 @@ public class BytecodeCompiler {
|
|||||||
* @param stdlib "kotlin-runtime.jar" path
|
* @param stdlib "kotlin-runtime.jar" path
|
||||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||||
*/
|
*/
|
||||||
public void sourcesToDir ( String src, String output, String stdlib, String[] classpath ) {
|
public void sourcesToDir ( @NotNull String src, @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||||
boolean success = env( stdlib, classpath ).compileBunchOfSources( src, null, output, true /* Last arg is ignored anyway */ );
|
try {
|
||||||
if ( ! success ) {
|
boolean success = env( stdlib, classpath ).compileBunchOfSources( src, null, output, true /* Last arg is ignored anyway */ );
|
||||||
throw new CompileEnvironmentException( compilationError( src ));
|
if ( ! success ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( src, false ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( src, true ), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,10 +109,15 @@ public class BytecodeCompiler {
|
|||||||
* @param stdlib "kotlin-runtime.jar" path
|
* @param stdlib "kotlin-runtime.jar" path
|
||||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||||
*/
|
*/
|
||||||
public void sourcesToJar ( String src, String jar, boolean includeRuntime, String stdlib, String[] classpath ) {
|
public void sourcesToJar ( @NotNull String src, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||||
boolean success = env( stdlib, classpath ).compileBunchOfSources( src, jar, null, includeRuntime );
|
try {
|
||||||
if ( ! success ) {
|
boolean success = env( stdlib, classpath ).compileBunchOfSources( src, jar, null, includeRuntime );
|
||||||
throw new CompileEnvironmentException( compilationError( src ));
|
if ( ! success ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( src, false ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( src, true ), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,10 +131,15 @@ public class BytecodeCompiler {
|
|||||||
* @param stdlib "kotlin-runtime.jar" path
|
* @param stdlib "kotlin-runtime.jar" path
|
||||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||||
*/
|
*/
|
||||||
public void moduleToJar ( String module, String jar, boolean includeRuntime, String stdlib, String[] classpath ) {
|
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||||
boolean success = env( stdlib, classpath ).compileModuleScript( module, jar, null, includeRuntime );
|
try {
|
||||||
if ( ! success ) {
|
boolean success = env( stdlib, classpath ).compileModuleScript( module, jar, null, includeRuntime );
|
||||||
throw new CompileEnvironmentException( compilationError( module ));
|
if ( ! success ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( module, false ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
|
throw new CompileEnvironmentException( errorMessage( module, true ), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user