mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 12:25:35 +02:00
Local: Fix Bug 466650 - Avoid org.eclipse.ui.startup extension for local
"show-in Git Bash" discovery
This commit is contained in:
parent
1b5d872532
commit
d284988e61
3 changed files with 61 additions and 93 deletions
|
@ -115,11 +115,6 @@
|
||||||
</initializer>
|
</initializer>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
<!-- Startup contributions -->
|
|
||||||
<extension point="org.eclipse.ui.startup">
|
|
||||||
<startup class="org.eclipse.tm.terminal.connector.local.showin.ExternalExecutablesInitializer"/>
|
|
||||||
</extension>
|
|
||||||
|
|
||||||
<!-- Help Context contributions -->
|
<!-- Help Context contributions -->
|
||||||
<extension point="org.eclipse.help.contexts">
|
<extension point="org.eclipse.help.contexts">
|
||||||
<contexts
|
<contexts
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014, 2015 Wind River Systems, Inc. and others. All rights reserved.
|
|
||||||
* This program and the accompanying materials are made available under the terms
|
|
||||||
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
|
||||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Wind River Systems - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.tm.terminal.connector.local.showin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.tm.terminal.connector.local.showin.interfaces.IExternalExecutablesProperties;
|
|
||||||
import org.eclipse.ui.IStartup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* External executables data initializer.
|
|
||||||
*/
|
|
||||||
public class ExternalExecutablesInitializer implements IStartup {
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IStartup#earlyStartup()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void earlyStartup() {
|
|
||||||
// On Windows, initialize the "Git Bash" custom "Show In" menu entry
|
|
||||||
if (Platform.OS_WIN32.equals(Platform.getOS())) {
|
|
||||||
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) {
|
|
||||||
// Load the configured external executables
|
|
||||||
List<Map<String, String>> l = ExternalExecutablesManager.load();
|
|
||||||
if (l == null) l = new ArrayList<Map<String, String>>();
|
|
||||||
// Find a entry labeled "Git Bash"
|
|
||||||
Map<String, String> m = null;
|
|
||||||
for (Map<String, String> 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<String, String>();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Assert;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.core.runtime.IPath;
|
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.ImageData;
|
||||||
import org.eclipse.swt.graphics.ImageLoader;
|
import org.eclipse.swt.graphics.ImageLoader;
|
||||||
import org.eclipse.tm.terminal.connector.local.activator.UIPlugin;
|
import org.eclipse.tm.terminal.connector.local.activator.UIPlugin;
|
||||||
|
import org.eclipse.tm.terminal.connector.local.showin.interfaces.IExternalExecutablesProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* External executables manager implementation.
|
* External executables manager implementation.
|
||||||
*/
|
*/
|
||||||
public class ExternalExecutablesManager {
|
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.
|
* 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<String, String> m = null;
|
||||||
|
for (Map<String, String> 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<String, String>();
|
||||||
|
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;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue