1 /*
2 * YuiCompressor Maven plugin
3 *
4 * Copyright 2012-2025 Hazendaz.
5 *
6 * Licensed under the GNU Lesser General Public License (LGPL),
7 * version 2.1 or later (the "License").
8 * You may not use this file except in compliance with the License.
9 * You may read the licence in the 'lgpl.txt' file in the root folder of
10 * project or obtain a copy at
11 *
12 * https://www.gnu.org/licenses/lgpl-2.1.html
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" basis,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package net.alchim31.maven.yuicompressor;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.nio.file.Files;
27
28 import org.codehaus.plexus.util.IOUtil;
29 import org.mozilla.javascript.ErrorReporter;
30
31 /**
32 * The Class JSLintChecker.
33 */
34 // TODO: use MojoErrorReporter
35 class JSLintChecker {
36
37 /** The jslint path. */
38 private String jslintPath;
39
40 /**
41 * Instantiates a new JS lint checker.
42 *
43 * @throws IOException
44 * the IO exception
45 */
46 public JSLintChecker() throws IOException {
47 File jslint = File.createTempFile("jslint", ".js");
48 jslint.deleteOnExit();
49 try (InputStream in = getClass().getResourceAsStream("/jslint.js");
50 OutputStream out = Files.newOutputStream(jslint.toPath())) {
51 IOUtil.copy(in, out);
52 }
53 jslintPath = jslint.getCanonicalPath();
54 }
55
56 /**
57 * Check.
58 *
59 * @param jsFile
60 * the js file
61 * @param reporter
62 * the reporter
63 *
64 * @throws IOException
65 * the IO exception
66 */
67 public void check(File jsFile, ErrorReporter reporter) throws IOException {
68 String[] args = new String[2];
69 args[0] = jslintPath;
70 args[1] = jsFile.getCanonicalPath();
71 BasicRhinoShell.exec(args, reporter);
72 }
73 }