2012-01-29 83 views
3

我有一個SVN外部文件夾,其中包含許多文件夾稱爲*Plugin然後在這些文件夾中有modules文件夾和binaries文件夾。Nant文件集basedir與模式

對我來說,問題是,在我的構建任務中,我想從模塊複製**/*到我的項目中的某個位置,以及從二進制文件位置到項目中其他任何位置的任何*.plugin.dll

因此,這裏是一個虛擬的例子:

- DummyPlugin1 
    |- binaries 
    |- some.assembly.dll 
    |- some.plugin.dll 
    |- modules 
    |- some-named-folder 
     |- some-sub-folder 
      |- some.content.xml 
     |- some-other-sub-folder 
      |- yet-another-folder 
       |- some.more.content.jpg 
- DummyPlugin2 
    |- binaries 
    |- some.other.plugin.dll 
    |- modules 
    |- another-named-folder 
     |- content.xml 
     |- image.jpg 
    |- yet-another-named-folder 
     |- some-web-page.html 

因此,在這個例子中,我想基本上覆制:

  • some.plugin.dll
  • some.other.plugin.dll

對於給定的輸出目錄,然後從模塊目錄我想要採取:

  • 一些命名的文件夾(和所有內容)
  • 另一個命名文件夾(和所有內容)
  • 尚未另一個命名文件夾(和所有內容)

並將所有這些放在另一個給定的輸出目錄中。

我試圖做到這一點:

<copy todir="${dir.projects.dynamic.binaries}"> 
    <fileset basedir="${dir.plugins}/**/binaries"> 
     <include name="*.plugin.dll" /> 
    </fileset> 
</copy> 
<copy todir="${dir.projects.dynamic.modules}"> 
    <fileset basedir="${dir.plugins}/**/modules"> 
     <include name="**/*" /> 
    </fileset> 
</copy> 

不過,我不斷收到錯誤,告訴我的文件集BASEDIR不能包含**或任何其他無效符號。該文檔似乎有點模糊,如果你可以或不可以在你的文件集basedir或不使用模式,但我假設在這個錯誤之後,我不能。

的問題是,如果我是這樣做,而不是這樣:

<copy todir="${dir.projects.dynamic.binaries}"> 
    <fileset basedir="${dir.plugins}"> 
     <include name="**/binaries/*.plugin.dll" /> 
    </fileset> 
</copy> 
<copy todir="${dir.projects.dynamic.modules}"> 
    <fileset basedir="${dir.plugins}"> 
     <include name="**/modules/**/*" /> 
    </fileset> 
</copy> 

但是它複製父文件夾,即DummyPlugin1/binaries/some.assembly.dllDummyPlugin2/binaries/some.other.plugin.dll而不僅僅是我想要的DLL。與模塊相同...

我知道我可以更改basedir來包含DummyPlugin1/binaries,DummyPlugin2/binaries,但我不知道有多少個文件夾將會在那裏,或者他們的名字將會是什麼,而不會不斷改變構建腳本,所以我寧願保持它的動態性,以便只是爲我提供任何插件和模塊,而不必爲每個插件文件夾製作可能或不可能存在的副本。

那麼我有什麼辦法讓我的蛋糕在這裏吃嗎?

回答

3

basedir必須是單個目錄,但您應該能夠使用flatten選項完成您想要的任務,該選項將所有輸入文件放入單個輸出目錄(基本上忽略路徑)。

再次閱讀您的問題:你可以試試這個嗎?

<copy todir="${dir.projects.dynamic.binaries}" flatten="true"> 
    <fileset> 
     <include name="${dir.plugins}/**/binaries/*.plugin.dll" /> 
    </fileset> 
</copy> 
<copy todir="${dir.projects.dynamic.modules}"> 
    <fileset basedir="${dir.plugins}"> 
     <include name="/**/modules/**/*" /> 
    </fileset> 
</copy> 
+0

問題是我需要保持文件夾結構從模塊目錄完整之內。正如我在那裏複製一個根文件夾和所有內容不只是一組文件。 – Grofit 2012-01-29 13:56:40

+0

也許用NAnt'foreach'生成單獨的文件集會更適合嗎?首先獲取目錄的文件集,然後遍歷它。 – skolima 2012-01-29 21:27:30

+0

您是否有示例或鏈接可以說明這種工作方式,Nant文檔現在有點稀疏。我打算使用Rake,但並不想要安裝ruby和rake的依賴。 – Grofit 2012-01-30 09:29:51

1

答案已經被列入你的問題:使用<foreach>循環:

<foreach item="Folder" property="binaries.path"> 
    <in> 
    <items basedir="${dir.plugins}"> 
     <include name="**/binaries" /> 
    </items> 
    </in> 
    <do> 
    <copy todir="${dir.projects.dynamic.binaries}"> 
     <fileset basedir="${binaries.path}"> 
     <include name="*.plugin.dll" /> 
     </fileset> 
    </copy> 
    </do> 
</foreach> 
<foreach item="Folder" property="modules.path"> 
    <in> 
    <items basedir="${dir.plugins}"> 
     <include name="**/modules" /> 
    </items> 
    </in> 
    <do> 
    <copy todir="${dir.projects.dynamic.modules}"> 
     <fileset basedir="${modules.path}"> 
     <include name="**/*" /> 
     </fileset> 
    </copy> 
    </do> 
</foreach>