提交 a614cd5b 编写于 作者: J Jesse Glick

[FIXED JENKINS-17125] FingerprintAction no longer need persist the build field...

[FIXED JENKINS-17125] FingerprintAction no longer need persist the build field thanks to new RunAction2.
上级 dfe2b9a2
......@@ -58,6 +58,9 @@ Upcoming changes</a>
<li class='major bug'>
Log cluttered with irrelevant warnings about build timestamps when running on Windows on Java 6.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15587">issue 15587</a>)
<li class='major bug'>
Fingerprint action deserialization problem fixed.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17125">issue 17125</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -35,9 +35,10 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import jenkins.model.RunAction2;
@ExportedBean
public class CauseAction implements FoldableAction, RunAction {
public class CauseAction implements FoldableAction, RunAction2 {
/**
* @deprecated since 2009-02-28
*/
......@@ -105,18 +106,14 @@ public class CauseAction implements FoldableAction, RunAction {
return causes.get(0).getShortDescription();
}
public void onLoad() {
// noop
}
public void onBuildComplete() {
@Override public void onLoad(Run<?,?> r) {
// noop
}
/**
* When hooked up to build, notify {@link Cause}s.
*/
public void onAttached(Run owner) {
@Override public void onAttached(Run<?,?> owner) {
if (owner instanceof AbstractBuild) {// this should be always true but being defensive here
AbstractBuild b = (AbstractBuild) owner;
for (Cause c : causes) {
......
......@@ -120,6 +120,7 @@ import java.io.OutputStream;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.RunAction2;
/**
* A particular execution of {@link Job}.
......@@ -314,10 +315,15 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
/**
* Called after the build is loaded and the object is added to the build list.
*/
@SuppressWarnings("deprecation")
protected void onLoad() {
for (Action a : getActions())
if (a instanceof RunAction)
for (Action a : getActions()) {
if (a instanceof RunAction2) {
((RunAction2) a).onLoad(this);
} else if (a instanceof RunAction) {
((RunAction) a).onLoad();
}
}
}
/**
......@@ -334,11 +340,15 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return Collections.unmodifiableList(actions);
}
@SuppressWarnings("deprecation")
@Override
public void addAction(Action a) {
super.addAction(a);
if (a instanceof RunAction)
if (a instanceof RunAction2) {
((RunAction2) a).onAttached(this);
} else if (a instanceof RunAction) {
((RunAction) a).onAttached(this);
}
}
static class InvalidDirectoryNameException extends IOException {
......
......@@ -23,11 +23,12 @@
*/
package hudson.model;
import jenkins.model.RunAction2;
/**
* Optional interface for {@link Action}s that add themselves to {@link Run}.
*
* @author Kohsuke Kawaguchi
* @deprecated Use {@link RunAction2} instead: {@link #onLoad} does not work well with lazy loading if you are trying to persist the owner; and {@link #onBuildComplete} was never called.
*/
@Deprecated
public interface RunAction extends Action {
/**
* Called after the build is loaded and the object is added to the build list.
......
......@@ -44,7 +44,6 @@ import hudson.model.FingerprintMap;
import jenkins.model.Jenkins;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.RunAction;
import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import hudson.util.FormValidation;
......@@ -75,6 +74,7 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.RunAction2;
/**
* Records fingerprints of the specified files.
......@@ -292,10 +292,10 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
/**
* Action for displaying fingerprints.
*/
public static final class FingerprintAction implements RunAction {
private AbstractBuild build;
public static final class FingerprintAction implements RunAction2 {
private transient AbstractBuild build;
private static final Random rand = new Random();
/**
......@@ -308,7 +308,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
public FingerprintAction(AbstractBuild build, Map<String, String> record) {
this.build = build;
this.record = PackedMap.of(record);
onLoad(); // make compact
compact();
}
public void add(Map<String,String> moreRecords) {
......@@ -316,7 +316,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
r.putAll(moreRecords);
record = PackedMap.of(r);
ref = null;
onLoad();
compact();
}
public String getIconFileName() {
......@@ -342,15 +342,16 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
return record;
}
public void onLoad() {
if (build == null) {
return;
}
if (build.getParent() == null) {
logger.warning("JENKINS-16845: broken FingerprintAction record");
build = null;
return;
}
@Override public void onLoad(Run<?,?> r) {
build = (AbstractBuild) r;
compact();
}
@Override public void onAttached(Run<?,?> r) {
// for historical reasons this setup is done in the constructor instead
}
private void compact() {
// share data structure with nearby builds, but to keep lazy loading efficient,
// don't go back the history forever.
if (rand.nextInt(2)!=0) {
......@@ -363,12 +364,6 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
}
}
public void onAttached(Run r) {
}
public void onBuildComplete() {
}
/**
* Reuse string instances from another {@link FingerprintAction} to reduce memory footprint.
*/
......@@ -438,11 +433,6 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
public Map<AbstractProject,Integer> getDependencies(boolean includeMissing) {
Map<AbstractProject,Integer> r = new HashMap<AbstractProject,Integer>();
if (build == null) {
// Broken, do not do anything.
return r;
}
for (Fingerprint fp : getFingerprints().values()) {
BuildPtr bp = fp.getOriginal();
if(bp==null) continue; // outside Hudson
......
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.model;
import hudson.model.Action;
import hudson.model.Run;
/**
* Optional interface for {@link Action}s that add themselves to a {@link Run}.
* @since 1.519
*/
public interface RunAction2 extends Action {
/**
* Called when this action is {@linkplain Run#addAction added to a build}.
*/
void onAttached(Run<?,?> r);
/**
* Called after a {@linkplain Run#onLoad build is loaded} to which this action was previously {@linkplain #onAttached attached}.
*/
void onLoad(Run<?,?> r);
}
......@@ -30,9 +30,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<l:layout>
<j:if test="${it.build != null}">
<st:include it="${it.build}" page="sidepanel.jelly"/>
</j:if> <!-- else broken -->
<st:include it="${it.build}" page="sidepanel.jelly"/>
<l:main-panel>
<h1>
<img src="${imagesURL}/48x48/fingerprint.png" alt="" height="48" width="48"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册