Reformatted Ant task code according to coding conventions.
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.buildtools.ant;
|
||||
|
||||
import static org.jetbrains.jet.buildtools.core.Util.*;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.Path;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
@@ -25,10 +24,12 @@ import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.jetbrains.jet.buildtools.core.Util.getPath;
|
||||
|
||||
|
||||
/**
|
||||
* Kotlin bytecode compiler Ant task.
|
||||
*
|
||||
* <p/>
|
||||
* See
|
||||
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
|
||||
* http://evgeny-goldin.org/javadoc/ant/develop.html
|
||||
@@ -36,20 +37,37 @@ import java.io.File;
|
||||
*/
|
||||
public class BytecodeCompilerTask extends Task {
|
||||
|
||||
private File output;
|
||||
private File jar;
|
||||
private File stdlib;
|
||||
private File src;
|
||||
private File module;
|
||||
private Path compileClasspath;
|
||||
private File output;
|
||||
private File jar;
|
||||
private File stdlib;
|
||||
private File src;
|
||||
private File module;
|
||||
private Path compileClasspath;
|
||||
private boolean includeRuntime = true;
|
||||
|
||||
public void setOutput ( File output ) { this.output = output; }
|
||||
public void setJar ( File jar ) { this.jar = jar; }
|
||||
public void setStdlib ( File stdlib ) { this.stdlib = stdlib; }
|
||||
public void setSrc ( File src ) { this.src = src; }
|
||||
public void setModule ( File module ) { this.module = module; }
|
||||
public void setIncludeRuntime ( boolean includeRuntime ) { this.includeRuntime = includeRuntime; }
|
||||
public void setOutput(File output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public void setJar(File jar) {
|
||||
this.jar = jar;
|
||||
}
|
||||
|
||||
public void setStdlib(File stdlib) {
|
||||
this.stdlib = stdlib;
|
||||
}
|
||||
|
||||
public void setSrc(File src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
public void setModule(File module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
public void setIncludeRuntime(boolean includeRuntime) {
|
||||
this.includeRuntime = includeRuntime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,25 +75,26 @@ public class BytecodeCompilerTask extends Task {
|
||||
*
|
||||
* @param classpath an Ant Path object containing the compilation classpath.
|
||||
*/
|
||||
public void setClasspath ( Path classpath ) {
|
||||
if ( this.compileClasspath == null ) {
|
||||
public void setClasspath(Path classpath) {
|
||||
if (this.compileClasspath == null) {
|
||||
this.compileClasspath = classpath;
|
||||
}
|
||||
else {
|
||||
this.compileClasspath.append( classpath );
|
||||
this.compileClasspath.append(classpath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a reference to a classpath defined elsewhere.
|
||||
*
|
||||
* @param ref a reference to a classpath.
|
||||
*/
|
||||
public void setClasspathRef( Reference ref ) {
|
||||
if ( this.compileClasspath == null ) {
|
||||
this.compileClasspath = new Path( getProject());
|
||||
public void setClasspathRef(Reference ref) {
|
||||
if (this.compileClasspath == null) {
|
||||
this.compileClasspath = new Path(getProject());
|
||||
}
|
||||
this.compileClasspath.createPath().setRefid( ref );
|
||||
this.compileClasspath.createPath().setRefid(ref);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,52 +103,52 @@ public class BytecodeCompilerTask extends Task {
|
||||
*
|
||||
* @param classpath an Ant Path object containing the compilation classpath.
|
||||
*/
|
||||
public void addConfiguredClasspath( Path classpath ) {
|
||||
setClasspath( classpath );
|
||||
public void addConfiguredClasspath(Path classpath) {
|
||||
setClasspath(classpath);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
final BytecodeCompiler compiler = new BytecodeCompiler();
|
||||
final String stdlibPath = ( this.stdlib != null ? getPath( this.stdlib ) : null );
|
||||
final String[] classpath = ( this.compileClasspath != null ? this.compileClasspath.list() : null );
|
||||
final BytecodeCompiler compiler = new BytecodeCompiler();
|
||||
final String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
|
||||
final String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);
|
||||
|
||||
if ( this.src != null ) {
|
||||
if (this.src != null) {
|
||||
|
||||
if (( this.output == null ) && ( this.jar == null )) {
|
||||
throw new CompileEnvironmentException( "\"output\" or \"jar\" should be specified" );
|
||||
if ((this.output == null) && (this.jar == null)) {
|
||||
throw new CompileEnvironmentException("\"output\" or \"jar\" should be specified");
|
||||
}
|
||||
|
||||
String source = getPath( this.src );
|
||||
String destination = getPath( this.output != null ? this.output : this.jar );
|
||||
String source = getPath(this.src);
|
||||
String destination = getPath(this.output != null ? this.output : this.jar);
|
||||
|
||||
log( String.format( "Compiling [%s] => [%s]", source, destination ));
|
||||
log(String.format("Compiling [%s] => [%s]", source, destination));
|
||||
|
||||
if ( this.output != null ) {
|
||||
compiler.sourcesToDir( source, destination, stdlibPath, classpath );
|
||||
if (this.output != null) {
|
||||
compiler.sourcesToDir(source, destination, stdlibPath, classpath);
|
||||
}
|
||||
else {
|
||||
compiler.sourcesToJar( source, destination, this.includeRuntime, stdlibPath, classpath );
|
||||
compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath);
|
||||
}
|
||||
}
|
||||
else if ( this.module != null ) {
|
||||
else if (this.module != null) {
|
||||
|
||||
if ( this.output != null ) {
|
||||
throw new CompileEnvironmentException( "Module compilation is only supported for jar destination" );
|
||||
if (this.output != null) {
|
||||
throw new CompileEnvironmentException("Module compilation is only supported for jar destination");
|
||||
}
|
||||
|
||||
String modulePath = getPath( this.module );
|
||||
String jarPath = ( this.jar != null ? getPath( this.jar ) : null );
|
||||
String modulePath = getPath(this.module);
|
||||
String jarPath = (this.jar != null ? getPath(this.jar) : null);
|
||||
|
||||
log( jarPath != null ? String.format( "Compiling [%s] => [%s]", modulePath, jarPath ) :
|
||||
String.format( "Compiling [%s]", modulePath ));
|
||||
log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) :
|
||||
String.format("Compiling [%s]", modulePath));
|
||||
|
||||
compiler.moduleToJar( modulePath, jarPath, this.includeRuntime, stdlibPath, classpath );
|
||||
compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath);
|
||||
}
|
||||
else {
|
||||
throw new CompileEnvironmentException( "\"src\" or \"module\" should be specified" );
|
||||
throw new CompileEnvironmentException("\"src\" or \"module\" should be specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class JavaScriptCompilerTask extends Task {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
log( "JavaScriptCompilerTask" );
|
||||
log("JavaScriptCompilerTask");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.*;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
@@ -40,7 +40,7 @@ public class BytecodeCompiler {
|
||||
|
||||
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
|
||||
|
||||
public BytecodeCompiler () {
|
||||
public BytecodeCompiler() {
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +49,9 @@ public class BytecodeCompiler {
|
||||
*
|
||||
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
|
||||
* @param classpath compilation classpath, only used if not null and not empty
|
||||
*
|
||||
* @return compile environment instance
|
||||
*/
|
||||
private K2JVMCompileEnvironmentConfiguration env( String stdlib, String[] classpath ) {
|
||||
private K2JVMCompileEnvironmentConfiguration env(String stdlib, String[] classpath) {
|
||||
List<File> classpathItems = new ArrayList<File>();
|
||||
classpathItems.add(PathUtil.findRtJar());
|
||||
if ((stdlib != null) && (stdlib.trim().length() > 0)) {
|
||||
@@ -68,7 +67,7 @@ public class BytecodeCompiler {
|
||||
}
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, classpathItems.toArray(new File[classpathItems.size()]));
|
||||
configuration.putUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File[]{PathUtil.getJdkAnnotationsPath()});
|
||||
configuration.putUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File[] {PathUtil.getJdkAnnotationsPath()});
|
||||
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), configuration
|
||||
);
|
||||
@@ -86,15 +85,14 @@ public class BytecodeCompiler {
|
||||
/**
|
||||
* Retrieves compilation error message.
|
||||
*
|
||||
* @param source compilation source
|
||||
* @param exceptionThrown whether compilation failed due to exception thrown
|
||||
*
|
||||
* @param source compilation source
|
||||
* @param exceptionThrown whether compilation failed due to exception thrown
|
||||
* @return compilation error message
|
||||
*/
|
||||
private static String errorMessage( @NotNull String source, boolean exceptionThrown ) {
|
||||
return String.format( "[%s] compilation failed" +
|
||||
( exceptionThrown ? "" : ", see \"ERROR:\" messages above for more details." ),
|
||||
new File( source ).getAbsolutePath());
|
||||
private static String errorMessage(@NotNull String source, boolean exceptionThrown) {
|
||||
return String.format("[%s] compilation failed" +
|
||||
(exceptionThrown ? "" : ", see \"ERROR:\" messages above for more details."),
|
||||
new File(source).getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
@@ -106,18 +104,18 @@ public class BytecodeCompiler {
|
||||
* @param stdlib "kotlin-runtime.jar" path
|
||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||
*/
|
||||
public void sourcesToDir ( @NotNull String src, @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||
public void sourcesToDir(@NotNull String src, @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath) {
|
||||
try {
|
||||
K2JVMCompileEnvironmentConfiguration configuration = env(stdlib, classpath);
|
||||
configuration.getEnvironment().addSources(src);
|
||||
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration, null, new File(output), true);
|
||||
if ( ! success ) {
|
||||
throw new CompileEnvironmentException( errorMessage( src, false ));
|
||||
if (!success) {
|
||||
throw new CompileEnvironmentException(errorMessage(src, false));
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new CompileEnvironmentException( errorMessage( src, true ), e );
|
||||
catch (Exception e) {
|
||||
throw new CompileEnvironmentException(errorMessage(src, true), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,18 +129,22 @@ public class BytecodeCompiler {
|
||||
* @param stdlib "kotlin-runtime.jar" path
|
||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||
*/
|
||||
public void sourcesToJar ( @NotNull String src, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||
public void sourcesToJar(@NotNull String src,
|
||||
@NotNull String jar,
|
||||
boolean includeRuntime,
|
||||
@Nullable String stdlib,
|
||||
@Nullable String[] classpath) {
|
||||
try {
|
||||
K2JVMCompileEnvironmentConfiguration configuration = env(stdlib, classpath);
|
||||
configuration.getEnvironment().addSources(src);
|
||||
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration, new File(jar), null, includeRuntime);
|
||||
if ( ! success ) {
|
||||
throw new CompileEnvironmentException( errorMessage( src, false ));
|
||||
if (!success) {
|
||||
throw new CompileEnvironmentException(errorMessage(src, false));
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new CompileEnvironmentException( errorMessage( src, true ), e );
|
||||
catch (Exception e) {
|
||||
throw new CompileEnvironmentException(errorMessage(src, true), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,18 +158,22 @@ public class BytecodeCompiler {
|
||||
* @param stdlib "kotlin-runtime.jar" path
|
||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
||||
*/
|
||||
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||
public void moduleToJar(@NotNull String module,
|
||||
@NotNull String jar,
|
||||
boolean includeRuntime,
|
||||
@Nullable String stdlib,
|
||||
@Nullable String[] classpath) {
|
||||
try {
|
||||
K2JVMCompileEnvironmentConfiguration env = env(stdlib, classpath);
|
||||
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector());
|
||||
File directory = new File(module).getParentFile();
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, new File(jar), null, includeRuntime);
|
||||
if ( ! success ) {
|
||||
throw new CompileEnvironmentException( errorMessage( module, false ));
|
||||
if (!success) {
|
||||
throw new CompileEnvironmentException(errorMessage(module, false));
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new CompileEnvironmentException( errorMessage( module, true ), e );
|
||||
catch (Exception e) {
|
||||
throw new CompileEnvironmentException(errorMessage(module, true), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,22 +25,22 @@ import java.io.IOException;
|
||||
*/
|
||||
public final class Util {
|
||||
|
||||
private Util () {
|
||||
private Util() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@code file.getCanonicalFile().getPath()} convenience wrapper.
|
||||
*
|
||||
* @param f file to get its canonical path.
|
||||
* @return file's canonical path
|
||||
* @return file's canonical path
|
||||
*/
|
||||
public static String getPath( File f ) {
|
||||
public static String getPath(File f) {
|
||||
try {
|
||||
return f.getCanonicalFile().getPath();
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new RuntimeException( String.format( "Failed to resolve canonical file of [%s]: %s", f, e ), e );
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(String.format("Failed to resolve canonical file of [%s]: %s", f, e), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user