提交 a6914c52 编写于 作者: O Oliver Gondža

Merge pull request #1009 from stephenc/master

[FIXED JENKINS-20514] Add a core extension point to allow plugins to con...
......@@ -84,6 +84,10 @@ Upcoming changes</a>
<li class=bug>
Global search box now remembers entered text
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18192">issue 18192</a>)
<li class=rfe>
Add extension point to allow plugins to contribute to the checking of
assigned labels.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20514">issue 20514</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -29,6 +29,7 @@ package hudson.model;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.EnvVars;
import hudson.ExtensionPoint;
import hudson.Functions;
import antlr.ANTLRException;
import hudson.AbortException;
......@@ -103,6 +104,7 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
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;
......@@ -2209,7 +2211,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
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 {
......@@ -2228,6 +2231,15 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch());
}
if (project != null) {
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();
}
......@@ -2384,5 +2396,23 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
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.
*
* @since 1.540
*/
public static abstract class LabelValidator implements ExtensionPoint {
/**
* Check the use of the label within the specified context.
*
* @param project the project that wants to restrict itself to the specified label.
* @param label the label that the project wants to restrict itself to.
* @return the {@link FormValidation} result.
*/
@Nonnull
public abstract FormValidation check(@Nonnull AbstractProject<?, ?> project, @Nonnull Label label);
}
}
......@@ -233,11 +233,11 @@ public class LabelExpressionTest extends HudsonTestCase {
Label l = jenkins.getLabel("foo");
DumbSlave s = createSlave(l);
String msg = d.doCheckAssignedLabelString("goo").renderHtml();
String msg = d.doCheckAssignedLabelString(null, "goo").renderHtml();
assertTrue(msg.contains("foo"));
assertTrue(msg.contains("goo"));
msg = d.doCheckAssignedLabelString("master && goo").renderHtml();
msg = d.doCheckAssignedLabelString(null, "master && goo").renderHtml();
assertTrue(msg.contains("foo"));
assertTrue(msg.contains("goo"));
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册