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