创建一个新的 Doxia 宏
您需要添加以下plexus-component-metadata 插件配置,以从包含宏的项目的注释中生成正确的 Plexus component.xml文件:
<project> ... <build> ... <plugins> <plugin> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-component-metadata</artifactId> <executions> <execution> <goals> <goal>generate-metadata</goal> </goals> </execution> </executions> </plugin> ... </plugins> ... </build> ... </project>
您应该实现AbstractMacro类:
import org.apache.maven.doxia.macro.AbstractMacro; /** * @plexus.component role="org.apache.maven.doxia.macro.Macro" role-hint="my" */ public class MyMacro extends AbstractMacro { ... public void execute( Sink sink, MacroRequest request ) throws MacroExecutionException { String myValue = (String) request.getParameter( "myParam" ); ... } ... }
要使用它,您需要编写以下标记:
- 易于
%{my|myParam=myValue} <!-- my is the macro name defined by role-hint -->
- XDoc
<macro name="my"> <!-- my is the required macro name defined by role-hint --> <param name="myParam" value="myValue"/> </macro>