@@ -19,6 +19,7 @@
import hudson .model .AbstractBuild ;
import hudson .model .AbstractProject ;
import hudson .model .Job ;
import hudson .model .Action ;
import hudson .model .Api ;
import hudson .model .Run ;
@@ -38,7 +39,7 @@
import hudson .util .Graph ;
/**
* A project action displays a link on the side panel of a project . This action
* A job action displays a link on the side panel of a job . This action
* also is responsible to render the historical trend via its associated
* 'floatingBox.jelly' view.
*
@@ -52,7 +53,7 @@
private static final Logger LOGGER = Logger .getLogger (AbstractProjectAction .class .getName ());
/** Project that owns this action. */
private final AbstractProject <?, ?> project ;
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. */
@@ -69,8 +70,8 @@
/**
* Creates a new instance of {@link AbstractProjectAction}.
*
* @param project
* the project that owns this action
* @param job
* the job that owns this action
* @param resultActionType
* the type of the result action
* @param name
@@ -84,16 +85,42 @@
* @param resultUrl
* the URL of the associated build results
*/
public AbstractProjectAction (final AbstractProject <?, ?> project , final Class <? extends T > resultActionType ,
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 .project = project ;
this .owner = job ;
this .resultActionType = resultActionType ;
this .name = name ;
this .trendName = trendName ;
this .pluginUrl = pluginUrl ;
this .iconUrl = iconUrl ;
this .resultUrl = resultUrl ;
}
/**
* Creates a new instance of {@link AbstractProjectAction}.
*
* @param project
* the project that owns this action
* @param resultActionType
* the type of the result action
* @param name
* the human readable name of this action
* @param trendName
* the human readable name of the trend graph
* @param pluginUrl
* the URL of the associated plug-in
* @param iconUrl
* 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 );
}
/**
* Gets the remote API for this action.
@@ -128,17 +155,30 @@ public String getTrendName() {
return asString (trendName );
}
/**
* Returns the owner this action belongs to.
*
* @return the owner
*/
public final Job <?, ?> getOwner () {
return owner ;
}
/**
* Returns the project this action belongs to.
*
* @return the project
*
* @deprecated use
* {@link #getOwner()}
*/
@ Deprecated
public final AbstractProject <?, ?> getProject () {
return project ;
return owner instanceof AbstractProject ? ( AbstractProject <?, ?>) owner : null ;
}
/**
* Returns the graph configuration view for this project . If the requested
* 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.
*
@@ -181,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 ());
}
/**
@@ -283,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 ());
}
@@ -293,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 ());
}
@@ -303,12 +343,12 @@ protected GraphConfigurationView createDefaultConfiguration() {
* @return build history
*/
protected BuildHistory createBuildHistory () {
AbstractBuild <?, ?> 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 );
}
}
@@ -358,10 +398,10 @@ protected GraphConfiguration createConfiguration(final List<BuildResultGraph> av
}
/**
* Returns the icon URL for the side-panel in the project 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 project screen
* @return the icon URL for the side-panel in the owner screen
*/
@ Override
public String getIconFileName () {
@@ -378,7 +418,7 @@ public final String getUrlName() {
}
/**
* Returns whether this project 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
*/
@@ -394,43 +434,56 @@ public final boolean hasValidResults() {
*/
@ CheckForNull
public ResultAction <?> getLastAction () {
AbstractBuild <?, ?> 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 AbstractBuild <?, ?> 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 AbstractBuild <?, ?> getLastFinishedBuild () {
if (project == null ) {
public Run <?, ?> getLastFinishedRun () {
if (owner == null ) {
return null ;
}
AbstractBuild <?, ?> lastBuild = project .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 ();
}
/**
@@ -444,14 +497,14 @@ protected T getResultAction(final AbstractBuild<?, ?> lastBuild) {
* in case of an error
*/
public void doIndex (final StaplerRequest request , final StaplerResponse response ) throws IOException {
AbstractBuild <?, ?> 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
@@ -460,10 +513,10 @@ 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 ) {
this (project , resultActionType , null , null , plugin .getPluginName (), plugin .getIconUrl (), plugin .getPluginResultUrlName ());
this (( Job <?, ?>) project , resultActionType , null , null , plugin .getPluginName (), plugin .getIconUrl (), plugin .getPluginResultUrlName ());
}
}