|
Groovy example source code file (CompileOrderTest.groovy)
The Groovy CompileOrderTest.groovy source code
package groovy
class CompileOrderTest extends GroovyTestCase {
public void testCompileOrder() {
def interfaceFile = File.createTempFile("TestOrderInterface", ".groovy", new File("target"))
def concreteFile = File.createTempFile("TestOrderConcrete", ".groovy", new File("target"))
def cl = new GroovyClassLoader(this.class.classLoader);
def currentDir = concreteFile.parentFile.absolutePath
println currentDir
cl.addClasspath(currentDir)
cl.shouldRecompile = true
try {
// Create the interface
println "a"
interfaceFile.deleteOnExit()
def interfaceName = interfaceFile.name - ".groovy"
interfaceFile.write "interface $interfaceName { }\n"
// Create a concrete class which implements the interface
concreteFile.deleteOnExit()
def concreteName = concreteFile.name - ".groovy"
concreteFile.write "class $concreteName implements $interfaceName { }\n"
// We're testing whether this fails:
def groovyClass = cl.loadClass(concreteName,true,false)
// Create an object, just for good measure.
def object = groovyClass.newInstance()
} finally {
interfaceFile.delete()
concreteFile.delete()
}
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy CompileOrderTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.