Skip to content

Commit 5b24068

Browse files
committed
Issue #82: Support custom context root
1 parent dd13928 commit 5b24068

File tree

6 files changed

+66
-20
lines changed

6 files changed

+66
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public class MCEclipseApplication extends MicroclimateApplication {
8080
private ILaunch launch = null;
8181

8282
MCEclipseApplication(MicroclimateConnection mcConnection,
83-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot)
83+
String id, String name, ProjectType projectType, String pathInWorkspace)
8484
throws MalformedURLException {
85-
super(mcConnection, id, name, projectType, pathInWorkspace, contextRoot);
85+
super(mcConnection, id, name, projectType, pathInWorkspace);
8686
}
8787

8888
public synchronized boolean hasAppConsole() {

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ public class MicroclimateApplication {
3434

3535
public final MicroclimateConnection mcConnection;
3636
public final String projectID, name, host;
37-
public final String contextRoot; // can be null
3837
public final IPath fullLocalPath;
3938
public final ProjectType projectType;
4039

41-
40+
private String contextRoot; // can be null
4241
private StartMode startMode;
4342
private AppState appState;
4443
private BuildStatus buildStatus;
@@ -59,22 +58,19 @@ public class MicroclimateApplication {
5958
private int httpPort = -1, debugPort = -1;
6059

6160
MicroclimateApplication(MicroclimateConnection mcConnection,
62-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot)
61+
String id, String name, ProjectType projectType, String pathInWorkspace)
6362
throws MalformedURLException {
6463

6564
this.mcConnection = mcConnection;
6665
this.projectID = id;
6766
this.name = name;
6867
this.projectType = projectType;
69-
this.contextRoot = contextRoot;
7068
this.host = mcConnection.baseUrl.getHost();
7169

7270
// The mcConnection.localWorkspacePath will end in /microclimate-workspace
7371
// and the path passed here will start with /microclimate-workspace, so here we fix the duplication.
7472
this.fullLocalPath = MCUtil.appendPathWithoutDupe(mcConnection.getWorkspacePath(), pathInWorkspace);
7573

76-
setBaseUrl();
77-
7874
this.startMode = StartMode.RUN;
7975
this.appState = AppState.UNKNOWN;
8076
this.buildStatus = BuildStatus.UNKOWN;
@@ -89,7 +85,7 @@ private void setBaseUrl() throws MalformedURLException {
8985

9086
baseUrl = new URL("http", host, httpPort, ""); //$NON-NLS-1$ //$NON-NLS-2$
9187

92-
if (contextRoot != null) {
88+
if (contextRoot != null && !contextRoot.isEmpty()) {
9389
baseUrl = new URL(baseUrl, contextRoot);
9490
}
9591
}
@@ -114,6 +110,15 @@ public synchronized void setBuildStatus(String buildStatus, String buildDetails)
114110
}
115111
}
116112

113+
public synchronized void setContextRoot(String contextRoot) {
114+
this.contextRoot = contextRoot;
115+
try {
116+
setBaseUrl();
117+
} catch (MalformedURLException e) {
118+
MCLogger.logError("An error occurred updating the base url with the new context root: " + contextRoot, e);
119+
}
120+
}
121+
117122
public synchronized void setStartMode(StartMode startMode) {
118123
this.startMode = startMode;
119124
}
@@ -168,7 +173,7 @@ public synchronized int getHttpPort() {
168173
public synchronized int getDebugPort() {
169174
return debugPort;
170175
}
171-
176+
172177
public synchronized StartMode getStartMode() {
173178
return startMode;
174179
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ public static MicroclimateApplication createApp(MicroclimateConnection mcConnect
114114

115115
String loc = appJso.getString(MCConstants.KEY_LOC_DISK);
116116

117-
String contextRoot = null;
118-
if(appJso.has(MCConstants.KEY_CONTEXTROOT)) {
119-
contextRoot = appJso.getString(MCConstants.KEY_CONTEXTROOT);
120-
}
121-
122-
MicroclimateApplication mcApp = MicroclimateObjectFactory.createMicroclimateApplication(mcConnection, id, name, type, loc, contextRoot);
117+
MicroclimateApplication mcApp = MicroclimateObjectFactory.createMicroclimateApplication(mcConnection, id, name, type, loc);
123118

124119
updateApp(mcApp, appJso);
125120
return mcApp;
@@ -205,6 +200,18 @@ public static void updateApp(MicroclimateApplication mcApp, JSONObject appJso) {
205200
MCLogger.logError("Failed to get the ports for application: " + mcApp.name, e); //$NON-NLS-1$
206201
}
207202

203+
// Set the context root
204+
String contextRoot = null;
205+
if (appJso.has(MCConstants.KEY_CONTEXTROOT)) {
206+
contextRoot = appJso.getString(MCConstants.KEY_CONTEXTROOT);
207+
} else if (appJso.has(MCConstants.KEY_CUSTOM)) {
208+
JSONObject custom = appJso.getJSONObject(MCConstants.KEY_CUSTOM);
209+
if (custom.has(MCConstants.KEY_CONTEXTROOT)) {
210+
contextRoot = custom.getString(MCConstants.KEY_CONTEXTROOT);
211+
}
212+
}
213+
mcApp.setContextRoot(contextRoot);
214+
208215
// Set the start mode
209216
StartMode startMode = StartMode.get(appJso);
210217
mcApp.setStartMode(startMode);

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

Lines changed: 3 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
@@ -30,8 +30,8 @@ public static MicroclimateConnection createMicroclimateConnection(URI uri) throw
3030
}
3131

3232
public static MicroclimateApplication createMicroclimateApplication(MicroclimateConnection mcConnection,
33-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot) throws Exception {
34-
return new MCEclipseApplication(mcConnection, id, name, projectType, pathInWorkspace, contextRoot);
33+
String id, String name, ProjectType projectType, String pathInWorkspace) throws Exception {
34+
return new MCEclipseApplication(mcConnection, id, name, projectType, pathInWorkspace);
3535
}
3636

3737
}

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public class MicroclimateSocket {
7171
EVENT_PROJECT_DELETION = "projectDeletion", //$NON-NLS-1$
7272
EVENT_CONTAINER_LOGS = "container-logs", //$NON-NLS-1$
7373
EVENT_PROJECT_VALIDATED = "projectValidated", //$NON-NLS-1$
74-
EVENT_LOG_UPDATE = "log-update"; //$NON-NLS-1$
74+
EVENT_LOG_UPDATE = "log-update", //$NON-NLS-1$
75+
EVENT_PROJECT_SETTINGS_CHANGED = "projectSettingsChanged"; //$NON-NLS-1$
7576

7677
public MicroclimateSocket(MicroclimateConnection mcConnection) throws URISyntaxException {
7778
this.mcConnection = mcConnection;
@@ -154,6 +155,19 @@ public void call(Object... arg0) {
154155
}
155156
}
156157
})
158+
.on(EVENT_PROJECT_SETTINGS_CHANGED, new Emitter.Listener() {
159+
@Override
160+
public void call(Object... arg0) {
161+
MCLogger.log(EVENT_PROJECT_SETTINGS_CHANGED + ": " + arg0[0].toString()); //$NON-NLS-1$
162+
163+
try {
164+
JSONObject event = new JSONObject(arg0[0].toString());
165+
onProjectSettingsChanged(event);
166+
} catch (JSONException e) {
167+
MCLogger.logError("Error parsing JSON: " + arg0[0].toString(), e); //$NON-NLS-1$
168+
}
169+
}
170+
})
157171
.on(EVENT_PROJECT_STATUS_CHANGE, new Emitter.Listener() {
158172
@Override
159173
public void call(Object... arg0) {
@@ -316,6 +330,24 @@ private void onProjectChanged(JSONObject event) throws JSONException {
316330
app.setAutoBuild(autoBuild);
317331
}
318332
}
333+
334+
private void onProjectSettingsChanged(JSONObject event) throws JSONException {
335+
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
336+
MicroclimateApplication app = mcConnection.getAppByID(projectID);
337+
if (app == null) {
338+
MCLogger.logError("No application found matching the project id for the project settings changed event: " + projectID); //$NON-NLS-1$
339+
return;
340+
}
341+
342+
app.setEnabled(true);
343+
344+
// Update context root
345+
if (event.has(MCConstants.KEY_CONTEXT_ROOT)) {
346+
app.setContextRoot(event.getString(MCConstants.KEY_CONTEXT_ROOT));
347+
}
348+
349+
// TODO: need to update ports?
350+
}
319351

320352
private void onProjectStatusChanged(JSONObject event) throws JSONException {
321353
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/constants/MCConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ private MCConstants() {}
4545
KEY_BUILD_TYPE = "buildType",
4646
KEY_LOC_DISK = "locOnDisk",
4747
KEY_CONTEXTROOT = "contextroot",
48+
KEY_CONTEXT_ROOT = "contextRoot",
4849
KEY_CONTAINER_ID = "containerId",
50+
KEY_CUSTOM = "custom",
4951

5052
KEY_BUILD_LOG = "build-log",
5153
KEY_BUILD_LOG_LAST_MODIFIED = "build-log-last-modified",

0 commit comments

Comments
 (0)