package hudson.plugins.promoted_builds;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.InvisibleAction;

/**
 * Remembers what build it's promoting. Attached to {@link Promotion}.
 *
 * @author Kohsuke Kawaguchi
 */
public class PromotionTargetAction extends InvisibleAction {
    private final String jobName;
    private final int number;

    public PromotionTargetAction(AbstractBuild<?,?> build) {
        jobName = build.getParent().getFullName();
        number = build.getNumber();
    }

    public AbstractBuild<?,?> resolve() {
        AbstractProject<?,?> j = Hudson.getInstance().getItemByFullName(jobName, AbstractProject.class);
        if (j==null)    return null;
        return j.getBuildByNumber(number);
    }

    public AbstractBuild<?,?> resolve(PromotionProcess parent) {
        AbstractProject<?,?> j = parent.getOwner();
        if (j==null)    return null;
        return j.getBuildByNumber(number);
    }

    public AbstractBuild<?,?> resolve(Promotion parent) {
        return resolve(parent.getParent());
    }
}

@@ -498,20 +498,21 @@
 ild.getP
-aren
+rojec
 t().getF
@@ -872,133 +872,24 @@
     
-    AbstractProject%3C?,?%3E j = parent.getOwner();%0A        if (j==null)    return null;%0A        return j.getBuildByNumber(number
+%09return resolve(
 );%0A 
@@ -952,28 +952,25 @@
 rent) %7B%0A    
-    
+%09
 return resol
@@ -976,26 +976,8 @@
 lve(
-parent.getParent()
 );%0A 

Resolve build.