Search in sources :

Example 6 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testRawTypes.

// ------------------------------------------------------------------------------
public void testRawTypes() throws Exception {
    KotlinTestUtils.compileJavaFiles(Collections.singletonList(new File(getTestDataDirectory() + "/library/test/A.java")), Arrays.asList("-d", tmpdir.getPath()));
    Pair<String, ExitCode> outputLib = compileKotlin("library/test/lib.kt", tmpdir, tmpdir);
    Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, tmpdir);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputLib) + "\n" + normalizeOutput(outputMain));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 7 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method doTestBrokenKotlinLibrary.

private void doTestBrokenKotlinLibrary(@NotNull String libraryName, @NotNull String... pathsToDelete) throws Exception {
    // Analogous to doTestBrokenJavaLibrary, but with a Kotlin library compiled to a JAR file
    File library = copyJarFileWithoutEntry(compileLibrary(libraryName), pathsToDelete);
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 8 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testInnerClassPackageConflict2.

public void testInnerClassPackageConflict2() throws Exception {
    final File library1 = compileJava("library1");
    final File library2 = compileJava("library2");
    // Copy everything from library2 to library1
    FileUtil.visitFiles(library2, new Processor<File>() {

        @Override
        public boolean process(File file) {
            if (!file.isDirectory()) {
                File newFile = new File(library1, FilesKt.relativeTo(file, library2).getPath());
                if (!newFile.getParentFile().exists()) {
                    assert newFile.getParentFile().mkdirs();
                }
                assert file.renameTo(newFile);
            }
            return true;
        }
    });
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 9 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CLICompiler method exec.

// Used in maven (see KotlinCompileMojoBase.java)
@SuppressWarnings("WeakerAccess")
@NotNull
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
    printVersionIfNeeded(messageCollector, arguments);
    if (arguments.suppressWarnings) {
        messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
    }
    reportUnknownExtraFlags(messageCollector, arguments);
    reportUnsupportedJavaVersion(messageCollector, arguments);
    GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, groupingCollector);
    setupCommonArgumentsAndServices(configuration, arguments, services);
    setupPlatformSpecificArgumentsAndServices(configuration, arguments, services);
    try {
        ExitCode exitCode = OK;
        int repeatCount = 1;
        if (arguments.repeat != null) {
            try {
                repeatCount = Integer.parseInt(arguments.repeat);
            } catch (NumberFormatException ignored) {
            }
        }
        CompilationCanceledStatus canceledStatus = services.get(CompilationCanceledStatus.class);
        ProgressIndicatorAndCompilationCanceledStatus.setCompilationCanceledStatus(canceledStatus);
        for (int i = 0; i < repeatCount; i++) {
            if (i > 0) {
                K2JVMCompiler.Companion.resetInitStartTime();
            }
            Disposable rootDisposable = Disposer.newDisposable();
            try {
                setIdeaIoUseFallback();
                ExitCode code = doExecute(arguments, configuration, rootDisposable);
                exitCode = groupingCollector.hasErrors() ? COMPILATION_ERROR : code;
            } catch (CompilationCanceledException e) {
                messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
                return ExitCode.OK;
            } catch (RuntimeException e) {
                Throwable cause = e.getCause();
                if (cause instanceof CompilationCanceledException) {
                    messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
                    return ExitCode.OK;
                } else {
                    throw e;
                }
            } finally {
                Disposer.dispose(rootDisposable);
            }
        }
        return exitCode;
    } catch (Throwable t) {
        groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t), CompilerMessageLocation.NO_LOCATION);
        return INTERNAL_ERROR;
    } finally {
        groupingCollector.flush();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) CompilationCanceledException(org.jetbrains.kotlin.progress.CompilationCanceledException) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ProgressIndicatorAndCompilationCanceledStatus(org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus) CompilationCanceledStatus(org.jetbrains.kotlin.progress.CompilationCanceledStatus) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CLICompiler method doMain.

/**
     * Useful main for derived command line tools
     */
public static void doMain(@NotNull CLICompiler compiler, @NotNull String[] args) {
    // We depend on swing (indirectly through PSI or something), so we want to declare headless mode,
    // to avoid accidentally starting the UI thread
    System.setProperty("java.awt.headless", "true");
    ExitCode exitCode = doMainNoExit(compiler, args);
    if (exitCode != OK) {
        System.exit(exitCode.getCode());
    }
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode)

Aggregations

ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)19 File (java.io.File)15 JarFile (java.util.jar.JarFile)12 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)12 NotNull (org.jetbrains.annotations.NotNull)2 Disposable (com.intellij.openapi.Disposable)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Pair (kotlin.Pair)1 Function2 (kotlin.jvm.functions.Function2)1 K2JSCompiler (org.jetbrains.kotlin.cli.js.K2JSCompiler)1 K2JVMCompiler (org.jetbrains.kotlin.cli.jvm.K2JVMCompiler)1 EcmaVersion (org.jetbrains.kotlin.js.config.EcmaVersion)1 JvmMetadataVersion (org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion)1 CompilationCanceledException (org.jetbrains.kotlin.progress.CompilationCanceledException)1 CompilationCanceledStatus (org.jetbrains.kotlin.progress.CompilationCanceledStatus)1 ProgressIndicatorAndCompilationCanceledStatus (org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus)1 DescriptorUtils.isObject (org.jetbrains.kotlin.resolve.DescriptorUtils.isObject)1