From a0c585ec1070e74ef561b857ea2c5a05ef6cfc53 Mon Sep 17 00:00:00 2001 From: Brian de Alwis Date: Mon, 19 Dec 2016 13:12:22 -0500 Subject: [PATCH] Reflect local App Engine server state in console (#1145) --- .../localserver/server/MessagesTest.java | 1 + .../appengine/localserver/Messages.java | 36 +++++------ .../localserver/launching/LaunchHelper.java | 14 +++-- .../LocalAppEngineStandardLaunchShortcut.java | 5 +- .../localserver/launching/Messages.java | 41 ------------- .../localserver/launching/messages.properties | 1 - .../appengine/localserver/messages.properties | 17 ++++++ .../server/LocalAppEngineServerBehaviour.java | 18 ++++-- .../server/LocalAppEngineServerDelegate.java | 17 ++---- ...gineServerLaunchConfigurationDelegate.java | 1 + .../localserver/server/Messages.java | 47 -------------- .../localserver/server/messages.properties | 5 -- .../localserver/ui/LocalAppEngineConsole.java | 61 ++++++++++++++++++- .../LocalAppEngineConsolePageParticipant.java | 19 +++++- .../LocalAppEngineServerWizardFragment.java | 8 +-- .../localserver/ui/ServerPortExtension.java | 6 +- .../DebugNativeAppEngineStandardProject.java | 7 +++ 17 files changed, 160 insertions(+), 144 deletions(-) delete mode 100644 plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/Messages.java delete mode 100644 plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/messages.properties delete mode 100644 plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/Messages.java delete mode 100644 plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/messages.properties diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/server/MessagesTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/server/MessagesTest.java index a0480b9192..546f973b38 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/server/MessagesTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/server/MessagesTest.java @@ -16,6 +16,7 @@ package com.google.cloud.tools.eclipse.appengine.localserver.server; +import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import org.junit.Assert; import org.junit.Test; diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/Messages.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/Messages.java index 592ca4fa88..e4847d9152 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/Messages.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/Messages.java @@ -16,29 +16,31 @@ package com.google.cloud.tools.eclipse.appengine.localserver; -import org.eclipse.osgi.util.NLS; +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; -public class Messages extends NLS { +public class Messages { private static final String BUNDLE_NAME = "com.google.cloud.tools.eclipse.appengine.localserver.messages"; //$NON-NLS-1$ - public static String NOT_FACETED_PROJECT; - public static String GAE_STANDARD_FACET_MISSING; - public static String NEW_SERVER_DIALOG_PORT; - public static String NEW_SERVER_DIALOG_INVALID_PORT_VALUE; - public static String PORT_IN_USE; - public static String PORT_OUT_OF_RANGE; + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - public static String CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION; - public static String CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE; - public static String OPEN_CLOUD_SDK_PREFERENCE_BUTTON; - public static String RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } } - private Messages() { + public static String getString(String key, Object... params) { + try { + return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params); + } catch (MissingResourceException ex) { + return '!' + key + '!'; + } } + + private Messages() {} } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LaunchHelper.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LaunchHelper.java index c84a1dbaaf..f28fba2c89 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LaunchHelper.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LaunchHelper.java @@ -16,6 +16,7 @@ package com.google.cloud.tools.eclipse.appengine.localserver.launching; +import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import com.google.cloud.tools.eclipse.appengine.localserver.server.LocalAppEngineServerDelegate; import com.google.cloud.tools.eclipse.util.AdapterUtil; import com.google.cloud.tools.eclipse.util.status.StatusUtil; @@ -58,9 +59,9 @@ public void launch(IModule[] modules, String launchMode) throws CoreException { for (IServer existing : servers) { if (isRunning(existing)) { ILaunch launch = existing.getLaunch(); - Preconditions.checkNotNull(launch, "Running server should have a launch"); - String detail = launchMode.equals(launch.getLaunchMode()) ? "Server is already running" - : MessageFormat.format("Server is already running in \"{0}\" mode", + Preconditions.checkNotNull(launch, Messages.getString("RUNNING_SERVER_SHOULD_HAVE_A_LAUNCH")); //$NON-NLS-1$ + String detail = launchMode.equals(launch.getLaunchMode()) ? Messages.getString("SERVER_ALREADY_RUNNING") //$NON-NLS-1$ + : MessageFormat.format(Messages.getString("SERVER_ALREADY_RUNNING_IN_MODE"), //$NON-NLS-1$ launch.getLaunchMode()); throw new CoreException(StatusUtil.info(this, detail)); } @@ -138,7 +139,7 @@ public IModule[] asModules(ISelection selection) throws CoreException { } return modules.toArray(new IModule[modules.size()]); } - throw new CoreException(StatusUtil.error(this, "Cannot determine server execution context")); + throw new CoreException(StatusUtil.error(this, Messages.getString("CANNOT_DETERMINE_EXECUTION_CONTEXT"))); //$NON-NLS-1$ } /** Check the project of the active editor. */ @@ -150,7 +151,7 @@ public IModule[] asModules(IEditorPart editor) throws CoreException { return new IModule[] {asModule(project)}; } } - throw new CoreException(StatusUtil.error(this, "Cannot determine server execution context")); + throw new CoreException(StatusUtil.error(this, Messages.getString("CANNOT_DETERMINE_EXECUTION_CONTEXT"))); //$NON-NLS-1$ } private IModule asModule(Object object) throws CoreException { @@ -165,7 +166,8 @@ private IModule asModule(Object object) throws CoreException { return module; } } - throw new CoreException(StatusUtil.error(this, "no module found for " + object)); + throw new CoreException( + StatusUtil.error(this, Messages.getString("NO_MODULE_FOUND_FOR", object))); //$NON-NLS-1$ } } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LocalAppEngineStandardLaunchShortcut.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LocalAppEngineStandardLaunchShortcut.java index 3af1b363cf..a385b709d4 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LocalAppEngineStandardLaunchShortcut.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/LocalAppEngineStandardLaunchShortcut.java @@ -16,6 +16,7 @@ package com.google.cloud.tools.eclipse.appengine.localserver.launching; +import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import java.util.ArrayList; import java.util.Collection; import org.eclipse.core.resources.IResource; @@ -42,7 +43,7 @@ public void launch(ISelection selection, String launchMode) { IModule[] modules = launcher.asModules(selection); launcher.launch(modules, launchMode); } catch (CoreException ex) { - ErrorDialog.openError(null, Messages.getString("UnableToLaunch"), ex.getLocalizedMessage(), //$NON-NLS-1$ + ErrorDialog.openError(null, Messages.getString("UNABLE_TO_LAUNCH"), ex.getLocalizedMessage(), //$NON-NLS-1$ ex.getStatus()); } } @@ -53,7 +54,7 @@ public void launch(IEditorPart editor, String launchMode) { IModule[] modules = launcher.asModules(editor); launcher.launch(modules, launchMode); } catch (CoreException ex) { - ErrorDialog.openError(null, Messages.getString("UnableToLaunch"), ex.getLocalizedMessage(), //$NON-NLS-1$ + ErrorDialog.openError(null, Messages.getString("UNABLE_TO_LAUNCH"), ex.getLocalizedMessage(), //$NON-NLS-1$ ex.getStatus()); } } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/Messages.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/Messages.java deleted file mode 100644 index aeac280312..0000000000 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/Messages.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.tools.eclipse.appengine.localserver.launching; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * @author bsd - * - */ -public class Messages { - private static final String BUNDLE_NAME = - "com.google.cloud.tools.eclipse.appengine.localserver.launching.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - - private Messages() {} - - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/messages.properties b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/messages.properties deleted file mode 100644 index 2ff3ff2a39..0000000000 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/launching/messages.properties +++ /dev/null @@ -1 +0,0 @@ -UnableToLaunch=Unable to launch App Engine server diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/messages.properties b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/messages.properties index 60d28c737f..a32d9927bc 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/messages.properties +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/messages.properties @@ -7,5 +7,22 @@ PORT_OUT_OF_RANGE=Port must be between 0 and 65535. CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION=The App Engine Standard runtime requires the Google Cloud SDK CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE=App Engine Standard Runtime +SERVICES_HAVE_SAME_ID="{0}" and "{1}" have same App Engine Service ID: {2} OPEN_CLOUD_SDK_PREFERENCE_BUTTON=Open the Cloud SDK Location preference page when the wizard closes RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND=Cannot find the Google Cloud SDK. + +SERVER_STARTING_TEMPLATE= {0} +SERVER_STOPPING_TEMPLATE= {0} +SERVER_STOPPED_TEMPLATE= {0} + +CANNOT_DETERMINE_EXECUTION_CONTEXT=Cannot determine server execution context +NO_MODULE_FOUND_FOR=no module found for {0} +SERVER_ALREADY_RUNNING=Server is already running +SERVER_ALREADY_RUNNING_IN_MODE=Server is already running in "{0}" mode +UNABLE_TO_LAUNCH=Unable to launch App Engine server + +cloudsdk.not.configured=Could not run project because the Cloud SDK was not found. \ + Check Preferences > Google Cloud Tools > SDK location and try again. +cloudsdk.out.of.date=Could not run project because the installed Cloud SDK is too old. \ + Run `gcloud components update` and try again. + \ No newline at end of file diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerBehaviour.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerBehaviour.java index 3dca3c6c8a..0709ba1fd8 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerBehaviour.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerBehaviour.java @@ -28,11 +28,11 @@ import com.google.cloud.tools.eclipse.appengine.localserver.Activator; import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import com.google.cloud.tools.eclipse.sdk.ui.MessageConsoleWriterOutputLineListener; +import com.google.cloud.tools.eclipse.util.status.StatusUtil; import com.google.common.annotations.VisibleForTesting; import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -116,6 +116,16 @@ public void stop(boolean force) { } } + + @Override + public IStatus canStop() { + int serverState = getServer().getServerState(); + if (serverState == IServer.STATE_STARTED) { + return Status.OK_STATUS; + } + return StatusUtil.error(this, "Not started"); + } + /** * Convenience method allowing access to protected method in superclass. */ @@ -200,7 +210,7 @@ private static int checkPortAttribute(IServer server, PortProber portProber, String attribute, int defaultPort) throws CoreException { int port = server.getAttribute(attribute, defaultPort); if (port < 0 || port > 65535) { - throw new CoreException(newErrorStatus(Messages.PORT_OUT_OF_RANGE)); + throw new CoreException(newErrorStatus(Messages.getString("PORT_OUT_OF_RANGE"))); } if (port != 0 && portProber.isPortInUse(port)) { @@ -209,8 +219,8 @@ private static int checkPortAttribute(IServer server, PortProber portProber, logger.log(Level.INFO, attribute + ": port " + port + " in use. Picking an unused port."); port = 0; } else { - throw new CoreException(newErrorStatus( - MessageFormat.format(Messages.PORT_IN_USE, String.valueOf(port)))); + throw new CoreException( + newErrorStatus(Messages.getString("PORT_IN_USE", String.valueOf(port)))); } } return port; diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerDelegate.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerDelegate.java index bee83e4a01..8b9adee618 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerDelegate.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerDelegate.java @@ -21,7 +21,6 @@ import com.google.cloud.tools.eclipse.util.status.StatusUtil; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -31,7 +30,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jst.server.core.IWebModule; -import org.eclipse.osgi.util.NLS; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; import org.eclipse.wst.server.core.IModule; import org.eclipse.wst.server.core.IModuleType; @@ -42,9 +40,9 @@ @SuppressWarnings("restriction") // For FacetUtil public class LocalAppEngineServerDelegate extends ServerDelegate { public static final String RUNTIME_TYPE_ID = - "com.google.cloud.tools.eclipse.appengine.standard.runtime"; + "com.google.cloud.tools.eclipse.appengine.standard.runtime"; //$NON-NLS-1$ public static final String SERVER_TYPE_ID = - "com.google.cloud.tools.eclipse.appengine.standard.server"; + "com.google.cloud.tools.eclipse.appengine.standard.server"; //$NON-NLS-1$ private static final IModule[] EMPTY_MODULES = new IModule[0]; private static final String SERVLET_MODULE_FACET = "jst.web"; //$NON-NLS-1$ @@ -124,8 +122,7 @@ IStatus checkConflictingServiceIds(IModule[] current, IModule[] toBeAdded, if (currentServiceIds.containsKey(moduleServiceId)) { // uh oh, we have a conflict within the already-defined modules return StatusUtil.error(LocalAppEngineServerDebugTarget.class, - MessageFormat.format( - "\"{0}\" and \"{1}\" have same App Engine Service ID: {2}", + Messages.getString("SERVICES_HAVE_SAME_ID", //$NON-NLS-1$ currentServiceIds.get(moduleServiceId).getName(), module.getName(), moduleServiceId)); } @@ -147,8 +144,7 @@ IStatus checkConflictingServiceIds(IModule[] current, IModule[] toBeAdded, String moduleServiceId = serviceIdFunction.apply(module); if (currentServiceIds.containsKey(moduleServiceId)) { return StatusUtil.error(LocalAppEngineServerDebugTarget.class, - MessageFormat.format( - "\"{0}\" and \"{1}\" have same App Engine Service ID: {2}", + Messages.getString("SERVICES_HAVE_SAME_ID", //$NON-NLS-1$ currentServiceIds.get(moduleServiceId).getName(), module.getName(), moduleServiceId)); } @@ -163,14 +159,13 @@ private static IStatus hasAppEngineStandardFacet(IModule module) { if (AppEngineStandardFacet.hasAppEngineFacet(ProjectFacetsManager.create(module.getProject()))) { return Status.OK_STATUS; } else { - String errorMessage = NLS.bind(Messages.GAE_STANDARD_FACET_MISSING, module.getName(), + String errorMessage = Messages.getString("GAE_STANDARD_FACET_MISSING", module.getName(), //$NON-NLS-1$ module.getProject().getName()); return StatusUtil.error(LocalAppEngineServerDelegate.class, errorMessage); } } catch (CoreException ex) { return StatusUtil.error(LocalAppEngineServerDelegate.class, - NLS.bind(Messages.NOT_FACETED_PROJECT, module.getProject().getName()), - ex); + Messages.getString("NOT_FACETED_PROJECT", module.getProject().getName()), ex); //$NON-NLS-1$ } } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java index 9fc9c53ad5..910889286b 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java @@ -20,6 +20,7 @@ import com.google.cloud.tools.appengine.cloudsdk.CloudSdk; import com.google.cloud.tools.appengine.cloudsdk.CloudSdkOutOfDateException; import com.google.cloud.tools.eclipse.appengine.localserver.Activator; +import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import com.google.cloud.tools.eclipse.appengine.localserver.PreferencesInitializer; import com.google.cloud.tools.eclipse.appengine.localserver.ui.LocalAppEngineConsole; import com.google.cloud.tools.eclipse.ui.util.MessageConsoleUtilities; diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/Messages.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/Messages.java deleted file mode 100644 index c814fbe010..0000000000 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/Messages.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.tools.eclipse.appengine.localserver.server; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class Messages { - private static final String BUNDLE_NAME = - "com.google.cloud.tools.eclipse.appengine.localserver.server.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - - private Messages() { - } - - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - public static String getString(String key, Object... params) { - try { - return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params); - } catch (MissingResourceException ex) { - return '!' + key + '!'; - } - } -} diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/messages.properties b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/messages.properties deleted file mode 100644 index c80694cb89..0000000000 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/messages.properties +++ /dev/null @@ -1,5 +0,0 @@ -cloudsdk.not.configured=Could not run project because the Cloud SDK was not found. \ - Check Preferences > Google Cloud Tools > SDK location and try again. -cloudsdk.out.of.date=Could not run project because the installed Cloud SDK is too old. \ - Run `gcloud components update` and try again. - \ No newline at end of file diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsole.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsole.java index 161c8e16ed..64276536fa 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsole.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsole.java @@ -16,26 +16,83 @@ package com.google.cloud.tools.eclipse.appengine.localserver.ui; -import org.eclipse.ui.console.MessageConsole; - +import com.google.cloud.tools.eclipse.appengine.localserver.Messages; import com.google.cloud.tools.eclipse.appengine.localserver.server.LocalAppEngineServerBehaviour; import com.google.cloud.tools.eclipse.ui.util.MessageConsoleUtilities.ConsoleFactory; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.progress.UIJob; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.IServerListener; +import org.eclipse.wst.server.core.ServerEvent; /** * A console that displays information for a run/debug session of the App Engine runtime */ public class LocalAppEngineConsole extends MessageConsole { private LocalAppEngineServerBehaviour serverBehaviour; + private String unprefixedName; + private IServerListener serverStateListener = new IServerListener() { + @Override + public void serverChanged(ServerEvent event) { + updateName(event.getState()); + } + }; public LocalAppEngineConsole(String name, LocalAppEngineServerBehaviour serverBehaviour) { super(name, null); + this.unprefixedName = name; this.serverBehaviour = serverBehaviour; } + /** + * Update the shown name with the server stop/stopping state. + */ + protected void updateName(int state) { + final String computedName; + if (state == IServer.STATE_STARTING) { + computedName = + Messages.getString("SERVER_STARTING_TEMPLATE", unprefixedName); + } else if (state == IServer.STATE_STOPPING) { + computedName = + Messages.getString("SERVER_STOPPING_TEMPLATE", unprefixedName); + } else if (state == IServer.STATE_STOPPED) { + computedName = + Messages.getString("SERVER_STOPPED_TEMPLATE", unprefixedName); + } else { + computedName = unprefixedName; + } + UIJob nameUpdateJob = new UIJob("Update server name") { + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + LocalAppEngineConsole.this.setName(computedName); + return Status.OK_STATUS; + } + }; + nameUpdateJob.setSystem(true); + nameUpdateJob.schedule(); + } + public LocalAppEngineServerBehaviour getServerBehaviourDelegate() { return serverBehaviour; } + @Override + protected void init() { + super.init(); + serverBehaviour.getServer().addServerListener(serverStateListener); + } + + @Override + protected void dispose() { + serverBehaviour.getServer().removeServerListener(serverStateListener); + super.dispose(); + } + + + public static class Factory implements ConsoleFactory { private LocalAppEngineServerBehaviour serverBehaviour; diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsolePageParticipant.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsolePageParticipant.java index d1bb4f7320..be2db81ad3 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsolePageParticipant.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineConsolePageParticipant.java @@ -17,7 +17,6 @@ package com.google.cloud.tools.eclipse.appengine.localserver.ui; import com.google.cloud.tools.eclipse.appengine.localserver.server.LocalAppEngineServerBehaviour; - import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; @@ -27,6 +26,8 @@ import org.eclipse.ui.console.IConsolePageParticipant; import org.eclipse.ui.part.IPageBookViewPage; import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.IServerListener; +import org.eclipse.wst.server.core.ServerEvent; import org.eclipse.wst.server.ui.internal.ImageResource; import org.eclipse.wst.server.ui.internal.Messages; @@ -37,6 +38,12 @@ public class LocalAppEngineConsolePageParticipant implements IConsolePageParticipant { private LocalAppEngineConsole console; private Action terminateAction; + private IServerListener serverStateListener = new IServerListener() { + @Override + public void serverChanged(ServerEvent event) { + update(); + } + }; @Override public T getAdapter(Class required) { @@ -50,10 +57,19 @@ public void init(IPageBookViewPage page, IConsole console) { // contribute to toolbar IActionBars actionBars = page.getSite().getActionBars(); configureToolBar(actionBars.getToolBarManager()); + + LocalAppEngineServerBehaviour serverBehaviour = this.console.getServerBehaviourDelegate(); + if (serverBehaviour != null) { + serverBehaviour.getServer().addServerListener(serverStateListener); + } } @Override public void dispose() { + LocalAppEngineServerBehaviour serverBehaviour = console.getServerBehaviourDelegate(); + if (serverBehaviour != null) { + serverBehaviour.getServer().removeServerListener(serverStateListener); + } terminateAction = null; } @@ -93,6 +109,7 @@ private void update() { if (terminateAction != null) { LocalAppEngineServerBehaviour serverBehaviour = console.getServerBehaviourDelegate(); if (serverBehaviour != null) { + // it's ok for us to call #canStop() since it's our implementation IStatus status = serverBehaviour.canStop(); terminateAction.setEnabled(status.isOK()); } diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineServerWizardFragment.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineServerWizardFragment.java index f2a198c88c..2e5312519f 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineServerWizardFragment.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/LocalAppEngineServerWizardFragment.java @@ -51,8 +51,8 @@ public boolean isComplete() { @Override public Composite createComposite(Composite parent, IWizardHandle wizard) { - wizard.setTitle(Messages.CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE); - wizard.setDescription(Messages.CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION); + wizard.setTitle(Messages.getString("CREATE_APP_ENGINE_RUNTIME_WIZARD_TITLE")); + wizard.setDescription(Messages.getString("CREATE_APP_ENGINE_RUNTIME_WIZARD_DESCRIPTION")); Composite cloudSdkComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -60,9 +60,9 @@ public Composite createComposite(Composite parent, IWizardHandle wizard) { cloudSdkComposite.setLayout(layout); Label label = new Label(cloudSdkComposite, SWT.NONE); - label.setText(Messages.RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND); + label.setText(Messages.getString("RUNTIME_WIZARD_CLOUD_SDK_NOT_FOUND")); cloudSdkButton = new Button(cloudSdkComposite, SWT.CHECK); - cloudSdkButton.setText(Messages.OPEN_CLOUD_SDK_PREFERENCE_BUTTON); + cloudSdkButton.setText(Messages.getString("OPEN_CLOUD_SDK_PREFERENCE_BUTTON")); cloudSdkButton.addSelectionListener(new CloudSdkButtonListener()); parent.addDisposeListener(new OpenPreferencePage()); diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/ServerPortExtension.java b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/ServerPortExtension.java index c0d45a22b4..28eff08d46 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/ServerPortExtension.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/ServerPortExtension.java @@ -49,7 +49,7 @@ public void createControl(UI_POSITION position, Composite parent) { if (position == UI_POSITION.BOTTOM) { portLabel = new Label(parent, SWT.NONE); portLabel.setVisible(false); - portLabel.setText(Messages.NEW_SERVER_DIALOG_PORT); + portLabel.setText(Messages.getString("NEW_SERVER_DIALOG_PORT")); portText = new Text(parent, SWT.SINGLE | SWT.BORDER); portText.setVisible(false); @@ -61,7 +61,7 @@ public void createControl(UI_POSITION position, Composite parent) { Image errorImage = registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage(); portDecoration = new ControlDecoration(portText, SWT.LEFT | SWT.TOP); - portDecoration.setDescriptionText(Messages.NEW_SERVER_DIALOG_INVALID_PORT_VALUE); + portDecoration.setDescriptionText(Messages.getString("NEW_SERVER_DIALOG_INVALID_PORT_VALUE")); portDecoration.setImage(errorImage); portDecoration.hide(); } @@ -107,7 +107,7 @@ private boolean updatePortAndTriggerDecoration(String newPortString) { portDecoration.hide(); } else { portDecoration.show(); - portDecoration.showHoverText(Messages.NEW_SERVER_DIALOG_INVALID_PORT_VALUE); + portDecoration.showHoverText(Messages.getString("NEW_SERVER_DIALOG_INVALID_PORT_VALUE")); } serverWc.setAttribute(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME, port); diff --git a/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DebugNativeAppEngineStandardProject.java b/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DebugNativeAppEngineStandardProject.java index e09346e588..ce79638dbc 100644 --- a/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DebugNativeAppEngineStandardProject.java +++ b/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DebugNativeAppEngineStandardProject.java @@ -18,6 +18,7 @@ import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -109,13 +110,19 @@ public void run() { assertEquals("Hello App Engine!", getUrlContents(new URL("http://localhost:8080/hello"), (int) SWTBotPreferences.TIMEOUT)); + SWTBotToolbarButton stopServerButton = null; for (SWTBotToolbarButton button : consoleView.getToolbarButtons()) { if ("Stop the server".equals(button.getToolTipText())) { + stopServerButton = button; button.click(); } } + assertNotNull(stopServerButton); SwtBotTreeUtilities.waitUntilTreeContainsText(bot, allItems[0], ""); assertNoService(new URL("http://localhost:8080/hello")); + assertTrue("App Engine console should mark as stopped", + consoleView.getViewReference().getContentDescription().startsWith("")); + assertFalse("Stop Server button should be disabled", stopServerButton.isEnabled()); } /**