Skip to content

Commit

Permalink
Search rt.jar even if compiler was run with jre
Browse files Browse the repository at this point in the history
 #KT-2599 Fixed
  • Loading branch information
goodwinnk committed Feb 15, 2013
1 parent 33fa065 commit 1aee735
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
12 changes: 10 additions & 2 deletions compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java
Expand Up @@ -67,8 +67,16 @@ protected ExitCode doExecute(K2JVMCompilerArguments arguments, MessageCollector
"Using Kotlin home directory " + paths.getHomePath(), CompilerMessageLocation.NO_LOCATION);

CompilerConfiguration configuration = new CompilerConfiguration();
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments));
configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments));

try {
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments));
configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments));
}
catch (Throwable t) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t),
CompilerMessageLocation.NO_LOCATION);
return INTERNAL_ERROR;
}

final List<String> argumentsSourceDirs = arguments.getSourceDirs();
if (!arguments.script &&
Expand Down
34 changes: 15 additions & 19 deletions compiler/util/src/org/jetbrains/jet/utils/PathUtil.java
Expand Up @@ -17,6 +17,7 @@
package org.jetbrains.jet.utils;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
Expand Down Expand Up @@ -138,30 +139,25 @@ public static VirtualFile jarFileOrDirectoryToVirtualFile(@NotNull File file) {

@NotNull
public static File findRtJar() {
String javaHome = System.getProperty("java.home");
if ("jre".equals(new File(javaHome).getName())) {
javaHome = new File(javaHome).getParent();
}

File rtJar = findRtJar(javaHome);

if (rtJar == null || !rtJar.exists()) {
throw new IllegalArgumentException("No JDK rt.jar found under " + javaHome);
}

return rtJar;
return findRtJar(System.getProperty("java.home"));
}

private static File findRtJar(String javaHome) {
File rtJar = new File(javaHome, "jre/lib/rt.jar");
if (rtJar.exists()) {
return rtJar;
if (SystemInfo.isMac) {
File classesJar = new File(new File(javaHome).getParentFile(), "Classes/classes.jar");
if (classesJar.exists()) {
return classesJar;
}

throw new IllegalArgumentException("No classes.jar found under " + classesJar.getParent());
}
else {
File rtJar = new File(javaHome, "lib/rt.jar");
if (rtJar.exists()) {
return rtJar;
}

File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
if (classesJar.exists()) {
return classesJar;
throw new IllegalArgumentException("No rt.jar found under " + rtJar.getParent());
}
return null;
}
}

3 comments on commit 1aee735

@develar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not working for Mac OS X with JDK 1.7 (Oracle) ;)

@develar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goodwinnk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Your commit was cherry-picked.

Please sign in to comment.