From d284988e618377457500c8c3464c300ca9e18e9e Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Thu, 7 May 2015 12:04:26 +0200 Subject: [PATCH] Local: Fix Bug 466650 - Avoid org.eclipse.ui.startup extension for local "show-in Git Bash" discovery --- .../plugin.xml | 5 -- .../ExternalExecutablesInitializer.java | 88 ------------------- .../showin/ExternalExecutablesManager.java | 61 +++++++++++++ 3 files changed, 61 insertions(+), 93 deletions(-) delete mode 100644 plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/showin/ExternalExecutablesInitializer.java diff --git a/plugins/org.eclipse.tm.terminal.connector.local/plugin.xml b/plugins/org.eclipse.tm.terminal.connector.local/plugin.xml index c58c478472e..7a8cadfae5a 100644 --- a/plugins/org.eclipse.tm.terminal.connector.local/plugin.xml +++ b/plugins/org.eclipse.tm.terminal.connector.local/plugin.xml @@ -115,11 +115,6 @@ - - - - - > l = ExternalExecutablesManager.load(); - if (l == null) l = new ArrayList>(); - // Find a entry labeled "Git Bash" - Map m = null; - for (Map candidate : l) { - String name = candidate.get(IExternalExecutablesProperties.PROP_NAME); - if ("Git Bash".equals(name)) { //$NON-NLS-1$ - m = candidate; - break; - } - } - - if (m == null) { - m = new HashMap(); - m.put(IExternalExecutablesProperties.PROP_NAME, "Git Bash"); //$NON-NLS-1$ - m.put(IExternalExecutablesProperties.PROP_PATH, gitPath); - m.put(IExternalExecutablesProperties.PROP_ARGS, "--login -i"); //$NON-NLS-1$ - if (iconPath != null) m.put(IExternalExecutablesProperties.PROP_ICON, iconPath); - m.put(IExternalExecutablesProperties.PROP_TRANSLATE, Boolean.TRUE.toString()); - - l.add(m); - ExternalExecutablesManager.save(l); - } - } - } - } -} diff --git a/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/showin/ExternalExecutablesManager.java b/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/showin/ExternalExecutablesManager.java index f9ee18b71f5..a85cff02055 100644 --- a/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/showin/ExternalExecutablesManager.java +++ b/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/showin/ExternalExecutablesManager.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.StringTokenizer; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IPath; @@ -27,11 +28,14 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.ImageLoader; import org.eclipse.tm.terminal.connector.local.activator.UIPlugin; +import org.eclipse.tm.terminal.connector.local.showin.interfaces.IExternalExecutablesProperties; /** * External executables manager implementation. */ public class ExternalExecutablesManager { + // Flag to indicate if we have searched for git bash already + private static boolean gitBashSearchDone = false; /** * Loads the list of all saved external executables. @@ -90,6 +94,63 @@ public class ExternalExecutablesManager { } } + // Lookup git bash (Windows Hosts only) + if (!gitBashSearchDone && Platform.OS_WIN32.equals(Platform.getOS())) { + // Check the existing entries first + // Find a entry labeled "Git Bash" + Map m = null; + for (Map candidate : l) { + String name = candidate.get(IExternalExecutablesProperties.PROP_NAME); + if ("Git Bash".equals(name)) { //$NON-NLS-1$ + m = candidate; + break; + } + } + + // If not found in the existing entries, check the path + if (m == null) { + String gitPath = null; + String iconPath = null; + + String path = System.getenv("PATH"); //$NON-NLS-1$ + if (path != null) { + StringTokenizer tokenizer = new StringTokenizer(path, ";"); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + File f = new File(token, "git.exe"); //$NON-NLS-1$ + if (f.canRead()) { + File f2 = new File(f.getParentFile().getParentFile(), "bin/sh.exe"); //$NON-NLS-1$ + if (f2.canExecute()) { + gitPath = f2.getAbsolutePath(); + } + + f2 = new File(f.getParentFile().getParentFile(), "etc/git.ico"); //$NON-NLS-1$ + if (f2.canRead()) { + iconPath = f2.getAbsolutePath(); + } + + break; + } + } + } + + if (gitPath != null) { + m = new HashMap(); + m.put(IExternalExecutablesProperties.PROP_NAME, "Git Bash"); //$NON-NLS-1$ + m.put(IExternalExecutablesProperties.PROP_PATH, gitPath); + m.put(IExternalExecutablesProperties.PROP_ARGS, "--login -i"); //$NON-NLS-1$ + if (iconPath != null) m.put(IExternalExecutablesProperties.PROP_ICON, iconPath); + m.put(IExternalExecutablesProperties.PROP_TRANSLATE, Boolean.TRUE.toString()); + + l.add(m); + save(l); + } + } + + // Do not search again for git bash while the session is running + gitBashSearchDone = true; + } + return l; }