View Javadoc
1   /*
2    * SPDX-License-Identifier: LGPL-2.1-or-later
3    * See LICENSE file for details.
4    *
5    * Copyright 2012-2026 Hazendaz.
6    */
7   package net.alchim31.maven.yuicompressor;
8   
9   import java.io.File;
10  import java.io.IOException;
11  import java.io.InputStream;
12  import java.io.OutputStream;
13  import java.nio.file.Files;
14  
15  import org.codehaus.plexus.util.IOUtil;
16  import org.mozilla.javascript.ErrorReporter;
17  
18  /**
19   * The Class JSLintChecker.
20   */
21  // TODO: use MojoErrorReporter
22  class JSLintChecker {
23  
24      /** The jslint path. */
25      private String jslintPath;
26  
27      /**
28       * Instantiates a new JS lint checker.
29       *
30       * @throws IOException
31       *             the IO exception
32       */
33      public JSLintChecker() throws IOException {
34          File jslint = File.createTempFile("jslint", ".js");
35          jslint.deleteOnExit();
36          try (InputStream in = getClass().getResourceAsStream("/jslint.js");
37                  OutputStream out = Files.newOutputStream(jslint.toPath())) {
38              IOUtil.copy(in, out);
39          }
40          jslintPath = jslint.getCanonicalPath();
41      }
42  
43      /**
44       * Check.
45       *
46       * @param jsFile
47       *            the js file
48       * @param reporter
49       *            the reporter
50       *
51       * @throws IOException
52       *             the IO exception
53       */
54      public void check(File jsFile, ErrorReporter reporter) throws IOException {
55          String[] args = new String[2];
56          args[0] = jslintPath;
57          args[1] = jsFile.getCanonicalPath();
58          BasicRhinoShell.exec(args, reporter);
59      }
60  }