====== Gant Ant Libraries ====== * [[http://ant.apache.org/manual/Types/antlib.html|AntLib]]는 그 자체는 Ant 라이브러리(태스크) 배포 시스템이다. 기존의 TaskDef의 부족한 점들을 메꿔주며 많은 Task들을 한 번에 정의하는 등의 기능을 제공한다. Ant 1.7 쯤 부터 기본 추가 돼 있다. * 태스크 이름 충돌이 발생하지 않도록 네임스페이스 지정 기능을 가지고 있다. * [[http://groovy.codehaus.org/Using+Ant+Libraries+with+AntBuilder|Using Ant Libraries with AntBuilder]] * [[http://ant.apache.org/antlibs/index.html|antlibs 공식 기본 라이브러리]] * [[http://onjava.com/pub/a/onjava/2006/08/09/ant-1-7-using-antlibs.html|Ant 1.7 Using antlibs]] * [[http://ant.apache.org/antlibs/antunit/index.html|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') } ===== 독립 네임스페이스로 가져오기 ===== 모든 태스크를 ant 기본 네임스페이스로 가져오면 태스크 이름의 충돌이 발생할 가능성이 높아진다. 이 이름 충돌을 방지하면서 여러 태스크를 정의하는 것이 AntLib의 기본적인 목적이다. AntUnit을 ''antunit'' 네임스페이스로 선언하여 사용할 수 있다. 이 방법을 권장한다. 가능하면 이 방법으로 AntLib 태스크들을 사용하는 것이 좋다. import groovy.xml.NamespaceBuilder // 네임스페이스 정의 // 자동으로 antlib: 뒤에있는 패키지경로에서 antlib.xml을 읽는 것 같음. // 즉, 여기서는 org/apache/ant/antunit/antlib.xml def antunit = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ant.antunit') target(antunittest: 'AntUnit Test') { // AntUnit의 태스크 바로 실행 antunit.assertFileDoesntExist(file:'copytest1.tmp') ant.copy(file:'src/some/HelloWorld.groovy', tofile:'copytest1.tmp') antunit.assertFileExists(file:'copytest1.tmp') ant.delete(file:'copytest1.tmp') antunit.assertFileDoesntExist(file:'copytest1.tmp') } ===== 기타 AntLib 지원 라이브러리들 ===== * [[http://ant.apache.org/antlibs/proper.html|Apache 기본 제공 AntLib들]] * [[http://maven.apache.org/ant-tasks/index.html|Maven Ant Tasks]] : Maven의 의존성 관리를 Ant에서 사용할 수 있게 해주는 AntLib * [[http://ant.apache.org/ivy/|Apache Ivy]] : Ivy는 Ant용 의존성 관리 시스템 * [[http://code.google.com/p/flyway/wiki/AntTasks|FlyWay]] 데이터베이스 마이그레이션 Ant 태스크