# HG changeset patch # Parent 651e1291f237ac8bacc4132ec40ca7b40d558fd2 # User Jaroslav Havlin #215135: HudsonJob.getName() should contain full path to the job diff --git a/hudson/src/org/netbeans/modules/hudson/impl/HudsonConnector.java b/hudson/src/org/netbeans/modules/hudson/impl/HudsonConnector.java --- a/hudson/src/org/netbeans/modules/hudson/impl/HudsonConnector.java +++ b/hudson/src/org/netbeans/modules/hudson/impl/HudsonConnector.java @@ -141,7 +141,7 @@ // Parse jobs and return them Collection viewsData = getViewData(docInstance, instanceUrl); Collection foldersData = new ArrayList(); - Collection jobsData = getJobsData(docInstance, instanceUrl, viewsData, foldersData); + Collection jobsData = getJobsData(docInstance, instanceUrl, viewsData, foldersData, null); return new InstanceData(jobsData, viewsData, foldersData); } @@ -160,7 +160,7 @@ // Clear cache cache.clear(); Collection foldersData = new ArrayList(); - Collection jobsData = getJobsData(docInstance, parentFolder.getUrl(), Collections.emptySet(), foldersData); + Collection jobsData = getJobsData(docInstance, parentFolder.getUrl(), Collections.emptySet(), foldersData, parentFolder); return new InstanceData(jobsData, Collections.emptySet(), foldersData); } @@ -324,7 +324,8 @@ } private Collection getJobsData(Document doc, String baseUrl, - Collection viewsData, Collection foldersData) { + Collection viewsData, Collection foldersData, + HudsonFolder parentFolder) { Collection jobs = new ArrayList(); NodeList nodes = doc.getDocumentElement().getChildNodes(); @@ -348,8 +349,11 @@ } String nodeName = d.getNodeName(); if (nodeName.equals(XML_API_NAME_ELEMENT)) { - jd.setJobName(d.getFirstChild().getTextContent()); - fd.setName(d.getFirstChild().getTextContent()); + String folder = parentFolder == null + ? "" : parentFolder.getName() + "/"; //NOI18N + String name = folder + d.getFirstChild().getTextContent(); + jd.setJobName(name); + fd.setName(name); } else if (nodeName.equals(XML_API_URL_ELEMENT)) { String u = normalizeUrl(baseUrl, d.getFirstChild().getTextContent(), "job/[^/]+/"); // NOI18N jd.setJobUrl(u); diff --git a/hudson/src/org/netbeans/modules/hudson/impl/HudsonInstanceProperties.java b/hudson/src/org/netbeans/modules/hudson/impl/HudsonInstanceProperties.java --- a/hudson/src/org/netbeans/modules/hudson/impl/HudsonInstanceProperties.java +++ b/hudson/src/org/netbeans/modules/hudson/impl/HudsonInstanceProperties.java @@ -46,6 +46,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -191,19 +192,28 @@ } public static List split(String prop) { - return prop != null && prop.trim().length() > 0 ? - Arrays.asList(prop.split("/")) : // NOI18N - Collections.emptyList(); + if (prop != null && prop.trim().length() > 0) { + String[] escaped = prop.split("(? list = new ArrayList(escaped.length); + for (String e : escaped) { + list.add(e.replace("//", "/")); //NOI18N + } + return list; + } else { + return Collections.emptyList(); + } } public static String join(List pieces) { StringBuilder b = new StringBuilder(); for (String piece : pieces) { - assert !piece.contains("/") : piece; + assert !piece.startsWith("/") //NOI18N + && !piece.endsWith("/") : piece; //NOI18N + String escaped = piece.replace("/", "//"); //NOI18N if (b.length() > 0) { b.append('/'); } - b.append(piece); + b.append(escaped); } return b.toString(); } diff --git a/hudson/src/org/netbeans/modules/hudson/spi/ProjectHudsonProvider.java b/hudson/src/org/netbeans/modules/hudson/spi/ProjectHudsonProvider.java --- a/hudson/src/org/netbeans/modules/hudson/spi/ProjectHudsonProvider.java +++ b/hudson/src/org/netbeans/modules/hudson/spi/ProjectHudsonProvider.java @@ -244,7 +244,20 @@ * @return the code name of the job on that server; may be null */ public String getJobName() { - return jobPath.length > 1 ? jobPath[jobPath.length - 1] : null; + if (jobPath.length == 2) { + return jobPath[1]; + } else if (jobPath.length > 2) { + StringBuilder sb = new StringBuilder(); + for (int i = 1; i < jobPath.length; i++) { + if (sb.length() > 0) { + sb.append("/"); //NOI18N + } + sb.append(jobPath[i]); + } + return sb.toString(); + } else { + return null; + } } /** diff --git a/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonFolderNode.java b/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonFolderNode.java --- a/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonFolderNode.java +++ b/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonFolderNode.java @@ -71,7 +71,11 @@ HudsonFolderNode(HudsonFolder folder) { super(Children.create(new HudsonFolderChildren(folder), true), Lookups.singleton(folder)); this.folder = folder; - setName(folder.getName()); + String name = folder.getName(); + setName(name); + setDisplayName(!name.contains("/") ? name //NOI18N + : name.substring(name.lastIndexOf("/") + 1, //NOI18N + name.length())); } public @Override Image getIcon(int type) { diff --git a/hudson/test/unit/src/org/netbeans/modules/hudson/spi/ProjectHudsonProviderTest.java b/hudson/test/unit/src/org/netbeans/modules/hudson/spi/ProjectHudsonProviderTest.java --- a/hudson/test/unit/src/org/netbeans/modules/hudson/spi/ProjectHudsonProviderTest.java +++ b/hudson/test/unit/src/org/netbeans/modules/hudson/spi/ProjectHudsonProviderTest.java @@ -80,7 +80,7 @@ Association a = Association.fromString( "http://localhost:8080/app/hudson/job/folder%201/job/folder%201a/job/TestJob/"); assertEquals("http://localhost:8080/app/hudson/", a.getServerUrl()); - assertEquals("TestJob", a.getJobName()); + assertEquals("folder 1/folder 1a/TestJob", a.getJobName()); String[] expectedPath = {"http://localhost:8080/app/hudson/", "folder 1", "folder 1a", "TestJob"}; assertEquals("Job path length is wrong",