author | wenzelm |
Tue, 22 Jul 2025 12:02:53 +0200 | |
changeset 82894 | a8e47bd31965 |
parent 81297 | 07f64697408e |
permissions | -rw-r--r-- |
81297 | 1 |
diff -ru jedit5.7.0/jEdit/org/gjt/sp/jedit/MiscUtilities.java jedit5.7.0-patched/jEdit/org/gjt/sp/jedit/MiscUtilities.java |
2 |
--- jedit5.7.0/jEdit/org/gjt/sp/jedit/MiscUtilities.java 2024-08-03 19:53:15.000000000 +0200 |
|
3 |
+++ jedit5.7.0-patched/jEdit/org/gjt/sp/jedit/MiscUtilities.java 2024-10-29 11:50:54.062016616 +0100 |
|
71932
65fd0f032a75
updated to jedit-5.6pre1 (repository version 25349);
wenzelm
parents:
69838
diff
changeset
|
4 |
@@ -131,6 +131,21 @@ |
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
5 |
static final Pattern winPattern = Pattern.compile(winPatternString); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
6 |
|
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
7 |
|
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
8 |
+ private static Map<String,String> environ = |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
9 |
+ Collections.synchronizedMap(new HashMap(System.getenv())); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
10 |
+ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
11 |
+ public static String getenv(String varName) |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
12 |
+ { |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
13 |
+ return environ.get(varName); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
14 |
+ } |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
15 |
+ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
16 |
+ public static void putenv(String varName, String value) |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
17 |
+ { |
69191 | 18 |
+ if (value == null) environ.remove(varName); |
19 |
+ else environ.put(varName, value); |
|
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
20 |
+ } |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
21 |
+ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
22 |
+ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
23 |
/** A helper function for expandVariables when handling Windows paths on non-windows systems. |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
24 |
*/ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
25 |
private static String win2unix(String winPath) |
71932
65fd0f032a75
updated to jedit-5.6pre1 (repository version 25349);
wenzelm
parents:
69838
diff
changeset
|
26 |
@@ -140,7 +155,7 @@ |
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
27 |
if (m.find()) |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
28 |
{ |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
29 |
String varName = m.group(2); |
81297 | 30 |
- String expansion = jEdit.systemManager.getenv(varName); |
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
31 |
+ String expansion = getenv(varName); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
32 |
if (expansion != null) |
81297 | 33 |
{ |
34 |
expansion = Matcher.quoteReplacement(expansion); |
|
35 |
@@ -182,7 +197,7 @@ |
|
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
36 |
return arg; |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
37 |
} |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
38 |
String varName = m.group(2); |
81297 | 39 |
- String expansion = jEdit.systemManager.getenv(varName); |
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
40 |
+ String expansion = getenv(varName); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
41 |
if (expansion == null) { |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
42 |
if (varName.equalsIgnoreCase("jedit_settings") && jEdit.getSettingsDirectory() != null) { |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
43 |
expansion = jEdit.getSettingsDirectory(); |
81297 | 44 |
@@ -192,7 +207,7 @@ |
69188
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
45 |
varName = varName.toUpperCase(); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
46 |
String uparg = arg.toUpperCase(); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
47 |
m = p.matcher(uparg); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
48 |
- expansion = System.getenv(varName); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
49 |
+ expansion = getenv(varName); |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
50 |
} |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
51 |
} |
2fd73a1a0937
updated to jedit_build-20181025 according to patches/macos (Java 11), patches/putenv;
wenzelm
parents:
diff
changeset
|
52 |
if (expansion != null) { |
81297 | 53 |
@@ -1674,13 +1689,11 @@ |
69191 | 54 |
//{{{ VarCompressor constructor |
55 |
VarCompressor() |
|
56 |
{ |
|
57 |
- ProcessBuilder pb = new ProcessBuilder(); |
|
58 |
- Map<String, String> env = pb.environment(); |
|
59 |
if (OperatingSystem.isUnix()) |
|
60 |
prefixMap.put(System.getProperty("user.home"), "~"); |
|
61 |
if (jEdit.getSettingsDirectory() != null) |
|
62 |
prefixMap.put(jEdit.getSettingsDirectory(), "JEDIT_SETTINGS"); |
|
63 |
- for (Map.Entry<String, String> entry: env.entrySet()) |
|
64 |
+ for (Map.Entry<String, String> entry: environ.entrySet()) |
|
65 |
{ |
|
66 |
String k = entry.getKey(); |
|
67 |
if (k.equalsIgnoreCase("pwd") || k.equalsIgnoreCase("oldpwd")) continue; |
|
81297 | 68 |
diff -ru jedit5.7.0/jEdit/test/org/gjt/sp/jedit/MiscUtilitiesTest.java jedit5.7.0-patched/jEdit/test/org/gjt/sp/jedit/MiscUtilitiesTest.java |
69 |
--- jedit5.7.0/jEdit/test/org/gjt/sp/jedit/MiscUtilitiesTest.java 2024-08-03 19:53:29.000000000 +0200 |
|
70 |
+++ jedit5.7.0-patched/jEdit/test/org/gjt/sp/jedit/MiscUtilitiesTest.java 2024-10-29 12:21:05.284840022 +0100 |
|
71 |
@@ -167,56 +167,6 @@ |
|
72 |
} |
|
73 |
||
74 |
@Test |
|
75 |
- public void expandVariablesEnvWindowsAsWindows() throws Exception |
|
76 |
- { |
|
77 |
- jEdit.systemManager = Mockito.mock(SystemManager.class); |
|
78 |
- var captor = ArgumentCaptor.forClass(String.class); |
|
79 |
- var value = "c:\\home\\jEdit"; |
|
80 |
- Mockito.when(jEdit.systemManager.getenv(captor.capture())).thenReturn(value); |
|
81 |
- updateOS(WINDOWS_NT); |
|
82 |
- var key = "jEdit_TEST"; |
|
83 |
- assertEquals(value, MiscUtilities.expandVariables('%' + key + '%')); |
|
84 |
- assertEquals(captor.getValue(), key); |
|
85 |
- } |
|
86 |
- @Test |
|
87 |
- public void expandVariablesEnvWindowsAsUnix() throws Exception |
|
88 |
- { |
|
89 |
- jEdit.systemManager = Mockito.mock(SystemManager.class); |
|
90 |
- var captor = ArgumentCaptor.forClass(String.class); |
|
91 |
- var value = "c:\\home\\jEdit"; |
|
92 |
- Mockito.when(jEdit.systemManager.getenv(captor.capture())).thenReturn(value); |
|
93 |
- updateOS(UNIX); |
|
94 |
- var key = "jEdit_TEST"; |
|
95 |
- assertEquals(value, MiscUtilities.expandVariables('%' + key + '%')); |
|
96 |
- assertEquals(captor.getValue(), key); |
|
97 |
- } |
|
98 |
- |
|
99 |
- @Test |
|
100 |
- public void expandVariablesEnvUnix() throws Exception |
|
101 |
- { |
|
102 |
- jEdit.systemManager = Mockito.mock(SystemManager.class); |
|
103 |
- var captor = ArgumentCaptor.forClass(String.class); |
|
104 |
- var value = "c:\\home\\jEdit"; |
|
105 |
- Mockito.when(jEdit.systemManager.getenv(captor.capture())).thenReturn(value); |
|
106 |
- updateOS(UNIX); |
|
107 |
- var key = "jEdit_TEST"; |
|
108 |
- assertEquals(value, MiscUtilities.expandVariables('$' + key)); |
|
109 |
- assertEquals(captor.getValue(), key); |
|
110 |
- } |
|
111 |
- |
|
112 |
- @Test |
|
113 |
- public void expandVariablesEnvUnix2() throws Exception |
|
114 |
- { |
|
115 |
- jEdit.systemManager = Mockito.mock(SystemManager.class); |
|
116 |
- var captor = ArgumentCaptor.forClass(String.class); |
|
117 |
- var value = "c:\\home\\jEdit"; |
|
118 |
- Mockito.when(jEdit.systemManager.getenv(captor.capture())).thenReturn(value); |
|
119 |
- updateOS(UNIX); |
|
120 |
- var key = "jEdit_TEST"; |
|
121 |
- assertEquals(value, MiscUtilities.expandVariables("${" + key + '}')); |
|
122 |
- } |
|
123 |
- |
|
124 |
- @Test |
|
125 |
public void expandVariablesEnvUnixNoMatch() throws Exception |
|
126 |
{ |
|
127 |
updateOS(UNIX); |