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

1 package hudson.util;
2
3 import hudson.FilePath;
4 import hudson.Util;
5 import hudson.remoting.Which;
6
7 import java.io.Serializable;
8 import java.io.File;
9 import java.io.IOException;
10 import java.util.List;
11 import java.util.ArrayList;
12
13 /**
14 * Used to build up an argument in the classpath format.
15 *
16 * @author Kohsuke Kawaguchi
17 * @since 1.300
18 */
19 public class ClasspathBuilder implements Serializable {
20 private final List<String> args = new ArrayList<String>();
21
22 /**
23 * Adds a single directory or a jar file.
24 */
25 public ClasspathBuilder add(File f) {
26 return add(f.getAbsolutePath());
27 }
28
29 /**
30 * Adds a single directory or a jar file.
31 */
32 public ClasspathBuilder add(FilePath f) {
33 return add(f.getRemote());
34 }
35
36 /**
37 * Adds a single directory or a jar file.
38 */
39 public ClasspathBuilder add(String path) {
40 args.add(path);
41 return this;
42 }
43
44 /**
45 * Adds a jar file that contains the given class.
46 * @since 1.361
47 */
48 public ClasspathBuilder addJarOf(Class c) throws IOException {
49 return add(Which.jarFile(c));
50 }
51
52 /**
53 * Adds all the files that matches the given glob in the directory.
54 *
55 * @see FilePath#list(String)
56 */
57 public ClasspathBuilder addAll(FilePath base, String glob) throws IOException, InterruptedException {
58 for(FilePath item : base.list(glob))
59 add(item);
60 return this;
61 }
62
63 /**
64 * Returns the string representation of the classpath.
65 */
66 @Override
67 public String toString() {
68 return Util.join(args,File.pathSeparator);
69 }
70 }
71