com.google.cloud.tools.appengine.configuration.RunConfiguration Java Examples

The following examples show how to use com.google.cloud.tools.appengine.configuration.RunConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateRunConfiguration_withEnvironment() throws CoreException {
  Map<String, String> definedMap = new HashMap<>();
  definedMap.put("foo", "bar");
  definedMap.put("baz", "${env_var:PATH}");
  when(launchConfiguration.getAttribute(eq(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES),
      anyMapOf(String.class, String.class)))
      .thenReturn(definedMap);

  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);

  Map<String, String> parsedEnvironment = config.getEnvironment();
  assertNotNull(parsedEnvironment);
  assertEquals("bar", parsedEnvironment.get("foo"));
  assertEquals(System.getenv("PATH"), parsedEnvironment.get("baz"));
  verify(launchConfiguration).getAttribute(eq(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES),
      anyMapOf(String.class, String.class));
  verify(launchConfiguration, atLeastOnce())
      .getAttribute(eq(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES),
      anyBoolean());
}
 
Example #2
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrepareCommand_booleanFlags()
    throws AppEngineException, ProcessHandlerException, IOException {
  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service)).build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java8Service.toString());
  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");
  devServer.run(configuration);
  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedJava8Environment,
          java8Service /* workingDirectory */);
}
 
Example #3
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrepareCommand_noFlags()
    throws AppEngineException, ProcessHandlerException, IOException {

  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service)).build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java8Service.toString());

  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedJava8Environment,
          java8Service /* workingDirectory */);
}
 
Example #4
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrepareCommand_noFlagsJava7()
    throws AppEngineException, ProcessHandlerException, IOException {

  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java7Service)).build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown", "--disable_update_check", java7Service.toString());
  List<String> expectedJvmArgs =
      ImmutableList.of(
          "-javaagent:"
              + fakeJavaSdkHome.resolve("agent/appengine-agent.jar").toAbsolutePath().toString());

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedJava7Environment,
          java7Service /* workingDirectory */);
}
 
Example #5
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrepareCommand_noFlagsMultiModule()
    throws AppEngineException, ProcessHandlerException, IOException {

  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java7Service, java8Service)).build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java7Service.toString(),
          java8Service.toString());

  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(expectedJvmArgs, expectedFlags, expectedJava8Environment, null /* workingDirectory */);
}
 
Example #6
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateRunConfiguration_withProgramArgs() throws CoreException {
  // DebugPlugin.parseArguments() only supports double-quotes on Windows
  when(launchConfiguration
      .getAttribute(eq(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS), anyString()))
          .thenReturn("e f \"g h\"");

  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);

  assertNotNull(config.getAdditionalArguments());
  assertEquals(Arrays.asList("e", "f", "g h"), config.getAdditionalArguments());
  verify(launchConfiguration)
      .getAttribute(eq(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS), anyString());
}
 
Example #7
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void checkConflictingLaunches(ILaunchConfigurationType launchConfigType, String mode,
    RunConfiguration runConfig, ILaunch[] launches) throws CoreException {

  for (ILaunch launch : launches) {
    if (launch.isTerminated()
        || launch.getLaunchConfiguration() == null
        || launch.getLaunchConfiguration().getType() != launchConfigType) {
      continue;
    }
    IServer otherServer = ServerUtil.getServer(launch.getLaunchConfiguration());
    List<Path> paths = new ArrayList<>();
    RunConfiguration otherRunConfig =
        generateServerRunConfiguration(launch.getLaunchConfiguration(), otherServer, mode, paths);
    IStatus conflicts = checkConflicts(runConfig, otherRunConfig,
        new MultiStatus(Activator.PLUGIN_ID, 0,
            Messages.getString("conflicts.with.running.server", otherServer.getName()), //$NON-NLS-1$
            null));
    if (!conflicts.isOK()) {
      throw new CoreException(StatusUtil.filter(conflicts));
    }
  }
}
 
Example #8
Source File: LocalAppEngineServerBehaviour.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the development server.
 *
 * @param mode the launch mode (see ILaunchManager.*_MODE constants)
 */
void startDevServer(String mode, RunConfiguration devServerRunConfiguration,
    Path javaHomePath, MessageConsoleStream outputStream, MessageConsoleStream errorStream)
    throws CoreException, CloudSdkNotFoundException {

  BiPredicate<InetAddress, Integer> portInUse = (addr, port) -> {
    Preconditions.checkArgument(port >= 0, "invalid port");
    return SocketUtil.isPortInUse(addr, port);
  };

  checkPorts(devServerRunConfiguration, portInUse);

  setServerState(IServer.STATE_STARTING);
  setMode(mode);

  // Create dev app server instance
  initializeDevServer(outputStream, errorStream, javaHomePath);

  // Run server
  try {
    devServer.run(devServerRunConfiguration);
  } catch (AppEngineException ex) {
    Activator.logError("Error starting server: " + ex.getMessage()); //$NON-NLS-1$
    stop(true);
  }
}
 
Example #9
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateRunConfiguration_withServerPort() throws CoreException {
  when(launchConfiguration.getAttribute(anyString(), anyString()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());
  when(launchConfiguration
      .getAttribute(eq(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME), anyInt()))
          .thenReturn(9999);

  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);

  Integer port = config.getPort();
  assertNotNull(port);
  assertEquals(9999, (int) port);
  verify(launchConfiguration)
      .getAttribute(eq(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME), anyInt());
  verify(server, never()).getAttribute(anyString(), anyInt());
}
 
Example #10
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateRunConfiguration() throws CoreException {
  when(launchConfiguration.getAttribute(anyString(), anyString()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());
  when(launchConfiguration.getAttribute(anyString(), anyInt()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());
  when(server.getAttribute(anyString(), anyString()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());
  when(server.getAttribute(anyString(), anyInt()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());

  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);
  assertNull(config.getHost());
  assertEquals((Integer) LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT, config.getPort());
  assertTrue(config.getJvmFlags().isEmpty());
  verify(server, atLeastOnce()).getHost();
  verify(launchConfiguration, atLeastOnce()).getAttribute(anyString(), anyInt());
  verify(server, atLeastOnce()).getAttribute(anyString(), anyInt());
}
 
Example #11
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateRunConfiguration_restart_debug() throws CoreException {
  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.DEBUG_MODE, services);
  Boolean automaticRestart = config.getAutomaticRestart();
  assertNotNull(automaticRestart);
  assertFalse(automaticRestart);
}
 
Example #12
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateRunConfiguration_withVMArgs() throws CoreException {
  // DebugPlugin.parseArguments() only supports double-quotes on Windows
  when(launchConfiguration.getAttribute(eq(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS),
      anyString())).thenReturn("a b \"c d\"");

  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);

  assertNotNull(config.getJvmFlags());
  assertEquals(Arrays.asList("a", "b", "c d"), config.getJvmFlags());
  verify(launchConfiguration)
      .getAttribute(eq(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS), anyString());
}
 
Example #13
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testLaunch_noNullPointerExceptionWhenLaunchHasNoConfiguration() throws CoreException {
  ILaunch launch = mock(ILaunch.class);
  ILaunch[] launches = new ILaunch[] {launch};
  when(launch.getLaunchConfiguration()).thenReturn(null);

  new LocalAppEngineServerLaunchConfigurationDelegate().checkConflictingLaunches(null,
      ILaunchManager.RUN_MODE, mock(RunConfiguration.class), launches);
}
 
Example #14
Source File: RunConfigConflictTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameConflict() {
  RunConfiguration config = RunConfiguration.builder(services).build();
  IStatus status = LocalAppEngineServerLaunchConfigurationDelegate.checkConflicts(config, config,
      StatusUtil.multi(RunConfigConflictTest.class, "Conflict"));
  assertFalse(status.isOK());
  assertThat(status, Matchers.instanceOf(MultiStatus.class));
  IStatus[] children = ((MultiStatus) status).getChildren();
  assertEquals(1, children.length);
  assertTrue(children[0].getMessage().startsWith("server port: "));
}
 
Example #15
Source File: RunConfigConflictTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConflicts() {
  RunConfiguration.Builder builder = RunConfiguration.builder(services);
  builder.port(0); // random allocation
  RunConfiguration config2 = RunConfiguration.builder(services).build();
  IStatus status = LocalAppEngineServerLaunchConfigurationDelegate.checkConflicts(builder.build(),
      config2, StatusUtil.multi(RunConfigConflictTest.class, "Conflict"));
  assertTrue(status.isOK());
}
 
Example #16
Source File: LocalAppEngineServerBehaviour.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void checkPorts(RunConfiguration devServerRunConfiguration,
    BiPredicate<InetAddress, Integer> portInUse) throws CoreException {
  InetAddress serverHost = InetAddress.getLoopbackAddress();
  if (devServerRunConfiguration.getHost() != null) {
    serverHost = LocalAppEngineServerLaunchConfigurationDelegate
        .resolveAddress(devServerRunConfiguration.getHost());
  }
  serverPort = checkPort(serverHost,
      ifNull(devServerRunConfiguration.getPort(), DEFAULT_SERVER_PORT), portInUse);
}
 
Example #17
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
  IServer server = ServerUtil.getServer(configuration);
  List<Path> paths = new ArrayList<>();
  RunConfiguration runConfig = generateServerRunConfiguration(configuration, server, mode, paths);
  ILaunch[] launches = getLaunchManager().getLaunches();
  checkConflictingLaunches(configuration.getType(), mode, runConfig, launches);
  return super.getLaunch(configuration, mode);
}
 
Example #18
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Check for known conflicting settings.
 */
@VisibleForTesting
static IStatus checkConflicts(RunConfiguration ours, RunConfiguration theirs,
    MultiStatus status) {
  Class<?> clazz = LocalAppEngineServerLaunchConfigurationDelegate.class;
  // use {0,number,#} to avoid localized port numbers
  if (equalPorts(ours.getPort(), theirs.getPort(),
      LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT)) {
    status.add(StatusUtil.error(clazz,
        Messages.getString("server.port", //$NON-NLS-1$
            ifNull(ours.getPort(), LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT))));
  }
  return status;
}
 
Example #19
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/** Set up the debug target to connect to the remote JVM. Returns the updated RunConfiguration. */
private RunConfiguration setupDebugTarget(
    RunConfiguration devServerRunConfiguration,
    ILaunch launch,
    int debugPort,
    IProgressMonitor monitor)
    throws CoreException {
  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$
  }
  List<String> jvmFlags = new ArrayList<>();
  if (devServerRunConfiguration.getJvmFlags() != null) {
    jvmFlags.addAll(devServerRunConfiguration.getJvmFlags());
  }
  jvmFlags.add("-Xdebug"); //$NON-NLS-1$
  jvmFlags.add("-Xrunjdwp:transport=dt_socket,server=n,suspend=y,quiet=y,address=" + debugPort); //$NON-NLS-1$
  devServerRunConfiguration = devServerRunConfiguration.toBuilder().jvmFlags(jvmFlags).build();

  // The 4.7 listen connector supports a connectionLimit
  IVMConnector connector =
      JavaRuntime.getVMConnector(IJavaLaunchConfigurationConstants.ID_SOCKET_LISTEN_VM_CONNECTOR);
  if (connector == null) {
    abort("Cannot find Socket Listening connector", null, 0); //$NON-NLS-1$
    // NOTREACHED
    return null; // keep JDT null analysis happy
  }

  // Set JVM debugger connection parameters
  @SuppressWarnings("deprecation")
  int timeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
  Map<String, String> connectionParameters = new HashMap<>();
  connectionParameters.put("hostname", DEBUGGER_HOST); //$NON-NLS-1$
  connectionParameters.put("port", Integer.toString(debugPort)); //$NON-NLS-1$
  connectionParameters.put("timeout", Integer.toString(timeout)); //$NON-NLS-1$
  connectionParameters.put("connectionLimit", "0"); //$NON-NLS-1$ //$NON-NLS-2$
  connector.connect(connectionParameters, monitor, launch);
  return devServerRunConfiguration;
}
 
Example #20
Source File: Runner.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
protected RunConfiguration buildRunConfiguration(List<Path> services, String projectId) {

      return RunConfiguration.builder(services)
          .additionalArguments(runMojo.getAdditionalArguments())
          .automaticRestart(runMojo.getAutomaticRestart())
          .defaultGcsBucketName(runMojo.getDefaultGcsBucketName())
          .projectId(projectId)
          .environment(runMojo.getEnvironment())
          .host(runMojo.getHost())
          .jvmFlags(runMojo.getJvmFlags())
          .port(runMojo.getPort())
          .build();
    }
 
Example #21
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateRunConfiguration_restart_run() throws CoreException {
  
  RunConfiguration config = new LocalAppEngineServerLaunchConfigurationDelegate()
      .generateServerRunConfiguration(launchConfiguration, server, ILaunchManager.RUN_MODE, services);
  Boolean automaticRestart = config.getAutomaticRestart();
  assertNotNull(automaticRestart);
  assertTrue(automaticRestart);
}
 
Example #22
Source File: RunExtension.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
RunConfiguration toRunConfiguration() {
  String processedProjectId = deployTargetResolver.getProject(projectId);
  return RunConfiguration.builder(
          services.stream().map(File::toPath).collect(Collectors.toList()))
      .additionalArguments(additionalArguments)
      .automaticRestart(automaticRestart)
      .defaultGcsBucketName(defaultGcsBucketName)
      .environment(environment)
      .host(host)
      .jvmFlags(jvmFlags)
      .port(port)
      .projectId(processedProjectId)
      .build();
}
 
Example #23
Source File: LocalAppEngineServerLaunchConfigurationDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateRunConfiguration_withHost() throws CoreException {
  when(launchConfiguration.getAttribute(anyString(), anyString()))
      .thenAnswer(AdditionalAnswers.returnsSecondArg());
  when(server.getHost()).thenReturn("example.com");
  RunConfiguration config =
      new LocalAppEngineServerLaunchConfigurationDelegate().generateServerRunConfiguration(
          launchConfiguration, server, ILaunchManager.RUN_MODE, services);
  assertEquals("example.com", config.getHost());
  verify(server, atLeastOnce()).getHost();
}
 
Example #24
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testWorkingDirectory_noFallbackIfManyProjects()
    throws ProcessHandlerException, AppEngineException, IOException {
  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service, java8Service)).build();

  devServer.run(configuration);

  verify(devAppServerRunner).run(any(), any(), any(), eq(null) /* workingDirectory */);
}
 
Example #25
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testWorkingDirectory_fallbackIfOneProject()
    throws ProcessHandlerException, AppEngineException, IOException {
  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service)).build();

  devServer.run(configuration);

  verify(devAppServerRunner).run(any(), any(), any(), eq(java8Service) /* workingDirectory */);
}
 
Example #26
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepareCommand_clientSuppliedAndAppEngineWebXmlEnvironmentVariables()
    throws AppEngineException, ProcessHandlerException, IOException {
  Map<String, String> clientEnvironmentVariables =
      ImmutableMap.of("mykey1", "myval1", "mykey2", "myval2");

  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service1EnvVars))
          .environment(clientEnvironmentVariables)
          .build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java8Service1EnvVars.toString());

  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");

  Map<String, String> appEngineEnvironment = ImmutableMap.of("key1", "val1", "key2", "val2");
  Map<String, String> expectedEnvironment =
      ImmutableMap.<String, String>builder()
          .putAll(appEngineEnvironment)
          .putAll(expectedJava8Environment)
          .putAll(clientEnvironmentVariables)
          .build();

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedEnvironment,
          java8Service1EnvVars /* workingDirectory */);
}
 
Example #27
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepareCommand_clientSuppliedEnvironmentVariables()
    throws AppEngineException, ProcessHandlerException, IOException {
  Map<String, String> clientEnvironmentVariables =
      ImmutableMap.of("mykey1", "myval1", "mykey2", "myval2");

  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java7Service))
          .environment(clientEnvironmentVariables)
          .build();

  Map<String, String> expectedEnvironment =
      ImmutableMap.<String, String>builder()
          .putAll(expectedJava7Environment)
          .putAll(clientEnvironmentVariables)
          .build();
  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown", "--disable_update_check", java7Service.toString());
  List<String> expectedJvmArgs =
      ImmutableList.of(
          "-javaagent:"
              + fakeJavaSdkHome.resolve("agent/appengine-agent.jar").toAbsolutePath().toString());

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedEnvironment,
          java7Service /* workingDirectory */);
}
 
Example #28
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepareCommand_multipleServicesDuplicateAppEngineWebXmlEnvironmentVariables()
    throws AppEngineException, ProcessHandlerException, IOException {
  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service1EnvVars, java8Service2EnvVars))
          .build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java8Service1EnvVars.toString(),
          java8Service2EnvVars.toString());

  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");

  Map<String, String> expectedConfigurationEnvironment =
      ImmutableMap.of("key1", "val1", "keya", "vala", "key2", "duplicated-key", "keyc", "valc");
  Map<String, String> expectedEnvironment =
      ImmutableMap.<String, String>builder()
          .putAll(expectedConfigurationEnvironment)
          .putAll(expectedJava8Environment)
          .build();

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(expectedJvmArgs, expectedFlags, expectedEnvironment, null /* workingDirectory */);
}
 
Example #29
Source File: DevServerTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepareCommand_appEngineWebXmlEnvironmentVariables()
    throws AppEngineException, ProcessHandlerException, IOException {
  RunConfiguration configuration =
      RunConfiguration.builder(ImmutableList.of(java8Service1EnvVars)).build();

  List<String> expectedFlags =
      ImmutableList.of(
          "--allow_remote_shutdown",
          "--disable_update_check",
          "--no_java_agent",
          java8Service1EnvVars.toString());

  List<String> expectedJvmArgs =
      ImmutableList.of("-Duse_jetty9_runtime=true", "-D--enable_all_permissions=true");

  Map<String, String> expectedConfigurationEnvironment =
      ImmutableMap.of("key1", "val1", "key2", "val2");
  Map<String, String> expectedEnvironment =
      ImmutableMap.<String, String>builder()
          .putAll(expectedConfigurationEnvironment)
          .putAll(expectedJava8Environment)
          .build();

  devServer.run(configuration);

  verify(devAppServerRunner, times(1))
      .run(
          expectedJvmArgs,
          expectedFlags,
          expectedEnvironment,
          java8Service1EnvVars /* workingDirectory */);
}
 
Example #30
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
/**
 * Create a CloudSdk RunConfiguration corresponding to the launch configuration and server
 * defaults. Details are pulled from {@link ILaunchConfiguration#getAttributes() launch
 * attributes} and {@link IServer server settings and attributes}.
 * @param runnables 
 */
@VisibleForTesting
RunConfiguration generateServerRunConfiguration(ILaunchConfiguration configuration,
    IServer server, String mode, List<Path> services) throws CoreException {

  RunConfiguration.Builder builder = RunConfiguration.builder(services);
  // Iterate through our different configurable parameters
  // TODO: storage-related paths, including storage_path and the {blob,data,*search*,logs} paths

  // TODO: allow setting host from launch config
  if (server.getHost() != null) {
    builder.host(server.getHost());
  }

  int serverPort = getPortAttribute(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME,
      LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT, configuration, server);
  if (serverPort >= 0) {
    builder.port(serverPort);
  }

  // only restart server on on-disk changes detected when in RUN mode
  builder.automaticRestart(ILaunchManager.RUN_MODE.equals(mode));

  // vmArguments is exactly as supplied by the user in the dialog box
  String vmArgumentString = getVMArguments(configuration);
  List<String> vmArguments = Arrays.asList(DebugPlugin.parseArguments(vmArgumentString));
  if (!vmArguments.isEmpty()) {
    builder.jvmFlags(vmArguments);
  }
  // programArguments is exactly as supplied by the user in the dialog box
  String programArgumentString = getProgramArguments(configuration);
  List<String> programArguments =
      Arrays.asList(DebugPlugin.parseArguments(programArgumentString));
  if (!programArguments.isEmpty()) {
    builder.additionalArguments(programArguments);
  }

  boolean environmentAppend =
      configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
  if (!environmentAppend) {
    // not externalized as this may change due to
    // https://github.com/GoogleCloudPlatform/appengine-plugins-core/issues/446
    throw new CoreException(
        StatusUtil.error(this, "'Environment > Replace environment' not yet supported")); //$NON-NLS-1$
  }
  // Could use getEnvironment(), but it does `append` processing and joins as key-value pairs
  Map<String, String> environment = configuration.getAttribute(
      ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, Collections.<String, String>emptyMap());
  Map<String, String> expanded = new HashMap<>();
  IStringVariableManager variableEngine = VariablesPlugin.getDefault().getStringVariableManager();
  for (Map.Entry<String, String> entry : environment.entrySet()) {
    // expand any variable references
    expanded.put(entry.getKey(), variableEngine.performStringSubstitution(entry.getValue()));
  }
  builder.environment(expanded);

  return builder.build();
}