我想创建一个目标,清除特定文件夹中7天以前的日志文件.当我尝试在文件集中放入"日期"元素时,我收到错误.我怎么能这样做?
<delete>
fileset basedir="${StageIISRoot}/MySite/App_Data/ErrorLog">
<date datetime="${datetime::now() - timespan::from-days(7)}" when="before"/>
<include name="*.xml" />
</fileset>
</delete>
Run Code Online (Sandbox Code Playgroud) 假设我有一组包含以下路径的PDF文件:
/some/path/pdfs/birds/duck.pdf
/some/path/pdfs/birds/goose.pdf
/some/path/pdfs/insects/fly.pdf
/some/path/pdfs/insects/mosquito.pdf
Run Code Online (Sandbox Code Playgroud)
我想做的是为每个PDF生成关于相对路径结构的缩略图,并输出到另一个位置,即:
/another/path/thumbnails/birds/duck.png
/another/path/thumbnails/birds/goose.png
/another/path/thumbnails/insects/fly.png
/another/path/thumbnails/insects/mosquito.png
Run Code Online (Sandbox Code Playgroud)
我希望这可以在Ant中完成.假设我将在命令行上使用Ghostscript并且我已经完成了对GS的调用:
<exec executable="${ghostscript.executable.name}">
<arg value="-q"/>
<arg value="-r72"/>
<arg value="-sDEVICE=png16m"/>
<arg value="-sOutputFile=${thumbnail.image.path}"/>
<arg value="${input.pdf.path}"/>
</exec>
Run Code Online (Sandbox Code Playgroud)
因此,我需要做的是制定出正确的价值观${thumbnail.image.path},并${input.pdf.path}在遍历PDF输入目录.
我可以访问ant-contrib(刚刚安装了"最新版本",即1.0b3),我正在使用Ant 1.8.0.我想我可以使用<for>任务,<fileset>s和<mapper>s 来做一些工作,但我无法将它们放在一起.
我尝试过类似的东西:
<for param="file">
<path>
<fileset dir="${some.dir.path}/pdfs">
<include name="**/*.pdf"/>
</fileset>
</path>
<sequential>
<echo message="@{file}"/>
</sequential>
</for>
Run Code Online (Sandbox Code Playgroud)
但不幸的@{file}是,该属性是一个绝对的路径,我找不到任何简单的方法将其分解为相关组件.
如果我只能使用自定义任务执行此操作,我想我可以编写一个,但我希望我可以将现有组件插入.
因为我<lineEnding>unix</lineEnding>在我的Maven程序集插件配置中将选项插入到我的文件集和文件中,所以奇怪的文件放在我的tar中.
他们看起来如下:
ignore.me.1499711160.filtered.903528596.formatted run.sh.2124782621.filtered.1130667884.formatted
你知道为什么会这么吗?
我正在使用ant 1.6.2并且我正在尝试设置一个比较源目录和目标目录的任务,识别源目录中存在的所有子目录,并删除目标目录中的like目录子目录.
所以,假设源目录中有子目录sub1,sub2和sub3,目标目录中有sub1,sub2,sub3和sub4,那么我想从目标dir中删除sub1,sub2和sub3.
我想我可以通过使用FileSelector来识别源中存在于目标中的所有目录.但是,我无法让<type>文件选择器返回目录的匹配项.
最终,我想我会做类似的事情:
<fileset id="dirSelector" dir="${install.dir}">
<type type="dir"/>
<present targetdir="${dist.dir}"/>
</fileset>
Run Code Online (Sandbox Code Playgroud)
我开始只是尝试列出源目录中的目录并将其打印出来:
<fileset id="dirSelector" dir="${install.dir}">
<type type="dir"/>
</fileset>
<property name="selected" refid="dirSelector" />
<echo>Selected: ${selected}</echo>
Run Code Online (Sandbox Code Playgroud)
但是,我从来没有打印过将类型选择器设置为目录的任何内容.如果我将类型更改为文件,我会打印出文件.
有没有更好的方法来完成我想要做的事情?我在使用类型选择器时遗漏了什么吗?
给定一个像这样的源文件目录:
tester$ ls -l src
-rw-r--r-- 1 tester staff 0 24 Feb 11:28 File 1.txt
-rw-r--r-- 1 tester staff 0 24 Feb 11:28 File 2.txt
-rw-r--r-- 1 tester staff 0 24 Feb 11:28 File 3.txt
-rw-r--r-- 1 tester staff 0 24 Feb 11:30 FileFalse 1.txt
-rw-r--r-- 1 tester staff 0 24 Feb 11:30 FileFalse 2.txt
-rw-r--r-- 1 tester staff 0 24 Feb 11:30 FileFalse 3.txt
Run Code Online (Sandbox Code Playgroud)
我可能会尝试使用以下方法将它们全部复制到另一个位置fileset:
<project name="test" default="copy">
<target name="copy">
<mkdir dir="build"/>
<copy todir="build">
<fileset dir="src" includes="File …Run Code Online (Sandbox Code Playgroud) 我在各种目录中有一堆子项目.我想将它们指定为一个列表,然后对于给定的目标,我想逐个浏览每一个,并调用subant.
我有类似的东西:
<target name="run">
<subant target="run" failonerror="true" verbose="true">
<fileset dir="${projectA}" includes="build.xml"/>
</subant>
<subant target="run" failonerror="true" verbose="true">
<fileset dir="${projectB}" includes="build.xml"/>
</subant>
</target>
Run Code Online (Sandbox Code Playgroud)
但我必须为每个项目和每个目标集指定一个单独的子行.我想做的就是创建一个子项目列表的属性,并以某种方式使用它.它应该很简单,但......
我有一组目标,每个目标基本上都是相同的,除了每个目标包含一个特定的模式集,在其上执行其任务.我想将这些目标折叠成一个"可重用"的目标,而是将一组文件"作为参数".
例如,这个
<target name="echo1">
<foreach item="File" property="fn">
<in>
<items>
<include name="*.config"/>
</items>
</in>
<do>
<echo message="${fn}" />
</do>
</foreach>
</target>
<target name="echo2">
<foreach item="File" property="fn">
<in>
<items>
<include name="*.xml"/>
</items>
</in>
<do>
<echo message="${fn}" />
</do>
</foreach>
</target>
<target name="use">
<call target="echo1"/>
<call target="echo2"/>
</target>
Run Code Online (Sandbox Code Playgroud)
将被替换为
<patternset id="configs">
<include name="*.config"/>
</patternset>
<patternset id="xmls">
<include name="*.xml"/>
</patternset>
<target name="echo">
<foreach item="File" property="fn">
<in>
<items>
<patternset refid="${sourcefiles}"/>
</items>
</in>
<do>
<echo message="${fn}" />
</do>
</foreach>
</target>
<target name="use">
<property name="sourcefiles" …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的文件夹结构:
/PROJECT/PROJECT.html
/PROJECT/PROJECT_readme.txt
/PROJECT/PROJECT.css
/PROJECT/PROJECT.js
/PROJECT/abc_PROJECT_def.txt
/PROJECT/something.js
/PROJECT/other.txt
/PROJECT/somefolder/PROJECT_other.txt
Run Code Online (Sandbox Code Playgroud)
我想使用 ANT 复制完整的目录,并将文件或文件夹中的 PROJECT 字符串更改为指定值,例如 mysuperproject,因此结果文件夹结构如下:
/mysuperproject/mysuperproject.html
/mysuperproject/mysuperproject_readme.txt
/mysuperproject/mysuperproject.css
/mysuperproject/mysuperproject.js
/mysuperproject/abc_mysuperproject_def.txt
/mysuperproject/something.js
/mysuperproject/other.txt
/mysuperproject/somefolder/mysuperproject_other.txt
Run Code Online (Sandbox Code Playgroud)
在 ANT 中有一个简单的方法可以做到这一点吗?
假设我的目标之一是:
<path id="files">
<fileset dir="${env.DIRECTORY}" casesensitive="false">
<include name="**/*.html"/>
<exclude name="**/*ant*"/>
</fileset>
</path>
Run Code Online (Sandbox Code Playgroud)
我想将所有html文件分组,除了包含字符串ant的文件.我上面写的方式,它不起作用.我也试过像这样指定排除:
<exclude name="*ant*"/>
Run Code Online (Sandbox Code Playgroud)
请注意,文件集的区分大小写已关闭.但是,如果我写:
<exclude name="**/*ant*/**"/>
Run Code Online (Sandbox Code Playgroud)
这确实有效.为什么第一版和第二版的排除不起作用?
有没有办法只选择那些具有Modified状态的文件?
是否可以将选择链接以添加更具体的选择器?
我想导出那些Modified文件中的更改,在安装插件之前还原为changeset,然后重新导入更改.
hg diff -I与模式匹配可能会有所帮助,但在这种情况下,我经常只想根据文件状态选择文件.
hg st的示例(实际内容因文件名和文件名/扩展名不同而异):
M /readme.txt
M /dir1/somefile1.txt
M /dir2/somefile2.txt
M /dir3/somefile3.txt
M /dir4/somefile4.txt
! /plugin/lotsoffileshere.txt
! /plugin/lotsoffileshere.txt
! /plugin/lotsoffileshere.txt
Run Code Online (Sandbox Code Playgroud) fileset ×10
ant ×6
nant ×2
delete-file ×1
diff ×1
expansion ×1
java ×1
line-endings ×1
list ×1
maven-2 ×1
mercurial ×1
move ×1
path ×1
properties ×1