1. Igor Baidiuk
  2. ant-events

Commits

Igor Baidiuk  committed 4404a19 Draft

Added optional header to fire-event that is evaluated and shown before each event. Moved event properties to fire-event code so they can be used in header

  • Participants
  • Parent commits 0cba9c3
  • Branches default

Comments (0)

Files changed (3)

File build.xml

View file
  • Ignore whitespace
 	<target name="test" depends="build" >
 		<typedef classpath="${basedir}/bin/ant-events.jar" resource="antlib.xml" />
 		
-		<event name="foo" priority="2" >
-			<echo message="event foo 1 ${event.name} ${event.priority}" />
-		</event>
+		<event name="foo" description="First event with default priority" />
+		<event name="foo" description="Second event with default priority" />
 		
-		<event name="foo" priority="1" >
-			<echo message="event foo 2 ${event.name} ${event.priority}" />
-		</event>
+		<event name="foo" priority="2" description="First prioritized event" />
+		<event name="foo" description="Third event with default priority" />
+		<event name="foo" priority="1" description="Second prioritized event" />
+		<event name="foo" priority="3" description="Third prioritized event" />
 		
-		<event name="foo" priority="3" >
-			<echo message="event foo 3 ${event.name} ${event.priority}" />
-		</event>
+		<event name="foo" description="Fourth event with default priority" />
 		
 		<echo message="Executing, natural order" />
-		<fire-event name="foo" />
+		<fire-event name="foo" header="$${event.name} ($${event.priority}): $${event.description}" />
 		<echo message="Executing, ascending order" />
-		<fire-event name="foo" order="ascending" />
+		<fire-event name="foo" order="ascending" header="$${event.name} ($${event.priority}): $${event.description}" />
 		<echo message="Executing, descending order" />
-		<fire-event name="foo" order="descending" />
+		<fire-event name="foo" order="descending" header="$${event.name} ($${event.priority}): $${event.description}" />
 		
 		<echo message="Adding another event" />
 		
-		<event name="foo" priority="4" >
-			<echo message="event foo 4 ${event.name} ${event.priority}" />
-		</event>
+		<event name="foo" priority="4" description="Fourth prioritized event" />
 		
 		<echo message="Executing, natural order" />
-		<fire-event name="foo" />
+		<fire-event name="foo" header="$${event.name} ($${event.priority}): $${event.description}" />
 		<echo message="Executing, ascending order" />
-		<fire-event name="foo" order="ascending" />
+		<fire-event name="foo" order="ascending" header="$${event.name} ($${event.priority}): $${event.description}" />
 		<echo message="Executing, descending order" />
-		<fire-event name="foo" order="descending" />
+		<fire-event name="foo" order="descending" header="$${event.name} ($${event.priority}): $${event.description}" />
 		
 		<!-- Test context closure -->
 		<local name="loc.value1" />

File src/org/antcontrib/events/Event.java

View file
  • Ignore whitespace
 			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);
 			// if closure is not empty, traverse it
 			// and put all values onto local context
 			if (closure != null)

File src/org/antcontrib/events/FireEvent.java

View file
  • Ignore whitespace
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.property.LocalProperties;
 
 import org.antcontrib.events.EventList;
 		lp.enterScope();
 		try
 		{
+			PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject());
+			
 			lp.addLocal("event.name");
 			lp.addLocal("event.priority");
 			lp.addLocal("event.description");
 			
 			for (Iterator i = events.iterator(); i.hasNext(); )
 			{
-				((Event)i.next()).performTasks();
+				Event e = (Event)i.next();
+				
+				ph.setProperty("event.name", e.getName(), true);
+				ph.setProperty("event.priority", new Integer(e.getPriority()), true);
+				ph.setProperty("event.description", e.getDescription(), true);
+				
+				if (header != null && !header.isEmpty())
+					log(ph.replaceProperties(header));
+				
+				e.performTasks();
 			}
 		}
 		finally