private int executeScriptFile( CommandLine commandLine, String scriptName, String env, GantBinding binding, Resource scriptFile) { // We can now safely set the default environment String scriptFileName = getScriptNameFromFile(scriptFile); setRunningEnvironment(commandLine, env); binding.setVariable("scriptName", scriptFileName); // Setup the script to call. ScriptBindingInitializer bindingInitializer = new ScriptBindingInitializer(commandLine, settings, pluginPathSupport, isInteractive); Gant gant = new Gant(bindingInitializer.initBinding(binding, scriptName), classLoader); gant.setUseCache(true); gant.setCacheDirectory(scriptCacheDir); GantResult result = null; try { gant.loadScript(scriptFile.getURL()); result = executeWithGantInstance(gant, DO_NOTHING_CLOSURE); return result.exitCode; } catch (IOException e) { console.error("I/O exception loading script [" + e.getMessage() + "]: " + e.getMessage()); return 1; } finally { cleanup(result, binding); } }
private GantResult executeWithGantInstance(Gant gant, final Closure<?> doNothingClosure) { GantResult result = new GantResult(); result.script = gant.prepareTargets(); gant.setAllPerTargetPostHooks(doNothingClosure); gant.setAllPerTargetPreHooks(doNothingClosure); // Invoke the default target. result.exitCode = gant.executeTargets(); return result; }
private void loadScriptClass(Gant gant, String scriptName) { try { // try externalized script first gant.loadScriptClass(scriptName + "_"); } catch (Exception e) { try { gant.loadScriptClass(scriptName); } catch (Exception ex) { if (ex instanceof ClassNotFoundException && ex.getMessage() != null && ex.getMessage().contains(scriptName)) { throw new ScriptNotFoundException(scriptName); } } } }