Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Krasilnikov2008-02-15 08:11:22 -0500
committerOleg Krasilnikov2008-02-15 08:11:22 -0500
commit0c363ef3e880853e8881a3172e51bb934808be7c (patch)
treeec20683b115ec310684e5b7015c4e4de40e4bbb5
parent864125184f9578cc8f209037449206f18e59cbdc (diff)
downloadorg.eclipse.cdt-0c363ef3e880853e8881a3172e51bb934808be7c.tar.gz
org.eclipse.cdt-0c363ef3e880853e8881a3172e51bb934808be7c.tar.xz
org.eclipse.cdt-0c363ef3e880853e8881a3172e51bb934808be7c.zip
Bug #218954 : New CDT Project Wizard causes Vista UAC warning
-rw-r--r--build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java182
-rw-r--r--build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuUIPlugin.java13
2 files changed, 95 insertions, 100 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
index 38da5a4d87..deced41a01 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 Intel Corporation and others.
+ * Copyright (c) 2005, 2008 Intel Corporation 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
@@ -12,52 +12,45 @@ package org.eclipse.cdt.managedbuilder.gnu.cygwin;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
-import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin;
+import org.eclipse.cdt.utils.WindowsRegistry;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
-import org.eclipse.core.runtime.IPath;
public class CygwinPathResolver implements IBuildPathResolver {
- static final String TOOL = "/cygpath -w -p "; //$NON-NLS-1$
- static final char BS = '\\'; //$NON-NLS-1$
- static final char SLASH = '/'; //$NON-NLS-1$
- static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$
- static final String PROPERTY_OS_VALUE = "windows";//$NON-NLS-1$
- static final String ARG0 = "regedit"; //$NON-NLS-1$
- static final String ARG1 = "/ea"; //$NON-NLS-1$
- static final String OUTFILE = "result.txt"; //$NON-NLS-1$
- static final String SP = " "; //$NON-NLS-1$
- static final String QUOT = "\""; //$NON-NLS-1$
- static final String REGISTRY_KEY = "\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2"; //$NON-NLS-1$
- static final String[] REGISTRY_ROOTS = {"\"HKEY_CURRENT_USER", "\"HKEY_LOCAL_MACHINE"}; //$NON-NLS-1$ //$NON-NLS-2$
- static final String REGISTRY_BINS = "/usr/bin"; //$NON-NLS-1$
- static final String CYGPREF_NAME = "cygdrive prefix"; //$NON-NLS-1$
- static final String PATH_NAME = "native"; //$NON-NLS-1$
- static final String REG_SZ = "REG_SZ"; //$NON-NLS-1$
- static final String BINPATTERN = "/usr/bin"; //$NON-NLS-1$
- static final String ETCPATTERN = "/etc"; //$NON-NLS-1$
- static final String ROOTPATTERN = "/"; //$NON-NLS-1$
- static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
- static final String DELIMITER_WIN = ";"; //$NON-NLS-1$
- static final String GCC_VERSION_CMD = "gcc --version"; //$NON-NLS-1$
- static final String MINGW_SPECIAL = "mingw "; //$NON-NLS-1$
- static final String CYGWIN_SPECIAL = "cygwin "; //$NON-NLS-1$
+ private static final String TOOL = "/cygpath -w -p "; //$NON-NLS-1$
+ private static final char BS = '\\'; //$NON-NLS-1$
+ private static final char SLASH = '/'; //$NON-NLS-1$
+ private static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$
+ private static final String PROPERTY_OS_VALUE = "windows";//$NON-NLS-1$
+ private static final String SP = " "; //$NON-NLS-1$
+ private static final String REGISTRY_KEY = "SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\"; //$NON-NLS-1$
+ private static final String PATH_NAME = "native"; //$NON-NLS-1$
+ private static final String EMPTY = ""; //$NON-NLS-1$
+ private static final String SSLASH = "/"; //$NON-NLS-1$
+ private static final String BSLASH = "\\\\"; //$NON-NLS-1$
+ private static final String BINPATTERN = "/usr/bin"; //$NON-NLS-1$
+ private static final String ETCPATTERN = "/etc"; //$NON-NLS-1$
+ private static final String ROOTPATTERN = SSLASH;
+ private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
+ private static final String DELIMITER_WIN = ";"; //$NON-NLS-1$
+ private static final String GCC_VERSION_CMD = "gcc --version"; //$NON-NLS-1$
+ private static final String MINGW_SPECIAL = "mingw "; //$NON-NLS-1$
+ private static final String CYGWIN_SPECIAL = "cygwin "; //$NON-NLS-1$
- static boolean checked = false;
- static String binCygwin = null;
- static String rootCygwin = null;
- static String etcCygwin = null;
+ private static boolean checked = false;
+ private static String binCygwin = null;
+ private static String rootCygwin = null;
+ private static String etcCygwin = null;
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IBuildPathResolver#resolveBuildPaths(int, java.lang.String, java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration)
@@ -73,10 +66,13 @@ public class CygwinPathResolver implements IBuildPathResolver {
String[] result = variableValue.split(DELIMITER_UNIX);
String exePath = getBinPath();
- if (exePath == null) { return result; } // no changes
+ if (exePath == null) {
+ return result; // no changes
+ }
File file = new File(exePath);
- if (!file.exists() || !file.isDirectory()) { return result; } // no changes
-
+ if (!file.exists() || !file.isDirectory()) {
+ return result; // no changes
+ }
String s = exePath + TOOL + variableValue;
String[] lines = exec(s, configuration);
if (lines != null && lines.length > 0) {
@@ -115,68 +111,36 @@ public class CygwinPathResolver implements IBuildPathResolver {
}
/**
- * reads once data from registry (for Win32 only)
- * and sets corresponding properties;
- */
-
- private static synchronized void checkRegistry() {
- if (checked) return;
- try {
- etcCygwin = null;
- binCygwin = null;
- rootCygwin = null;
- if (!isWindows()) return;
- for(int i = 0; i < REGISTRY_ROOTS.length; i++){
- IPath toSave = GnuUIPlugin.getDefault().getStateLocation();
- toSave = toSave.addTrailingSeparator().append(OUTFILE);
- String[] args = {ARG0, ARG1, toSave.toOSString(), REGISTRY_ROOTS[i]+REGISTRY_KEY+QUOT };
- try {
- File f = new File(toSave.toOSString());
- f.delete();
- if (ProcessFactory.getFactory().exec(args).waitFor() == 0 && f.exists() && f.canRead()) {
- BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
- ArrayList ls = new ArrayList(1);
- String s;
- while ((s = r.readLine() ) != null ) ls.add(s);
- r.close();
- f.delete();
- String[] aus = (String[])ls.toArray(new String[0]);
- if (etcCygwin == null) { etcCygwin = getDir(aus, ETCPATTERN); }
- if (binCygwin == null) { binCygwin = getDir(aus, BINPATTERN); }
- if (rootCygwin == null) { rootCygwin = getDir(aus, ROOTPATTERN);}
- }
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- } catch (InterruptedException e) {
- } catch (SecurityException e) {
- }
- }
- } finally {
- checked = true;
- }
- }
-
- /**
- * @param ls - "regedit"'s output
- * @param pattern - path to search
+ * Reads required value from registry.
+ *
+ * If there's no such key, tries to read "parent" key
+ * and forms resulting path from parent path and
+ * key suffix.
+ *
+ * For example, if there's no key for "/etc",
+ * reads key for "/" (has value "c:/cygwin")
+ * and forms result "c:/cygwin/etc".
+ *
+ * @param user
+ * if true, reads from HKEY_CURRENT_USER
+ * if false, reads from HKEY_LOCAL_MACHINE
+ * @param pattern
+ * specific registry key value (last segment)
* @return
+ * corresponding string value
+ * or null if nothing found
*/
- private static String getDir(String[] ls, String pattern) {
- String tail = ""; //$NON-NLS-1$
+ private static String read(boolean user, String pattern) {
+ String tail = EMPTY;
while (pattern.length() > 0) {
- boolean search = false;
- for (int i=0; i<ls.length; i++) {
- int pos=0;
- if (ls[i].lastIndexOf(REGISTRY_KEY) > 0) {
- search = ls[i].endsWith(pattern+"]"); //$NON-NLS-1$
- }
- else if (search && ((pos = ls[i].lastIndexOf(PATH_NAME)) > 0)) {
- String s = ls[i].substring(pos + PATH_NAME.length() + 3).trim();
- s = s.substring(0, s.length() - 1) + tail;
- return s.replaceAll("\\\\+", "/"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- if (pattern.equals(ROOTPATTERN)) break; // no other paths to search
+ String key = REGISTRY_KEY + pattern;
+ String s = user ?
+ WindowsRegistry.getRegistry().getCurrentUserValue(key, PATH_NAME) :
+ WindowsRegistry.getRegistry().getLocalMachineValue(key, PATH_NAME);
+ if (s != null)
+ return (s.concat(tail).replaceAll(BSLASH, SSLASH));
+ if (pattern.equals(ROOTPATTERN))
+ break; // no other paths to search
int pos = pattern.lastIndexOf(SLASH);
if (pos < 0) break;
tail = pattern.substring(pos, pattern.length()) + tail;
@@ -185,13 +149,33 @@ public class CygwinPathResolver implements IBuildPathResolver {
else
pattern = pattern.substring(0, pos);
}
- return null;
+ return null;
+ }
+
+ /**
+ * reads once data from registry (for Win32 only)
+ * and sets corresponding properties;
+ */
+ private static synchronized void checkRegistry() {
+ if (checked) return;
+ etcCygwin = null;
+ binCygwin = null;
+ rootCygwin = null;
+ if (!isWindows()) return;
+ for (int i=0; i<2; i++) {
+ if (etcCygwin == null)
+ etcCygwin = read((i==0), ETCPATTERN);
+ if (binCygwin == null)
+ binCygwin = read((i==0), BINPATTERN);
+ if (rootCygwin == null)
+ rootCygwin = read((i==0), ROOTPATTERN);
+ }
+ checked = true;
}
private static String[] exec(String cmd, IConfiguration cfg) {
try {
-// Process proc = Runtime.getRuntime().exec(cmd);
- IBuildEnvironmentVariable vars[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true,true);
+ IEnvironmentVariable vars[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true);
String env[] = new String[vars.length];
for(int i = 0; i < env.length; i++){
env[i] = vars[i].getName() + "=";
@@ -213,7 +197,7 @@ public class CygwinPathResolver implements IBuildPathResolver {
return (String[])ls.toArray(new String[0]);
}
} catch (IOException e) {
- //TODO: log
+ GnuUIPlugin.getDefault().log(e);
}
return null;
}
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuUIPlugin.java b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuUIPlugin.java
index 545d4a1d4f..013e1713a4 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuUIPlugin.java
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/ui/GnuUIPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 Texas Instruments Inc. and others.
+ * Copyright (c) 2005, 2008 Texas Instruments 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
@@ -11,7 +11,9 @@
package org.eclipse.cdt.managedbuilder.gnu.ui;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
import java.util.*;
@@ -19,6 +21,8 @@ import java.util.*;
* The main plugin class to be used in the desktop.
*/
public class GnuUIPlugin extends Plugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.cdt.managedbuilder.gnu.ui"; //$NON-NLS-1$
//The shared instance.
private static GnuUIPlugin plugin;
//Resource bundle.
@@ -81,4 +85,11 @@ public class GnuUIPlugin extends Plugin {
return resourceBundle;
}
+ public void log(Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$
+ }
+
+ public void log(IStatus status) {
+ getLog().log(status);
+ }
}

Back to the top