views:

270

answers:

1

I am building a build script for our web development team. We will be using this script to prepare all our front-end code for production. I am using the YUI Compressor to compress our CSS and JavaScript files. Everything works fine for the CSS portion but I am running into an issue the JavaScriptCompressor class instance.

I am importing the YUI files via this line:

import com.yahoo.platform.yui.compressor.*;

Here is my JavaScriptCompressor instance:

FileReader ftcreader = new FileReader(ftc);
JavaScriptCompressor js = new JavaScriptCompressor(ftcreader);

For reference, here is how I am using the CssCompressor class,which works properly:

FileReader ftcreader = new FileReader(ftc);
CssCompressor css = new CssCompressor(ftcreader);

For some reason, I am getting an error for the JavaScriptCompressor class, stating:

The constructor JavaScriptCompressor(FileReader) is undefined

Am I importing the YUI Compressor files incorrectly? Or is it something else? Any help would be greatly appreciated.

+1  A: 

you are missing ErrorReporter, the second argument of constructor:

    JavaScriptCompressor compressor = 
      new JavaScriptCompressor(in, new SystemOutErrorReporter());
    compressor.compress(out, 1 << 20, false, false, false, false);

then a sample ErrorReporter:

class SystemOutErrorReporter implements ErrorReporter {

    private String format(String arg0, String arg1, int arg2, String arg3, int arg4) {
        return String.format("%s%s at line %d, column %d:\n%s",
            arg0,
            arg1 == null ? "" : ":" + arg1,
            arg2,
            arg4,
            arg3);
    }

    @Override
    public void warning(String arg0, String arg1, int arg2, String arg3, int arg4) {
        System.out.println("WARNING: " + format(arg0, arg1, arg2, arg3, arg4));
    }

    @Override
    public void error(String arg0, String arg1, int arg2, String arg3, int arg4) {
        System.out.println("ERROR: " + format(arg0, arg1, arg2, arg3, arg4));
    }

    @Override
    public EvaluatorException runtimeError(String arg0, String arg1, int arg2, String arg3, int arg4) {
        System.out.println("RUNTIME ERROR: " + format(arg0, arg1, arg2, arg3, arg4));
        return new EvaluatorException(arg0);
    }
}
dfa