Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-31202] To preserve backward compatibility we need to keep al…
Browse files Browse the repository at this point in the history
…l API methods unchanged.
  • Loading branch information
benjaminfuchs committed Jul 18, 2016
1 parent 05d7c5d commit e577749
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 49 deletions.
106 changes: 68 additions & 38 deletions src/main/java/hudson/plugins/analysis/core/AbstractProjectAction.java
Expand Up @@ -17,11 +17,12 @@

import jenkins.model.Jenkins;

import hudson.model.Run;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Action;
import hudson.model.Api;
import hudson.model.Run;
import hudson.plugins.analysis.graph.BuildResultGraph;
import hudson.plugins.analysis.graph.DefaultGraphConfigurationView;
import hudson.plugins.analysis.graph.DifferenceGraph;
Expand Down Expand Up @@ -52,7 +53,7 @@ public abstract class AbstractProjectAction<T extends ResultAction<?>> implement
private static final Logger LOGGER = Logger.getLogger(AbstractProjectAction.class.getName());

/** Project that owns this action. */
private final Job<?, ?> job;
private final Job<?, ?> owner;
/** The type of the result action. */
private final Class<? extends T> resultActionType;
/** The icon URL of this action: it will be shown as soon as a result is available. */
Expand Down Expand Up @@ -86,7 +87,7 @@ public abstract class AbstractProjectAction<T extends ResultAction<?>> implement
*/
public AbstractProjectAction(final Job<?, ?> job, final Class<? extends T> resultActionType,
final Localizable name, final Localizable trendName, final String pluginUrl, final String iconUrl, final String resultUrl) {
this.job = job;
this.owner = job;
this.resultActionType = resultActionType;
this.name = name;
this.trendName = trendName;
Expand All @@ -112,7 +113,10 @@ public AbstractProjectAction(final Job<?, ?> job, final Class<? extends T> resul
* the icon to show
* @param resultUrl
* the URL of the associated build results
* @deprecated use
* {@link #AbstractProjectAction(Job, Class, Localizable, Localizable, String, String, String)}
*/
@Deprecated
public AbstractProjectAction(final AbstractProject<?, ?> project, final Class<? extends T> resultActionType,
final Localizable name, final Localizable trendName, final String pluginUrl, final String iconUrl, final String resultUrl) {
this((Job<?, ?>) project, resultActionType, name, trendName, pluginUrl, iconUrl, resultUrl);
Expand Down Expand Up @@ -152,16 +156,29 @@ public String getTrendName() {
}

/**
* Returns the job this action belongs to.
* Returns the owner this action belongs to.
*
* @return the job
* @return the owner
*/
public final Job<?, ?> getProject() {
return job;
public final Job<?, ?> getOwner() {
return owner;
}

/**
* Returns the graph configuration view for this job. If the requested
* Returns the project this action belongs to.
*
* @return the project
*
* @deprecated use
* {@link #getOwner()}
*/
@Deprecated
public final AbstractProject<?, ?> getProject() {
return (AbstractProject<?, ?>) getOwner();
}

/**
* Returns the graph configuration view for this owner. If the requested
* link is neither the user graph configuration nor the default
* configuration then <code>null</code> is returned.
*
Expand Down Expand Up @@ -204,7 +221,7 @@ public Object getTrendDetails() {
* @return the details
*/
public Object getTrendDetails(final StaplerRequest request, final StaplerResponse response) {
return new TrendDetails(getProject(), getTrendGraph(request, response, "../../"), getTrendGraphId());
return new TrendDetails(getOwner(), getTrendGraph(request, response, "../../"), getTrendGraphId());
}

/**
Expand Down Expand Up @@ -306,7 +323,7 @@ public boolean canShowEnableTrendLink(final StaplerRequest request) {
* @return a view to configure the trend graph for the current user
*/
protected GraphConfigurationView createUserConfiguration(final StaplerRequest request) {
return new UserGraphConfigurationView(createConfiguration(), getProject(),
return new UserGraphConfigurationView(createConfiguration(), getOwner(),
getUrlName(), request.getCookies(), createBuildHistory());
}

Expand All @@ -316,7 +333,7 @@ protected GraphConfigurationView createUserConfiguration(final StaplerRequest re
* @return a view to configure the trend graph defaults
*/
protected GraphConfigurationView createDefaultConfiguration() {
return new DefaultGraphConfigurationView(createConfiguration(), getProject(),
return new DefaultGraphConfigurationView(createConfiguration(), getOwner(),
getUrlName(), createBuildHistory());
}

Expand All @@ -326,12 +343,12 @@ protected GraphConfigurationView createDefaultConfiguration() {
* @return build history
*/
protected BuildHistory createBuildHistory() {
Run<?, ?> lastFinishedBuild = getLastFinishedBuild();
if (lastFinishedBuild == null) {
Run<?, ?> lastFinishedRun = getLastFinishedRun();
if (lastFinishedRun == null) {
return new NullBuildHistory();
}
else {
return new BuildHistory((Run<?, ?>) lastFinishedBuild, resultActionType, false, false);
return new BuildHistory(lastFinishedRun, resultActionType, false, false);
}
}

Expand Down Expand Up @@ -381,10 +398,10 @@ protected GraphConfiguration createConfiguration(final List<BuildResultGraph> av
}

/**
* Returns the icon URL for the side-panel in the job screen. If there
* Returns the icon URL for the side-panel in the owner screen. If there
* is no valid result yet, then <code>null</code> is returned.
*
* @return the icon URL for the side-panel in the job screen
* @return the icon URL for the side-panel in the owner screen
*/
@Override
public String getIconFileName() {
Expand All @@ -401,7 +418,7 @@ public final String getUrlName() {
}

/**
* Returns whether this job has a valid result action attached.
* Returns whether this owner has a valid result action attached.
*
* @return <code>true</code> if the results are valid
*/
Expand All @@ -417,43 +434,56 @@ public final boolean hasValidResults() {
*/
@CheckForNull
public ResultAction<?> getLastAction() {
Run<?, ?> lastBuild = getLastFinishedBuild();
if (lastBuild == null) {
Run<?, ?> lastRun = getLastFinishedRun();
if (lastRun == null) {
return null;
}
else {
return getResultAction(lastBuild);
return getResultAction(lastRun);
}
}

/**
* Returns the result action for the specified build.
*
* @param lastBuild
* @param lastRun
* the build to get the action for
* @return the action or <code>null</code> if there is no such action
*/
@CheckForNull
protected T getResultAction(final Run<?, ?> lastBuild) {
return lastBuild.getAction(resultActionType);
protected T getResultAction(final Run<?, ?> lastRun) {
return lastRun.getAction(resultActionType);
}

/**
* Returns the last finished build.
* Returns the last finished run.
*
* @return the last finished build or <code>null</code> if there is no
* such build
* @return the last finished run or <code>null</code> if there is no
* such run
*/
@CheckForNull @Exported
public Run<?, ?> getLastFinishedBuild() {
if (job == null) {
public Run<?, ?> getLastFinishedRun() {
if (owner == null) {
return null;
}
Run<?, ?> lastBuild = job.getLastBuild();
while (lastBuild != null && (lastBuild.isBuilding() || getResultAction(lastBuild) == null)) {
lastBuild = lastBuild.getPreviousBuild();
Run<?, ?> lastRun = owner.getLastBuild();
while (lastRun != null && (lastRun.isBuilding() || getResultAction(lastRun) == null)) {
lastRun = lastRun.getPreviousBuild();
}
return lastBuild;
return lastRun;
}

/**
* Returns the last finished build.
*
* @return the last finished build or <code>null</code> if there is no
* such build
* @deprecated use
* {@link #getLastFinishedRun()}
*/
@Deprecated @CheckForNull @Exported
public AbstractBuild<?, ?> getLastFinishedBuild() {
return (AbstractBuild<?, ?>) getLastFinishedRun();
}

/**
Expand All @@ -467,14 +497,14 @@ protected T getResultAction(final Run<?, ?> lastBuild) {
* in case of an error
*/
public void doIndex(final StaplerRequest request, final StaplerResponse response) throws IOException {
Run<?, ?> build = getLastFinishedBuild();
if (build != null) {
response.sendRedirect2(String.format("../%d/%s", build.getNumber(), resultUrl));
Run<?, ?> lastRun = getLastFinishedRun();
if (lastRun != null) {
response.sendRedirect2(String.format("../%d/%s", lastRun.getNumber(), resultUrl));
}
}

/**
* Creates a new instance of <code>AbstractProjectAction</code>.
* Creates a new instance of {@link AbstractProjectAction}.
*
* @param project
* the project that owns this action
Expand All @@ -483,7 +513,7 @@ public void doIndex(final StaplerRequest request, final StaplerResponse response
* @param plugin
* the plug-in that owns this action
* @deprecated use
* {@link #AbstractProjectAction(AbstractProject, Class, Localizable, Localizable, String, String, String)}
* {@link #AbstractProjectAction(Job, Class, Localizable, Localizable, String, String, String)}
*/
@Deprecated
public AbstractProjectAction(final AbstractProject<?, ?> project, final Class<? extends T> resultActionType, final PluginDescriptor plugin) {
Expand Down
Expand Up @@ -9,6 +9,7 @@
import org.kohsuke.stapler.StaplerResponse;

import hudson.model.Job;
import hudson.model.AbstractProject;

import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.core.BuildHistory;
Expand Down Expand Up @@ -41,6 +42,28 @@ public DefaultGraphConfigurationView(final GraphConfiguration configuration, fin
configuration.initializeFromFile(createDefaultsFile(job, pluginName));
}

/**
* Creates a new instance of {@link DefaultGraphConfigurationView}.
*
* @param configuration
* the graph configuration
* @param project
* the owning project to configure the graphs for
* @param pluginName
* The URL of the project action (there might be a one to many mapping to this defaults view)
* @param buildHistory
* the build history for this project
* @param url
* The URL of this view
* @deprecated use
* {@link #DefaultGraphConfigurationView(GraphConfiguration, Job, String, BuildHistory, String)}
*/
@Deprecated
public DefaultGraphConfigurationView(final GraphConfiguration configuration, final AbstractProject<?, ?> project,
final String pluginName, final BuildHistory buildHistory, final String url) {
this(configuration, (Job<?, ?>) project, pluginName, buildHistory, url);
}

/**
* Creates a new instance of {@link DefaultGraphConfigurationView}.
*
Expand All @@ -58,6 +81,27 @@ public DefaultGraphConfigurationView(final GraphConfiguration configuration, fin
this(configuration, job, pluginName, buildHistory,
job.getAbsoluteUrl() + pluginName + "/configureDefaults");
}

/**
* Creates a new instance of {@link DefaultGraphConfigurationView}.
*
* @param configuration
* the graph configuration
* @param project
* the owning project to configure the graphs for
* @param pluginName
* The name of the plug-in.
* @param buildHistory
* the build history for this project
* @deprecated use
* {@link #AbstractProjectAction(GraphConfiguration, Job, String, BuildHistory)}
*/
@Deprecated
public DefaultGraphConfigurationView(final GraphConfiguration configuration, final AbstractProject<?, ?> project,
final String pluginName, final BuildHistory buildHistory) {
this(configuration, (Job<?, ?>) project, pluginName, buildHistory,
project.getAbsoluteUrl() + pluginName + "/configureDefaults");
}

@Override
public String getDisplayName() {
Expand Down

0 comments on commit e577749

Please sign in to comment.