Made compiler aware of multiple alt-header paths.

This commit is contained in:
Evgeny Gerashchenko
2012-05-15 00:16:44 +04:00
parent 554280a1b3
commit 4ab2588cbd
7 changed files with 62 additions and 25 deletions
@@ -16,7 +16,11 @@
package org.jetbrains.jet.lang.resolve.java;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.utils.PathUtil;
@@ -34,15 +38,15 @@ public class CompilerDependencies {
private final CompilerSpecialMode compilerSpecialMode;
@Nullable
private final File jdkJar;
@Nullable
private final File jdkHeadersJar;
@NotNull
private final File[] altHeadersClasspath;
@Nullable
private final File runtimeJar;
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @NotNull File[] altHeadersClasspath, @Nullable File runtimeJar) {
this.compilerSpecialMode = compilerSpecialMode;
this.jdkJar = jdkJar;
this.jdkHeadersJar = jdkHeadersJar;
this.altHeadersClasspath = altHeadersClasspath;
this.runtimeJar = runtimeJar;
if (compilerSpecialMode.includeJdk()) {
@@ -51,8 +55,8 @@ public class CompilerDependencies {
}
}
if (compilerSpecialMode.includeJdkHeaders()) {
if (jdkHeadersJar == null) {
throw new IllegalArgumentException("jdkHeaders must be included for mode " + compilerSpecialMode);
if (altHeadersClasspath.length == 0) {
throw new IllegalArgumentException("altHeaders must be included for mode " + compilerSpecialMode);
}
}
if (compilerSpecialMode.includeKotlinRuntime()) {
@@ -72,9 +76,9 @@ public class CompilerDependencies {
return jdkJar;
}
@Nullable
public File getJdkHeadersJar() {
return jdkHeadersJar;
@NotNull
public File[] getAltHeadersClassPath() {
return altHeadersClasspath;
}
@Nullable
@@ -83,9 +87,24 @@ public class CompilerDependencies {
}
@NotNull
public List<VirtualFile> getJdkHeaderRoots() {
public List<VirtualFile> getAltHeaderRoots() {
if (compilerSpecialMode.includeJdkHeaders()) {
return Collections.singletonList(PathUtil.jarFileToVirtualFile(jdkHeadersJar));
return ContainerUtil.map2List(altHeadersClasspath, new Function<File, VirtualFile>() {
@Override
public VirtualFile fun(File file) {
if (file.exists()) {
if (file.isDirectory()) {
return VirtualFileManager.getInstance().findFileByUrl("file://" + FileUtil.toSystemIndependentName(file.getAbsolutePath()));
}
else {
return PathUtil.jarFileToVirtualFile(file);
}
}
else {
throw new IllegalStateException("Path " + file + " does not exist.");
}
}
});
}
else {
return Collections.emptyList();
@@ -107,7 +126,7 @@ public class CompilerDependencies {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? findRtJar() : null,
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
compilerSpecialMode.includeJdkHeaders() ? new File[]{PathUtil.getAltHeadersPath()} : new File[0],
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
}
@@ -59,7 +59,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
@PostConstruct
public void initialize() {
this.altClassFinder = new AltClassFinder(project, compilerDependencies.getJdkHeaderRoots());
this.altClassFinder = new AltClassFinder(project, compilerDependencies.getAltHeaderRoots());
this.javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
@Override
public boolean contains(VirtualFile file) {