Switching from log/learn to reportOutput/add
This commit is contained in:
@@ -61,7 +61,6 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
|
|
||||||
private ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) {
|
private ClassBuilder newVisitor(String outputFilePath, Collection<? extends PsiFile> sourceFiles) {
|
||||||
state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath));
|
state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath));
|
||||||
state.getProgress().log("Emitting: " + outputFilePath);
|
|
||||||
final ClassBuilder answer = builderFactory.newClassBuilder();
|
final ClassBuilder answer = builderFactory.newClassBuilder();
|
||||||
generators.put(outputFilePath, answer);
|
generators.put(outputFilePath, answer);
|
||||||
return answer;
|
return answer;
|
||||||
|
|||||||
@@ -92,14 +92,6 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
VirtualFile vFile = file.getVirtualFile();
|
VirtualFile vFile = file.getVirtualFile();
|
||||||
try {
|
try {
|
||||||
final String path = vFile != null ? vFile.getPath() : "no_virtual_file/" + file.getName();
|
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);
|
generate(file, multiFile);
|
||||||
}
|
}
|
||||||
catch (ProcessCanceledException e) {
|
catch (ProcessCanceledException e) {
|
||||||
|
|||||||
@@ -27,18 +27,11 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public interface Progress {
|
public interface Progress {
|
||||||
Progress DEAF = new Progress() {
|
Progress DEAF = new Progress() {
|
||||||
@Override
|
|
||||||
public void log(String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
void log(String message);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sourceFiles a (possibly empty) collection of source files {@code outputFile} was generated from
|
* @param sourceFiles a (possibly empty) collection of source files {@code outputFile} was generated from
|
||||||
* @param outputFile an output file
|
* @param outputFile an output file
|
||||||
|
|||||||
@@ -335,11 +335,6 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
Project project = environment.getProject();
|
Project project = environment.getProject();
|
||||||
final CompilerConfiguration configuration = environment.getConfiguration();
|
final CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
Progress backendProgress = new Progress() {
|
Progress backendProgress = new Progress() {
|
||||||
@Override
|
|
||||||
public void log(String message) {
|
|
||||||
configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
||||||
if (outputFile == null) return;
|
if (outputFile == null) return;
|
||||||
|
|||||||
-73
@@ -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<S, R> implements OutputItemsCollector {
|
|
||||||
private static final String FOR_SOURCE_PREFIX = "For source: ";
|
|
||||||
private static final String EMITTING_PREFIX = "Emitting: ";
|
|
||||||
private S currentSource;
|
|
||||||
private final List<R> answer = ContainerUtil.newArrayList();
|
|
||||||
private final List<S> 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<R> getOutputs() {
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<S> getSources() {
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -180,6 +180,7 @@ public class CompilerRunnerUtil {
|
|||||||
.put("error", ERROR)
|
.put("error", ERROR)
|
||||||
.put("warning", WARNING)
|
.put("warning", WARNING)
|
||||||
.put("logging", LOGGING)
|
.put("logging", LOGGING)
|
||||||
|
.put("output", OUTPUT)
|
||||||
.put("exception", ERROR)
|
.put("exception", ERROR)
|
||||||
.put("info", INFO)
|
.put("info", INFO)
|
||||||
.put("messages", INFO) // Root XML element
|
.put("messages", INFO) // Root XML element
|
||||||
|
|||||||
@@ -23,7 +23,5 @@ import java.util.Collection;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public interface OutputItemsCollector {
|
public interface OutputItemsCollector {
|
||||||
@Deprecated
|
|
||||||
void learn(String message);
|
|
||||||
void add(Collection<File> sourceFiles, File outputFile);
|
void add(Collection<File> sourceFiles, File outputFile);
|
||||||
}
|
}
|
||||||
|
|||||||
+45
@@ -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<SimpleOutputItem> outputs = ContainerUtil.newArrayList();
|
||||||
|
@Nullable
|
||||||
|
private final File outputDir;
|
||||||
|
|
||||||
|
public OutputItemsCollectorImpl(@Nullable File outputDir) {
|
||||||
|
this.outputDir = outputDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Collection<File> sourceFiles, File outputFile) {
|
||||||
|
outputs.add(new SimpleOutputItem(sourceFiles, new File(outputDir, outputFile.getPath())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<SimpleOutputItem> getOutputs() {
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<File> sourceFiles;
|
||||||
|
private final File outputFile;
|
||||||
|
|
||||||
|
public SimpleOutputItem(Collection<File> sourceFiles, File outputFile) {
|
||||||
|
this.sourceFiles = sourceFiles;
|
||||||
|
this.outputFile = outputFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<File> getSourceFiles() {
|
||||||
|
return sourceFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getOutputFile() {
|
||||||
|
return outputFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return sourceFiles + " -> " + outputFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.compiler;
|
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.compiler.impl.javaCompiler.OutputItemImpl;
|
||||||
import com.intellij.openapi.compiler.CompileContext;
|
import com.intellij.openapi.compiler.CompileContext;
|
||||||
import com.intellij.openapi.compiler.TranslatingCompiler;
|
import com.intellij.openapi.compiler.TranslatingCompiler;
|
||||||
@@ -24,11 +26,13 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
|||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.CompilerEnvironment;
|
||||||
|
import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl;
|
||||||
|
import org.jetbrains.jet.compiler.runner.SimpleOutputItem;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
@@ -50,31 +54,24 @@ public final class CompilerUtils {
|
|||||||
return new File(file.getPath());
|
return new File(file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OutputItemsCollectorImpl extends AbstractOutputItemCollector<VirtualFile, TranslatingCompiler.OutputItem> {
|
public static void reportOutputs(
|
||||||
|
TranslatingCompiler.OutputSink outputSink,
|
||||||
|
File outputDir,
|
||||||
|
OutputItemsCollectorImpl outputItemsCollector
|
||||||
|
) {
|
||||||
|
Set<VirtualFile> sources = Sets.newHashSet();
|
||||||
|
List<TranslatingCompiler.OutputItem> outputs = Lists.newArrayList();
|
||||||
|
|
||||||
public OutputItemsCollectorImpl(@NotNull String outputPath) {
|
for (SimpleOutputItem output : outputItemsCollector.getOutputs()) {
|
||||||
super(outputPath);
|
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(output.getOutputFile());
|
||||||
}
|
for (File sourceFile : output.getSourceFiles()) {
|
||||||
|
|
||||||
@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<File> sourceFiles, File outputFile) {
|
|
||||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(outputFile);
|
|
||||||
for (File sourceFile : sourceFiles) {
|
|
||||||
VirtualFile virtualFileForSourceFile = LocalFileSystem.getInstance().findFileByIoFile(sourceFile);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ import com.intellij.util.Function;
|
|||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.compiler.runner.CompilerEnvironment;
|
import org.jetbrains.jet.compiler.runner.*;
|
||||||
import org.jetbrains.jet.compiler.runner.KotlinCompilerRunner;
|
|
||||||
import org.jetbrains.jet.compiler.runner.KotlinModuleScriptGenerator;
|
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||||
|
|
||||||
@@ -114,24 +112,33 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final File outputDir = environment.getOutput();
|
||||||
|
|
||||||
File scriptFile = tryToWriteScriptFile(compileContext, moduleChunk, files, module, tests,
|
File scriptFile = tryToWriteScriptFile(compileContext, moduleChunk, files, module, tests,
|
||||||
compileContext.getModuleOutputDirectory(module),
|
compileContext.getModuleOutputDirectory(module),
|
||||||
environment.getOutput());
|
outputDir);
|
||||||
|
|
||||||
if (scriptFile == null) return;
|
if (scriptFile == null) return;
|
||||||
|
|
||||||
CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath());
|
OutputItemsCollectorImpl collector = new OutputItemsCollectorImpl(outputDir) {
|
||||||
|
@Override
|
||||||
|
public void add(Collection<File> sourceFiles, File outputFile) {
|
||||||
|
super.add(sourceFiles, outputFile);
|
||||||
|
compileContext.getProgressIndicator().setText("Emitting: " + outputFile);
|
||||||
|
}
|
||||||
|
};
|
||||||
runCompiler(messageCollector, environment, scriptFile, collector);
|
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(
|
private static void runCompiler(
|
||||||
MessageCollector messageCollector,
|
MessageCollector messageCollector,
|
||||||
CompilerEnvironment environment,
|
CompilerEnvironment environment,
|
||||||
File scriptFile,
|
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(
|
public static File tryToWriteScriptFile(
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
|||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.compiler.runner.CompilerEnvironment;
|
import org.jetbrains.jet.compiler.runner.CompilerEnvironment;
|
||||||
import org.jetbrains.jet.compiler.runner.CompilerRunnerUtil;
|
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.JetFileType;
|
||||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
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,
|
private static void doCompile(@NotNull final MessageCollector messageCollector, @NotNull OutputSink sink, @NotNull final Module module,
|
||||||
@NotNull final CompilerEnvironment environment) {
|
@NotNull final CompilerEnvironment environment) {
|
||||||
CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath());
|
OutputItemsCollectorImpl collector = new OutputItemsCollectorImpl(environment.getOutput());
|
||||||
outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
|
outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function<PrintStream, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer fun(PrintStream stream) {
|
public Integer fun(PrintStream stream) {
|
||||||
return execInProcess(messageCollector, environment, stream, module);
|
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
|
@Nullable
|
||||||
|
|||||||
Reference in New Issue
Block a user