package org.jvnet.hudson.plugins.triggers.startup;

import hudson.model.Node;

import java.io.Serializable;

/**
 * @author Gregory Boissinot
 */
public class HudsonStartupService implements Serializable {

    public boolean has2Schedule(HudsonStartupTrigger startupTrigger, Node jobNode) {

        if (startupTrigger == null) {
            throw new NullPointerException("A startupTrigger object has to be set.");
        }
        if (jobNode == null) {
            throw new NullPointerException("A node object has to be set.");
        }

        String triggerLabel = startupTrigger.getLabel();

        return has2Schedule(triggerLabel, jobNode);
    }

    private boolean has2Schedule(String triggerLabel, Node jobNode) {

        String jobNodeName = jobNode.getNodeName();

        if (triggerLabel == null) { //Jobs on master has to schedule
            return isMaster(jobNodeName);
        }

        if (triggerLabel.equalsIgnoreCase("master")) { //User set 'master' string, Jobs on master has to schedule
            return isMaster(jobNodeName);
        }

        if (triggerLabel.equalsIgnoreCase(jobNodeName)) { //Match exactly node name
            return true;
        }

        return triggerLabel.equalsIgnoreCase(jobNode.getLabelString());  //Match node label
    }

    private boolean isMaster(String nodeName) {
        //Master node name is "", slave node name is never empty
        return nodeName.equals("");
    }

}

@@ -1196,23 +1196,147 @@
         
-return 
+String labelString = jobNode.getLabelString();%0A        if (labelString == null) %7B%0A            return false;%0A        %7D%0A%0A        if (
 triggerL
@@ -1357,28 +1357,17 @@
 oreCase(
-jobNode.getL
+l
 abelStri
@@ -1372,13 +1372,12 @@
 ring
-(
 ))
-;
  
+%7B
  //M
@@ -1392,16 +1392,103 @@
 e label%0A
+            return true;%0A        %7D%0A%0A        return labelString.contains(triggerLabel);%0A
     %7D%0A%0A 

Enable to specify a string for the trigger label as a substring of the node label. For example a node label with "WinXP Acceptance London" and 'Restricted node Label = London'