Permalink
Browse files

Applied a patch that adds support for wildcard input and output file

filter spec so that a single process can process multiple
files [fixes #1872317].
  • Loading branch information...
1 parent 87d7e4b commit b73265b5f1b53c2d5669a61ba9e918003b10e80f Adam Moore committed May 11, 2010
View
@@ -3,6 +3,6 @@ lib.dir = lib
doc.dir = doc
build.dir = build
product.name = yuicompressor
-version.number = 2.4.3
+version.number = 2.4.4
jar.name = ${product.name}-${version.number}.jar
dist.package.name = ${product.name}-${version.number}
View
@@ -1,13 +1,20 @@
-YUI Compressor 2.4.2, 2008-11-10
---------------------------------
-
-+ Preserved comments shouldn't prevent obfuscation (Thanks to Matjaz Lipus)
+YUI Compressor 2.4.4, 2010-11-05
+-------------------------------
++ Default file encoding changed from system default to UTF-8.
++ Errors/messages/usage info all are sent to stderr.
++ Removed unnecessary warning about short undeclared global symbols.
++ Added support for processing multiple files with a single invokation
YUI Compressor 2.4.3, 2009-12-07
-------------------------------
-
+ Changed custodian to ci-tools@
+
+YUI Compressor 2.4.2, 2008-11-10
+--------------------------------
++ Preserved comments shouldn't prevent obfuscation (Thanks to Matjaz Lipus)
+
+
YUI Compressor 2.4.1, 2008-10-28
--------------------------------
View
@@ -16,7 +16,8 @@ SYNOPSIS
--charset <charset> Read the input file using <charset>
--line-break <column> Insert a line break after the specified column number
-v, --verbose Display informational messages and warnings
- -o <file> Place the output into <file>. Defaults to stdout.
+ -o <file> Place the output into <file> or a file pattern.
+ Defaults to stdout.
JavaScript Options
--nomunge Minify only, do not obfuscate
@@ -60,8 +61,13 @@ GLOBAL OPTIONS
the same character set.
-o outfile
+
Place output in file outfile. If not specified, the YUI Compressor will
default to the standard output, which you can redirect to a file.
+ Supports a filter syntax for expressing the output pattern when there are
+ multiple input files. ex:
+ java -jar yuicompressor.jar -o '.css$:-min.css' *.css
+ ... will minify all .css files and save them as -min.css
-v, --verbose
Display informational messages and warnings.
@@ -83,6 +89,8 @@ NOTES
+ If no input file is specified, it defaults to stdin.
+ + Supports wildcards for specifying multiple input files.
+
+ The YUI Compressor requires Java version >= 1.4.
+ It is possible to prevent a local variable, nested function or function
@@ -130,15 +138,8 @@ MODIFIED RHINO FILES
characters in regular expressions, and to allow for the optimization
of escaped quotes in string literals.
-AUTHOR
-
- The YUI Compressor was written and is maintained by:
- Julien Lecomte - http://www.julienlecomte.net/
-
- The CSS portion is a port of Isaac Schlueter's cssmin utility.
-
COPYRIGHT AND LICENSE
- Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+ Copyright (c) 2010 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed
by Yahoo! Inc. under the BSD (revised) open source license.
@@ -870,7 +870,15 @@ private void parseExpression() {
// We don't need to declare longer symbols since they won't cause
// any conflict with other munged symbols.
globalScope.declareIdentifier(symbol);
- warn("Found an undeclared symbol: " + symbol, true);
+
+ // I removed the warning since was only being done when
+ // for identifiers 3 chars or less, and was just causing
+ // noise for people who happen to rely on an externally
+ // declared variable that happen to be that short. We either
+ // should always warn or never warn -- the fact that we
+ // declare the short symbols in the global space doesn't
+ // change anything.
+ // warn("Found an undeclared symbol: " + symbol, true);
}
} else {
@@ -61,42 +61,6 @@ public static void main(String args[]) {
}
}
- String[] fileArgs = parser.getRemainingArgs();
- String type = (String) parser.getOptionValue(typeOpt);
-
- if (fileArgs.length == 0) {
-
- if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
- usage();
- System.exit(1);
- }
-
- in = new InputStreamReader(System.in, charset);
-
- } else {
-
- if (type != null && !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
- usage();
- System.exit(1);
- }
-
- String inputFilename = fileArgs[0];
-
- if (type == null) {
- int idx = inputFilename.lastIndexOf('.');
- if (idx >= 0 && idx < inputFilename.length() - 1) {
- type = inputFilename.substring(idx + 1);
- }
- }
-
- if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
- usage();
- System.exit(1);
- }
-
- in = new InputStreamReader(new FileInputStream(inputFilename), charset);
- }
-
int linebreakpos = -1;
String linebreakstr = (String) parser.getOptionValue(linebreakOpt);
if (linebreakstr != null) {
@@ -108,108 +72,155 @@ public static void main(String args[]) {
}
}
- String outputFilename = (String) parser.getOptionValue(outputFilenameOpt);
+ String type = (String) parser.getOptionValue(typeOpt);
+ if (type != null && !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
+ usage();
+ System.exit(1);
+ }
- if (type.equalsIgnoreCase("js")) {
+ String[] fileArgs = parser.getRemainingArgs();
+ java.util.List files = java.util.Arrays.asList(fileArgs);
+ if (files.isEmpty()) {
+ files = new java.util.ArrayList();
+ files.add("-"); // read from stdin
+ }
+
+ String output = (String) parser.getOptionValue(outputFilenameOpt);
+ String pattern[] = output != null ? output.split(":") : new String[0];
+
+ java.util.Iterator filenames = files.iterator();
+ while(filenames.hasNext()) {
+ String inputFilename = (String)filenames.next();
try {
+ if (inputFilename.equals("-")) {
- JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
+ in = new InputStreamReader(System.in, charset);
- 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);
- }
- }
+ } else {
- 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);
+ if (type == null) {
+ int idx = inputFilename.lastIndexOf('.');
+ if (idx >= 0 && idx < inputFilename.length() - 1) {
+ type = inputFilename.substring(idx + 1);
}
}
- public EvaluatorException runtimeError(String message, String sourceName,
- int line, String lineSource, int lineOffset) {
- error(message, sourceName, line, lineSource, lineOffset);
- return new EvaluatorException(message);
+ if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
+ usage();
+ System.exit(1);
}
- });
- // Close the input stream first, and then open the output stream,
- // in case the output file should override the input file.
- in.close(); in = null;
+ in = new InputStreamReader(new FileInputStream(inputFilename), charset);
+ }
- if (outputFilename == null) {
- out = new OutputStreamWriter(System.out, charset);
- } else {
- out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
+ String outputFilename = output;
+ // if a substitution pattern was passed in
+ if (pattern.length > 1 && files.size() > 1) {
+ outputFilename = inputFilename.replaceFirst(pattern[0], pattern[1]);
}
- boolean munge = parser.getOptionValue(nomungeOpt) == null;
- boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
- boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;
+ if (type.equalsIgnoreCase("js")) {
+
+ try {
+
+ 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 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);
+ }
+ });
+
+ // Close the input stream first, and then open the output stream,
+ // in case the output file should override the input file.
+ in.close(); in = null;
+
+ if (outputFilename == null) {
+ out = new OutputStreamWriter(System.out, charset);
+ } else {
+ out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
+ }
- compressor.compress(out, linebreakpos, munge, verbose,
- preserveAllSemiColons, disableOptimizations);
+ boolean munge = parser.getOptionValue(nomungeOpt) == null;
+ boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
+ boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;
- } catch (EvaluatorException e) {
+ compressor.compress(out, linebreakpos, munge, verbose,
+ preserveAllSemiColons, disableOptimizations);
- e.printStackTrace();
- // Return a special error code used specifically by the web front-end.
- System.exit(2);
+ } catch (EvaluatorException e) {
- }
+ e.printStackTrace();
+ // Return a special error code used specifically by the web front-end.
+ System.exit(2);
- } else if (type.equalsIgnoreCase("css")) {
+ }
- CssCompressor compressor = new CssCompressor(in);
+ } else if (type.equalsIgnoreCase("css")) {
- // Close the input stream first, and then open the output stream,
- // in case the output file should override the input file.
- in.close(); in = null;
+ CssCompressor compressor = new CssCompressor(in);
- if (outputFilename == null) {
- out = new OutputStreamWriter(System.out, charset);
- } else {
- out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
- }
+ // Close the input stream first, and then open the output stream,
+ // in case the output file should override the input file.
+ in.close(); in = null;
- compressor.compress(out, linebreakpos);
- }
+ if (outputFilename == null) {
+ out = new OutputStreamWriter(System.out, charset);
+ } else {
+ out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
+ }
- } catch (CmdLineParser.OptionException e) {
+ compressor.compress(out, linebreakpos);
+ }
- usage();
- System.exit(1);
+ } catch (IOException e) {
- } catch (IOException e) {
+ e.printStackTrace();
+ System.exit(1);
- e.printStackTrace();
- System.exit(1);
+ } finally {
- } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
+ } catch (CmdLineParser.OptionException e) {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ usage();
+ System.exit(1);
}
}
@@ -223,7 +234,10 @@ private static void usage() {
+ " --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\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"
+ " --nomunge Minify only, do not obfuscate\n"

0 comments on commit b73265b

Please sign in to comment.