Skip to content

Commit

Permalink
Fix the windows registry to correctly load the windows registry value. (
Browse files Browse the repository at this point in the history
  • Loading branch information
groboclown committed May 11, 2017
1 parent 255a1e4 commit 53b7755
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 74 deletions.
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# IDEA Community VCS Integration for Perforce


## ::v0.8.7::

### Overview

* Added support for "P4ENVIRO" loaded from the Windows registry.
* Bug fixes.

### Details

* Added support for "P4ENVIRO" loaded from the Windows registry.
* Before, the Windows registry loader would not correctly read in the
`P4ENVIRO` setting from the Windows registry.
* Bug fixes.
* Fixed the


## ::v0.8.6::

### Overview
Expand Down
26 changes: 13 additions & 13 deletions plugin/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,7 @@
<category>VCS Integration</category>
<change-notes><![CDATA[
<ol>
<li><em>0.8.6</em>
<ol>
<li>Change "maximum timeout" setting meaning to now mean the maximum
socket timeout to live.</li>
<li>Add lock timeout user setting.</li>
<li>Went back to actually using the "reconnect with each request" setting,
so that it can reuse the existing connection.</li>
<li>Clarified error message when reverting files while working offline.</li>
<li>Reduced number of false error messages when the plugin hasn't loaded the
client spec when requests are made.</li>
</ol>
</li>
<li><em>0.8.5</em>
<li><em>0.8.7</em>
<ol>
<li>Remove issues around setting up default Perforce configuration.</li>
<li>Added back the SSL key strength checking and error reporting.</li>
Expand All @@ -31,6 +19,18 @@
potential SocketTimeoutExceptions.</li>
</ol>
</li>
<li><em>0.8.6</em>
<ol>
<li>Change "maximum timeout" setting meaning to now mean the maximum
socket timeout to live.</li>
<li>Add lock timeout user setting.</li>
<li>Went back to actually using the "reconnect with each request" setting,
so that it can reuse the existing connection.</li>
<li>Clarified error message when reverting files while working offline.</li>
<li>Reduced number of false error messages when the plugin hasn't loaded the
client spec when requests are made.</li>
</ol>
</li>
</ol>
]]></change-notes>
<description><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

package net.groboclown.idea.p4ic.config.part;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.perforce.p4java.env.PerforceEnvironment;
import net.groboclown.idea.p4ic.config.ConfigProblem;
import net.groboclown.idea.p4ic.config.ConfigPropertiesUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -31,6 +33,8 @@
public class EnvCompositePart extends CompositePart {
static final String TAG_NAME = "env-composite-part";
static final ConfigPartFactory<EnvCompositePart> FACTORY = new Factory();
private static final Logger LOG = Logger.getInstance(EnvCompositePart.class);


private final Project project;

Expand Down Expand Up @@ -89,17 +93,30 @@ private void loadEnvironmentParts() {
parts = new ArrayList<ConfigPart>();

String p4config = null;
String p4enviro = null;

if (WinRegDataPart.isAvailable()) {
WinRegDataPart userReg = new WinRegDataPart(true);
if (LOG.isDebugEnabled()) {
LOG.debug("Loaded user windows registry: " + ConfigPropertiesUtil.toProperties(userReg));
}
// p4config is always null at this point.
// if (p4config == null) {
p4config = userReg.getP4ConfigFile();
// }
// if (p4enviro == null) {
p4enviro = userReg.getP4EnviroFile();
// }
WinRegDataPart sysReg = new WinRegDataPart(false);
if (p4config == null) {
p4config = sysReg.getP4ConfigFile();
}
if (p4enviro == null) {
p4enviro = sysReg.getP4EnviroFile();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Loaded system windows registry: " + ConfigPropertiesUtil.toProperties(sysReg));
}
parts.add(userReg);
parts.add(sysReg);
}
Expand All @@ -115,10 +132,16 @@ private void loadEnvironmentParts() {
envData.setAuthTicketFile(PerforceEnvironment.getP4Tickets());
envData.setTrustTicketFile(PerforceEnvironment.getP4Trust());
envData.setIgnoreFilename(PerforceEnvironment.getP4Ignore());
if (LOG.isDebugEnabled()) {
LOG.debug("Loaded environment variables: " + ConfigPropertiesUtil.toProperties(envData));
}

if (p4config == null) {
p4config = PerforceEnvironment.getP4Config();
}
if (p4enviro == null) {
p4enviro = PerforceEnvironment.getP4Enviro();
}

// P4CONFIG loading
{
Expand All @@ -129,16 +152,25 @@ private void loadEnvironmentParts() {
if (!f.isAbsolute()) {
f = new File(new File(project.getBaseDir().getPath()), p4config);
}
parts.add(new FileDataPart(project, f));

final FileDataPart envConf = new FileDataPart(project, f);
if (LOG.isDebugEnabled()) {
LOG.debug("Env defined absolute P4CONFIG: " + f + ": " +
ConfigPropertiesUtil.toProperties(envConf));
}
parts.add(envConf);
} else {
parts.add(new RelativeConfigCompositePart(project, p4config));
final RelativeConfigCompositePart envConf = new RelativeConfigCompositePart(project, p4config);
if (LOG.isDebugEnabled()) {
LOG.debug("Env defined relative P4CONFIG: " + p4config);
}
parts.add(envConf);
}
}
}

// P4ENVIRO loading
{
String p4enviro = PerforceEnvironment.getP4Enviro();
if (p4enviro != null) {
File f = new File(p4enviro);
if (!f.isAbsolute()) {
Expand All @@ -147,7 +179,12 @@ private void loadEnvironmentParts() {
// The P4ENVIRO will have a default value if the user didn't specify one.
// Therefore, if the file doesn't exist, don't complain.
if (f.exists()) {
parts.add(new FileDataPart(project, f));
final FileDataPart envConf = new FileDataPart(project, f);
if (LOG.isDebugEnabled()) {
LOG.debug("Env defined P4ENVIRO: " + f + ": " +
ConfigPropertiesUtil.toProperties(envConf));
}
parts.add(envConf);
}
}
}
Expand Down
70 changes: 53 additions & 17 deletions plugin/src/net/groboclown/idea/p4ic/config/part/WinRegDataPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import sun.misc.Perf;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Map;

class WinRegDataPart implements DataPart {
private static final Logger LOG = Logger.getInstance(WinRegDataPart.class);

@NonNls
private static final String USER_KEY = "\\Software\\Perforce\\Environment";
private static final String[] USER_KEYS = {
"Software\\Perforce\\Environment",

};
@NonNls
private static final String MACHINE_KEY = "\\SOFTWARE\\Perforce\\Environment";
private static final String[] MACHINE_KEYS = {
"SOFTWARE\\Perforce\\Environment",
"SOFTWARE\\Wow6432Node\\Perforce\\Environment"
};

private final int hive;
private final String key;
private final String[] keys;


private String rawPort;
Expand All @@ -51,6 +59,7 @@ class WinRegDataPart implements DataPart {
private String authTicketPath;
private String trustTicket;
private String configFile;
private String enviroFile;
private String clientHostname;
private String ignoreFileName;
private String charset;
Expand All @@ -64,10 +73,10 @@ static boolean isAvailable() {
WinRegDataPart(boolean userReg) {
if (userReg) {
hive = PreferencesWinRegistry.HKEY_CURRENT_USER;
key = USER_KEY;
keys = USER_KEYS;
} else {
hive = PreferencesWinRegistry.HKEY_LOCAL_MACHINE;
key = MACHINE_KEY;
keys = MACHINE_KEYS;
}
reload();
}
Expand All @@ -81,21 +90,33 @@ public Element marshal() {
@Override
public boolean reload() {
try {
rawPort = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4PORT);
if (LOG.isDebugEnabled()) {
for (String key: keys) {
LOG.debug("String values for " + key + ": " + PreferencesWinRegistry.readStringValues(hive, key));
LOG.debug("");
}
}


rawPort = readRegString(PerforceEnvironment.P4PORT);
serverName = P4ServerName.forPort(rawPort);
clientName = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4CLIENT);
userName = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4USER);
password = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4PASSWD);
authTicketPath = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4TICKETS);
trustTicket = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4TRUST);
configFile = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4CONFIG);
clientHostname = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4HOST);
ignoreFileName = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4IGNORE);
charset = PreferencesWinRegistry.readString(hive, key, PerforceEnvironment.P4CHARSET);
loginSso = PreferencesWinRegistry.readString(hive, key, "P4LOGINSSO");
clientName = readRegString(PerforceEnvironment.P4CLIENT);
userName = readRegString(PerforceEnvironment.P4USER);
password = readRegString(PerforceEnvironment.P4PASSWD);
authTicketPath = readRegString(PerforceEnvironment.P4TICKETS);
trustTicket = readRegString(PerforceEnvironment.P4TRUST);
configFile = readRegString(PerforceEnvironment.P4CONFIG);
enviroFile = readRegString(PerforceEnvironment.P4ENVIRO);
clientHostname = readRegString(PerforceEnvironment.P4HOST);
ignoreFileName = readRegString(PerforceEnvironment.P4IGNORE);
charset = readRegString(PerforceEnvironment.P4CHARSET);
loginSso = readRegString("P4LOGINSSO");

if (LOG.isDebugEnabled()) {
LOG.debug("Loaded windows registry " + key + " " + ConfigPropertiesUtil.toProperties(this));
Map<String, String> props = ConfigPropertiesUtil.toProperties(this);
props.put(PerforceEnvironment.P4CONFIG, configFile);
props.put(PerforceEnvironment.P4ENVIRO, enviroFile);
LOG.debug("Loaded windows registry " + keys[0] + " " + props);
}
} catch (IllegalAccessException e) {
// Do not mark as an actual problem. This is a JVM incompatible issue.
Expand All @@ -107,10 +128,25 @@ public boolean reload() {
return hasError();
}

private String readRegString(String valueName)
throws InvocationTargetException, IllegalAccessException {
for (String key: keys) {
String ret = PreferencesWinRegistry.readString(hive, key, valueName);
if (ret != null) {
return ret;
}
}
return null;
}

String getP4ConfigFile() {
return configFile;
}

String getP4EnviroFile() {
return enviroFile;
}

@NotNull
@Override
public Collection<ConfigProblem> getConfigProblems() {
Expand Down
Loading

0 comments on commit 53b7755

Please sign in to comment.