Skip to content

Commit

Permalink
Fix boxuk#8 (unable to read resource)
Browse files Browse the repository at this point in the history
See boxuk#8
The 'fix' that had been put in to make it on Windows worked with older
versions of Jenkins, but as of 1.519, it errored. I don't know if this
breaks things for Windows, but at least it'll fix it for Linux.
  • Loading branch information
Gavin Davies committed Jul 15, 2013
1 parent 949829e commit 40c3edd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.474</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.523</version><!-- which version of Jenkins is this plugin built against? -->
</parent>

<developers>
Expand All @@ -16,7 +16,7 @@
<url>https://wiki.jenkins-ci.org/display/JENKINS/JSLint+plugin</url>

<artifactId>jslint</artifactId>
<version>0.8.1-SNAPSHOT</version>
<version>0.8.1</version>
<packaging>hpi</packaging>

<name>Box UK - JSLint</name>
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/boxuk/jenkins/jslint/LintRunner.java
Expand Up @@ -4,9 +4,7 @@
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.remoting.Callable;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -15,6 +13,10 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import jenkins.model.Jenkins;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* Class that actually runs the linting. Because it is callable, it is safe
Expand Down Expand Up @@ -108,20 +110,30 @@ public Properties call() {
try {
file = URLDecoder.decode(res.toString(), "UTF-8");
} catch(java.io.UnsupportedEncodingException ex) {
file = URLDecoder.decode(res.toString());
listener.getLogger().println("[JSLint] Unable to decode using UTF-8: " + ex.toString());
file = URLDecoder.decode(res.toString());
}
// Breaks on Windows without this
file = file.replaceAll("file:", "");
// BUT!! breaks on EVERYTHING with it since circa Jenkins 1.519
// file = file.replaceAll("file:", "");
listener.getLogger().println("[JSLint] JSLint path is " + file);

try {
URL url = new URL(file);
InputStream inputStream = url.openStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);

context.evaluateReader(
scope,
new FileReader(new File(file)), "jslint.js", 0, null
inputStreamReader,
"jslint.js",
0,
null
);
} catch (IOException ex) {
listener.getLogger().println("[JSLint] IO Error " + ex.toString());
} catch (IOException e) {
e.printStackTrace();
}

} finally {
// Exit from the context.
Context.exit();
Expand Down

0 comments on commit 40c3edd

Please sign in to comment.