Skip to content
Browse files

Added support for stdin processing of coverage files

  • Loading branch information...
1 parent 910e3c0 commit eaf1f11a889b8b737944ddb4bb98ac1f352b1389 @davglass davglass committed
Showing with 21 additions and 5 deletions.
  1. +21 −5 java/src/com/yahoo/platform/yuitest/coverage/YUITestCoverage.java
View
26 java/src/com/yahoo/platform/yuitest/coverage/YUITestCoverage.java
@@ -33,6 +33,8 @@ public static void main(String args[]) {
CmdLineParser.Option outputLocationOpt = parser.addStringOption('o', "output");
CmdLineParser.Option directoryOpt = parser.addBooleanOption('d', "dir");
CmdLineParser.Option excludeOpt = parser.addStringOption('x', "exclude");
+ CmdLineParser.Option stdinOpt = parser.addBooleanOption("stdin");
+ CmdLineParser.Option coverFileNameOpt = parser.addStringOption("cover-name");
Reader in = null;
Writer out = null;
@@ -51,6 +53,11 @@ public static void main(String args[]) {
//Verbose option
boolean verbose = parser.getOptionValue(verboseOpt) != null;
+
+
+ //Use STDIN
+ boolean useStdin = parser.getOptionValue(stdinOpt) != null;
+ String coverFileName = (String) parser.getOptionValue(coverFileNameOpt);
//Charset option
String charset = (String) parser.getOptionValue(charsetOpt);
@@ -68,8 +75,10 @@ public static void main(String args[]) {
String[] fileArgs = parser.getRemainingArgs();
if (fileArgs.length == 0) {
- usage();
- System.exit(1);
+ if (!useStdin) {
+ usage();
+ System.exit(1);
+ }
}
String outputLocation = (String) parser.getOptionValue(outputLocationOpt);
@@ -82,9 +91,14 @@ public static void main(String args[]) {
if (verbose) {
System.err.println("\n[INFO] Preparing to instrument JavaScript file " + fileArgs[0] + ".");
}
-
- in = new InputStreamReader(new FileInputStream(fileArgs[0]), charset);
- JavaScriptInstrumenter instrumenter = new JavaScriptInstrumenter(in, fileArgs[0]);
+
+ if (useStdin) {
+ in = new InputStreamReader(System.in, charset);
+ } else {
+ in = new InputStreamReader(new FileInputStream(fileArgs[0]), charset);
+ }
+ String fileName = (coverFileName != null) ? coverFileName : ((fileArgs.length > 0) ? fileArgs[0] : "<stdin>");
+ JavaScriptInstrumenter instrumenter = new JavaScriptInstrumenter(in, fileName, charset);
out = new OutputStreamWriter(System.out, charset);
instrumenter.instrument(out, verbose);
} else{
@@ -163,6 +177,8 @@ private static void usage() {
+ "Global Options\n"
+ " -h, --help Displays this information.\n"
+ " --charset <charset> Read the input file using <charset>.\n"
+ + " --stdin Read input from stdin"
+ + " --cover-name When intrumenting, use this name instead of the filename (mainly for stdin)"
+ " -d, --dir Input and output (-o) are both directories.\n"
+ " -v, --verbose Display informational messages and warnings.\n"
+ " -o <file|dir> Place the output into <file|dir>. Defaults to stdout.\n\n");

0 comments on commit eaf1f11

Please sign in to comment.
Something went wrong with that request. Please try again.