diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java
index e9c01f8a49..cc2b36387d 100644
--- a/core/src/main/java/hudson/model/AbstractProject.java
+++ b/core/src/main/java/hudson/model/AbstractProject.java
@@ -3,7 +3,8 @@
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
* Brian Westrich, Erik Ramfelt, Ertan Deniz, Jean-Baptiste Quenot,
- * Luca Domenico Milanesio, R. Tyler Ballance, Stephen Connolly, Tom Huybrechts, id:cactusman
+ * Luca Domenico Milanesio, R. Tyler Ballance, Stephen Connolly, Tom Huybrechts,
+ * id:cactusman, Yahoo! Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +26,8 @@
*/
package hudson.model;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import antlr.ANTLRException;
import hudson.AbortException;
import hudson.CopyOnWrite;
@@ -1763,6 +1766,63 @@ public abstract class AbstractProject
,R extends A
return FormValidation.warning("There's no slave/cloud that matches this assignment");
return FormValidation.ok();
}
+
+ public AutoCompletionCandidates doAutoCompleteAssignedLabelString(@QueryParameter String value) {
+ AutoCompletionCandidates c = new AutoCompletionCandidates();
+ Set labels = Hudson.getInstance().getLabels();
+ List queries = new AutoCompleteSeeder(value).getSeeds();
+
+ for (String term : queries) {
+ for (Label l : labels) {
+ if (l.getName().startsWith(term)) {
+ c.add(l.getName());
+ }
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Utility class for taking the current input value and computing a list
+ * of potential terms to match against the list of defined labels.
+ */
+ static class AutoCompleteSeeder {
+ private String source;
+ private Pattern quoteMatcher = Pattern.compile("(\\\"?)(.+?)(\\\"?+)(\\s*)");
+
+ AutoCompleteSeeder(String source) {
+ this.source = source;
+ }
+
+ List getSeeds() {
+ ArrayList terms = new ArrayList();
+ boolean trailingQuote = source.endsWith("\"");
+ boolean leadingQuote = source.startsWith("\"");
+ boolean trailingSpace = source.endsWith(" ");
+
+ if (trailingQuote || (trailingSpace && !leadingQuote)) {
+ terms.add("");
+ } else {
+ if (leadingQuote) {
+ int quote = source.lastIndexOf('"');
+ if (quote == 0) {
+ terms.add(source.substring(1));
+ } else {
+ terms.add("");
+ }
+ } else {
+ int space = source.lastIndexOf(' ');
+ if (space > -1) {
+ terms.add(source.substring(space+1));
+ } else {
+ terms.add(source);
+ }
+ }
+ }
+
+ return terms;
+ }
+ }
}
/**
diff --git a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
index 7d5c2ae4cb..fb40c91665 100644
--- a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
+++ b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
@@ -1,7 +1,8 @@
diff --git a/core/src/test/java/hudson/model/AutoCompleteSeederTest.java b/core/src/test/java/hudson/model/AutoCompleteSeederTest.java
new file mode 100644
index 0000000000..256938165a
--- /dev/null
+++ b/core/src/test/java/hudson/model/AutoCompleteSeederTest.java
@@ -0,0 +1,86 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2010 Yahoo! Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package hudson.model;
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.runners.Parameterized;
+import org.junit.runner.RunWith;
+import hudson.model.AbstractProject.AbstractProjectDescriptor.AutoCompleteSeeder;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author dty
+ */
+@RunWith(Parameterized.class)
+public class AutoCompleteSeederTest {
+
+ public static class TestData {
+ private String seed;
+ private List expected;
+
+ public TestData(String seed, String... expected) {
+ this.seed = seed;
+ this.expected = Arrays.asList(expected);
+ }
+ }
+
+ @Parameterized.Parameters
+ public static Collection data() {
+ return Arrays.asList( new Object[][] {
+ { new TestData("", "") },
+ { new TestData("\"", "") },
+ { new TestData("\"\"", "") },
+ { new TestData("freebsd", "freebsd") },
+ { new TestData(" freebsd", "freebsd") },
+ { new TestData("freebsd ", "") },
+ { new TestData("freebsd 6", "6") },
+ { new TestData("\"freebsd", "freebsd") },
+ { new TestData("\"freebsd ", "freebsd ") },
+ { new TestData("\"freebsd\"", "") },
+ { new TestData("\"freebsd\" ", "") },
+ { new TestData("\"freebsd 6", "freebsd 6") },
+ { new TestData("\"freebsd 6\"", "") },
+ });
+ }
+
+ private String seed;
+ private List expected;
+
+ public AutoCompleteSeederTest(TestData dataSet) {
+ this.seed = dataSet.seed;
+ this.expected = dataSet.expected;
+ }
+
+ @Test
+ public void testAutoCompleteSeeds() throws Exception {
+ AutoCompleteSeeder seeder = new AbstractProject.AbstractProjectDescriptor.AutoCompleteSeeder(seed);
+ assertEquals(expected, seeder.getSeeds());
+
+ }
+}
\ No newline at end of file
diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js
index 097ea3a0a0..0647d5f1ef 100644
--- a/war/src/main/webapp/scripts/hudson-behavior.js
+++ b/war/src/main/webapp/scripts/hudson-behavior.js
@@ -605,6 +605,7 @@ var hudsonRules = {
ac.animSpeed = 0;
ac.useShadow = true;
ac.autoSnapContainer = true;
+ ac.delimChar = e.getAttribute("autoCompleteDelimiChar");
ac.doBeforeExpandContainer = function(textbox,container) {// adjust the width every time we show it
container.style.width=textbox.clientWidth+"px";
var Dom = YAHOO.util.Dom;