diff --git a/core/src/main/java/hudson/matrix/LinkedLogRotator.java b/core/src/main/java/hudson/matrix/LinkedLogRotator.java
new file mode 100644
index 0000000000000000000000000000000000000000..dbf06234fb506b8330a60fbad75de312200e95aa
--- /dev/null
+++ b/core/src/main/java/hudson/matrix/LinkedLogRotator.java
@@ -0,0 +1,37 @@
+package hudson.matrix;
+
+import hudson.model.Job;
+import hudson.tasks.LogRotator;
+
+import java.io.IOException;
+
+/**
+ * {@link LogRotator} for {@link MatrixConfiguration},
+ * which discards the builds if and only if it's discarded
+ * in the parent.
+ *
+ *
+ * Because of the serialization compatibility, we can't easily
+ * refactor {@link LogRotator} into a contract and an implementation.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+final class LinkedLogRotator extends LogRotator {
+ LinkedLogRotator() {
+ super(-1,-1);
+ }
+
+ @Override
+ public void perform(Job _job) throws IOException {
+ // copy it to the array because we'll be deleting builds as we go.
+ MatrixConfiguration job = (MatrixConfiguration) _job;
+
+ for( MatrixRun r : job.getBuilds().toArray(new MatrixRun[0]) ) {
+ if(job.getParent().getBuildByNumber(r.getNumber())==null)
+ r.delete();
+ }
+
+ if(!job.isActiveConfiguration() && job.getLastBuild()==null)
+ job.delete();
+ }
+}
diff --git a/core/src/main/java/hudson/matrix/MatrixConfiguration.java b/core/src/main/java/hudson/matrix/MatrixConfiguration.java
index 7d94dd50baca09bb4d36c8ea2c450f4181eaab06..d96dd581ef1021bfa61d9698e89ebdb2d258fd29 100644
--- a/core/src/main/java/hudson/matrix/MatrixConfiguration.java
+++ b/core/src/main/java/hudson/matrix/MatrixConfiguration.java
@@ -146,7 +146,7 @@ public class MatrixConfiguration extends Project
@Override
public LogRotator getLogRotator() {
- return getParent().getLogRotator();
+ return new LinkedLogRotator();
}
@Override
@@ -171,4 +171,15 @@ public class MatrixConfiguration extends Project
public void setLogRotator(LogRotator logRotator) {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Returns true if this configuration is a configuration
+ * currently in use today (as opposed to the ones that are
+ * there only to keep the past record.)
+ *
+ * @see MatrixProject#getActiveConfigurations()
+ */
+ public boolean isActiveConfiguration() {
+ return getParent().getActiveConfigurations().contains(this);
+ }
}
diff --git a/core/src/main/java/hudson/matrix/MatrixProject.java b/core/src/main/java/hudson/matrix/MatrixProject.java
index b6bd34c5b676cd972b6dd5c97341dc62b02a8a7a..337ecc8898f5aa7e3a39be37bd0f917402310a62 100644
--- a/core/src/main/java/hudson/matrix/MatrixProject.java
+++ b/core/src/main/java/hudson/matrix/MatrixProject.java
@@ -113,6 +113,16 @@ public class MatrixProject extends AbstractProject im
rebuildConfigurations();
}
+ public void logRotate() throws IOException {
+ super.logRotate();
+ // perform the log rotation of inactive configurations to make sure
+ // their logs get eventually discarded
+ for (MatrixConfiguration config : configurations.values()) {
+ if(!config.isActiveConfiguration())
+ config.logRotate();
+ }
+ }
+
/**
* Rebuilds the {@link #configurations} list and {@link #activeConfigurations}.
*/
diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java
index 1b78f06d61632be335f9e20fdf1ae4aa22f2bac0..0b7b67f96af0d034e6aebd7a9db3bbf4eb969a2c 100644
--- a/core/src/main/java/hudson/model/AbstractItem.java
+++ b/core/src/main/java/hudson/model/AbstractItem.java
@@ -163,16 +163,23 @@ public abstract class AbstractItem extends Actionable implements Item {
/**
* Deletes this item.
*/
- public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException {
+ public void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException {
if(!Hudson.adminCheck(req,rsp))
return;
+ delete();
+ rsp.sendRedirect2(req.getContextPath()+"/"+getParent().getUrl());
+ }
+
+ /**
+ * Deletes this item.
+ */
+ public synchronized void delete() throws IOException {
performDelete();
if(this instanceof TopLevelItem)
Hudson.getInstance().deleteJob((TopLevelItem)this);
Hudson.getInstance().rebuildDependencyGraph();
- rsp.sendRedirect2(req.getContextPath()+"/"+getParent().getUrl());
}
/**
diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java
index 75f8fa7068a6c046dec3134504b93976b226d230..d0916033b0837375943ccca9163ee00c4fdef945 100644
--- a/core/src/main/java/hudson/model/Job.java
+++ b/core/src/main/java/hudson/model/Job.java
@@ -175,6 +175,15 @@ public abstract class Job, RunT extends Run,RunT extends Run