Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2005, 2007 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 
 package org.eclipse.ant.internal.ui.antsupport.logger.util;
 
 import java.util.Map;
 
 import  org.apache.tools.ant.BuildEvent;
 import  org.apache.tools.ant.Location;
 import  org.apache.tools.ant.Project;
 import  org.apache.tools.ant.Target;
 import  org.apache.tools.ant.Task;
 import  org.apache.tools.ant.taskdefs.MacroInstance;
 
 public class AntDebugState {
     
     private static final String fgAntTaskName"ant"//$NON-NLS-1$
     private static final String fgAntCallTaskName"antcall"//$NON-NLS-1$
     
 	private Stack fTasksnew Stack();
 	private Map fTaskToProxiesnew HashMap();
 	private Task fCurrentTask;
 	private Task fStepOverTask;
 	private Task fStepIntoTask;
 	private Task fLastTaskFinished;
     
 	//properties set before execution
     private Map fInitialPropertiesnull;
 	private Map fPropertiesnull;
     
     private Map fProjectToTargetNamesnull;
     private Map fProjectToMapOfTargetToBuildSequencenull;
     private Stack fTargetsToExecutenew Stack();
     private Stack fTargetsExecutingnew Stack();
 	
 	private boolean fConsiderTargetBreakpointsfalse;
 	private boolean fShouldSuspend;
 	private boolean fClientSuspendfalse;
 	private boolean fStepIntoSuspendfalse;
 	private boolean fIsAfterTaskEventfalse;
 	
 	
 	public AntDebugState(IDebugBuildLogger logger) {
 		logger;
 	}
 
 	public void waitIfSuspended() {
 	}
 
 	public Task getLastTaskFinished() {
 	}
 
 	private void setLastTaskFinished(Task lastTaskFinished) {
 		lastTaskFinished;
 
 	}
 
 	public Task getCurrentTask() {
 		return ;
 	}
 
 	public void setCurrentTask(Task currentTask) {
 		currentTask;
 
 	}
 
 	private Map getInitialProperties() {
 	}
 
 	public Task getStepOverTask() {
 		return ;
 	}
 
 	public void setStepOverTask(Task stepOverTask) {
 		stepOverTask;
 
 	}
 
 	private boolean considerTargetBreakpoints() {
 	}
 
	private void setConsiderTargetBreakpoints(boolean considerTargetBreakpoints) {
		considerTargetBreakpoints;
	}
	private Stack getTasks() {
		return ;
	}
	public void setShouldSuspend(boolean shouldSuspend) {
		shouldSuspend;
	}
	public boolean shouldSuspend() {
	}
	private Map getTargetToBuildSequence(Project project) {
	}
	public void setTargetToExecute(Target target) {
        if (target == null) {
            .pop();
        } else {
            .push(target);
        }
	}
	public void setTargetExecuting(Target target) {
        if (target == null) {
            .pop();
        } else {
            .push(target);
        }
	}
	private Target getTargetToExecute() {
	    if (.isEmpty()) {
            return null;
        }
		return (Target) .peek();
	}
	private Target getTargetExecuting() {
        if (.isEmpty()) {
            return null;
        }
		return (Target) .peek();
	}
	public boolean isStepIntoSuspend() {
	}
	public void setStepIntoSuspend(boolean stepIntoSuspend) {
		 = stepIntoSuspend;
	}
	public boolean isClientSuspend() {
	}
	public void setClientSuspend(boolean clientSuspend) {
		 = clientSuspend;
	}
	public Task getStepIntoTask() {
	}
	public void setStepIntoTask(Task stepIntoTask) {
		 = stepIntoTask;
	}
	public void resume() {
	}
	public Map getProperties() {
		return ;
	}
	public Location getBreakpointLocation() {
		if (isAfterTaskEvent() && getCurrentTask() != null) {
			return getCurrentTask().getLocation();
		}
	        Target targetExecutinggetTargetExecuting();
	        if (targetExecuting != null) {
                return getLocation(targetExecuting);      
            }
		}
		return null;
	}
	private boolean isAfterTaskEvent() {
	}
	private void setAfterTaskEvent(boolean isAfterTaskEvent) {
		 = isAfterTaskEvent;
	}
	public void taskStarted(BuildEvent event) {
		if (getInitialProperties() == null) {//implicit or top level target does not fire targetStarted()
			event.getProject().getProperties();
		}
		setCurrentTask(event.getTask());
		if (!getTasks().isEmpty()) {
			//cache the parent task proxy as when that task is started or finished the
			//proxy is not yet available or is nulled out
			Task parentTask = (Task) getTasks().peek();
			Object proxy = parentTask.getRuntimeConfigurableWrapper().getProxy();
			if (proxy != null) {
				.put(parentTaskproxy);
			}
		}
	}
    public void taskFinished() {
    	Task lastTask= (Task)getTasks().pop();
        setLastTaskFinished(lastTask);
        setCurrentTask(null);
        String taskNamelastTask.getTaskName();
       
        if (getStepOverTask() != null) {
        	if ((.equals(taskName) || .equals(taskName)) && (!.equals(getStepOverTask().getTaskName()) && !.equals(getStepOverTask().getTaskName()))) {
        		setShouldSuspend(true);
        	} else if (.remove(lastTaskinstanceof MacroInstance) {
        		setShouldSuspend(true);
        	}
        }
        waitIfSuspended();
    }
    public void stepOver() {
        if (getCurrentTask() == null) {
            //stepping over target breakpoint
           setShouldSuspend(true);
        }
        resume();
    }
    public void targetStarted(BuildEvent event) {
        Project eventProject = event.getProject();
        if (getInitialProperties() == null) {
            eventProject.getProperties();
        }
        if (.get(eventProject) == null) {
            Object refeventProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
            if (ref != null) {
                .put(eventProjectref);
                Map targetToBuildSequencenew HashMap();
                setTargetToExecute(initializeBuildSequenceInformation(eventtargetToBuildSequence));
                .put(eventProjecttargetToBuildSequence);
            }
        }
        
        setTargetExecuting(event.getTarget());
        if (event.getTarget().equals(getTargetToExecute())) {
            //the dependencies of the target to execute have been met
            //prepare for the next target
            Vector targets= (Vector.get(eventProject);
            if (!targets.isEmpty()) {
                setTargetToExecute((Target) eventProject.getTargets().get(targets.remove(0)));
            } else {
                setTargetToExecute(null);
            }
        }
        setConsiderTargetBreakpoints(true);
    }
	public int getLineNumber(Location location) {
	    try { //succeeds with Ant newer than 1.6
	        return location.getLineNumber();
	    } catch (NoSuchMethodError e) {
	        //Ant before 1.6
	        String locationStringlocation.toString();
	        if (locationString.length() == 0) {
	            return 0;
	        }
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")
	        int lastIndexlocationString.lastIndexOf(':');
	        int index =locationString.lastIndexOf(':'lastIndex - 1);
	        if (index != -1) {
	            try {
	                return Integer.parseInt(locationString.substring(index+1, lastIndex));
	            } catch (NumberFormatException nfe) {
	                return 0;
	            }
	        }
	        return 0;
	    }
	}
	public static Location getLocation(Target target) {
	    try {//succeeds with Ant newer than 1.6.2
	        return target.getLocation();
	    } catch (NoSuchMethodError e) {
	        return Location.UNKNOWN_LOCATION;
	    }
	}
	public String getFileName(Location location) {
	    try {//succeeds with Ant newer than 1.6
	        return location.getFileName();
	    } catch (NoSuchMethodError e) {
	        //Ant before 1.6
	        String locationStringlocation.toString();
	        if (locationString.length() == 0) {
	            return null;
	        }
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")          
	        int lastIndexlocationString.lastIndexOf(':');
	        int index =locationString.lastIndexOf(':'lastIndex-1);
	        if (index == -1) {
	            indexlastIndex//only the filename is known
	        }
	        if (index != -1) {
	        //bug 84403
	            //if (locationString.startsWith("file:")) {
	              //  return FileUtils.newFileUtils().fromURI(locationString);
	            //}
	            //remove file:
	            return locationString.substring(5, index);
	        }
	        return null;
	    }
	}
	private void appendToStack(StringBuffer stackRepresentationString targetNameString taskName, Location location) {
	    stackRepresentation.append(targetName);
	    stackRepresentation.append(.);
	    stackRepresentation.append(taskName);
	    stackRepresentation.append(.);
	    
	    stackRepresentation.append(getFileName(location));
	    stackRepresentation.append(.);
	    stackRepresentation.append(getLineNumber(location));
	    stackRepresentation.append(.);
	}
	public void marshalStack(StringBuffer stackRepresentation) {
		Stack tasksgetTasks();
	    stackRepresentation.append(.);
	    stackRepresentation.append(.);
	    
		Target targetToExecutegetTargetToExecute();
		Target targetExecutinggetTargetExecuting();
      
        Project projectExecutingnull;
        if (targetExecuting != null) {
            projectExecutingtargetExecuting.getProject();
        } else { //no target...must be a task
            Task task= (Task) tasks.peek();
            projectExecutingtask.getProject();
        }
        
		if (!isAfterTaskEvent()) {
			appendToStack(stackRepresentationtargetExecuting.getName(), ""getLocation(targetExecuting)); //$NON-NLS-1$
		}
		for (int i = tasks.size() - 1; i >= 0 ; i--) {
			Task task= (Task) tasks.get(i);
            if (task.getProject() == projectExecuting) {
                appendToStack(stackRepresentationtask.getOwningTarget().getName(), task.getTaskName(), task.getLocation());
            } else {
                //sub build target dependencies
                String targetNametask.getOwningTarget().getName();
                if (targetName != null && targetName.length() != 0) { //skip for implicit target
                    Iterator itr.iterator();
                    while (itr.hasNext()) {
                        Target target= (Target) itr.next();
                        if (target.getProject() != projectExecuting) {
                        	targetToExecutetarget;
                            continue;
                        }
                        marshalTargetDependancyStack(stackRepresentationtargettargetExecuting);
                    }
                }
                projectExecutingtask.getProject();
                targetExecutingtask.getOwningTarget();
                appendToStack(stackRepresentationtargetExecuting.getName(), task.getTaskName(), task.getLocation());
            }
		}
		//target dependency stack 
		marshalTargetDependancyStack(stackRepresentationtargetToExecutetargetExecuting);
	}
    private void marshalTargetDependancyStack(StringBuffer stackRepresentation, Target targetToExecute, Target targetExecuting) {
        if (targetToExecute != null) {
	     	Vector buildSequence= (VectorgetTargetToBuildSequence(targetToExecute.getProject()).get(targetToExecute);
	     	int startIndexbuildSequence.indexOf(targetExecuting) + 1;
	     	int dependancyStackDepthbuildSequence.indexOf(targetToExecute);
	     	
	     	Target stackTarget;
	     	for (int i = startIndexi <= dependancyStackDepthi++) {
	     		stackTarget= (Target) buildSequence.get(i);
	            if (stackTarget.dependsOn(targetExecuting.getName())) {
	     		    appendToStack(stackRepresentationstackTarget.getName(), ""getLocation(stackTarget)); //$NON-NLS-1$
	            }
	     	}
	     }
    }
	public void marshallProperties(StringBuffer propertiesRepresentationboolean escapeLineSep) {
		if (getTasks().isEmpty()) {
			return;
		}
	    propertiesRepresentation.append(.);
	    propertiesRepresentation.append(.);
		Project project= ((Task)getTasks().peek()).getProject();
		Map lastPropertiesgetProperties(); 
	    Map currentPropertiesproject.getProperties();
	    if (lastProperties != null && currentProperties.size() == lastProperties.size()) {
	        //no new properties
	        return;
	    }
	    
		Map initialPropertiesgetInitialProperties();
	    Map currentUserPropertiesproject.getUserProperties();
	    Iterator itercurrentProperties.keySet().iterator();
	    String propertyName;
		String originalPropertyName;
	    String propertyValue;
	    while (iter.hasNext()) {
	        propertyName = (Stringiter.next();
			originalPropertyNamepropertyName;
	        if (lastProperties == null || lastProperties.get(propertyName) == null) { //new property
				if (escapeLineSep) {
					propertyNameescapeLineSeparator(propertyName);
				}
	            propertiesRepresentation.append(propertyName.length());
	            propertiesRepresentation.append(.);
	            propertiesRepresentation.append(propertyName);
	            propertiesRepresentation.append(.);
	            propertyValue= (StringcurrentProperties.get(originalPropertyName);
				if (escapeLineSep) {
					propertyValueescapeLineSeparator(propertyValue);
				}
	            propertiesRepresentation.append(propertyValue.length());
	            propertiesRepresentation.append(.);
				propertiesRepresentation.append(propertyValue);
	            propertiesRepresentation.append(.);
	            propertiesRepresentation.append(getPropertyType(initialPropertiescurrentUserPropertiesoriginalPropertyName));
	            propertiesRepresentation.append(.);
	        }
	    }
	    
	    propertiesRepresentation.deleteCharAt(propertiesRepresentation.length() - 1);
		currentProperties;
	}
	private int getPropertyType(Map initialPropertiesMap currentUserPropertiesString propertyName) {
		if (initialProperties.get(propertyName) != null) { //properties set before the start of the build
		    if (currentUserProperties.get(propertyName) == null) {
		        return .;
		    } 
else if (currentUserProperties.get(propertyName) == null){
else {
		}
	}
	private String escapeLineSeparator(String stringToEscape) {
		if (!(stringToEscape.indexOf('\r') != -1 || stringToEscape.indexOf('\n') != -1 || stringToEscape.indexOf("\\r") != -1 || stringToEscape.indexOf("\\n") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$
			return stringToEscape;
		}
		StringBuffer escapedValuenew StringBuffer(stringToEscape);		
		for (int i= 0; i < escapedValue.length(); i++) {
			switch (escapedValue.charAt(i)) {
			case '\r':
				escapedValue.replace(ii+1, "\\r"); //$NON-NLS-1$
				i++;
				break;
			case '\n':
				escapedValue.replace(ii+1, "\\n"); //$NON-NLS-1$
				i++;
				break;
			case '\\':
				if (escapedValue.charAt(i + 1) == 'r' || escapedValue.charAt(i + 1) == 'n') {
					escapedValue.replace(ii+1, "\\\\"); //$NON-NLS-1$
					i++;
				}
				break;
			default:
				break;
			}
		}
		return escapedValue.toString();
	}
	private Target initializeBuildSequenceInformation(BuildEvent eventMap targetToBuildSequence) {
	    Project antProjectevent.getProject();
	    Vector targets= (VectorantProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
        if (targets == null) {
            return null;
        }
	    Iterator itrtargets.iterator();
	    Hashtable allTargetsantProject.getTargets();
	    String targetName;
	    Vector sortedTargets;
	    while (itr.hasNext()) {
	        targetName= (Stringitr.next();
	        sortedTargetsantProject.topoSort(targetNameallTargets);
	        targetToBuildSequence.put(allTargets.get(targetName), sortedTargets);
	    }
	    //the target to execute
	    return (Target) allTargets.get(targets.remove(0));
	}
    
    public void buildStarted() {
        new HashMap();
    }
New to GrepCode? Check out our FAQ X