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));
}
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));
}
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));
}
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();
}
}
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());
}
}
Aggregations