Removed the exec(String...) method in KotlinCompiler

It's important to be aware of what stream the messages will be written to, so such a default implementation is harmful
This commit is contained in:
Andrey Breslav
2012-04-13 19:59:28 +04:00
parent 882412ea06
commit 4eb594024a
3 changed files with 11 additions and 18 deletions
@@ -72,7 +72,7 @@ public class KotlinCompiler {
*/ */
public static void doMain(KotlinCompiler compiler, String[] args) { public static void doMain(KotlinCompiler compiler, String[] args) {
try { try {
ExitCode rc = compiler.exec(args); ExitCode rc = compiler.exec(System.out, args);
if (rc != OK) { if (rc != OK) {
System.err.println("exec() finished with " + rc + " return code"); System.err.println("exec() finished with " + rc + " return code");
System.exit(rc.getCode()); System.exit(rc.getCode());
@@ -83,10 +83,6 @@ public class KotlinCompiler {
} }
} }
public ExitCode exec(String... args) {
return exec(System.out, args);
}
public ExitCode exec(PrintStream errStream, String... args) { public ExitCode exec(PrintStream errStream, String... args) {
CompilerArguments arguments = createArguments(); CompilerArguments arguments = createArguments();
if (!parseArguments(errStream, arguments, args)) { if (!parseArguments(errStream, arguments, args)) {
@@ -18,11 +18,9 @@ package org.jetbrains.jet.compiler;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.jetbrains.jet.CompileCompilerDependenciesTest;
import org.jetbrains.jet.cli.KotlinCompiler; import org.jetbrains.jet.cli.KotlinCompiler;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.parsing.JetParsingTest; import org.jetbrains.jet.parsing.JetParsingTest;
import org.junit.Assert; import org.junit.Assert;
@@ -47,11 +45,11 @@ public class CompileEnvironmentTest extends TestCase {
File stdlib = ForTestCompileRuntime.runtimeJarForTests(); File stdlib = ForTestCompileRuntime.runtimeJarForTests();
File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests(); File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests();
File resultJar = new File(tempDir, "result.jar"); File resultJar = new File(tempDir, "result.jar");
KotlinCompiler.ExitCode rv = new KotlinCompiler().exec( KotlinCompiler.ExitCode rv = new KotlinCompiler().exec(System.out,
"-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts", "-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
"-jar", resultJar.getAbsolutePath(), "-jar", resultJar.getAbsolutePath(),
"-stdlib", stdlib.getAbsolutePath(), "-stdlib", stdlib.getAbsolutePath(),
"-jdkHeaders", jdkHeaders.getAbsolutePath()); "-jdkHeaders", jdkHeaders.getAbsolutePath());
Assert.assertEquals("compilation completed with non-zero code", KotlinCompiler.ExitCode.OK, rv); Assert.assertEquals("compilation completed with non-zero code", KotlinCompiler.ExitCode.OK, rv);
FileInputStream fileInputStream = new FileInputStream(resultJar); FileInputStream fileInputStream = new FileInputStream(resultJar);
try { try {
@@ -80,11 +78,9 @@ public class CompileEnvironmentTest extends TestCase {
File out = new File(tempDir, "out"); File out = new File(tempDir, "out");
File stdlib = ForTestCompileRuntime.runtimeJarForTests(); File stdlib = ForTestCompileRuntime.runtimeJarForTests();
File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests(); File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests();
KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec( KotlinCompiler.ExitCode exitCode = new KotlinCompiler()
"-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", .exec(System.out, "-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", "-output",
"-output", out.getAbsolutePath(), out.getAbsolutePath(), "-stdlib", stdlib.getAbsolutePath(), "-jdkHeaders", jdkHeaders.getAbsolutePath());
"-stdlib", stdlib.getAbsolutePath(),
"-jdkHeaders", jdkHeaders.getAbsolutePath());
Assert.assertEquals(KotlinCompiler.ExitCode.OK, exitCode); Assert.assertEquals(KotlinCompiler.ExitCode.OK, exitCode);
assertEquals(1, out.listFiles().length); assertEquals(1, out.listFiles().length);
assertEquals(1, out.listFiles()[0].listFiles().length); assertEquals(1, out.listFiles()[0].listFiles().length);
@@ -60,7 +60,8 @@ public abstract class AbstractLibrariesTest extends PlatformTestCase {
}); });
librarySourceDir = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/library"); librarySourceDir = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/library");
assertNotNull(librarySourceDir); assertNotNull(librarySourceDir);
KotlinCompiler.ExitCode compilerExec = new KotlinCompiler().exec("-src", librarySourceDir.getPath(), "-output", libraryIoDir.getAbsolutePath()); KotlinCompiler.ExitCode compilerExec =
new KotlinCompiler().exec(System.out, "-src", librarySourceDir.getPath(), "-output", libraryIoDir.getAbsolutePath());
assertEquals(KotlinCompiler.ExitCode.OK, compilerExec); assertEquals(KotlinCompiler.ExitCode.OK, compilerExec);
libraryDir = LocalFileSystem.getInstance().findFileByIoFile(libraryIoDir); libraryDir = LocalFileSystem.getInstance().findFileByIoFile(libraryIoDir);
assertNotNull(libraryDir); assertNotNull(libraryDir);