Passing custom class loader for loading incremental cache implementation.

This commit is contained in:
Evgeny Gerashchenko
2014-06-09 20:50:51 +04:00
parent 04f7ad450f
commit d3e5790674
8 changed files with 141 additions and 18 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="module" module-name="cli-common" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="preloader" />
<orderEntry type="module" module-name="preloader" exported="" />
</component>
</module>
@@ -19,6 +19,7 @@ package org.jetbrains.jet.compiler.runner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.preloading.ClassLoaderFactory;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.PathUtil;
@@ -29,17 +30,25 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.ERRO
public final class CompilerEnvironment {
public static CompilerEnvironment getEnvironmentFor(@NotNull KotlinPaths kotlinPaths, @Nullable File outputDir) {
return new CompilerEnvironment(kotlinPaths, outputDir);
public static CompilerEnvironment getEnvironmentFor(
@NotNull KotlinPaths kotlinPaths,
@Nullable File outputDir,
@Nullable ClassLoaderFactory parentFactory
) {
return new CompilerEnvironment(kotlinPaths, outputDir, parentFactory);
}
@NotNull
private final KotlinPaths kotlinPaths;
@Nullable
private final File output;
@Nullable
private final ClassLoaderFactory parentFactory;
private CompilerEnvironment(@NotNull KotlinPaths kotlinPaths, @Nullable File output) {
private CompilerEnvironment(@NotNull KotlinPaths kotlinPaths, @Nullable File output, @Nullable ClassLoaderFactory parentFactory) {
this.kotlinPaths = kotlinPaths;
this.output = output;
this.parentFactory = parentFactory;
}
public boolean success() {
@@ -57,6 +66,11 @@ public final class CompilerEnvironment {
return output;
}
@Nullable
public ClassLoaderFactory getParentFactory() {
return parentFactory;
}
public void reportErrorsTo(@NotNull MessageCollector messageCollector) {
if (output == null) {
messageCollector.report(ERROR, "[Internal Error] No output directory", NO_LOCATION);
@@ -66,5 +80,4 @@ public final class CompilerEnvironment {
"or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property", NO_LOCATION);
}
}
}
@@ -17,8 +17,11 @@
package org.jetbrains.jet.compiler.runner;
import com.intellij.util.Function;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.preloading.ClassLoaderFactory;
import org.jetbrains.jet.preloading.ClassPreloadingUtils;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -54,12 +57,17 @@ public class CompilerRunnerUtil {
return answer;
}
public static ClassLoader getOrCreatePreloader(KotlinPaths paths, MessageCollector messageCollector) {
@NotNull
public static ClassLoader getOrCreatePreloader(
@NotNull KotlinPaths paths,
@Nullable ClassLoaderFactory parentFactory,
@NotNull MessageCollector messageCollector
) {
ClassLoader answer = ourClassLoaderRef.get();
if (answer == null) {
try {
int estimatedClassNumber = 4096;
answer = ClassPreloadingUtils.preloadClasses(kompilerClasspath(paths, messageCollector), estimatedClassNumber, null);
answer = ClassPreloadingUtils.preloadClasses(kompilerClasspath(paths, messageCollector), estimatedClassNumber, parentFactory);
}
catch (IOException e) {
throw new RuntimeException(e);
@@ -112,7 +120,7 @@ public class CompilerRunnerUtil {
MessageCollector messageCollector, PrintStream out, boolean usePreloader
) throws Exception {
ClassLoader loader = usePreloader
? getOrCreatePreloader(environment.getKotlinPaths(), messageCollector)
? getOrCreatePreloader(environment.getKotlinPaths(), environment.getParentFactory(), messageCollector)
: getOrCreateClassLoader(environment.getKotlinPaths(), messageCollector);
Class<?> kompiler = Class.forName(compilerClassName, true, loader);