mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 01:58:32 +00:00
NIFI-10621 Allow ExecuteGroovyScript classpath properties to accept commas or semicolons
ExecuteGroovyScript's "Additional classpath" property treats commas and semicolons as delimiters Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #6523
This commit is contained in:
parent
08a1f09905
commit
b784d6e8ee
@ -131,7 +131,7 @@ public class ExecuteGroovyScript extends AbstractProcessor {
|
||||
.name("groovyx-additional-classpath")
|
||||
.displayName("Additional classpath")
|
||||
.required(false)
|
||||
.description("Classpath list separated by semicolon. You can use masks like `*`, `*.jar` in file name.")
|
||||
.description("Classpath list separated by semicolon or comma. You can use masks like `*`, `*.jar` in file name.")
|
||||
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
|
||||
.build();
|
||||
|
@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
||||
public class Files {
|
||||
|
||||
/**
|
||||
* Classpath list separated by semicolon. You can use masks like `*`, `*.jar` in file name.
|
||||
* Classpath list separated by semicolon or comma. You can use masks like `*`, `*.jar` in file name.
|
||||
*
|
||||
* @return file list defined by classpath parameter
|
||||
*/
|
||||
@ -39,7 +39,7 @@ public class Files {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<File> files = new HashSet<>();
|
||||
for (String cp : classpath.split("\\s*;\\s*")) {
|
||||
for (String cp : classpath.split("\\s*[;,]\\s*")) {
|
||||
files.addAll(listPathFiles(cp));
|
||||
}
|
||||
return files;
|
||||
|
@ -46,13 +46,17 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@ -162,6 +166,25 @@ public class ExecuteGroovyScriptTest {
|
||||
result.get(0).assertAttributeEquals("testAttr", "test content");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdditionalClasspath() throws Exception {
|
||||
Set<URL> expectedClasspathURLs = new HashSet<>();
|
||||
StringBuilder additionalClasspath = new StringBuilder();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Path p = java.nio.file.Files.createTempFile(getClass().getName(), ".tmp");
|
||||
expectedClasspathURLs.add(p.toUri().toURL());
|
||||
additionalClasspath.append(p);
|
||||
additionalClasspath.append(i == 0 ? ',' : ';'); // create additional classpath string separated by ; and ,
|
||||
}
|
||||
|
||||
runner.setProperty(ExecuteGroovyScript.ADD_CLASSPATH, additionalClasspath.toString());
|
||||
runner.setProperty(ExecuteGroovyScript.SCRIPT_BODY, ";");
|
||||
runner.assertValid();
|
||||
|
||||
URL[] classpathURLs = proc.shell.getClassLoader().getURLs();
|
||||
assertEquals(expectedClasspathURLs, new HashSet<>(Arrays.asList(classpathURLs)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_onTrigger_groovy() {
|
||||
runner.setProperty(proc.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "test_onTrigger.groovy");
|
||||
|
Loading…
x
Reference in New Issue
Block a user