Commits

Igor Baidiuk  committed 182389d

Done with ordered execution. Faced Java's issue with unoverloadable == operator. Writing str1.equals(str2) just sucks to me :(

  • Participants
  • Parent commits 0fbcfb2

Comments (0)

Files changed (2)

 	<target name="test" depends="build" >
 		<typedef classpath="${basedir}/bin/ant-events.jar" resource="org/antcontrib/events/antlib.xml" />
 		
-		<event name="foo" >
-			<echo message="event foo" />
+		<event name="foo" priority="2" >
+			<echo message="event foo 1" />
+		</event>
+		
+		<event name="foo" priority="1" >
+			<echo message="event foo 2" />
+		</event>
+		
+		<event name="foo" priority="3" >
+			<echo message="event foo 3" />
 		</event>
 		
 		<fire-event name="foo" />
+		<fire-event name="foo" order="ascending" />
+		<fire-event name="foo" order="descending" />
 	</target>
 </project>

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

 import org.antcontrib.events.Event;
 
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
 import org.apache.tools.ant.BuildException;
 
 public class EventList
 	
 	public void execute(String order)
 	{
+		if (order == null)
+			order = "";
+		
 		List l = new ArrayList();
 		l.addAll(events);
 		
-		if (order == "ascending")
+		if (order.equals("ascending"))
+		{
 			Collections.sort(l, new Comparator()
 				{
 					public int compare(Object left, Object right)
 					}
 				}
 			);
-		else if (order == "descending")
+		}
+		else if (order.equals("descending"))
+		{
 			Collections.sort(l, new Comparator()
 				{
 					public int compare(Object left, Object right)
 					}
 				}
 			);
-		else if (order != null && !order.isEmpty() && order != "unordered")
+		}
+		else if (!order.isEmpty() && !order.equals("unordered"))
+		{
 			throw new BuildException("Order must be either 'unordered', 'ascending' or 'descending'");
+		}
 		
 		for (Iterator i = l.iterator(); i.hasNext(); )
 			((Event)i.next()).performTasks();