1 7 package fr.jayasoft.ivy.ant; 8 9 import org.apache.tools.ant.BuildEvent; 10 import org.apache.tools.ant.BuildListener; 11 import org.apache.tools.ant.Task; 12 13 import fr.jayasoft.ivy.util.Message; 14 import fr.jayasoft.ivy.util.MessageImpl; 15 16 21 public class AntMessageImpl implements MessageImpl { 22 private Task _task; 23 24 private static long _lastProgressFlush = 0; 25 private static StringBuffer _buf = new StringBuffer (); 26 27 30 public AntMessageImpl(Task task) { 31 _task = task; 32 task.getProject().addBuildListener(new BuildListener() { 33 private int stackDepth = 0; 34 public void buildFinished(BuildEvent event) { 35 } 36 public void buildStarted(BuildEvent event) { 37 } 38 public void targetStarted(BuildEvent event) { 39 } 40 public void targetFinished(BuildEvent event) { 41 } 42 public void taskStarted(BuildEvent event) { 43 stackDepth++; 44 } 45 public void taskFinished(BuildEvent event) { 46 if (stackDepth==0) { 52 Message.uninit(); 53 event.getProject().removeBuildListener(this); 54 } 55 stackDepth--; 56 } 57 public void messageLogged(BuildEvent event) { 58 } 59 }); 60 } 61 62 public void log(String msg, int level) { 63 _task.log(msg, level); 64 } 65 66 public void rawlog(String msg, int level) { 67 _task.getProject().log(msg, level); 68 } 69 70 public void progress() { 71 _buf.append("."); 72 if (_lastProgressFlush == 0) { 73 _lastProgressFlush = System.currentTimeMillis(); 74 } 75 if (_task != null) { 76 if (System.currentTimeMillis() - _lastProgressFlush > 1500) { 78 _task.log(_buf.toString()); 79 _buf.setLength(0); 80 _lastProgressFlush = System.currentTimeMillis(); 81 } 82 } 83 } 84 85 public void endProgress(String msg) { 86 _task.log(_buf + msg); 87 _buf.setLength(0); 88 _lastProgressFlush = 0; 89 } 90 } 91 | Popular Tags |