refactor PathUtil - it is a big difference now, whether we find sdk home from plugin or from compiler
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
e5589e1037
commit
843fb8d7a9
@@ -21,6 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.*;
|
||||
import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
@@ -63,7 +65,7 @@ public class BytecodeCompiler {
|
||||
configuration.add(CLASSPATH_KEY, new File(stdlib));
|
||||
}
|
||||
else {
|
||||
File path = PathUtil.getDefaultRuntimePath();
|
||||
File path = CompilerPathUtil.getRuntimePath();
|
||||
if (path != null) {
|
||||
configuration.add(CLASSPATH_KEY, path);
|
||||
}
|
||||
@@ -73,7 +75,7 @@ public class BytecodeCompiler {
|
||||
configuration.add(CLASSPATH_KEY, new File(path));
|
||||
}
|
||||
}
|
||||
File jdkAnnotationsPath = PathUtil.getJdkAnnotationsPath();
|
||||
File jdkAnnotationsPath = CompilerPathUtil.getJdkAnnotationsPath();
|
||||
if (jdkAnnotationsPath != null) {
|
||||
configuration.add(ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.cli.common.util;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Maxim.Manuylov
|
||||
* Date: 20.05.12
|
||||
*/
|
||||
public class CompilerPathUtil {
|
||||
private CompilerPathUtil() {}
|
||||
|
||||
@Nullable
|
||||
public static File getSDKHome() {
|
||||
final File compilerJar = new File(getJarPathForClass(CompilerPathUtil.class));
|
||||
if (!compilerJar.exists()) return null;
|
||||
|
||||
if (compilerJar.getName().equals(PathUtil.KOTLIN_COMPILER_JAR)) {
|
||||
final File lib = compilerJar.getParentFile();
|
||||
final File answer = lib.getParentFile();
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
|
||||
File current = new File("").getAbsoluteFile(); // CWD
|
||||
|
||||
do {
|
||||
File atDevHome = new File(current, "dist/kotlinc");
|
||||
if (atDevHome.exists()) return atDevHome;
|
||||
current = current.getParentFile();
|
||||
} while (current != null);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getRuntimePath() {
|
||||
return PathUtil.getRuntimePath(getSDKHome());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJdkAnnotationsPath() {
|
||||
return PathUtil.getJdkAnnotationsPath(getSDKHome());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getJarPathForClass(@NotNull final Class aClass) {
|
||||
final String resourceRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class");
|
||||
return new File(resourceRoot).getAbsoluteFile().getAbsolutePath();
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||
@@ -180,7 +181,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
classpath.add(PathUtil.findRtJar());
|
||||
}
|
||||
if (!arguments.noStdlib) {
|
||||
classpath.add(PathUtil.getDefaultRuntimePath());
|
||||
classpath.add(CompilerPathUtil.getRuntimePath());
|
||||
}
|
||||
if (arguments.classpath != null) {
|
||||
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) {
|
||||
@@ -194,7 +195,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
private static List<File> getAnnotationsPath(@NotNull K2JVMCompilerArguments arguments) {
|
||||
List<File> annotationsPath = Lists.newArrayList();
|
||||
if (!arguments.noJdkAnnotations) {
|
||||
annotationsPath.add(PathUtil.getJdkAnnotationsPath());
|
||||
annotationsPath.add(CompilerPathUtil.getJdkAnnotationsPath());
|
||||
}
|
||||
if (arguments.annotations != null) {
|
||||
for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.annotations)) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
@@ -89,12 +90,12 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
};
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
File defaultRuntimePath = PathUtil.getDefaultRuntimePath();
|
||||
File defaultRuntimePath = CompilerPathUtil.getRuntimePath();
|
||||
if (defaultRuntimePath != null) {
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, defaultRuntimePath);
|
||||
}
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.findRtJar());
|
||||
File jdkAnnotationsPath = PathUtil.getJdkAnnotationsPath();
|
||||
File jdkAnnotationsPath = CompilerPathUtil.getJdkAnnotationsPath();
|
||||
if (jdkAnnotationsPath != null) {
|
||||
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
|
||||
}
|
||||
@@ -124,7 +125,7 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
|
||||
private static List<Module> runDefineModules(String moduleFile, ClassFileFactory factory) {
|
||||
File stdlibJar = PathUtil.getDefaultRuntimePath();
|
||||
File stdlibJar = CompilerPathUtil.getRuntimePath();
|
||||
GeneratedClassLoader loader;
|
||||
if (stdlibJar != null) {
|
||||
try {
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.jet.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
@@ -241,7 +242,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
try {
|
||||
GeneratedClassLoader classLoader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{
|
||||
// TODO: add all classpath
|
||||
PathUtil.getDefaultRuntimePath().toURI().toURL()
|
||||
CompilerPathUtil.getRuntimePath().toURI().toURL()
|
||||
},
|
||||
AllModules.class.getClassLoader()));
|
||||
Class<?> scriptClass = classLoader.loadClass(ScriptCodegen.SCRIPT_DEFAULT_CLASS_NAME.getFqName().getFqName());
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
package org.jetbrains.jet.utils;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
@@ -27,84 +26,49 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PathUtil {
|
||||
|
||||
public static final String JS_LIB_JAR_NAME = "kotlin-jslib.jar";
|
||||
public static final String JS_LIB_JS_NAME = "kotlinLib.js";
|
||||
public static final String JDK_ANNOTATIONS_JAR = "kotlin-jdk-annotations.jar";
|
||||
public static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.jar";
|
||||
public static final String KOTLIN_RUNTIME_JAR = "kotlin-runtime.jar";
|
||||
|
||||
private PathUtil() {}
|
||||
|
||||
public static File getDefaultCompilerPath() {
|
||||
File plugin_jar_path = new File(getJarPathForClass(PathUtil.class));
|
||||
|
||||
if (!plugin_jar_path.exists()) return null;
|
||||
|
||||
if (plugin_jar_path.getName().equals("kotlin-plugin.jar")) {
|
||||
File lib = plugin_jar_path.getParentFile();
|
||||
File pluginHome = lib.getParentFile();
|
||||
|
||||
File answer = new File(pluginHome, "kotlinc");
|
||||
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
|
||||
if (plugin_jar_path.getName().equals("kotlin-compiler.jar")) {
|
||||
File lib = plugin_jar_path.getParentFile();
|
||||
File answer = lib.getParentFile();
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
|
||||
File current = new File("").getAbsoluteFile(); // CWD
|
||||
|
||||
do {
|
||||
File atDevHome = new File(current, "dist/kotlinc");
|
||||
if (atDevHome.exists()) return atDevHome;
|
||||
current = current.getParentFile();
|
||||
} while (current != null);
|
||||
|
||||
return null;
|
||||
@Nullable
|
||||
public static File getRuntimePath(@Nullable final File sdkHome) {
|
||||
return getFilePackedIntoLib(sdkHome, KOTLIN_RUNTIME_JAR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getDefaultRuntimePath() {
|
||||
return getFilePackedIntoLib("kotlin-runtime.jar");
|
||||
public static File getCompilerPath(@Nullable final File sdkHome) {
|
||||
return getFilePackedIntoLib(sdkHome, KOTLIN_COMPILER_JAR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getDefaultJsLibJsPath() {
|
||||
return getFilePackedIntoLib(JS_LIB_JS_NAME);
|
||||
public static File getJsLibJsPath(@Nullable final File sdkHome) {
|
||||
return getFilePackedIntoLib(sdkHome, JS_LIB_JS_NAME);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getDefaultJsLibJarPath() {
|
||||
return getFilePackedIntoLib(JS_LIB_JAR_NAME);
|
||||
public static File getJsLibJarPath(@Nullable final File sdkHome) {
|
||||
return getFilePackedIntoLib(sdkHome, JS_LIB_JAR_NAME);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File getFilePackedIntoLib(@NotNull String filePathFromLib) {
|
||||
File compilerPath = getDefaultCompilerPath();
|
||||
if (compilerPath == null) return null;
|
||||
|
||||
File answer = new File(compilerPath, "lib/" + filePathFromLib);
|
||||
public static File getJdkAnnotationsPath(@Nullable final File sdkHome) {
|
||||
return getFilePackedIntoLib(sdkHome, JDK_ANNOTATIONS_JAR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File getFilePackedIntoLib(@Nullable final File sdkHome, @NotNull final String filePathFromLib) {
|
||||
if (sdkHome == null) return null;
|
||||
final File answer = new File(sdkHome, "lib/" + filePathFromLib);
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJdkAnnotationsPath() {
|
||||
return getFilePackedIntoLib(JDK_ANNOTATIONS_JAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getJarPathForClass(@NotNull Class aClass) {
|
||||
String resourceRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class");
|
||||
return new File(resourceRoot).getAbsoluteFile().getAbsolutePath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static VirtualFile jarFileOrDirectoryToVirtualFile(@NotNull File file) {
|
||||
if (file.exists()) {
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.highlighter.DeclarationHintSupport</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.OutdatedKotlinRuntimeNotification</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<module-components>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.project.K2JSModuleComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.OutdatedKotlinRuntimeNotification</implementation-class>
|
||||
</component>
|
||||
</module-components>
|
||||
|
||||
<actions>
|
||||
|
||||
@@ -14,19 +14,16 @@ package org.jetbrains.jet.plugin;/*
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleComponent;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
@@ -38,6 +35,7 @@ import com.intellij.util.text.VersionComparatorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.quickfix.ConfigureKotlinLibraryNotificationProvider;
|
||||
import org.jetbrains.jet.plugin.util.PluginPathUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
@@ -50,36 +48,40 @@ import java.util.jar.JarFile;
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 5/22/12
|
||||
*/
|
||||
public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent {
|
||||
public class OutdatedKotlinRuntimeNotification implements ModuleComponent {
|
||||
private static final String UNKNOWN_VERSION = "UNKNOWN";
|
||||
private static final String SUPPRESSED_PROPERTY_NAME = "oudtdated.runtime.suppressed.plugin.version";
|
||||
private static final String SUPPRESSED_PROPERTY_NAME_PATTERN = "oudtdated.runtime.suppressed.plugin.version[%s]";
|
||||
|
||||
public OutdatedKotlinRuntimeNotification(final Project project) {
|
||||
super(project);
|
||||
private final Module myModule;
|
||||
private final String mySuppressedPropertyName;
|
||||
|
||||
public OutdatedKotlinRuntimeNotification(final Module module) {
|
||||
myModule = module;
|
||||
mySuppressedPropertyName = String.format(SUPPRESSED_PROPERTY_NAME_PATTERN, module.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
if (ApplicationManager.getApplication().isInternal()) return;
|
||||
String runtimeVersion = getRuntimeVersion();
|
||||
final String pluginVersion = getPluginVersion();
|
||||
String runtimeVersion = getRuntimeVersion(getKotlinRuntimeJar());
|
||||
if (runtimeVersion == null) return; // runtime is not present in project
|
||||
if ("@snapshot@".equals(pluginVersion)) return; // plugin is run from sources, can't compare versions
|
||||
final String sdkVersion = getRuntimeVersion(getRuntimeFromSdk());
|
||||
if (sdkVersion == null || "snapshot".equals(sdkVersion)) return; // plugin is run from sources, can't compare versions
|
||||
|
||||
// user already clicked suppress
|
||||
if (pluginVersion.equals(PropertiesComponent.getInstance(myProject).getValue(SUPPRESSED_PROPERTY_NAME))) return;
|
||||
if (sdkVersion.equals(PropertiesComponent.getInstance(myModule.getProject()).getValue(mySuppressedPropertyName))) return;
|
||||
|
||||
boolean isRuntimeOutdated = "snapshot".equals(runtimeVersion)
|
||||
|| UNKNOWN_VERSION.equals(runtimeVersion)
|
||||
|| runtimeVersion.startsWith("internal-") != pluginVersion.startsWith("internal-")
|
||||
|| VersionComparatorUtil.compare(pluginVersion, runtimeVersion) > 0;
|
||||
|| runtimeVersion.startsWith("internal-") != sdkVersion.startsWith("internal-")
|
||||
|| VersionComparatorUtil.compare(sdkVersion, runtimeVersion) > 0;
|
||||
|
||||
if (!isRuntimeOutdated) return;
|
||||
|
||||
String message = String.format("<p>Your version of Kotlin runtime library is %s, while plugin version is %s." +
|
||||
String message = String.format("<p>Your version of Kotlin runtime library in module \"%s\" is %s, while Kotlin SDK version in this module is %s." +
|
||||
" Runtime library should be updated to avoid compatibility problems.</p>" +
|
||||
"<p><a href=\"update\">Update Runtime</a> <a href=\"ignore\">Ignore</a></p>",
|
||||
UNKNOWN_VERSION.equals(runtimeVersion) ? "older than 0.1.2296" : runtimeVersion, pluginVersion);
|
||||
myModule.getName(), UNKNOWN_VERSION.equals(runtimeVersion) ? "older than 0.1.2296" : runtimeVersion, sdkVersion);
|
||||
Notifications.Bus.notify(new Notification("Outdated Kotlin Runtime", "Outdated Kotlin Runtime",
|
||||
message,
|
||||
NotificationType.WARNING, new NotificationListener() {
|
||||
@@ -90,7 +92,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent
|
||||
updateRuntime();
|
||||
}
|
||||
else if ("ignore".equals(event.getDescription())) {
|
||||
PropertiesComponent.getInstance(myProject).setValue(SUPPRESSED_PROPERTY_NAME, pluginVersion);
|
||||
PropertiesComponent.getInstance(myModule.getProject()).setValue(mySuppressedPropertyName, sdkVersion);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError();
|
||||
@@ -98,16 +100,17 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
}), myProject);
|
||||
}
|
||||
}), myModule.getProject());
|
||||
}
|
||||
|
||||
private void updateRuntime() {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File runtimePath = PathUtil.getDefaultRuntimePath();
|
||||
File runtimePath = PluginPathUtil.getRuntimePath(myModule);
|
||||
if (runtimePath == null) {
|
||||
Messages.showErrorDialog(myProject, "kotlin-runtime.jar is not found. Make sure plugin is properly installed.",
|
||||
Messages.showErrorDialog(myModule.getProject(),
|
||||
"kotlin-runtime.jar is not found. Make sure plugin is properly installed.",
|
||||
"No Runtime Found");
|
||||
return;
|
||||
}
|
||||
@@ -130,8 +133,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getRuntimeVersion() {
|
||||
VirtualFile kotlinRuntimeJar = getKotlinRuntimeJar();
|
||||
private static String getRuntimeVersion(@Nullable final VirtualFile kotlinRuntimeJar) {
|
||||
if (kotlinRuntimeJar == null) return null;
|
||||
VirtualFile manifestFile = kotlinRuntimeJar.findFileByRelativePath(JarFile.MANIFEST_NAME);
|
||||
if (manifestFile != null) {
|
||||
@@ -145,7 +147,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getKotlinRuntimeJar() {
|
||||
LibraryTable table = ProjectLibraryTable.getInstance(myProject);
|
||||
LibraryTable table = ModuleRootManager.getInstance(myModule).getModifiableModel().getModuleLibraryTable();
|
||||
Library kotlinRuntime = table.getLibraryByName(ConfigureKotlinLibraryNotificationProvider.LIBRARY_NAME);
|
||||
if (kotlinRuntime != null) {
|
||||
for (VirtualFile root : kotlinRuntime.getFiles(OrderRootType.CLASSES)) {
|
||||
@@ -157,10 +159,27 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getRuntimeFromSdk() {
|
||||
final File runtimePath = PluginPathUtil.getRuntimePath(myModule);
|
||||
return runtimePath == null ? null : PathUtil.jarFileOrDirectoryToVirtualFile(runtimePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moduleAdded() {}
|
||||
|
||||
@Override
|
||||
public void projectClosed() {}
|
||||
|
||||
@Override
|
||||
public void initComponent() {}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {}
|
||||
|
||||
@NotNull
|
||||
private static String getPluginVersion() {
|
||||
IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("org.jetbrains.kotlin"));
|
||||
assert plugin != null : "How can it be? Kotlin plugin is available, but its component is running. Complete nonsense.";
|
||||
return plugin.getVersion();
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ package org.jetbrains.jet.plugin.compiler;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.jetbrains.jet.plugin.sdk.KotlinSdkUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
|
||||
import static com.intellij.openapi.compiler.CompilerMessageCategory.ERROR;
|
||||
|
||||
@@ -37,7 +36,7 @@ public final class CompilerEnvironment {
|
||||
public static CompilerEnvironment getEnvironmentFor(@NotNull CompileContext compileContext, @NotNull Module module, boolean tests) {
|
||||
VirtualFile mainOutput = compileContext.getModuleOutputDirectory(module);
|
||||
final VirtualFile outputDir = tests ? compileContext.getModuleOutputDirectoryForTests(module) : mainOutput;
|
||||
File kotlinHome = PathUtil.getDefaultCompilerPath();
|
||||
File kotlinHome = KotlinSdkUtil.getSDKHomeFor(module);
|
||||
return new CompilerEnvironment(kotlinHome, outputDir);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -55,7 +55,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
import org.jetbrains.jet.plugin.sdk.KotlinSdkUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.jetbrains.jet.plugin.util.PluginPathUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
@@ -105,7 +105,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
return null;
|
||||
}
|
||||
|
||||
private Library findOrCreateRuntimeLibrary() {
|
||||
private Library findOrCreateRuntimeLibrary(@NotNull Module module) {
|
||||
LibraryTable table = ProjectLibraryTable.getInstance(myProject);
|
||||
Library kotlinRuntime = table.getLibraryByName(LIBRARY_NAME);
|
||||
if (kotlinRuntime != null) {
|
||||
@@ -116,7 +116,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
}
|
||||
}
|
||||
|
||||
File runtimePath = PathUtil.getDefaultRuntimePath();
|
||||
File runtimePath = PluginPathUtil.getRuntimePath(module);
|
||||
if (runtimePath == null) {
|
||||
Messages.showErrorDialog(myProject, "kotlin-runtime.jar is not found. Make sure plugin is properly installed.",
|
||||
"No Runtime Found");
|
||||
@@ -192,7 +192,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Library library = findOrCreateRuntimeLibrary();
|
||||
Library library = findOrCreateRuntimeLibrary(module);
|
||||
if (library != null) {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
if (model.findLibraryOrderEntry(library) == null) {
|
||||
@@ -214,7 +214,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
/* package */ static void addJdkAnnotations(Module module) {
|
||||
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
assert sdk != null;
|
||||
File annotationsIoFile = PathUtil.getJdkAnnotationsPath();
|
||||
File annotationsIoFile = PluginPathUtil.getJdkAnnotationsPath(module);
|
||||
if (annotationsIoFile != null) {
|
||||
VirtualFile jdkAnnotationsJar = LocalFileSystem.getInstance().findFileByIoFile(annotationsIoFile);
|
||||
if (jdkAnnotationsJar != null) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.intellij.psi.impl.PsiModificationTrackerImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.project.K2JSModuleComponent;
|
||||
import org.jetbrains.jet.plugin.util.PluginPathUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
@@ -65,7 +66,7 @@ public final class JsModuleSetUp {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!copyJsLibFiles(rootDir)) return;
|
||||
if (!copyJsLibFiles(module, rootDir)) return;
|
||||
|
||||
setUpK2JSModuleComponent(module);
|
||||
setUpLibraryAsSourceLibrary(module, rootDir);
|
||||
@@ -108,9 +109,9 @@ public final class JsModuleSetUp {
|
||||
DaemonCodeAnalyzer.getInstance(module.getProject()).restart();
|
||||
}
|
||||
|
||||
private static boolean copyJsLibFiles(@NotNull File rootDir) {
|
||||
File jsLibJarPath = PathUtil.getDefaultJsLibJarPath();
|
||||
File jsLibJsPath = PathUtil.getDefaultJsLibJsPath();
|
||||
private static boolean copyJsLibFiles(@NotNull Module module, @NotNull File rootDir) {
|
||||
File jsLibJarPath = PluginPathUtil.getJsLibJarPath(module);
|
||||
File jsLibJsPath = PluginPathUtil.getJsLibJsPath(module);
|
||||
if ((jsLibJarPath == null) || (jsLibJsPath == null)) {
|
||||
notifyFailure("JavaScript library not found. Make sure plugin is installed properly.");
|
||||
return false;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.search.FilenameIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -46,7 +47,6 @@ public class KotlinSdkUtil {
|
||||
return new KotlinSdkProperties("");
|
||||
}
|
||||
};
|
||||
@NotNull private static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.jar";
|
||||
@NotNull private static final String[] KOTLIN_COMPILER_JAR_ENTRY_NAMES = {
|
||||
"org/jetbrains/jet/cli/KotlinCompiler.class",
|
||||
"org/jetbrains/jet/cli/jvm/K2JVMCompiler.class"
|
||||
@@ -59,7 +59,7 @@ public class KotlinSdkUtil {
|
||||
}
|
||||
|
||||
private static boolean isSDKHome(@NotNull final File dir) {
|
||||
return dir.isDirectory() && isKotlinCompilerJar(getKotlinCompilerJar(dir));
|
||||
return dir.isDirectory() && isKotlinCompilerJar(PathUtil.getCompilerPath(dir));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -77,7 +77,8 @@ public class KotlinSdkUtil {
|
||||
}
|
||||
catch (final IOException e) {
|
||||
try {
|
||||
return getJarImplementationVersion(getKotlinCompilerJar(new File(sdkHomePath)));
|
||||
final File compilerJar = PathUtil.getCompilerPath(new File(sdkHomePath));
|
||||
return compilerJar == null ? null : getJarImplementationVersion(compilerJar);
|
||||
}
|
||||
catch (final IOException e1) {
|
||||
return null;
|
||||
@@ -97,15 +98,10 @@ public class KotlinSdkUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File getKotlinCompilerJar(@NotNull final File sdkHome) {
|
||||
return new File(new File(sdkHome, "lib"), KOTLIN_COMPILER_JAR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String detectSDKVersion(@NotNull final List<VirtualFile> jars) {
|
||||
for (final VirtualFile jar : jars) {
|
||||
if (jar.getName().equals(KOTLIN_COMPILER_JAR) && isKotlinCompilerJar(new File(jar.getPath()))) {
|
||||
if (jar.getName().equals(PathUtil.KOTLIN_COMPILER_JAR) && isKotlinCompilerJar(new File(jar.getPath()))) {
|
||||
final VirtualFile libDir = jar.getParent();
|
||||
if (libDir != null) {
|
||||
final VirtualFile sdkHomeDir = libDir.getParent();
|
||||
@@ -119,22 +115,29 @@ public class KotlinSdkUtil {
|
||||
}
|
||||
|
||||
public static boolean isSDKConfiguredFor(@NotNull final Module module) {
|
||||
final GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
|
||||
return containsKotlinCompilerJar(FilenameIndex.getVirtualFilesByName(module.getProject(), KOTLIN_COMPILER_JAR, scope));
|
||||
return getSDKHomeFor(module) != null;
|
||||
}
|
||||
|
||||
private static boolean containsKotlinCompilerJar(@NotNull final Collection<VirtualFile> jars) {
|
||||
@Nullable
|
||||
public static File getSDKHomeFor(@NotNull final Module module) {
|
||||
final GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
|
||||
return findKotlinCompilerJar(FilenameIndex.getVirtualFilesByName(module.getProject(), PathUtil.KOTLIN_COMPILER_JAR, scope));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File findKotlinCompilerJar(@NotNull final Collection<VirtualFile> jars) {
|
||||
for (final VirtualFile jar : jars) {
|
||||
if (isKotlinCompilerJar(new File(jar.getPath()))) {
|
||||
return true;
|
||||
final File file = new File(jar.getPath());
|
||||
if (isKotlinCompilerJar(file)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isKotlinCompilerJar(@NotNull final File jar) {
|
||||
private static boolean isKotlinCompilerJar(@Nullable final File jar) {
|
||||
try {
|
||||
return doIsKotlinCompilerJar(jar);
|
||||
return jar != null && doIsKotlinCompilerJar(jar);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.util;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.sdk.KotlinSdkUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Maxim.Manuylov
|
||||
* Date: 20.05.12
|
||||
*/
|
||||
public class PluginPathUtil {
|
||||
private PluginPathUtil() {}
|
||||
|
||||
@Nullable
|
||||
public static File getRuntimePath(@NotNull final Module module) {
|
||||
return PathUtil.getRuntimePath(KotlinSdkUtil.getSDKHomeFor(module));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJsLibJsPath(@NotNull final Module module) {
|
||||
return PathUtil.getJsLibJsPath(KotlinSdkUtil.getSDKHomeFor(module));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJsLibJarPath(@NotNull final Module module) {
|
||||
return PathUtil.getJsLibJarPath(KotlinSdkUtil.getSDKHomeFor(module));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getJdkAnnotationsPath(@NotNull final Module module) {
|
||||
return PathUtil.getJdkAnnotationsPath(KotlinSdkUtil.getSDKHomeFor(module));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user