Skip to content

Commit

Permalink
Added support for stdin processing of coverage files
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Aug 24, 2012
1 parent 910e3c0 commit eaf1f11
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions java/src/com/yahoo/platform/yuitest/coverage/YUITestCoverage.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static void main(String args[]) {
CmdLineParser.Option outputLocationOpt = parser.addStringOption('o', "output"); CmdLineParser.Option outputLocationOpt = parser.addStringOption('o', "output");
CmdLineParser.Option directoryOpt = parser.addBooleanOption('d', "dir"); CmdLineParser.Option directoryOpt = parser.addBooleanOption('d', "dir");
CmdLineParser.Option excludeOpt = parser.addStringOption('x', "exclude"); CmdLineParser.Option excludeOpt = parser.addStringOption('x', "exclude");
CmdLineParser.Option stdinOpt = parser.addBooleanOption("stdin");
CmdLineParser.Option coverFileNameOpt = parser.addStringOption("cover-name");


Reader in = null; Reader in = null;
Writer out = null; Writer out = null;
Expand All @@ -51,6 +53,11 @@ public static void main(String args[]) {


//Verbose option //Verbose option
boolean verbose = parser.getOptionValue(verboseOpt) != null; boolean verbose = parser.getOptionValue(verboseOpt) != null;


//Use STDIN
boolean useStdin = parser.getOptionValue(stdinOpt) != null;
String coverFileName = (String) parser.getOptionValue(coverFileNameOpt);


//Charset option //Charset option
String charset = (String) parser.getOptionValue(charsetOpt); String charset = (String) parser.getOptionValue(charsetOpt);
Expand All @@ -68,8 +75,10 @@ public static void main(String args[]) {
String[] fileArgs = parser.getRemainingArgs(); String[] fileArgs = parser.getRemainingArgs();


if (fileArgs.length == 0) { if (fileArgs.length == 0) {
usage(); if (!useStdin) {
System.exit(1); usage();
System.exit(1);
}
} }


String outputLocation = (String) parser.getOptionValue(outputLocationOpt); String outputLocation = (String) parser.getOptionValue(outputLocationOpt);
Expand All @@ -82,9 +91,14 @@ public static void main(String args[]) {
if (verbose) { if (verbose) {
System.err.println("\n[INFO] Preparing to instrument JavaScript file " + fileArgs[0] + "."); System.err.println("\n[INFO] Preparing to instrument JavaScript file " + fileArgs[0] + ".");
} }


in = new InputStreamReader(new FileInputStream(fileArgs[0]), charset); if (useStdin) {
JavaScriptInstrumenter instrumenter = new JavaScriptInstrumenter(in, fileArgs[0]); 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); out = new OutputStreamWriter(System.out, charset);
instrumenter.instrument(out, verbose); instrumenter.instrument(out, verbose);
} else{ } else{
Expand Down Expand Up @@ -163,6 +177,8 @@ private static void usage() {
+ "Global Options\n" + "Global Options\n"
+ " -h, --help Displays this information.\n" + " -h, --help Displays this information.\n"
+ " --charset <charset> Read the input file using <charset>.\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" + " -d, --dir Input and output (-o) are both directories.\n"
+ " -v, --verbose Display informational messages and warnings.\n" + " -v, --verbose Display informational messages and warnings.\n"
+ " -o <file|dir> Place the output into <file|dir>. Defaults to stdout.\n\n"); + " -o <file|dir> Place the output into <file|dir>. Defaults to stdout.\n\n");
Expand Down

0 comments on commit eaf1f11

Please sign in to comment.