# HG changeset patch # User jrice@netbeans.org # Date 1206552683 0 # Node ID 51f01e967a067bf1e725992b73481256cd947f1d # Parent 26cd68076a26cbb0850fa680394b4e8294744df6 #126803: Username setting on Windows - part2 fixes Options and Properties to behave consistently diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/HgModuleConfig.java --- a/mercurial/src/org/netbeans/modules/mercurial/HgModuleConfig.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/HgModuleConfig.java Wed Mar 26 17:31:23 2008 +0000 @@ -54,6 +54,7 @@ import org.openide.util.NbPreferences; import org.openide.util.NbPreferences; import org.netbeans.modules.versioning.util.TableSorter; import org.netbeans.modules.versioning.util.Utils; +import org.openide.util.Utilities; /** * Stores Mercurial module configuration. @@ -158,6 +159,11 @@ public class HgModuleConfig { } public void setExecutableBinaryPath(String path) { + if(Utilities.isWindows() && path.endsWith(HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE)){ + path = path.substring(0, path.length() - (HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE).length()); + }else if(path.endsWith(HgCommand.HG_COMMAND)){ + path = path.substring(0, path.length() - HgCommand.HG_COMMAND.length()); + } getPreferences().put(KEY_EXECUTABLE_BINARY, path); } @@ -202,7 +208,7 @@ public class HgModuleConfig { } catch (Exception ex) { return userName; } - userName = userId + " <" + userId + "@" + hostName + ">"; // NOI18N + userName = userId + "@" + hostName + ".zzz"; // NOI18N } return userName; } diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/Mercurial.java --- a/mercurial/src/org/netbeans/modules/mercurial/Mercurial.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/Mercurial.java Wed Mar 26 17:31:23 2008 +0000 @@ -59,6 +59,7 @@ import java.util.prefs.Preferences; import java.util.prefs.Preferences; import org.openide.NotifyDescriptor; import org.openide.DialogDisplayer; +import org.openide.util.Utilities; /** * Main entry point for Mercurial functionality, use getInstance() to get the Mercurial object. @@ -142,6 +143,14 @@ public class Mercurial { break; } } + } + }else if (Utilities.isWindows()) { // NOI18N + String defaultPath = HgModuleConfig.getDefault().getExecutableBinaryPath (); + if (defaultPath == null || defaultPath.length() == 0) { + String path = HgUtils.findInUserPath(HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE); + if (path != null && !path.equals("")) { // NOI18N + HgModuleConfig.getDefault().setExecutableBinaryPath (path); // NOI18N + } } } } diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java --- a/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Wed Mar 26 17:31:23 2008 +0000 @@ -54,6 +54,7 @@ import org.ini4j.Ini; import org.ini4j.Ini; import org.netbeans.modules.mercurial.HgModuleConfig; import org.netbeans.modules.mercurial.Mercurial; +import org.netbeans.modules.mercurial.util.HgUtils; import org.openide.filesystems.FileUtil; import org.openide.util.Utilities; @@ -89,16 +90,17 @@ public class HgConfigFiles { private static final String WINDOWS_HG_RC_FILE = "Mercurial.ini"; // NOI18N private static final String WINDOWS_DEFAULT_MECURIAL_INI_PATH = "C:\\Mercurial\\Mercurial.ini"; // NOI18N - + private boolean bIsProjectConfig; /** * Creates a new instance */ - private HgConfigFiles() { + private HgConfigFiles() { + bIsProjectConfig = false; // get the system hgrc file if(Utilities.isWindows()) { - hgrc = loadFile(WINDOWS_HG_RC_FILE); + hgrc = loadSystemAndGlobalFile(WINDOWS_HG_RC_FILE); }else{ - hgrc = loadFile(HG_RC_FILE); + hgrc = loadSystemAndGlobalFile(HG_RC_FILE); } } @@ -115,9 +117,10 @@ public class HgConfigFiles { } public HgConfigFiles(File file) { + bIsProjectConfig = true; dir = file; // /.hg/hgrc on all platforms - hgrc = loadFile(file); + hgrc = loadRepoHgrcFile(file); } public void setProperty(String name, String value) { @@ -153,7 +156,11 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, true); inisection.put(name, value); } - storeIni(hgrc, HG_RC_FILE); + if (!bIsProjectConfig && Utilities.isWindows()) { + storeIni(hgrc, WINDOWS_HG_RC_FILE); + } else { + storeIni(hgrc, HG_RC_FILE); + } } public void setProperty(String section, String name, String value) { @@ -184,7 +191,11 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, false); if (inisection != null) { inisection.clear(); - storeIni(hgrc, HG_RC_FILE); + if (!bIsProjectConfig && Utilities.isWindows()) { + storeIni(hgrc, WINDOWS_HG_RC_FILE); + } else { + storeIni(hgrc, HG_RC_FILE); + } } } @@ -192,7 +203,11 @@ public class HgConfigFiles { Ini.Section inisection = getSection(hgrc, section, false); if (inisection != null) { inisection.remove(name); - storeIni(hgrc, HG_RC_FILE); + if (!bIsProjectConfig && Utilities.isWindows()) { + storeIni(hgrc, WINDOWS_HG_RC_FILE); + } else { + storeIni(hgrc, HG_RC_FILE); + } } } @@ -234,9 +249,13 @@ public class HgConfigFiles { private void doReload () { if (dir == null) { - hgrc = loadFile(HG_RC_FILE); + if(!bIsProjectConfig && Utilities.isWindows()) { + hgrc = loadSystemAndGlobalFile(WINDOWS_HG_RC_FILE); + }else{ + hgrc = loadSystemAndGlobalFile(HG_RC_FILE); + } } else { - hgrc = loadFile(dir); + hgrc = loadRepoHgrcFile(dir); } } @@ -267,7 +286,7 @@ public class HgConfigFiles { /** * Loads Repository configuration file /.hg/hgrc on all platforms * */ - private Ini loadFile(File dir) { + private Ini loadRepoHgrcFile(File dir) { String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + HG_RC_FILE; // NOI18N File file = FileUtil.normalizeFile(new File(filePath)); Ini system = null; @@ -296,13 +315,18 @@ public class HgConfigFiles { * @param fileName the file name * @return an Ini instance holding the configuration file. */ - private Ini loadFile(String fileName) { + private Ini loadSystemAndGlobalFile(String fileName) { // config files from userdir String filePath = getUserConfigPath() + fileName; File file = FileUtil.normalizeFile(new File(filePath)); + File tmpFile = HgUtils.fixPathsInIniFileOnWindows(file); + if (tmpFile != null && tmpFile.isFile() && tmpFile.canWrite() && file != null) { + file.delete(); + tmpFile.renameTo(file); + } Ini system = null; try { - system = new Ini(new FileReader(file)); + system = tmpFile != null? new Ini(new FileReader(tmpFile)): null; } catch (FileNotFoundException ex) { // ignore } catch (IOException ex) { @@ -316,7 +340,10 @@ public class HgConfigFiles { Ini global = null; try { - global = new Ini(new FileReader(getGlobalConfigPath() + File.separator + fileName)); // NOI18N + File gFile = FileUtil.normalizeFile(new File(getGlobalConfigPath() + File.separator + fileName)); + File tmp2File = HgUtils.fixPathsInIniFileOnWindows(gFile); + tmp2File.deleteOnExit(); + global = new Ini(new FileReader(tmp2File)); // NOI18N } catch (FileNotFoundException ex) { // just doesn't exist - ignore } catch (IOException ex) { @@ -379,9 +406,8 @@ public class HgConfigFiles { } else if (Utilities.isWindows()){ // \Mercurial.ini String mercurialPath = HgModuleConfig.getDefault().getExecutableBinaryPath (); - if(mercurialPath != null){ - File f = new File(mercurialPath); - File ini = new File(f.getParentFile(), WINDOWS_HG_RC_FILE); + if(mercurialPath != null && !mercurialPath.equals("")){ + File ini = new File(mercurialPath, WINDOWS_HG_RC_FILE); if(ini != null && ini.exists() && ini.canRead()){ return ini.getParentFile().getAbsolutePath(); } @@ -396,10 +422,11 @@ public class HgConfigFiles { } private static String getUSERPROFILE() { + if(!Utilities.isWindows()) return null; + String userprofile = ""; // NOI18N - if(Utilities.isWindows()) { - userprofile = System.getenv("USERPROFILE");// NOI18N - } + userprofile = System.getenv("USERPROFILE");// NOI18N + return userprofile!= null? userprofile: ""; // NOI18N } diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/options/Bundle.properties --- a/mercurial/src/org/netbeans/modules/mercurial/options/Bundle.properties Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/options/Bundle.properties Wed Mar 26 17:31:23 2008 +0000 @@ -90,7 +90,7 @@ LBL_Properties_Progress=Scanning Mercuri MSG_WARN_FIELD_TITLE = Invalid Field MSG_WARN_USER_NAME_TEXT = The text specified in the Mercurial User Name is not a valid email address. -MSG_WARN_EXEC_PATH_TEXT = The directory specified in the Mercurial Executable path does not contain mercurial program. +MSG_WARN_EXEC_PATH_TEXT = The specified Mercurial Executable Path does not contain the Mercurial program. MercurialPanel.ExportFilename.text=&Default Export Filename\: diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/options/MercurialOptionsPanelController.java --- a/mercurial/src/org/netbeans/modules/mercurial/options/MercurialOptionsPanelController.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/options/MercurialOptionsPanelController.java Wed Mar 26 17:31:23 2008 +0000 @@ -63,6 +63,7 @@ import org.netbeans.modules.mercurial.op import org.netbeans.modules.mercurial.options.PropertiesPanel; import org.netbeans.modules.mercurial.options.PropertiesTable; import org.netbeans.modules.mercurial.options.PropertiesTableModel; +import org.netbeans.modules.mercurial.util.HgCommand; import org.netbeans.spi.options.OptionsPanelController; import org.netbeans.modules.versioning.util.AccessibleJFileChooser; import org.openide.DialogDescriptor; @@ -71,6 +72,7 @@ import org.openide.util.HelpCtx; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.Utilities; final class MercurialOptionsPanelController extends OptionsPanelController implements ActionListener { @@ -167,6 +169,11 @@ final class MercurialOptionsPanelControl return false; } String execpath = panel.executablePathTextField.getText(); + if(Utilities.isWindows() && execpath.endsWith(HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE)){ + execpath = execpath.substring(0, execpath.length() - (HgCommand.HG_COMMAND + HgCommand.HG_WINDOWS_EXE).length()); + }else if(execpath.endsWith(HgCommand.HG_COMMAND)){ + execpath = execpath.substring(0, execpath.length() - HgCommand.HG_COMMAND.length()); + } if (!HgModuleConfig.getDefault().isExecPathValid(execpath)) { JOptionPane.showMessageDialog(null, NbBundle.getMessage(MercurialPanel.class, "MSG_WARN_EXEC_PATH_TEXT"), // NOI18N diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/options/MercurialPanel.java --- a/mercurial/src/org/netbeans/modules/mercurial/options/MercurialPanel.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/options/MercurialPanel.java Wed Mar 26 17:31:23 2008 +0000 @@ -52,6 +52,7 @@ final class MercurialPanel extends javax private final MercurialOptionsPanelController controller; private final DocumentListener listener; + private String initialUserName; MercurialPanel(MercurialOptionsPanelController controller) { this.controller = controller; @@ -248,7 +249,8 @@ final class MercurialPanel extends javax // someCheckBox.setSelected(NbPreferences.forModule(MercurialPanel.class).getBoolean("someFlag", false)); // NOI18N // or: // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty()); - userNameTextField.setText(HgModuleConfig.getDefault().getUserName()); + initialUserName = HgModuleConfig.getDefault().getUserName(); + userNameTextField.setText(initialUserName); executablePathTextField.setText(HgModuleConfig.getDefault().getExecutableBinaryPath()); exportFilenameTextField.setText(HgModuleConfig.getDefault().getExportFilename()); annotationTextField.setText(HgModuleConfig.getDefault().getAnnotationFormat()); @@ -263,7 +265,8 @@ final class MercurialPanel extends javax // NbPreferences.forModule(MercurialPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N // or: // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText()); - HgModuleConfig.getDefault().setUserName(userNameTextField.getText()); + if(!initialUserName.equals(userNameTextField.getText())) + HgModuleConfig.getDefault().setUserName(userNameTextField.getText()); HgModuleConfig.getDefault().setExecutableBinaryPath(executablePathTextField.getText()); HgModuleConfig.getDefault().setExportFilename(exportFilenameTextField.getText()); HgModuleConfig.getDefault().setAnnotationFormat(annotationTextField.getText()); diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.form --- a/mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.form Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.form Wed Mar 26 17:31:23 2008 +0000 @@ -28,7 +28,7 @@ - + @@ -36,11 +36,11 @@ - + - + diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/diff/ExportDiffPanel.java Wed Mar 26 17:31:23 2008 +0000 @@ -268,6 +268,7 @@ private void revisionsComboBoxActionPerf targetsModel = new DefaultComboBoxModel(new Vector(initislRevsSet)); revisionsComboBox.setModel(targetsModel); revisionsComboBox.setEditable(false); + setDefaultOutputFile(); refreshViewThread = Thread.currentThread(); changesetPanel1.setInfo(repoRev.getLog()); Thread.interrupted(); // clear interupted status @@ -276,13 +277,13 @@ private void revisionsComboBoxActionPerf initislRevsSet.add(NbBundle.getMessage(ExportDiffPanel.class, "MSG_Fetching_Revisions")); // NOI18N targetsModel = new DefaultComboBoxModel(new Vector(initislRevsSet)); revisionsComboBox.setModel(targetsModel); + setDefaultOutputFile(); refreshViewThread = Thread.currentThread(); Thread.interrupted(); // clear interupted status ph.start(); refreshRevisions(); } - setDefaultOutputFile(); } finally { SwingUtilities.invokeLater(new Runnable() { public void run() { diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java Wed Mar 26 17:31:23 2008 +0000 @@ -95,6 +95,7 @@ public class HgProperties implements Lis private HgProgressSupport support; private File loadedValueFile; private Font fontTextArea; + private HgPropertiesNode[] initHgProps; /** Creates a new instance of HgProperties */ public HgProperties(PropertiesPanel panel, PropertiesTable propTable, File root) { @@ -134,6 +135,7 @@ public class HgProperties implements Lis protected void perform() { Properties props = HgModuleConfig.getDefault().getProperties(root); HgPropertiesNode[] hgProps = new HgPropertiesNode[props.size()]; + initHgProps = new HgPropertiesNode[props.size()]; int i = 0; for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) { @@ -141,6 +143,7 @@ public class HgProperties implements Lis String tmp = props.getProperty(name); String value = tmp != null ? tmp : ""; // NOI18N hgProps[i] = new HgPropertiesNode(name, value); + initHgProps[i] = new HgPropertiesNode(name, value); i++; } propTable.setNodes(hgProps); @@ -157,13 +160,12 @@ public class HgProperties implements Lis try { support = new HgProgressSupport() { protected void perform() { - HgModuleConfig.getDefault().clearProperties(root, "paths"); // NOI18N - HgModuleConfig.getDefault().removeProperty(root, "ui", HGPROPNAME_USERNAME); // NOI18N HgPropertiesNode[] hgPropertiesNodes = propTable.getNodes(); for (int i = 0; i < hgPropertiesNodes.length; i++) { String hgPropertyName = hgPropertiesNodes[i].getName(); String hgPropertyValue = hgPropertiesNodes[i].getValue(); - if (hgPropertyValue.trim().length() > 0 ) { + boolean bPropChanged = !(initHgProps[i].getValue()).equals(hgPropertyValue); + if (bPropChanged && hgPropertyValue.trim().length() > 0 ) { HgModuleConfig.getDefault().setProperty(root, hgPropertyName, hgPropertyValue); } } diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgCommand.java Wed Mar 26 17:31:23 2008 +0000 @@ -2853,10 +2853,15 @@ public class HgCommand { private static String getHgCommand() { String defaultPath = HgModuleConfig.getDefault().getExecutableBinaryPath(); - if (defaultPath == null || defaultPath.length() == 0) + if (defaultPath == null || defaultPath.length() == 0){ return HG_COMMAND; - else - return defaultPath + File.separatorChar + HG_COMMAND; + }else{ + if(Utilities.isWindows()){ + return defaultPath + File.separatorChar + HG_COMMAND + HG_WINDOWS_EXE; + }else{ + return defaultPath + File.separatorChar + HG_COMMAND; + } + } } private static void handleError(List command, List list, String message, OutputLogger logger) throws HgException{ diff -r 26cd68076a26 -r 51f01e967a06 mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java --- a/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Fri Mar 14 15:49:41 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java Wed Mar 26 17:31:23 2008 +0000 @@ -192,22 +192,33 @@ public class HgUtils { * @return boolean true - on PATH, false - not on PATH */ public static boolean isInUserPath(String name) { + String path = findInUserPath(name); + return (path == null || path.equals(""))? false: true; + } + + /** + * findInUserPath - check if passed in name is on the Users PATH environment setting and return the path + * + * @param name to check + * @return String full path to name + */ + public static String findInUserPath(String name) { String pathEnv = System.getenv().get("PATH");// NOI18N // Work around issues on Windows fetching PATH if(pathEnv == null) pathEnv = System.getenv().get("Path");// NOI18N if(pathEnv == null) pathEnv = System.getenv().get("path");// NOI18N String pathSeparator = System.getProperty("path.separator");// NOI18N - if (pathEnv == null || pathSeparator == null) return false; + if (pathEnv == null || pathSeparator == null) return ""; String[] paths = pathEnv.split(pathSeparator); for (String path : paths) { File f = new File(path, name); // On Windows isFile will fail on hgk.cmd use !isDirectory if (f.exists() && !f.isDirectory()) { - return true; + return path; } } - return false; + return ""; } /** @@ -255,6 +266,58 @@ public class HgUtils { } return path; } + + + /** + * fixIniFilePathsOnWindows - converts '\' to '\\' in paths in IniFile on Windows + * + * @param File iniFile to process + * @return File processed tmpFile + */ + public static File fixPathsInIniFileOnWindows(File iniFile) { + if(!Utilities.isWindows()) return iniFile; + + File tmpFile = null; + BufferedReader br = null; + PrintWriter pw = null; + + try { + if (iniFile == null || !iniFile.isFile() || !iniFile.canWrite()) { + return null; + } + + tmpFile = File.createTempFile(HgCommand.HG_COMMAND + "-", "tmp"); //NOI18N + + if (tmpFile == null) { + return null; + } + br = new BufferedReader(new FileReader(iniFile)); + pw = new PrintWriter(new FileWriter(tmpFile)); + + String line = null; + String stripLine = null; + while ((line = br.readLine()) != null) { + stripLine = line.replace("\\\\", "\\"); + pw.println(stripLine.replace("\\", "\\\\")); + pw.flush(); + } + } catch (IOException ex) { + // Ignore + } finally { + try { + if (pw != null) { + pw.close(); + } + if (br != null) { + br.close(); + } + } catch (IOException ex) { + // Ignore + } + } + return tmpFile; + } + /** * isLocallyAdded - checks to see if this file has been Locally Added to Hg *