Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

batch processing

  • Loading branch information...
commit 02086b07ae822f9b7a05a09c7130b26dcfdd6df3 1 parent 4c54e62
@bierbaum authored
Showing with 63 additions and 38 deletions.
  1. +63 −38 src/com/yahoo/platform/yui/compressor/YUICompressor.java
View
101 src/com/yahoo/platform/yui/compressor/YUICompressor.java
@@ -16,9 +16,7 @@
import java.nio.charset.Charset;
public class YUICompressor {
-
- public static void main(String args[]) {
-
+ private static void process(String[] args) {
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option typeOpt = parser.addStringOption("type");
CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
@@ -130,30 +128,30 @@ public static void main(String args[]) {
JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
- public void warning(String message, String sourceName,
- int line, String lineSource, int lineOffset) {
- if (line < 0) {
- System.err.println("\n[WARNING] " + message);
- } else {
- System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
+ public void warning(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ if (line < 0) {
+ System.err.println("\n[WARNING] " + message);
+ } else {
+ System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
+ }
}
- }
-
- public void error(String message, String sourceName,
- int line, String lineSource, int lineOffset) {
- if (line < 0) {
- System.err.println("\n[ERROR] " + message);
- } else {
- System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
+
+ public void error(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ if (line < 0) {
+ System.err.println("\n[ERROR] " + message);
+ } else {
+ System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
+ }
}
- }
- public EvaluatorException runtimeError(String message, String sourceName,
- int line, String lineSource, int lineOffset) {
- error(message, sourceName, line, lineSource, lineOffset);
- return new EvaluatorException(message);
- }
- });
+ public EvaluatorException runtimeError(String message, String sourceName,
+ int line, String lineSource, int lineOffset) {
+ error(message, sourceName, line, lineSource, lineOffset);
+ return new EvaluatorException(message);
+ }
+ });
// Close the input stream first, and then open the output stream,
// in case the output file should override the input file.
@@ -170,7 +168,7 @@ public EvaluatorException runtimeError(String message, String sourceName,
boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;
compressor.compress(out, linebreakpos, munge, verbose,
- preserveAllSemiColons, disableOptimizations);
+ preserveAllSemiColons, disableOptimizations);
} catch (EvaluatorException e) {
@@ -228,19 +226,46 @@ public EvaluatorException runtimeError(String message, String sourceName,
}
}
- private static void usage() {
- System.err.println(
- "\nUsage: java -jar yuicompressor-2.4.6.jar [options] [input file]\n\n"
-
- + "Global Options\n"
- + " -h, --help Displays this information\n"
- + " --type <js|css> Specifies the type of the input file\n"
- + " --charset <charset> Read the input file using <charset>\n"
- + " --line-break <column> Insert a line break after the specified column number\n"
- + " -v, --verbose Display informational messages and warnings\n"
- + " -o <file> Place the output into <file>. Defaults to stdout.\n"
- + " Multiple files can be processed using the following syntax:\n"
- + " java -jar yuicompressor.jar -o '.css$:-min.css' *.css\n"
+ public static void main(String args[]) {
+ if (args.length > 0 && args[0].equalsIgnoreCase("--batch")) {
+ try {
+ if (args.length != 2)
+ throw new Exception("Wrong number of arguments for batch mode.");
+
+ BufferedReader in = new BufferedReader(new FileReader(args[1]));
+ int lineNumber = 1;
+ for (String line; (line = in.readLine()) != null; ++lineNumber) {
+ String lineargs[] = line.split(" ");
+ if (lineargs[0] != null && lineargs[0].length() > 0) {
+ System.err.println("[INFO] Processing " + args[1] + ":" + lineNumber + "': " + line + "'");
+ process(lineargs);
+ }
+ }
+ in.close();
+ } catch (Exception e) {
+ System.err.println("Batch invocation failed: " + e.getMessage());
+ e.printStackTrace();
+ }
+ } else {
+ process(args);
+ }
+ }
+
+ private static void usage() {
+ System.err.println(
+ "\nUsage: java -jar yuicompressor-2.4.6.jar [options] [input file]\n\n"
+
+ + "Global Options\n"
+ + " --batch <filename> Invoke in batch mode, processing each line as though it were a separate invocation.\n"
+
+ + " -h, --help Displays this information\n"
+ + " --type <js|css> Specifies the type of the input file\n"
+ + " --charset <charset> Read the input file using <charset>\n"
+ + " --line-break <column> Insert a line break after the specified column number\n"
+ + " -v, --verbose Display informational messages and warnings\n"
+ + " -o <file> Place the output into <file>. Defaults to stdout.\n"
+ + " Multiple files can be processed using the following syntax:\n"
+ + " java -jar yuicompressor.jar -o '.css$:-min.css' *.css\n"
+ " java -jar yuicompressor.jar -o '.js$:-min.js' *.js\n\n"
+ "JavaScript Options\n"
Please sign in to comment.
Something went wrong with that request. Please try again.