Lines 63-68
Link Here
|
63 |
import java.util.regex.Pattern; |
63 |
import java.util.regex.Pattern; |
64 |
import org.netbeans.api.annotations.common.CheckForNull; |
64 |
import org.netbeans.api.annotations.common.CheckForNull; |
65 |
import org.netbeans.modules.hudson.api.ConnectionBuilder; |
65 |
import org.netbeans.modules.hudson.api.ConnectionBuilder; |
|
|
66 |
import org.netbeans.modules.hudson.api.HudsonFolder; |
66 |
import org.netbeans.modules.hudson.api.HudsonJob; |
67 |
import org.netbeans.modules.hudson.api.HudsonJob; |
67 |
import org.netbeans.modules.hudson.api.HudsonJob.Color; |
68 |
import org.netbeans.modules.hudson.api.HudsonJob.Color; |
68 |
import org.netbeans.modules.hudson.api.HudsonJobBuild; |
69 |
import org.netbeans.modules.hudson.api.HudsonJobBuild; |
Lines 119-124
Link Here
|
119 |
Document docInstance = getDocument(instanceUrl + XML_API_URL + (canUseTree(authentication) ? |
120 |
Document docInstance = getDocument(instanceUrl + XML_API_URL + (canUseTree(authentication) ? |
120 |
"?tree=primaryView[name],views[name,url,jobs[name]]," + |
121 |
"?tree=primaryView[name],views[name,url,jobs[name]]," + |
121 |
"jobs[name,url,color,displayName,buildable,inQueue," + |
122 |
"jobs[name,url,color,displayName,buildable,inQueue," + |
|
|
123 |
"primaryView," + // #215135: marker for folders |
122 |
"lastBuild[number],lastFailedBuild[number],lastStableBuild[number],lastSuccessfulBuild[number],lastCompletedBuild[number]," + |
124 |
"lastBuild[number],lastFailedBuild[number],lastStableBuild[number],lastSuccessfulBuild[number],lastCompletedBuild[number]," + |
123 |
"modules[name,displayName,url,color]]," + |
125 |
"modules[name,displayName,url,color]]," + |
124 |
"securedJobs[name,url]" : // HUDSON-3924 |
126 |
"securedJobs[name,url]" : // HUDSON-3924 |
Lines 131-144
Link Here
|
131 |
if (null == docInstance) { |
133 |
if (null == docInstance) { |
132 |
return new InstanceData( |
134 |
return new InstanceData( |
133 |
Collections.<JobData>emptyList(), |
135 |
Collections.<JobData>emptyList(), |
134 |
Collections.<ViewData>emptyList()); |
136 |
Collections.<ViewData>emptyList(), |
|
|
137 |
Collections.<FolderData>emptyList()); |
135 |
} |
138 |
} |
136 |
// Clear cache |
139 |
// Clear cache |
137 |
cache.clear(); |
140 |
cache.clear(); |
138 |
// Parse jobs and return them |
141 |
// Parse jobs and return them |
139 |
Collection<ViewData> viewsData = getViewData(docInstance); |
142 |
Collection<ViewData> viewsData = getViewData(docInstance, instanceUrl); |
140 |
Collection<JobData> jobsData = getJobsData(docInstance, viewsData); |
143 |
Collection<FolderData> foldersData = new ArrayList<FolderData>(); |
141 |
return new InstanceData(jobsData, viewsData); |
144 |
Collection<JobData> jobsData = getJobsData(docInstance, instanceUrl, viewsData, foldersData); |
|
|
145 |
return new InstanceData(jobsData, viewsData, foldersData); |
146 |
} |
147 |
|
148 |
@Override public InstanceData getInstanceData(HudsonFolder parentFolder, boolean authentication) { |
149 |
Document docInstance = getDocument(parentFolder.getUrl() + XML_API_URL + "?tree=jobs[name,url,color,displayName,buildable,inQueue,primaryView," + |
150 |
"lastBuild[number],lastFailedBuild[number],lastStableBuild[number],lastSuccessfulBuild[number],lastCompletedBuild[number]," + |
151 |
"modules[name,displayName,url,color]]," + |
152 |
"securedJobs[name,url]", authentication); // NOI18N |
153 |
|
154 |
if (null == docInstance) { |
155 |
return new InstanceData( |
156 |
Collections.<JobData>emptyList(), |
157 |
Collections.<ViewData>emptyList(), |
158 |
Collections.<FolderData>emptyList()); |
159 |
} |
160 |
// Clear cache |
161 |
cache.clear(); |
162 |
Collection<FolderData> foldersData = new ArrayList<FolderData>(); |
163 |
Collection<JobData> jobsData = getJobsData(docInstance, parentFolder.getUrl(), Collections.<ViewData>emptySet(), foldersData); |
164 |
return new InstanceData(jobsData, Collections.<ViewData>emptySet(), foldersData); |
142 |
} |
165 |
} |
143 |
|
166 |
|
144 |
@Override |
167 |
@Override |
Lines 235-241
Link Here
|
235 |
|
258 |
|
236 |
} |
259 |
} |
237 |
|
260 |
|
238 |
private Collection<ViewData> getViewData(Document doc) { |
261 |
private Collection<ViewData> getViewData(Document doc, String baseUrl) { |
239 |
String primaryViewName = null; |
262 |
String primaryViewName = null; |
240 |
Element primaryViewEl = XMLUtil.findElement(doc.getDocumentElement(), "primaryView", null); // NOI18N |
263 |
Element primaryViewEl = XMLUtil.findElement(doc.getDocumentElement(), "primaryView", null); // NOI18N |
241 |
if (primaryViewEl != null) { |
264 |
if (primaryViewEl != null) { |
Lines 267-273
Link Here
|
267 |
name = o.getFirstChild().getTextContent(); |
290 |
name = o.getFirstChild().getTextContent(); |
268 |
isPrimary = name.equals(primaryViewName); |
291 |
isPrimary = name.equals(primaryViewName); |
269 |
} else if (o.getNodeName().equals(XML_API_URL_ELEMENT)) { |
292 |
} else if (o.getNodeName().equals(XML_API_URL_ELEMENT)) { |
270 |
url = normalizeUrl(o.getFirstChild().getTextContent(), isPrimary ? "" : "view/[^/]+/"); // NOI18N |
293 |
url = normalizeUrl(baseUrl, o.getFirstChild().getTextContent(), isPrimary ? "" : "view/[^/]+/"); // NOI18N |
271 |
} |
294 |
} |
272 |
} |
295 |
} |
273 |
|
296 |
|
Lines 300-307
Link Here
|
300 |
return views; |
323 |
return views; |
301 |
} |
324 |
} |
302 |
|
325 |
|
303 |
private Collection<JobData> getJobsData(Document doc, |
326 |
private Collection<JobData> getJobsData(Document doc, String baseUrl, |
304 |
Collection<ViewData> viewsData) { |
327 |
Collection<ViewData> viewsData, Collection<FolderData> foldersData) { |
305 |
Collection<JobData> jobs = new ArrayList<JobData>(); |
328 |
Collection<JobData> jobs = new ArrayList<JobData>(); |
306 |
|
329 |
|
307 |
NodeList nodes = doc.getDocumentElement().getChildNodes(); |
330 |
NodeList nodes = doc.getDocumentElement().getChildNodes(); |
Lines 314-319
Link Here
|
314 |
|
337 |
|
315 |
JobData jd = new JobData(); |
338 |
JobData jd = new JobData(); |
316 |
jd.setSecured(secured); |
339 |
jd.setSecured(secured); |
|
|
340 |
FolderData fd = new FolderData(); |
341 |
boolean isFolder = false; |
317 |
|
342 |
|
318 |
NodeList jobDetails = n.getChildNodes(); |
343 |
NodeList jobDetails = n.getChildNodes(); |
319 |
for (int k = 0; k < jobDetails.getLength(); k++) { |
344 |
for (int k = 0; k < jobDetails.getLength(); k++) { |
Lines 324-331
Link Here
|
324 |
String nodeName = d.getNodeName(); |
349 |
String nodeName = d.getNodeName(); |
325 |
if (nodeName.equals(XML_API_NAME_ELEMENT)) { |
350 |
if (nodeName.equals(XML_API_NAME_ELEMENT)) { |
326 |
jd.setJobName(d.getFirstChild().getTextContent()); |
351 |
jd.setJobName(d.getFirstChild().getTextContent()); |
|
|
352 |
fd.setName(d.getFirstChild().getTextContent()); |
327 |
} else if (nodeName.equals(XML_API_URL_ELEMENT)) { |
353 |
} else if (nodeName.equals(XML_API_URL_ELEMENT)) { |
328 |
jd.setJobUrl(normalizeUrl(d.getFirstChild().getTextContent(), "job/[^/]+/")); // NOI18N |
354 |
String u = normalizeUrl(baseUrl, d.getFirstChild().getTextContent(), "job/[^/]+/"); // NOI18N |
|
|
355 |
jd.setJobUrl(u); |
356 |
fd.setUrl(u); |
357 |
} else if (nodeName.equals("primaryView")) { // NOI18N |
358 |
isFolder = true; |
329 |
} else if (nodeName.equals(XML_API_COLOR_ELEMENT)) { |
359 |
} else if (nodeName.equals(XML_API_COLOR_ELEMENT)) { |
330 |
jd.setColor(Color.find(d.getFirstChild().getTextContent().trim())); |
360 |
jd.setColor(Color.find(d.getFirstChild().getTextContent().trim())); |
331 |
} else if (nodeName.equals(XML_API_DISPLAY_NAME_ELEMENT)) { |
361 |
} else if (nodeName.equals(XML_API_DISPLAY_NAME_ELEMENT)) { |
Lines 362-368
Link Here
|
362 |
} else if (nodeName2.equals("displayName")) { // NOI18N |
392 |
} else if (nodeName2.equals("displayName")) { // NOI18N |
363 |
displayName = text; |
393 |
displayName = text; |
364 |
} else if (nodeName2.equals("url")) { // NOI18N |
394 |
} else if (nodeName2.equals("url")) { // NOI18N |
365 |
url = normalizeUrl(text, "job/[^/]+/[^/]+/"); // NOI18N |
395 |
url = normalizeUrl(baseUrl, text, "job/[^/]+/[^/]+/"); // NOI18N |
366 |
} else if (nodeName2.equals("color")) { // NOI18N |
396 |
} else if (nodeName2.equals("color")) { // NOI18N |
367 |
color = Color.find(text); |
397 |
color = Color.find(text); |
368 |
} else { |
398 |
} else { |
Lines 391-397
Link Here
|
391 |
jd.addView(v.getName()); |
421 |
jd.addView(v.getName()); |
392 |
} |
422 |
} |
393 |
} |
423 |
} |
394 |
jobs.add(jd); |
424 |
if (isFolder) { |
|
|
425 |
foldersData.add(fd); |
426 |
} else { |
427 |
jobs.add(jd); |
428 |
} |
395 |
} |
429 |
} |
396 |
return jobs; |
430 |
return jobs; |
397 |
} |
431 |
} |
Lines 403-409
Link Here
|
403 |
* @return analogous URL constructed from instance root, e.g. {@code https://my.facade/hudson/job/My%20Job/} |
437 |
* @return analogous URL constructed from instance root, e.g. {@code https://my.facade/hudson/job/My%20Job/} |
404 |
* @see "#165735" |
438 |
* @see "#165735" |
405 |
*/ |
439 |
*/ |
406 |
private String normalizeUrl(String suggested, String relativePattern) { |
440 |
private static String normalizeUrl(String instanceUrl, String suggested, String relativePattern) { |
407 |
Pattern tailPattern; |
441 |
Pattern tailPattern; |
408 |
synchronized (tailPatterns) { |
442 |
synchronized (tailPatterns) { |
409 |
tailPattern = tailPatterns.get(relativePattern); |
443 |
tailPattern = tailPatterns.get(relativePattern); |
Lines 620-623
Link Here
|
620 |
} |
654 |
} |
621 |
return items; |
655 |
return items; |
622 |
} |
656 |
} |
|
|
657 |
|
623 |
} |
658 |
} |