I'm creating a custom ant task, which performs an IO tasks based on the user received param(like an file write/append)
I wanted to write the task so as if the developer using it in the ant task runs it with a -v or -d flag, will output more,
I'm wondering how are the core ant tasks doing it. Are they checking the output level before printing to console or is it just done by using java.util.logging.Logger
Follow this tutorial.
Extract :
Integration with TaskAdapter
Our class has nothing to do with Ant. It extends no superclass and implements no interface. How does Ant know to integrate? Via name convention: our class provides a method with signature public void execute(). This class is wrapped by Ant's
org.apache.tools.ant.TaskAdapterwhich is a task and uses reflection for setting a reference to the project and calling theexecute()method.Setting a reference to the project? Could be interesting. The Project class gives us some nice abilities: access to Ant's logging facilities getting and setting properties and much more. So we try to use that class:
import org.apache.tools.ant.Project; public class HelloWorld { private Project project; public void setProject(Project proj) { project = proj; } public void execute() { String message = project.getProperty("ant.project.name"); project.log("Here is project '" + message + "'.", Project.MSG_INFO); } }[...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With