build.xml
<taskdef
onerror ="ignore"
name ="monitor-client"
classpath="${jar-client}"
classname="hpms.app.mon.client.AntTask" />
<target name="run-client" depends="compile-sample" description="Launch monitor">
<monitor-client
layout ="Layout.xml"
gui ="true"
autostart ="true">
<log-server
port ="3000"
capacity="2048" />
...
AntTask.java
public final class AntTask extends Task {
private ...
public void setLayout( String layout ) {
}
public void setGui( boolean gui ) {
}
public void setAutostart( boolean autostart ) {
}
public void addConfiguredLogServer( LogServer logServer ) {
}
@Override
public void execute() {
...
}
}
Execution
Buildfile: ...\build.xml
compile-sample:
run-client:
BUILD FAILED
...\build.xml:116: monitor-client doesn't support the nested "log-server" element.
Question
I search the applicable naming rules for elements and attributes and the mapping rules to Java language.
org.apache.tools.ant.IntrospectionHelper
is the class that does introspection to extract attributes from setter methods.
From the Javadocs of the constructor:
void setFoo(Bar)
is recognised as a method for setting the value of attributefoo
, so long asBar
is non-void and is not an array type. Non-String parameter types always overload String parameter types, but that is the only guarantee made in terms of priority.
Answer based on matt comment, many thanks to him!
Apache ANT use two ways to identify element and attributes:
org.apache.tools.ant.DynamicElement
and org.apache.tools.ant.AttributeElement
Interfaces must be used to map XML identifiers to Java identifiers when special characters are used, like hyphen, as shown below:
import org.apache.tools.ant.DynamicElement;
import org.apache.tools.ant.Task;
public final class AntTask extends Task implements DynamicElement {
private ...
public void setLayout( String layout ) {
}
public void setGui( boolean gui ) {
}
@Override
public Object createDynamicElement( String name ) {
if( name.equals( "log-server" )) {
return new Logserver();
}
return null;
}
...
@Override
public void execute() {
}
}
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