Skip to content

Commit 1e4273d

Browse files
eharris369GitHub Enterprise
authored andcommitted
Merge pull request #219 from eharris/210-checkActionValueOnProject
Issue #210: Check the project action value
2 parents 1630cb8 + ed2208b commit 1e4273d

File tree

16 files changed

+78
-44
lines changed

16 files changed

+78
-44
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.ibm.microclimate.core.internal.connection.MicroclimateConnection;
2121
import com.ibm.microclimate.core.internal.constants.AppState;
2222
import com.ibm.microclimate.core.internal.constants.BuildStatus;
23+
import com.ibm.microclimate.core.internal.constants.MCConstants;
2324
import com.ibm.microclimate.core.internal.constants.ProjectCapabilities;
2425
import com.ibm.microclimate.core.internal.constants.ProjectType;
2526
import com.ibm.microclimate.core.internal.constants.StartMode;
@@ -44,6 +45,7 @@ public class MicroclimateApplication {
4445
private boolean enabled = true;
4546
private String containerId;
4647
private ProjectCapabilities projectCapabilities;
48+
private String action;
4749

4850
// Must be updated whenever httpPort changes. Can be null
4951
private URL baseUrl;
@@ -119,6 +121,10 @@ public synchronized void setContainerId(String id) {
119121
this.containerId = id;
120122
}
121123

124+
public synchronized void setAction(String action) {
125+
this.action = action;
126+
}
127+
122128
// Getters for our project state fields
123129

124130
/**
@@ -163,14 +169,27 @@ public synchronized boolean isEnabled() {
163169
public synchronized String getContainerId() {
164170
return containerId;
165171
}
166-
172+
167173
public boolean isActive() {
168174
return getAppState() == AppState.STARTING || getAppState() == AppState.STARTED;
169175
}
170176

171177
public boolean isRunning() {
172178
return baseUrl != null;
173179
}
180+
181+
public boolean isDeleting() {
182+
return MCConstants.VALUE_ACTION_DELETING.equals(action);
183+
}
184+
185+
public boolean isImporting() {
186+
// The action value is called "validating" but really this means the project is importing
187+
return MCConstants.VALUE_ACTION_VALIDATING.equals(action);
188+
}
189+
190+
public boolean isAvailable() {
191+
return isEnabled() && !isImporting();
192+
}
174193

175194
public boolean hasBuildLog() {
176195
return (!projectType.isType(ProjectType.TYPE_NODEJS));

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public static void getAppsFromProjectsJson(MicroclimateConnection mcConnection,
4747
MicroclimateApplication app = mcConnection.getAppByID(id);
4848
if (app != null) {
4949
updateApp(app, appJso);
50+
if (app.isDeleting()) {
51+
// Remove the app from the list
52+
mcConnection.removeApp(id);
53+
}
5054
} else {
5155
app = createApp(mcConnection, appJso);
52-
if (app != null) {
56+
if (app != null && !app.isDeleting()) {
5357
mcConnection.addApp(app);
5458
}
5559
}
@@ -113,6 +117,18 @@ public static MicroclimateApplication createApp(MicroclimateConnection mcConnect
113117
*/
114118
public static void updateApp(MicroclimateApplication mcApp, JSONObject appJso) {
115119
try {
120+
// Set the action
121+
if (appJso.has(MCConstants.KEY_ACTION)) {
122+
String action = appJso.getString(MCConstants.KEY_ACTION);
123+
mcApp.setAction(action);
124+
if (MCConstants.VALUE_ACTION_DELETING.equals(action)) {
125+
// No point in updating any further since this app should be removed from the list
126+
return;
127+
}
128+
} else {
129+
mcApp.setAction(null);
130+
}
131+
116132
// Set the app status
117133
if (appJso.has(MCConstants.KEY_APP_STATUS)) {
118134
String appStatus = appJso.getString(MCConstants.KEY_APP_STATUS);
@@ -143,28 +159,31 @@ public static void updateApp(MicroclimateApplication mcApp, JSONObject appJso) {
143159
if (appJso.has(MCConstants.KEY_PORTS) && (appJso.get(MCConstants.KEY_PORTS) instanceof JSONObject)) {
144160
JSONObject portsObj = appJso.getJSONObject(MCConstants.KEY_PORTS);
145161

162+
int httpPortNum = -1;
146163
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_PORT)) {
147164
String httpPort = portsObj.getString(MCConstants.KEY_EXPOSED_PORT);
148165
if (httpPort != null && !httpPort.isEmpty()) {
149-
int portNum = MCUtil.parsePort(httpPort);
150-
if (portNum != -1) {
151-
mcApp.setHttpPort(portNum);
152-
}
166+
httpPortNum = MCUtil.parsePort(httpPort);
153167
}
154168
}
169+
if (httpPortNum != -1) {
170+
mcApp.setHttpPort(httpPortNum);
171+
}
155172

173+
int debugPortNum = -1;
156174
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_DEBUG_PORT)) {
157175
String debugPort = portsObj.getString(MCConstants.KEY_EXPOSED_DEBUG_PORT);
158176
if (debugPort != null && !debugPort.isEmpty()) {
159-
int portNum = MCUtil.parsePort(debugPort);
160-
if (portNum != -1) {
161-
mcApp.setDebugPort(portNum);
162-
}
177+
debugPortNum = MCUtil.parsePort(debugPort);
163178
}
164179
}
180+
mcApp.setDebugPort(debugPortNum);
181+
182+
} else {
183+
MCLogger.logError("No ports object on project info for application: " + mcApp.name); //$NON-NLS-1$
165184
}
166185
} catch (Exception e) {
167-
MCLogger.logError("Failed to get the ports for application: " + mcApp.name, e);
186+
MCLogger.logError("Failed to get the ports for application: " + mcApp.name, e); //$NON-NLS-1$
168187
}
169188

170189
// Set the start mode

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,14 @@ private void onProjectChanged(JSONObject event) throws JSONException {
262262
// Update ports
263263
JSONObject portsObj = event.getJSONObject(MCConstants.KEY_PORTS);
264264

265-
// If the app is started, get the http port. If it's not started, this will be missing, and we can't proceed.
266-
if (!portsObj.has(MCConstants.KEY_EXPOSED_PORT)) {
267-
MCLogger.log(String.format("No %s key - %s is not running.", //$NON-NLS-1$
268-
MCConstants.KEY_EXPOSED_PORT, app.name));
269-
return;
265+
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_PORT)) {
266+
int port = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_PORT));
267+
app.setHttpPort(port);
268+
} else {
269+
MCLogger.logError("No http port on project changed event for: " + app.name); //$NON-NLS-1$
270270
}
271271

272-
int port = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_PORT));
273-
app.setHttpPort(port);
274-
275-
if (portsObj.has(MCConstants.KEY_EXPOSED_DEBUG_PORT)) {
272+
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_DEBUG_PORT)) {
276273
int debugPort = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_DEBUG_PORT));
277274
app.setDebugPort(debugPort);
278275
if (StartMode.DEBUG_MODES.contains(app.getStartMode()) && debugPort != -1) {
@@ -338,23 +335,23 @@ private void onProjectRestart(JSONObject event) throws JSONException {
338335
return;
339336
}
340337

341-
// this event should always have a 'ports' sub-object
338+
// This event should always have a 'ports' sub-object
342339
JSONObject portsObj = event.getJSONObject(MCConstants.KEY_PORTS);
343340

344-
// ports object should always have an http port
345-
int port = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_PORT));
346-
if (port != -1) {
341+
// The ports object should always have an http port
342+
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_PORT)) {
343+
int port = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_PORT));
347344
app.setHttpPort(port);
345+
} else {
346+
MCLogger.logError("No http port on project restart event for: " + app.name); //$NON-NLS-1$
348347
}
349348

350-
// Debug port will obviously be missing if the restart was into Run mode.
349+
// Debug port will be missing if the restart was into Run mode.
351350
int debugPort = -1;
352-
if (portsObj.has(MCConstants.KEY_EXPOSED_DEBUG_PORT)) {
351+
if (portsObj != null && portsObj.has(MCConstants.KEY_EXPOSED_DEBUG_PORT)) {
353352
debugPort = MCUtil.parsePort(portsObj.getString(MCConstants.KEY_EXPOSED_DEBUG_PORT));
354-
if (debugPort != -1) {
355-
app.setDebugPort(debugPort);
356-
}
357353
}
354+
app.setDebugPort(debugPort);
358355

359356
StartMode startMode = StartMode.get(event);
360357
app.setStartMode(startMode);

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
@@ -73,6 +73,8 @@ private MCConstants() {}
7373
VALUE_ACTION_BUILD = "build",
7474
VALUE_ACTION_ENABLEAUTOBUILD = "enableautobuild",
7575
VALUE_ACTION_DISABLEAUTOBUILD = "disableautobuild",
76+
VALUE_ACTION_DELETING = "deleting",
77+
VALUE_ACTION_VALIDATING = "validating",
7678

7779
KEY_VALIDATION_STATUS = "validationStatus",
7880
KEY_VALIDATION_RESULTS = "validationResults",

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/AttachDebuggerAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void selectionChanged(IStructuredSelection sel) {
4040
Object obj = sel.getFirstElement();
4141
if (obj instanceof MCEclipseApplication) {
4242
app = (MCEclipseApplication) obj;
43-
if (app.isEnabled() && StartMode.DEBUG_MODES.contains(app.getStartMode()) &&
43+
if (app.isAvailable() && StartMode.DEBUG_MODES.contains(app.getStartMode()) && app.getDebugPort() != -1 &&
4444
(app.getAppState() == AppState.STARTED || app.getAppState() == AppState.STARTING)) {
4545
IDebugTarget debugTarget = app.getDebugTarget();
4646
setEnabled(debugTarget == null || debugTarget.isDisconnected());

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/ContainerShellAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void selectionChanged(IAction action, ISelection selection) {
5454
Object obj = sel.getFirstElement();
5555
if (obj instanceof MicroclimateApplication) {
5656
app = (MicroclimateApplication)obj;
57-
action.setEnabled(app.isEnabled() && app.getContainerId() != null);
57+
action.setEnabled(app.isAvailable() && app.getContainerId() != null);
5858
return;
5959
}
6060
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/EnableDisableAutoBuildAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void selectionChanged(IAction action, ISelection selection) {
4040
Object obj = sel.getFirstElement();
4141
if (obj instanceof MCEclipseApplication) {
4242
app = (MCEclipseApplication)obj;
43-
if (app.isEnabled()) {
43+
if (app.isAvailable()) {
4444
if (app.isAutoBuild()) {
4545
action.setText(Messages.DisableAutoBuildLabel);
4646
} else {

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/EnableDisableProjectAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void selectionChanged(IAction action, ISelection selection) {
3939
Object obj = sel.getFirstElement();
4040
if (obj instanceof MCEclipseApplication) {
4141
app = (MCEclipseApplication)obj;
42-
if (app.isEnabled()) {
42+
if (app.isAvailable()) {
4343
action.setText(Messages.DisableProjectLabel);
4444
} else {
4545
action.setText(Messages.EnableProjectLabel);

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/ImportProjectAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void selectionChanged(IAction action, ISelection selection) {
4646
Object obj = sel.getFirstElement();
4747
if (obj instanceof MicroclimateApplication) {
4848
app = (MicroclimateApplication) obj;
49-
if (app.isEnabled()) {
49+
if (app.isAvailable()) {
5050
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(app.name);
5151
action.setEnabled(project == null || !project.exists());
5252
return;

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/OpenAppAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void selectionChanged(IAction action, ISelection selection) {
4747
Object obj = sel.getFirstElement();
4848
if (obj instanceof MicroclimateApplication) {
4949
app = (MicroclimateApplication)obj;
50-
action.setEnabled(app.isEnabled() && app.getAppState() == AppState.STARTED);
50+
action.setEnabled(app.isAvailable() && app.getAppState() == AppState.STARTED);
5151
return;
5252
}
5353
}

0 commit comments

Comments
 (0)