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

1 package hudson.cli;
2
3 import org.apache.commons.codec.binary.Base64;
4
5 import java.io.IOException;
6 import java.net.MalformedURLException;
7 import java.net.URL;
8 import java.util.concurrent.ExecutorService;
9
10 /**
11 * Fluent-API to instantiate {@link CLI}.
12 *
13 * @author Kohsuke Kawaguchi
14 */
15 public class CLIConnectionFactory {
16 URL jenkins;
17 ExecutorService exec;
18 String httpsProxyTunnel;
19 String authorization;
20
21 /**
22 * Top URL of the Jenkins to connect to.
23 */
24 public CLIConnectionFactory url(URL jenkins) {
25 this.jenkins = jenkins;
26 return this;
27 }
28
29 public CLIConnectionFactory url(String jenkins) throws MalformedURLException {
30 return url(new URL(jenkins));
31 }
32
33 /**
34 * This {@link ExecutorService} is used to execute closures received from the server.
35 */
36 public CLIConnectionFactory executorService(ExecutorService es) {
37 this.exec = es;
38 return this;
39 }
40
41 /**
42 * Configures the HTTP proxy that we use for making a plain TCP/IP connection.
43 * "host:port" that points to an HTTP proxy or null.
44 */
45 public CLIConnectionFactory httpsProxyTunnel(String value) {
46 this.httpsProxyTunnel = value;
47 return this;
48 }
49
50 /**
51 * For CLI connection that goes through HTTP, sometimes you need
52 * to pass in the custom authentication header (before Jenkins even get to authenticate
53 * the CLI channel.) This method lets you specify the value of this header.
54 */
55 public CLIConnectionFactory authorization(String value) {
56 this.authorization = value;
57 return this;
58 }
59
60 /**
61 * Convenience method to call {@link #authorization} with the HTTP basic authentication.
62 */
63 public CLIConnectionFactory basicAuth(String username, String password) {
64 return basicAuth(username+':'+password);
65 }
66
67 public CLIConnectionFactory basicAuth(String userInfo) {
68 return authorization("Basic " + new String(Base64.encodeBase64((userInfo).getBytes())));
69 }
70
71 public CLI connect() throws IOException, InterruptedException {
72 return new CLI(this);
73 }
74 }
75