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