提交 3dccd183 编写于 作者: K kohsuke

MatrixRun log needs to be discarded as new MatrixBuild is created.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3575 71c3de6d-444a-0410-be80-ed276b4c234a
上级 0dcfae19
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.
*
* <p>
* 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();
}
}
...@@ -146,7 +146,7 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> ...@@ -146,7 +146,7 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
@Override @Override
public LogRotator getLogRotator() { public LogRotator getLogRotator() {
return getParent().getLogRotator(); return new LinkedLogRotator();
} }
@Override @Override
...@@ -171,4 +171,15 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> ...@@ -171,4 +171,15 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
public void setLogRotator(LogRotator logRotator) { public void setLogRotator(LogRotator logRotator) {
throw new UnsupportedOperationException(); 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);
}
} }
...@@ -113,6 +113,16 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im ...@@ -113,6 +113,16 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
rebuildConfigurations(); 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}. * Rebuilds the {@link #configurations} list and {@link #activeConfigurations}.
*/ */
......
...@@ -163,16 +163,23 @@ public abstract class AbstractItem extends Actionable implements Item { ...@@ -163,16 +163,23 @@ public abstract class AbstractItem extends Actionable implements Item {
/** /**
* Deletes this 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)) if(!Hudson.adminCheck(req,rsp))
return; return;
delete();
rsp.sendRedirect2(req.getContextPath()+"/"+getParent().getUrl());
}
/**
* Deletes this item.
*/
public synchronized void delete() throws IOException {
performDelete(); performDelete();
if(this instanceof TopLevelItem) if(this instanceof TopLevelItem)
Hudson.getInstance().deleteJob((TopLevelItem)this); Hudson.getInstance().deleteJob((TopLevelItem)this);
Hudson.getInstance().rebuildDependencyGraph(); Hudson.getInstance().rebuildDependencyGraph();
rsp.sendRedirect2(req.getContextPath()+"/"+getParent().getUrl());
} }
/** /**
......
...@@ -175,6 +175,15 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run ...@@ -175,6 +175,15 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run
this.logRotator = logRotator; this.logRotator = logRotator;
} }
/**
* Perform log rotation.
*/
public void logRotate() throws IOException {
LogRotator lr = getLogRotator();
if(lr!=null)
lr.perform(this);
}
/** /**
* True if this instance supports log rotation configuration. * True if this instance supports log rotation configuration.
*/ */
......
...@@ -601,9 +601,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run ...@@ -601,9 +601,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
} }
try { try {
LogRotator lr = getParent().getLogRotator(); getParent().logRotate();
if(lr!=null)
lr.perform(getParent());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册