-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This change causes the command-line checker to emit its “other” output (usage message and “verbose” messages and failure messages) to stderr rather than stdout (in order to ensure that the only output going to stdout are the checker errors and warnings).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import java.io.InputStreamReader; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
import java.util.jar.Manifest; | ||
|
@@ -66,6 +67,8 @@ public class SimpleCommandLineValidator { | |
|
||
private static OutputStream out; | ||
|
||
private static PrintStream otherOut; | ||
|
||
private static Pattern filterPattern; | ||
|
||
private static MessageEmitterAdapter errorHandler; | ||
|
@@ -128,6 +131,7 @@ public static void main(String[] args) throws SAXException, Exception { | |
} | ||
} | ||
out = System.err; | ||
otherOut = System.out; | ||
userAgent = "Validator.nu/LV"; | ||
System.setProperty("nu.validator.datatype.warn", "true"); | ||
errorsOnly = false; | ||
|
@@ -226,9 +230,9 @@ public static void main(String[] args) throws SAXException, Exception { | |
userAgent = args[++i]; | ||
} else if ("--version".equals(args[i])) { | ||
if (version != null) { | ||
System.out.println(version); | ||
otherOut.println(version); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sideshowbarker
Author
Contributor
|
||
} else { | ||
System.out.println("[unknown version]"); | ||
otherOut.println("[unknown version]"); | ||
} | ||
System.exit(0); | ||
} else if ("--help".equals(args[i])) { | ||
|
@@ -269,6 +273,7 @@ public static void main(String[] args) throws SAXException, Exception { | |
} | ||
if (reportMessagesToStdOut) { | ||
out = System.out; | ||
otherOut = System.err; | ||
} | ||
if (!"".equals(filterString)) { | ||
filterPattern = Pattern.compile(filterString); | ||
|
@@ -331,16 +336,16 @@ private static void setSchema(String schemaUrl) | |
try { | ||
validator.setUpMainSchema(schemaUrl, new SystemErrErrorHandler()); | ||
} catch (SchemaReadException e) { | ||
System.out.println(e.getMessage() + " Terminating."); | ||
otherOut.println(e.getMessage() + " Terminating."); | ||
This comment has been minimized.
Sorry, something went wrong.
mhansen
Contributor
|
||
System.exit(1); | ||
} catch (StackOverflowError e) { | ||
System.out.println("StackOverflowError" | ||
otherOut.println("StackOverflowError" | ||
+ " while evaluating HTML schema."); | ||
System.out.println("The checker requires a java thread stack size" | ||
otherOut.println("The checker requires a java thread stack size" | ||
+ " of at least 512k."); | ||
System.out.println("Consider invoking java with the -Xss" | ||
otherOut.println("Consider invoking java with the -Xss" | ||
+ " option. For example:"); | ||
System.out.println("\n java -Xss512k -jar ~/vnu.jar FILE.html"); | ||
otherOut.println("\n java -Xss512k -jar ~/vnu.jar FILE.html"); | ||
System.exit(1); | ||
} | ||
validator.setUpValidatorAndParsers(errorHandler, noStream, loadEntities); | ||
|
@@ -561,7 +566,7 @@ private static boolean isHtml(File file) { | |
|
||
private static void emitFilename(String name) { | ||
if (verbose) { | ||
System.out.println(name); | ||
otherOut.println(name); | ||
} | ||
} | ||
|
||
|
@@ -595,49 +600,49 @@ private static void setErrorHandler() { | |
} | ||
|
||
private static void usage() { | ||
System.out.println("Usage:"); | ||
System.out.println(""); | ||
System.out.println(" vnu-runtime-image/bin/vnu OPTIONS FILES (Linux or macOS)"); | ||
System.out.println(" vnu-runtime-image\\bin\\vnu.bat OPTIONS FILES (Windows)"); | ||
System.out.println(" java -jar ~/vnu.jar OPTIONS FILES (any system with Java8+ installed)"); | ||
System.out.println(""); | ||
System.out.println("...where FILES are the documents to check, and OPTIONS are zero or more of:"); | ||
System.out.println(""); | ||
System.out.println(" --errors-only --Werror --exit-zero-always --stdout --asciiquotes"); | ||
System.out.println(" --user-agent USER_AGENT --no-langdetect --no-stream --filterfile FILENAME"); | ||
System.out.println(" --filterpattern PATTERN --css --skip-non-css --also-check-css --svg"); | ||
System.out.println(" --skip-non-svg --also-check-svg --html --skip-non-html"); | ||
System.out.println(" --format gnu|xml|json|text --help --verbose --version"); | ||
System.out.println(""); | ||
System.out.println("For detailed usage information, try the \"--help\" option or see:"); | ||
System.out.println(""); | ||
System.out.println(" http://validator.github.io/"); | ||
System.out.println(""); | ||
System.out.println("To read from stdin, use \"-\" as the filename, like this: \"java -jar vnu.jar - \"."); | ||
System.out.println(""); | ||
System.out.println("To run the checker as a standalone Web-based service, open a new terminal"); | ||
System.out.println("window and invoke the checker like this"); | ||
System.out.println(""); | ||
System.out.println(" java -cp vnu.jar nu.validator.servlet.Main 8888"); | ||
System.out.println(" vnu-runtime-image/bin/java nu.validator.servlet.Main 8888"); | ||
System.out.println(" vnu-runtime-image\\bin\\java -cp vnu.jar nu.validator.servlet.Main 8888"); | ||
System.out.println(""); | ||
System.out.println("...then open http://127.0.0.1:8888 in a browser."); | ||
System.out.println(""); | ||
System.out.println("After that, to check documents locally using the packaged HTTP client, do this:"); | ||
System.out.println(""); | ||
System.out.println(" java -cp vnu.jar nu.validator.client.HttpClient FILES"); | ||
System.out.println(" vnu-runtime-image/bin/java nu.validator.client.HttpClient FILES"); | ||
System.out.println(" vnu-runtime-image\\bin\\java nu.validator.client.HttpClient FILES"); | ||
System.out.println(""); | ||
otherOut.println("Usage:"); | ||
otherOut.println(""); | ||
otherOut.println(" vnu-runtime-image/bin/vnu OPTIONS FILES (Linux or macOS)"); | ||
otherOut.println(" vnu-runtime-image\\bin\\vnu.bat OPTIONS FILES (Windows)"); | ||
otherOut.println(" java -jar ~/vnu.jar OPTIONS FILES (any system with Java8+ installed)"); | ||
otherOut.println(""); | ||
otherOut.println("...where FILES are the documents to check, and OPTIONS are zero or more of:"); | ||
otherOut.println(""); | ||
otherOut.println(" --errors-only --Werror --exit-zero-always --stdout --asciiquotes"); | ||
otherOut.println(" --user-agent USER_AGENT --no-langdetect --no-stream --filterfile FILENAME"); | ||
otherOut.println(" --filterpattern PATTERN --css --skip-non-css --also-check-css --svg"); | ||
otherOut.println(" --skip-non-svg --also-check-svg --html --skip-non-html"); | ||
otherOut.println(" --format gnu|xml|json|text --help --verbose --version"); | ||
otherOut.println(""); | ||
otherOut.println("For detailed usage information, try the \"--help\" option or see:"); | ||
otherOut.println(""); | ||
otherOut.println(" http://validator.github.io/"); | ||
otherOut.println(""); | ||
otherOut.println("To read from stdin, use \"-\" as the filename, like this: \"java -jar vnu.jar - \"."); | ||
otherOut.println(""); | ||
otherOut.println("To run the checker as a standalone Web-based service, open a new terminal"); | ||
otherOut.println("window and invoke the checker like this"); | ||
otherOut.println(""); | ||
otherOut.println(" java -cp vnu.jar nu.validator.servlet.Main 8888"); | ||
otherOut.println(" vnu-runtime-image/bin/java nu.validator.servlet.Main 8888"); | ||
otherOut.println(" vnu-runtime-image\\bin\\java -cp vnu.jar nu.validator.servlet.Main 8888"); | ||
otherOut.println(""); | ||
otherOut.println("...then open http://127.0.0.1:8888 in a browser."); | ||
otherOut.println(""); | ||
otherOut.println("After that, to check documents locally using the packaged HTTP client, do this:"); | ||
otherOut.println(""); | ||
otherOut.println(" java -cp vnu.jar nu.validator.client.HttpClient FILES"); | ||
otherOut.println(" vnu-runtime-image/bin/java nu.validator.client.HttpClient FILES"); | ||
otherOut.println(" vnu-runtime-image\\bin\\java nu.validator.client.HttpClient FILES"); | ||
otherOut.println(""); | ||
} | ||
|
||
private static void help() { | ||
try (InputStream help = SimpleCommandLineValidator.class.getClassLoader().getResourceAsStream( | ||
"nu/validator/localentities/files/cli-help")) { | ||
System.out.println(""); | ||
otherOut.println(""); | ||
for (int b = help.read(); b != -1; b = help.read()) { | ||
System.out.write(b); | ||
otherOut.write(b); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
|
My 2c: I think version should always go to stderr (I just want stdout for the structured output / json/xml/gnu/text HTML warnings). This one I'm less worried about than I am about java exceptions though.