Skip to content

Commit

Permalink
[FIXED JENKINS-14560] Downstream jobs textbox is now auto-complete-ca…
Browse files Browse the repository at this point in the history
…pable
  • Loading branch information
ohtake committed Aug 16, 2012
1 parent c06d1c9 commit 1653a48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
@@ -1,15 +1,18 @@
package hudson.plugins.promoted_builds.conditions;

import com.google.common.collect.Lists;
import hudson.CopyOnWrite;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.AutoCompletionCandidates;
import hudson.model.Cause.UpstreamCause;
import hudson.model.Fingerprint;
import hudson.model.Fingerprint.BuildPtr;
import hudson.model.Hudson;
import hudson.model.InvisibleAction;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Result;
import hudson.model.Run;
Expand All @@ -20,7 +23,10 @@
import hudson.plugins.promoted_builds.PromotionCondition;
import hudson.plugins.promoted_builds.PromotionConditionDescriptor;
import hudson.plugins.promoted_builds.PromotionProcess;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
Expand Down Expand Up @@ -147,6 +153,33 @@ public PromotionCondition newInstance(StaplerRequest req, JSONObject formData) t
return new DownstreamPassCondition(
formData.getString("jobs"), formData.getBoolean("evenIfUnstable"));
}

public AutoCompletionCandidates doAutoCompleteJobs(@QueryParameter String value, @AncestorInPath AbstractProject project) {
List<AbstractProject> downstreams = project.getDownstreamProjects();
List<Item> all = Jenkins.getInstance().getItems(Item.class);
List<String> candidatesDownstreams = Lists.newArrayList();
List<String> candidatesOthers = Lists.newArrayList();
for (Item i : all) {
if (i.getFullName().startsWith(value)) {

This comment has been minimized.

Copy link
@jglick

jglick Aug 16, 2012

Member

Note that getJobList treats entries in jobs as potentially relative to the containing folder, so ideally this would also complete items in the same folder using short names.

This comment has been minimized.

Copy link
@ohtake

ohtake Aug 16, 2012

Author Member

Fixed in 9542efc. Thank you.

if (i.hasPermission(Item.READ)) {
if(downstreams.contains(i)) {
candidatesDownstreams.add(i.getFullName());
}else{
candidatesOthers.add(i.getFullName());
}
}
}
}
AutoCompletionCandidates candidates = new AutoCompletionCandidates();
candidates.add(candidatesDownstreams.toArray(new String[0]));
if(candidatesDownstreams.size() > 0 && candidatesOthers.size() > 0) {
candidates.add("- - -");
}
// Downstream jobs might not be set when user wants to set DownstreamPassCondition.
// Better to show non-downstream candidates even if they are not downstreams at the moment.
candidates.add(candidatesOthers.toArray(new String[0]));
return candidates;
}
}

/**
Expand Down
@@ -1,6 +1,6 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Job names">
<f:textbox name="promotion.downstream.jobs" value="${instance.jobs}" />
<f:textbox field="jobs" autoCompleteDelimChar=","/>
</f:entry>
<f:entry>
<f:checkbox name="promotion.downstream.evenIfUnstable" checked="${instance.evenIfUnstable}"/>
Expand Down

0 comments on commit 1653a48

Please sign in to comment.