compile(path, Collections.singletonList(sourceFile), Collections.<File>emptyList());
generate(path, fileName, Collections.<File>emptyList(), path);
}
static void generate(final String path, final String className, List<File> dependencies, String outputDir) {
Generator gen = new Generator();
try {
List<URL> classpathElements = new ArrayList<URL>();
classpathElements.add(new File(path).toURI().toURL());
for (File dep : dependencies) {
classpathElements.add(dep.toURI().toURL());
}
ClassLoader builtProjectClassLoader = new URLClassLoader(classpathElements.toArray(new URL[classpathElements.size()]), Thread
.currentThread().getContextClassLoader());
File sourceFolder = new File(path);
GenerationDirectory targetFolder = new GenerationDirectory(new File(outputDir), null, null);
File generationFolder = targetFolder.getAbsolutePath();
GeneratorConfigurationBuilder configBuilder = new GeneratorConfigurationBuilder();
configBuilder.allowedPackage(builtProjectClassLoader.loadClass(className).getPackage().getName());
GeneratorConfiguration configuration = configBuilder.build();
gen.init(builtProjectClassLoader, configuration.getSourceEncoding());
gen.generateJavascript(builtProjectClassLoader, className, sourceFolder, targetFolder, generationFolder, configuration);
}
catch (Exception e) {
throw Throwables.propagate(e);
}
finally {
gen.close();
}
}