Source:
public void execute(ApplicationContext currentContext) throws CLIException { SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler(); try { Map<String, Object> schedulerProperties = scheduler.getSchedulerPropertiesFromSessionId(currentContext.getSessionId()); resultStack(currentContext).push(schedulerProperties); logger.info("The scheduler properties are retrieved"); if (!validatePackagePath()) { throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("'%s'does not exist or is not a valid Package path.", PACKAGE_PATH_NAME)); } schedulerProperties.put("package.path.name", PACKAGE_PATH_NAME); schedulerProperties.put("session.id", currentContext.getSessionId()); ScriptHandler scriptHandler = new ScriptHandler(); scriptHandler.addBindings(schedulerProperties); ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os, true); ScriptResult scriptResult; File scriptFile; scriptFile = new File(PASchedulerProperties.getAbsolutePath(SCRIPT_PATH)); if (scriptFile.exists()) { logger.info("Executing " + SCRIPT_PATH); String[] param = { PACKAGE_PATH_NAME }; scriptResult = scriptHandler.handle(new SimpleScript(scriptFile, param), ps, ps); if (scriptResult.errorOccured()) { os.close(); ps.close(); throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException()); } logger.info(os.toString()); os.reset(); } else { logger.warn("Start script " + SCRIPT_PATH + " not found"); } os.close(); ps.close(); writeLine(currentContext, "Package('%s') successfully installed in the catalog", PACKAGE_PATH_NAME); resultStack(currentContext).push(PACKAGE_PATH_NAME); } catch (Exception e) { handleError(String.format("An error occurred while attempting to install package('%s') in the catalog", PACKAGE_PATH_NAME), e, currentContext); e.printStackTrace(); } }

Target:
public void execute(ApplicationContext currentContext) throws CLIException { SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler(); ByteArrayOutputStream outputStream = null; PrintStream printStream = null; ScriptResult scriptResult; try { validatePackagePath(); Map<String, Object> schedulerProperties = retrieveSchedulerProperties(currentContext, scheduler); Map<String, Object> propertiesWithSessionIdAndPackage = addSessionIdAndPackageNameToProperties(currentContext, schedulerProperties); ScriptHandler scriptHandler = createScriptHandlerAndAddBindings(propertiesWithSessionIdAndPackage); File scriptFile = new File(PASchedulerProperties.getAbsolutePath(SCRIPT_PATH)); String[] param = { PACKAGE_PATH_NAME }; scriptResult = scriptExecutor.execute(scriptHandler, scriptFile, param); if (scriptResult.errorOccured()) { logger.warn("Failed to execute script: " + SCRIPT_PATH); throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException()); } else { writeLine(currentContext, "Package('%s') successfully installed in the catalog", PACKAGE_PATH_NAME); } } catch (Exception e) { handleError(String.format("An error occurred while attempting to install package('%s') in the catalog", PACKAGE_PATH_NAME), e, currentContext); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { } } if (printStream != null) { printStream.close(); } } }