JPS plugin: make the code more understandable -- added some comments and rename scriptFile to moduleFile.
This commit is contained in:
+13
-12
@@ -41,34 +41,34 @@ public class KotlinCompilerRunner {
|
||||
public static void runCompiler(
|
||||
MessageCollector messageCollector,
|
||||
CompilerEnvironment environment,
|
||||
File scriptFile,
|
||||
File moduleFile,
|
||||
OutputItemsCollector collector,
|
||||
boolean runOutOfProcess
|
||||
) {
|
||||
if (runOutOfProcess) {
|
||||
runOutOfProcess(messageCollector, collector, environment, scriptFile);
|
||||
runOutOfProcess(messageCollector, collector, environment, moduleFile);
|
||||
}
|
||||
else {
|
||||
runInProcess(messageCollector, collector, environment, scriptFile);
|
||||
runInProcess(messageCollector, collector, environment, moduleFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runInProcess(final MessageCollector messageCollector,
|
||||
OutputItemsCollector collector,
|
||||
final CompilerEnvironment environment,
|
||||
final File scriptFile) {
|
||||
final File moduleFile) {
|
||||
CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
|
||||
@Override
|
||||
public Integer fun(PrintStream stream) {
|
||||
return execInProcess(environment, scriptFile, stream, messageCollector);
|
||||
return execInProcess(environment, moduleFile, stream, messageCollector);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static int execInProcess(CompilerEnvironment environment, File scriptFile, PrintStream out, MessageCollector messageCollector) {
|
||||
private static int execInProcess(CompilerEnvironment environment, File moduleFile, PrintStream out, MessageCollector messageCollector) {
|
||||
try {
|
||||
String compilerClassName = "org.jetbrains.jet.cli.jvm.K2JVMCompiler";
|
||||
String[] arguments = commandLineArguments(environment.getOutput(), scriptFile);
|
||||
String[] arguments = commandLineArguments(environment.getOutput(), moduleFile);
|
||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||
"Using kotlinHome=" + environment.getKotlinPaths().getHomePath(),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
@@ -87,9 +87,9 @@ public class KotlinCompilerRunner {
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] commandLineArguments(File outputDir, File scriptFile) {
|
||||
private static String[] commandLineArguments(File outputDir, File moduleFile) {
|
||||
return new String[]{
|
||||
"-module", scriptFile.getAbsolutePath(),
|
||||
"-module", moduleFile.getAbsolutePath(),
|
||||
"-output", outputDir.getPath(),
|
||||
"-tags", "-verbose", "-version",
|
||||
"-notNullAssertions", "-notNullParamAssertions",
|
||||
@@ -100,13 +100,13 @@ public class KotlinCompilerRunner {
|
||||
final MessageCollector messageCollector,
|
||||
final OutputItemsCollector itemCollector,
|
||||
CompilerEnvironment environment,
|
||||
File scriptFile
|
||||
File moduleFile
|
||||
) {
|
||||
SimpleJavaParameters params = new SimpleJavaParameters();
|
||||
params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
|
||||
params.setMainClass("org.jetbrains.jet.cli.jvm.K2JVMCompiler");
|
||||
|
||||
for (String arg : commandLineArguments(environment.getOutput(), scriptFile)) {
|
||||
for (String arg : commandLineArguments(environment.getOutput(), moduleFile)) {
|
||||
params.getProgramParametersList().add(arg);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,8 @@ public class KotlinCompilerRunner {
|
||||
|
||||
Sdk sdk = params.getJdk();
|
||||
|
||||
assert sdk != null;
|
||||
|
||||
GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(
|
||||
((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false);
|
||||
|
||||
@@ -157,7 +159,6 @@ public class KotlinCompilerRunner {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"[Internal Error] " + e.getLocalizedMessage(),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
OutputConsumer outputConsumer
|
||||
) throws ProjectBuildException, IOException {
|
||||
MessageCollector messageCollector = new MessageCollectorAdapter(context);
|
||||
// Workaround for Android Studio
|
||||
if (!isJavaPluginEnabled(context)) {
|
||||
messageCollector.report(INFO, "Kotlin JPS plugin is disabled", CompilerMessageLocation.NO_LOCATION);
|
||||
return ExitCode.NOTHING_DONE;
|
||||
@@ -141,6 +142,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
|
||||
private static boolean isJavaPluginEnabled(@NotNull CompileContext context) {
|
||||
try {
|
||||
// Using reflection for backward compatibility with IDEA 12
|
||||
Field javaPluginIsEnabledField = JavaBuilder.class.getDeclaredField("IS_ENABLED");
|
||||
return Modifier.isPublic(javaPluginIsEnabledField.getModifiers()) ? JavaBuilder.IS_ENABLED.get(context, Boolean.TRUE) : true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user