Ant Ivy:生成运行时 jar 的文本报告 [英] Ant Ivy: Producing text report of the runtime jars

查看:28
本文介绍了Ant Ivy:生成运行时 jar 的文本报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我们从 Ivy 下载 jar 时,我们会将 pattern 设置为包含 jar 的版本号.

Normally, when we download jars from Ivy, we set pattern to include the version number of the jar.

<ivy:retrieve
    pattern="${lib.dir}/[conf]/[artifact]-[revision].[ext]"
    log="${ivy.log}"/>

但是,对于这个项目,我们不能这样做.必须在没有版本 ID 的情况下下载 Jar:

However, for this one project, we can't do that. Jars have to be downloaded without version ID on them:

<ivy:retrieve
    pattern="${lib.dir}/[conf]/[artifact].[ext]"/>

通过覆盖已经存在的内容来安装此应用程序.如果特定 jar 的修订版从一个版本更改为下一个版本,我们最终会同时拥有该 jar 的旧版本和新版本,并且我们不知道正在使用哪个版本.删除修订信息可以轻松确保将旧 jar 替换为新版本.

This app is installed by overwriting what is already there. If a revision of a particular jar gets changed from one release to the next, we would end up with both the older jar and the newer version of that jar, and we would not know which version was being used. Removing the revision information makes it easy to make sure that older jars are replaced with the newer version.

但是,开发者仍然想要一个简单的报告,说明下载了哪些版本的 jar 并将其放入构建的战争中,那么我如何生成这样的报告.我正在查看 ivy:report 但它没有生成文本报告.有一个 <ivy:artifactreport/> 任务,但也会生成 XML 报告而不是文本报告.

However, the developer would still like a simple report on what versions of the jars were downloaded and put into the built war, so how can I generate such a report. I was looking at ivy:report but it doesn't produce a text report. There's a <ivy:artifactreport/> task, but that also produces an XML report and not a text report.

我可以使用 Perl 或 Python 解析此报告,但我不想在构建过程中使用可执行文件.否则,当开发人员进行构建时,他们必须确保正确安装和配置这些外部程序.

I could parse this report using Perl or Python, but I'd rather not use an executable as part of the build process. Otherwise, when a developer does a build, they'll have to make sure these external programs are correctly installed and configured.

是否有一种简单的方法可以生成纯文本报告?

Is there an easy way to produce a plain text report?

推荐答案

使用 ANT xslt 生成 CSV 格式文本文件的任务

Uses the ANT xslt task to generate a CSV formatted text file

├── build
│   └── ivy
│       ├── com.myspotontheweb-demo-compile.html
│       ├── com.myspotontheweb-demo-runtime.html
│       ├── com.myspotontheweb-demo-test.html
│       ├── ivy-report.css
│       ├── report.txt
│       └── report.xml
├── build.xml
├── ivy.xml
└── report.xsl

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="resolve" description="Use ivy to resolve dependencies">
        <ivy:resolve/>

        <!-- Reports -->
        <ivy:report todir='build/ivy' graph='false' xml='false'/>

        <ivy:artifactreport tofile="build/ivy/report.xml"/>
        <xslt style="report.xsl" in="build/ivy/report.xml" out="build/ivy/report.txt"/>

    </target>

</project>

报告.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates select="modules/module/artifact"/>
  </xsl:template>

  <xsl:template match="artifact">
    <xsl:value-of select="../@organisation"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="../@name"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="../@rev"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="origin-location"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="cache-location"/>
    <xsl:text>
</xsl:text>
  </xsl:template>

</xsl:stylesheet>

报告.txt

org.slf4j,slf4j-api,1.7.5,http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar,/home/mark/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.5.jar
org.slf4j,slf4j-log4j12,1.7.5,http://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar,/home/mark/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.5.jar
log4j,log4j,1.2.17,http://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar,/home/mark/.ivy2/cache/log4j/log4j/bundles/log4j-1.2.17.jar
junit,junit,4.11,http://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.jar,/home/mark/.ivy2/cache/junit/junit/jars/junit-4.11.jar
org.hamcrest,hamcrest-core,1.3,http://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar,/home/mark/.ivy2/cache/org.hamcrest/hamcrest-core/jars/hamcrest-core-1.3.jar

这篇关于Ant Ivy:生成运行时 jar 的文本报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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