Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-12302] Refactor anonymout class for loading groovy scr…
…ipt into separate class as static block (due to inheritance of outer class from CLICommand) initialization leads to NPE (namely in Jenkins.getInstance Jenkins.getInstance().getPluginManager())
- Loading branch information
Showing
2 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package hudson.cli.util; | ||
|
||
import hudson.AbortException; | ||
import hudson.remoting.Callable; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
/** | ||
* | ||
* @author vjuranek | ||
* | ||
*/ | ||
public class ScriptLoader implements Callable<String,IOException> { | ||
|
||
private final String script; | ||
|
||
public ScriptLoader(String script){ | ||
this.script = script; | ||
} | ||
|
||
public String call() throws IOException { | ||
File f = new File(script); | ||
if(f.exists()) | ||
return FileUtils.readFileToString(f); | ||
|
||
URL url; | ||
try { | ||
url = new URL(script); | ||
} catch (MalformedURLException e) { | ||
throw new AbortException("Unable to find a script "+script); | ||
} | ||
InputStream s = url.openStream(); | ||
try { | ||
return IOUtils.toString(s); | ||
} finally { | ||
s.close(); | ||
} | ||
} | ||
|
||
} |
7bdc179
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, according to all other commands, it would be a good idea if GroovyCommand doesn't implement Serializable anymore, since this is a bit misleading now.
7bdc179
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, thanks for spotting it. Removed in a77011e