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
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user