Progress messages when emitting classfiles
This commit is contained in:
@@ -56,6 +56,9 @@ public class CompilerArguments {
|
||||
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
|
||||
public boolean tags;
|
||||
|
||||
@Argument(value = "verbose", description = "Enable verbose logging output")
|
||||
public boolean verbose;
|
||||
|
||||
|
||||
public String getClasspath() {
|
||||
return classpath;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class KotlinCompiler {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
|
||||
MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
||||
CompileEnvironment environment = new CompileEnvironment(messageRenderer);
|
||||
CompileEnvironment environment = new CompileEnvironment(messageRenderer, arguments.verbose);
|
||||
try {
|
||||
configureEnvironment(environment, arguments, errStream);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.jet.lang.resolve.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
import org.jetbrains.jet.plugin.compiler.PathUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -63,12 +63,14 @@ public class CompileEnvironment {
|
||||
|
||||
private boolean ignoreErrors = false;
|
||||
private boolean stubs = false;
|
||||
private final boolean verbose;
|
||||
|
||||
public CompileEnvironment() {
|
||||
this(MessageRenderer.PLAIN);
|
||||
this(MessageRenderer.PLAIN, false);
|
||||
}
|
||||
|
||||
public CompileEnvironment(MessageRenderer messageRenderer) {
|
||||
public CompileEnvironment(MessageRenderer messageRenderer, boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
myRootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
@@ -179,7 +181,7 @@ public class CompileEnvironment {
|
||||
|
||||
final String directory = new File(moduleScriptFile).getParent();
|
||||
for (Module moduleBuilder : modules) {
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment(myMessageRenderer);
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment(myMessageRenderer, verbose);
|
||||
compileEnvironment.setIgnoreErrors(ignoreErrors);
|
||||
compileEnvironment.setErrorStream(myErrorStream);
|
||||
// copy across any compiler plugins
|
||||
@@ -204,11 +206,11 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public List<Module> loadModuleScript(String moduleFile) {
|
||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||
CompileSession scriptCompileSession = newCompileSession();
|
||||
scriptCompileSession.addSources(moduleFile);
|
||||
ensureRuntime();
|
||||
|
||||
if (!scriptCompileSession.analyze(myErrorStream, myMessageRenderer)) {
|
||||
if (!scriptCompileSession.analyze()) {
|
||||
return null;
|
||||
}
|
||||
final ClassFileFactory factory = scriptCompileSession.generate(true);
|
||||
@@ -242,7 +244,7 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public ClassFileFactory compileModule(Module moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||
CompileSession moduleCompileSession = newCompileSession();
|
||||
moduleCompileSession.setStubs(stubs);
|
||||
|
||||
if (moduleBuilder.getSourceFiles().isEmpty()) {
|
||||
@@ -267,7 +269,7 @@ public class CompileEnvironment {
|
||||
|
||||
ensureRuntime();
|
||||
|
||||
if (!moduleCompileSession.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) {
|
||||
if (!moduleCompileSession.analyze() && !ignoreErrors) {
|
||||
return null;
|
||||
}
|
||||
return moduleCompileSession.generate(false);
|
||||
@@ -351,10 +353,10 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public ClassLoader compileText(String code) {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
CompileSession session = newCompileSession();
|
||||
session.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
|
||||
|
||||
if (!session.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) {
|
||||
if (!session.analyze() && !ignoreErrors) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -363,7 +365,7 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
CompileSession session = newCompileSession();
|
||||
session.setStubs(stubs);
|
||||
|
||||
session.addSources(sourceFileOrDir);
|
||||
@@ -379,7 +381,7 @@ public class CompileEnvironment {
|
||||
|
||||
ensureRuntime();
|
||||
|
||||
if (!session.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) {
|
||||
if (!session.analyze() && !ignoreErrors) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -400,6 +402,10 @@ public class CompileEnvironment {
|
||||
return true;
|
||||
}
|
||||
|
||||
private CompileSession newCompileSession() {
|
||||
return new CompileSession(myEnvironment, myMessageRenderer, myErrorStream, verbose);
|
||||
}
|
||||
|
||||
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.utils.Progress;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
@@ -55,9 +56,13 @@ import java.util.List;
|
||||
*/
|
||||
public class CompileSession {
|
||||
private final JetCoreEnvironment myEnvironment;
|
||||
private final MessageCollector myMessageCollector;
|
||||
private final List<JetFile> mySourceFiles = new ArrayList<JetFile>();
|
||||
private List<String> myErrors = new ArrayList<String>();
|
||||
private boolean stubs = false;
|
||||
private final MessageRenderer myMessageRenderer;
|
||||
private final PrintStream myErrorStream;
|
||||
private final boolean myIsVerbose;
|
||||
|
||||
public BindingContext getMyBindingContext() {
|
||||
return myBindingContext;
|
||||
@@ -65,8 +70,12 @@ public class CompileSession {
|
||||
|
||||
private BindingContext myBindingContext;
|
||||
|
||||
public CompileSession(JetCoreEnvironment environment) {
|
||||
public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose) {
|
||||
myEnvironment = environment;
|
||||
myMessageRenderer = messageRenderer;
|
||||
myErrorStream = errorStream;
|
||||
myIsVerbose = verbose;
|
||||
myMessageCollector = new MessageCollector(myMessageRenderer);
|
||||
}
|
||||
|
||||
public void setStubs(boolean stubs) {
|
||||
@@ -130,19 +139,17 @@ public class CompileSession {
|
||||
return mySourceFiles;
|
||||
}
|
||||
|
||||
public boolean analyze(@NotNull PrintStream out, @NotNull MessageRenderer renderer) {
|
||||
MessageCollector collector = new MessageCollector(renderer);
|
||||
|
||||
public boolean analyze() {
|
||||
for (String error : myErrors) {
|
||||
collector.report(Severity.ERROR, error, null, -1, -1);
|
||||
myMessageCollector.report(Severity.ERROR, error, null, -1, -1);
|
||||
}
|
||||
|
||||
reportSyntaxErrors(collector);
|
||||
analyzeAndReportSemanticErrors(collector);
|
||||
reportSyntaxErrors();
|
||||
analyzeAndReportSemanticErrors();
|
||||
|
||||
collector.printTo(out);
|
||||
myMessageCollector.printTo(myErrorStream);
|
||||
|
||||
return !collector.hasErrors();
|
||||
return !myMessageCollector.hasErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,17 +165,17 @@ public class CompileSession {
|
||||
}
|
||||
}
|
||||
|
||||
private void analyzeAndReportSemanticErrors(MessageCollector collector) {
|
||||
private void analyzeAndReportSemanticErrors() {
|
||||
Predicate<PsiFile> filesToAnalyzeCompletely =
|
||||
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
||||
myBindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
myEnvironment.getProject(), mySourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY);
|
||||
|
||||
for (Diagnostic diagnostic : myBindingContext.getDiagnostics()) {
|
||||
reportDiagnostic(collector, diagnostic);
|
||||
reportDiagnostic(myMessageCollector, diagnostic);
|
||||
}
|
||||
|
||||
reportIncompleteHierarchies(collector);
|
||||
reportIncompleteHierarchies(myMessageCollector);
|
||||
}
|
||||
|
||||
private void reportIncompleteHierarchies(MessageCollector collector) {
|
||||
@@ -182,7 +189,7 @@ public class CompileSession {
|
||||
}
|
||||
}
|
||||
|
||||
private void reportSyntaxErrors(final MessageCollector messageCollector) {
|
||||
private void reportSyntaxErrors() {
|
||||
for (JetFile file : mySourceFiles) {
|
||||
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
@@ -190,7 +197,7 @@ public class CompileSession {
|
||||
String description = element.getErrorDescription();
|
||||
String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
|
||||
Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element);
|
||||
reportDiagnostic(messageCollector, diagnostic);
|
||||
reportDiagnostic(myMessageCollector, diagnostic);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -206,7 +213,7 @@ public class CompileSession {
|
||||
@NotNull
|
||||
public ClassFileFactory generate(boolean module) {
|
||||
Project project = myEnvironment.getProject();
|
||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs));
|
||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), myIsVerbose ? new BackendProgress() : Progress.DEAF);
|
||||
generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true);
|
||||
ClassFileFactory answer = generationState.getFactory();
|
||||
|
||||
@@ -220,4 +227,11 @@ public class CompileSession {
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
private class BackendProgress implements Progress {
|
||||
@Override
|
||||
public void log(String message) {
|
||||
myErrorStream.println(myMessageRenderer.render(Severity.LOGGING, message, null, -1, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.compiler.PathUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
Reference in New Issue
Block a user