Skip to content

Commit b4e4b7a

Browse files
eharris369GitHub Enterprise
authored andcommitted
Merge pull request #221 from eharris/209-useFullPathForDockerOnMAC
Issue #209: Use full path for running docker commands on MAC
2 parents 1e4273d + 5f51e78 commit b4e4b7a

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MCUtil.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* General utils that don't belong anywhere else
2828
*/
2929
public class MCUtil {
30+
31+
// Provide a way for users to override the path used for running commands
32+
private static final String ENV_PATH_PROPERTY = "com.ibm.microclimate.envPath";
3033

3134
/**
3235
* Open a dialog on top of the current active window. Can be called off the UI thread.
@@ -161,5 +164,33 @@ public static void updateApplication(MicroclimateApplication app) {
161164
}
162165
}
163166

164-
167+
public static String getOSName() {
168+
return (String)System.getProperty("os.name");
169+
}
170+
171+
public static boolean isMACOS() {
172+
String osName = getOSName();
173+
if (osName != null && osName.toLowerCase().contains("mac")) {
174+
return true;
175+
}
176+
return false;
177+
}
178+
179+
public static String getEnvPath() {
180+
String path = (String)System.getProperty(ENV_PATH_PROPERTY);
181+
if (path == null || path.trim().isEmpty()) {
182+
if (isMACOS()) {
183+
// On MAC a full path is required for running commands
184+
return "/usr/local/bin/";
185+
}
186+
return null;
187+
}
188+
path = path.trim();
189+
path = path.replaceAll("\\", "/");
190+
if (!path.endsWith("/")) {
191+
path = path + "/";
192+
}
193+
return path;
194+
}
195+
165196
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/ContainerShellAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.ui.IWorkbenchPart;
2323

2424
import com.ibm.microclimate.core.internal.MCLogger;
25+
import com.ibm.microclimate.core.internal.MCUtil;
2526
import com.ibm.microclimate.core.internal.MicroclimateApplication;
2627
import com.ibm.microclimate.core.internal.constants.ProjectType;
2728

@@ -31,7 +32,7 @@
3132
public class ContainerShellAction implements IObjectActionDelegate {
3233

3334
private static final String LAUNCHER_DELEGATE_ID = "org.eclipse.tm.terminal.connector.local.launcher.local"; //$NON-NLS-1$
34-
35+
3536
protected MicroclimateApplication app;
3637
protected ILauncherDelegate delegate;
3738

@@ -87,10 +88,12 @@ public void run(IAction action) {
8788
}
8889

8990
// Open a shell in the application container
91+
String envPath = MCUtil.getEnvPath();
92+
String dockerPath = envPath != null ? envPath + "docker" : "docker";
9093
Map<String, Object> properties = new HashMap<>();
9194
properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId());
9295
properties.put(ITerminalsConnectorConstants.PROP_TITLE, app.name);
93-
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, "docker");
96+
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, dockerPath);
9497
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, "exec -it " + app.getContainerId() + " " + command);
9598
delegate.execute(properties, null);
9699
}

0 commit comments

Comments
 (0)