Igor Baidiuk avatar Igor Baidiuk committed 89a3b27

Added event.name and event.priority as each event's context variables

Comments (0)

Files changed (2)

 		<typedef classpath="${basedir}/bin/ant-events.jar" resource="org/antcontrib/events/antlib.xml" />
 		
 		<event name="foo" priority="2" >
-			<echo message="event foo 1" />
+			<echo message="event foo 1 ${event.name} ${event.priority}" />
 		</event>
 		
 		<event name="foo" priority="1" >
-			<echo message="event foo 2" />
+			<echo message="event foo 2 ${event.name} ${event.priority}" />
 		</event>
 		
 		<event name="foo" priority="3" >
-			<echo message="event foo 3" />
+			<echo message="event foo 3 ${event.name} ${event.priority}" />
 		</event>
 		
 		<echo message="Executing, natural order" />
 		<echo message="Adding another event" />
 		
 		<event name="foo" priority="4" >
-			<echo message="event foo 4" />
+			<echo message="event foo 4 ${event.name} ${event.priority}" />
 		</event>
 		
 		<echo message="Executing, natural order" />

src/org/antcontrib/events/Event.java

 
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.TaskContainer;
+import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.property.LocalProperties;
 
 public class Event extends Task implements TaskContainer {
 	
 	public void performTasks()
 	{
-		// TODO: implement closure enforcement
+		int scopes = 0;
 		LocalProperties lp = LocalProperties.get(getProject());
-		lp.enterScope();
 		try
 		{
+			// Closure scope, includes special event subscriber variables and ones captured from creation context
+			// TODO: implement closure application at this point
+			lp.enterScope();
+			++scopes;
+			PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject());
+			lp.addLocal("event.name");
+			lp.addLocal("event.priority");
+			ph.setProperty("event.name", name, true);
+			ph.setProperty("event.priority", new Integer(priority), true);
+			// actual event's scope
+			lp.enterScope();
+			++scopes;
 			// Perform child tasks
 			for (int i = 0; i < tasks.size(); ++i)
 				((Task)tasks.get(i)).perform();
 		}
 		finally
 		{
-			lp.exitScope();
+			for (; scopes != 0; --scopes)
+				lp.exitScope();
 		}
 	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.