Showing alert message in logs while doing copy in Ant

混江龙づ霸主 提交于 2019-12-20 07:37:27

问题


I have fromfolder=xxx it has one.txt and
tofolder=yyy same file is there one.txt

While performing copy operation by using ant if it found same name of file is present then it will show alert message like files already present one.txt in log and should not overwrite the file.

 <target name="copyPublicHtml" description="Copy Public_html to output directory" >
     <touch>
     <fileset dir="../html"/>
    </touch>

       <copy todir="../html" failonerror="on" verbose="on" overwrite="false"> 
            <fileset dir="../src">           
       </copy>
  </target>

回答1:


You can use the groovy task to iterate thru the files:

  <target name="copyPublicHtml" depends="init" description="Copy Public_html to output directory">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <fileset id="srcFiles" dir="src"/>

    <groovy>
      project.references.srcFiles.each {
        def src = new File(it.toString())
        def trg = new File("html", src.name)

        if (trg.exists()) {
          project.log "File already exists: ${trg}"
        }

        ant.copy(file:it, todir:"html", verbose:"true", overwrite:"false")
      }
    </groovy>
  </target>


来源:https://stackoverflow.com/questions/14586610/showing-alert-message-in-logs-while-doing-copy-in-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!