2014-09-26 29 views
1

我敲我的头撞墙用Ant文件集/ regexpmapper打,试图简单地重命名一个目录(在路的中间)...蚂蚁regexpmapper文件分隔符发出

的情况是真的简单:

  • 我有路径component/DB/,我正在复制到DB/api/src/main/distribution/component
  • 路径组件/ DB包含一组install.sql脚本和一个名为api(或“API”或“Api”)的目录。这个“api”目录包含额外的sql,并将批量复制到目标DB/api/component(因此创建DB/api/src/main/distribution/component/api)。
  • 作为此副本的一部分,我只想将小写的“api”目录名称保持一致。

听起来很简单,我一直在玩文件集和regexpmapper(或mapper type=regexp)来实现这一目标。然而,我的结果好坏参半......值得注意的是,只要我在(或'\\'或'/'或${file.separator}中放入'/',即使使用regexpmapper.handledirsep=yes)也不起作用。

下面是模糊的源路径结构(从find):

component/DB/ 
component/DB/API 
component/DB/API/file1.sql 
component/DB/API/file2.sql 
component/DB/xyz.sql 
component/DB/Install_API.sql 
component/DB/excludes1/... 

我的基本副本如下:

<copy todir="${my.db.api.dir}/src/main/distribution/component" verbose="true"> 
    <fileset dir="${component.src.dir}/DB"> 
     <exclude name="exclude1"/> 
     <exclude name="exclude1/**/*"/> 
    </fileset> 
    <regexpmapper handledirsep="yes" 
      from="(.*)/API(.*)" to="\1/api\2"/> 
    <!--mapper type="regexp" from="(.*)/API(.*)" to="\1/api\2"/--> 
</copy> 

我已经离开为了清楚而简单的 '/'。你可以看到基本的前提是找到“API”,抓住周围的文本并用“api”重放它。如果我省略了from中的'/',那么这确实起作用,但只要将'/'(或它的朋友)放入,目录根本就不会被复制。请注意,我想要前面的'/',因为我只想重命名该目录,而不是其中包含的Install_API.sql文件。

在网上有很多例子,但似乎没有人遇到过这个问题,因为假设的工作示例似乎都使用普通的'/','\'或声称由handledirset属性来处理。

ant 1.8.4在RH6.3上

非常感谢。

回答

1

你的文件集的基本目录是DB目录,这意味着你的映射器将映射路径的形式为

API/file1.sql 
Install_API.sql 
excludes1/... 

相对于该目录。因此,API目录名称前面没有斜杠,并且您的from模式永远不匹配。但是还有一个更深的问题,那就是regexpmapper完全忽略了与from模式不匹配的任何文件名。这不是您想要的,因为您需要将API更改为api,但保留非API文件名不变。因此,而不是一个regexpmapper你需要一个filtermapperreplaceregex过滤器:

<copy todir="${my.db.api.dir}/src/main/distribution/component" verbose="true"> 
    <fileset dir="${component.src.dir}/DB"> 
     <exclude name="exclude1"/> 
     <exclude name="exclude1/**/*"/> 
    </fileset> 
    <filtermapper> 
     <!-- look for either just "API" with no trailer, or API followed by 
      a slash, in any combination of case --> 
     <replaceregex pattern="^API(?=${file.separator}|$$)" replace="api" 
         flags="i"/><!-- case-insensitive search, finds API, Api, ... --> 
    </filtermapper> 
</copy> 
+0

这是梦幻般的感谢,我已经错过了良好的放课。如果没关系,我有一个后续问题...在我的输出中,我现在看到'/ src/main/distribution/component \ api'(我想要),还有'/ src/main/distribution/component/API'(详细日志告诉我“[copy] API添加为API不存在“和”将1个空目录复制到...组件下的1个空目录“我可以在此后删除它,但想知道它是否是配置问题(在mo上有读取)。 – wmorrison365 2014-09-26 16:05:14

+0

@ wmorrison365这很奇怪,我认为'fileset'应该是一组_files_,不包括'API'目录作为它的一个条目(并且我在一个不区分大小写的FS上测试过一开始我没有发现这个)我改变了我的正则表达式,所以它只匹配“API”以及“API/something” – 2014-09-26 16:18:10

+0

再次感谢@ianroberts。我以为不包含sep文件使用^,给出你的解释。我会尝试你的改进,但很感激! – wmorrison365 2014-09-27 11:15:24