Search in sources :

Example 1 with K2JVMCompiler

use of org.jetbrains.kotlin.cli.jvm.K2JVMCompiler in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testReleaseCompilerAgainstPreReleaseLibrary.

public void testReleaseCompilerAgainstPreReleaseLibrary() throws Exception {
    File destination = new File(tmpdir, "library.jar");
    doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination);
}
Also used : K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 2 with K2JVMCompiler

use of org.jetbrains.kotlin.cli.jvm.K2JVMCompiler in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method compileKotlin.

@NotNull
private Pair<String, ExitCode> compileKotlin(@NotNull CLICompiler<?> compiler, @NotNull String fileName, @NotNull File output, @NotNull List<String> additionalOptions, @NotNull File... classpath) {
    List<String> args = new ArrayList<String>();
    File sourceFile = new File(getTestDataDirectory(), fileName);
    assert sourceFile.exists() : "Source file does not exist: " + sourceFile.getAbsolutePath();
    args.add(sourceFile.getPath());
    if (compiler instanceof K2JSCompiler) {
        if (classpath.length > 0) {
            args.add("-libraries");
            args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
        }
        args.add("-output");
        args.add(output.getPath());
        args.add("-meta-info");
    } else if (compiler instanceof K2JVMCompiler) {
        if (classpath.length > 0) {
            args.add("-classpath");
            args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
        }
        args.add("-d");
        args.add(output.getPath());
    } else {
        throw new UnsupportedOperationException(compiler.toString());
    }
    args.addAll(additionalOptions);
    return AbstractCliTest.executeCompilerGrabOutput(compiler, args);
}
Also used : K2JSCompiler(org.jetbrains.kotlin.cli.js.K2JSCompiler) K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with K2JVMCompiler

use of org.jetbrains.kotlin.cli.jvm.K2JVMCompiler in project kotlin by JetBrains.

the class CompileEnvironmentTest method testSmokeWithCompilerOutput.

public void testSmokeWithCompilerOutput() throws IOException {
    File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
    try {
        File out = new File(tempDir, "out");
        File stdlib = ForTestCompileRuntime.runtimeJarForTests();
        ExitCode exitCode = new K2JVMCompiler().exec(System.out, KotlinTestUtils.getTestDataPathBase() + "/compiler/smoke/Smoke.kt", "-d", out.getAbsolutePath(), "-no-stdlib", "-classpath", stdlib.getAbsolutePath());
        Assert.assertEquals(ExitCode.OK, exitCode);
        File[] files = out.listFiles();
        Arrays.sort(files);
        assertEquals(2, files.length);
        //META-INF
        assertEquals(1, files[0].listFiles().length);
        // SmokeKt
        assertEquals(1, files[1].listFiles().length);
    } finally {
        FileUtil.delete(tempDir);
    }
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) File(java.io.File)

Example 4 with K2JVMCompiler

use of org.jetbrains.kotlin.cli.jvm.K2JVMCompiler in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method compileLibrary.

private File compileLibrary(@NotNull String sourcePath, List<String> additionalOptions, @NotNull File... extraClassPath) {
    File destination = new File(tmpdir, sourcePath + ".jar");
    compileLibrary(new K2JVMCompiler(), sourcePath, destination, additionalOptions, extraClassPath);
    return destination;
}
Also used : K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 5 with K2JVMCompiler

use of org.jetbrains.kotlin.cli.jvm.K2JVMCompiler in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck.

public void testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck() throws Exception {
    File destination = new File(tmpdir, "library.jar");
    doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination, "-Xskip-metadata-version-check");
}
Also used : K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Aggregations

File (java.io.File)5 K2JVMCompiler (org.jetbrains.kotlin.cli.jvm.K2JVMCompiler)5 JarFile (java.util.jar.JarFile)4 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)4 NotNull (org.jetbrains.annotations.NotNull)1 ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)1 K2JSCompiler (org.jetbrains.kotlin.cli.js.K2JSCompiler)1