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

The following examples show how to use com.google.cloud.tools.appengine.configuration.AppEngineWebXmlProjectStageConfiguration. 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: AppEngineWebXmlProjectStagingTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
    throws IOException, InvalidJavaSdkException, ProcessHandlerException,
        AppEngineJavaComponentsNotInstalledException {
  source = tmpDir.newFolder("source").toPath();
  destination = tmpDir.newFolder("destination").toPath();
  dockerfile = tmpDir.newFile("dockerfile").toPath();

  staging = new AppEngineWebXmlProjectStaging(appCfgRunner);

  builder =
      AppEngineWebXmlProjectStageConfiguration.builder()
          .sourceDirectory(source)
          .stagingDirectory(destination);

  // create an app.yaml in staging output when we run.
  Mockito.doAnswer(
          ignored -> {
            Files.createFile(destination.resolve("app.yaml"));
            return null;
          })
      .when(appCfgRunner)
      .run(Mockito.anyList());
}
 
Example #2
Source File: AppEngineWebXmlProjectStagingTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFlags_booleanFlags()
    throws AppEngineException, ProcessHandlerException, IOException {
  builder.enableQuickstart(false);
  builder.disableUpdateCheck(false);
  builder.enableJarSplitting(false);
  builder.deleteJsps(false);
  builder.enableJarClasses(false);
  builder.disableJarJsps(false);

  AppEngineWebXmlProjectStageConfiguration configuration = builder.build();

  List<String> expected = ImmutableList.of("stage", source.toString(), destination.toString());

  staging.stageStandard(configuration);

  verify(appCfgRunner, times(1)).run(eq(expected));
}
 
Example #3
Source File: CloudSdkStagingHelper.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * @param explodedWarDirectory the input of the staging operation
 * @param stagingDirectory where the result of the staging operation will be written
 * @param appEngineStandardStaging executes the staging operation
 * @throws AppEngineException when staging fails
 */
public static void stageStandard(IPath explodedWarDirectory, IPath stagingDirectory,
    AppEngineWebXmlProjectStaging appEngineStandardStaging, IProgressMonitor monitor)
        throws AppEngineException {
  if (monitor.isCanceled()) {
    throw new OperationCanceledException("canceled early");
  }

  SubMonitor progress = SubMonitor.convert(monitor, 1);
  progress.setTaskName(Messages.getString("task.name.stage.project")); //$NON-NLS-1$

  AppEngineWebXmlProjectStageConfiguration stagingConfig =
      AppEngineWebXmlProjectStageConfiguration.builder(
          explodedWarDirectory.toFile().toPath(), stagingDirectory.toFile().toPath())
          .enableJarSplitting(true)
          .disableUpdateCheck(true)
          .build();

  appEngineStandardStaging.stageStandard(stagingConfig);

  progress.worked(1);
}
 
Example #4
Source File: StageStandardExtension.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
AppEngineWebXmlProjectStageConfiguration toStageStandardConfiguration() {
  return AppEngineWebXmlProjectStageConfiguration.builder(
          sourceDirectory.toPath(), stagingDirectory.toPath())
      .compileEncoding(compileEncoding)
      .deleteJsps(deleteJsps)
      .disableJarJsps(disableJarJsps)
      .dockerfile(NullSafe.convert(dockerfile, File::toPath))
      .disableUpdateCheck(disableUpdateCheck)
      .enableJarClasses(enableJarClasses)
      .enableJarSplitting(enableJarSplitting)
      .enableQuickstart(enableQuickstart)
      .jarSplittingExcludes(jarSplittingExcludes)
      .runtime(runtime)
      .build();
}
 
Example #5
Source File: AppEngineWebXmlProjectStagingTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testSourceDirectoryRequired() {
  try {
    AppEngineWebXmlProjectStageConfiguration.builder().stagingDirectory(destination).build();
    Assert.fail("allowed missing source directory");
  } catch (IllegalStateException ex) {
    Assert.assertEquals("No source directory supplied", ex.getMessage());
  }
}
 
Example #6
Source File: AppEngineWebXmlProjectStagingTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testStagingDirectoryRequired() {
  try {
    AppEngineWebXmlProjectStageConfiguration.builder().sourceDirectory(destination).build();
    Assert.fail("allowed missing staging directory");
  } catch (IllegalStateException ex) {
    Assert.assertEquals("No staging directory supplied", ex.getMessage());
  }
}
 
Example #7
Source File: AppEngineWebXmlProjectStagingTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckFlags_allFlags() throws Exception {
  builder
      .dockerfile(dockerfile)
      .enableQuickstart(true)
      .disableUpdateCheck(true)
      .enableJarSplitting(true)
      .jarSplittingExcludes("suffix1,suffix2")
      .compileEncoding("UTF8")
      .deleteJsps(true)
      .enableJarClasses(true)
      .disableJarJsps(true)
      .runtime("java");

  AppEngineWebXmlProjectStageConfiguration configuration = builder.build();

  List<String> expected =
      ImmutableList.of(
          "--enable_quickstart",
          "--disable_update_check",
          "--enable_jar_splitting",
          "--jar_splitting_excludes=suffix1,suffix2",
          "--compile_encoding=UTF8",
          "--delete_jsps",
          "--enable_jar_classes",
          "--disable_jar_jsps",
          "--allow_any_runtime",
          "--runtime=java",
          "stage",
          source.toString(),
          destination.toString());

  staging.stageStandard(configuration);

  verify(appCfgRunner, times(1)).run(eq(expected));
}
 
Example #8
Source File: AppEngineWebXmlStager.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
AppEngineWebXmlProjectStageConfiguration buildConfiguration() throws MojoExecutionException {
  return AppEngineWebXmlProjectStageConfiguration.builder(
          stageMojo.getSourceDirectory(), stageMojo.getStagingDirectory())
      .compileEncoding(stageMojo.getCompileEncoding())
      .deleteJsps(stageMojo.isDeleteJsps())
      .disableJarJsps(stageMojo.isDisableJarJsps())
      .disableUpdateCheck(stageMojo.isDisableUpdateCheck())
      .dockerfile(processDockerfile())
      .enableJarClasses(stageMojo.isEnableJarClasses())
      .enableJarSplitting(stageMojo.isEnableJarSplitting())
      .enableQuickstart(stageMojo.isEnableQuickstart())
      .jarSplittingExcludes(stageMojo.getJarSplittingExcludes())
      .runtime(processRuntime())
      .build();
}
 
Example #9
Source File: AppEngineWebXmlProjectStaging.java    From appengine-plugins-core with Apache License 2.0 4 votes vote down vote up
/**
 * Stages an appengine-web.xml based project for deployment. Calls out to appcfg to execute this
 * staging.
 *
 * @param config Specifies source config and staging destination
 * @throws AppEngineException When staging fails
 */
public void stageStandard(AppEngineWebXmlProjectStageConfiguration config)
    throws AppEngineException {
  Preconditions.checkNotNull(config);
  Preconditions.checkNotNull(config.getSourceDirectory());
  Preconditions.checkNotNull(config.getStagingDirectory());

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

  arguments.addAll(AppCfgArgs.get("enable_quickstart", config.getEnableQuickstart()));
  arguments.addAll(AppCfgArgs.get("disable_update_check", config.getDisableUpdateCheck()));
  arguments.addAll(AppCfgArgs.get("enable_jar_splitting", config.getEnableJarSplitting()));
  arguments.addAll(AppCfgArgs.get("jar_splitting_excludes", config.getJarSplittingExcludes()));
  arguments.addAll(AppCfgArgs.get("compile_encoding", config.getCompileEncoding()));
  arguments.addAll(AppCfgArgs.get("delete_jsps", config.getDeleteJsps()));
  arguments.addAll(AppCfgArgs.get("enable_jar_classes", config.getEnableJarClasses()));
  arguments.addAll(AppCfgArgs.get("disable_jar_jsps", config.getDisableJarJsps()));
  if (config.getRuntime() != null) {
    // currently only java7 is allowed without --allow_any_runtime
    arguments.addAll(AppCfgArgs.get("allow_any_runtime", true));
    arguments.addAll(AppCfgArgs.get("runtime", config.getRuntime()));
  }
  arguments.add("stage");
  arguments.add(config.getSourceDirectory().toString());
  arguments.add(config.getStagingDirectory().toString());

  Path dockerfile = config.getDockerfile();

  try {

    if (dockerfile != null && Files.exists(dockerfile)) {
      Files.copy(
          dockerfile,
          config.getSourceDirectory().resolve(dockerfile.getFileName()),
          StandardCopyOption.REPLACE_EXISTING);
    }

    runner.run(arguments);

    // TODO : Move this fix up the chain (appcfg)
    if (config.getRuntime() != null && config.getRuntime().equals("java")) {
      Path appYaml = config.getStagingDirectory().resolve("app.yaml");
      Files.write(
          appYaml,
          "\nruntime_config:\n  jdk: openjdk8\n".getBytes(StandardCharsets.UTF_8),
          StandardOpenOption.APPEND);
    }

  } catch (IOException | ProcessHandlerException e) {
    throw new AppEngineException(e);
  }
}