Skip to content

Commit

Permalink
Apply StringTokenizer to build/test/pdoc parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
albilu committed Oct 16, 2024
1 parent 4c76adc commit 3991900
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/netbeans/modules/python/PythonUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> asList1 = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public void actionPerformed(ActionEvent ev) {
String[] params = {};
List<String> 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<String> asList1 = null;

asList1 = Arrays.asList(/*osShell[1],*/PythonUtility.getLspPythonExe(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +57,8 @@ public static List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3991900

Please sign in to comment.