1
2
3
4
5
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
20
21
22 class JSLintChecker {
23
24
25 private String jslintPath;
26
27
28
29
30
31
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
45
46
47
48
49
50
51
52
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 }