loading optimized file manager dynamically from the pre-compiled jar

This commit is contained in:
Eugene Zhuravlev
2011-10-19 13:06:01 +02:00
parent fe2cd90669
commit 7f1d792711
7 changed files with 90 additions and 12 deletions

View File

@@ -153,6 +153,7 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
module("jps-builders")
module("jps-model")
}
fileset(dir: "$home/jps/lib", includes: "optimizedFileManager.jar")
fileset(dir: "$home/lib", includesfile: "${home}/lib/required_for_dist.txt")

View File

@@ -18,6 +18,15 @@
<orderEntry type="library" name="jgoodies-forms" level="project" />
<orderEntry type="library" name="Netty" level="project" />
<orderEntry type="library" exported="" name="protobuf" level="project" />
<orderEntry type="module-library" scope="RUNTIME">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/optimizedFileManager.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@@ -1,8 +1,10 @@
package org.jetbrains.jps.incremental.java;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.messages.CompilerMessage;
import org.jetbrains.jps.server.ClasspathBootstrap;
import javax.tools.*;
import java.io.File;
@@ -66,6 +68,7 @@ public class EmbeddedJavac {
}
}
//noinspection IOResourceOpenedButNotSafelyClosed
final LineOutputWriter out = new LineOutputWriter() {
protected void lineAvailable(String line) {
outConsumer.outputLineAvailable(line);
@@ -121,11 +124,16 @@ public class EmbeddedJavac {
}
};
StandardJavaFileManager stdManager = null;
try {
stdManager = (StandardJavaFileManager)Class.forName("org.jetbrains.jps.incremental.java.OptimizedFileManager").newInstance();
}
catch (Throwable e) {
compileContext.processMessage(new CompilerMessage("Javac", BuildMessage.Kind.INFO, "Failed to load JPS optimized file manager for javac: " + e.getMessage()));
final Class<StandardJavaFileManager> optimizedManagerClass = ClasspathBootstrap.getOptimizedFileManagerClass();
if (optimizedManagerClass != null) {
try {
stdManager = optimizedManagerClass.newInstance();
}
catch (Throwable e) {
if (SystemInfo.isWindows) {
compileContext.processMessage(new CompilerMessage("Javac", BuildMessage.Kind.INFO, "Failed to load JPS optimized file manager for javac: " + e.getMessage()));
}
}
}
if (stdManager != null) {
myStdManager = stdManager;

View File

@@ -54,6 +54,8 @@ public class JavaBuilder extends Builder{
}
};
//private static final Key<Callbacks.Backend> DELTA_MAPPINGS_CALLBACK_KEY = Key.create("_dependency_data_");
private final EmbeddedJavac myJavacCompiler;
public JavaBuilder(ExecutorService tasksExecutor) {
@@ -61,6 +63,21 @@ public class JavaBuilder extends Builder{
//add here class processors in the sequence they should be executed
//myJavacCompiler.addClassProcessor(new EmbeddedJavac.ClassPostProcessor() {
// public void process(CompileContext context, OutputFileObject out) {
// final Callbacks.Backend callback = DELTA_MAPPINGS_CALLBACK_KEY.get(context);
// if (callback != null) {
// final String className = out.getClassName();
// final OutputFileObject.Content content = out.getContent();
// final File srcFile = out.getSourceFile();
// if (srcFile != null && content != null) {
// // todo: the callback is not thread-safe?
// final ClassReader reader = new ClassReader(content.getBuffer(), content.getOffset(), content.getLength());
// //noinspection SynchronizationOnLocalVariableOrMethodParameter
// synchronized (callback) {
// // todo: parse class data out of synchronized block (move it from the 'associate' implementation)
// callback.associate(className, Callbacks.getDefaultLookup(srcFile.getPath()), reader);
// }
// }
// }
// }
//});
}
@@ -164,6 +181,10 @@ public class JavaBuilder extends Builder{
ProjectPaths.KEY.set(context, paths = new ProjectPaths(context.getProject()));
}
//final Mappings delta = new Mappings(null); // todo
//final Callbacks.Backend callback = delta.getCallback();
//DELTA_MAPPINGS_CALLBACK_KEY.set(context, callback);
// todo: consider corresponding setting in CompilerWorkspaceConfiguration
final boolean addNotNullAssertions = true;
@@ -212,9 +233,14 @@ public class JavaBuilder extends Builder{
return ExitCode.OK;
}
finally {
//DELTA_MAPPINGS_CALLBACK_KEY.set(context, callback);
outputSink.writePendingData();
for (File file : outputSink.getSuccessfullyCompiled()) {
final Set<File> successfullyCompiled = outputSink.getSuccessfullyCompiled();
//delta.compensateRemovedContent(successfullyCompiled);
//globalMappings.integrate(mappings, ); //todo
for (File file : successfullyCompiled) {
tsStorage.saveStamp(file);
}
for (File file : successfulForms) {

View File

@@ -24,9 +24,11 @@ import com.jgoodies.forms.layout.CellConstraints;
import gnu.trove.TIntHash;
import net.n3.nanoxml.IXMLBuilder;
import org.codehaus.groovy.GroovyException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.MacroExpander;
import org.objectweb.asm.ClassWriter;
import javax.tools.*;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -38,10 +40,28 @@ import java.util.Set;
* Date: 9/12/11
*/
public class ClasspathBootstrap {
private ClasspathBootstrap() {
public static final String JPS_RUNTIME_PATH = "rt/jps-incremental";
private static class OptimizedFileManagerClassHolder {
static final String CLASS_NAME = "org.jetbrains.jps.incremental.java.OptimizedFileManager";
static final Class<StandardJavaFileManager> managerClass;
static {
Class<StandardJavaFileManager> aClass = null;
try {
aClass = (Class<StandardJavaFileManager>)Class.forName(CLASS_NAME);
}
catch (Throwable e) {
aClass = null;
}
managerClass = aClass;
}
private OptimizedFileManagerClassHolder() {
}
}
public static final String JPS_RUNTIME_PATH = "rt/jps-incremental";
private ClasspathBootstrap() {
}
public static List<File> getApplicationClasspath() {
final Set<File> cp = new LinkedHashSet<File>();
@@ -61,6 +81,13 @@ public class ClasspathBootstrap {
cp.add(getResourcePath(NotNullVerifyingInstrumenter.class)); // not-null
cp.add(getResourcePath(IXMLBuilder.class)); // nano-xml
final Class<StandardJavaFileManager> optimizedFileManagerClass = getOptimizedFileManagerClass();
if (optimizedFileManagerClass != null) {
cp.add(getResourcePath(optimizedFileManagerClass)); // optimizedFileManager
}
//cp.add(getResourcePath(Mappings.class)); // todo: temporary
//final File jpsRuntime = new File(jpsFacadeJar.getParentFile(), JPS_RUNTIME_PATH);
//final File[] files = jpsRuntime.listFiles();
//if (files != null) {
@@ -85,6 +112,11 @@ public class ClasspathBootstrap {
return new ArrayList<File>(cp);
}
@Nullable
public static Class<StandardJavaFileManager> getOptimizedFileManagerClass() {
return OptimizedFileManagerClassHolder.managerClass;
}
public static File getResourcePath(Class aClass) {
return new File(PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class"));
}

Binary file not shown.

View File

@@ -1,6 +1,6 @@
package org.jetbrains.ether.dependencyView;
import org.codehaus.groovy.transform.DelegateASTTransformation;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.Pair;
import org.jetbrains.ether.ProjectWrapper;
import org.objectweb.asm.ClassReader;
@@ -895,14 +895,15 @@ public class Mappings {
}
public void associate(final String classFileName, final Callbacks.SourceFileNameLookup sourceFileName, final ClassReader cr) {
final StringCache.S classFileNameS = StringCache.get(project.getRelativePath(classFileName));
final StringCache.S classFileNameS = StringCache.get(project != null? project.getRelativePath(classFileName) : classFileName);
final Pair<ClassRepr, Pair<UsageRepr.Cluster, Set<UsageRepr.Usage>>> result = ClassfileAnalyzer.analyze(classFileNameS, cr);
final ClassRepr repr = result.fst;
final UsageRepr.Cluster localUsages = result.snd.fst;
final Set<UsageRepr.Usage> localAnnotationUsages = result.snd.snd;
final String srcFileName = sourceFileName.get(repr == null ? null : repr.getSourceFileName().value);
final StringCache.S sourceFileNameS =
StringCache.get(project.getRelativePath(sourceFileName.get(repr == null ? null : repr.getSourceFileName().value)));
StringCache.get(project != null? project.getRelativePath(srcFileName) : srcFileName);
for (UsageRepr.Usage u : localUsages.getUsages()) {
updateDependency(sourceFileNameS, u.getOwner());
@@ -957,9 +958,10 @@ public class Mappings {
};
}
@Nullable
private final ProjectWrapper project;
public Mappings(final ProjectWrapper p) {
public Mappings(@Nullable final ProjectWrapper p) {
project = p;
}