提交 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
throw new UnsupportedOperationException();
}
public void onDeleted(MatrixConfiguration item) throws IOException {
// noop
}
public File getRootDirFor(Combination combination) {
File f = getConfigurationsDir();
for (Entry<String, String> e : combination.entrySet())
......
......@@ -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.
*/
......
......@@ -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 {
for (ItemListener l : ItemListener.all())
l.onDeleted(item);
public void onRenamed(TopLevelItem job, String oldName, String newName) throws IOException {
items.remove(oldName);
items.put(newName,job);
items.remove(item.getName());
for (View v : views)
v.onJobRenamed(item, item.getName(), null);
v.onJobRenamed(job, oldName, newName);
save();
}
/**
* Called by {@link Job#renameTo(String)} to update relevant data structure.
* assumed to be synchronized on Hudson by the caller.
* Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)}
*/
public void onRenamed(TopLevelItem job, String oldName, String newName) throws IOException {
items.remove(oldName);
items.put(newName,job);
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(job, oldName, newName);
v.onJobRenamed(item, item.getName(), null);
save();
}
......
......@@ -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.
*/
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
throw new UnsupportedOperationException();
}
public void onDeleted(MavenModule item) throws IOException {
// noop
}
public Collection<Job> getAllJobs() {
Set<Job> jobs = new HashSet<Job>(getItems());
jobs.add(this);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册