/** * Method to get the mapper script type and load the default mapper script * * @return */ private String getMapperScriptType() { String mapperScriptType = ""; if (beanShellRadioButton.isSelected()) { defaultMapperScript = ScriptUtil.getTextForBeanShellScript(); mapperScriptType = ASpaceMapper.BEANSHELL_SCRIPT; } else if (jrubyRadioButton.isSelected()) { defaultMapperScript = ScriptUtil.getTextForJRubyScript(); mapperScriptType = ASpaceMapper.JRUBY_SCRIPT; } else if (pythonRadioButton.isSelected()) { defaultMapperScript = ScriptUtil.getTextForJythonScript(); mapperScriptType = ASpaceMapper.JYTHON_SCRIPT; } else { defaultMapperScript = ScriptUtil.getTextForJavascriptScript(); mapperScriptType = ASpaceMapper.JAVASCRIPT_SCRIPT; } System.out.println("Mapper Script Type: " + mapperScriptType); return mapperScriptType; }
private Map<String, Object> serviceInvoker( String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException { if (UtilValidate.isEmpty(modelService.location)) { throw new GenericServiceException("Cannot run Groovy service with empty location"); } Map<String, Object> params = FastMap.newInstance(); params.putAll(context); context.put(ScriptUtil.PARAMETERS_KEY, params); DispatchContext dctx = dispatcher.getLocalContext(localName); context.put("dctx", dctx); context.put("dispatcher", dctx.getDispatcher()); context.put("delegator", dispatcher.getDelegator()); try { ScriptContext scriptContext = ScriptUtil.createScriptContext(context, protectedKeys); ScriptHelper scriptHelper = (ScriptHelper) scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY); if (scriptHelper != null) { context.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper); } Script script = InvokerHelper.createScript( GroovyUtil.getScriptClassFromLocation( this.getLocation(modelService), groovyClassLoader), GroovyUtil.getBinding(context)); Object resultObj = null; if (UtilValidate.isEmpty(modelService.invoke)) { resultObj = script.run(); } else { resultObj = script.invokeMethod(modelService.invoke, EMPTY_ARGS); } if (resultObj == null) { resultObj = scriptContext.getAttribute(ScriptUtil.RESULT_KEY); } if (resultObj != null && resultObj instanceof Map<?, ?>) { return cast(resultObj); } Map<String, Object> result = ServiceUtil.returnSuccess(); result.putAll( modelService.makeValid(scriptContext.getBindings(ScriptContext.ENGINE_SCOPE), "OUT")); return result; } catch (GeneralException ge) { throw new GenericServiceException(ge); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } }
/** * Parses a camunda script element. * * @param scriptElement the script element ot parse * @return the generated executable script * @throws BpmnParseException if the a attribute is missing or the script cannot be processed */ public static ExecutableScript parseCamundaScript(Element scriptElement) { String scriptLanguage = scriptElement.attribute("scriptFormat"); if (scriptLanguage == null || scriptLanguage.isEmpty()) { throw new BpmnParseException( "Missing attribute 'scriptFormatAttribute' for 'script' element", scriptElement); } else { String scriptResource = scriptElement.attribute("resource"); String scriptSource = scriptElement.getText(); try { return ScriptUtil.getScript( scriptLanguage, scriptSource, scriptResource, getExpressionManager()); } catch (ProcessEngineException e) { throw new BpmnParseException("Unable to process script", scriptElement, e); } } }
public void packageToFile(File packageFile, ScriptUtil.Strategy strategy) throws Exception { File workingDirectoryF = VfsUtil.asFile(workingDirectory); File rpms = new File(workingDirectoryF, "RPMS"); File specsDir = new File(workingDirectoryF, "SPECS"); File tmp = new File(workingDirectoryF, "tmp"); File specFilePath = new File(specsDir, specFile.name + ".spec"); FileUtils.forceMkdir(new File(workingDirectoryF, "BUILD")); FileUtils.forceMkdir(rpms); FileUtils.forceMkdir(new File(workingDirectoryF, "SOURCES")); FileUtils.forceMkdir(specsDir); FileUtils.forceMkdir(new File(workingDirectoryF, "SRPMS")); FileUtils.forceMkdir(tmp); fileCollector.collect(); ScriptUtil.Result result = scriptUtil .createExecution(specFile.name, "rpm", getScripts(), workingDirectoryF, strategy) .execute(); specFile.includePre = result.preInstall; specFile.includePost = result.postInstall; specFile.includePreun = result.preRemove; specFile.includePostun = result.postRemove; specFile.buildRoot = VfsUtil.asFile(fileCollector.getFsRoot()); LineStreamUtil.toFile(specFile, specFilePath); new Rpmbuild() .setDebug(debug) .setBuildroot(VfsUtil.asFile(fileCollector.getFsRoot())) .define("_tmppath " + tmp.getAbsolutePath()) .define("_topdir " + workingDirectoryF.getAbsolutePath()) .define("_rpmdir " + packageFile.getParentFile().getAbsolutePath()) .define("_rpmfilename " + packageFile.getName()) .setSpecFile(specFilePath) .setRpmbuildPath(rpmbuildPath) .buildBinary(); }
/** Method to open up the code viewer dialog */ private void editScriptButtonActionPerformed() { if (beanShellRadioButton.isSelected()) { if (mapperScript.isEmpty()) { mapperScript = ScriptUtil.getTextForBeanShellScript(); } if (codeViewerDialogBeanshell == null) { codeViewerDialogBeanshell = new CodeViewerDialog( this, SyntaxConstants.SYNTAX_STYLE_JAVA, mapperScript, true, false); } else { codeViewerDialogBeanshell.setCurrentScript(mapperScript); } codeViewerDialogBeanshell.setScriptFile(scriptFile); codeViewerDialogBeanshell.setTitle("BeanShell Mapper Script Editor"); codeViewerDialogBeanshell.pack(); codeViewerDialogBeanshell.setVisible(true); } else if (jrubyRadioButton.isSelected()) { if (mapperScript.isEmpty()) { mapperScript = ScriptUtil.getTextForJRubyScript(); } // must be a python script if (codeViewerDialogJruby == null) { codeViewerDialogJruby = new CodeViewerDialog( this, SyntaxConstants.SYNTAX_STYLE_RUBY, mapperScript, true, false); } else { codeViewerDialogJruby.setCurrentScript(mapperScript); } codeViewerDialogJruby.setScriptFile(scriptFile); codeViewerDialogJruby.setTitle("JRuby Mapper Script Editor"); codeViewerDialogJruby.pack(); codeViewerDialogJruby.setVisible(true); } else if (pythonRadioButton.isSelected()) { if (mapperScript.isEmpty()) { mapperScript = ScriptUtil.getTextForJythonScript(); } // must be a python script if (codeViewerDialogJython == null) { codeViewerDialogJython = new CodeViewerDialog( this, SyntaxConstants.SYNTAX_STYLE_PYTHON, mapperScript, true, false); } else { codeViewerDialogJython.setCurrentScript(mapperScript); } codeViewerDialogJython.setScriptFile(scriptFile); codeViewerDialogJython.setTitle("Jython Mapper Script Editor"); codeViewerDialogJython.pack(); codeViewerDialogJython.setVisible(true); } else { if (mapperScript.isEmpty()) { mapperScript = ScriptUtil.getTextForJavascriptScript(); } // must be a javascript if (codeViewerDialogJavascript == null) { codeViewerDialogJavascript = new CodeViewerDialog( this, SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, mapperScript, true, false); } else { codeViewerDialogJavascript.setCurrentScript(mapperScript); } codeViewerDialogJavascript.setScriptFile(scriptFile); codeViewerDialogJavascript.setTitle("Javascript Mapper Script Editor"); codeViewerDialogJavascript.pack(); codeViewerDialogJavascript.setVisible(true); } }