2009-08-07 5 views
14

파일 디렉토리를 복사하고 그 중 일부의 이름을 바꾸고 싶습니다. 아래 스크립트를 실행해도 아무 것도 복사되지 않습니다. 아래 파일의 glob 매퍼에 댓글을 달면 파일 이름이 바뀌지 않고 복사됩니다.ANT 복사 중 파일 이름 바꾸기

도움을 주셔서 감사합니다. 제임스

<?xml version="1.0" ?> 
<project name="Create project structure" default="main"> 
    <target name="main" description="Copy template files to project folder"> 
    <echo>Copying template files to project folder</echo> 
    <copy todir="${project.dir}" verbose="true" overwrite="true"> 
     <fileset dir="${shared.files}/templateproject" excludes=".svn"/> 
     <mapper> 
     <chainedmapper> 
      <mapper type="glob" from="*PACKAGENAME*" to="*${package.name}*"/> 
      <mapper type="glob" from="*GAMENAME*" to="*${game.name}*"/> 
      <mapper type="identity"/> 
     </chainedmapper> 
     </mapper> 
    </copy> 
    </target> 
</project> 

답변

10

것 같다, 하나와 '*'는 glob-mapper 작동하는지. 나는 시도 할 것이다 regexp-mapper : "이동"및 Mnementh로 표시된 바와 같이 올바른 매퍼 유형을 사용하여 해결 방법에 의존

<mapper type="regexp" from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2"/> 
<mapper type="regexp" from="(.*)GAMENAME(.*)" to="\1${game.name}\2"/> 
+0

답변 해 주셔서 감사합니다. 바로 사용할 수있는 매퍼입니다. 그러나 매퍼는 한 번에 하나씩 만 작업하고 싶습니다. 두 명을 주석으로 처리하면 다른 하나가 작동합니다. 각자 테스트를 거쳐야합니다. 첫 번째 바꾸기를 시도한 다음 두 번째 바꾸기를 복사하지 않으면 (ID 매퍼). 감사합니다. 도움이되었습니다. – tarling

14

. 감사합니다

<?xml version="1.0" ?> 
<project name="Create project structure" default="main"> 
    <target name="main" description="Copy template files to project folder"> 
    <echo>Copying template files to project folder</echo> 
    <copy todir="${project.dir}" verbose="true" overwrite="true"> 
     <fileset dir="${shared.files}/templateproject" excludes=".svn" /> 
    </copy> 
    <move todir="${project.dir}"> 
     <fileset dir="${project.dir}" /> 
     <mapper> 
     <mapper type="regexp" 
       from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2" /> 
     <mapper type="regexp" 
       from="(.*)GAMENAME(.*)" to="\1${game.name}\2" /> 
     </mapper> 
    </move> 
    </target> 
</project> 
+0

매우 유용합니다. 감사합니다! –

+0

좋은 해결책! 작동하지 않는 한 가지는 교체 할 품목이 여러 개있는 경우입니다. 예 : PACKAGENAME \ blah \ foo \ PACKAGENAME 경로를 고려하십시오. 내가 관찰 한 것은 첫 번째 이름 바꾸기 만 작동한다는 것입니다. 나의 일반적인 해결 방법은이 이동을 10 번 반복하기 위해서 단순히 루프를 사용하는 것이었다. 추악하지만 작동하는 것 같습니다. – John

4

귀하의 문제는 당신이 바로 매퍼 선택하지 않은 것입니다 : <chainedmapper>

대신 마지막 매퍼에 처음부터 체인 정보를 전달하는 것, <firstmatchmapper>는 모든 매퍼를 시도하는, 사용되어야한다 http://ant.apache.org/manual/Types/mapper.html

(꽤 오래된 질문,하지만 난 그냥 :-) 거의 같은 문제를 찾고 발견)

하나는

참조 일치 할 때까지, 설정