View Javadoc
1   package net_alchim31_maven_yuicompressor;
2   
3   import java.io.File;
4   import java.io.FileOutputStream;
5   import java.io.InputStream;
6   
7   import org.codehaus.plexus.util.IOUtil;
8   import org.mozilla.javascript.ErrorReporter;
9   
10  //TODO: use MojoErrorReporter
11  class JSLintChecker {
12      private String jslintPath_;
13  
14      public JSLintChecker() throws Exception {
15          FileOutputStream out = null;
16          InputStream in = null;
17          try {
18              File jslint = File.createTempFile("jslint", ".js");
19              jslint.deleteOnExit();
20              in = getClass().getResourceAsStream("/jslint.js");
21              out = new FileOutputStream(jslint);
22              IOUtil.copy(in, out);
23              jslintPath_ = jslint.getAbsolutePath();
24          } finally {
25              IOUtil.close(in);
26              IOUtil.close(out);
27          }
28      }
29  
30      public void check(File jsFile, ErrorReporter reporter) {
31          String[] args = new String[2];
32          args[0] = jslintPath_;
33          args[1] = jsFile.getAbsolutePath();
34          BasicRhinoShell.exec(args, reporter);
35          //if (Main.exec(args) != 0) {
36          //    reporter.warning("warnings during checking of :" + jsFile.getAbsolutePath(), null, -1, null, -1);
37          //}
38      }
39  }