com.googlecode.jslint4java.ant.JSLintTask Maven / Gradle / Ivy
package com.googlecode.jslint4java.ant;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Union;
import com.googlecode.jslint4java.JSLint;
import com.googlecode.jslint4java.JSLintBuilder;
import com.googlecode.jslint4java.JSLintResult;
import com.googlecode.jslint4java.Option;
import com.googlecode.jslint4java.UnicodeBomInputStream;
/**
* Run {@link JSLint} over a tree of files in order to pick holes in your
* JavaScript.
*
*
* Example build.xml usage:
*
*
* <project name="build-test" xmlns:jsl="antlib:com.googlecode.jslint4java">
* <target name="jslint">
* <jsl:jslint options="undef">
* <formatter type="plain" />
* <fileset dir="." includes="*.js" excludes="*.pack.js" />
* </jsl:jslint>
* </target>
* </project
*
*
*
* You have to specify one or more nested fileset elements. You may
* optionally specify a formatter element in order to generate output (as
* opposed to just a build failed message). Usually, you will want the plain
* formatter, but in case you want to generate a report, the xml formatter
* mighht be useful.
*
*
Attributes
*
*
* encoding
* - Optional. The encoding of the JavaScript files. Defaults to system
* encoding.
* haltOnFailure
* - Optional. Specify if the build should fail if there are files which do
* not pass JSLint. Defaults to true.
* options
* - Optional. A comma separated list of {@link Option} names. No default.
* timeout
* - Optional. The maximum amount of time that JSLint can run.
*
*
* @author dom
* @see jslint.com< /a>
* @see FormatterElement
*/
public class JSLintTask extends Task {
private static final String NO_FILES_TO_LINT = "no files to lint!";
private final Union resources = new Union();
private final List formatters = new ArrayList();
private boolean haltOnFailure = true;
private String encoding = System.getProperty("file.encoding", "UTF-8");
private String failureProperty = null;
private File jslintSource = null;
private final Map