简体   繁体   English

通过命令行 arguments 到 Apache Ant 来自 DITAOT 自定义插件的构建文件

[英]Pass Command Line arguments to Apache Ant build file from DITAOT custom plugin

I am trying to build a very basic custom html5 plugin for dita-ot.我正在尝试为 dita-ot 构建一个非常基本的自定义 html5 插件。 Below is my current setup.下面是我目前的设置。 Here is my plugin.xml file.这是我的 plugin.xml 文件。

plugin.xml插件.xml

<plugin id="html5-test" version="3.6.1">        
    <transtype name="html5-test" desc="testing html5 transformation with current setup." >
        <param name="args.artlbl" desc="Specifies whether to generate a label for each image;" type="enum">
            <val>yes</val>
            <val default="true">no</val>
          </param>
    </transtype>
    

    <feature extension="ant.import" file="build.xml" />
</plugin>

Here is build.xml这里是 build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:if="ant:if" xmlns:unless="ant:unless" name="dita2html5-test" default="get-parameters">
<target name="get-parameters">
    <echoproperties/>
    <!-- here I want to access CLI arguments for further use. --!>
    <echo message="print value:${args.artlbl}"/>
</target>

the console only shows text and no value.控制台只显示文本,没有值。 I was expecting to see "no" there as it is default value.我期待在那里看到“否”,因为它是默认值。 Ultimate goal is to get CLI arguments inside transtype tag and then pass them to build.xml.最终目标是在转换标签中获取 CLI arguments,然后将它们传递给 build.xml。 After that add this to properties and then use inside ant xslt task.之后将其添加到属性中,然后在 ant xslt 任务中使用。

Configuring parameter default value in plugin.xml doesn't actually set the property default value.plugin.xml中配置参数默认值实际上并没有设置属性默认值。 DITA-OT only uses the information when generating documentation for plug-ins. DITA-OT 仅在为插件生成文档时使用这些信息。

You have to handle the default value in the build.xml .您必须处理build.xml中的默认值。 DITA-OT built-in plug-ins use the following convention: DITA-OT 内置插件使用以下约定:

<project>
  <!--
  This is the enty point DITA-OT will call when running html5-test.
  In depends first call your own init target, then normal HTML5 target.
  -->
  <target name="dita2html5-test"
          depends="html5-test.init,
                   dita2html5"/>
  <target name="html5-test.init">
    <!--
    Since property values cannot be overwritten once set, this will only
    set the value if there is no value set from the command line.
    -->
    <property name="args.artlbl" value="no"/>
  </target>

</project>

So finally I figured it out.所以最后我想通了。

dita -f html5 -i /test.dita -Done=abc

will pass "one" as a parameter to the build.xml file.将“one”作为参数传递给 build.xml 文件。 In build.xml file you will access the argument by following.在 build.xml 文件中,您将通过以下方式访问参数。 No changes needed in plugin.xml file. plugin.xml 文件无需更改。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:if="ant:if" xmlns:unless="ant:unless" name="dita2html5-test" default="get-parameters">
<target name="get-parameters">
    <echo>Embed another1:${one}</echo>
    <echo message="print value:${args.artlbl}"/>
</target>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM