Skip to content

Commit

Permalink
[FIXED JENKINS-20514] Add a core extension point to allow plugins to …
Browse files Browse the repository at this point in the history
…contribute to the checking of assigned labels
  • Loading branch information
stephenc committed Nov 11, 2013
1 parent d7b031a commit beffcd6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -29,6 +29,7 @@

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.EnvVars;
import hudson.ExtensionPoint;
import hudson.Functions;
import antlr.ANTLRException;
import hudson.AbortException;
Expand Down Expand Up @@ -103,6 +104,7 @@
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.ForwardToView;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
Expand Down Expand Up @@ -2209,7 +2211,8 @@ public boolean isApplicable(Descriptor descriptor) {
return true;
}

public FormValidation doCheckAssignedLabelString(@QueryParameter String value) {
public FormValidation doCheckAssignedLabelString(@AncestorInPath AbstractProject<?,?> project,
@QueryParameter String value) {
if (Util.fixEmpty(value)==null)
return FormValidation.ok(); // nothing typed yet
try {
Expand All @@ -2228,6 +2231,12 @@ public FormValidation doCheckAssignedLabelString(@QueryParameter String value) {
}
return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch());
}
for (AbstractProject.LabelValidator v: Jenkins.getInstance().getExtensionList(AbstractProject.LabelValidator.class)) {
FormValidation result = v.check(project, l);
if (!FormValidation.Kind.OK.equals(result.kind)) {
return result;
}
}
return FormValidation.ok();
}

Expand Down Expand Up @@ -2384,5 +2393,13 @@ public void setCustomWorkspace(String customWorkspace) throws IOException {
this.customWorkspace= Util.fixEmptyAndTrim(customWorkspace);
save();
}

/**
* Plugins may want to contribute additional restrictions on the use of specific labels for specific projects.
* This extension point allows such restrictions
*/
public static abstract class LabelValidator implements ExtensionPoint {
public abstract FormValidation check(@CheckForNull AbstractProject<?,?> project, @Nonnull Label label);
}

}

0 comments on commit beffcd6

Please sign in to comment.