refactor compiler launcher
* method should not modify input * replace String with File * add @NotNull and @Nullable annotations
This commit is contained in:
@@ -106,6 +106,9 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
try {
|
||||
configureEnvironment(configuration, arguments);
|
||||
|
||||
File jar = arguments.jar != null ? new File(arguments.jar) : null;
|
||||
File outputDir = arguments.outputDir != null ? new File(arguments.outputDir) : null;
|
||||
|
||||
boolean noErrors;
|
||||
if (arguments.module != null) {
|
||||
boolean oldVerbose = messageCollector.isVerbose();
|
||||
@@ -115,28 +118,30 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
messageCollector.setVerbose(oldVerbose);
|
||||
File directory = new File(arguments.module).getParentFile();
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||
directory, arguments.jar, arguments.outputDir,
|
||||
directory, jar, outputDir,
|
||||
arguments.includeRuntime);
|
||||
}
|
||||
else {
|
||||
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
|
||||
if (arguments.getSourceDirs() != null) {
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration,
|
||||
arguments.getSourceDirs(), arguments.jar, arguments.outputDir, arguments.script, arguments.includeRuntime);
|
||||
arguments.getSourceDirs(), jar, outputDir, arguments.script, arguments.includeRuntime);
|
||||
}
|
||||
else {
|
||||
List<String> sources = Lists.newArrayList();
|
||||
if (arguments.src != null) {
|
||||
sources.add(arguments.src);
|
||||
configuration.getEnvironment().addSources(arguments.src);
|
||||
}
|
||||
if (arguments.script) {
|
||||
sources.add(arguments.freeArgs.get(0));
|
||||
configuration.getEnvironment().addSources(arguments.freeArgs.get(0));
|
||||
}
|
||||
else {
|
||||
sources.addAll(arguments.freeArgs);
|
||||
for (String freeArg : arguments.freeArgs) {
|
||||
configuration.getEnvironment().addSources(freeArg);
|
||||
}
|
||||
}
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(configuration,
|
||||
sources, arguments.jar, arguments.outputDir, arguments.script, arguments.includeRuntime);
|
||||
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(
|
||||
configuration, jar, outputDir, arguments.script, arguments.includeRuntime);
|
||||
}
|
||||
}
|
||||
return noErrors ? OK : COMPILATION_ERROR;
|
||||
|
||||
@@ -276,7 +276,7 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
||||
public static void writeToOutputDirectory(ClassFileFactory factory, @NotNull File outputDir) {
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
File target = new File(outputDir, file);
|
||||
|
||||
+8
-8
@@ -90,8 +90,8 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
@NotNull List<Module> modules,
|
||||
@NotNull File directory,
|
||||
@Nullable String jarPath,
|
||||
@Nullable String outputDir,
|
||||
@Nullable File jarPath,
|
||||
@Nullable File outputDir,
|
||||
boolean jarRuntime) {
|
||||
|
||||
for (Module moduleBuilder : modules) {
|
||||
@@ -108,7 +108,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
CompileEnvironmentUtil.writeToOutputDirectory(moduleFactory, outputDir);
|
||||
}
|
||||
else {
|
||||
String path = jarPath != null ? jarPath : new File(directory, moduleBuilder.getModuleName() + ".jar").getPath();
|
||||
File path = jarPath != null ? jarPath : new File(directory, moduleBuilder.getModuleName() + ".jar");
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new FileOutputStream(path);
|
||||
@@ -131,10 +131,10 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean compileBunchOfSources(
|
||||
public static boolean compileBunchOfSources(
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
String jar,
|
||||
String outputDir,
|
||||
@Nullable File jar,
|
||||
@Nullable File outputDir,
|
||||
boolean script,
|
||||
boolean includeRuntime
|
||||
) {
|
||||
@@ -202,7 +202,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
public static boolean compileBunchOfSources(
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
List<String> sourceFilesOrDirs, String jar, String outputDir, boolean script, boolean includeRuntime) {
|
||||
List<String> sourceFilesOrDirs, File jar, File outputDir, boolean script, boolean includeRuntime) {
|
||||
for (String sourceFileOrDir : sourceFilesOrDirs) {
|
||||
configuration.getEnvironment().addSources(sourceFileOrDir);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
public static boolean compileBunchOfSourceDirectories(
|
||||
K2JVMCompileEnvironmentConfiguration configuration,
|
||||
|
||||
List<String> sources, String jar, String outputDir, boolean script, boolean includeRuntime) {
|
||||
List<String> sources, File jar, File outputDir, boolean script, boolean includeRuntime) {
|
||||
for (String source : sources) {
|
||||
configuration.getEnvironment().addSources(source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user