File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\cli\util\ScriptLoader.java.html

1 package hudson.cli.util;
2
3 import hudson.AbortException;
4 import hudson.remoting.Callable;
5
6 import java.io.File;
7 import java.io.IOException;
8 import java.io.InputStream;
9 import java.net.MalformedURLException;
10 import java.net.URL;
11
12 import org.apache.commons.io.FileUtils;
13 import org.apache.commons.io.IOUtils;
14
15 /**
16 *
17 * @author vjuranek
18 *
19 */
20 public class ScriptLoader implements Callable<String,IOException> {
21
22 private final String script;
23
24 public ScriptLoader(String script){
25 this.script = script;
26 }
27
28 public String call() throws IOException {
29 File f = new File(script);
30 if(f.exists())
31 return FileUtils.readFileToString(f);
32
33 URL url;
34 try {
35 url = new URL(script);
36 } catch (MalformedURLException e) {
37 throw new AbortException("Unable to find a script "+script);
38 }
39 InputStream s = url.openStream();
40 try {
41 return IOUtils.toString(s);
42 } finally {
43 s.close();
44 }
45 }
46
47 }
48