Minor, inline some CompileEnvironmentUtil utilities
This commit is contained in:
+17
-42
@@ -38,12 +38,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleScriptData;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.kotlin.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory;
|
||||
import org.jetbrains.kotlin.codegen.GeneratedClassLoader;
|
||||
@@ -74,12 +72,6 @@ import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.E
|
||||
|
||||
public class CompileEnvironmentUtil {
|
||||
|
||||
@Nullable
|
||||
private static File getRuntimeJarPath() {
|
||||
File runtimePath = PathUtil.getKotlinPathsForCompiler().getRuntimePath();
|
||||
return runtimePath.exists() ? runtimePath : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ModuleScriptData loadModuleDescriptions(KotlinPaths paths, String moduleDefinitionFile, MessageCollector messageCollector) {
|
||||
File file = new File(moduleDefinitionFile);
|
||||
@@ -219,27 +211,26 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
|
||||
private static void writeRuntimeToJar(JarOutputStream stream) throws IOException {
|
||||
File runtimeJarPath = getRuntimeJarPath();
|
||||
if (runtimeJarPath != null) {
|
||||
JarInputStream jis = new JarInputStream(new FileInputStream(runtimeJarPath));
|
||||
try {
|
||||
while (true) {
|
||||
JarEntry e = jis.getNextJarEntry();
|
||||
if (e == null) {
|
||||
break;
|
||||
}
|
||||
if (FileUtilRt.extensionEquals(e.getName(), "class")) {
|
||||
stream.putNextEntry(e);
|
||||
FileUtil.copy(jis, stream);
|
||||
}
|
||||
File runtimePath = PathUtil.getKotlinPathsForCompiler().getRuntimePath();
|
||||
if (!runtimePath.exists()) {
|
||||
throw new CompileEnvironmentException("Couldn't find runtime library");
|
||||
}
|
||||
|
||||
JarInputStream jis = new JarInputStream(new FileInputStream(runtimePath));
|
||||
try {
|
||||
while (true) {
|
||||
JarEntry e = jis.getNextJarEntry();
|
||||
if (e == null) {
|
||||
break;
|
||||
}
|
||||
if (FileUtilRt.extensionEquals(e.getName(), "class")) {
|
||||
stream.putNextEntry(e);
|
||||
FileUtil.copy(jis, stream);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
jis.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new CompileEnvironmentException("Couldn't find runtime library");
|
||||
finally {
|
||||
jis.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,22 +244,6 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static void writeOutputToDirOrJar(
|
||||
@Nullable File jar,
|
||||
@Nullable File outputDir,
|
||||
boolean includeRuntime,
|
||||
@Nullable FqName mainClass,
|
||||
@NotNull ClassFileFactory outputFiles,
|
||||
@NotNull MessageCollector messageCollector
|
||||
) {
|
||||
if (jar != null) {
|
||||
writeToJar(jar, includeRuntime, mainClass, outputFiles);
|
||||
}
|
||||
else {
|
||||
OutputUtilsPackage.writeAll(outputFiles, outputDir == null ? new File(".") : outputDir, messageCollector);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> getJetFiles(
|
||||
@NotNull final Project project,
|
||||
|
||||
+8
-2
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.kotlin.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.kotlin.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
@@ -100,8 +101,13 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
boolean jarRuntime,
|
||||
@Nullable FqName mainClass
|
||||
) {
|
||||
MessageCollector messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE);
|
||||
CompileEnvironmentUtil.writeOutputToDirOrJar(jarPath, outputDir, jarRuntime, mainClass, outputFiles, messageCollector);
|
||||
if (jarPath != null) {
|
||||
CompileEnvironmentUtil.writeToJar(jarPath, jarRuntime, mainClass, outputFiles);
|
||||
}
|
||||
else {
|
||||
MessageCollector messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE);
|
||||
OutputUtilsPackage.writeAll(outputFiles, outputDir == null ? new File(".") : outputDir, messageCollector);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean compileModules(
|
||||
|
||||
Reference in New Issue
Block a user