Progress messages when emitting classfiles

This commit is contained in:
Maxim Shafirov
2012-03-14 21:55:27 +04:00
parent fecc98af8c
commit e82dd48662
18 changed files with 131 additions and 62 deletions
@@ -38,6 +38,7 @@ public class ClassFileFactory {
} }
ClassBuilder newVisitor(String filePath) { ClassBuilder newVisitor(String filePath) {
state.getProgress().log("Emitting: " + filePath);
final ClassBuilder answer = builderFactory.newClassBuilder(); final ClassBuilder answer = builderFactory.newClassBuilder();
generators.put(filePath, answer); generators.put(filePath, answer);
return answer; return answer;
@@ -31,8 +31,8 @@ import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@@ -128,7 +128,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
funClass, funClass,
new String[0] new String[0]
); );
cv.visitSource(state.transformFileName(fun.getContainingFile().getName()), null); cv.visitSource(fun.getContainingFile().getName(), null);
generateBridge(name, funDescriptor, fun, cv); generateBridge(name, funDescriptor, fun, cv);
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.utils.Progress;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -51,9 +52,15 @@ public class GenerationState {
private final Stack<BindingContext> bindingContexts = new Stack<BindingContext>(); private final Stack<BindingContext> bindingContexts = new Stack<BindingContext>();
private final JetStandardLibrary standardLibrary; private final JetStandardLibrary standardLibrary;
private final IntrinsicMethods intrinsics; private final IntrinsicMethods intrinsics;
private final Progress progress;
public GenerationState(Project project, ClassBuilderFactory builderFactory) { public GenerationState(Project project, ClassBuilderFactory builderFactory) {
this(project, builderFactory, Progress.DEAF);
}
public GenerationState(Project project, ClassBuilderFactory builderFactory, Progress progress) {
this.project = project; this.project = project;
this.progress = progress;
this.standardLibrary = JetStandardLibrary.getInstance(); this.standardLibrary = JetStandardLibrary.getInstance();
this.factory = new ClassFileFactory(builderFactory, this); this.factory = new ClassFileFactory(builderFactory, this);
this.intrinsics = new IntrinsicMethods(project, standardLibrary); this.intrinsics = new IntrinsicMethods(project, standardLibrary);
@@ -64,6 +71,10 @@ public class GenerationState {
return factory; return factory;
} }
public Progress getProgress() {
return progress;
}
public Project getProject() { public Project getProject() {
return project; return project;
} }
@@ -133,14 +144,15 @@ public class GenerationState {
typeMapper = new JetTypeMapper(standardLibrary, bindingContext, closureAnnotator); typeMapper = new JetTypeMapper(standardLibrary, bindingContext, closureAnnotator);
bindingContexts.push(bindingContext); bindingContexts.push(bindingContext);
try { try {
for (JetFile namespace : files) { for (JetFile file : files) {
if (namespace == null) throw new IllegalArgumentException("A null file given for compilation"); if (file == null) throw new IllegalArgumentException("A null file given for compilation");
VirtualFile vFile = file.getVirtualFile();
progress.log("For source: " + vFile.getPath());
try { try {
generateNamespace(namespace); generateNamespace(file);
} }
catch (Throwable e) { catch (Throwable e) {
VirtualFile virtualFile = namespace.getContainingFile().getVirtualFile(); errorHandler.reportException(e, vFile == null ? "no file" : vFile.getUrl());
errorHandler.reportException(e, virtualFile == null ? "no file" : virtualFile.getUrl());
DiagnosticUtils.throwIfRunningOnServer(e); DiagnosticUtils.throwIfRunningOnServer(e);
if (ApplicationManager.getApplication().isInternal()) { if (ApplicationManager.getApplication().isInternal()) {
e.printStackTrace(); e.printStackTrace();
@@ -188,9 +200,4 @@ public class GenerationState {
return answer.toString(); return answer.toString();
} }
@NotNull
public String transformFileName(@NotNull String fileName) {
return fileName;
}
} }
@@ -21,12 +21,7 @@ import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.signature.BothSignatureWriter; import org.jetbrains.jet.codegen.signature.*;
import org.jetbrains.jet.codegen.signature.JvmClassSignature;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
import org.jetbrains.jet.codegen.signature.kotlin.JetValueParameterAnnotationWriter; import org.jetbrains.jet.codegen.signature.kotlin.JetValueParameterAnnotationWriter;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -115,7 +110,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
signature.getSuperclassName(), signature.getSuperclassName(),
signature.getInterfaces().toArray(new String[0]) signature.getInterfaces().toArray(new String[0])
); );
v.visitSource(state.transformFileName(myClass.getContainingFile().getName()), null); v.visitSource(myClass.getContainingFile().getName(), null);
ClassDescriptor container = getContainingClassDescriptor(descriptor); ClassDescriptor container = getContainingClassDescriptor(descriptor);
if(container != null) { if(container != null) {
@@ -51,7 +51,7 @@ public class NamespaceCodegen {
new String[0] new String[0]
); );
// TODO figure something out for a namespace that spans multiple files // TODO figure something out for a namespace that spans multiple files
v.visitSource(state.transformFileName(sourceFile.getName()), null); v.visitSource(sourceFile.getName(), null);
} }
public void generate(JetFile file) { public void generate(JetFile file) {
@@ -21,8 +21,8 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import java.util.List; import java.util.List;
@@ -70,7 +70,7 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
"java/lang/Object", "java/lang/Object",
new String[0] new String[0]
); );
v.visitSource(state.transformFileName(myClass.getContainingFile().getName()), null); v.visitSource(myClass.getContainingFile().getName(), null);
} }
private String jvmName() { private String jvmName() {
@@ -56,6 +56,9 @@ public class CompilerArguments {
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag") @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags; public boolean tags;
@Argument(value = "verbose", description = "Enable verbose logging output")
public boolean verbose;
public String getClasspath() { public String getClasspath() {
return classpath; return classpath;
@@ -73,7 +73,7 @@ public class KotlinCompiler {
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");
MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN; MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
CompileEnvironment environment = new CompileEnvironment(messageRenderer); CompileEnvironment environment = new CompileEnvironment(messageRenderer, arguments.verbose);
try { try {
configureEnvironment(environment, arguments, errStream); 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.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.plugin.JetLanguage; import org.jetbrains.jet.plugin.JetLanguage;
import org.jetbrains.jet.plugin.JetMainDetector; import org.jetbrains.jet.plugin.JetMainDetector;
import org.jetbrains.jet.plugin.compiler.PathUtil; import org.jetbrains.jet.utils.PathUtil;
import java.io.*; import java.io.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -63,12 +63,14 @@ public class CompileEnvironment {
private boolean ignoreErrors = false; private boolean ignoreErrors = false;
private boolean stubs = false; private boolean stubs = false;
private final boolean verbose;
public CompileEnvironment() { 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() { myRootDisposable = new Disposable() {
@Override @Override
public void dispose() { public void dispose() {
@@ -179,7 +181,7 @@ public class CompileEnvironment {
final String directory = new File(moduleScriptFile).getParent(); final String directory = new File(moduleScriptFile).getParent();
for (Module moduleBuilder : modules) { for (Module moduleBuilder : modules) {
CompileEnvironment compileEnvironment = new CompileEnvironment(myMessageRenderer); CompileEnvironment compileEnvironment = new CompileEnvironment(myMessageRenderer, verbose);
compileEnvironment.setIgnoreErrors(ignoreErrors); compileEnvironment.setIgnoreErrors(ignoreErrors);
compileEnvironment.setErrorStream(myErrorStream); compileEnvironment.setErrorStream(myErrorStream);
// copy across any compiler plugins // copy across any compiler plugins
@@ -204,11 +206,11 @@ public class CompileEnvironment {
} }
public List<Module> loadModuleScript(String moduleFile) { public List<Module> loadModuleScript(String moduleFile) {
CompileSession scriptCompileSession = new CompileSession(myEnvironment); CompileSession scriptCompileSession = newCompileSession();
scriptCompileSession.addSources(moduleFile); scriptCompileSession.addSources(moduleFile);
ensureRuntime(); ensureRuntime();
if (!scriptCompileSession.analyze(myErrorStream, myMessageRenderer)) { if (!scriptCompileSession.analyze()) {
return null; return null;
} }
final ClassFileFactory factory = scriptCompileSession.generate(true); final ClassFileFactory factory = scriptCompileSession.generate(true);
@@ -242,7 +244,7 @@ public class CompileEnvironment {
} }
public ClassFileFactory compileModule(Module moduleBuilder, String directory) { public ClassFileFactory compileModule(Module moduleBuilder, String directory) {
CompileSession moduleCompileSession = new CompileSession(myEnvironment); CompileSession moduleCompileSession = newCompileSession();
moduleCompileSession.setStubs(stubs); moduleCompileSession.setStubs(stubs);
if (moduleBuilder.getSourceFiles().isEmpty()) { if (moduleBuilder.getSourceFiles().isEmpty()) {
@@ -267,7 +269,7 @@ public class CompileEnvironment {
ensureRuntime(); ensureRuntime();
if (!moduleCompileSession.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) { if (!moduleCompileSession.analyze() && !ignoreErrors) {
return null; return null;
} }
return moduleCompileSession.generate(false); return moduleCompileSession.generate(false);
@@ -351,10 +353,10 @@ public class CompileEnvironment {
} }
public ClassLoader compileText(String code) { public ClassLoader compileText(String code) {
CompileSession session = new CompileSession(myEnvironment); CompileSession session = newCompileSession();
session.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code)); session.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
if (!session.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) { if (!session.analyze() && !ignoreErrors) {
return null; return null;
} }
@@ -363,7 +365,7 @@ public class CompileEnvironment {
} }
public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) { public boolean compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
CompileSession session = new CompileSession(myEnvironment); CompileSession session = newCompileSession();
session.setStubs(stubs); session.setStubs(stubs);
session.addSources(sourceFileOrDir); session.addSources(sourceFileOrDir);
@@ -379,7 +381,7 @@ public class CompileEnvironment {
ensureRuntime(); ensureRuntime();
if (!session.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) { if (!session.analyze() && !ignoreErrors) {
return false; return false;
} }
@@ -400,6 +402,10 @@ public class CompileEnvironment {
return true; return true;
} }
private CompileSession newCompileSession() {
return new CompileSession(myEnvironment, myMessageRenderer, myErrorStream, verbose);
}
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) { public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
List<String> files = factory.files(); List<String> files = factory.files();
for (String file : 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.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.utils.Progress;
import java.io.File; import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
@@ -55,9 +56,13 @@ import java.util.List;
*/ */
public class CompileSession { public class CompileSession {
private final JetCoreEnvironment myEnvironment; private final JetCoreEnvironment myEnvironment;
private final MessageCollector myMessageCollector;
private final List<JetFile> mySourceFiles = new ArrayList<JetFile>(); private final List<JetFile> mySourceFiles = new ArrayList<JetFile>();
private List<String> myErrors = new ArrayList<String>(); private List<String> myErrors = new ArrayList<String>();
private boolean stubs = false; private boolean stubs = false;
private final MessageRenderer myMessageRenderer;
private final PrintStream myErrorStream;
private final boolean myIsVerbose;
public BindingContext getMyBindingContext() { public BindingContext getMyBindingContext() {
return myBindingContext; return myBindingContext;
@@ -65,8 +70,12 @@ public class CompileSession {
private BindingContext myBindingContext; private BindingContext myBindingContext;
public CompileSession(JetCoreEnvironment environment) { public CompileSession(JetCoreEnvironment environment, MessageRenderer messageRenderer, PrintStream errorStream, boolean verbose) {
myEnvironment = environment; myEnvironment = environment;
myMessageRenderer = messageRenderer;
myErrorStream = errorStream;
myIsVerbose = verbose;
myMessageCollector = new MessageCollector(myMessageRenderer);
} }
public void setStubs(boolean stubs) { public void setStubs(boolean stubs) {
@@ -130,19 +139,17 @@ public class CompileSession {
return mySourceFiles; return mySourceFiles;
} }
public boolean analyze(@NotNull PrintStream out, @NotNull MessageRenderer renderer) { public boolean analyze() {
MessageCollector collector = new MessageCollector(renderer);
for (String error : myErrors) { for (String error : myErrors) {
collector.report(Severity.ERROR, error, null, -1, -1); myMessageCollector.report(Severity.ERROR, error, null, -1, -1);
} }
reportSyntaxErrors(collector); reportSyntaxErrors();
analyzeAndReportSemanticErrors(collector); 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 = Predicate<PsiFile> filesToAnalyzeCompletely =
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue(); stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
myBindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( myBindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
myEnvironment.getProject(), mySourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY); myEnvironment.getProject(), mySourceFiles, filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY);
for (Diagnostic diagnostic : myBindingContext.getDiagnostics()) { for (Diagnostic diagnostic : myBindingContext.getDiagnostics()) {
reportDiagnostic(collector, diagnostic); reportDiagnostic(myMessageCollector, diagnostic);
} }
reportIncompleteHierarchies(collector); reportIncompleteHierarchies(myMessageCollector);
} }
private void reportIncompleteHierarchies(MessageCollector collector) { 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) { for (JetFile file : mySourceFiles) {
file.accept(new PsiRecursiveElementWalkingVisitor() { file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override @Override
@@ -190,7 +197,7 @@ public class CompileSession {
String description = element.getErrorDescription(); String description = element.getErrorDescription();
String message = StringUtil.isEmpty(description) ? "Syntax error" : description; String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element); Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element);
reportDiagnostic(messageCollector, diagnostic); reportDiagnostic(myMessageCollector, diagnostic);
} }
}); });
} }
@@ -206,7 +213,7 @@ public class CompileSession {
@NotNull @NotNull
public ClassFileFactory generate(boolean module) { public ClassFileFactory generate(boolean module) {
Project project = myEnvironment.getProject(); 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); generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true);
ClassFileFactory answer = generationState.getFactory(); ClassFileFactory answer = generationState.getFactory();
@@ -220,4 +227,11 @@ public class CompileSession {
} }
return answer; 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.parsing.JetParserDefinition;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.plugin.JetFileType; 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.io.File;
import java.net.URL; import java.net.URL;
@@ -26,7 +26,7 @@ import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiManager; import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.FqName; import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.plugin.compiler.PathUtil; import org.jetbrains.jet.utils.PathUtil;
import java.util.List; import java.util.List;
@@ -20,6 +20,7 @@ package org.jetbrains.jet.lang.diagnostics;
* @author abreslav * @author abreslav
*/ */
public enum Severity { public enum Severity {
LOGGING,
INFO, INFO,
ERROR, ERROR,
WARNING WARNING
@@ -69,7 +69,7 @@ public class TestlibTest extends CodegenTestCase {
private TestSuite doBuildSuite() { private TestSuite doBuildSuite() {
try { try {
CompileSession session = new CompileSession(myEnvironment); CompileSession session = new CompileSession(myEnvironment, MessageRenderer.PLAIN, System.err, false);
myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests()); myEnvironment.addToClasspath(ForTestCompileStdlib.stdlibJarForTests());
@@ -85,7 +85,7 @@ public class TestlibTest extends CodegenTestCase {
session.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test")); session.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test"));
session.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src")); session.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
if (!session.analyze(System.err, MessageRenderer.PLAIN)) { if (!session.analyze()) {
throw new RuntimeException("There were compilation errors"); throw new RuntimeException("There were compilation errors");
} }
@@ -17,7 +17,7 @@
/* /*
* @author max * @author max
*/ */
package org.jetbrains.jet.plugin.compiler; package org.jetbrains.jet.utils;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package org.jetbrains.jet.utils;
public interface Progress {
Progress DEAF = new Progress() {
@Override
public void log(String message) {
}
};
void log(String message);
}
@@ -42,6 +42,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Severity; import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.utils.PathUtil;
import java.io.*; import java.io.*;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
@@ -262,7 +263,7 @@ public class JetCompiler implements TranslatingCompiler {
Class<?> kompiler = Class.forName(compilerClassName, true, loader); Class<?> kompiler = Class.forName(compilerClassName, true, loader);
Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class); Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class);
String[] arguments = { "-module", scriptFile.getAbsolutePath(), "-output", path(outputDir), "-tags" }; String[] arguments = { "-module", scriptFile.getAbsolutePath(), "-output", path(outputDir), "-tags", "-verbose" };
context.addMessage(INFORMATION, "Using kotlinHome=" + kotlinHome, "", -1, -1); context.addMessage(INFORMATION, "Using kotlinHome=" + kotlinHome, "", -1, -1);
context.addMessage(INFORMATION, "Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments), "", -1, -1); context.addMessage(INFORMATION, "Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments), "", -1, -1);
@@ -312,6 +313,7 @@ public class JetCompiler implements TranslatingCompiler {
params.getProgramParametersList().add("-module", scriptFile.getAbsolutePath()); params.getProgramParametersList().add("-module", scriptFile.getAbsolutePath());
params.getProgramParametersList().add("-output", path(outputDir)); params.getProgramParametersList().add("-output", path(outputDir));
params.getProgramParametersList().add("-tags"); params.getProgramParametersList().add("-tags");
params.getProgramParametersList().add("-verbose");
for (File jar : kompilerClasspath(kotlinHome, compileContext)) { for (File jar : kompilerClasspath(kotlinHome, compileContext)) {
params.getClassPath().add(jar); params.getClassPath().add(jar);
@@ -383,10 +385,10 @@ public class JetCompiler implements TranslatingCompiler {
} }
private static class CompilerProcessListener extends ProcessAdapter { private static class CompilerProcessListener extends ProcessAdapter {
private static final Pattern DIAGNOSTIC_PATTERN = Pattern.compile("<(ERROR|WARNING|INFO|EXCEPTION)", Pattern.MULTILINE); private static final Pattern DIAGNOSTIC_PATTERN = Pattern.compile("<(ERROR|WARNING|INFO|EXCEPTION|LOGGING)", Pattern.MULTILINE);
private static final Pattern OPEN_TAG_END_PATTERN = Pattern.compile(">", Pattern.MULTILINE | Pattern.DOTALL); private static final Pattern OPEN_TAG_END_PATTERN = Pattern.compile(">", Pattern.MULTILINE | Pattern.DOTALL);
private static final Pattern ATTRIBUTE_PATTERN = Pattern.compile("\\s*(path|line|column)\\s*=\\s*\"(.*?)\"", Pattern.MULTILINE | Pattern.DOTALL); private static final Pattern ATTRIBUTE_PATTERN = Pattern.compile("\\s*(path|line|column)\\s*=\\s*\"(.*?)\"", Pattern.MULTILINE | Pattern.DOTALL);
private static final Pattern MESSAGE_PATTERN = Pattern.compile("(.*?)</(ERROR|WARNING|INFO|EXCEPTION)>", Pattern.MULTILINE | Pattern.DOTALL); private static final Pattern MESSAGE_PATTERN = Pattern.compile("(.*?)</(ERROR|WARNING|INFO|EXCEPTION|LOGGING)>", Pattern.MULTILINE | Pattern.DOTALL);
private enum State { private enum State {
WAITING, ATTRIBUTES, MESSAGE WAITING, ATTRIBUTES, MESSAGE
@@ -409,6 +411,9 @@ public class JetCompiler implements TranslatingCompiler {
else if (Severity.WARNING.toString().equals(tagName)) { else if (Severity.WARNING.toString().equals(tagName)) {
messageCategory = WARNING; messageCategory = WARNING;
} }
else if (Severity.LOGGING.toString().equals(tagName)) {
messageCategory = STATISTICS;
}
else { else {
messageCategory = INFORMATION; messageCategory = INFORMATION;
} }
@@ -441,9 +446,17 @@ public class JetCompiler implements TranslatingCompiler {
} }
public void reportTo(CompileContext compileContext) { public void reportTo(CompileContext compileContext) {
compileContext.addMessage(messageCategory, message, url == null ? "" : url, line == null ? -1 : line, column == null ? -1 : column); if (messageCategory == STATISTICS) {
if (isException) { compileContext.getProgressIndicator().setText(message);
LOG.error(message); }
else {
compileContext.addMessage(messageCategory, message, url == null ? "" : url, line == null ? -1 : line,
column == null
? -1
: column);
if (isException) {
LOG.error(message);
}
} }
} }
} }
@@ -50,7 +50,7 @@ import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotifications; import com.intellij.ui.EditorNotifications;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.plugin.compiler.PathUtil; import org.jetbrains.jet.utils.PathUtil;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;