【问题标题】:Ant build and empty directoriesAnt 构建和清空目录
【发布时间】:2012-04-09 19:38:57
【问题描述】:

由于某种原因,当我使用scp 将文件从当前机器移动到使用ant 的服务器时,它总是忽略空目录。

<scp todir="ec2-user@xx.x.x.xxx:/var/www/html" keyfile="${basedir}\..\keys\prod_default.pem" trust="true">
<fileset dir="${staging.dir}" />
</scp>

为什么会这样?

完整更新详细日志:

D:\BUILD\SCRIPTS>ant -v -f getcom.xml update
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\BUILD\SCRIPTS\getcom.xml
Detected Java version: 1.7 in: C:\Program Files (x86)\Java\jdk1.7.0_02\jre
Detected OS: Windows Server 2008 R2
parsing buildfile D:\BUILD\SCRIPTS\getcom.xml with URI = file:/D:/BUILD/SCRIPTS/getcom.xml
Project base dir set to: D:\BUILD\SCRIPTS
parsing buildfile jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml
with URI = jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
 [property] Loading D:\BUILD\SCRIPTS\build.properties
Build sequence for target(s) `update' is [update]
Complete build sequence is [update, upload, cleanup, staging, export, init, ]

update:
     [exec] Current OS is Windows Server 2008 R2
     [exec] Executing 'C:\\Program Files (x86)\\subversion\\bin\\\svn' with arguments:
     [exec] 'update'
     [exec] 'D:\BUILD\SCRIPTS\..\_STAGING\GETOM'
     [exec] '--username'
     [exec] 'uuuu'
     [exec] '--password'
     [exec] 'uuuu'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] Updating 'D:\BUILD\_STAGING\GETOM':
     [exec] At revision 134.
      [scp] Connecting to xx.0.0.100:22
      [scp] done.
      [scp] Connecting to xx.0.2.100:22
      [scp] done.

BUILD SUCCESSFUL
Total time: 8 seconds

属性:

svn.repoBaseURL="https://uuu@uuuu.uuuu.com"
svn.username="uuuu"
svn.password="uuuu"
svn.bin=C://Program Files (x86)//subversion//bin//
MSBuildPath=C://WINDOWS//Microsoft.NET//Framework//v4.0.30319//MSBuild.exe
lib.path.ant-contrib=C:/ant/lib/ant-contrib-1.0b3.jar

请注意,文件夹名称已更改。

【问题讨论】:

  • 你是否以详细模式运行它?
  • @AmitBhargava 我已经更新了我的问题以显示我在详细模式下得到的结果。
  • 好吧,它似乎是从字面上理解 lib.path.ant-contrib 而不是替换这些值。你能分享你的构建属性文件吗?
  • @AmitBhargava 我已经解决了这个问题,并用日志更新了我的问题,因为它没有解决原来的问题。
  • 空目录的列表是否总是已知的?您可以在单独的步骤中创建它们吗?

标签: ant scp


【解决方案1】:

您必须想出一个解决方法。 Ant 实现 scp 的方式意味着总是会跳过空目录。

它的要点是 Scp 类这样做:

DirectoryScanner scanner = set.getDirectoryScanner(getProject());
Directory root = new Directory(scanner.getBasedir());
String[] files = scanner.getIncludedFiles();
if (files.length != 0) {
    ...
}

换句话说,它只处理包含至少一个文件的目录。

您可能会考虑使用patch for the Scp task code,但这意味着定制的 Ant 构建。

想到的另外两种方法是

  • 通过填充占位符文件(部署后可以删除)使目录非空
  • 在单独的步骤中创建空目录

【讨论】:

  • 谢谢马丁。我以为是这样。我会带你第一个选项,确保所有目录文件中至少有一个文件。
猜你喜欢
  • 1970-01-01
  • 2010-11-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-19
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多