Skip to content

Commit

Permalink
[JENKINS-49237] - Stop serializing AbstractBuilds in Statistic and St…
Browse files Browse the repository at this point in the history
…atisticsResult
  • Loading branch information
oleg-nenashev committed Jan 30, 2018
1 parent 0ddbdc1 commit 68810b3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/main/java/hudson/plugins/cppncss/parser/Statistic.java
@@ -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.*;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/hudson/plugins/cppncss/parser/StatisticsResult.java
@@ -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;
Expand Down Expand Up @@ -51,6 +59,11 @@ public void clear() {
fileResults.clear();
}

/**
* @deprecated Should not be used.
*/
@Deprecated
@CheckForNull
public AbstractBuild<?, ?> getOwner() {
return owner;
}
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/hudson/plugins/helpers/AbstractBuildAction.java
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -25,7 +27,7 @@ public abstract class AbstractBuildAction<BUILD extends AbstractBuild<?, ?>>
* 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.
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 68810b3

Please sign in to comment.