Skip to content

Commit

Permalink
Add more launch configuration tabs (#1139)
Browse files Browse the repository at this point in the history
* more launch config tabs

* remove classpath and sourcepath tabs

* pass environment variables into server behavior delegate

* wip

* reset wizard page

* remove environment variables; they don't get passed to the server

* fix compile

* pass along JVM flags from eclipse UI

* program and JVM args are different

* not sure what to do with program arguments yet
  • Loading branch information
elharo authored Jan 5, 2017
1 parent 514cf8a commit 80d7b12
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 26 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.ui;

import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -25,8 +26,11 @@ public class AppEngineTabGroupTest {
public void testCreateTabs() {
AppEngineTabGroup group = new AppEngineTabGroup();
group.createTabs(null, "");
for (ILaunchConfigurationTab tab : group.getTabs()) {
Assert.assertNotNull(tab);
}
Assert.assertEquals("Server", group.getTabs()[0].getName());
Assert.assertEquals("Environment", group.getTabs()[1].getName());
Assert.assertEquals("Arguments", group.getTabs()[1].getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Bundle-Activator: com.google.cloud.tools.eclipse.appengine.localserver.Activator
Bundle-ActivationPolicy: lazy
Require-Bundle: com.google.cloud.tools.appengine;bundle-version="0.2.5",
com.google.cloud.tools.eclipse.appengine.ui;bundle-version="0.1.0",
com.google.guava;bundle-version="20.0.0",
javax.servlet;bundle-version="2.5.0",
javax.servlet.jsp;bundle-version="2.1.0",
org.eclipse.wst.server.core;bundle-version="1.7.0",
org.eclipse.wst.server.ui;bundle-version="1.5.201",
org.eclipse.wst.common.project.facet.core;bundle-version="1.4.300",
Expand All @@ -20,21 +23,16 @@ Require-Bundle: com.google.cloud.tools.appengine;bundle-version="0.2.5",
org.eclipse.jst.server.generic.ui;bundle-version="1.0.600",
org.eclipse.jst.common.project.facet.core;bundle-version="1.4.400",
org.eclipse.jst.common.project.facet.ui;bundle-version="1.4.510",
javax.servlet;bundle-version="2.5.0",
javax.servlet.jsp;bundle-version="2.1.0",
org.eclipse.core.resources;bundle-version="3.10.1",
org.eclipse.debug.core;bundle-version="3.10.0",
com.google.guava;bundle-version="20.0.0",
org.eclipse.debug.ui;bundle-version="3.11.101",
org.eclipse.core.expressions;bundle-version="3.5.0",
org.eclipse.m2e.core;bundle-version="1.6.2",
org.eclipse.m2e.maven.runtime;bundle-version="1.6.2",
org.eclipse.m2e.wtp;bundle-version="1.2.1",
org.eclipse.m2e.jdt;bundle-version="1.6.2",
org.eclipse.ui.console;bundle-version="3.6.100",
org.eclipse.ui.ide;bundle-version="3.11.0",
org.eclipse.jdt.core,
org.eclipse.swt
org.eclipse.ui.ide;bundle-version="3.11.0"
Export-Package: com.google.cloud.tools.eclipse.appengine.localserver.server
Import-Package: com.google.cloud.tools.eclipse.appengine.facets,
com.google.cloud.tools.eclipse.appengine.libraries.model,
Expand All @@ -51,4 +49,9 @@ Import-Package: com.google.cloud.tools.eclipse.appengine.facets,
com.google.cloud.tools.eclipse.util.service,
com.google.cloud.tools.eclipse.util.status,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di
org.eclipse.e4.core.di,
org.eclipse.jdt.core,
org.eclipse.jdt.debug.ui.launchConfigurations,
org.eclipse.swt


Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,14 @@ public int getServerPort() {
/**
* Starts the development server.
*
* @param runnables the path to directories that contain configuration files like appengine-web.xml
* @param runnables the path to directories that contain configuration files such as
* appengine-web.xml
* @param console the stream (Eclipse console) to send development server process output to
* @param arguments JVM arguments to pass to the dev server
*/
void startDevServer(List<File> runnables, MessageConsoleStream console) throws CoreException {
void startDevServer(List<File> runnables, MessageConsoleStream console, List<String> vmArguments)
throws CoreException {

checkAndSetPorts(); // Must be called before setting the STARTING state.
setServerState(IServer.STATE_STARTING);

Expand All @@ -263,6 +267,7 @@ void startDevServer(List<File> runnables, MessageConsoleStream console) throws C
devServerRunConfiguration.setHost(getServer().getHost());
devServerRunConfiguration.setPort(serverPort);
devServerRunConfiguration.setAdminPort(adminPort);
devServerRunConfiguration.setJvmFlags(vmArguments);

// Run server
try {
Expand All @@ -276,18 +281,21 @@ void startDevServer(List<File> runnables, MessageConsoleStream console) throws C
/**
* Starts the development server in debug mode.
*
* @param runnables the path to directories that contain configuration files like appengine-web.xml
* @param runnables the path to directories that contain configuration files like
* appengine-web.xml
* @param console the stream (Eclipse console) to send development server process output to
* @param debugPort the port to attach a debugger to if launch is in debug mode
* @param arguments JVM arguments to pass to the dev server
*/
void startDebugDevServer(List<File> runnables, MessageConsoleStream console, int debugPort)
void startDebugDevServer(List<File> runnables, MessageConsoleStream console, int debugPort,
List<String> vmArguments)
throws CoreException {
checkAndSetPorts(); // Must be called before setting the STARTING state.
setServerState(IServer.STATE_STARTING);

// Create dev app server instance
initializeDevServer(console);

// Create run configuration
DefaultRunConfiguration devServerRunConfiguration = new DefaultRunConfiguration();
devServerRunConfiguration.setAutomaticRestart(false);
Expand All @@ -302,12 +310,15 @@ void startDebugDevServer(List<File> runnables, MessageConsoleStream console, int

List<String> jvmFlags = new ArrayList<String>();

// todo only real difference between this method and startDevServer are these two extra
// JVM flags. Just set them and call startDevServer
if (debugPort <= 0 || debugPort > 65535) {
throw new IllegalArgumentException("Debug port is set to " + debugPort //$NON-NLS-1$
+ ", should be between 1-65535"); //$NON-NLS-1$
}
jvmFlags.add("-Xdebug"); //$NON-NLS-1$
jvmFlags.add("-Xrunjdwp:transport=dt_socket,server=n,suspend=y,quiet=y,address=" + debugPort); //$NON-NLS-1$
jvmFlags.addAll(vmArguments);
devServerRunConfiguration.setJvmFlags(jvmFlags);

// Run server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -82,10 +83,10 @@ private static void validateCloudSdk() throws CoreException {
CloudSdk cloudSdk = new CloudSdk.Builder().build();
cloudSdk.validateCloudSdk();
} catch (CloudSdkOutOfDateException ex) {
String detailMessage = Messages.getString("cloudsdk.out.of.date");
Status status = new Status(IStatus.ERROR,
"com.google.cloud.tools.eclipse.appengine.deploy.ui", detailMessage);
throw new CoreException(status);
String detailMessage = Messages.getString("cloudsdk.out.of.date");
Status status = new Status(IStatus.ERROR,
"com.google.cloud.tools.eclipse.appengine.deploy.ui", detailMessage);
throw new CoreException(status);
} catch (AppEngineException ex) {
String detailMessage = Messages.getString("cloudsdk.not.configured"); //$NON-NLS-1$
Status status = new Status(IStatus.ERROR,
Expand All @@ -101,7 +102,7 @@ public void launch(ILaunchConfiguration configuration, String mode, final ILaunc
AnalyticsEvents.APP_ENGINE_LOCAL_SERVER_MODE, mode);

validateCloudSdk();

IServer server = ServerUtil.getServer(configuration);
if (server == null) {
String message = "There is no App Engine development server available";
Expand Down Expand Up @@ -136,14 +137,18 @@ public void launch(ILaunchConfiguration configuration, String mode, final ILaunc

new ServerLaunchMonitor(launch, server).engage();

String vmArgumentString = getVMArguments(configuration);
// This string is exactly as supplied by the user in the dialog box

List<String> vmArguments = Arrays.asList(vmArgumentString.split("\\s+"));
if (ILaunchManager.DEBUG_MODE.equals(mode)) {
int debugPort = getDebugPort();
setupDebugTarget(launch, debugPort, monitor);
serverBehaviour.startDebugDevServer(runnables, console.newMessageStream(), debugPort);
serverBehaviour.startDebugDevServer(runnables, console.newMessageStream(), debugPort, vmArguments);
} else {
// A launch must have at least one debug target or process, or it otherwise becomes a zombie
LocalAppEngineServerDebugTarget.addTarget(launch, serverBehaviour);
serverBehaviour.startDevServer(runnables, console.newMessageStream());
serverBehaviour.startDevServer(runnables, console.newMessageStream(), vmArguments);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@

import com.google.cloud.tools.eclipse.appengine.localserver.server.LocalAppEngineServerDelegate;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.EnvironmentTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.wst.server.ui.ServerLaunchConfigurationTab;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;

/**
* Tabs shown in launch configurations for an App Engine Server.
* To get to these in the UI:
*
* 1. Open Servers view
* 2. Right click on the server to configure
* 3. Open
* 4. Open Launch Configuration
*/
public class AppEngineTabGroup extends AbstractLaunchConfigurationTabGroup {

private static final String[] SERVER_TYPE_IDS = {LocalAppEngineServerDelegate.SERVER_TYPE_ID};
Expand All @@ -33,13 +42,9 @@ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[2];
tabs[0] = new AppEngineServerLaunchConfigurationTab(SERVER_TYPE_IDS);
tabs[0].setLaunchConfigurationDialog(dialog);
tabs[1] = new EnvironmentTab();
tabs[1] = new JavaArgumentsTab();
tabs[1].setLaunchConfigurationDialog(dialog);

// see
// http://git.eclipse.org/c/jetty/org.eclipse.jetty.wtp.git/tree/org.eclipse.jst.server.jetty.ui/src/org/eclipse/jst/server/jetty/ui/internal/JettyLaunchConfigurationTabGroup.java
// for examples of other tabs we might want to add

setTabs(tabs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
public class LaunchModes implements IParameterValues {
@Override
@SuppressWarnings("rawtypes")
public Map getParameterValues() {
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
Map<String, String> modes = new HashMap<>();
Expand Down

0 comments on commit 80d7b12

Please sign in to comment.