标签: macrodef

如何从另一个文件中调用macrodef

我在单独的文件中写了一个小的macrodef:

macrodefs.xml

<macrodef name="do-cool-stuff">
  <attribute name="message"/>

  <sequential>
    <echo message="@{message}" />
  </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

我有第二个文件,我的主要构建文件:

build.xml文件

<target name="build">
  <!-- do this and that -->

  <!-- cheking out macrodefs.xml via CVS -->

  <ant antfile="macrodefs.xml" target="do-cool-stuff" >
    <property name="message" value="Hello, World!" />
  </ant>
</target>
Run Code Online (Sandbox Code Playgroud)

你可能会猜到这不会起作用.错误消息类似于:

Target 'do-cool-stuff' does not exist in this project.
Run Code Online (Sandbox Code Playgroud)

我发现唯一可行的解​​决方案是在macrodefs.xml中提供额外的目标来转发ant调用.

是否有可能从另一个文件中调用macrodef?

提前致谢.

ant build macrodef

10
推荐指数
1
解决办法
1万
查看次数

Ant macrodef:有没有办法获取元素参数的内容?

我正在尝试在Ant中调试macrodef.我似乎无法找到一种方法来显示作为元素发送的参数的内容.

<project name='debug.macrodef'>
  <macrodef name='def.to.debug'>
    <attribute name='attr' />
    <element name='elem' />
    <sequential>
      <echo>Sure, the attribute is easy to debug: @{attr}</echo>
      <echo>The element works only in restricted cases: <elem /> </echo>
      <!-- This works only if <elem /> doesn't contain anything but a
           textnode, if there were any elements in there echo would
           complain it doesn't understand them. -->
    </sequential>
  </macrodef>

  <target name='works'>
    <def.to.debug attr='contents of attribute'>
      <elem>contents of elem</elem>
    </def.to.debug>
  </target>

  <target name='does.not.work'>
    <def.to.debug attr='contents of attribute'>
      <elem><sub.elem>contents of sub.elem</sub.elem></elem> …
Run Code Online (Sandbox Code Playgroud)

ant element macrodef

8
推荐指数
1
解决办法
5671
查看次数

Macrodef和"本地属性"

我试图将文件(由模式指定)移动到Ant macrodef中的给定位置:

<macrodef name="extract">
    <attribute name="package"/> 
    <sequential>

        <!-- the path will contain the unique file in extracted regardless of the name -->
        <path id="source_refid">
            <dirset dir="${dep}/lib/@{package}/extracted/">
                <include name="@{package}-*"/>
            </dirset>
        </path>

        <!-- this is not working: properties are immutable -->
        <property name="source_name" refid="source_refid"/>

        <move
            file="${source_name}"
            tofile="${dep}/@{package}/"
            overwrite="true"
        />

    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

这将只工作一次,因为它${source_name}是不可变的.

一个选项是使用变量任务,但我没有找到一种方法来为一个refid分配一个var.

有没有办法在macrodef中有类似于局部变量的东西?或者(XY问题)有更好的方法来解决我的问题吗?

ant macrodef

7
推荐指数
1
解决办法
6489
查看次数

ant macrodef和元素命名

我有一个带有一个名为"libs"的元素的macrodef

<macrodef name="deploy-libs">
    <element name="libs"/>
    <sequential>
        <copy todir="${glassfish.home}/glassfish/domains/domain1/lib">              
            <fileset dir="${lib}">
                <libs/>
            </fileset>
        </copy>
    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

然后调用为

<deploy-libs>
    <libs>
        <include name="mysql-connector-*.jar"/>
        <include name="junit-*.jar" />
        <!-- .... -->
    </libs>
</deploy-libs>
Run Code Online (Sandbox Code Playgroud)

然后我有另一个macrodef调用几个macrodef,包括"deploy-libs".如果这个macrodef也有一个元素"libs"会很好,但是:

<macrodef name="init-glassfish">
    <element name="libs"/>
    <sequential>

        <!-- other stuff -->

        <deploy-libs>
            <libs>
                <libs/>
            </libs>
        </deploy-libs>

        <!-- other stuff -->

    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

显然不起作用(因为<libs><libs/></libs>):

Commons/ant-glassfish-server.xml:116: unsupported element include
Run Code Online (Sandbox Code Playgroud)

解决方案可能是以不同的方式命名"init-glassfish"中的元素:

<macrodef name="init-glassfish">
    <element name="libraries"/>
    <sequential>

        <!-- other stuff -->

        <deploy-libs>
            <libs>
                <libraries/>
            </libs>
        </deploy-libs>

        <!-- other stuff -->

    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

有没有办法让两个macrodef以相同的方式命名元素?

ant macrodef

5
推荐指数
1
解决办法
833
查看次数

在Ant中在运行时创建具有动态内容的Union和Macrodef样式元素

我有一个用Ant构建的构建脚本,它有一个macrodef,它接受一些默认参数,target,root等,然后是一个可选的两个,extrasrc-f和extrasrc-c.在他们进来之后,我喜欢对所有相关资源进行最新检查,然后只在目标过期时才进行构建.

我现在拥有的是什么

<?xml version="1.0" encoding="UTF-8"?>
<project name="Custom build" default="default">

    <taskdef resource="net/sf/antcontrib/antlib.xml"
        classpath="C:/dev/ant/ant-contrib/ant-contrib-1.0b3.jar"/>

    <macrodef name="checkuptodate">
        <attribute name="target" />
        <element name="resource" />
        <sequential>
            <condition property="needbuild">
                <and>
                    <resourcecount when="greater" count="0"> <resource /> </resourcecount>
                    <not>
                        <uptodate targetfile="@{target}">
                            <srcresources> <resource /> </srcresources>
                        </uptodate>
                    </not>
                </and>
            </condition>
        </sequential>
    </macrodef>

    <macrodef name="projbuild">
        <attribute name="root" />
        <attribute name="target" />

        <element name="extrasrc-f" optional="true" />
        <element name="extrasrc-c" optional="true" />
        <sequential>
            <local name="needbuild" />
            <checkuptodate target="@{root}/bin/@{target}">
                <resource>
                    <union>
                        <extrasrc-f />
                        <fileset dir="@{root}/src" includes="**/*.java" />
                    </union>
                </resource>
            </checkuptodate>

            <if>
                <istrue value="${needbuild}" /> …
Run Code Online (Sandbox Code Playgroud)

ant union element macrodef

5
推荐指数
1
解决办法
732
查看次数

从Gradle调用Ant Macrodef

我似乎找不到从Gradle脚本中列出和/或调用Ant Macrodef的方法。《 Gradle用户指南》讨论了Macrodef,但此处未提供任何示例。谁能告诉我如何做到这一点?

目前,我通过执行ant.importBuild任务来导入Ant构建。当Ant目标显示为Gradle任务时,这可以正常工作。但是,我无法列出和/或调用Ant构建中所述的Ant Macrodef。谁能给我答案?

ant macrodef gradle build.gradle

5
推荐指数
1
解决办法
816
查看次数

如何将列表的每个元素分配给任务Ant的参数?

如何将已定义任务的参数值转换为值列表(而不必为每个参数值重写任务)?

示例:我想避免为了回显三个不同的值(值1,值2,值3)而必须重写三次相同的任务:

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 1"/>
</exec>

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 2"/>
</exec>

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 3"/>
</exec>
Run Code Online (Sandbox Code Playgroud)

谢谢

ant macrodef

4
推荐指数
1
解决办法
448
查看次数

如何从另一个macrodef中调用Ant宏?

我有一个build.xml,从这里我调用一个宏:

<import file="macro_file.xml" />
<ant-macro message="Hello, World!" />
Run Code Online (Sandbox Code Playgroud)

我的macro_file.xml文件如下所示:

<macrodef name="ant-macro">
    <attributes name="message"/>
    <sequential>
        <echo message="@{message}" />
    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

如何调用宏内的另一个ant-macro宏?

我尝试了以下方式,但它给出了一个错误.

<macrodef name="ant-macro">
    <attributes name="message"/>
    <second-macro messge="hi"/>
    <sequential>
        <echo message="@{message}" />
    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

second-macro宏还在macro_file.xml文件中定义.

ant macrodef

3
推荐指数
1
解决办法
3666
查看次数

为什么我不能在C中使用#define作为关键字?

我正在尝试在C++中使用以下代码.有人能告诉我为什么会出现错误吗?

#define  def namespace;
using def std;
int main(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)

而以下代码工作正常

#define  def namespace std;
using def;
int main(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c c++ macros macrodef

2
推荐指数
1
解决办法
183
查看次数

if else和#if #else #endif之间的区别

我在if/ else#if/ #else/ #endif构造之间感到困惑.

  1. 它们之间有什么区别?
  2. 我应该在哪些特定情况下使用它们?

c c++ macrodef

-6
推荐指数
3
解决办法
3968
查看次数

标签 统计

macrodef ×10

ant ×8

c ×2

c++ ×2

element ×2

build ×1

build.gradle ×1

gradle ×1

macros ×1

union ×1