From 70fde5f74e4167a33bb24dd9832385c91f9417b8 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 29 Dec 2010 17:19:33 -0800 Subject: [PATCH] added a callback to be notified when a child is removed --- .../java/hudson/matrix/MatrixProject.java | 4 +++ .../main/java/hudson/model/AbstractItem.java | 15 +++++++++-- core/src/main/java/hudson/model/Hudson.java | 26 +++++++++---------- .../src/main/java/hudson/model/ItemGroup.java | 5 ++++ .../java/hudson/maven/MavenModuleSet.java | 4 +++ 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/hudson/matrix/MatrixProject.java b/core/src/main/java/hudson/matrix/MatrixProject.java index 6fddfa3abd..e366882e02 100644 --- a/core/src/main/java/hudson/matrix/MatrixProject.java +++ b/core/src/main/java/hudson/matrix/MatrixProject.java @@ -467,6 +467,10 @@ public class MatrixProject extends AbstractProject im throw new UnsupportedOperationException(); } + public void onDeleted(MatrixConfiguration item) throws IOException { + // noop + } + public File getRootDirFor(Combination combination) { File f = getConfigurationsDir(); for (Entry e : combination.entrySet()) diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 9117bcb6d6..4208b84765 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -412,12 +412,23 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet checkPermission(DELETE); performDelete(); - if(this instanceof TopLevelItem) - Hudson.getInstance().deleteJob((TopLevelItem)this); + try { + invokeOnDeleted(); + } catch (AbstractMethodError e) { + // ignore + } Hudson.getInstance().rebuildDependencyGraph(); } + /** + * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 + * on BugParade for more details. + */ + private void invokeOnDeleted() throws IOException { + getParent().onDeleted(this); + } + /** * Does the real job of deleting the item. */ diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index dc6dd93342..2b55f2ea7b 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -2152,19 +2152,6 @@ public final class Hudson extends Node implements ItemGroup, Stapl return type.cast(createProject((TopLevelItemDescriptor)getDescriptor(type),name)); } - /** - * Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)} - */ - /*package*/ void deleteJob(TopLevelItem item) throws IOException { - for (ItemListener l : ItemListener.all()) - l.onDeleted(item); - - items.remove(item.getName()); - for (View v : views) - v.onJobRenamed(item, item.getName(), null); - save(); - } - /** * Called by {@link Job#renameTo(String)} to update relevant data structure. * assumed to be synchronized on Hudson by the caller. @@ -2178,6 +2165,19 @@ public final class Hudson extends Node implements ItemGroup, Stapl save(); } + /** + * Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)} + */ + public void onDeleted(TopLevelItem item) throws IOException { + for (ItemListener l : ItemListener.all()) + l.onDeleted(item); + + items.remove(item.getName()); + for (View v : views) + v.onJobRenamed(item, item.getName(), null); + save(); + } + public FingerprintMap getFingerprintMap() { return fingerprintMap; } diff --git a/core/src/main/java/hudson/model/ItemGroup.java b/core/src/main/java/hudson/model/ItemGroup.java index 9713567109..9c7fe37d7c 100644 --- a/core/src/main/java/hudson/model/ItemGroup.java +++ b/core/src/main/java/hudson/model/ItemGroup.java @@ -77,4 +77,9 @@ public interface ItemGroup extends PersistenceRoot, ModelObject * Internal method. Called by {@link Item}s when they are renamed by users. */ void onRenamed(T item, String oldName, String newName) throws IOException; + + /** + * Internal method. Called by {@link Item}s when they are deleted by users. + */ + void onDeleted(T item) throws IOException; } diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index 898e181281..0cbbe52641 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -449,6 +449,10 @@ public final class MavenModuleSet extends AbstractMavenProject getAllJobs() { Set jobs = new HashSet(getItems()); jobs.add(this);