summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jack/src/com/android/jack/reporting/CommonReporter.java18
-rw-r--r--jack/src/com/android/jack/reporting/DefaultReporter.java10
-rw-r--r--jack/src/com/android/jack/reporting/Reporter.java32
-rw-r--r--jack/src/com/android/jack/reporting/SdkReporter.java10
-rw-r--r--sched/src/com/android/sched/util/file/InputStreamFile.java15
-rw-r--r--sched/src/com/android/sched/util/file/OutputStreamFile.java33
6 files changed, 88 insertions, 30 deletions
diff --git a/jack/src/com/android/jack/reporting/CommonReporter.java b/jack/src/com/android/jack/reporting/CommonReporter.java
index d7b8f2e..6561d78 100644
--- a/jack/src/com/android/jack/reporting/CommonReporter.java
+++ b/jack/src/com/android/jack/reporting/CommonReporter.java
@@ -21,10 +21,14 @@ import com.android.jack.Options.VerbosityLevel;
import com.android.jack.frontend.java.EcjProblem;
import com.android.jack.reporting.Reportable.ProblemLevel;
import com.android.sched.util.config.ThreadConfig;
+import com.android.sched.util.file.OutputStreamFile;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import java.io.PrintStream;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -39,8 +43,18 @@ abstract class CommonReporter implements Reporter {
private final VerbosityLevel verbosityLevel = ThreadConfig.get(Options.VERBOSITY_LEVEL);
@Nonnull
- protected final PrintStream reporterStream =
- ThreadConfig.get(REPORTER_OUTPUT_STREAM).getPrintStream();
+ protected final PrintStream streamByDefault = ThreadConfig.get(REPORTER_OUTPUT_STREAM)
+ .getPrintStream();
+ @Nonnull
+ protected final Map<ProblemLevel, PrintStream> streamByLevel =
+ new EnumMap<ProblemLevel, PrintStream>(ProblemLevel.class);
+
+ protected CommonReporter() {
+ for (final Entry<ProblemLevel, OutputStreamFile> entry : ThreadConfig.get(
+ Reporter.REPORTER_OUTPUT_STREAM_BY_LEVEL).entrySet()) {
+ streamByLevel.put(entry.getKey(), entry.getValue().getPrintStream());
+ }
+ }
@Override
public void report(@Nonnull Severity severity, @Nonnull Reportable reportable) {
diff --git a/jack/src/com/android/jack/reporting/DefaultReporter.java b/jack/src/com/android/jack/reporting/DefaultReporter.java
index ac9e335..8371878 100644
--- a/jack/src/com/android/jack/reporting/DefaultReporter.java
+++ b/jack/src/com/android/jack/reporting/DefaultReporter.java
@@ -19,6 +19,8 @@ package com.android.jack.reporting;
import com.android.jack.reporting.Reportable.ProblemLevel;
import com.android.sched.util.codec.ImplementationName;
+import java.io.PrintStream;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -48,6 +50,12 @@ public class DefaultReporter extends CommonReporter {
}
messageBuffer.append(": ");
messageBuffer.append(message);
- reporterStream.println(messageBuffer.toString());
+
+ PrintStream printer = streamByLevel.get(problemLevel);
+ if (printer == null) {
+ printer = streamByDefault;
+ }
+
+ printer.println(messageBuffer.toString());
}
}
diff --git a/jack/src/com/android/jack/reporting/Reporter.java b/jack/src/com/android/jack/reporting/Reporter.java
index 5a09d07..c42e5e8 100644
--- a/jack/src/com/android/jack/reporting/Reporter.java
+++ b/jack/src/com/android/jack/reporting/Reporter.java
@@ -18,13 +18,23 @@ package com.android.jack.reporting;
import com.android.jack.config.id.Arzon;
import com.android.jack.config.id.Brest;
+import com.android.jack.reporting.Reportable.ProblemLevel;
+import com.android.sched.util.codec.EnumCodec;
+import com.android.sched.util.codec.ListCodec;
import com.android.sched.util.codec.OutputStreamCodec;
+import com.android.sched.util.codec.PairCodec;
+import com.android.sched.util.codec.PairListToMapCodecConverter;
import com.android.sched.util.config.HasKeyId;
import com.android.sched.util.config.id.ImplementationPropertyId;
import com.android.sched.util.config.id.PropertyId;
+import com.android.sched.util.config.id.PropertyId.ShutdownRunnable;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.OutputStreamFile;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+
import javax.annotation.Nonnull;
/**
@@ -52,6 +62,26 @@ public interface Reporter {
.addDefaultValue("--").requiredIf(REPORTER.getClazz().isImplementedBy(DefaultReporter.class)
.or(REPORTER.getClazz().isImplementedBy(SdkReporter.class))).withCategory(Brest.get());
- public void report(@Nonnull Severity severity, @Nonnull Reportable reportable);
+ @Nonnull
+ public static final PropertyId<Map<ProblemLevel, OutputStreamFile>>
+ REPORTER_OUTPUT_STREAM_BY_LEVEL =
+ PropertyId
+ .create(
+ "jack.reporter.level.file",
+ "File where the reporter will write by level",
+ new PairListToMapCodecConverter<ProblemLevel, OutputStreamFile>(
+ new ListCodec<Entry<ProblemLevel, OutputStreamFile>>("pair",
+ new PairCodec<ProblemLevel, OutputStreamFile>(new EnumCodec<ProblemLevel>(
+ ProblemLevel.values()).ignoreCase(), new OutputStreamCodec(
+ Existence.MAY_EXIST).allowStandardOutputOrError()).on("="))))
+ .addDefaultValue(Collections.<ProblemLevel, OutputStreamFile>emptyMap())
+ .setShutdownHook(new ShutdownRunnable<Map<ProblemLevel, OutputStreamFile>>() {
+ @Override
+ public void run(@Nonnull Map<ProblemLevel, OutputStreamFile> map) {
+ for (OutputStreamFile osf : map.values()) {
+ osf.getPrintStream().close();
+ }
+ }});
+ public void report(@Nonnull Severity severity, @Nonnull Reportable reportable);
}
diff --git a/jack/src/com/android/jack/reporting/SdkReporter.java b/jack/src/com/android/jack/reporting/SdkReporter.java
index 505933c..c72eab3 100644
--- a/jack/src/com/android/jack/reporting/SdkReporter.java
+++ b/jack/src/com/android/jack/reporting/SdkReporter.java
@@ -19,6 +19,8 @@ package com.android.jack.reporting;
import com.android.jack.reporting.Reportable.ProblemLevel;
import com.android.sched.util.codec.ImplementationName;
+import java.io.PrintStream;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -62,6 +64,12 @@ public class SdkReporter extends CommonReporter {
}
messageBuffer.append(MESSAGE_SEPARATOR);
messageBuffer.append(message);
- reporterStream.println(messageBuffer.toString());
+
+ PrintStream printer = streamByLevel.get(problemLevel);
+ if (printer == null) {
+ printer = streamByDefault;
+ }
+
+ printer.println(messageBuffer.toString());
}
}
diff --git a/sched/src/com/android/sched/util/file/InputStreamFile.java b/sched/src/com/android/sched/util/file/InputStreamFile.java
index 179da19..1aa3b4f 100644
--- a/sched/src/com/android/sched/util/file/InputStreamFile.java
+++ b/sched/src/com/android/sched/util/file/InputStreamFile.java
@@ -35,7 +35,7 @@ import javax.annotation.Nonnull;
*/
public class InputStreamFile extends AbstractStreamFile {
@CheckForNull
- private InputStream in;
+ private InputStream stream;
public InputStreamFile(@Nonnull String name)
throws WrongPermissionException, NotFileException, NoSuchFileException {
@@ -44,12 +44,12 @@ public class InputStreamFile extends AbstractStreamFile {
public InputStreamFile() {
super(new StandardInputLocation());
- in = System.in;
+ stream = new UncloseableInputStream(System.in);
}
public InputStreamFile(@Nonnull InputStream in, @Nonnull Location location) {
super(location);
- this.in = in;
+ this.stream = new UncloseableInputStream(in);
}
public InputStreamFile(@CheckForNull Directory workingDirectory, @Nonnull String string)
@@ -74,15 +74,16 @@ public class InputStreamFile extends AbstractStreamFile {
@Nonnull
public InputStream getInputStream() {
- if (in != null) {
- return new UncloseableInputStream(in);
- } else {
+ if (stream == null) {
clearRemover();
+
try {
- return new FileInputStream(file);
+ stream = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new ConcurrentIOException(e);
}
}
+
+ return stream;
}
} \ No newline at end of file
diff --git a/sched/src/com/android/sched/util/file/OutputStreamFile.java b/sched/src/com/android/sched/util/file/OutputStreamFile.java
index 17644e0..0b78ebb 100644
--- a/sched/src/com/android/sched/util/file/OutputStreamFile.java
+++ b/sched/src/com/android/sched/util/file/OutputStreamFile.java
@@ -22,7 +22,6 @@ import com.android.sched.util.location.FileLocation;
import com.android.sched.util.location.Location;
import com.android.sched.util.location.StandardErrorLocation;
import com.android.sched.util.location.StandardOutputLocation;
-import com.android.sched.util.stream.UncloseableOutputStream;
import com.android.sched.util.stream.UncloseablePrintStream;
import java.io.File;
@@ -42,6 +41,8 @@ public class OutputStreamFile extends AbstractStreamFile {
@CheckForNull
private PrintStream printer;
+ @CheckForNull
+ private OutputStream stream;
public OutputStreamFile(@Nonnull String name,
@CheckForNull RunnableHooks hooks,
@@ -157,7 +158,7 @@ public class OutputStreamFile extends AbstractStreamFile {
@Override
@Nonnull
public PrintStream getPrintStream() {
- return System.out;
+ return new UncloseablePrintStream(System.out);
}
@Override
@@ -171,7 +172,7 @@ public class OutputStreamFile extends AbstractStreamFile {
@Override
@Nonnull
public PrintStream getPrintStream() {
- return System.err;
+ return new UncloseablePrintStream(System.err);
}
@Override
@@ -196,35 +197,31 @@ public class OutputStreamFile extends AbstractStreamFile {
public OutputStreamFile(@Nonnull PrintStream printer, @Nonnull Location location) {
super(location);
- this.printer = printer;
+ this.printer = new UncloseablePrintStream(printer);
this.append = true;
}
@Nonnull
public OutputStream getOutputStream() {
- if (printer != null) {
- return new UncloseableOutputStream(printer);
- } else {
+ if (stream == null) {
clearRemover();
+
try {
- return new FileOutputStream(file, append);
+ stream = new FileOutputStream(file, append);
} catch (FileNotFoundException e) {
throw new ConcurrentIOException(e);
}
}
+
+ return stream;
}
@Nonnull
public PrintStream getPrintStream() {
- if (printer != null) {
- return new UncloseablePrintStream(printer);
- } else {
- clearRemover();
- try {
- return new PrintStream(file);
- } catch (FileNotFoundException e) {
- throw new ConcurrentIOException(e);
- }
+ if (printer == null) {
+ printer = new PrintStream(getOutputStream());
}
+
+ return printer;
}
-} \ No newline at end of file
+}