@Override
protected void doCompile(String filename, File sourceDirectory, File outputDirectory) throws IOException {
try {
@SuppressWarnings("rawtypes")
List runtimeClasspathElements = project.getRuntimeClasspathElements();
Idl parser;
List<URL> runtimeUrls = new ArrayList<URL>();
// Add the source directory of avro files to the classpath so that
// imports can refer to other idl files as classpath resources
runtimeUrls.add(sourceDirectory.toURI().toURL());
// If runtimeClasspathElements is not empty values add its values to Idl path.
if (runtimeClasspathElements != null && !runtimeClasspathElements.isEmpty()) {
for (Object runtimeClasspathElement : runtimeClasspathElements) {
String element = (String) runtimeClasspathElement;
runtimeUrls.add(new File(element).toURI().toURL());
}
}
URLClassLoader projPathLoader = new URLClassLoader
(runtimeUrls.toArray(new URL[0]), Thread.currentThread().getContextClassLoader());
parser = new Idl(new File(sourceDirectory, filename), projPathLoader);
Protocol p = parser.CompilationUnit();
String json = p.toString(true);
Protocol protocol = Protocol.parse(json);
SpecificCompiler compiler = new SpecificCompiler(protocol);
compiler.setStringType(GenericData.StringType.valueOf(stringType));
compiler.setTemplateDir(templateDirectory);