Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-18074] Avoid clearing AbstractItem.displayName when th…
…e new parent ItemGroup is different.

(cherry picked from commit 04e2cca)
  • Loading branch information
jglick authored and olivergondza committed Sep 17, 2013
1 parent 0d5b6a2 commit c0102e7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -273,6 +273,9 @@ <h3><a name=v1.517>What's new in 1.517</a> <!--=DATE=--></h3>
<li class=bug>
When copying a folder, the display names of contained jobs were gratuitously cleared.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18074">issue 18074</a>)
<li class=bug>
When copying a folder, the display names of contained jobs were gratuitously cleared.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18074">issue 18074</a>)
<li class=bug>
“Recurse in subfolders” option for list views produced exceptions when used with native Maven projects.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18025">issue 18025</a>)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/DisplayNameListener.java
Expand Up @@ -50,7 +50,7 @@ public class DisplayNameListener extends ItemListener {
*/
public void onCopied(Item src, Item item) {
// bug 5056825 - Display name field should be cleared when you copy a job.
if(item instanceof AbstractItem) {
if(item instanceof AbstractItem && src.getParent() == item.getParent()) {
AbstractItem dest = (AbstractItem)item;
try {
dest.setDisplayName(null);
Expand Down
11 changes: 11 additions & 0 deletions test/src/main/java/org/jvnet/hudson/test/MockFolder.java
Expand Up @@ -106,6 +106,17 @@ private ItemGroupMixIn mixin() {
return mixin().copy(src, name);
}

@Override public void onCopiedFrom(Item src) {
super.onCopiedFrom(src);
for (TopLevelItem item : ((MockFolder) src).getItems()) {
try {
copy(item, item.getName());
} catch (IOException x) {
assert false : x;
}
}
}

@Override public TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException {
return mixin().createProjectFromXML(name, xml);
}
Expand Down
14 changes: 14 additions & 0 deletions test/src/test/java/hudson/model/DisplayNameTest.java
Expand Up @@ -28,7 +28,9 @@
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;

/**
* @author kingfai
Expand Down Expand Up @@ -90,4 +92,16 @@ public void testCopyJobWithDisplayName() throws Exception {
Assert.assertEquals(newProjectName, newProject.getDisplayName());

}

@Bug(18074)
@Test public void copyJobWithDisplayNameToDifferentFolder() throws Exception {
MockFolder d1 = j.createFolder("d1");
FreeStyleProject job = d1.createProject(FreeStyleProject.class, "job");
job.setDisplayName("My Job");
MockFolder d2 = j.jenkins.copy(d1, "d2");
FreeStyleProject j2 = (FreeStyleProject) d2.getItem("job");
Assert.assertNotNull(j2);
Assert.assertEquals("My Job", j2.getDisplayName());
}

}

0 comments on commit c0102e7

Please sign in to comment.