Version Differences for Miscellaneous Scripts

(AHPSCRIPTS-38)
(AHPSCRIPTS-41)
Line 593:
  throw e;    throw e; 
  }</pre>    }</pre> 
       
    + = Invoke Build of Another Project and Wait for Results =  
    + This script needs to launch a build of another project that is not a dependency but treat it like it is.  
    + ==== AHPSCRIPTS-40 ====  
    + <pre>// beanshell script to mimic dependencies without actually configuring them  
       
    + import com.urbancode.anthill3.domain.buildrequest.*;  
    + import com.urbancode.anthill3.domain.project.*;  
    + import com.urbancode.anthill3.domain.security.*;  
    + import com.urbancode.anthill3.domain.workflow.*;  
    + import com.urbancode.anthill3.persistence.UnitOfWork;  
    + import com.urbancode.anthill3.runtime.scripting.helpers.*;  
    + import com.urbancode.anthill3.services.build.BuildService;  
    + import com.urbancode.anthill3.services.event.EventListener;  
    + import com.urbancode.anthill3.services.event.EventService;  
    + import com.urbancode.anthill3.services.event.criteria.Criteria;  
    + import com.urbancode.command.CommandException;  
    + import java.util.EventObject;  
       
    + //import org.apache.log4j.Logger;  
    + //log = Logger.getLogger("MasterScript");  
       
    + class BlockingEventListener implements EventListener {  
    +  
    + private BuildRequest request;  
    + private WorkflowEndEvent event;  
    + private User user;  
    +  
    + public BlockingEventListener(BuildRequest request, User user) {  
    + this.request = request;  
    + this.user = user;  
    + }  
    +  
    + public void handleEvent(EventObject event) {  
    + if (event instanceof WorkflowEndEvent) {  
    + UnitOfWork uow = null;  
    + try {  
    + uow = UnitOfWork.create(user);  
    +  
    + WorkflowEndEvent workflowEndEvent = (WorkflowEndEvent) event;  
    + if (request.equals(workflowEndEvent.getBuildRequest())) {  
    + synchronized (this) {  
    + this.event = workflowEndEvent;  
    + this.notifyAll();  
    + }  
    + }  
    + }  
    + catch (PersistenceException e) {  
    + throw new PersistenceRuntimeException(e);  
    + }  
    + finally {  
    + if (uow != null) {  
    + uow.close();  
    + }  
    + }  
    + }  
    + }  
       
    + public Class getEventClass() {  
    + return WorkflowEndEvent.class;  
    + }  
       
    + public Criteria[] getCriteria() {  
    + return null;  
    + }  
    +  
    + public void register() {  
    + EventService.getInstance().registerEventListener(this);  
    + }  
    +  
    + public void unregister() {  
    + EventService.getInstance().removeEventListener(this);  
    + }  
    +  
    + public void waitForEvent()  
    + throws InterruptedException {  
    + if (this.event == null) {  
    + synchronized (this) {  
    + this.wait();  
    + }  
    + }  
    + }  
    +  
    + public WorkflowEndEvent getEvent() {  
    + return this.event;  
    + }  
    + }  
       
    + try {  
    + thisRequest = BuildRequestLookup.getCurrent();  
    +  
    + // BEGIN SECTION TO REPEAT FOR EACH DEPENDENCY  
    + project = ProjectFactory.getInstance().restoreForName("Project C");  
    + workflow = project.getWorkflow("Wait");  
    +  
    + request = new BuildRequest(workflow.getBuildProfile(), thisRequest.getUser(), RequestSourceEnum.DEPENDENCY, thisRequest);  
    + request.setForcedFlag(true); // always build  
    + // properties can be set here as well  
    +  
    + listener = new BlockingEventListener(request, UnitOfWork.getCurrent().getUser());  
    + try {  
    + listener.register();  
    + BuildService.getInstance().runBuild(request);  
    +  
    + listener.waitForEvent();  
    +  
    + endEvent = listener.getEvent();  
    + if (endEvent.getCase().getStatus().isSuccess()) {  
    + BuildLifeLookup.getCurrent().addDependencyBuildLife(endEvent.getCase().getBuildLife());  
    + UnitOfWork.getCurrent().commit();  
    + }  
    + else {  
    + throw new CommandException("Dependency Request Failed: " + endEvent.getBuildRequest());  
    + }  
    + }  
    + finally {  
    + listener.unregister();  
    + }  
    + // END SECTION TO REPEAT FOR EACH DEPENDENCY  
    + }  
    + catch (Exception e) {  
    + throw new CommandException("Dependency Request Failed: " + e.getMessage(), e);  
    + }  
       
       
    + // continue processing the other dependencies .... </pre>