提交 50f84ab1 编写于 作者: K kohsuke

moved the code to Label

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18324 71c3de6d-444a-0410-be80-ed276b4c234a
上级 02bd194f
......@@ -1231,24 +1231,6 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
}
}
/**
* Convers a whitespace-separate list of tokens into a set of {@link Label}s.
*
* @param labels
* Strings like "abc def ghi". Can be empty or null.
* @return
* Can be empty but never null. A new writable set is always returned,
* so that the caller can add more to the set.
*/
public Set<Label> parseLabels(String labels) {
Set<Label> r = new HashSet<Label>();
labels = fixNull(labels);
if(labels.length()>0)
for( String l : labels.split(" +"))
r.add(getLabel(l));
return r;
}
/**
* Gets all the active labels in the current system.
*/
......@@ -1896,7 +1878,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
public Set<Label> getAssignedLabels() {
Set<Label> lset = labelSet; // labelSet may be set by another thread while we are in this method, so capture it.
if (lset == null) {
Set<Label> r = parseLabels(getLabelString());
Set<Label> r = Label.parse(getLabelString());
r.addAll(getDynamicLabels());
r.add(getSelfLabel());
this.labelSet = lset = Collections.unmodifiableSet(r);
......
......@@ -24,6 +24,7 @@
package hudson.model;
import hudson.Util;
import static hudson.Util.fixNull;
import hudson.slaves.NodeProvisioner;
import hudson.slaves.Cloud;
import org.kohsuke.stapler.export.Exported;
......@@ -305,4 +306,23 @@ public class Label implements Comparable<Label>, ModelObject {
return Hudson.getInstance().getLabel(reader.getValue());
}
}
/**
* Convers a whitespace-separate list of tokens into a set of {@link Label}s.
*
* @param labels
* Strings like "abc def ghi". Can be empty or null.
* @return
* Can be empty but never null. A new writable set is always returned,
* so that the caller can add more to the set.
* @since 1.308
*/
public static Set<Label> parse(String labels) {
Set<Label> r = new HashSet<Label>();
labels = fixNull(labels);
if(labels.length()>0)
for( String l : labels.split(" +"))
r.add(Hudson.getInstance().getLabel(l));
return r;
}
}
......@@ -227,7 +227,7 @@ public abstract class Slave extends Node implements Serializable {
public Set<Label> getAssignedLabels() {
// todo refactor to make dynamic labels a bit less hacky
if(labels==null || isChangedDynamicLabels()) {
Set<Label> r = Hudson.getInstance().parseLabels(getLabelString());
Set<Label> r = Label.parse(getLabelString());
r.add(getSelfLabel());
r.addAll(getDynamicLabels());
this.labels = Collections.unmodifiableSet(r);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册