6
6
7
7
package com .offbytwo .jenkins .model ;
8
8
9
- import static org .apache .commons .lang .StringUtils .join ;
10
-
11
9
import java .io .ByteArrayOutputStream ;
12
10
import java .io .IOException ;
13
11
import java .io .InputStream ;
14
12
import java .net .URI ;
13
+ import java .util .ArrayList ;
14
+ import java .util .List ;
15
15
import java .util .Map ;
16
16
17
+ import org .apache .http .HttpResponse ;
18
+ import org .apache .http .NameValuePair ;
19
+ import org .apache .http .message .BasicNameValuePair ;
20
+ import org .apache .http .util .EntityUtils ;
21
+
17
22
import com .google .common .base .Function ;
18
23
import com .google .common .collect .Collections2 ;
19
- import com .google .common .escape .Escaper ;
20
- import com .google .common .net .UrlEscapers ;
21
24
22
25
public class Job extends BaseModel {
23
26
@@ -27,7 +30,7 @@ public class Job extends BaseModel {
27
30
28
31
public Job () {
29
32
}
30
-
33
+
31
34
public Job (String name , String url ) {
32
35
this ();
33
36
this .name = name ;
@@ -49,7 +52,7 @@ public String getName() {
49
52
public String getUrl () {
50
53
return url ;
51
54
}
52
-
55
+
53
56
public String getFullName () {
54
57
return fullName ;
55
58
}
@@ -60,9 +63,9 @@ public JobWithDetails details() throws IOException {
60
63
61
64
/**
62
65
* Get a file from workspace.
63
- *
66
+ *
64
67
* @param fileName The name of the file to download from workspace. You can
65
- * also access files which are in sub folders of the workspace.
68
+ * also access files which are in sub folders of the workspace.
66
69
* @return The string which contains the content of the file.
67
70
* @throws IOException in case of an error.
68
71
*/
@@ -79,7 +82,7 @@ public String getFileFromWorkspace(String fileName) throws IOException {
79
82
80
83
/**
81
84
* Trigger a build without parameters
82
- *
85
+ *
83
86
* @return {@link QueueReference} for further analysis of the queued build.
84
87
* @throws IOException in case of an error.
85
88
*/
@@ -91,7 +94,7 @@ public QueueReference build() throws IOException {
91
94
92
95
/**
93
96
* Trigger a build with crumbFlag.
94
- *
97
+ *
95
98
* @param crumbFlag true or false.
96
99
* @return {@link QueueReference} for further analysis of the queued build.
97
100
* @throws IOException in case of an error.
@@ -115,15 +118,19 @@ public QueueReference build(Map<String, String> params) throws IOException {
115
118
/**
116
119
* Trigger a parameterized build
117
120
*
118
- * @param params the job parameters
121
+ * @param params the job parameters
119
122
* @param crumbFlag determines whether crumb flag is used
120
123
* @return {@link QueueReference} for further analysis of the queued build.
121
124
* @throws IOException in case of an error.
122
125
*/
123
126
public QueueReference build (Map <String , String > params , boolean crumbFlag ) throws IOException {
124
- String qs = join (Collections2 .transform (params .entrySet (), new MapEntryToQueryStringPair ()), "&" );
125
- ExtractHeader location = client .post (url + "buildWithParameters?" + qs , null , ExtractHeader .class , crumbFlag );
126
- return new QueueReference (location .getLocation ());
127
+ List <NameValuePair > paramsList = new ArrayList <>(Collections2 .transform (params .entrySet (),
128
+ new MapEntryToNameValuePair ()));
129
+ HttpResponse response = this .client
130
+ .post_form_with_result (this .url + "buildWithParameters" , paramsList , crumbFlag );
131
+ String location = response .getFirstHeader ("Location" ).getValue ();
132
+ EntityUtils .consume (response .getEntity ());
133
+ return new QueueReference (location );
127
134
}
128
135
129
136
@ Override
@@ -152,11 +159,10 @@ public int hashCode() {
152
159
return result ;
153
160
}
154
161
155
- private static class MapEntryToQueryStringPair implements Function <Map .Entry <String , String >, String > {
162
+ private static class MapEntryToNameValuePair implements Function <Map .Entry <String , String >, NameValuePair > {
156
163
@ Override
157
- public String apply (Map .Entry <String , String > entry ) {
158
- Escaper escaper = UrlEscapers .urlFormParameterEscaper ();
159
- return escaper .escape (entry .getKey ()) + "=" + escaper .escape (entry .getValue ());
164
+ public NameValuePair apply (Map .Entry <String , String > entry ) {
165
+ return new BasicNameValuePair (entry .getKey (), entry .getValue ());
160
166
}
161
167
}
162
168
}
0 commit comments