// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestriction.java
// public abstract class JobRestriction implements ExtensionPoint, Describable<JobRestriction>, Serializable {
//     
//     public static final JobRestriction DEFAULT = new AnyJobRestriction();
//     
//     /**
//      * Check if the {@link Queue} item can be taken.
//      * This method is being used to check if the {@link Node} can take the
//      * specified job. If the job cannot be taken, Jenkins will try to launch 
//      * the job on other nodes.
//      * @param item An item to be checked
//      * @return true if the node can take the item
//      */
//     public abstract boolean canTake(@Nonnull Queue.BuildableItem item);
//         
//     /**
//      * Check if the {@link Job} can be executed according to the specified {@link Run}.
//      * If the job cannot be executed, it will be aborted by the plugin.
//      * @param run A {@link Run} to be checked 
//      * @return true if the build can be executed
//      */
//     public abstract boolean canTake(@Nonnull Run run);
// 
//     @Override
//     public JobRestrictionDescriptor getDescriptor() {
//         return (JobRestrictionDescriptor) JenkinsHelper.getInstanceOrDie().getDescriptorOrDie(getClass());
//     }
// 
//     /**
//      * Get list of all registered {@link JobRestriction}s.
//      * @return List of {@link JobRestriction}s.
//      */    
//     public static DescriptorExtensionList<JobRestriction,JobRestrictionDescriptor> all() {
//         return JenkinsHelper.getInstanceOrDie().<JobRestriction,JobRestrictionDescriptor>getDescriptorList
//             (JobRestriction.class);
//     }
//     
//     /**
//      * Returns list of {@link JobRestrictionDescriptor}s.
//      * @return List of available descriptors.
//      * @since 0.2
//      */
//     public static List<JobRestrictionDescriptor> allDescriptors() {
//         return all().reverseView();
//     }
//     
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestrictionDescriptor.java
// public abstract class JobRestrictionDescriptor extends Descriptor<JobRestriction> {
//     public JobRestrictionDescriptor getDefaultSettingsProvider() {
//         return (JobRestrictionDescriptor)JobRestriction.all().find(AnyJobRestriction.class);
//     } 
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/QueueHelper.java
// @Restricted(NoExternalUse.class)
// public class QueueHelper {
// 
//     //TODO: Optimize by StringBuilder
//     /**
//      * Generates job-style project name for the buildable item
//      * @deprecated Just a hack, will be removed in the future versions
//      * @param item Item, for which the name should be retrieved
//      * @return String in the {@link Job#getFullName()} format (a/b/c/d)
//      */
//     @Deprecated
//     public static String getFullName(@Nonnull Queue.BuildableItem item) {
//         Queue.Task current = item.task;
//         String res = getItemName(current);
// 
//         // this is only executed if we didn't call Item.getFullName() in getItemName
//         while (!(current instanceof Item)) {
//             Queue.Task parent = current.getOwnerTask();
//             if (parent == current || parent == null) {
//                 break;
//             }
//             res = getItemName(parent) + "/" + res;
//             current = parent;
//         }
//         return res;
//     }
// 
//     private static String getItemName(Queue.Task task) {
//         if (task instanceof Item) {
//             Item stub = (Item)task;
//             return stub.getFullName();
//         } else {
//             return task.getName();
//         }
//     }
// }


import hudson.util.FormValidation;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util.QueueHelper;
import hudson.Extension;
import hudson.model.Queue;
import hudson.model.Run;
    }

    public String getRegexExpression() {
        return regexExpression;
    }

    public boolean isCheckShortName() {
        return checkShortName;
    }
    
    @Override
    public boolean canTake(Queue.BuildableItem item) {
        //FIXME: switch to  the "getFullName" in the future
        return canTake(QueueHelper.getFullName(item));
    }
    
    @Override
    public boolean canTake(Run run) {
        return canTake(run.getParent().getFullName());
    }
    
    public boolean canTake(String projectName) {
        try {
            return projectName.matches(regexExpression);
        } catch (PatternSyntaxException ex) {
            return true; // Ignore invalid pattern
        }
    }
    
    @Extension
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestriction.java
// public abstract class JobRestriction implements ExtensionPoint, Describable<JobRestriction>, Serializable {
//     
//     public static final JobRestriction DEFAULT = new AnyJobRestriction();
//     
//     /**
//      * Check if the {@link Queue} item can be taken.
//      * This method is being used to check if the {@link Node} can take the
//      * specified job. If the job cannot be taken, Jenkins will try to launch 
//      * the job on other nodes.
//      * @param item An item to be checked
//      * @return true if the node can take the item
//      */
//     public abstract boolean canTake(@Nonnull Queue.BuildableItem item);
//         
//     /**
//      * Check if the {@link Job} can be executed according to the specified {@link Run}.
//      * If the job cannot be executed, it will be aborted by the plugin.
//      * @param run A {@link Run} to be checked 
//      * @return true if the build can be executed
//      */
//     public abstract boolean canTake(@Nonnull Run run);
// 
//     @Override
//     public JobRestrictionDescriptor getDescriptor() {
//         return (JobRestrictionDescriptor) JenkinsHelper.getInstanceOrDie().getDescriptorOrDie(getClass());
//     }
// 
//     /**
//      * Get list of all registered {@link JobRestriction}s.
//      * @return List of {@link JobRestriction}s.
//      */    
//     public static DescriptorExtensionList<JobRestriction,JobRestrictionDescriptor> all() {
//         return JenkinsHelper.getInstanceOrDie().<JobRestriction,JobRestrictionDescriptor>getDescriptorList
//             (JobRestriction.class);
//     }
//     
//     /**
//      * Returns list of {@link JobRestrictionDescriptor}s.
//      * @return List of available descriptors.
//      * @since 0.2
//      */
//     public static List<JobRestrictionDescriptor> allDescriptors() {
//         return all().reverseView();
//     }
//     
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/JobRestrictionDescriptor.java
// public abstract class JobRestrictionDescriptor extends Descriptor<JobRestriction> {
//     public JobRestrictionDescriptor getDefaultSettingsProvider() {
//         return (JobRestrictionDescriptor)JobRestriction.all().find(AnyJobRestriction.class);
//     } 
// }
// 
// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/QueueHelper.java
// @Restricted(NoExternalUse.class)
// public class QueueHelper {
// 
//     //TODO: Optimize by StringBuilder
//     /**
//      * Generates job-style project name for the buildable item
//      * @deprecated Just a hack, will be removed in the future versions
//      * @param item Item, for which the name should be retrieved
//      * @return String in the {@link Job#getFullName()} format (a/b/c/d)
//      */
//     @Deprecated
//     public static String getFullName(@Nonnull Queue.BuildableItem item) {
//         Queue.Task current = item.task;
//         String res = getItemName(current);
// 
//         // this is only executed if we didn't call Item.getFullName() in getItemName
//         while (!(current instanceof Item)) {
//             Queue.Task parent = current.getOwnerTask();
//             if (parent == current || parent == null) {
//                 break;
//             }
//             res = getItemName(parent) + "/" + res;
//             current = parent;
//         }
//         return res;
//     }
// 
//     private static String getItemName(Queue.Task task) {
//         if (task instanceof Item) {
//             Item stub = (Item)task;
//             return stub.getFullName();
//         } else {
//             return task.getName();
//         }
//     }
// }


// Path: src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/job/RegexNameRestriction.java
import hudson.util.FormValidation;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util.QueueHelper;
import hudson.Extension;
import hudson.model.Queue;
import hudson.model.Run;

    }

    public String getRegexExpression() {
        return regexExpression;
    }

    public boolean isCheckShortName() {
        return checkShortName;
    }
    
    @Override
    public boolean canTake(Queue.BuildableItem item) {
        //FIXME: switch to  the "getFullName" in the future
        return canTake(QueueHelper.getFullName(item));
    }
    
    @Override
    public boolean canTake(Run run) {
        return canTake(run.getParent().getFullName());
    }
    
    public boolean canTake(String projectName) {
        try {
            return projectName.matches(regexExpression);
        } catch (PatternSyntaxException ex) {
            return true; // Ignore invalid pattern
        }
    }
    
    @Extension
    public static class DescriptorImpl extends JobRestrictionDescriptor {