Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/main/java/com/cj/jshintmojo/Mojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public class Mojo extends AbstractMojo {
*/
private String ignoreFile = "";

/**
* @parameter property="customJSHint"
*/
private File customJSHint = null;

/**
* @parameter property="jshint.version"
*/
Expand Down Expand Up @@ -119,13 +124,21 @@ public Mojo(String options, String globals, File basedir, List<String> directori
this.reportFile = reportFile;
this.ignoreFile = ignoreFile;
}

public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("using jshint version " + version);

final String jshintCode = getEmbeddedJshintCode(version);

final JSHint jshint = new JSHint(jshintCode);
public void execute() throws MojoExecutionException, MojoFailureException {
final JSHint jshint;
if (customJSHint == null) {
getLog().info("using jshint version " + version);
final String jshintCode = getEmbeddedJshintCode(version);
jshint = new JSHint(jshintCode);
} else {
getLog().info("using customJSHint " + customJSHint);
try {
jshint = new JSHint(customJSHint);
} catch (IOException e) {
throw new MojoExecutionException("Could not load customJSHint", e);
}
}

final Config config = readConfig(this.options, this.globals, this.configFile, this.basedir, getLog());
if (this.excludes.isEmpty() || (this.ignoreFile != null && !this.ignoreFile.isEmpty())) {
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/com/cj/jshintmojo/jshint/JSHint.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
package com.cj.jshintmojo.jshint;

import com.cj.jshintmojo.util.Rhino;
import java.io.File;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;
import org.mozilla.javascript.EcmaError;
import org.mozilla.javascript.NativeArray;
import java.io.IOException;
import org.mozilla.javascript.NativeObject;

import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.cj.jshintmojo.util.Rhino;
import org.apache.commons.io.FileUtils;

public class JSHint {

private final Rhino rhino;

public JSHint (String jshintCode) {
public JSHint(File customJSHint) throws IOException {
rhino = createRhino(FileUtils.readFileToString(customJSHint, "UTF-8"));
}

public JSHint(String jshintCode) {
rhino = createRhino(resourceAsString(jshintCode));
}

rhino = new Rhino ();
private static Rhino createRhino(final String code) {
Rhino result = new Rhino();
try {
rhino.eval (
result.eval(
"print=function(){};" +
"quit=function(){};" +
"arguments=[];");
"quit=function(){};" +
"arguments=[];");

rhino.eval (commentOutTheShebang (resourceAsString (jshintCode)));
result.eval(commentOutTheShebang(code));
} catch (EcmaError e) {
throw new RuntimeException ("Javascript eval error:" + e.getScriptStackTrace (), e);
throw new RuntimeException("Javascript eval error:" + e.getScriptStackTrace(), e);
}
return result;
}

private String commentOutTheShebang (String code) {
private static String commentOutTheShebang(String code) {
String minusShebang = code.startsWith ("#!") ? "//" + code : code;
return minusShebang;
}
Expand Down