Ant-Ivy post-检索触发器

Ant-Ivy post-retrieve-trigger

我正在尝试解决我们 Ant/Ivy 系统中的一些技术债务,我当前的任务之一是解决我们目前拥有的一些 post- 检索行为。默认情况下,我们的构建系统检索 Ivy 依赖项,然后将压缩的工件(tar、tar.bz2、gzip、zip only)提取到依赖项文件夹,以便我们的项目具有一致的依赖项位置:

(project.root)/dependency/.archive       <- the compressed dependency location 
(project.root)/dependency/extracted-foo` <- the uncompressed dependency

提取发生在 post-retrieve-artifact trigger 中,这样我们就可以利用一些元数据(路径、名称、类型等,所有前缀为 'dep'。

我们目前有一个 属性 可以设置为关闭 ivy.xml 文件中指定的所有依赖项的默认行为。因此,我们面临着全有或全无的局面。如果我们想要介于两者之间的东西,我们目前必须使用我们的 build.xml 文件并编写一些自定义代码。这很痛苦,因为元数据不容易获得。

我想保留全有或全无标志的使用,但允许项目有选择地提取项目 - 我们有几个项目,如果我们可以取消提取过程,其 build.xml 文件将大大简化细化到工件本身的一个属性。

因此,我的想法是使用 extra attribute on the artifact 标签来 "inject" 此信息并覆盖 ivy.retrieve.pattern 来搜索此属性。

Ivy.xml

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
  <dependencies>
    <dependency org="my.org" name="foo" rev="${foo.version}" conf="${conf.archive}->*" transitive="false">
      <artifact name="megapin" type="war" e:expand="expand"/>
    </dependency>
  </dependencies>
</ivy-module>

Build.xml

这是我认为无法显示 expand 额外属性的地方。

问题 1: 这会在检索时将 "extract" 属性添加到工件名称。我可以使用 contains 子句来检查 dep.to 中是否存在有没有办法检索 extra 属性(例如 ${dep.extra.expand} ?

<property name="ivy.retrieve.pattern" value="${dependency.dir}/[conf]/[artifact]-[rev])(-[expand]).[ext]"/>
</property>    

<target name="ivy-post-retrieve-trigger">
  <local name="doexpand"/>
  <condition property="doexpand">
    <contains string="${dep.to}" substring="expand" casesensitive="false"/>
  </condition>

  <!-- this step works if the flag is set properly, so I'm leaving out these non-relevant steps-->
  <...extract if:isset="doexpand"... />   

ivysettings.xml

这个文件基本上有触发器和其他解析器设置。

<triggers>
  <ant-call target="ivy-post-retrieve-trigger" prefix="dep" event="post-retrieve-artifact"/>
</triggers>

问题 2: 对 "noexpand" 名字有什么建议吗?我对 <contains> 子句的担心是 "expand" 会一直受到攻击。

我想我快要完成这项工作了 - 但我得到的唯一信息是:Property "doexpand" has not been set 因此它跳过了提取步骤。 Q3 关于如何在 trigger 和 Ant/Ivy 上使用 extra 属性的任何 tips/advice/examples?

我最终向 Ivy 添加了一些额外的调试语句(从源代码编译)。在 ant-ivy/src/java/org/apache/ivy/ant/AntCallTrigger.java 中,我添加了以下行:

Message.verbose("\tp.name=" + p.getName() + " | p.value=" + p.getValue() );

如果我将 Ivy.xml 文件中的依赖项修改为:

<dependency org="my.org" name="foo" rev="${foo.version}" conf="${conf.archive}->*" transitive="false">
  <artifact name="megapin" type="war" e:expand="true"/>
</dependency>

这表明

[ivy:retrieve]  p.name=dep.expand | p.value=true

此时我可以做类似

的事情
<isset property="dep.expand"/>

<istrue value=${dep.expand}/>

这回答了我的 Q1。此外,我不需要将它添加到 Ivy 检索模式(因此在检索后更改文件名),可以根据需要使用 "true" 或 "false" 值(Q2),此通用指南回答了 Q3