사용자 도구

사이트 도구


gant:antlib

문서의 이전 판입니다!


Gant Ant Libraries

  • AntLib는 그 자체는 Ant 라이브러리(태스크) 배포 시스템이다. 기존의 TaskDef의 부족한 점들을 메꿔주며 많은 Task들을 한 번에 정의하는 등의 기능을 제공한다. Ant 1.7 쯤 부터 기본 추가 돼 있다.
  • 태스크 이름 충돌이 발생하지 않도록 네임스페이스 지정 기능을 가지고 있다.
  • AntUnit으로 알아보는 Gant에서 AntLib 적용하기. 미리 antunit jar 파일을 $GANT_HOME/lib에 복사해 둘 것.

직접 호출 방식

AntUnit의 태스크들이 antlib:org.apache.ant.antunit 네임스페이스에 속한 상태이며, 이를 매번 직접 지정하여 호출한다.

// 파일이 존재하지 않음(assertFileDoesntExist)을 확인
ant.'antlib:org.apache.ant.antunit:assertFileDoesntExist'(file:'copytest1.tmp')
 
ant.copy(file:'src/antunit.groovy', tofile:'copytest1.tmp')
// 이제 파일이 존재함(assertFileExists)을 확인
ant.'antlib:org.apache.ant.antunit:assertFileExists'(file:'copytest1.tmp')
 
ant.delete(file:'copytest1.tmp')
ant.'antlib:org.apache.ant.antunit:assertFileDoesntExist'(file:'copytest1.tmp')

antlib를 기본 네임스페이스로 가져오기

자신만의 네임스페이스에 있던 antlib 태스크들을 기본 네임스페이스로 가져와서 ant.*(혹은, ant. 빼고) 직접 호출하게 변경할 수 있다.

import org.apache.tools.ant.taskdefs.Antlib
 
// AntUnit 태스크 설정정보 파일 읽기
def url = this.class.getResource('org/apache/ant/antunit/antlib.xml')
// AntUnit의 태스크들을 현재 네임스페이스(ant.*)로 가져옴
Antlib.createAntlib(ant.antProject, url, 'antlib:org.apache.ant.antunit').execute()
 
target(antunittest: 'AntUnit Test') {
    // AntUnit의 태스크 바로 실행
    assertFileDoesntExist(file:'copytest1.tmp')
 
    copy(file:'src/some/HelloWorld.groovy', tofile:'copytest1.tmp')
    assertFileExists(file:'copytest1.tmp')
 
    delete(file:'copytest1.tmp')
    assertFileDoesntExist(file:'copytest1.tmp')
 
}
gant/antlib.1350898456.txt.gz · 마지막으로 수정됨: 2012/10/22 18:34 저자 kwon37xi