Skip to content

Commit d62b56e

Browse files
authored
Merge pull request #147 from snyk/fix/HEAD-447_custom_path
Fix: custom path for CLI
2 parents 257521b + 8d946ff commit d62b56e

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

plugin/src/main/java/io/snyk/languageserver/LsRuntimeEnvironment.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,9 @@ public void addPath(Map<String, String> env) {
123123
var pathOptional = Preferences.getInstance().getPath();
124124
if (pathOptional.isPresent()) {
125125
var path = pathOptional.get();
126-
String splitBy;
127-
if (path.contains(";")) {
128-
splitBy = ";";
129-
} else {
130-
splitBy = ":";
131-
}
132-
String newPath = path.replace(splitBy, File.pathSeparator)
133-
+ File.pathSeparator
126+
String newPath = path + File.pathSeparator
134127
+ System.getenv("PATH");
135-
env.put("PATH", newPath);
128+
env.put("PATH", newPath);
136129
}
137130
}
138131

tests/src/test/java/io/snyk/languageserver/LsRuntimeEnvironmentTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.osgi.framework.Version;
1919

2020
import java.util.HashMap;
21+
import java.util.Optional;
2122

2223
import static org.junit.jupiter.api.Assertions.assertEquals;
2324
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -145,4 +146,14 @@ void testEnableTelemetryIsAddedToEnvironmentDisabled() throws StorageException {
145146
// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for ENABLE, so it's reverted
146147
assertEquals("1", env.get(Preferences.ENABLE_TELEMETRY));
147148
}
149+
@Test
150+
void testAddPath() throws StorageException {
151+
String expected = "C;/myPath/:";
152+
HashMap<String, String> env = new HashMap<>();
153+
when(preferenceMock.getPath()).thenReturn(Optional.of(expected));
154+
155+
environment.addPath(env);
156+
157+
assert(env.get("PATH").startsWith(expected));
158+
}
148159
}

0 commit comments

Comments
 (0)