Skip to content

Commit a0c585e

Browse files
authored
Reflect local App Engine server state in console (#1145)
1 parent 28f32d8 commit a0c585e

File tree

17 files changed

+160
-144
lines changed

17 files changed

+160
-144
lines changed

plugins/com.google.cloud.tools.eclipse.appengine.localserver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/server/MessagesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.tools.eclipse.appengine.localserver.server;
1818

19+
import com.google.cloud.tools.eclipse.appengine.localserver.Messages;
1920
import org.junit.Assert;
2021
import org.junit.Test;
2122

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/Messages.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,31 @@
1616

1717
package com.google.cloud.tools.eclipse.appengine.localserver;
1818

19-
import org.eclipse.osgi.util.NLS;
19+
import java.text.MessageFormat;
20+
import java.util.MissingResourceException;
21+
import java.util.ResourceBundle;
2022

21-
public class Messages extends NLS {
23+
public class Messages {
2224
private static final String BUNDLE_NAME =
2325
"com.google.cloud.tools.eclipse.appengine.localserver.messages"; //$NON-NLS-1$
2426

25-
public static String NOT_FACETED_PROJECT;
26-
public static String GAE_STANDARD_FACET_MISSING;
27-
public static String NEW_SERVER_DIALOG_PORT;
28-
public static String NEW_SERVER_DIALOG_INVALID_PORT_VALUE;
29-
public static String PORT_IN_USE;
30-
public static String PORT_OUT_OF_RANGE;
27+
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
3128

32-
public static String CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION;
33-
public static String CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE;
34-
public static String OPEN_CLOUD_SDK_PREFERENCE_BUTTON;
35-
public static String RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND;
36-
37-
static {
38-
// initialize resource bundle
39-
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
29+
public static String getString(String key) {
30+
try {
31+
return RESOURCE_BUNDLE.getString(key);
32+
} catch (MissingResourceException e) {
33+
return '!' + key + '!';
34+
}
4035
}
4136

42-
private Messages() {
37+
public static String getString(String key, Object... params) {
38+
try {
39+
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
40+
} catch (MissingResourceException ex) {
41+
return '!' + key + '!';
42+
}
4343
}
44+
45+
private Messages() {}
4446
}

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LaunchHelper.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.tools.eclipse.appengine.localserver.launching;
1818

19+
import com.google.cloud.tools.eclipse.appengine.localserver.Messages;
1920
import com.google.cloud.tools.eclipse.appengine.localserver.server.LocalAppEngineServerDelegate;
2021
import com.google.cloud.tools.eclipse.util.AdapterUtil;
2122
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
@@ -58,9 +59,9 @@ public void launch(IModule[] modules, String launchMode) throws CoreException {
5859
for (IServer existing : servers) {
5960
if (isRunning(existing)) {
6061
ILaunch launch = existing.getLaunch();
61-
Preconditions.checkNotNull(launch, "Running server should have a launch");
62-
String detail = launchMode.equals(launch.getLaunchMode()) ? "Server is already running"
63-
: MessageFormat.format("Server is already running in \"{0}\" mode",
62+
Preconditions.checkNotNull(launch, Messages.getString("RUNNING_SERVER_SHOULD_HAVE_A_LAUNCH")); //$NON-NLS-1$
63+
String detail = launchMode.equals(launch.getLaunchMode()) ? Messages.getString("SERVER_ALREADY_RUNNING") //$NON-NLS-1$
64+
: MessageFormat.format(Messages.getString("SERVER_ALREADY_RUNNING_IN_MODE"), //$NON-NLS-1$
6465
launch.getLaunchMode());
6566
throw new CoreException(StatusUtil.info(this, detail));
6667
}
@@ -138,7 +139,7 @@ public IModule[] asModules(ISelection selection) throws CoreException {
138139
}
139140
return modules.toArray(new IModule[modules.size()]);
140141
}
141-
throw new CoreException(StatusUtil.error(this, "Cannot determine server execution context"));
142+
throw new CoreException(StatusUtil.error(this, Messages.getString("CANNOT_DETERMINE_EXECUTION_CONTEXT"))); //$NON-NLS-1$
142143
}
143144

144145
/** Check the project of the active editor. */
@@ -150,7 +151,7 @@ public IModule[] asModules(IEditorPart editor) throws CoreException {
150151
return new IModule[] {asModule(project)};
151152
}
152153
}
153-
throw new CoreException(StatusUtil.error(this, "Cannot determine server execution context"));
154+
throw new CoreException(StatusUtil.error(this, Messages.getString("CANNOT_DETERMINE_EXECUTION_CONTEXT"))); //$NON-NLS-1$
154155
}
155156

156157
private IModule asModule(Object object) throws CoreException {
@@ -165,7 +166,8 @@ private IModule asModule(Object object) throws CoreException {
165166
return module;
166167
}
167168
}
168-
throw new CoreException(StatusUtil.error(this, "no module found for " + object));
169+
throw new CoreException(
170+
StatusUtil.error(this, Messages.getString("NO_MODULE_FOUND_FOR", object))); //$NON-NLS-1$
169171
}
170172

171173
}

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LocalAppEngineStandardLaunchShortcut.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.tools.eclipse.appengine.localserver.launching;
1818

19+
import com.google.cloud.tools.eclipse.appengine.localserver.Messages;
1920
import java.util.ArrayList;
2021
import java.util.Collection;
2122
import org.eclipse.core.resources.IResource;
@@ -42,7 +43,7 @@ public void launch(ISelection selection, String launchMode) {
4243
IModule[] modules = launcher.asModules(selection);
4344
launcher.launch(modules, launchMode);
4445
} catch (CoreException ex) {
45-
ErrorDialog.openError(null, Messages.getString("UnableToLaunch"), ex.getLocalizedMessage(), //$NON-NLS-1$
46+
ErrorDialog.openError(null, Messages.getString("UNABLE_TO_LAUNCH"), ex.getLocalizedMessage(), //$NON-NLS-1$
4647
ex.getStatus());
4748
}
4849
}
@@ -53,7 +54,7 @@ public void launch(IEditorPart editor, String launchMode) {
5354
IModule[] modules = launcher.asModules(editor);
5455
launcher.launch(modules, launchMode);
5556
} catch (CoreException ex) {
56-
ErrorDialog.openError(null, Messages.getString("UnableToLaunch"), ex.getLocalizedMessage(), //$NON-NLS-1$
57+
ErrorDialog.openError(null, Messages.getString("UNABLE_TO_LAUNCH"), ex.getLocalizedMessage(), //$NON-NLS-1$
5758
ex.getStatus());
5859
}
5960
}

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/Messages.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/messages.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/messages.properties

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,22 @@ PORT_OUT_OF_RANGE=Port must be between 0 and 65535.
77

88
CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION=The App Engine Standard runtime requires the Google Cloud SDK
99
CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE=App Engine Standard Runtime
10+
SERVICES_HAVE_SAME_ID="{0}" and "{1}" have same App Engine Service ID: {2}
1011
OPEN_CLOUD_SDK_PREFERENCE_BUTTON=Open the Cloud SDK Location preference page when the wizard closes
1112
RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND=Cannot find the Google Cloud SDK.
13+
14+
SERVER_STARTING_TEMPLATE=<starting...> {0}
15+
SERVER_STOPPING_TEMPLATE=<stopping...> {0}
16+
SERVER_STOPPED_TEMPLATE=<stopped> {0}
17+
18+
CANNOT_DETERMINE_EXECUTION_CONTEXT=Cannot determine server execution context
19+
NO_MODULE_FOUND_FOR=no module found for {0}
20+
SERVER_ALREADY_RUNNING=Server is already running
21+
SERVER_ALREADY_RUNNING_IN_MODE=Server is already running in "{0}" mode
22+
UNABLE_TO_LAUNCH=Unable to launch App Engine server
23+
24+
cloudsdk.not.configured=Could not run project because the Cloud SDK was not found. \
25+
Check Preferences > Google Cloud Tools > SDK location and try again.
26+
cloudsdk.out.of.date=Could not run project because the installed Cloud SDK is too old. \
27+
Run `gcloud components update` and try again.
28+

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerBehaviour.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import com.google.cloud.tools.eclipse.appengine.localserver.Activator;
2929
import com.google.cloud.tools.eclipse.appengine.localserver.Messages;
3030
import com.google.cloud.tools.eclipse.sdk.ui.MessageConsoleWriterOutputLineListener;
31+
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
3132
import com.google.common.annotations.VisibleForTesting;
3233
import java.io.File;
3334
import java.net.URI;
3435
import java.net.URISyntaxException;
35-
import java.text.MessageFormat;
3636
import java.util.ArrayList;
3737
import java.util.Collection;
3838
import java.util.List;
@@ -116,6 +116,16 @@ public void stop(boolean force) {
116116
}
117117
}
118118

119+
120+
@Override
121+
public IStatus canStop() {
122+
int serverState = getServer().getServerState();
123+
if (serverState == IServer.STATE_STARTED) {
124+
return Status.OK_STATUS;
125+
}
126+
return StatusUtil.error(this, "Not started");
127+
}
128+
119129
/**
120130
* Convenience method allowing access to protected method in superclass.
121131
*/
@@ -200,7 +210,7 @@ private static int checkPortAttribute(IServer server, PortProber portProber,
200210
String attribute, int defaultPort) throws CoreException {
201211
int port = server.getAttribute(attribute, defaultPort);
202212
if (port < 0 || port > 65535) {
203-
throw new CoreException(newErrorStatus(Messages.PORT_OUT_OF_RANGE));
213+
throw new CoreException(newErrorStatus(Messages.getString("PORT_OUT_OF_RANGE")));
204214
}
205215

206216
if (port != 0 && portProber.isPortInUse(port)) {
@@ -209,8 +219,8 @@ private static int checkPortAttribute(IServer server, PortProber portProber,
209219
logger.log(Level.INFO, attribute + ": port " + port + " in use. Picking an unused port.");
210220
port = 0;
211221
} else {
212-
throw new CoreException(newErrorStatus(
213-
MessageFormat.format(Messages.PORT_IN_USE, String.valueOf(port))));
222+
throw new CoreException(
223+
newErrorStatus(Messages.getString("PORT_IN_USE", String.valueOf(port))));
214224
}
215225
}
216226
return port;

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerDelegate.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.base.Function;
24-
import java.text.MessageFormat;
2524
import java.util.ArrayList;
2625
import java.util.HashMap;
2726
import java.util.List;
@@ -31,7 +30,6 @@
3130
import org.eclipse.core.runtime.IStatus;
3231
import org.eclipse.core.runtime.Status;
3332
import org.eclipse.jst.server.core.IWebModule;
34-
import org.eclipse.osgi.util.NLS;
3533
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
3634
import org.eclipse.wst.server.core.IModule;
3735
import org.eclipse.wst.server.core.IModuleType;
@@ -42,9 +40,9 @@
4240
@SuppressWarnings("restriction") // For FacetUtil
4341
public class LocalAppEngineServerDelegate extends ServerDelegate {
4442
public static final String RUNTIME_TYPE_ID =
45-
"com.google.cloud.tools.eclipse.appengine.standard.runtime";
43+
"com.google.cloud.tools.eclipse.appengine.standard.runtime"; //$NON-NLS-1$
4644
public static final String SERVER_TYPE_ID =
47-
"com.google.cloud.tools.eclipse.appengine.standard.server";
45+
"com.google.cloud.tools.eclipse.appengine.standard.server"; //$NON-NLS-1$
4846

4947
private static final IModule[] EMPTY_MODULES = new IModule[0];
5048
private static final String SERVLET_MODULE_FACET = "jst.web"; //$NON-NLS-1$
@@ -124,8 +122,7 @@ IStatus checkConflictingServiceIds(IModule[] current, IModule[] toBeAdded,
124122
if (currentServiceIds.containsKey(moduleServiceId)) {
125123
// uh oh, we have a conflict within the already-defined modules
126124
return StatusUtil.error(LocalAppEngineServerDebugTarget.class,
127-
MessageFormat.format(
128-
"\"{0}\" and \"{1}\" have same App Engine Service ID: {2}",
125+
Messages.getString("SERVICES_HAVE_SAME_ID", //$NON-NLS-1$
129126
currentServiceIds.get(moduleServiceId).getName(), module.getName(),
130127
moduleServiceId));
131128
}
@@ -147,8 +144,7 @@ IStatus checkConflictingServiceIds(IModule[] current, IModule[] toBeAdded,
147144
String moduleServiceId = serviceIdFunction.apply(module);
148145
if (currentServiceIds.containsKey(moduleServiceId)) {
149146
return StatusUtil.error(LocalAppEngineServerDebugTarget.class,
150-
MessageFormat.format(
151-
"\"{0}\" and \"{1}\" have same App Engine Service ID: {2}",
147+
Messages.getString("SERVICES_HAVE_SAME_ID", //$NON-NLS-1$
152148
currentServiceIds.get(moduleServiceId).getName(), module.getName(),
153149
moduleServiceId));
154150
}
@@ -163,14 +159,13 @@ private static IStatus hasAppEngineStandardFacet(IModule module) {
163159
if (AppEngineStandardFacet.hasAppEngineFacet(ProjectFacetsManager.create(module.getProject()))) {
164160
return Status.OK_STATUS;
165161
} else {
166-
String errorMessage = NLS.bind(Messages.GAE_STANDARD_FACET_MISSING, module.getName(),
162+
String errorMessage = Messages.getString("GAE_STANDARD_FACET_MISSING", module.getName(), //$NON-NLS-1$
167163
module.getProject().getName());
168164
return StatusUtil.error(LocalAppEngineServerDelegate.class, errorMessage);
169165
}
170166
} catch (CoreException ex) {
171167
return StatusUtil.error(LocalAppEngineServerDelegate.class,
172-
NLS.bind(Messages.NOT_FACETED_PROJECT, module.getProject().getName()),
173-
ex);
168+
Messages.getString("NOT_FACETED_PROJECT", module.getProject().getName()), ex); //$NON-NLS-1$
174169
}
175170
}
176171

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.cloud.tools.appengine.cloudsdk.CloudSdk;
2121
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkOutOfDateException;
2222
import com.google.cloud.tools.eclipse.appengine.localserver.Activator;
23+
import com.google.cloud.tools.eclipse.appengine.localserver.Messages;
2324
import com.google.cloud.tools.eclipse.appengine.localserver.PreferencesInitializer;
2425
import com.google.cloud.tools.eclipse.appengine.localserver.ui.LocalAppEngineConsole;
2526
import com.google.cloud.tools.eclipse.ui.util.MessageConsoleUtilities;

0 commit comments

Comments
 (0)