Skip to content
Permalink
Browse files
[JENKINS-49237] - Stop serializing AbstractBuilds in Statistic and St…
…atisticsResult
  • Loading branch information
oleg-nenashev committed Jan 30, 2018
1 parent 0ddbdc1 commit 68810b3da5e27f3ab7e31a235fede07985e746f4
@@ -1,11 +1,13 @@
package hudson.plugins.cppncss.parser;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractBuild;
import hudson.util.IOException2;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import javax.annotation.CheckForNull;
import java.io.*;
import java.util.*;

@@ -16,10 +18,16 @@
* @author Shaohua Wen
* @since 25-Feb-2008 21:33:40
*/
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID", justification = "Not used in XStream")
public class Statistic implements Serializable {
// ------------------------------ FIELDS ------------------------------

private AbstractBuild<?, ?> owner;
/**
* @deprecated this field should not be used
*/
@CheckForNull
private transient AbstractBuild<?, ?> owner;

private String name;
private long functions;
private long ncss;
@@ -302,6 +310,11 @@ public void setNcss(long ncss) {
this.ncss = ncss;
}

/**
* @deprecated this field is not really supposed to be used.
*/
@Deprecated
@CheckForNull
public AbstractBuild<?, ?> getOwner() {
return owner;
}
@@ -1,19 +1,27 @@
package hudson.plugins.cppncss.parser;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractBuild;

import javax.annotation.CheckForNull;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID", justification = "Not used in XStream")
public class StatisticsResult implements Serializable {

//cppncss function results
private Collection<Statistic> functionResults = Collections.emptySet();
//cppncss file results
private Collection<Statistic> fileResults = Collections.emptySet();

private AbstractBuild<?, ?> owner;

/**
* @deprecated this field should not be used
*/
@Deprecated
@CheckForNull
private transient AbstractBuild<?, ?> owner;

public void setFunctionResults(Collection<Statistic> functionResults) {
this.functionResults = functionResults;
@@ -51,6 +59,11 @@ public void clear() {
fileResults.clear();
}

/**
* @deprecated Should not be used.
*/
@Deprecated
@CheckForNull
public AbstractBuild<?, ?> getOwner() {
return owner;
}
@@ -3,8 +3,10 @@
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.HealthReportingAction;
import hudson.model.Run;
import hudson.plugins.cppncss.parser.StatisticSummary;
import hudson.plugins.cppncss.parser.StringStatisticSummary;
import jenkins.model.RunAction2;

import java.io.Serializable;

@@ -16,7 +18,7 @@
* @since 04-Feb-2008 19:41:25
*/
public abstract class AbstractBuildAction<BUILD extends AbstractBuild<?, ?>>
implements HealthReportingAction, Serializable
implements HealthReportingAction, Serializable, RunAction2
{
/** Unique identifier for this class. */
private static final long serialVersionUID = 31415926L;
@@ -25,7 +27,7 @@
* The owner of this Action. Ideally I'd like this to be final and set in the constructor, but Maven does not
* let us do that, so we need a setter.
*/
private BUILD build = null;
private transient BUILD build = null;

/**
* Constructs a new AbstractBuildAction.
@@ -54,6 +56,26 @@ public synchronized void setBuild(BUILD build) {
}
}

private BUILD runToBuild(Run<?, ?> run) throws IllegalStateException {
final BUILD b;
try {
b = (BUILD)run;
} catch (ClassCastException ex) {
throw new IllegalStateException("Action is attached to a wrong job type for run " + run.getFullDisplayName(), ex);
}
return b;
}

@Override
public final void onAttached(Run<?, ?> r) {
setBuild(runToBuild(r));
}

@Override
public final void onLoad(Run<?, ?> r) {
setBuild(runToBuild(r));
}

/**
* Override to control when the floating box should be displayed.
*

0 comments on commit 68810b3

Please sign in to comment.