refactor PathUtil - it is a big difference now, whether we find sdk home from plugin or from compiler

This commit is contained in:
Maxim Manuylov
2012-07-22 17:57:39 +04:00
committed by Evgeny Gerashchenko
parent e5589e1037
commit 843fb8d7a9
13 changed files with 239 additions and 125 deletions
@@ -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()) {