| author | akozak | 2011-11-24 02:14:18 (EST) |
|---|---|---|
| committer | Winston Prakash | 2011-12-01 20:47:22 (EST) |
| commit | 291e61d705aebdb608103bb82c018931bbaa2ae4 (patch) (side-by-side diff) | |
| tree | d9c5f5242b71d7b2d34a6fde8a9143f2f8630ddf | |
| parent | 3e8ad3333515300e3b17d0c4756b97018362c8c9 (diff) | |
| download | org.eclipse.hudson.core-291e61d705aebdb608103bb82c018931bbaa2ae4.zip org.eclipse.hudson.core-291e61d705aebdb608103bb82c018931bbaa2ae4.tar.gz org.eclipse.hudson.core-291e61d705aebdb608103bb82c018931bbaa2ae4.tar.bz2 | |
Added cascading links updating on the project renaming.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
| -rw-r--r-- | hudson-core/src/main/java/hudson/Functions.java | 41 | ||||
| -rw-r--r-- | hudson-core/src/main/java/hudson/model/AbstractItem.java | 13 | ||||
| -rw-r--r-- | hudson-core/src/main/java/hudson/model/Job.java | 32 |
3 files changed, 85 insertions, 1 deletions
diff --git a/hudson-core/src/main/java/hudson/Functions.java b/hudson-core/src/main/java/hudson/Functions.java index e0ed83c..2a35b57 100644 --- a/hudson-core/src/main/java/hudson/Functions.java +++ b/hudson-core/src/main/java/hudson/Functions.java @@ -1404,4 +1404,45 @@ public class Functions { } } } + + /** + * Updates the name of the project in the in all children cascading references. + * If this project uses some cascading parent, the name of this project will be renamed in the cascading children + * collection of the cascading parent project. + * + * @param cascadingProject cascading project. + * @param oldName old project name. + * @param newName new project name. + */ + @SuppressWarnings("unchecked") + public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName){ + if(cascadingProject != null){ + cascadingProject.renameCascadingChildName(oldName, newName); + if(cascadingProject.hasCascadingProject()){ + renameCascadingChildLinks(cascadingProject.getCascadingProject(), oldName, newName); + } + } + } + + /** + * Updates the name of the project in the in all parent cascading references. + * If this project is used as cascading parent, it's name will be renamed in all children projects. + * + * @param oldName old project name. + * @param newName new project name. + + */ + @SuppressWarnings("unchecked") + public static void renameCascadingParentLinks(final String oldName, final String newName){ + if (StringUtils.isBlank(newName)|| StringUtils.isBlank(oldName)) { + return; + } + for (Job job : Hudson.getInstance().getAllItems(Job.class)) { + if(oldName.equals(job.getCascadingProjectName())){ + job.renameCascadingProjectNameTo(newName); + } + + } + } } + diff --git a/hudson-core/src/main/java/hudson/model/AbstractItem.java b/hudson-core/src/main/java/hudson/model/AbstractItem.java index 1875d53..2cbe055 100644 --- a/hudson-core/src/main/java/hudson/model/AbstractItem.java +++ b/hudson-core/src/main/java/hudson/model/AbstractItem.java @@ -142,6 +142,16 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet } /** + * Ad additional action which should be performed before the item will be renamed. + * It's possible to add some logic in the subclasses. + * + * @param oldName old item name. + * @param newName new item name. + */ + protected void performBeforeItemRenaming(String oldName, String newName){ + } + + /** * Renames this item. * Not all the Items need to support this operation, but if you decide to do so, * you can use this method. @@ -168,6 +178,9 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet + " already exists"); String oldName = this.name; + + performBeforeItemRenaming(oldName,newName); + File oldRoot = this.getRootDir(); doSetName(newName); diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java index a2aa3da..7099993 100644 --- a/hudson-core/src/main/java/hudson/model/Job.java +++ b/hudson-core/src/main/java/hudson/model/Job.java @@ -351,6 +351,17 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R cascadingChildrenNames.remove(cascadingChildName); } + /** + * Remove cascading child project name. + * + * @param oldChildName old child project name. + * @param newChildName new child project name. + */ + public synchronized void renameCascadingChildName(String oldChildName, String newChildName) { + cascadingChildrenNames.remove(oldChildName); + cascadingChildrenNames.add(newChildName); + } + @Override public synchronized void save() throws IOException { if (null == allowSave) { @@ -785,10 +796,19 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R }; /** + * @inheritDoc + */ + @Override + protected void performBeforeItemRenaming(String oldName, String newName){ + Functions.renameCascadingChildLinks(this, oldName, newName); + Functions.renameCascadingParentLinks(oldName, newName); + } + + /** * Renames a job. */ @Override - public void renameTo(String newName) throws IOException { + public synchronized void renameTo(String newName) throws IOException { super.renameTo(newName); } @@ -1469,6 +1489,16 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R } /** + * Renames cascading project name. For the properties prcessing and children links updating + * please use {@link #setCascadingProjectName} instead. + * + * @param cascadingProjectName new project name. + */ + public void renameCascadingProjectNameTo(String cascadingProjectName) { + this.cascadingProjectName = cascadingProjectName; + } + + /** * Returns cascading project name. * * @return cascading project name. |

