Ant task: drop "module" support, drop unused compiler plugins code
Modules should only be used in IDE and the compiler is launched there directly
This commit is contained in:
@@ -45,7 +45,6 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
private File stdlib;
|
private File stdlib;
|
||||||
private Path src;
|
private Path src;
|
||||||
private Path externalAnnotations;
|
private Path externalAnnotations;
|
||||||
private File module;
|
|
||||||
private Path compileClasspath;
|
private Path compileClasspath;
|
||||||
private boolean includeRuntime = true;
|
private boolean includeRuntime = true;
|
||||||
private final List<Commandline.Argument> additionalArguments = new ArrayList<Commandline.Argument>();
|
private final List<Commandline.Argument> additionalArguments = new ArrayList<Commandline.Argument>();
|
||||||
@@ -80,10 +79,6 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
return externalAnnotations.createPath();
|
return externalAnnotations.createPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModule(File module) {
|
|
||||||
this.module = module;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIncludeRuntime(boolean includeRuntime) {
|
public void setIncludeRuntime(boolean includeRuntime) {
|
||||||
this.includeRuntime = includeRuntime;
|
this.includeRuntime = includeRuntime;
|
||||||
}
|
}
|
||||||
@@ -108,7 +103,6 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a reference to a classpath defined elsewhere.
|
* Adds a reference to a classpath defined elsewhere.
|
||||||
*
|
*
|
||||||
@@ -121,7 +115,6 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
this.compileClasspath.createPath().setRefid(ref);
|
this.compileClasspath.createPath().setRefid(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the nested {@code <classpath>} to be used for this compilation.
|
* Set the nested {@code <classpath>} to be used for this compilation.
|
||||||
*
|
*
|
||||||
@@ -131,43 +124,28 @@ public class BytecodeCompilerTask extends Task {
|
|||||||
setClasspath(classpath);
|
setClasspath(classpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
BytecodeCompiler compiler = new BytecodeCompiler();
|
String stdlibPath = stdlib != null ? getPath(stdlib) : null;
|
||||||
String stdlibPath = (stdlib != null ? getPath(stdlib) : null);
|
String[] classpath = compileClasspath != null ? compileClasspath.list() : null;
|
||||||
String[] classpath = (compileClasspath != null ? compileClasspath.list() : null);
|
String[] externalAnnotationsPath = externalAnnotations != null ? externalAnnotations.list() : null;
|
||||||
String[] externalAnnotationsPath = (externalAnnotations != null) ? externalAnnotations.list() : null;
|
|
||||||
|
|
||||||
List<String> args = new ArrayList<String>();
|
List<String> args = new ArrayList<String>();
|
||||||
for (Commandline.Argument argument : additionalArguments) {
|
for (Commandline.Argument argument : additionalArguments) {
|
||||||
args.addAll(Arrays.asList(argument.getParts()));
|
args.addAll(Arrays.asList(argument.getParts()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (src == null) {
|
||||||
|
throw new BuildException("\"src\" should be specified");
|
||||||
|
}
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
throw new BuildException("\"output\" should be specified");
|
throw new BuildException("\"output\" should be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src != null) {
|
String[] source = Util.getPaths(src.list());
|
||||||
String[] source = Util.getPaths(src.list());
|
String destination = getPath(output);
|
||||||
String destination = getPath(output);
|
|
||||||
|
|
||||||
log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination));
|
log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination));
|
||||||
compiler.compileSources(source, destination, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args);
|
BytecodeCompiler.compileSources(source, destination, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args);
|
||||||
}
|
|
||||||
else if (module != null) {
|
|
||||||
if (!output.toString().endsWith(".jar")) {
|
|
||||||
throw new BuildException("Module compilation is only supported for jar destination");
|
|
||||||
}
|
|
||||||
|
|
||||||
String modulePath = getPath(module);
|
|
||||||
String jarPath = getPath(output);
|
|
||||||
|
|
||||||
log(String.format("Compiling [%s] => [%s]", modulePath, jarPath));
|
|
||||||
compiler.compileModule(modulePath, jarPath, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new BuildException("\"src\" or \"module\" should be specified");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,12 @@ import com.intellij.openapi.util.text.StringUtil;
|
|||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
import kotlin.modules.Module;
|
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream;
|
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream;
|
||||||
import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
|
|
||||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||||
@@ -43,24 +40,17 @@ import org.jetbrains.jet.utils.KotlinPathsFromHomeDir;
|
|||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
||||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY;
|
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY;
|
||||||
import static org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil.loadModuleDescriptions;
|
|
||||||
|
|
||||||
public class BytecodeCompiler {
|
public class BytecodeCompiler {
|
||||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||||
|
|
||||||
private List<CompilerPlugin> compilerPlugins = new ArrayList<CompilerPlugin>();
|
|
||||||
|
|
||||||
public BytecodeCompiler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CompilerConfiguration createConfiguration(
|
private static CompilerConfiguration createConfiguration(
|
||||||
@Nullable String stdlib,
|
@Nullable String stdlib,
|
||||||
@Nullable String[] classpath,
|
@Nullable String[] classpath,
|
||||||
@Nullable String[] externalAnnotationsPath,
|
@Nullable String[] externalAnnotationsPath,
|
||||||
@@ -114,8 +104,6 @@ public class BytecodeCompiler {
|
|||||||
|
|
||||||
K2JVMCompiler.putAdvancedOptions(configuration, arguments);
|
K2JVMCompiler.putAdvancedOptions(configuration, arguments);
|
||||||
|
|
||||||
// lets register any compiler plugins
|
|
||||||
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,13 +129,12 @@ public class BytecodeCompiler {
|
|||||||
/**
|
/**
|
||||||
* {@code KotlinToJVMBytecodeCompiler#compileBunchOfSources} wrapper.
|
* {@code KotlinToJVMBytecodeCompiler#compileBunchOfSources} wrapper.
|
||||||
* @param src compilation source (directory or file)
|
* @param src compilation source (directory or file)
|
||||||
* @param destination compilation destination jar
|
* @param destination compilation destination (directory or jar)
|
||||||
* @param includeRuntime whether Kotlin runtime library is included in destination jar
|
* @param includeRuntime whether Kotlin runtime library is included in destination jar
|
||||||
* @param stdlib "kotlin-runtime.jar" path
|
* @param stdlib "kotlin-runtime.jar" path
|
||||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
|
||||||
* @param args additional command line arguments to Kotlin compiler
|
* @param args additional command line arguments to Kotlin compiler
|
||||||
*/
|
*/
|
||||||
public void compileSources(
|
public static void compileSources(
|
||||||
@NotNull String[] src,
|
@NotNull String[] src,
|
||||||
@NotNull String destination,
|
@NotNull String destination,
|
||||||
boolean includeRuntime,
|
boolean includeRuntime,
|
||||||
@@ -183,61 +170,7 @@ public class BytecodeCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@code KotlinToJVMBytecodeCompiler#compileModules} wrapper.
|
|
||||||
* @param module compilation module file
|
|
||||||
* @param jar compilation destination jar
|
|
||||||
* @param includeRuntime whether Kotlin runtime library is included in destination jar
|
|
||||||
* @param stdlib "kotlin-runtime.jar" path
|
|
||||||
* @param classpath compilation classpath, can be <code>null</code> or empty
|
|
||||||
* @param args additional command line arguments to Kotlin compiler
|
|
||||||
*/
|
|
||||||
public void compileModule(
|
|
||||||
@NotNull String module,
|
|
||||||
@NotNull String jar,
|
|
||||||
boolean includeRuntime,
|
|
||||||
@Nullable String stdlib,
|
|
||||||
@Nullable String[] classpath,
|
|
||||||
@Nullable String[] externalAnnotationsPath,
|
|
||||||
@NotNull List<String> args
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
ModuleScriptData moduleScriptData =
|
|
||||||
loadModuleDescriptions(getKotlinPathsForAntTask(), module, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
|
|
||||||
List<Module> modules = moduleScriptData.getModules();
|
|
||||||
List<String> sourcesRoots = new ArrayList<String>();
|
|
||||||
for (Module m : modules) {
|
|
||||||
sourcesRoots.addAll(m.getSourceFiles());
|
|
||||||
}
|
|
||||||
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath,
|
|
||||||
ArrayUtil.toStringArray(sourcesRoots), args);
|
|
||||||
File directory = new File(module).getParentFile();
|
|
||||||
boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime);
|
|
||||||
if (!success) {
|
|
||||||
throw new CompileEnvironmentException(errorMessage(new String[]{module}, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (BuildException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch (CompileEnvironmentException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new CompileEnvironmentException(errorMessage(new String[]{module}, true), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CompilerPlugin> getCompilerPlugins() {
|
|
||||||
return compilerPlugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCompilerPlugins(List<CompilerPlugin> compilerPlugins) {
|
|
||||||
this.compilerPlugins = compilerPlugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static KotlinPaths getKotlinPathsForAntTask() {
|
private static KotlinPaths getKotlinPathsForAntTask() {
|
||||||
return new KotlinPathsFromHomeDir(PathUtil.getJarPathForClass(BytecodeCompiler.class).getParentFile().getParentFile());
|
return new KotlinPathsFromHomeDir(PathUtil.getJarPathForClass(BytecodeCompiler.class).getParentFile().getParentFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user