Minor: report error instead of crash with exceptions when collect JetFiles to compile and remove obsolete (wrong now) code

#EA-61681 Obsolete
This commit is contained in:
Zalim Bashorov
2015-09-10 22:32:24 +03:00
parent 909cbc6817
commit 1b00eb3a17
9 changed files with 43 additions and 8 deletions
@@ -171,19 +171,22 @@ public open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val compilerConfiguration = KotlinToJVMBytecodeCompiler.createCompilerConfiguration(configuration, moduleScript.getModules(), directory)
environment = createCoreEnvironment(rootDisposable, compilerConfiguration)
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
KotlinToJVMBytecodeCompiler.compileModules(environment, configuration, moduleScript.getModules(), directory, jar, arguments.includeRuntime)
}
else if (arguments.script) {
val scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size())
environment = createCoreEnvironment(rootDisposable, configuration)
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(configuration, paths, environment, scriptArgs)
}
else {
environment = createCoreEnvironment(rootDisposable, configuration)
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) {
return COMPILATION_ERROR
}
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
if (environment.getSourceFiles().isEmpty()) {
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
@@ -85,11 +85,6 @@ public class KotlinToJVMBytecodeCompiler {
if (!source.isAbsolute()) {
source = new File(directory, sourceFile);
}
if (!source.exists()) {
throw new CompileEnvironmentException("'" + source + "' does not exist in module " + module.getModuleName());
}
result.add(source.getAbsolutePath());
}
return result;
@@ -0,0 +1,2 @@
-module
$TESTDATA_DIR$/nonexistentPathInModule.xml
+3
View File
@@ -0,0 +1,3 @@
error: source file or directory not found: $TESTDATA_DIR$/nonexistentFile.kt
error: source file or directory not found: $TESTDATA_DIR$/some/nonexistent/dir
COMPILATION_ERROR
+6
View File
@@ -0,0 +1,6 @@
<modules>
<module name="name" outputDir="whatever" type="java-production">
<sources path="nonexistentFile.kt"/>
<sources path="some/nonexistent/dir/"/>
</module>
</modules>
+2
View File
@@ -0,0 +1,2 @@
-script
path/to/nonexistent.kts
+2
View File
@@ -0,0 +1,2 @@
error: source file or directory not found: path/to/nonexistent.kts
COMPILATION_ERROR
@@ -53,6 +53,16 @@ public class CliCommonTest extends CliBaseTest {
executeCompilerCompareOutputJVM();
}
@Test
public void nonexistentPathInModule() throws Exception {
executeCompilerCompareOutputJVM();
}
@Test
public void nonexistentScript() throws Exception {
executeCompilerCompareOutputJVM();
}
@Test
public void diagnosticsOrder() throws Exception {
executeCompilerCompareOutputJVM();
@@ -169,6 +169,18 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJvmTest(fileName);
}
@TestMetadata("nonexistentPathInModule.args")
public void testNonexistentPathInModule() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/nonexistentPathInModule.args");
doJvmTest(fileName);
}
@TestMetadata("nonexistentScript.args")
public void testNonexistentScript() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/nonexistentScript.args");
doJvmTest(fileName);
}
@TestMetadata("pluginSimple.args")
public void testPluginSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/pluginSimple.args");