From 84f1fb395963614a2ff78a615c92fc79a52e2942 Mon Sep 17 00:00:00 2001 From: Andre F de Miranda Date: Sat, 1 Apr 2017 02:31:39 +1100 Subject: [PATCH] NIFI-3222 - Allow ExecuteScript,InvokeScriptedProcessor and ScriptedReporting to use ExpressionLanguage to define the scripting engine modules path Signed-off-by: Matt Burgess This closes #1640 --- .../nifi/processors/script/InvokeScriptedProcessor.java | 2 +- .../nifi/processors/script/ScriptingComponentHelper.java | 2 +- .../nifi/processors/script/ScriptingComponentUtils.java | 2 +- .../apache/nifi/reporting/script/ScriptedReportingTask.java | 2 +- .../apache/nifi/processors/script/TestExecuteJavascript.java | 3 ++- .../org/apache/nifi/processors/script/TestInvokeJython.java | 4 +++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java index fde4bb6c89..165fc75035 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java @@ -444,7 +444,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor { scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue()); scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue()); scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue()); - String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); + String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue(); if (!StringUtils.isEmpty(modulePath)) { scriptingComponentHelper.setModules(modulePath.split(",")); } else { diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentHelper.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentHelper.java index 9edad98486..a89b7b8a87 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentHelper.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentHelper.java @@ -285,7 +285,7 @@ public class ScriptingComponentHelper { scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue(); scriptPath = context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue(); scriptBody = context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue(); - String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); + String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue(); if (!StringUtils.isEmpty(modulePath)) { modules = modulePath.split(","); } else { diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentUtils.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentUtils.java index ac9e778d8f..43da7aad38 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentUtils.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptingComponentUtils.java @@ -60,7 +60,7 @@ public class ScriptingComponentUtils { .name("Module Directory") .description("Comma-separated list of paths to files and/or directories which contain modules required by the script.") .required(false) - .expressionLanguageSupported(false) + .expressionLanguageSupported(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java index b2873d4324..9241d83965 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java @@ -122,7 +122,7 @@ public class ScriptedReportingTask extends AbstractReportingTask { scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue()); scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue()); scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue()); - String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue(); + String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).evaluateAttributeExpressions().getValue(); if (!StringUtils.isEmpty(modulePath)) { scriptingComponentHelper.setModules(modulePath.split(",")); } else { diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java index cdfdb2ed43..032f567e8b 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java @@ -44,7 +44,8 @@ public class TestExecuteJavascript extends BaseScriptTest { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_onTrigger.js"); - runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/javascript"); + // Use basic manipulation to validate that EL is working + runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/${literal('JAVASCRIPT'):toLower()}"); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java index 50339279b4..661b8e470d 100755 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java @@ -104,7 +104,8 @@ public class TestInvokeJython extends BaseScriptTest { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_reader.py"); - runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jython"); + // Use EL to populate MODULES property + runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/${literal('JYTHON'):toLower()}"); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); @@ -139,6 +140,7 @@ public class TestInvokeJython extends BaseScriptTest { final TestRunner two = TestRunners.newTestRunner(new InvokeScriptedProcessor()); two.setValidateExpressionUsage(false); two.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); + two.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jython"); two.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/jython/test_compress.py"); two.setProperty("mode", "decompress");