From 3991900dfc956fc62b5463fc3d17407fc63df005 Mon Sep 17 00:00:00 2001 From: albilu <35330562+albilu@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:00:20 +0200 Subject: [PATCH] Apply StringTokenizer to build/test/pdoc parameters --- .../org/netbeans/modules/python/PythonUtility.java | 13 +++++++++++++ .../modules/python/actions/PythonBuild.java | 5 +++-- .../modules/python/actions/PythonDocGenerator.java | 5 +++-- .../netbeans/modules/python/actions/PythonRun.java | 5 ++--- .../python/testrunner/PythonTestManager.java | 3 ++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/netbeans/modules/python/PythonUtility.java b/src/main/java/org/netbeans/modules/python/PythonUtility.java index f144b01..be60f27 100644 --- a/src/main/java/org/netbeans/modules/python/PythonUtility.java +++ b/src/main/java/org/netbeans/modules/python/PythonUtility.java @@ -25,6 +25,8 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.text.StringTokenizer; +import org.apache.commons.text.matcher.StringMatcherFactory; import org.json.JSONObject; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.extexecution.ExecutionDescriptor; @@ -56,6 +58,13 @@ public class PythonUtility { public static final Logger LOG = Logger.getLogger(PythonUtility.class.getName()); + public static final StringTokenizer STRING_TOKENIZER = new StringTokenizer(); + + static { + STRING_TOKENIZER.setDelimiterMatcher(StringMatcherFactory.INSTANCE.spaceMatcher()); + STRING_TOKENIZER.setQuoteMatcher(StringMatcherFactory.INSTANCE.quoteMatcher()); + } + public static final RequestProcessor RP = new RequestProcessor("Retry RP", 2); public static final String PYTHON_MIME_TYPE = "text/x-python"; public static final File PYLSP_VENV_DIR = Paths.get(System.getProperty("netbeans.user")).resolve(".pythonlsp").toFile(); @@ -74,6 +83,10 @@ public class PythonUtility { return toFileObject != null ? toFileObject : null; }; + public static StringTokenizer getParamsTokenizer() { + return STRING_TOKENIZER; + } + public static LineConvertor FILE_CONVERTOR = LineConvertors.filePattern(FILE_LOCATOR, PYTHON_STACKTRACE_PATTERN, null, 1, 2); diff --git a/src/main/java/org/netbeans/modules/python/actions/PythonBuild.java b/src/main/java/org/netbeans/modules/python/actions/PythonBuild.java index 9cda480..84ebbbd 100644 --- a/src/main/java/org/netbeans/modules/python/actions/PythonBuild.java +++ b/src/main/java/org/netbeans/modules/python/actions/PythonBuild.java @@ -45,8 +45,9 @@ public static void runAction(Project owner, FileObject context) { if (owner != null) { Properties prop = PythonUtility.getProperties(owner, false); if (!prop.getProperty("nbproject.build.params", "").isEmpty()) { - params = prop.getProperty("nbproject.build.params", "") - .split(" "); + params = PythonUtility.getParamsTokenizer().reset( + prop.getProperty("nbproject.build.params", "") + ).getTokenArray(); } } List asList1 = null; diff --git a/src/main/java/org/netbeans/modules/python/actions/PythonDocGenerator.java b/src/main/java/org/netbeans/modules/python/actions/PythonDocGenerator.java index 7a6437e..f054ea9 100644 --- a/src/main/java/org/netbeans/modules/python/actions/PythonDocGenerator.java +++ b/src/main/java/org/netbeans/modules/python/actions/PythonDocGenerator.java @@ -52,8 +52,9 @@ public void actionPerformed(ActionEvent ev) { String[] params = {}; List argList = new ArrayList<>(); Properties prop = PythonUtility.getProperties(context, false); - params = prop.getProperty("nbproject.pdoc.params", "-o docs") - .split(" "); + params = PythonUtility.getParamsTokenizer().reset( + prop.getProperty("nbproject.pdoc.params", "-o docs") + ).getTokenArray(); List asList1 = null; asList1 = Arrays.asList(/*osShell[1],*/PythonUtility.getLspPythonExe(), diff --git a/src/main/java/org/netbeans/modules/python/actions/PythonRun.java b/src/main/java/org/netbeans/modules/python/actions/PythonRun.java index f7ca882..5422059 100644 --- a/src/main/java/org/netbeans/modules/python/actions/PythonRun.java +++ b/src/main/java/org/netbeans/modules/python/actions/PythonRun.java @@ -7,8 +7,6 @@ import java.util.List; import java.util.Properties; import java.util.logging.Logger; -import org.apache.commons.text.StringTokenizer; -import org.apache.commons.text.matcher.StringMatcherFactory; import org.netbeans.api.extexecution.ExecutionService; import org.netbeans.api.project.Project; import org.netbeans.modules.python.PythonOutputLine; @@ -59,7 +57,8 @@ public static List getRunArgs(Project owner, DataObject context, boolean if (owner != null) { Properties prop = PythonUtility.getProperties(owner, false); if (!prop.getProperty("nbproject.run.params", "").isEmpty()) { - params = new StringTokenizer(prop.getProperty("nbproject.run.params", ""), StringMatcherFactory.INSTANCE.spaceMatcher(), StringMatcherFactory.INSTANCE.quoteMatcher()).getTokenArray(); + params = PythonUtility.getParamsTokenizer() + .reset(prop.getProperty("nbproject.run.params", "")).getTokenArray(); } } if (owner != null && PythonUtility.isPoetry((PythonProject) owner) && !isDebug) { diff --git a/src/main/java/org/netbeans/modules/python/testrunner/PythonTestManager.java b/src/main/java/org/netbeans/modules/python/testrunner/PythonTestManager.java index 5ef0e20..d1a8408 100644 --- a/src/main/java/org/netbeans/modules/python/testrunner/PythonTestManager.java +++ b/src/main/java/org/netbeans/modules/python/testrunner/PythonTestManager.java @@ -31,7 +31,8 @@ public static Object[] getTestRunParams(PythonProject project) { try { Properties prop = PythonUtility.getProperties(project, false); return new Object[]{prop.getProperty("nbproject.test.runner", "unittest"), - prop.getProperty("nbproject.test.params", "*Test.py").split(" ")}; + PythonUtility.getParamsTokenizer().reset( + prop.getProperty("nbproject.test.params", "*Test.py")).getTokenArray()}; } catch (IOException ex) { Exceptions.printStackTrace(ex); }