From b2b5ccefbde117302851f7b11f901dc2ff4ca78e Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 12 Nov 2012 19:57:39 +0400 Subject: [PATCH] Switching from log/learn to reportOutput/add --- .../jet/codegen/ClassFileFactory.java | 1 - .../jet/codegen/NamespaceCodegen.java | 8 -- .../jetbrains/jet/codegen/state/Progress.java | 7 -- .../compiler/KotlinToJVMBytecodeCompiler.java | 5 -- .../runner/AbstractOutputItemCollector.java | 73 ------------------- .../compiler/runner/CompilerRunnerUtil.java | 1 + .../compiler/runner/OutputItemsCollector.java | 2 - .../runner/OutputItemsCollectorImpl.java | 45 ++++++++++++ .../jet/compiler/runner/SimpleOutputItem.java | 43 +++++++++++ .../jet/plugin/compiler/CompilerUtils.java | 45 ++++++------ .../jet/plugin/compiler/JetCompiler.java | 23 ++++-- .../jet/plugin/compiler/K2JSCompiler.java | 5 +- 12 files changed, 128 insertions(+), 130 deletions(-) delete mode 100644 ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java create mode 100644 ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollectorImpl.java create mode 100644 ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/SimpleOutputItem.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java index b1959c93389..41c071e3b96 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java @@ -61,7 +61,6 @@ public final class ClassFileFactory extends GenerationStateAware { private ClassBuilder newVisitor(String outputFilePath, Collection sourceFiles) { state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath)); - state.getProgress().log("Emitting: " + outputFilePath); final ClassBuilder answer = builderFactory.newClassBuilder(); generators.put(outputFilePath, answer); return answer; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index 5cab1995178..d42525520b3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -92,14 +92,6 @@ public class NamespaceCodegen extends MemberCodegen { VirtualFile vFile = file.getVirtualFile(); try { final String path = vFile != null ? vFile.getPath() : "no_virtual_file/" + file.getName(); - if (progress != null) { - v.addOptionalDeclaration(new ClassBuilderOnDemand.ClassBuilderCallback() { - @Override - public void doSomething(@NotNull ClassBuilder classBuilder) { - progress.log("For source: " + path); - } - }); - } generate(file, multiFile); } catch (ProcessCanceledException e) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/Progress.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/Progress.java index c8ac84b1d50..38090e79e07 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/Progress.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/Progress.java @@ -27,18 +27,11 @@ import java.util.Collection; public interface Progress { Progress DEAF = new Progress() { - @Override - public void log(String message) { - } - @Override public void reportOutput(@NotNull Collection sourceFiles, @Nullable File outputFile) { } }; - @Deprecated - void log(String message); - /** * @param sourceFiles a (possibly empty) collection of source files {@code outputFile} was generated from * @param outputFile an output file diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 72486928577..cd8a96f1b59 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -335,11 +335,6 @@ public class KotlinToJVMBytecodeCompiler { Project project = environment.getProject(); final CompilerConfiguration configuration = environment.getConfiguration(); Progress backendProgress = new Progress() { - @Override - public void log(String message) { - configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION); - } - @Override public void reportOutput(@NotNull Collection sourceFiles, @Nullable File outputFile) { if (outputFile == null) return; diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java deleted file mode 100644 index eb9112329f1..00000000000 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/AbstractOutputItemCollector.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.jet.compiler.runner; - -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public abstract class AbstractOutputItemCollector implements OutputItemsCollector { - private static final String FOR_SOURCE_PREFIX = "For source: "; - private static final String EMITTING_PREFIX = "Emitting: "; - private S currentSource; - private final List answer = ContainerUtil.newArrayList(); - private final List sources = ContainerUtil.newArrayList(); - - private final String outputPath; - - public AbstractOutputItemCollector(@NotNull String outputPath) { - this.outputPath = outputPath; - } - - protected void addItem(R item) { - answer.add(item); - } - - @Override - public final void learn(String message) { - message = message.trim(); - if (message.startsWith(FOR_SOURCE_PREFIX)) { - String sourcePath = message.substring(FOR_SOURCE_PREFIX.length()); - currentSource = convertSource(sourcePath); - if (currentSource != null) { - sources.add(currentSource); - } - } - else if (message.startsWith(EMITTING_PREFIX)) { - if (currentSource != null) { - String resultPath = message.substring(EMITTING_PREFIX.length()); - R item = convertResult(outputPath + "/" + resultPath, currentSource); - if (item != null) { - answer.add(item); - } - } - } - } - - protected abstract R convertResult(String resultPath, S correspondingSource); - - protected abstract S convertSource(String sourcePath); - - public List getOutputs() { - return answer; - } - - public List getSources() { - return sources; - } -} diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java index 7ab53d833a8..bf6d0c43061 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java @@ -180,6 +180,7 @@ public class CompilerRunnerUtil { .put("error", ERROR) .put("warning", WARNING) .put("logging", LOGGING) + .put("output", OUTPUT) .put("exception", ERROR) .put("info", INFO) .put("messages", INFO) // Root XML element diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollector.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollector.java index 325e1fb3dc9..372e3c0fbfa 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollector.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollector.java @@ -23,7 +23,5 @@ import java.util.Collection; * @author abreslav */ public interface OutputItemsCollector { - @Deprecated - void learn(String message); void add(Collection sourceFiles, File outputFile); } diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollectorImpl.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollectorImpl.java new file mode 100644 index 00000000000..572b5b46cbb --- /dev/null +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/OutputItemsCollectorImpl.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.jetbrains.jet.compiler.runner; + +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.util.Collection; +import java.util.List; + +public class OutputItemsCollectorImpl implements OutputItemsCollector { + private final List outputs = ContainerUtil.newArrayList(); + @Nullable + private final File outputDir; + + public OutputItemsCollectorImpl(@Nullable File outputDir) { + this.outputDir = outputDir; + } + + @Override + public void add(Collection sourceFiles, File outputFile) { + outputs.add(new SimpleOutputItem(sourceFiles, new File(outputDir, outputFile.getPath()))); + } + + @NotNull + public List getOutputs() { + return outputs; + } +} diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/SimpleOutputItem.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/SimpleOutputItem.java new file mode 100644 index 00000000000..ba29a610d1c --- /dev/null +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/SimpleOutputItem.java @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package org.jetbrains.jet.compiler.runner; + +import java.io.File; +import java.util.Collection; + +public class SimpleOutputItem { + private final Collection sourceFiles; + private final File outputFile; + + public SimpleOutputItem(Collection sourceFiles, File outputFile) { + this.sourceFiles = sourceFiles; + this.outputFile = outputFile; + } + + public Collection getSourceFiles() { + return sourceFiles; + } + + public File getOutputFile() { + return outputFile; + } + + @Override + public String toString() { + return sourceFiles + " -> " + outputFile; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java index 1bc24ee7731..23dff238cbd 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java @@ -16,6 +16,8 @@ package org.jetbrains.jet.plugin.compiler; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.intellij.compiler.impl.javaCompiler.OutputItemImpl; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.compiler.TranslatingCompiler; @@ -24,11 +26,13 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.compiler.runner.AbstractOutputItemCollector; import org.jetbrains.jet.compiler.runner.CompilerEnvironment; +import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl; +import org.jetbrains.jet.compiler.runner.SimpleOutputItem; import java.io.File; -import java.util.Collection; +import java.util.List; +import java.util.Set; /** * @author Pavel Talanov @@ -50,31 +54,24 @@ public final class CompilerUtils { return new File(file.getPath()); } - public static class OutputItemsCollectorImpl extends AbstractOutputItemCollector { + public static void reportOutputs( + TranslatingCompiler.OutputSink outputSink, + File outputDir, + OutputItemsCollectorImpl outputItemsCollector + ) { + Set sources = Sets.newHashSet(); + List outputs = Lists.newArrayList(); - public OutputItemsCollectorImpl(@NotNull String outputPath) { - super(outputPath); - } - - @Override - protected TranslatingCompiler.OutputItem convertResult(String resultPath, VirtualFile correspondingSource) { - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(resultPath)); - return new OutputItemImpl(resultPath, correspondingSource); - } - - @Override - protected VirtualFile convertSource(String sourcePath) { - return LocalFileSystem.getInstance().findFileByPath(sourcePath); - } - - @Override - public void add(Collection sourceFiles, File outputFile) { - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(outputFile); - for (File sourceFile : sourceFiles) { + for (SimpleOutputItem output : outputItemsCollector.getOutputs()) { + LocalFileSystem.getInstance().refreshAndFindFileByIoFile(output.getOutputFile()); + for (File sourceFile : output.getSourceFiles()) { VirtualFile virtualFileForSourceFile = LocalFileSystem.getInstance().findFileByIoFile(sourceFile); - addItem(new OutputItemImpl(outputFile.getPath(), virtualFileForSourceFile)); + + sources.add(virtualFileForSourceFile); + outputs.add(new OutputItemImpl(output.getOutputFile().getPath(), virtualFileForSourceFile)); } } + + outputSink.add(outputDir.getPath(), outputs, sources.toArray(VirtualFile.EMPTY_ARRAY)); } } - diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java index a3211ebf952..ffb83bad9c1 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java @@ -32,9 +32,7 @@ import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.messages.MessageCollector; -import org.jetbrains.jet.compiler.runner.CompilerEnvironment; -import org.jetbrains.jet.compiler.runner.KotlinCompilerRunner; -import org.jetbrains.jet.compiler.runner.KotlinModuleScriptGenerator; +import org.jetbrains.jet.compiler.runner.*; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.project.JsModuleDetector; @@ -114,24 +112,33 @@ public class JetCompiler implements TranslatingCompiler { return; } + final File outputDir = environment.getOutput(); + File scriptFile = tryToWriteScriptFile(compileContext, moduleChunk, files, module, tests, compileContext.getModuleOutputDirectory(module), - environment.getOutput()); + outputDir); if (scriptFile == null) return; - CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath()); + OutputItemsCollectorImpl collector = new OutputItemsCollectorImpl(outputDir) { + @Override + public void add(Collection sourceFiles, File outputFile) { + super.add(sourceFiles, outputFile); + compileContext.getProgressIndicator().setText("Emitting: " + outputFile); + } + }; runCompiler(messageCollector, environment, scriptFile, collector); - outputSink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY)); + + CompilerUtils.reportOutputs(outputSink, outputDir, collector); } private static void runCompiler( MessageCollector messageCollector, CompilerEnvironment environment, File scriptFile, - CompilerUtils.OutputItemsCollectorImpl collector + OutputItemsCollector outputItemsCollector ) { - KotlinCompilerRunner.runCompiler(messageCollector, environment, scriptFile, collector, RUN_OUT_OF_PROCESS); + KotlinCompilerRunner.runCompiler(messageCollector, environment, scriptFile, outputItemsCollector, RUN_OUT_OF_PROCESS); } public static File tryToWriteScriptFile( diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java index 7358269dec6..7016a3d5e9b 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java @@ -40,6 +40,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.compiler.runner.CompilerEnvironment; import org.jetbrains.jet.compiler.runner.CompilerRunnerUtil; +import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.project.JsModuleDetector; @@ -92,14 +93,14 @@ public final class K2JSCompiler implements TranslatingCompiler { private static void doCompile(@NotNull final MessageCollector messageCollector, @NotNull OutputSink sink, @NotNull final Module module, @NotNull final CompilerEnvironment environment) { - CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath()); + OutputItemsCollectorImpl collector = new OutputItemsCollectorImpl(environment.getOutput()); outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function() { @Override public Integer fun(PrintStream stream) { return execInProcess(messageCollector, environment, stream, module); } }); - sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY)); + CompilerUtils.reportOutputs(sink, environment.getOutput(), collector); } @Nullable