ISSUE #1375 - Improve svn provider english outputs#1376
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses ISSUE #1375 by normalizing the locale-related environment used for svn command execution in the svnexe provider, aiming to make command outputs more consistently parseable regardless of the user/system locale.
Changes:
- Add a
CommandlineFactoryhook to allow tests to interceptCommandlinecreation. - Update
getBaseSvnCommandLine(...)to unsetLC_ALLand setLC_MESSAGEStoC. - Add a unit test to verify the intended locale environment variables are applied.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java | Adds a configurable Commandline factory and applies locale environment normalization for SVN command lines. |
| maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtilsTest.java | Adds a test that injects a custom Commandline to assert LC_ALL/LC_MESSAGES are set as expected. |
Comments suppressed due to low confidence (1)
maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/SvnCommandLineUtils.java:121
- The locale env vars are set inside the same try/catch as addSystemEnvironment(). If addSystemEnvironment() throws, the catch block will skip setting LC_ALL/LC_MESSAGES, which undermines the purpose of this change (locale normalization). Set LC_* outside the try/catch so they’re applied even when system env cannot be loaded.
try {
cl.addSystemEnvironment();
// ISSUE-1375: ensure that LC_ALL is unset to avoid locale issues with svn command output parsing
// (setting just LC_ALL=C goes too far, since it would imply that LC_CTYPE=C, which would cause
// svn to output non-ASCII chars in an unreadable way.)
cl.addEnvironment("LC_ALL", "");
cl.addEnvironment("LC_MESSAGES", "C");
} catch (Exception e) {
// Do nothing
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // ISSUE-1375: ensure that LC_ALL is unset to avoid locale issues with svn command output parsing | ||
| // (setting just LC_ALL=C goes too far, since it would imply that LC_CTYPE=C, which would cause | ||
| // svn to output non-ASCII chars in an unreadable way.) | ||
| cl.addEnvironment("LC_ALL", ""); | ||
| cl.addEnvironment("LC_MESSAGES", "C"); |
| public static void setCommandlineFactory(CommandlineFactory factory) { | ||
| commandlineFactory = (factory != null) ? factory : DEFAULT_FACTORY; | ||
| } |
| * Active factory. Replaced only in tests; never {@code null}. | ||
| */ | ||
| private static CommandlineFactory commandlineFactory = DEFAULT_FACTORY; |
There was a problem hiding this comment.
The factory is meant just for testing. Not really to be used in multi-threaded executions.
| // ISSUE-1375: ensure that LC_ALL is unset and LC_MESSAGES is set to C to avoid locale issues with svn command | ||
| // output parsing | ||
| void testGetBaseSvnCommandLineLcAllIsSetToC() throws Exception { | ||
| Map<String, String> capturedEnvVarsMap = new HashMap<String, String>(); |
| @FunctionalInterface | ||
| public interface CommandlineFactory { | ||
| Commandline create(); | ||
| } |
kwin
left a comment
There was a problem hiding this comment.
Thanks for the PR @belingueres, can you look at the comments from Copilot?
|
@kwin do you want me to squash the new commit? |
|
No need to squash, I can do during merge. |
Force unset the LC_ALL env var in SvnCommandLineUtils class.
Force unset the LC_ALL env var in SvnCommandLineUtils class.
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.