Skip to content
Permalink
Browse files

[FIXED JENKINS-16917] do not extends BuildTrigger.DescriptorImpl

  • Loading branch information
kutzi committed Feb 21, 2013
1 parent 351a350 commit a695bc2741ec539684ce4ad31b28f47de9f7371e
@@ -25,41 +25,50 @@

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixAggregatable;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.AutoCompletionCandidates;
import hudson.model.BuildListener;
import hudson.model.DependecyDeclarer;
import hudson.model.DependencyGraph;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Items;
import hudson.model.Project;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.Project;
import hudson.model.listeners.ItemListener;
import hudson.plugins.downstream_ext.DownstreamTrigger.DescriptorImpl.ItemListenerImpl;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.BuildTrigger;
import hudson.tasks.Messages;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;

import hudson.tasks.BuildTrigger;
import hudson.util.FormValidation;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

/**
@@ -292,8 +301,8 @@ private Object readResolve() {

@Extension
// for some reason when running mvn from commandline the build fails,
// if BuildTrigger is not fully qualified here!?
public static class DescriptorImpl extends hudson.tasks.BuildTrigger.DescriptorImpl {
// if the class names are not fully qualified here!?
public static class DescriptorImpl extends hudson.tasks.BuildStepDescriptor<hudson.tasks.Publisher> {

public static final String[] THRESHOLD_VALUES = {
Result.SUCCESS.toString(), Result.UNSTABLE.toString(),
@@ -312,10 +321,56 @@ private Object readResolve() {

public static final Strategy[] STRATEGY_VALUES = Strategy.values();

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

@Override
public String getDisplayName() {
return hudson.plugins.downstream_ext.Messages.DownstreamTrigger_DisplayName();
}

/**
* Form validation method.
*/
public FormValidation doCheck(@AncestorInPath Item project, @QueryParameter String value ) {
// Require CONFIGURE permission on this project
if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok();

StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),",");
boolean hasProjects = false;
while(tokens.hasMoreTokens()) {
String projectName = tokens.nextToken().trim();
if (StringUtils.isNotBlank(projectName)) {
Item item = Jenkins.getInstance().getItem(projectName,project,Item.class);
if(item==null)
return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName,
AbstractProject.findNearest(projectName,project.getParent()).getRelativeNameFrom(project)));
if(!(item instanceof AbstractProject))
return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName));
hasProjects = true;
}
}
if (!hasProjects) {
return FormValidation.error(Messages.BuildTrigger_NoProjectSpecified());
}

return FormValidation.ok();
}

public AutoCompletionCandidates doAutoCompleteChildProjects(@QueryParameter String value) {
AutoCompletionCandidates candidates = new AutoCompletionCandidates();
List<Job> jobs = Jenkins.getInstance().getItems(Job.class);
for (Job job: jobs) {
if (job.getFullName().startsWith(value)) {
if (job.hasPermission(Item.READ)) {
candidates.add(job.getFullName());
}
}
}
return candidates;
}

This comment has been minimized.

Copy link
@jglick

jglick Feb 21, 2013

Member

None of this is necessary; you can just use descriptorByName/hudson.tasks.BuildTrigger/… for the check & complete URLs.

This comment has been minimized.

Copy link
@kutzi

kutzi Feb 21, 2013

Author Member

Thanks.
How is the syntax for the complete URLs parameter?

This comment has been minimized.

Copy link
@jglick

jglick Feb 21, 2013

Member

Similar to what you are already using for checkUrl below.


@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
@@ -23,8 +23,8 @@ THE SOFTWARE.
-->

<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="${%Projects to build}">
<f:textbox name="downstreamTrigger.childProjects" value="${instance.childProjectsValue}"
<f:entry title="${%Projects to build}" field="childProjects">
<f:textbox value="${instance.childProjectsValue}"
checkUrl="'descriptorByName/DownstreamTrigger/check?value='+encodeURIComponent(this.value)"/>

This comment has been minimized.

Copy link
@jglick

jglick Feb 21, 2013

Member

BTW do not use unqualified class names here.

</f:entry>
<f:entry title="${%Build result is}" description="${%Trigger downstream job if build result meets condition}">

0 comments on commit a695bc2

Please sign in to comment.
You can’t perform that action at this time.