Alternative methods for progress reporting
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Type;
|
||||
@@ -27,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||
@@ -56,7 +59,8 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
return newVisitor(outputFilePath, Collections.singletonList(sourceFile));
|
||||
}
|
||||
|
||||
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().log("Emitting: " + outputFilePath);
|
||||
final ClassBuilder answer = builderFactory.newClassBuilder();
|
||||
generators.put(outputFilePath, answer);
|
||||
@@ -139,4 +143,18 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName() + ".class",
|
||||
sourceFile);
|
||||
}
|
||||
|
||||
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
||||
List<File> result = Lists.newArrayList();
|
||||
for (PsiFile psiFile : psiFiles) {
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
// We ignore non-physical files here, because this code is needed to tell the make what inputs affect which outputs
|
||||
// a non-physical file cannot be processed by make
|
||||
if (virtualFile != null) {
|
||||
result.add(new File(virtualFile.getPath()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,11 +19,29 @@
|
||||
*/
|
||||
package org.jetbrains.jet.codegen.state;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Progress {
|
||||
Progress DEAF = new Progress() {
|
||||
@Override
|
||||
public void log(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
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 outputFile an output file
|
||||
*/
|
||||
void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile);
|
||||
}
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@ public enum CompilerMessageSeverity {
|
||||
ERROR,
|
||||
WARNING,
|
||||
EXCEPTION,
|
||||
LOGGING;
|
||||
LOGGING,
|
||||
OUTPUT;
|
||||
|
||||
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
|
||||
}
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.cli.common.messages;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public class OutputMessageUtil {
|
||||
private static final String SOURCE_FILES_PREFIX = "Sources:";
|
||||
private static final String OUTPUT_FILES_PREFIX = "Output:";
|
||||
|
||||
public static String formatOutputMessage(Collection<File> sourceFiles, File outputFile) {
|
||||
return OUTPUT_FILES_PREFIX + "\n" + outputFile.getPath() + "\n" +
|
||||
SOURCE_FILES_PREFIX + "\n" + StringUtil.join(sourceFiles, "\n");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Output parseOutputMessage(@NotNull String message) {
|
||||
String[] strings = message.split("\n");
|
||||
|
||||
// Must have at least one line per prefix
|
||||
if (strings.length <= 2) return null;
|
||||
|
||||
if (!OUTPUT_FILES_PREFIX.equals(strings[0])) return null;
|
||||
|
||||
if (SOURCE_FILES_PREFIX.equals(strings[1])) {
|
||||
// Output:
|
||||
// Sources:
|
||||
// ...
|
||||
return new Output(parseSourceFiles(strings, 2), null);
|
||||
}
|
||||
else {
|
||||
File outputFile = new File(strings[1]);
|
||||
|
||||
if (!SOURCE_FILES_PREFIX.equals(strings[2])) return null;
|
||||
|
||||
return new Output(parseSourceFiles(strings, 3), outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static Collection<File> parseSourceFiles(String[] strings, int start) {
|
||||
Collection<File> sourceFiles = ContainerUtil.newArrayList();
|
||||
for (int i = start; i < strings.length; i++) {
|
||||
sourceFiles.add(new File(strings[i]));
|
||||
}
|
||||
return sourceFiles;
|
||||
}
|
||||
|
||||
public static class Output {
|
||||
@NotNull
|
||||
public final Collection<File> sourceFiles;
|
||||
@Nullable
|
||||
public final File outputFile;
|
||||
|
||||
public Output(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
||||
this.sourceFiles = sourceFiles;
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -19,10 +19,6 @@ package org.jetbrains.jet.cli.common.messages;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
@@ -52,7 +48,7 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
@NotNull String message,
|
||||
@NotNull CompilerMessageLocation location) {
|
||||
String text = messageRenderer.render(severity, message, location);
|
||||
if (severity == CompilerMessageSeverity.LOGGING) {
|
||||
if (severity == CompilerMessageSeverity.LOGGING || severity == CompilerMessageSeverity.OUTPUT) {
|
||||
if (!verbose) {
|
||||
return;
|
||||
}
|
||||
|
||||
+14
-1
@@ -36,6 +36,7 @@ import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.GenerationStrategy;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
@@ -51,7 +52,6 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -339,6 +339,19 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
public void log(String message) {
|
||||
configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
||||
if (outputFile == null) return;
|
||||
|
||||
MessageCollector messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY);
|
||||
if (messageCollector == null) return;
|
||||
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.OUTPUT,
|
||||
OutputMessageUtil.formatOutputMessage(sourceFiles, outputFile),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
}
|
||||
};
|
||||
GenerationState generationState = new GenerationState(
|
||||
project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(),
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.cli.common.messages;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class OutputMessageUtilTest extends TestCase {
|
||||
enum TargetOS {
|
||||
UNIX {
|
||||
@Override
|
||||
public String convert(String path) {
|
||||
return path.replace('\\', '/');
|
||||
}
|
||||
},
|
||||
WINDOWS {
|
||||
@Override
|
||||
public String convert(String path) {
|
||||
// convert absolute paths to declare their disk as C:
|
||||
if (path.startsWith("/")) {
|
||||
path = "C:" + path;
|
||||
}
|
||||
return path.replace('/', '\\');
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String convert(String path);
|
||||
}
|
||||
|
||||
private void doTest(String outputPath, String... sourcePathArray) {
|
||||
doTest(TargetOS.UNIX, outputPath, sourcePathArray);
|
||||
doTest(TargetOS.WINDOWS, outputPath, sourcePathArray);
|
||||
}
|
||||
|
||||
private void doTest(TargetOS os, String outputPath, String... sourcePathArray) {
|
||||
File[] sourceFileArray = new File[sourcePathArray.length];
|
||||
for (int i = 0; i < sourcePathArray.length; i++) {
|
||||
String path = sourcePathArray[i];
|
||||
sourceFileArray[i] = new File(os.convert(path));
|
||||
}
|
||||
doTest(new File(os.convert(outputPath)), sourceFileArray);
|
||||
}
|
||||
|
||||
private void doTest(File outputFile, File... sourceFileArray) {
|
||||
List<File> sourceFiles = Arrays.asList(sourceFileArray);
|
||||
String message = OutputMessageUtil.formatOutputMessage(sourceFiles, outputFile);
|
||||
OutputMessageUtil.Output output = OutputMessageUtil.parseOutputMessage(message);
|
||||
assertNotNull("Output is null", output);
|
||||
assertEquals(sourceFiles, output.sourceFiles);
|
||||
assertEquals(outputFile, output.outputFile);
|
||||
}
|
||||
|
||||
public void testOneInOneOut() throws Exception {
|
||||
doTest("foo/bar.class", "foo/bar.kt");
|
||||
doTest("/foo/bar.class", "/foo/bar.kt");
|
||||
doTest("/foo/bar.class", "foo/bar.kt");
|
||||
doTest("foo/bar.class", "/foo/bar.kt");
|
||||
}
|
||||
|
||||
public void testTwoInOneOut() throws Exception {
|
||||
doTest("foo/bar.class", "foo/bar.kt", "foo/buzz.kt");
|
||||
doTest("/foo/bar.class", "/foo/bar.kt", "/foo/buzz.kt");
|
||||
doTest("foo/bar.class", "/foo/bar.kt", "foo/buzz.kt");
|
||||
doTest("foo/bar.class", "foo/bar.kt", "/foo/buzz.kt");
|
||||
}
|
||||
|
||||
public void testOneInNoneOut() throws Exception {
|
||||
doTest("foo/bar.class");
|
||||
doTest("/foo/bar.class");
|
||||
}
|
||||
|
||||
public void testWrongStart() throws Exception {
|
||||
assertNull(OutputMessageUtil.parseOutputMessage("foo\nOutput:\nfoo"));
|
||||
}
|
||||
|
||||
public void testTwoOuts() throws Exception {
|
||||
assertNull(OutputMessageUtil.parseOutputMessage("Output:\nfoo\nbar\nInputs:\n"));
|
||||
}
|
||||
|
||||
public void testTooFewStrings() throws Exception {
|
||||
assertNull(OutputMessageUtil.parseOutputMessage("Output:\nInputs:"));
|
||||
}
|
||||
}
|
||||
+4
@@ -34,6 +34,10 @@ public abstract class AbstractOutputItemCollector<S, R> implements OutputItemsCo
|
||||
this.outputPath = outputPath;
|
||||
}
|
||||
|
||||
protected void addItem(R item) {
|
||||
answer.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void learn(String message) {
|
||||
message = message.trim();
|
||||
|
||||
@@ -21,10 +21,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
@@ -45,6 +42,7 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_L
|
||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*;
|
||||
|
||||
public class CompilerRunnerUtil {
|
||||
|
||||
private static SoftReference<URLClassLoader> ourClassLoaderRef = new SoftReference<URLClassLoader>(null);
|
||||
|
||||
public static List<File> kompilerClasspath(File kotlinHome, MessageCollector messageCollector) {
|
||||
@@ -241,8 +239,8 @@ public class CompilerRunnerUtil {
|
||||
}
|
||||
String text = message.toString();
|
||||
|
||||
if (category == LOGGING) {
|
||||
collector.learn(text);
|
||||
if (category == OUTPUT) {
|
||||
reportToCollector(text);
|
||||
}
|
||||
else {
|
||||
messageCollector.report(category, text, CompilerMessageLocation.create(path, line, column));
|
||||
@@ -250,6 +248,13 @@ public class CompilerRunnerUtil {
|
||||
tags.pop();
|
||||
}
|
||||
|
||||
private void reportToCollector(String text) {
|
||||
OutputMessageUtil.Output output = OutputMessageUtil.parseOutputMessage(text);
|
||||
if (output != null) {
|
||||
collector.add(output.sourceFiles, output.outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static int safeParseInt(@Nullable String value, int defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
|
||||
package org.jetbrains.jet.compiler.runner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface OutputItemsCollector {
|
||||
@Deprecated
|
||||
void learn(String message);
|
||||
void add(Collection<File> sourceFiles, File outputFile);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.compiler.runner.AbstractOutputItemCollector;
|
||||
import org.jetbrains.jet.compiler.runner.CompilerEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -65,6 +66,15 @@ public final class CompilerUtils {
|
||||
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);
|
||||
addItem(new OutputItemImpl(outputFile.getPath(), virtualFileForSourceFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user