aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 02:14:18 (EST)
committerWinston Prakash2011-12-01 20:47:22 (EST)
commit04926599e92a0278c6c9019ae92918c7886bb780 (patch)
treee3cca8a26a2d3cb3c2c2ecf6e3d4be34339f20ee
parent0c9456f0acf1db9d4d68099f19563eec50ac6901 (diff)
downloadorg.eclipse.hudson.core-04926599e92a0278c6c9019ae92918c7886bb780.zip
org.eclipse.hudson.core-04926599e92a0278c6c9019ae92918c7886bb780.tar.gz
org.eclipse.hudson.core-04926599e92a0278c6c9019ae92918c7886bb780.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.java41
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractItem.java13
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java32
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.