⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 anttest.groovy

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 GROOVY
字号:
package groovy.utilimport java.io.Fileimport org.apache.tools.ant.Projectimport org.apache.tools.ant.ProjectHelperclass AntTest extends GroovyTestCase {        void testAnt() {        def ant = new AntBuilder()        // lets just call one task        ant.echo("hello")                // here"s an example of a block of Ant inside GroovyMarkup        ant.sequential {            echo("inside sequential")                        def myDir = "target/AntTest/"                        mkdir(dir:myDir)             copy(todir:myDir) {                fileset(dir:"src/test") {                    include(name:"**/*.groovy")                }            }                        echo("done")        }                // now lets do some normal Groovy again        def file = new File("target/AntTest/groovy/util/AntTest.groovy")        assert file.exists()    }        void testFileIteration() {        def ant = new AntBuilder()                // lets create a scanner of filesets        def scanner = ant.fileScanner {            fileset(dir:"src/test") {                include(name:"**/Ant*.groovy")            }        }                // now lets iterate over         def found = false        for (f in scanner) {            println("Found file ${f}")                        found = true                        assert f instanceof File            assert f.name.endsWith(".groovy")        }        assert found    }        void testJunitTask() {        def ant = new AntBuilder()                ant.junit {            test(name:'groovy.util.SomethingThatDoesNotExist')        }    }        void testPathBuilding() {        def ant = new AntBuilder()                def value = ant.path {            fileset(dir:"xdocs") {                include(name:"*.wiki")            }        }        assert value != null        assertEquals org.apache.tools.ant.types.Path, value.getClass()    }    void testTaskContainerExecutionSequence() {        SpoofTaskContainer.getSpoof().length = 0        def antFile = new File("src/test/groovy/util/AntTest.xml")        assertTrue "Couldn't find ant test script", antFile.exists()		// run it with ant, to be sure that our assumptions are correct		def project = new Project()		project.init()		ProjectHelper.projectHelper.parse(project, antFile)		project.executeTarget(project.defaultTarget);		        def expectedSpoof ="""SpoofTaskContainer ctorin addTaskconfiguring UnknownElementSpoofTask ctorbegin SpoofTaskContainer executebegin SpoofTask executetag name from wrapper: spoofattributes map from wrapper: ["foo":"123"]param foo: 123end SpoofTask executeend SpoofTaskContainer execute"""		println SpoofTaskContainer.getSpoof().toString()        assertEquals expectedSpoof, SpoofTaskContainer.getSpoof().toString()        SpoofTaskContainer.spoof.length = 0        def ant = new AntBuilder()        def PATH = 'task.path'		// and now run it with the AntBuilder                ant.path(id:PATH) {ant.pathelement(location:'classes')}        ['spoofcontainer': SpoofTaskContainer, 'spoof': SpoofTask].each{ pair ->            ant.taskdef(name:pair.key, classname: pair.value.name, classpathref: PATH)        }        ant.spoofcontainer(){            ant.spoof(foo: 123)        }        assertEquals expectedSpoof, SpoofTaskContainer.getSpoof().toString()    }    /** Checks that we can access dynamically (through Ant's property task) defined properties in Groovy scriptlets */    void testDynamicProperties() {        def antBuilder = new AntBuilder()        antBuilder.property(name: "testProp1", value: "TEST 1")        antBuilder.taskdef(name:"groovy", classname:"org.codehaus.groovy.ant.Groovy")        antBuilder.groovy("""            ant.property(name: "testProp2", value: "TEST 2")            assert properties.testProp1 == project.properties.testProp1            assert properties.testProp2 == project.properties.testProp2        """)    }        /**    * Tests that the AntBuilder can handle conditions (conditions aren't tasks)    * (test for GROOVY-824)    */    void testCondition() {        def ant = new AntBuilder()        ant.condition(property: "containsHi") {        	contains([string: "hi", substring: "hi"])        }        assertEquals "true", ant.project.properties["containsHi"]        ant.condition(property: "equalsHi", else: "false") {        	Equals([arg1: "hi", arg2: "bye"])        }        assertEquals "false", ant.project.properties["equalsHi"]    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -