diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java index a861b1e2956..2235ff0cd95 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java @@ -26,9 +26,6 @@ public abstract class CommonCompilerArguments { @Argument(value = "nowarn", description = "Generate no warnings") public boolean suppressWarnings; - @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag") - public boolean tags; - @Argument(value = "verbose", description = "Enable verbose logging output") public boolean verbose; diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java index d2954a1713d..12bfcd8fe42 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java @@ -22,6 +22,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.util.Disposer; import com.sampullara.cli.Args; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; @@ -48,44 +49,34 @@ public abstract class CLICompiler { @NotNull public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) { - A arguments = createArguments(); - if (!parseArguments(errStream, arguments, args)) { - return INTERNAL_ERROR; - } - return exec(errStream, getMessageRenderer(arguments), arguments); + return exec(errStream, MessageRenderer.PLAIN, args); } @SuppressWarnings("UnusedDeclaration") // Used via reflection in CompilerRunnerUtil#invokeExecMethod @NotNull public ExitCode execAndOutputHtml(@NotNull PrintStream errStream, @NotNull String... args) { - A arguments = createArguments(); - if (!parseArguments(errStream, arguments, args)) { - return INTERNAL_ERROR; - } - return exec(errStream, MessageRenderer.TAGS, arguments); + return exec(errStream, MessageRenderer.TAGS, args); } - /** - * Returns true if the arguments can be parsed correctly - */ - protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) { + @Nullable + private A parseArguments(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) { try { + A arguments = createArguments(); arguments.freeArgs = Args.parse(arguments, args); - return true; + return arguments; } catch (IllegalArgumentException e) { errStream.println(e.getMessage()); usage(errStream, false); } catch (Throwable t) { - // Always use tags - errStream.println(MessageRenderer.TAGS.render( + errStream.println(messageRenderer.render( CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t), CompilerMessageLocation.NO_LOCATION) ); } - return false; + return null; } /** @@ -106,11 +97,13 @@ public abstract class CLICompiler { @NotNull protected abstract A createArguments(); - /** - * Executes the compiler on the parsed arguments - */ @NotNull - public ExitCode exec(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull A arguments) { + private ExitCode exec(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) { + A arguments = parseArguments(errStream, messageRenderer, args); + if (arguments == null) { + return INTERNAL_ERROR; + } + if (arguments.help || arguments.extraHelp) { usage(errStream, arguments.extraHelp); return OK; @@ -161,12 +154,6 @@ public abstract class CLICompiler { @NotNull protected abstract ExitCode doExecute(@NotNull A arguments, @NotNull MessageCollector messageCollector, @NotNull Disposable rootDisposable); - //TODO: can we make it private? - @NotNull - protected MessageRenderer getMessageRenderer(@NotNull A arguments) { - return arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN; - } - protected void printVersionIfNeeded( @NotNull PrintStream errStream, @NotNull A arguments, diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index c23c79f5978..01fea73ad76 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -8,7 +8,6 @@ where possible options include: -output-prefix Path to file which will be added to the beginning of output file -output-postfix Path to file which will be added to the end of output file -nowarn Generate no warnings - -tags Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose Enable verbose logging output -version Display compiler version -help (-h) Print a synopsis of standard options diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index 31b661d85e1..1e57bcf2f98 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -11,7 +11,6 @@ where possible options include: -script Evaluate the script file -kotlin-home Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery -nowarn Generate no warnings - -tags Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose Enable verbose logging output -version Display compiler version -help (-h) Print a synopsis of standard options diff --git a/compiler/testData/cli/jvm/wrongArgument.out b/compiler/testData/cli/jvm/wrongArgument.out index cb7e8baa86b..fe9de40aa70 100644 --- a/compiler/testData/cli/jvm/wrongArgument.out +++ b/compiler/testData/cli/jvm/wrongArgument.out @@ -12,7 +12,6 @@ where possible options include: -script Evaluate the script file -kotlin-home Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery -nowarn Generate no warnings - -tags Demarcate each compilation message (error, warning, etc) with an open and close tag -verbose Enable verbose logging output -version Display compiler version -help (-h) Print a synopsis of standard options diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java index a7005b0244b..a87e983be9c 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.compiler.runner; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; @@ -41,19 +42,14 @@ import static org.jetbrains.jet.cli.common.messages.MessageCollectorUtil.reportE public class CompilerOutputParser { public static void parseCompilerMessagesFromReader(MessageCollector messageCollector, final Reader reader, OutputItemsCollector collector) { - // Sometimes the compiler can't output valid XML - // Example: error in command line arguments passed to the compiler - // having no -tags key (arguments are not parsed), the compiler doesn't know - // if it should put any tags in the output, so it will simply print the usage - // and the SAX parser will break. - // In this case, we want to read everything from this stream - // and report it as an IDE error. + // Sometimes the compiler doesn't output valid XML. + // Example: error in command line arguments passed to the compiler. + // The compiler will print the usage and the SAX parser will break. + // In this case, we want to read everything from this stream and report it as an IDE error. final StringBuilder stringBuilder = new StringBuilder(); - //noinspection IOResourceOpenedButNotSafelyClosed Reader wrappingReader = new Reader() { - @Override - public int read(char[] cbuf, int off, int len) throws IOException { + public int read(@NotNull char[] cbuf, int off, int len) throws IOException { int read = reader.read(cbuf, off, len); stringBuilder.append(cbuf, off, len); return read; @@ -74,7 +70,6 @@ public class CompilerOutputParser { parser.parse(new InputSource(wrappingReader), new CompilerOutputSAXHandler(messageCollector, collector)); } catch (Throwable e) { - // Load all the text into the stringBuilder try { // This will not close the reader (see the wrapper above) @@ -112,7 +107,7 @@ public class CompilerOutputParser { private final OutputItemsCollector collector; private final StringBuilder message = new StringBuilder(); - private Stack tags = new Stack(); + private final Stack tags = new Stack(); private String path; private int line; private int column; @@ -123,7 +118,8 @@ public class CompilerOutputParser { } @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + public void startElement(@NotNull String uri, @NotNull String localName, @NotNull String qName, @NotNull Attributes attributes) + throws SAXException { tags.push(qName); message.setLength(0); @@ -148,7 +144,7 @@ public class CompilerOutputParser { } @Override - public void endElement(String uri, String localName, String qName) throws SAXException { + public void endElement(String uri, @NotNull String localName, @NotNull String qName) throws SAXException { if (tags.size() == 1) { // We're directly inside the root tag: return; diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java index 8bc2b859116..c4f47b10201 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java @@ -131,7 +131,6 @@ public class KotlinCompilerRunner { } private static void setupCommonSettings(CommonCompilerArguments settings) { - settings.tags = true; settings.verbose = true; } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java index 2e2f429c577..9a075e3094c 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java @@ -17,15 +17,16 @@ package org.jetbrains.k2js.test.semantics; import com.google.common.collect.Lists; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.ExitCode; -import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; -import org.jetbrains.jet.cli.common.messages.MessageRenderer; import org.jetbrains.jet.cli.js.K2JSCompiler; import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.test.SingleFileTranslationTest; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -35,7 +36,6 @@ import java.util.List; * has completed so that there are various kotlin files to be compiled */ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { - protected final String generatedJsDir = "libraries/tools/kotlin-js-library/target/"; protected String generatedJsDefinitionsDir = generatedJsDir + "generated-js-definitions"; protected File generatedJsLibraryDir = new File( generatedJsDir + "generated-js-library"); @@ -66,22 +66,23 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { "collections/ListTest.kt", "collections/SetTest.kt", "text/StringTest.kt"); - - } else { + } + else { System.out.println("Warning " + generatedJsLibraryDir + " does not exist - I guess you've not run the maven build in library/ yet?"); } } - protected void generateJavaScriptFiles(@NotNull Iterable ecmaVersions, - @NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception { + private void generateJavaScriptFiles( + @NotNull Iterable ecmaVersions, + @NotNull String sourceDir, + @NotNull String... stdLibFiles + ) throws Exception { List files = Lists.newArrayList(); - // now lets add all the files from the definitions and library //addAllSourceFiles(files, generatedJsDefinitionsDir); addAllSourceFiles(files, generatedJsLibraryDir); - File stdlibDir = new File(sourceDir); assertTrue("Cannot find stdlib test source: " + stdlibDir, stdlibDir.exists()); for (String file : stdLibFiles) { @@ -90,14 +91,17 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { // now lets try invoke the compiler for (EcmaVersion version : ecmaVersions) { - K2JSCompiler compiler = new K2JSCompiler(); - K2JSCompilerArguments arguments = new K2JSCompilerArguments(); - arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version); - arguments.freeArgs = files; - arguments.verbose = true; - arguments.libraryFiles = new String[] {generatedJsDefinitionsDir}; - System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); - ExitCode answer = compiler.exec(System.out, MessageRenderer.PLAIN, arguments); + String outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version); + System.out.println("Compiling with version: " + version + " to: " + outputFile); + + List args = new ArrayList(Arrays.asList( + "-output", outputFile, + "-library-files", generatedJsDefinitionsDir, + "-verbose" + )); + args.addAll(files); + ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args)); + assertEquals("Compile failed", ExitCode.OK, answer); } } @@ -108,7 +112,8 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { for (File child : children) { if (child.isDirectory()) { addAllSourceFiles(files, child); - } else { + } + else { String name = child.getName(); if (name.toLowerCase().endsWith(".kt")) { files.add(child.getPath()); diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java index aec5d6eb726..c791c17d847 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java @@ -20,18 +20,17 @@ import com.google.common.collect.Lists; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.ExitCode; -import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; -import org.jetbrains.jet.cli.common.messages.MessageRenderer; import org.jetbrains.jet.cli.js.K2JSCompiler; import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.test.SingleFileTranslationTest; import org.jetbrains.k2js.test.utils.LibraryFilePathsUtil; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; abstract class StdLibTestBase extends SingleFileTranslationTest { - protected StdLibTestBase() { super("stdlib/"); } @@ -66,16 +65,19 @@ abstract class StdLibTestBase extends SingleFileTranslationTest { } //TODO: reuse this in CompileMavenGeneratedJSLibrary - private static void invokeCompiler(@NotNull List files, @NotNull List libFiles, - @NotNull EcmaVersion version, @NotNull String outputFilePath) { - K2JSCompiler compiler = new K2JSCompiler(); - K2JSCompilerArguments arguments = new K2JSCompilerArguments(); - arguments.outputFile = outputFilePath; - arguments.freeArgs = files; - arguments.verbose = true; - arguments.libraryFiles = ArrayUtil.toStringArray(libFiles); - System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); - ExitCode answer = compiler.exec(System.out, MessageRenderer.PLAIN, arguments); + private static void invokeCompiler( + @NotNull List files, + @NotNull List libFiles, + @NotNull EcmaVersion version, + @NotNull String outputFilePath + ) { + System.out.println("Compiling with version: " + version + " to: " + outputFilePath); + + List args = new ArrayList(Arrays.asList("-output", outputFilePath, "-verbose", "-library-files")); + args.addAll(libFiles); + args.addAll(files); + ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args)); + assertEquals("Compile failed", ExitCode.OK, answer); }