Skip to content

Commit d5e09ec

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/local-install-command
2 parents bf7c8b3 + 60e2fcb commit d5e09ec

6 files changed

Lines changed: 403 additions & 71 deletions

File tree

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
required: false
1919
jdeploy_version:
2020
description: The version of Jdeploy
21-
default: '6.0.14'
21+
default: '6.0.19'
2222
jdeploy_registry_url:
2323
description: The URL of the jDeploy application registry
2424
required: false

‎installer/src/main/java/ca/weblite/jdeploy/installer/cli/UnixPathManager.java‎

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ca.weblite.jdeploy.installer.util.DebugLogger;
44
import ca.weblite.tools.io.IOUtil;
5+
import ca.weblite.tools.platform.Platform;
56

67
import java.io.File;
78
import java.io.FileInputStream;
@@ -40,6 +41,21 @@ private UnixPathManager() {
4041
* @return true if PATH was updated or already contained the directory, false otherwise
4142
*/
4243
public static boolean addToPath(File binDir, String shell, String pathEnv, File homeDir) {
44+
return addToPath(binDir, shell, pathEnv, homeDir, Platform.getSystemPlatform());
45+
}
46+
47+
/**
48+
* Adds a directory to the system PATH environment variable.
49+
* This overload allows specifying the platform for testing purposes.
50+
*
51+
* @param binDir directory to add to PATH
52+
* @param shell shell path from environment (e.g., /bin/bash), or null to use default
53+
* @param pathEnv current PATH environment variable
54+
* @param homeDir user's home directory to update config files under
55+
* @param platform the platform to use for determining behavior
56+
* @return true if PATH was updated or already contained the directory, false otherwise
57+
*/
58+
static boolean addToPath(File binDir, String shell, String pathEnv, File homeDir, Platform platform) {
4359
// Log input parameters
4460
DebugLogger.log("UnixPathManager.addToPath() called with:");
4561
DebugLogger.log(" binDir: " + (binDir != null ? binDir.getAbsolutePath() : "null"));
@@ -54,20 +70,45 @@ public static boolean addToPath(File binDir, String shell, String pathEnv, File
5470
return false;
5571
}
5672

57-
// Always write to BOTH bash and zsh configuration files to ensure PATH works
58-
// for both shells regardless of which one the user is using. This is critical
59-
// when running from GUI applications where SHELL env var may not be set.
60-
DebugLogger.log("Writing to both bash and zsh configuration files");
73+
// Write to shell configuration files to ensure PATH works for both bash and zsh.
74+
// Platform-specific behavior:
75+
// - macOS: Write to .bash_profile (Terminal.app uses login shells) and .bashrc
76+
// - Linux: Write to .bashrc only (avoid creating .bash_profile which would break
77+
// Ubuntu's convention where .profile sources .bashrc)
78+
boolean isMac = platform != null && platform.isMac();
79+
DebugLogger.log("Platform detection: isMac=" + isMac);
80+
DebugLogger.log("Writing to shell configuration files");
6181

6282
boolean anyUpdated = false;
6383

64-
// Update bash configuration files (.bash_profile and .bashrc)
65-
File bashProfile = new File(homeDir, ".bash_profile");
84+
// Update bash configuration files
6685
File bashrc = new File(homeDir, ".bashrc");
67-
68-
boolean profileUpdated = addPathToConfigFile(bashProfile, binDir, homeDir);
6986
boolean bashrcUpdated = addPathToConfigFile(bashrc, binDir, homeDir);
70-
anyUpdated = profileUpdated || bashrcUpdated;
87+
anyUpdated = bashrcUpdated;
88+
89+
// On macOS, also update login shell config because Terminal.app starts login shells.
90+
// Bash reads the first file it finds among: .bash_profile, .bash_login, .profile
91+
// We mirror this logic to avoid breaking existing setups:
92+
// - If .bash_profile exists → use it
93+
// - Else if .profile exists → use it (don't create .bash_profile)
94+
// - Else → create .bash_profile
95+
if (isMac) {
96+
File bashProfile = new File(homeDir, ".bash_profile");
97+
File profile = new File(homeDir, ".profile");
98+
99+
File loginShellConfig;
100+
if (bashProfile.exists()) {
101+
loginShellConfig = bashProfile;
102+
} else if (profile.exists()) {
103+
loginShellConfig = profile;
104+
DebugLogger.log("Using existing .profile instead of creating .bash_profile");
105+
} else {
106+
loginShellConfig = bashProfile;
107+
}
108+
109+
boolean profileUpdated = addPathToConfigFile(loginShellConfig, binDir, homeDir);
110+
anyUpdated = anyUpdated || profileUpdated;
111+
}
71112

72113
// Update zsh configuration file (.zshrc)
73114
File zshrc = new File(homeDir, ".zshrc");
@@ -192,7 +233,6 @@ private static String computeDisplayPath(File binDir, File homeDir) {
192233
}
193234
return binPath;
194235
}
195-
196236
/**
197237
* Checks if the given config file contains the no-auto-path marker.
198238
* If present, automatic PATH modification should be skipped for this file.

‎installer/src/test/java/ca/weblite/jdeploy/installer/MainAddToPathTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public void testAlreadyInPath() throws Exception {
3838
assertTrue(ok);
3939

4040
// Verify that bash config files were still created despite being in PATH
41+
// At minimum, .bashrc should always be created
4142
assertTrue(new File(home, ".bashrc").exists());
42-
assertTrue(new File(home, ".bash_profile").exists());
43+
// Note: .bash_profile creation is platform-dependent (created on macOS, not on Linux)
4344
}
4445

4546
@Test

‎installer/src/test/java/ca/weblite/jdeploy/installer/cli/LinuxCliCommandInstallerTest.java‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,15 @@ public void testAddToPathBash() {
366366
String pathEnv = "/usr/bin:/bin";
367367
File bashrc = new File(homeDir, ".bashrc");
368368

369-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
369+
// Use explicit Linux platform to test Linux-specific behavior
370+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
371+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
370372

371373
assertTrue(result);
372374
assertTrue(bashrc.exists(), "bashrc was not created");
375+
// On Linux, .bash_profile should NOT be created
376+
File bashProfile = new File(homeDir, ".bash_profile");
377+
assertFalse(bashProfile.exists(), "bash_profile should NOT be created on Linux");
373378
}
374379

375380
@Test
@@ -378,19 +383,25 @@ public void testAddToPathZsh() {
378383
String pathEnv = "/usr/bin:/bin";
379384
File zshrc = new File(homeDir, ".zshrc");
380385

381-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
386+
// Use explicit Linux platform to test Linux-specific behavior
387+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
388+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
382389

383390
assertTrue(result);
384391
assertTrue(zshrc.exists());
392+
// On Linux, .bash_profile should NOT be created
393+
File bashProfile = new File(homeDir, ".bash_profile");
394+
assertFalse(bashProfile.exists(), "bash_profile should NOT be created on Linux");
385395
}
386396

387397
@Test
388398
public void testAddToPathAlreadyInPath() {
389399
String shell = "/bin/bash";
390400
String pathEnv = "/usr/bin:" + binDir.getAbsolutePath() + ":/bin";
391-
File bashrc = new File(homeDir, ".bashrc");
392401

393-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
402+
// Use explicit Linux platform to test Linux-specific behavior
403+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
404+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
394405

395406
assertTrue(result);
396407
}
@@ -405,7 +416,9 @@ public void testAddToPathAlreadyInConfig() throws IOException {
405416
// Pre-populate bashrc with the path
406417
Files.write(bashrc.toPath(), ("export PATH=\"$HOME/.local/bin:$PATH\"\n").getBytes(StandardCharsets.UTF_8));
407418

408-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
419+
// Use explicit Linux platform to test Linux-specific behavior
420+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
421+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
409422

410423
assertTrue(result);
411424
}
@@ -415,14 +428,16 @@ public void testAddToPathFish() {
415428
String shell = "/usr/bin/fish";
416429
String pathEnv = "/usr/bin:/bin";
417430

418-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
431+
// Use explicit Linux platform to test Linux-specific behavior
432+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
433+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
419434

420435
assertTrue(result);
421-
// Now we write to both bash and zsh config files regardless of shell
436+
// On Linux, we write to bashrc and zshrc but NOT bash_profile
422437
File bashrc = new File(homeDir, ".bashrc");
423438
assertTrue(bashrc.exists(), "bashrc should be created");
424439
File bashProfile = new File(homeDir, ".bash_profile");
425-
assertTrue(bashProfile.exists(), "bash_profile should be created");
440+
assertFalse(bashProfile.exists(), "bash_profile should NOT be created on Linux");
426441
File zshrc = new File(homeDir, ".zshrc");
427442
assertTrue(zshrc.exists(), "zshrc should be created");
428443
}
@@ -432,14 +447,16 @@ public void testAddToPathUnknownShell() {
432447
String shell = "/bin/unknown";
433448
String pathEnv = "/usr/bin:/bin";
434449

435-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
450+
// Use explicit Linux platform to test Linux-specific behavior
451+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
452+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
436453

437454
assertTrue(result);
438-
// Now we write to both bash and zsh config files regardless of shell
455+
// On Linux, we write to bashrc and zshrc but NOT bash_profile
439456
File bashrc = new File(homeDir, ".bashrc");
440457
assertTrue(bashrc.exists(), "bashrc should be created");
441458
File bashProfile = new File(homeDir, ".bash_profile");
442-
assertTrue(bashProfile.exists(), "bash_profile should be created");
459+
assertFalse(bashProfile.exists(), "bash_profile should NOT be created on Linux");
443460
File zshrc = new File(homeDir, ".zshrc");
444461
assertTrue(zshrc.exists(), "zshrc should be created");
445462
}
@@ -450,9 +467,15 @@ public void testAddToPathNullShell() {
450467
String pathEnv = "/usr/bin:/bin";
451468
File bashrc = new File(homeDir, ".bashrc");
452469

453-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
470+
// Use explicit Linux platform to test Linux-specific behavior
471+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
472+
new ca.weblite.tools.platform.Platform("Linux", "amd64"));
454473

455474
assertTrue(result);
475+
assertTrue(bashrc.exists(), "bashrc should be created");
476+
// On Linux, .bash_profile should NOT be created
477+
File bashProfile = new File(homeDir, ".bash_profile");
478+
assertFalse(bashProfile.exists(), "bash_profile should NOT be created on Linux");
456479
}
457480

458481
@Test

‎installer/src/test/java/ca/weblite/jdeploy/installer/cli/MacCliCommandInstallerTest.java‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,15 @@ public void testAddToPathBash() {
230230
String pathEnv = "/usr/bin:/bin";
231231
File bashrc = new File(homeDir, ".bashrc");
232232

233-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
233+
// Use explicit macOS platform to test macOS-specific behavior
234+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
235+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
234236

235237
assertTrue(result);
236238
assertTrue(bashrc.exists(), "bashrc was not created");
239+
// On macOS, .bash_profile should also be created
240+
File bashProfile = new File(homeDir, ".bash_profile");
241+
assertTrue(bashProfile.exists(), "bash_profile should be created on macOS");
237242
}
238243

239244
@Test
@@ -242,19 +247,25 @@ public void testAddToPathZsh() {
242247
String pathEnv = "/usr/bin:/bin";
243248
File zshrc = new File(homeDir, ".zshrc");
244249

245-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
250+
// Use explicit macOS platform to test macOS-specific behavior
251+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
252+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
246253

247254
assertTrue(result);
248255
assertTrue(zshrc.exists());
256+
// On macOS, .bash_profile should also be created
257+
File bashProfile = new File(homeDir, ".bash_profile");
258+
assertTrue(bashProfile.exists(), "bash_profile should be created on macOS");
249259
}
250260

251261
@Test
252262
public void testAddToPathAlreadyInPath() {
253263
String shell = "/bin/bash";
254264
String pathEnv = "/usr/bin:" + binDir.getAbsolutePath() + ":/bin";
255-
File bashrc = new File(homeDir, ".bashrc");
256265

257-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
266+
// Use explicit macOS platform to test macOS-specific behavior
267+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
268+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
258269

259270
assertTrue(result);
260271
}
@@ -269,7 +280,9 @@ public void testAddToPathAlreadyInConfig() throws IOException {
269280
// Pre-populate bashrc with the path
270281
Files.write(bashrc.toPath(), ("export PATH=\"$HOME/.local/bin:$PATH\"\n").getBytes(StandardCharsets.UTF_8));
271282

272-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
283+
// Use explicit macOS platform to test macOS-specific behavior
284+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
285+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
273286

274287
assertTrue(result);
275288
}
@@ -279,14 +292,16 @@ public void testAddToPathFish() {
279292
String shell = "/usr/bin/fish";
280293
String pathEnv = "/usr/bin:/bin";
281294

282-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
295+
// Use explicit macOS platform to test macOS-specific behavior
296+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
297+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
283298

284299
assertTrue(result);
285-
// Now we write to both bash and zsh config files regardless of shell
300+
// On macOS, we write to bashrc, bash_profile, and zshrc
286301
File bashrc = new File(homeDir, ".bashrc");
287302
assertTrue(bashrc.exists(), "bashrc should be created");
288303
File bashProfile = new File(homeDir, ".bash_profile");
289-
assertTrue(bashProfile.exists(), "bash_profile should be created");
304+
assertTrue(bashProfile.exists(), "bash_profile should be created on macOS");
290305
File zshrc = new File(homeDir, ".zshrc");
291306
assertTrue(zshrc.exists(), "zshrc should be created");
292307
}
@@ -296,14 +311,16 @@ public void testAddToPathUnknownShell() {
296311
String shell = "/bin/unknown";
297312
String pathEnv = "/usr/bin:/bin";
298313

299-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
314+
// Use explicit macOS platform to test macOS-specific behavior
315+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
316+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
300317

301318
assertTrue(result);
302-
// Now we write to both bash and zsh config files regardless of shell
319+
// On macOS, we write to bashrc, bash_profile, and zshrc
303320
File bashrc = new File(homeDir, ".bashrc");
304321
assertTrue(bashrc.exists(), "bashrc should be created");
305322
File bashProfile = new File(homeDir, ".bash_profile");
306-
assertTrue(bashProfile.exists(), "bash_profile should be created");
323+
assertTrue(bashProfile.exists(), "bash_profile should be created on macOS");
307324
File zshrc = new File(homeDir, ".zshrc");
308325
assertTrue(zshrc.exists(), "zshrc should be created");
309326
}
@@ -314,9 +331,15 @@ public void testAddToPathNullShell() {
314331
String pathEnv = "/usr/bin:/bin";
315332
File bashrc = new File(homeDir, ".bashrc");
316333

317-
boolean result = AbstractUnixCliCommandInstaller.addToPath(binDir, shell, pathEnv, homeDir);
334+
// Use explicit macOS platform to test macOS-specific behavior
335+
boolean result = UnixPathManager.addToPath(binDir, shell, pathEnv, homeDir,
336+
new ca.weblite.tools.platform.Platform("Mac OS X", "x86_64"));
318337

319338
assertTrue(result);
339+
assertTrue(bashrc.exists(), "bashrc should be created");
340+
// On macOS, .bash_profile should also be created
341+
File bashProfile = new File(homeDir, ".bash_profile");
342+
assertTrue(bashProfile.exists(), "bash_profile should be created on macOS");
320343
}
321344

322345
@Test

0 commit comments

Comments
 (0)