Skip to content

Commit d4eb785

Browse files
authored
Merge pull request #30 from eharris369/25-dontCacheConnectionDetails
Issue #25: Re-initialize connection information on reconnect
2 parents b46de61 + 6d9bd0b commit d4eb785

File tree

7 files changed

+65
-15
lines changed

7 files changed

+65
-15
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class MicroclimateApplication {
6767

6868
// The mcConnection.localWorkspacePath will end in /microclimate-workspace
6969
// and the path passed here will start with /microclimate-workspace, so here we fix the duplication.
70-
this.fullLocalPath = MCUtil.appendPathWithoutDupe(mcConnection.localWorkspacePath, pathInWorkspace);
70+
this.fullLocalPath = MCUtil.appendPathWithoutDupe(mcConnection.getWorkspacePath(), pathInWorkspace);
7171

7272
setBaseUrl();
7373

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateConnection.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public class MicroclimateConnection {
5151
private static final Pattern pattern = Pattern.compile(BRANCH_VERSION);
5252

5353
public final URI baseUrl;
54-
public final IPath localWorkspacePath;
55-
public final String versionStr;
54+
private IPath localWorkspacePath;
55+
private String versionStr;
56+
private String connectionErrorMsg = null;
5657

5758
public final MicroclimateSocket mcSocket;
5859

@@ -224,6 +225,10 @@ public boolean checkVersion(int requiredVersion, String requiredVersionBr) {
224225

225226
return false;
226227
}
228+
229+
public String getConnectionErrorMsg() {
230+
return this.connectionErrorMsg;
231+
}
227232

228233
private static Path getWorkspacePath(JSONObject env) throws JSONException {
229234
// Try the internal system property first
@@ -507,6 +512,41 @@ public synchronized void onConnectionError() {
507512
*/
508513
public synchronized void clearConnectionError() {
509514
MCLogger.log("MCConnection to " + baseUrl + " restored"); //$NON-NLS-1$ //$NON-NLS-2$
515+
516+
// Reset any cached information in case it has changed
517+
try {
518+
JSONObject envData = getEnvData(baseUrl);
519+
String version = getMCVersion(envData);
520+
if (UNKNOWN_VERSION.equals(versionStr)) {
521+
MCLogger.logError("Failed to get the Microclimate version after reconnect");
522+
this.connectionErrorMsg = NLS.bind(Messages.MicroclimateConnection_ErrConnection_VersionUnknown, MCConstants.REQUIRED_MC_VERSION);
523+
MCUtil.updateConnection(this);
524+
return;
525+
}
526+
if (!isSupportedVersion(version)) {
527+
MCLogger.logError("The detected version of Microclimate after reconnect is not supported: " + version);
528+
this.connectionErrorMsg = NLS.bind(Messages.MicroclimateConnection_ErrConnection_OldVersion, versionStr, MCConstants.REQUIRED_MC_VERSION);
529+
MCUtil.updateConnection(this);
530+
return;
531+
}
532+
this.versionStr = version;
533+
IPath path = getWorkspacePath(envData);
534+
if (path == null) {
535+
// This should not happen since the version was ok
536+
MCLogger.logError("Failed to get the local workspace path after reconnect");
537+
this.connectionErrorMsg = Messages.MicroclimateConnection_ErrConnection_WorkspaceErr;
538+
MCUtil.updateConnection(this);
539+
return;
540+
}
541+
this.localWorkspacePath = path;
542+
} catch (Exception e) {
543+
MCLogger.logError("An exception occurred while trying to update the connection information", e);
544+
this.connectionErrorMsg = Messages.MicroclimateConnection_ErrConnection_UpdateCacheException;
545+
MCUtil.updateConnection(this);
546+
return;
547+
}
548+
549+
this.connectionErrorMsg = null;
510550
isConnected = true;
511551
refreshApps(null);
512552
MCUtil.updateConnection(this);

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/messages/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Messages extends NLS {
2323
public static String MicroclimateConnection_ErrContactingServerDialogMsg;
2424
public static String MicroclimateConnection_ErrContactingServerDialogTitle;
2525
public static String MicroclimateConnection_ErrGettingProjectListTitle;
26+
public static String MicroclimateConnection_ErrConnection_UpdateCacheException;
2627

2728
public static String MicroclimateConnectionException_ConnectingToMCFailed;
2829

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/messages/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2018 IBM Corporation and others.
2+
# Copyright (c) 2018, 2019 IBM Corporation and others.
33
# All rights reserved. This program and the accompanying materials
44
# are made available under the terms of the Eclipse Public License v2.0
55
# which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@ MicroclimateConnection_ErrConnection_WorkspaceErr=The location of your Microclim
1616
MicroclimateConnection_ErrContactingServerDialogMsg=Failed to contact the Microclimate server at {0}.
1717
MicroclimateConnection_ErrContactingServerDialogTitle=Error contacting Microclimate server
1818
MicroclimateConnection_ErrGettingProjectListTitle=Error getting list of projects
19+
MicroclimateConnection_ErrConnection_UpdateCacheException=An error occurred while initializing the Microclimate connection. Check the workspace logs.
1920

2021
MicroclimateConnectionException_ConnectingToMCFailed=Connecting to Microclimate at {0} failed.
2122

dev/com.ibm.microclimate.ui/plugin.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Bundle-Name = Microclimate UI Plugin
1717

1818
ACTION_REFRESH=Re&fresh
1919

20-
ACTION_OPEN_MICROCLIMATE_UI=Open Microclimate &UI
21-
ACTION_CREATE_NEW_PROJECT=Open Create &Project Page
22-
ACTION_IMPORT_PROJECT=Open &Import Project Page
23-
ACTION_REMOVE_CONNECTION=&Remove Connection
20+
ACTION_CONNECTION_OPEN_MICROCLIMATE_UI=Open Microclimate &UI
21+
ACTION_CONNECTION_CREATE_NEW_PROJECT=Open New &Project Page
22+
ACTION_CONNECTION_IMPORT_PROJECT=Open &Import Project Page
23+
ACTION_CONNECTION_REMOVE_CONNECTION=&Remove Connection
2424

2525
ACTION_OPEN_APP=&Open Application
2626
ACTION_CONTAINER_SHELL=Open &Container Shell

dev/com.ibm.microclimate.ui/plugin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,28 @@
208208
id="com.ibm.microclimate.ui.removeConnection"
209209
enablesFor="1"
210210
menubarPath="group.additions"
211-
label="%ACTION_REMOVE_CONNECTION"
211+
label="%ACTION_CONNECTION_REMOVE_CONNECTION"
212212
class="com.ibm.microclimate.ui.internal.actions.RemoveConnectionAction"/>
213213
<action
214214
id="com.ibm.microclimate.ui.importProject"
215215
enablesFor="1"
216216
menubarPath="group.new"
217217
icon="%DEFAULT_ICON_PATH"
218-
label="%ACTION_IMPORT_PROJECT"
218+
label="%ACTION_CONNECTION_IMPORT_PROJECT"
219219
class="com.ibm.microclimate.ui.internal.actions.OpenMicroclimateUIAction"/>
220220
<action
221221
id="com.ibm.microclimate.ui.createNewProject"
222222
enablesFor="1"
223223
menubarPath="group.new"
224224
icon="%DEFAULT_ICON_PATH"
225-
label="%ACTION_CREATE_NEW_PROJECT"
225+
label="%ACTION_CONNECTION_CREATE_NEW_PROJECT"
226226
class="com.ibm.microclimate.ui.internal.actions.OpenMicroclimateUIAction"/>
227227
<action
228228
id="com.ibm.microclimate.ui.openMicroclimateUI"
229229
enablesFor="1"
230230
menubarPath="group.new"
231231
icon="%DEFAULT_ICON_PATH"
232-
label="%ACTION_OPEN_MICROCLIMATE_UI"
232+
label="%ACTION_CONNECTION_OPEN_MICROCLIMATE_UI"
233233
class="com.ibm.microclimate.ui.internal.actions.OpenMicroclimateUIAction"/>
234234
</objectContribution>
235235
</extension>

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/views/MicroclimateNavigatorLabelProvider.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -48,7 +48,11 @@ public String getText(Object element) {
4848
MicroclimateConnection connection = (MicroclimateConnection)element;
4949
String text = Messages.MicroclimateConnectionLabel + " " + connection.baseUrl;
5050
if (!connection.isConnected()) {
51-
text = text + " (" + Messages.MicroclimateDisconnected + ")";
51+
String errorMsg = connection.getConnectionErrorMsg();
52+
if (errorMsg == null) {
53+
errorMsg = Messages.MicroclimateDisconnected;
54+
}
55+
text = text + " (" + errorMsg + ")";
5256
} else if (connection.getApps().size() == 0) {
5357
text = text + " (" + Messages.MicroclimateConnectionNoProjects + ")";
5458
}
@@ -85,7 +89,11 @@ public StyledString getStyledText(Object element) {
8589
styledString = new StyledString(Messages.MicroclimateConnectionLabel + " " );
8690
styledString.append(connection.baseUrl.toString(), StyledString.QUALIFIER_STYLER);
8791
if (!connection.isConnected()) {
88-
styledString.append(" (" + Messages.MicroclimateDisconnected + ")", ERROR_STYLER);
92+
String errorMsg = connection.getConnectionErrorMsg();
93+
if (errorMsg == null) {
94+
errorMsg = Messages.MicroclimateDisconnected;
95+
}
96+
styledString.append(" (" + errorMsg + ")", ERROR_STYLER);
8997
} else if (connection.getApps().size() == 0) {
9098
styledString.append(" (" + Messages.MicroclimateConnectionNoProjects + ")", StyledString.DECORATIONS_STYLER);
9199
}

0 commit comments

Comments
 (0)