/** * Create an API object from the specified file. Java files are read by * Janino and are expected to implement a build method (they implement a * derived class of SunflowAPI. The build method is called if the code * compiles succesfully. Other files types are handled by the parse method. * * @param filename filename to load * @return a valid SunflowAPI object or <code>null</code> on failure */ public static SunflowAPI create(string filename, int frameNumber) { if (filename == null) { return(new SunflowAPI()); } SunflowAPI api = null; if (filename.EndsWith(".java")) { Timer t = new Timer(); UI.printInfo(UI.Module.API, "Compiling \"" + filename + "\" ..."); t.start(); try { //FileInputStream stream = new FileInputStream(filename); api = null;//(SunflowAPI) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(filename, stream), SunflowAPI.class, ClassLoader.getSystemClassLoader()); //fixme: the dynamic loading //stream.close(); } catch (Exception e) { UI.printError(UI.Module.API, "Could not compile: \"{0}\"", filename); UI.printError(UI.Module.API, "{0}", e); return(null); } t.end(); UI.printInfo(UI.Module.API, "Compile time: " + t.ToString()); if (api != null) { string currentFolder = Path.GetDirectoryName(filename);//new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath(); api.includeSearchPath.addSearchPath(currentFolder); api.textureSearchPath.addSearchPath(currentFolder); } UI.printInfo(UI.Module.API, "Build script running ..."); t.start(); api.setCurrentFrame(frameNumber); api.build(); t.end(); UI.printInfo(UI.Module.API, "Build script time: {0}", t.ToString()); } else { api = new SunflowAPI(); api = api.parse(filename) ? api : null; } return(api); }