Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.downstream_ext;
  
  import hudson.model.Cause;
  import hudson.model.Run;
 
 import java.util.List;
Defines a dependency introduced by the downstream-ext plugin.

Author(s):
kutzi
 
 public class DownstreamDependency extends Dependency {
 
 	private static final Logger LOGGER = Logger.getLogger(DownstreamDependency.class.getName());
 	
 	private final DownstreamTrigger trigger;
 
 	public DownstreamDependency(AbstractProject<?, ?> upstreamAbstractProject<?, ?> downstream,
 			DownstreamTrigger trigger) {
 		super(upstreamdownstream);
 		this. = trigger;
 	}

 
 	@SuppressWarnings("unchecked")
 	public boolean shouldTriggerBuild(AbstractBuild build,
 			TaskListener listenerList<Actionactions) {
 		PrintStream logger = listener.getLogger();
             AbstractProject p = getDownstreamProject();
                 
             if(.isOnlyIfSCMChanges()) {
             	if (p.getScm().requiresWorkspaceForPolling()) {
             		// Downstream project locks workspace while building.
             		// If polled synchronously this could make the upstream build
             		// lock for a possibly long time.
             		// See HUDSON-5406
             		logger.println(Messages.DownstreamTrigger_StartedAsynchPoll(p.getName()));
             		Runnable run = getPoller(pnew Cause.UpstreamCause((Run<?,?>)build), actions);
             		DownstreamTrigger.executeForProject(prun);
             		return false;
             	}
             	
             	if (p.pollSCMChanges(listener)) {
             		return true;
             	} else {
             		logger.println(Messages.DownstreamTrigger_NoSCMChanges(p.getName()));
             		return false;
             	}
             }
             return true;
 		} else {
 			return false;
 		}
 	}
 
 	// Technically it'd be safe to not override equals
 	// since superclass implements it well.
 	// But maybe that changes in the future.
 	public boolean equals(Object obj) {
 		if (!(obj instanceof DownstreamDependency)) {
 			return false;
 		}
 		
 		// Currently, there can be only one downstream-ext dependency per project
 		// If that'd change later we must check the trigger instance here, too.
 		
 		return super.equals(obj);
 	}
 	
 	@SuppressWarnings("unchecked")
 	Runnable getPoller(AbstractProject pCause causeList<Actionactions) {
 		return new PollRunner(pcauseactions);
 	}
 	
 	@SuppressWarnings("unchecked")
 	private static class PollRunner implements Runnable {
 
 		private final AbstractProject project;
 		private final Cause cause;
 		private final List<ActionbuildActions;
		private final TaskListener taskListener;
		public PollRunner(AbstractProject pCause causeList<Actionactions) {
			this. = p;
			this. = cause;
			this. = actions;
			// workaround for HUDSON-5406:
			// some (all?) SCMs require a serializable TaskListener for AbstractProject#pollSCMChanges
			// LogTaskListener is not serializable (at least not up until Hudson 1.352)
			if (tl instanceof Serializable) {
			    this. = tl;
else {
			    this. = new StreamTaskListener(.);
			}
		}
		public void run() {
		    .info("Polling for SCM changes in " + this..getName());
				.info("SCM changes found for " + this..getName() + ". Triggering build.");
                        .toArray(new Action[.size()]))) {
					.info("Build of " + this..getName() + " scheduled successfully.");
else {
					.info("No build of " + this..getName() + " scheduled - this usually means that another build is already in the queue.");
				}
else {
			}
		}
	}
New to GrepCode? Check out our FAQ X