Java – buildfinished and buildstarted will not work properly
I'm from org apache. tools. ant. Defaultlogger of defaultlogger creates a subclass:
public class ExtendedLogger extends DefaultLogger { // My stuff }
I took the information here
So I overloaded some methods from defaultlogger:
@Override public void targetStarted(BuildEvent event){ System.out.println("Logger : "+"[TARGET STARTED]\n"); } @Override public void targetFinished(BuildEvent event){ System.out.println("Logger : "+"[TARGET FINISHED]\n"); }
Which works well (I can see the output)
These methods are also effective:
public void taskStarted(BuildEvent event); public void taskFinished(BuildEvent event);
But I'm in trouble:
@Override public void buildFinished(BuildEvent event) { System.out.println("Logger : "+"[BUILD FINISHED]\n"); } @Override public void buildStarted(BuildEvent event) { System.out.println("Logger : "+"[BUILD STARTED]\n"); }
It is impossible to enter these methods!
What's wrong with me?
thank you.
Editor 12 / 01 / 2016:
I just tried a simple testbuild like @ vaspar xml:
<?xml version="1.0" encoding="UTF-8"?> <project name="MyProject" default="Init" basedir="."> <target name="Init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <echo message="INIT-ING"/> </target> <!-- targets used in my project --> <target name="Clean" description="Clean output directory."> <echo>Clean</echo> </target> <target name="CleanAutogenerated" description="Clean auto-generated folder."> <echo>CleanAutogenerated</echo> </target> <target name="AutoGenerateTopics" description="Manual specific targets."> <echo>AutoGenerateTopics</echo> </target> <target name="BuildDocument" description="Build full documentation"> <echo>BuildDocument</echo> </target> </project>
The output is:
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=Clean] Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@12f33e1] [echo] Clean Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@12f33e1] Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=Clean] CleanDocumentTask DONE Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=CleanAutogenerated] Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@1e2862f] [echo] CleanAutogenerated Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@1e2862f] Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=CleanAutogenerated] CleanAutoGenerateTask DONE Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=AutoGenerateTopics] Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@19bf1ed] [echo] AutoGenerateTopics Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@19bf1ed] Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=AutoGenerateTopics] AutoGenerateTask DONE Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=BuildDocument] Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@10b85cb] [echo] BuildDocument Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@10b85cb] Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=BuildDocument] DocumentTask DONE
Note that cleandocumenttask done, documenttask done, and so on are pure Java output from my project (not ant)
As you can see, targetstarted or targetfinished still has no output:/
Editor 12 / 01 / 2016 (2):
My extendedlogger Java content:
import javax.swing.SwingUtilities; import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.DefaultLogger; /* * This class has been wrote to deals with ant build outputs. * * However,buildFinished and buildStarted seems not to work. * See details at : * * http://api.dpml.net/ant/1.7.0/org/apache/tools/ant/DefaultLogger.html * */ public class ExtendedLogger extends DefaultLogger { /* * public class ColorPane extends JTextPane * * (personal class : JTextPane + Ansi coloring) */ ColorPane colorPane = null; public ExtendedLogger(ColorPane c){ super(); if (c != null){ colorPane = c; } else { System.out.println("ColorPane given to constructor is null. Exiting program."); System.exit(0); } } @Override public void buildFinished(BuildEvent event) { ColorPane.appendInEDT("[BUILD FINISHED]\n",ColorPane.B_Yellow,colorPane); System.out.println("Logger : "+"[BUILD FINISHED]\n"); } @Override public void buildStarted(BuildEvent event) { ColorPane.appendInEDT("[BUILD STARTED]\n",colorPane); System.out.println("Logger : "+"[BUILD STARTED]\n"); } @Override public void log(String message){ appendInEDT(message); } private void appendInEDT(String s){ /* * Detach the graphical modifications in the Event Dispatch Thread (EDT) */ final String newLine = s; Thread t = new Thread(new Runnable(){ public void run(){ colorPane.append(ColorPane.B_White,newLine+"\n"); } }); if (SwingUtilities.isEventDispatchThread()) { t.start(); } else { SwingUtilities.invokelater(t); } } }
Solution
Strange I used your code example, and I can also get the buildstarted / buildfinished log
CustomLogger
import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.DefaultLogger; public class CustomLogger extends DefaultLogger{ @Override public void targetStarted(BuildEvent event){ System.out.println("Logger : "+"[TARGET STARTED] " + event); } @Override public void targetFinished(BuildEvent event){ System.out.println("Logger : "+"[TARGET FINISHED] " + event); } @Override public void taskStarted(BuildEvent event) { System.out.println("Logger : "+"[TASK FINISHED] " + event); } @Override public void taskFinished(BuildEvent event) { System.out.println("Logger : "+"[TASK FINISHED] " + event); } @Override public void buildFinished(BuildEvent event) { System.out.println("Logger : "+"[BUILD FINISHED] " + event); } @Override public void buildStarted(BuildEvent event) { System.out.println("Logger : "+"[BUILD STARTED] " + event); } }
build. XML file
<?xml version="1.0" encoding="UTF-8"?> <project name="MyProject" default="init" basedir="."> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <echo message="INIT-ING"/> </target> </project>
The following is the output
yield
/DummyTest> ant -logger CustomLogger Buildfile: /DummyTest/build.xml Logger : [BUILD STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.Project@1318bd3c] Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=init] [tstamp] Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@31623389] Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@31623389] [echo] Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@636c7a8f] [echo] INIT-ING Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnkNownElement@636c7a8f] Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=init] Logger : [BUILD FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.Project@1318bd3c]