如何设置Groovy的Antbuilder中的build.xml? [英] How to set the build.xml for the Groovy Antbuilder?

查看:158
本文介绍了如何设置Groovy的Antbuilder中的build.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从使用GMaven(Maven插件在聚甲醛的Groovy内嵌执行)执行build.xml文件(Ant构建)。由于我使用Maven的antrun-插件执行构建文件几次是不是一种选择。构建文件正在演变以及从与变化不大的合作伙伴项目采取。这就是为什么我不想把逻辑到另一个环境(常规code或Maven配置)。

我带属性的列表(环境,并可以在数量和名称有很大的不同机器名,在我看来这不能付诸模块)从一个XML文件,并希望执行蚂蚁构建为每个机器。我发现的javadoc的executeTarget方法但不知道如何设置构建文件的位置。我该怎么做? - 而这是足够的。

我有如下所示:

 <&插件GT;
    <的groupId方式>组织codehaus.groovy.maven< /的groupId>
    <&的artifactId GT; gmaven-插件< / artifactId的>
    <&执行GT;
      <执行与GT;
        <&ID GT;有的蚂蚁构建与LT; / ID>
        <阶段>的过程来源:LT; /阶段>
        <目标>
          <&目标GT;执行< /目标>
        < /目标>
        <结构>
          <信源>
            高清蚂蚁=新AntBuilder()
            。高清机=新XmlParser的()解析(新文件(project.build.outputDirectory +'/MachineList.xml'));            machines.children(){每             log.info(+ it.Id.text()+'/'+ it.Environment.text()'创建机器描述');
                ant.project.setProperty(环境,it.Environment.text());
                ant.project.setProperty('机',it.Id.text());                // 少了什么东西?                ant.project.executeTarget('裁缝');            }            log.info('蚂蚁已经完成。)          < /源>
        < /结构>
      < /执行>
    < /处决>
  < /插件>


解决方案

一个解决方案是利用这样的org.apache.tools.ant项目和ProjectHelper类(省略从我的任务的其他详细信息):

 进口org.apache.tools.ant.Project
进口org.apache.tools.ant.ProjectHelper高清antFile =新的文件('的src / main / ANT / myBuildfile.xml')//创建构建文件的一个项目
高清antProject =新项目()
antProject.init()
ProjectHelper.projectHelper.configureProject(antProject,antFile)//使用蚂蚁运行它,并设定目标
antProject.executeTarget('myTarget');

现在缺少的是在这里记录。我用

  antProject.addBuildListener(antListener)

像你找到它的这里 - 这是从那里我得到了一段时间后soluting ...

I want to execute a build.xml (Ant buildfile) from using GMaven (Maven Plugin for inline execution of Groovy in a POM). Since I have to execute the buildfile several times using the maven-antrun-plugin is not an option. The buildfile is evolving and taken from a partner project with little changes. That's why I don't want to put the logic in it into another environment (groovy code or Maven configuration).

I take a list of properties (environment and machine names that can differ widely in number and names, to my mind this cannot be put into modules) from an xml file and want to execute ant builds for each of those machines. I found the executeTarget method in the javadocs but not how to set the location of the buildfile. How can I do that - and is this enough?

What I have looks as follows:

<plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <executions>
      <execution>
        <id>some ant builds</id>
        <phase>process-sources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <source>
            def ant = new AntBuilder()
            def machines = new XmlParser().parse(new File(project.build.outputDirectory + '/MachineList.xml'));

            machines.children().each { 

             log.info('Creating machine description for ' + it.Id.text() + ' / ' + it.Environment.text());
                ant.project.setProperty('Environment',it.Environment.text());
                ant.project.setProperty('Machine',it.Id.text());

                // What's missing?                    

                ant.project.executeTarget('Tailoring');

            }

            log.info('Ant has finished.')

          </source>
        </configuration>
      </execution>
    </executions>
  </plugin>

解决方案

A solution is using the Project and ProjectHelper Classes from org.apache.tools.ant like this (omitting the other details from my task):

import org.apache.tools.ant.Project
import org.apache.tools.ant.ProjectHelper

def antFile = new File('src/main/ant/myBuildfile.xml')

//create a project with the buildfile
def antProject = new Project()
antProject.init()
ProjectHelper.projectHelper.configureProject(antProject, antFile)

// run it with ant and set the target
antProject.executeTarget('myTarget');

What's missing here is the logging. I used

antProject.addBuildListener(antListener)

to add a customized listener like you find it here - that's from where I got the soluting after some time...

这篇关于如何设置Groovy的Antbuilder中的build.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆