summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lesot <jplesot@google.com>2015-03-06 13:06:51 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-06 13:06:51 +0000
commitd6059b4371b3039f5e6e473664302b4c6cada7dc (patch)
tree6f61704ce9553abc48924becc947ff099a52951e
parentee0fc945c65b1cedd16ee086cc034749844c3852 (diff)
parent6ed461d24dea889a408f7e326c2598af24e4f410 (diff)
downloadtoolchain_jack-d6059b4371b3039f5e6e473664302b4c6cada7dc.zip
toolchain_jack-d6059b4371b3039f5e6e473664302b4c6cada7dc.tar.gz
toolchain_jack-d6059b4371b3039f5e6e473664302b4c6cada7dc.tar.bz2
Merge "Add support of configurable standard input/output/error" into ub-jack
-rw-r--r--jack/src/com/android/jack/Main.java4
-rw-r--r--jack/src/com/android/jack/reporting/Reportable.java2
-rw-r--r--jack/src/com/android/jack/shrob/obfuscation/MappingPrinter.java2
-rw-r--r--jack/src/com/android/jack/shrob/seed/SeedPrinter.java2
-rw-r--r--jack/src/com/android/jack/shrob/shrink/ShrinkStructurePrinter.java2
-rw-r--r--sched/src/com/android/sched/scheduler/PlanPrinterFactory.java2
-rw-r--r--sched/src/com/android/sched/util/codec/CodecContext.java39
-rw-r--r--sched/src/com/android/sched/util/codec/InputStreamCodec.java28
-rw-r--r--sched/src/com/android/sched/util/codec/OutputStreamCodec.java60
-rw-r--r--sched/src/com/android/sched/util/codec/StreamCodec.java70
-rw-r--r--sched/src/com/android/sched/util/config/AsapConfigBuilder.java22
-rw-r--r--sched/src/com/android/sched/util/config/ConfigPrinterFactory.java2
-rw-r--r--sched/src/com/android/sched/util/config/GatherConfigBuilder.java22
-rw-r--r--sched/src/com/android/sched/util/file/AbstractStreamFile.java21
-rw-r--r--sched/src/com/android/sched/util/file/Directory.java7
-rw-r--r--sched/src/com/android/sched/util/file/InputStreamFile.java18
-rw-r--r--sched/src/com/android/sched/util/file/InputZipFile.java1
-rw-r--r--sched/src/com/android/sched/util/file/OutputStreamFile.java69
-rw-r--r--sched/src/com/android/sched/util/file/StreamFile.java6
-rw-r--r--sched/src/com/android/sched/util/location/NoLocation.java2
-rw-r--r--sched/src/com/android/sched/util/location/StandardErrorLocation.java41
-rw-r--r--sched/src/com/android/sched/util/table/ReportPrinterFactory.java2
22 files changed, 310 insertions, 114 deletions
diff --git a/jack/src/com/android/jack/Main.java b/jack/src/com/android/jack/Main.java
index 54b85f9..ca3e4ff 100644
--- a/jack/src/com/android/jack/Main.java
+++ b/jack/src/com/android/jack/Main.java
@@ -70,8 +70,6 @@ public abstract class Main extends CommandLine {
// Compile
runJackAndExitOnError(options);
-
- System.exit(ExitStatus.SUCCESS);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
CmdLineParser parser = e.getParser();
@@ -87,6 +85,8 @@ public abstract class Main extends CommandLine {
System.exit(ExitStatus.FAILURE_USAGE);
}
+
+ System.exit(ExitStatus.SUCCESS);
}
@Nonnull
diff --git a/jack/src/com/android/jack/reporting/Reportable.java b/jack/src/com/android/jack/reporting/Reportable.java
index 00a3a17..0833bd8 100644
--- a/jack/src/com/android/jack/reporting/Reportable.java
+++ b/jack/src/com/android/jack/reporting/Reportable.java
@@ -27,7 +27,7 @@ public interface Reportable {
* The level of a problem.
*/
public static enum ProblemLevel {
- ERROR, WARNING, INFO
+ ERROR, WARNING, INFO;
}
@Nonnull
diff --git a/jack/src/com/android/jack/shrob/obfuscation/MappingPrinter.java b/jack/src/com/android/jack/shrob/obfuscation/MappingPrinter.java
index 40b1fd3..72bf856 100644
--- a/jack/src/com/android/jack/shrob/obfuscation/MappingPrinter.java
+++ b/jack/src/com/android/jack/shrob/obfuscation/MappingPrinter.java
@@ -70,7 +70,7 @@ public class MappingPrinter implements RunnableSchedulable<JSession> {
@Nonnull
public static final PropertyId<OutputStreamFile> MAPPING_OUTPUT_FILE = PropertyId.create(
"jack.obfuscation.mapping.dump.file", "File where the mapping will be emitted",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-").withCategory(Arzon.get());
@Nonnull
diff --git a/jack/src/com/android/jack/shrob/seed/SeedPrinter.java b/jack/src/com/android/jack/shrob/seed/SeedPrinter.java
index f6d2627..31e7521 100644
--- a/jack/src/com/android/jack/shrob/seed/SeedPrinter.java
+++ b/jack/src/com/android/jack/shrob/seed/SeedPrinter.java
@@ -53,7 +53,7 @@ public class SeedPrinter implements RunnableSchedulable<JSession> {
@Nonnull
public static final PropertyId<OutputStreamFile> SEEDS_OUTPUT_FILE = PropertyId.create(
"jack.seed.dump.file", "File where the seeds will be printed",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-");
@Nonnull
diff --git a/jack/src/com/android/jack/shrob/shrink/ShrinkStructurePrinter.java b/jack/src/com/android/jack/shrob/shrink/ShrinkStructurePrinter.java
index 8f31e47..684d28c 100644
--- a/jack/src/com/android/jack/shrob/shrink/ShrinkStructurePrinter.java
+++ b/jack/src/com/android/jack/shrob/shrink/ShrinkStructurePrinter.java
@@ -51,7 +51,7 @@ public class ShrinkStructurePrinter implements RunnableSchedulable<JSession> {
@Nonnull
public static final PropertyId<OutputStreamFile> STRUCTURE_PRINTING_FILE = PropertyId.create(
"jack.internal.structure.print.file", "File containing the list of all types and members",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-").requiredIf(STRUCTURE_PRINTING.getValue().isTrue());
static class WriteException extends RuntimeException {
diff --git a/sched/src/com/android/sched/scheduler/PlanPrinterFactory.java b/sched/src/com/android/sched/scheduler/PlanPrinterFactory.java
index de80928..fc0fe3b 100644
--- a/sched/src/com/android/sched/scheduler/PlanPrinterFactory.java
+++ b/sched/src/com/android/sched/scheduler/PlanPrinterFactory.java
@@ -42,7 +42,7 @@ public class PlanPrinterFactory {
@Nonnull
public static final PropertyId<OutputStreamFile> PLAN_PRINTER_FILE = PropertyId.create(
"sched.plan.printer.file", "The file where to print the plan",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-");
public static PlanPrinter getPlanPrinter() {
diff --git a/sched/src/com/android/sched/util/codec/CodecContext.java b/sched/src/com/android/sched/util/codec/CodecContext.java
index f6deebd..e8884de 100644
--- a/sched/src/com/android/sched/util/codec/CodecContext.java
+++ b/sched/src/com/android/sched/util/codec/CodecContext.java
@@ -18,6 +18,9 @@ package com.android.sched.util.codec;
import com.android.sched.util.RunnableHooks;
+import java.io.InputStream;
+import java.io.PrintStream;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -31,6 +34,15 @@ public class CodecContext {
private RunnableHooks hooks;
@Nonnull
+ private InputStream standardInput = System.in;
+
+ @Nonnull
+ private PrintStream standardOutput = System.out;
+
+ @Nonnull
+ private PrintStream standardError = System.err;
+
+ @Nonnull
public CodecContext setDebug() {
this.debug = true;
@@ -52,4 +64,31 @@ public class CodecContext {
public RunnableHooks getRunnableHooks() {
return hooks;
}
+
+ @Nonnull
+ public InputStream getStandardInput() {
+ return standardInput;
+ }
+
+ public void setStandardInput(@Nonnull InputStream standardInput) {
+ this.standardInput = standardInput;
+ }
+
+ @Nonnull
+ public PrintStream getStandardOutput() {
+ return standardOutput;
+ }
+
+ public void setStandardOutput(@Nonnull PrintStream standardOutput) {
+ this.standardOutput = standardOutput;
+ }
+
+ @Nonnull
+ public PrintStream getStandardError() {
+ return standardError;
+ }
+
+ public void setStandardError(@Nonnull PrintStream standardError) {
+ this.standardError = standardError;
+ }
}
diff --git a/sched/src/com/android/sched/util/codec/InputStreamCodec.java b/sched/src/com/android/sched/util/codec/InputStreamCodec.java
index 0d86110..de5c3fc 100644
--- a/sched/src/com/android/sched/util/codec/InputStreamCodec.java
+++ b/sched/src/com/android/sched/util/codec/InputStreamCodec.java
@@ -17,10 +17,11 @@
package com.android.sched.util.codec;
import com.android.sched.util.config.ConfigurationError;
-import com.android.sched.util.file.AbstractStreamFile;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.FileOrDirectory.Permission;
import com.android.sched.util.file.InputStreamFile;
+import com.android.sched.util.location.Location;
+import com.android.sched.util.location.StandardInputLocation;
import java.io.IOException;
@@ -36,8 +37,8 @@ public class InputStreamCodec extends StreamCodec
}
@Nonnull
- public InputStreamCodec allowStandard() {
- this.allowStandard = true;
+ public InputStreamCodec allowStandardInput() {
+ this.allowStandardIO = true;
return this;
}
@@ -45,13 +46,19 @@ public class InputStreamCodec extends StreamCodec
@Override
@Nonnull
public String formatValue(@Nonnull InputStreamFile stream) {
- return formatValue((AbstractStreamFile) stream);
+ if (stream.isStandard()) {
+ return STANDARD_IO_NAME;
+ } else {
+ return stream.getPath();
+ }
}
@Override
public void checkValue(@Nonnull CodecContext context, @Nonnull InputStreamFile stream)
throws CheckingException {
- checkValue(context, (AbstractStreamFile) stream);
+ if (stream.isStandard() && !allowStandardIO) {
+ throw new CheckingException("Standard input is not allowed");
+ }
}
@Override
@@ -64,14 +71,19 @@ public class InputStreamCodec extends StreamCodec
}
}
+ @Nonnull
+ private static final Location STANDARD_INPUT_LOCATION = new StandardInputLocation();
+
@Override
@Nonnull
public InputStreamFile checkString(@Nonnull CodecContext context, @Nonnull String string)
throws ParsingException {
- super.checkString(context, string);
-
if (string.equals(STANDARD_IO_NAME)) {
- return new InputStreamFile();
+ if (!allowStandardIO) {
+ throw new ParsingException("Standard input can not be used");
+ }
+
+ return new InputStreamFile(context.getStandardInput(), STANDARD_INPUT_LOCATION);
} else {
try {
return new InputStreamFile(string);
diff --git a/sched/src/com/android/sched/util/codec/OutputStreamCodec.java b/sched/src/com/android/sched/util/codec/OutputStreamCodec.java
index 86c3e3d..c642f7d 100644
--- a/sched/src/com/android/sched/util/codec/OutputStreamCodec.java
+++ b/sched/src/com/android/sched/util/codec/OutputStreamCodec.java
@@ -17,11 +17,12 @@
package com.android.sched.util.codec;
import com.android.sched.util.config.ConfigurationError;
-import com.android.sched.util.file.AbstractStreamFile;
import com.android.sched.util.file.FileOrDirectory.ChangePermission;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.FileOrDirectory.Permission;
import com.android.sched.util.file.OutputStreamFile;
+import com.android.sched.util.file.OutputStreamFile.StandardOutputKind;
+import com.android.sched.util.location.Location;
import java.io.IOException;
@@ -53,8 +54,23 @@ public class OutputStreamCodec extends StreamCodec
}
@Nonnull
- public OutputStreamCodec allowStandard() {
- this.allowStandard = true;
+ public OutputStreamCodec allowStandardOutputOrError() {
+ this.allowStandardIO = true;
+ this.allowStandardError = true;
+
+ return this;
+ }
+
+ @Nonnull
+ public OutputStreamCodec allowStandardOutput() {
+ this.allowStandardIO = true;
+
+ return this;
+ }
+
+ @Nonnull
+ public OutputStreamCodec allowStandardError() {
+ this.allowStandardError = true;
return this;
}
@@ -66,17 +82,33 @@ public class OutputStreamCodec extends StreamCodec
return this;
}
-
@Override
@Nonnull
public String formatValue(@Nonnull OutputStreamFile stream) {
- return formatValue((AbstractStreamFile) stream);
+ if (stream.isStandard()) {
+ if (stream.getLocation().equals(StandardOutputKind.STANDARD_OUTPUT.getLocation())) {
+ return STANDARD_IO_NAME;
+ } else {
+ assert stream.getLocation().equals(StandardOutputKind.STANDARD_ERROR.getLocation());
+
+ return STANDARD_ERROR_NAME;
+ }
+ } else {
+ return stream.getPath();
+ }
}
@Override
public void checkValue(@Nonnull CodecContext context, @Nonnull OutputStreamFile stream)
throws CheckingException {
- checkValue(context, (AbstractStreamFile) stream);
+ Location location = stream.getLocation();
+
+ if (location.equals(StandardOutputKind.STANDARD_OUTPUT.getLocation()) && !allowStandardIO) {
+ throw new CheckingException("Standard output is not allowed");
+ } else if (location.equals(StandardOutputKind.STANDARD_ERROR.getLocation())
+ && !allowStandardError) {
+ throw new CheckingException("Standard error is not allowed");
+ }
}
@Override
@@ -93,10 +125,20 @@ public class OutputStreamCodec extends StreamCodec
@Nonnull
public OutputStreamFile checkString(@Nonnull CodecContext context, @Nonnull String string)
throws ParsingException {
- super.checkString(context, string);
-
if (string.equals(STANDARD_IO_NAME)) {
- return new OutputStreamFile();
+ if (!allowStandardIO) {
+ throw new ParsingException("Standard output can not be used");
+ }
+
+ return new OutputStreamFile(context.getStandardOutput(),
+ StandardOutputKind.STANDARD_OUTPUT.getLocation());
+ } else if (string.equals(STANDARD_ERROR_NAME)) {
+ if (!allowStandardError) {
+ throw new ParsingException("Standard error can not be used");
+ }
+
+ return new OutputStreamFile(context.getStandardError(),
+ StandardOutputKind.STANDARD_ERROR.getLocation());
} else {
try {
return new OutputStreamFile(string, context.getRunnableHooks(), existence, change, append);
diff --git a/sched/src/com/android/sched/util/codec/StreamCodec.java b/sched/src/com/android/sched/util/codec/StreamCodec.java
index c8776eb..4708796 100644
--- a/sched/src/com/android/sched/util/codec/StreamCodec.java
+++ b/sched/src/com/android/sched/util/codec/StreamCodec.java
@@ -16,12 +16,10 @@
package com.android.sched.util.codec;
-import com.android.sched.util.file.AbstractStreamFile;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.FileOrDirectory.Permission;
import com.android.sched.util.file.StreamFile;
-import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
@@ -31,8 +29,11 @@ import javax.annotation.Nonnull;
public abstract class StreamCodec extends FileOrDirCodec {
@Nonnull
protected static final String STANDARD_IO_NAME = "-";
+ @Nonnull
+ protected static final String STANDARD_ERROR_NAME = "--";
- protected boolean allowStandard;
+ protected boolean allowStandardIO = false;
+ protected boolean allowStandardError = false;
protected StreamCodec(@Nonnull Existence existence, int permissions) {
super(existence, permissions);
@@ -43,65 +44,30 @@ public abstract class StreamCodec extends FileOrDirCodec {
@Nonnull
public String getUsage() {
- StringBuilderAppender sb = new StringBuilderAppender(", ");
+ StringBuilder sb = new StringBuilder();
sb.append("a path to a file (");
-
sb.append(getUsageDetails());
- if (allowStandard) {
- StringBuilderAppender ssb = new StringBuilderAppender("/");
-
- ssb.append("can be '");
- ssb.append(STANDARD_IO_NAME);
- ssb.append("' for standard ");
- ssb.append((permissions & Permission.READ) != 0, "input");
- ssb.append((permissions & Permission.WRITE) != 0, "output");
-
- sb.append(true, ssb.toString());
- }
-
sb.append(")");
- return sb.toString();
- }
-
- @CheckForNull
- protected AbstractStreamFile checkString(@Nonnull CodecContext context, @Nonnull String value)
- throws ParsingException {
- if (value.equals(STANDARD_IO_NAME)) {
- if (!allowStandard) {
- throw new ParsingException(getStandardStreamDescription() + " can not be used");
- }
- }
+ if (allowStandardIO) {
+ StringBuilderAppender sbSlash = new StringBuilderAppender("/");
- return null;
- }
+ sbSlash.append(", can be '");
+ sbSlash.append(STANDARD_IO_NAME);
+ sbSlash.append("' for standard ");
+ sbSlash.append((permissions & Permission.READ) != 0, "input");
+ sbSlash.append((permissions & Permission.WRITE) != 0, "output");
- protected void checkValue(@Nonnull CodecContext context, @Nonnull AbstractStreamFile stream)
- throws CheckingException {
- if (stream.isStandard() && !allowStandard) {
- throw new CheckingException(getStandardStreamDescription() + " is not allowed");
+ sb.append(sbSlash.toString());
}
- }
-
- @Nonnull
- private String getStandardStreamDescription() {
- StringBuilderAppender sb = new StringBuilderAppender("/");
-
- sb.append("Standard ");
- sb.append((permissions & Permission.READ) != 0, "input");
- sb.append((permissions & Permission.WRITE) != 0, "output");
+ if (allowStandardError) {
+ sb.append(", can be '");
+ sb.append(STANDARD_ERROR_NAME);
+ sb.append("' for standard error");
+ }
return sb.toString();
}
-
- @Nonnull
- protected String formatValue(@Nonnull AbstractStreamFile stream) {
- if (stream.isStandard()) {
- return STANDARD_IO_NAME;
- } else {
- return stream.getPath();
- }
- }
}
diff --git a/sched/src/com/android/sched/util/config/AsapConfigBuilder.java b/sched/src/com/android/sched/util/config/AsapConfigBuilder.java
index 421fd99..5c623eb 100644
--- a/sched/src/com/android/sched/util/config/AsapConfigBuilder.java
+++ b/sched/src/com/android/sched/util/config/AsapConfigBuilder.java
@@ -39,6 +39,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
+import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -296,6 +297,27 @@ public class AsapConfigBuilder {
}
@Nonnull
+ public AsapConfigBuilder setStandardInput(@Nonnull InputStream in) {
+ context.setStandardInput(in);
+
+ return this;
+ }
+
+ @Nonnull
+ public AsapConfigBuilder setStandardOutput(@Nonnull PrintStream printer) {
+ context.setStandardOutput(printer);
+
+ return this;
+ }
+
+ @Nonnull
+ public AsapConfigBuilder setStandardError(@Nonnull PrintStream printer) {
+ context.setStandardError(printer);
+
+ return this;
+ }
+
+ @Nonnull
public AsapConfigBuilder setStrictMode() {
this.strict = true;
diff --git a/sched/src/com/android/sched/util/config/ConfigPrinterFactory.java b/sched/src/com/android/sched/util/config/ConfigPrinterFactory.java
index dbfe23e..29c4bc2 100644
--- a/sched/src/com/android/sched/util/config/ConfigPrinterFactory.java
+++ b/sched/src/com/android/sched/util/config/ConfigPrinterFactory.java
@@ -38,7 +38,7 @@ public class ConfigPrinterFactory {
@Nonnull
public static final PropertyId<OutputStreamFile> CONFIG_PRINTER_FILE = PropertyId.create(
"config.printer.file", "The file where to print the config",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-");
@Nonnull
diff --git a/sched/src/com/android/sched/util/config/GatherConfigBuilder.java b/sched/src/com/android/sched/util/config/GatherConfigBuilder.java
index 9baf7da..a927669 100644
--- a/sched/src/com/android/sched/util/config/GatherConfigBuilder.java
+++ b/sched/src/com/android/sched/util/config/GatherConfigBuilder.java
@@ -25,6 +25,7 @@ import com.android.sched.util.location.Location;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintStream;
import java.util.Collection;
import javax.annotation.CheckForNull;
@@ -188,6 +189,27 @@ public class GatherConfigBuilder {
}
@Nonnull
+ public GatherConfigBuilder setStandardInput(@Nonnull InputStream in) {
+ builder.setStandardInput(in);
+
+ return this;
+ }
+
+ @Nonnull
+ public GatherConfigBuilder setStandardOutput(@Nonnull PrintStream printer) {
+ builder.setStandardOutput(printer);
+
+ return this;
+ }
+
+ @Nonnull
+ public GatherConfigBuilder setStandardError(@Nonnull PrintStream printer) {
+ builder.setStandardError(printer);
+
+ return this;
+ }
+
+ @Nonnull
public GatherConfigBuilder setStrictMode() {
builder.setStrictMode();
diff --git a/sched/src/com/android/sched/util/file/AbstractStreamFile.java b/sched/src/com/android/sched/util/file/AbstractStreamFile.java
index 9b20b40..2a680d4 100644
--- a/sched/src/com/android/sched/util/file/AbstractStreamFile.java
+++ b/sched/src/com/android/sched/util/file/AbstractStreamFile.java
@@ -18,10 +18,7 @@ package com.android.sched.util.file;
import com.android.sched.util.RunnableHooks;
import com.android.sched.util.location.FileLocation;
-import com.android.sched.util.location.FileOrDirLocation;
import com.android.sched.util.location.Location;
-import com.android.sched.util.location.StandardInputLocation;
-import com.android.sched.util.location.StandardOutputLocation;
import com.android.sched.util.log.LoggerFactory;
import java.io.File;
@@ -49,18 +46,10 @@ public abstract class AbstractStreamFile extends FileOrDirectory {
this.location = new FileLocation(file);
}
- protected AbstractStreamFile(int permissions) {
+ protected AbstractStreamFile(@Nonnull Location location) {
super(null);
-
- assert permissions == Permission.READ || permissions == Permission.WRITE;
-
this.file = null;
-
- if (permissions == Permission.READ) {
- this.location = new StandardInputLocation();
- } else {
- this.location = new StandardOutputLocation();
- }
+ this.location = location;
}
protected void performChecks(@Nonnull Existence existence, int permissions,
@@ -83,7 +72,7 @@ public abstract class AbstractStreamFile extends FileOrDirectory {
switch (existence) {
case MUST_EXIST:
- AbstractStreamFile.check(file, (FileOrDirLocation) location);
+ AbstractStreamFile.check(file, (FileLocation) location);
FileOrDirectory.checkPermissions(file, location, permissions);
break;
case NOT_EXIST:
@@ -129,7 +118,7 @@ public abstract class AbstractStreamFile extends FileOrDirectory {
}
}
- public static void check(@Nonnull File file, @Nonnull FileOrDirLocation location)
+ public static void check(@Nonnull File file, @Nonnull FileLocation location)
throws NoSuchFileException, NotFileException {
assert file != null;
@@ -140,7 +129,7 @@ public abstract class AbstractStreamFile extends FileOrDirectory {
// Check it is a file
if (!file.isFile()) {
- throw new NotFileException((FileLocation) location);
+ throw new NotFileException(location);
}
}
diff --git a/sched/src/com/android/sched/util/file/Directory.java b/sched/src/com/android/sched/util/file/Directory.java
index 28c6e4c..55b30da 100644
--- a/sched/src/com/android/sched/util/file/Directory.java
+++ b/sched/src/com/android/sched/util/file/Directory.java
@@ -18,7 +18,6 @@ package com.android.sched.util.file;
import com.android.sched.util.RunnableHooks;
import com.android.sched.util.location.DirectoryLocation;
-import com.android.sched.util.location.FileOrDirLocation;
import com.android.sched.util.location.Location;
import com.android.sched.util.log.LoggerFactory;
@@ -61,7 +60,7 @@ public class Directory extends FileOrDirectory {
switch (existence) {
case MUST_EXIST:
- Directory.check(file, (FileOrDirLocation) location);
+ Directory.check(file, (DirectoryLocation) location);
FileOrDirectory.checkPermissions(file, location, permissions);
break;
case NOT_EXIST:
@@ -88,7 +87,7 @@ public class Directory extends FileOrDirectory {
return location.getDescription();
}
- public static void check(@Nonnull File file, @Nonnull FileOrDirLocation location)
+ public static void check(@Nonnull File file, @Nonnull DirectoryLocation location)
throws NoSuchFileException, NotDirectoryException {
assert file != null;
@@ -99,7 +98,7 @@ public class Directory extends FileOrDirectory {
// Check directory
if (!file.isDirectory()) {
- throw new NotDirectoryException((DirectoryLocation) location);
+ throw new NotDirectoryException(location);
}
}
diff --git a/sched/src/com/android/sched/util/file/InputStreamFile.java b/sched/src/com/android/sched/util/file/InputStreamFile.java
index 9f5a6d6..a693e56 100644
--- a/sched/src/com/android/sched/util/file/InputStreamFile.java
+++ b/sched/src/com/android/sched/util/file/InputStreamFile.java
@@ -17,18 +17,24 @@
package com.android.sched.util.file;
import com.android.sched.util.ConcurrentIOException;
+import com.android.sched.util.location.Location;
+import com.android.sched.util.location.StandardInputLocation;
import com.android.sched.util.stream.UncloseableInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
* Class representing a input stream from a file path or a standard input.
*/
public class InputStreamFile extends AbstractStreamFile {
+ @CheckForNull
+ private InputStream in;
+
public InputStreamFile(@Nonnull String name)
throws WrongPermissionException, NotFileException, NoSuchFileException {
super(name, null /* hooks */);
@@ -45,13 +51,19 @@ public class InputStreamFile extends AbstractStreamFile {
}
public InputStreamFile() {
- super(Permission.READ);
+ super(new StandardInputLocation());
+ in = System.in;
+ }
+
+ public InputStreamFile(@Nonnull InputStream in, @Nonnull Location location) {
+ super(location);
+ this.in = in;
}
@Nonnull
public InputStream getInputStream() {
- if (file == null) {
- return new UncloseableInputStream(System.in);
+ if (in != null) {
+ return new UncloseableInputStream(in);
} else {
clearRemover();
try {
diff --git a/sched/src/com/android/sched/util/file/InputZipFile.java b/sched/src/com/android/sched/util/file/InputZipFile.java
index 7dccb58..670d712 100644
--- a/sched/src/com/android/sched/util/file/InputZipFile.java
+++ b/sched/src/com/android/sched/util/file/InputZipFile.java
@@ -48,6 +48,7 @@ public class InputZipFile extends StreamFile {
zipFile = processZip(file);
}
+ @Nonnull
private ZipFile processZip(File file) throws ZipException {
try {
return new ZipFile(file);
diff --git a/sched/src/com/android/sched/util/file/OutputStreamFile.java b/sched/src/com/android/sched/util/file/OutputStreamFile.java
index 59fa247..055869b 100644
--- a/sched/src/com/android/sched/util/file/OutputStreamFile.java
+++ b/sched/src/com/android/sched/util/file/OutputStreamFile.java
@@ -18,6 +18,9 @@ package com.android.sched.util.file;
import com.android.sched.util.ConcurrentIOException;
import com.android.sched.util.RunnableHooks;
+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;
@@ -35,6 +38,9 @@ import javax.annotation.Nonnull;
public class OutputStreamFile extends AbstractStreamFile {
private final boolean append;
+ @CheckForNull
+ private PrintStream printer;
+
public OutputStreamFile(@Nonnull String name,
@CheckForNull RunnableHooks hooks,
@Nonnull Existence existence,
@@ -77,16 +83,67 @@ public class OutputStreamFile extends AbstractStreamFile {
this.append = false;
}
- public OutputStreamFile() {
- super(Permission.WRITE);
+ @Nonnull
+ private static final Location STANDARD_OUTPUT_LOCATION = new StandardOutputLocation();
+ @Nonnull
+ private static final Location STANDARD_ERROR_LOCATION = new StandardErrorLocation();
+
+ /**
+ * Standard output stream kinds
+ */
+ public enum StandardOutputKind {
+
+ STANDARD_OUTPUT {
+ @Override
+ @Nonnull
+ public PrintStream getPrintStream() {
+ return System.out;
+ }
+
+ @Override
+ @Nonnull
+ public Location getLocation() {
+ return STANDARD_OUTPUT_LOCATION;
+ }
+ },
+
+ STANDARD_ERROR {
+ @Override
+ @Nonnull
+ public PrintStream getPrintStream() {
+ return System.err;
+ }
+
+ @Override
+ @Nonnull
+ public Location getLocation() {
+ return STANDARD_ERROR_LOCATION;
+ }
+ };
+
+ @Nonnull
+ public abstract PrintStream getPrintStream();
+
+ @Nonnull
+ public abstract Location getLocation();
+ }
+
+ public OutputStreamFile(@Nonnull StandardOutputKind standardOutputKind) {
+ super(standardOutputKind.getLocation());
+ this.printer = standardOutputKind.getPrintStream();
+ this.append = true;
+ }
+ public OutputStreamFile(@Nonnull PrintStream printer, @Nonnull Location location) {
+ super(location);
+ this.printer = printer;
this.append = true;
}
@Nonnull
public OutputStream getOutputStream() {
- if (file == null) {
- return new UncloseableOutputStream(System.out);
+ if (printer != null) {
+ return new UncloseableOutputStream(printer);
} else {
clearRemover();
try {
@@ -99,8 +156,8 @@ public class OutputStreamFile extends AbstractStreamFile {
@Nonnull
public PrintStream getPrintStream() {
- if (file == null) {
- return new UncloseablePrintStream(System.out);
+ if (printer != null) {
+ return new UncloseablePrintStream(printer);
} else {
clearRemover();
try {
diff --git a/sched/src/com/android/sched/util/file/StreamFile.java b/sched/src/com/android/sched/util/file/StreamFile.java
index 863b7ca..3903dce 100644
--- a/sched/src/com/android/sched/util/file/StreamFile.java
+++ b/sched/src/com/android/sched/util/file/StreamFile.java
@@ -42,10 +42,4 @@ public class StreamFile extends AbstractStreamFile {
performChecks(existence, permissions, change);
}
-
- public StreamFile(int permissions) {
- super(permissions);
- }
-
-
} \ No newline at end of file
diff --git a/sched/src/com/android/sched/util/location/NoLocation.java b/sched/src/com/android/sched/util/location/NoLocation.java
index bbdbd71..e158c49 100644
--- a/sched/src/com/android/sched/util/location/NoLocation.java
+++ b/sched/src/com/android/sched/util/location/NoLocation.java
@@ -36,6 +36,6 @@ public class NoLocation extends Location {
@Override
public final int hashCode() {
- return 0x12345678;
+ return NoLocation.class.hashCode();
}
}
diff --git a/sched/src/com/android/sched/util/location/StandardErrorLocation.java b/sched/src/com/android/sched/util/location/StandardErrorLocation.java
new file mode 100644
index 0000000..c42cf51
--- /dev/null
+++ b/sched/src/com/android/sched/util/location/StandardErrorLocation.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * 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 com.android.sched.util.location;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * Class describing a standard error.
+ */
+public class StandardErrorLocation extends Location {
+ @Override
+ @Nonnull
+ public String getDescription() {
+ return "standard error";
+ }
+
+ @Override
+ public final boolean equals(@CheckForNull Object obj) {
+ return obj instanceof StandardErrorLocation;
+ }
+
+ @Override
+ public final int hashCode() {
+ return StandardErrorLocation.class.hashCode();
+ }
+}
diff --git a/sched/src/com/android/sched/util/table/ReportPrinterFactory.java b/sched/src/com/android/sched/util/table/ReportPrinterFactory.java
index 7a0c1e0..50be05c 100644
--- a/sched/src/com/android/sched/util/table/ReportPrinterFactory.java
+++ b/sched/src/com/android/sched/util/table/ReportPrinterFactory.java
@@ -41,7 +41,7 @@ public class ReportPrinterFactory{
@Nonnull
public static final PropertyId<OutputStreamFile> REPORT_PRINTER_FILE = PropertyId.create(
"sched.report.printer.file", "The file where to print the report",
- new OutputStreamCodec(Existence.MAY_EXIST).allowStandard())
+ new OutputStreamCodec(Existence.MAY_EXIST).allowStandardOutputOrError())
.addDefaultValue("-");
public static ReportPrinter getReportPrinter() {