Skip to content

Commit

Permalink
Reflect local App Engine server state in console (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis authored Dec 19, 2016
1 parent 28f32d8 commit a0c585e
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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. */
Expand All @@ -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 {
Expand All @@ -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$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Expand All @@ -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());
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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=<starting...> {0}
SERVER_STOPPING_TEMPLATE=<stopping...> {0}
SERVER_STOPPED_TEMPLATE=<stopped> {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.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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$
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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$
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit a0c585e

Please sign in to comment.