Search in sources :

Example 1 with UnicodeBomInputStream

use of com.googlecode.jslint4java.UnicodeBomInputStream in project jslint4java by happygiraffe.

the class JSLintTask method lintStream.

/**
     * Lint a given stream. Closes the stream after use.
     *
     * @param lint
     *
     * @throws IOException
     */
private int lintStream(JSLint lint, Resource resource) throws UnsupportedEncodingException, IOException {
    BufferedReader reader = null;
    try {
        UnicodeBomInputStream stream = new UnicodeBomInputStream(resource.getInputStream());
        stream.skipBOM();
        reader = new BufferedReader(new InputStreamReader(stream, encoding));
        String name = resource.toString();
        JSLintResult result = lint.lint(name, reader);
        log("Found " + result.getIssues().size() + " issues in " + name, Project.MSG_VERBOSE);
        for (ResultFormatter rf : formatters) {
            rf.output(result);
        }
        return result.getIssues().size();
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnicodeBomInputStream(com.googlecode.jslint4java.UnicodeBomInputStream) BufferedReader(java.io.BufferedReader) JSLintResult(com.googlecode.jslint4java.JSLintResult)

Example 2 with UnicodeBomInputStream

use of com.googlecode.jslint4java.UnicodeBomInputStream in project jslint4java by happygiraffe.

the class JSLintMojo method lintFile.

private JSLintResult lintFile(JSLint jsLint, File file) throws MojoExecutionException {
    getLog().debug("lint " + file);
    BufferedReader reader = null;
    try {
        UnicodeBomInputStream stream = new UnicodeBomInputStream(new FileInputStream(file));
        stream.skipBOM();
        reader = new BufferedReader(new InputStreamReader(stream, getEncoding()));
        return jsLint.lint(file.toString(), reader);
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("file not found: " + file, e);
    } catch (UnsupportedEncodingException e) {
        // Can never happen.
        throw new MojoExecutionException("unsupported character encoding UTF-8", e);
    } catch (IOException e) {
        throw new MojoExecutionException("problem whilst linting " + file, e);
    } finally {
        Closeables.closeQuietly(reader);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UnicodeBomInputStream(com.googlecode.jslint4java.UnicodeBomInputStream) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

UnicodeBomInputStream (com.googlecode.jslint4java.UnicodeBomInputStream)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 JSLintResult (com.googlecode.jslint4java.JSLintResult)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1