Search in sources :

Example 11 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method doTestPreReleaseKotlinLibrary.

@SuppressWarnings("deprecation")
private void doTestPreReleaseKotlinLibrary(@NotNull CLICompiler<?> compiler, @NotNull String libraryName, @NotNull File destination, @NotNull File result, @NotNull String... additionalOptions) throws Exception {
    try {
        System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "true");
        compileLibrary(compiler, libraryName, destination, Collections.<String>emptyList());
    } finally {
        System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
    }
    Pair<String, ExitCode> output;
    try {
        System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false");
        output = compileKotlin(compiler, "source.kt", tmpdir, Arrays.asList(additionalOptions), result);
    } finally {
        System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
    }
    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 12 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method testMissingDependencyJavaConflictingLibraries.

public void testMissingDependencyJavaConflictingLibraries() throws Exception {
    File library1 = deletePaths(compileJava("library1"), "test/A.class", "test/A$Inner.class");
    File library2 = deletePaths(compileJava("library2"), "test/A.class", "test/A$Inner.class");
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1, library2);
    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 13 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method doTestBrokenJavaLibrary.

private void doTestBrokenJavaLibrary(@NotNull String libraryName, @NotNull String... pathsToDelete) throws Exception {
    // This function compiles a Java library, then deletes one class file and attempts to compile a Kotlin source against
    // this broken library. The expected result is an error message from the compiler
    File library = deletePaths(compileJava(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 14 with ExitCode

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

the class KotlinCompileMojoBase method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Kotlin Compiler version " + KotlinCompilerVersion.VERSION);
    if (!hasKotlinFilesInSources()) {
        getLog().warn("No sources found skipping Kotlin compile");
        return;
    }
    A arguments = createCompilerArguments();
    CLICompiler<A> compiler = createCompiler();
    configureCompilerArguments(arguments, compiler);
    printCompilerArgumentsIfDebugEnabled(arguments, compiler);
    MavenPluginLogMessageCollector messageCollector = new MavenPluginLogMessageCollector(getLog());
    ExitCode exitCode = compiler.exec(messageCollector, Services.EMPTY, arguments);
    if (exitCode != ExitCode.OK) {
        messageCollector.throwKotlinCompilerException();
    }
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode)

Example 15 with ExitCode

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

the class AbstractCliTest method doTest.

private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler, BinaryVersion version) throws Exception {
    System.setProperty("java.awt.headless", "true");
    Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath()));
    String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), new File(fileName).getParent(), version);
    File outFile = new File(fileName.replaceFirst("\\.args$", ".out"));
    KotlinTestUtils.assertEqualsToFile(outFile, actual);
    File additionalTestConfig = new File(fileName.replaceFirst("\\.args$", ".test"));
    if (additionalTestConfig.exists()) {
        doTestAdditionalChecks(additionalTestConfig);
    }
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) File(java.io.File)

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