Package org.rhq.bundle.filetemplate.recipe

Examples of org.rhq.bundle.filetemplate.recipe.RecipeContext$Script


   
    this.modifiedQuery = q.toString();
   
    Boolean result = null;
    if (rewritten) {
      Script script = engine.createScript(this.modifiedQuery);
      try {
        result = (Boolean) script.execute(ctx);
      } catch (Exception e) {
        log.error("Error evaluating script: " + this.modifiedQuery + " against event" + eventFields.toString(), e);
      }
    } else {
      Expression expr = engine.createExpression(this.modifiedQuery);
View Full Code Here


            throw new NullPointerException("script and context must be non-null");
        }
        // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
        context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
        try {
            Script jexlScript = jexlEngine.createScript(script);
            JexlContext ctxt = new JexlContextWrapper(context);
            return jexlScript.execute(ctxt);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        // This is mandated by JSR-223
        if (script == null) {
            throw new NullPointerException("script must be non-null");
        }
        try {
            Script jexlScript = jexlEngine.createScript(script);
            return new JexlCompiledScript(jexlScript);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        if (ctx instanceof JexlContext) {
            jexlCtx = (JexlContext) ctx;
        } else {
            throw new SCXMLExpressionException(ERR_CTX_TYPE);
        }
        Script jexlScript = null;
        try {
            final JexlContext effective = getEffectiveContext(jexlCtx);
            effective.setEvaluatingLocation(true);
            jexlScript = getJexlEngine().createScript(script);
            return jexlScript.execute(effective);
        } catch (Exception e) {
            String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
            throw new SCXMLExpressionException("evalScript('" + script + "'): " + exMessage, e);
        }
    }
View Full Code Here

  public boolean filterMatchesEntry(String filter, FeedEntry entry) throws FeedEntryFilterException {
    if (StringUtils.isBlank(filter)) {
      return true;
    }

    Script script = null;
    try {
      script = ENGINE.createScript(filter);
    } catch (JexlException e) {
      throw new FeedEntryFilterException("Exception while parsing expression " + filter, e);
    }

    JexlContext context = new MapContext();
    context.set("title", Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
    context.set("author", entry.getContent().getAuthor().toLowerCase());
    context.set("content", Jsoup.parse(entry.getContent().getContent()).text().toLowerCase());
    context.set("url", entry.getUrl().toLowerCase());

    Callable<Object> callable = script.callable(context);
    Future<Object> future = executor.submit(callable);
    Object result = null;
    try {
      result = future.get(500, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
View Full Code Here

        log.debug("The filetemplate bundle plugin has been shut down!!! : " + this);
    }

    public RecipeParseResults parseRecipe(String recipe) throws UnknownRecipeException, Exception {
        RecipeParser parser = new RecipeParser();
        RecipeContext recipeContext = new RecipeContext(recipe);
        try {
            parser.parseRecipe(recipeContext);
        } catch (Exception e) {
            if (recipeContext.isUnknownRecipe()) {
                throw new UnknownRecipeException("Not a valid file template recipe");
            }
            throw e;
        }

        DeploymentProperties bundleMetadata = recipeContext.getDeploymentProperties();

        Set<String> bundleFileNames = new HashSet<String>();
        Map<String, String> deployFiles = recipeContext.getDeployFiles();
        bundleFileNames.addAll(deployFiles.keySet());
        Set<String> scriptFiles = recipeContext.getScriptFiles();
        bundleFileNames.addAll(scriptFiles);
        Set<String> files = recipeContext.getFiles().keySet();
        bundleFileNames.addAll(files);

        ConfigurationDefinition configDef = null;
        if (recipeContext.getReplacementVariables() != null) {
            configDef = new ConfigurationDefinition("replacementVariables", null);
            for (String replacementVar : recipeContext.getReplacementVariables()) {
                PropertyDefinitionSimple prop = new PropertyDefinitionSimple(replacementVar,
                    "Needed by bundle recipe.", false, PropertySimpleType.STRING);
                prop.setDisplayName(replacementVar);
                prop.setDefaultValue(recipeContext.getReplacementVariableDefaultValues().get(replacementVar));
                configDef.put(prop);
            }
        }

        RecipeParseResults results = new RecipeParseResults(bundleMetadata, configDef, bundleFileNames);
View Full Code Here

        File anotherDest = new File(testDestDir, "/OTHER/another.xml");

        addRecipeCommand("file --source=run-me.sh \"--destination=" + runmeDest + "\"");
        addRecipeCommand("file -s META-INF/another.xml -d \"" + anotherDest + "\"");

        RecipeContext context = parseRecipeNow(testDir);

        Map<String, String> files = context.getFiles();
        assert files.size() == 2 : files;
        assert files.get("run-me.sh") != null : files;
        assert files.get("run-me.sh").equals(runmeDest.getPath()) : files;
        assert files.get("META-INF/another.xml") != null : files;
        assert files.get("META-INF/another.xml").equals(anotherDest.getPath()) : files;
View Full Code Here

        File unzippedFile = new File(testDestDir, "zipped-file.txt");
        File zipFile = createZip("zipped file content", testDir, "deploy-test.zip", unzippedFile.getName());

        addRecipeCommand("deploy -f " + zipFile.getName() + " -d \"" + testDestDir + "\"");

        RecipeContext context = parseRecipeNow(testDir);

        Map<String, String> files = context.getDeployFiles();
        assert files.size() == 1 : files;
        assert files.get(zipFile.getName()) != null;

        String zippedFileContent = readFile(unzippedFile);
        assert zippedFileContent.equals("zipped file content");
View Full Code Here

        echoOutput.getParentFile().mkdirs();
        File script = writeFile("echo hello > \"" + echoOutput.getAbsolutePath() + "\"\n", testDir, "bin/test.sh");

        addRecipeCommand("script bin/test.sh");

        RecipeContext context = parseRecipeNow(testDir);

        Set<String> scripts = context.getScriptFiles();
        assert scripts.size() == 1 : scripts;
        assert scripts.contains("bin/test.sh") : scripts;
        String echoOutputContent = readFile(echoOutput);
        assert echoOutputContent.trim().equals("hello");
    }
View Full Code Here

            addRecipeCommand("command cmd /C \"echo helloWorld > '" + echoOutput.getAbsolutePath() + "'\"");
        } else {
            addRecipeCommand("command sh -c \"echo helloWorld > '" + echoOutput.getAbsolutePath() + "'\"");
        }

        RecipeContext context = parseRecipeNow(testDir);

        String echoOutputContent = readFile(echoOutput);
        assert echoOutputContent.trim().equals("helloWorld");
    }
View Full Code Here

TOP

Related Classes of org.rhq.bundle.filetemplate.recipe.RecipeContext$Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.