提交 70fde5f7 编写于 作者: K Kohsuke Kawaguchi

added a callback to be notified when a child is removed

上级 46a033a9
...@@ -467,6 +467,10 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im ...@@ -467,6 +467,10 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void onDeleted(MatrixConfiguration item) throws IOException {
// noop
}
public File getRootDirFor(Combination combination) { public File getRootDirFor(Combination combination) {
File f = getConfigurationsDir(); File f = getConfigurationsDir();
for (Entry<String, String> e : combination.entrySet()) for (Entry<String, String> e : combination.entrySet())
......
...@@ -412,12 +412,23 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet ...@@ -412,12 +412,23 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
checkPermission(DELETE); checkPermission(DELETE);
performDelete(); performDelete();
if(this instanceof TopLevelItem) try {
Hudson.getInstance().deleteJob((TopLevelItem)this); invokeOnDeleted();
} catch (AbstractMethodError e) {
// ignore
}
Hudson.getInstance().rebuildDependencyGraph(); 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. * Does the real job of deleting the item.
*/ */
......
...@@ -2153,28 +2153,28 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl ...@@ -2153,28 +2153,28 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
} }
/** /**
* Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)} * Called by {@link Job#renameTo(String)} to update relevant data structure.
* assumed to be synchronized on Hudson by the caller.
*/ */
/*package*/ void deleteJob(TopLevelItem item) throws IOException { public void onRenamed(TopLevelItem job, String oldName, String newName) throws IOException {
for (ItemListener l : ItemListener.all()) items.remove(oldName);
l.onDeleted(item); items.put(newName,job);
items.remove(item.getName());
for (View v : views) for (View v : views)
v.onJobRenamed(item, item.getName(), null); v.onJobRenamed(job, oldName, newName);
save(); save();
} }
/** /**
* Called by {@link Job#renameTo(String)} to update relevant data structure. * Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)}
* assumed to be synchronized on Hudson by the caller.
*/ */
public void onRenamed(TopLevelItem job, String oldName, String newName) throws IOException { public void onDeleted(TopLevelItem item) throws IOException {
items.remove(oldName); for (ItemListener l : ItemListener.all())
items.put(newName,job); l.onDeleted(item);
items.remove(item.getName());
for (View v : views) for (View v : views)
v.onJobRenamed(job, oldName, newName); v.onJobRenamed(item, item.getName(), null);
save(); save();
} }
......
...@@ -77,4 +77,9 @@ public interface ItemGroup<T extends Item> extends PersistenceRoot, ModelObject ...@@ -77,4 +77,9 @@ public interface ItemGroup<T extends Item> extends PersistenceRoot, ModelObject
* Internal method. Called by {@link Item}s when they are renamed by users. * Internal method. Called by {@link Item}s when they are renamed by users.
*/ */
void onRenamed(T item, String oldName, String newName) throws IOException; 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;
} }
...@@ -449,6 +449,10 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma ...@@ -449,6 +449,10 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void onDeleted(MavenModule item) throws IOException {
// noop
}
public Collection<Job> getAllJobs() { public Collection<Job> getAllJobs() {
Set<Job> jobs = new HashSet<Job>(getItems()); Set<Job> jobs = new HashSet<Job>(getItems());
jobs.add(this); jobs.add(this);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册