Source:
public FormValidation doCheckDependencyJobsNames(@AncestorInPath Item project, @QueryParameter String value) { StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ","); while (tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (!projectName.equals("")) { Item item = Hudson.getInstance().getItem(projectName, project, Item.class); if ((item == null) || !(item instanceof AbstractProject)) { return FormValidation.error(hudson.model.Messages.AbstractItem_NoSuchJobExists(projectName, AbstractProject.findNearest(projectName, project.getParent()).getRelativeNameFrom(project))); } } } Set<AbstractProject> explored = new HashSet<AbstractProject>(); for (AbstractProject directDependency : DependencyQueueTaskDispatcher.getProjectsFromString(value, (Item)project)) { if (directDependency == project) { return FormValidation.error(Messages.CannotAddSelfAsDependency()); } java.util.Queue<AbstractProject> toExplore = new LinkedList<AbstractProject>(); toExplore.add(directDependency); while (toExplore.size() > 0) { AbstractProject currentlyExploring = toExplore.remove(); explored.add(currentlyExploring); GerritTrigger currentTrigger = getTrigger(currentlyExploring); if (currentTrigger == null) { continue; } String currentDependenciesString = getTrigger(currentlyExploring).getDependencyJobsNames(); List<AbstractProject> currentDependencies = DependencyQueueTaskDispatcher.getProjectsFromString( currentDependenciesString, (Item)project); if (currentDependencies == null) { continue; } for (AbstractProject dependency : currentDependencies) { if (dependency == project) { return FormValidation.error(Messages.AddingDependentProjectWouldCreateLoop( directDependency.getFullName(), currentlyExploring.getFullName())); } if (!explored.contains(dependency)) { toExplore.add(dependency); } } } } return FormValidation.ok(); }

Target:
public FormValidation doCheckDependencyJobsNames(@AncestorInPath Item project, @QueryParameter String value) { StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ","); while (tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (!projectName.equals("")) { Item item = Hudson.getInstance().getItem(projectName, project, Item.class); if ((item == null) || !(item instanceof AbstractProject)) { return FormValidation.error(hudson.model.Messages.AbstractItem_NoSuchJobExists(projectName, AbstractProject.findNearest(projectName, project.getParent()).getRelativeNameFrom(project))); } } } Set<AbstractProject> explored = new HashSet<AbstractProject>(); List<AbstractProject> directDependencies = DependencyQueueTaskDispatcher.getProjectsFromString(value, project); if (directDependencies == null) { return FormValidation.ok(); } for (AbstractProject directDependency : directDependencies) { if (directDependency.getFullName().equals(project.getFullName())) { return FormValidation.error(Messages.CannotAddSelfAsDependency()); } java.util.Queue<AbstractProject> toExplore = new LinkedList<AbstractProject>(); toExplore.add(directDependency); while (toExplore.size() > 0) { AbstractProject currentlyExploring = toExplore.remove(); explored.add(currentlyExploring); GerritTrigger currentTrigger = getTrigger(currentlyExploring); if (currentTrigger == null) { continue; } String currentDependenciesString = getTrigger(currentlyExploring).getDependencyJobsNames(); List<AbstractProject> currentDependencies = DependencyQueueTaskDispatcher.getProjectsFromString( currentDependenciesString, (Item)project); if (currentDependencies == null) { continue; } for (AbstractProject dependency : currentDependencies) { if (dependency.getFullName().equals(project.getFullName())) { return FormValidation.error(Messages.AddingDependentProjectWouldCreateLoop( directDependency.getFullName(), currentlyExploring.getFullName())); } if (!explored.contains(dependency)) { toExplore.add(dependency); } } } } return FormValidation.ok(); }