com.google.cloud.tools.appengine.operations.cloudsdk.CloudSdkNotFoundException Java Examples

The following examples show how to use com.google.cloud.tools.appengine.operations.cloudsdk.CloudSdkNotFoundException. 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: LocalAppEngineServerBehaviour.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void initializeDevServer(MessageConsoleStream stdout, MessageConsoleStream stderr,
    Path javaHomePath) throws CloudSdkNotFoundException {
  MessageConsoleWriterListener stdoutListener = new MessageConsoleWriterListener(stdout);
  MessageConsoleWriterListener stderrListener = new MessageConsoleWriterListener(stderr);

  // dev_appserver output goes to stderr
  cloudSdk = new CloudSdk.Builder()
      .javaHome(javaHomePath)
      .build();

  ProcessHandler processHandler = LegacyProcessHandler.builder()
      .addStdOutLineListener(stdoutListener).addStdErrLineListener(stderrListener)
      .addStdErrLineListener(serverOutputListener)
      .setStartListener(localAppEngineStartListener)
      .setExitListener(localAppEngineExitListener)
      .async(true)
      .build();

  DevServers localRun = DevServers.builder(cloudSdk).build();
  devServer = localRun.newDevAppServer(processHandler);
  moduleToUrlMap.clear();
}
 
Example #2
Source File: DeployTargetResolver.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Process user configuration of "projectId". If set to GCLOUD_CONFIG then read from gcloud's
 * global state. If set but not a keyword then just return the set value.
 */
public String getProject(String configString) {
  if (configString == null
      || configString.trim().isEmpty()
      || configString.equals(APPENGINE_CONFIG)) {
    throw new GradleException(PROJECT_ERROR);
  }
  if (configString.equals(GCLOUD_CONFIG)) {
    try {
      String gcloudProject = cloudSdkOperations.getGcloud().getConfig().getProject();
      if (gcloudProject == null || gcloudProject.trim().isEmpty()) {
        throw new GradleException("Project was not found in gcloud config");
      }
      return gcloudProject;
    } catch (IOException
        | CloudSdkOutOfDateException
        | ProcessHandlerException
        | CloudSdkNotFoundException
        | CloudSdkVersionFileException ex) {
      throw new GradleException("Failed to read project from gcloud config", ex);
    }
  }
  return configString;
}
 
Example #3
Source File: DeployMojoIntegrationTest.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployFlexible()
    throws IOException, VerificationException, CloudSdkNotFoundException,
        ProcessHandlerException {

  Verifier verifier = new FlexibleVerifier("testDeployFlexible");

  // execute with staging directory not present
  verifier.executeGoal("package");
  verifier.executeGoal("appengine:deploy");

  // verify
  verifier.verifyErrorFreeLog();
  verifier.verifyTextInLog("Detected App Engine flexible environment application");
  verifier.verifyTextInLog("GCLOUD: Deployed service");

  // verify debugger required file generation
  verifier.assertFilePresent(
      "target/flexible-project-1.0-SNAPSHOT/WEB-INF/classes/" + "source-context.json");

  // cleanup
  deleteService("flexible-project");
}
 
Example #4
Source File: SourceContextPlugin.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private void createExtension() {
  // obtain extensions defined by core plugin.
  ExtensionAware appengine = new ExtensionUtil(project).get("appengine");
  final ToolsExtension tools = ((AppEngineCoreExtensionProperties) appengine).getTools();

  // create source context extension and set defaults
  extension =
      appengine
          .getExtensions()
          .create(SOURCE_CONTEXT_EXTENSION, GenRepoInfoFileExtension.class, project);
  extension.setOutputDirectory(new File(project.getBuildDir(), "sourceContext"));
  extension.setSourceDirectory(new File(project.getProjectDir(), "src"));

  // wait to read the cloudSdkHome till after project evaluation
  project.afterEvaluate(
      project -> {
        try {
          cloudSdkOperations = new CloudSdkOperations(tools.getCloudSdkHome(), null);
        } catch (CloudSdkNotFoundException ex) {
          // this should be caught in AppEngineCorePluginConfig before it can ever reach here.
          throw new GradleException("Could not find CloudSDK: ", ex);
        }
      });
}
 
Example #5
Source File: CloudSdkAppEngineFactoryTest.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildCloudSdk_checkNoAppEngine()
    throws CloudSdkOutOfDateException, CloudSdkNotFoundException, CloudSdkVersionFileException {
  when(mojoMock.getCloudSdkHome()).thenReturn(CLOUD_SDK_HOME);
  when(mojoMock.getCloudSdkVersion()).thenReturn(CLOUD_SDK_VERSION);

  // invoke
  CloudSdk sdk =
      CloudSdkAppEngineFactory.buildCloudSdk(
          mojoMock, cloudSdkChecker, cloudSdkDownloader, false);

  // verify
  Assert.assertEquals(CLOUD_SDK_HOME, sdk.getPath());
  verify(cloudSdkChecker).checkCloudSdk(sdk, CLOUD_SDK_VERSION);
  verifyNoMoreInteractions(cloudSdkDownloader);
  verifyNoMoreInteractions(cloudSdkChecker);
}
 
Example #6
Source File: CloudSdkAppEngineFactoryTest.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildCloudSdk_checkAppEngine()
    throws CloudSdkOutOfDateException, CloudSdkNotFoundException, CloudSdkVersionFileException,
        AppEngineJavaComponentsNotInstalledException {
  when(mojoMock.getCloudSdkHome()).thenReturn(CLOUD_SDK_HOME);
  when(mojoMock.getCloudSdkVersion()).thenReturn(CLOUD_SDK_VERSION);

  // invoke
  CloudSdk sdk =
      CloudSdkAppEngineFactory.buildCloudSdk(mojoMock, cloudSdkChecker, cloudSdkDownloader, true);

  // verify
  Assert.assertEquals(CLOUD_SDK_HOME, sdk.getPath());
  verify(cloudSdkChecker).checkCloudSdk(sdk, CLOUD_SDK_VERSION);
  verify(cloudSdkChecker).checkForAppEngine(sdk);
  verifyNoMoreInteractions(cloudSdkDownloader);
  verifyNoMoreInteractions(cloudSdkChecker);
}
 
Example #7
Source File: AppEngineStandardPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeploy()
    throws CloudSdkNotFoundException, IOException, ProcessHandlerException,
        UnsupportedOsException {
  BuildResult buildResult =
      GradleRunner.create()
          .withProjectDir(testProjectDir.getRoot())
          .withPluginClasspath()
          .withArguments("appengineDeploy", "--stacktrace")
          .build();

  Assert.assertThat(
      buildResult.getOutput(),
      CoreMatchers.containsString("Deployed service [standard-project]"));

  deleteProject();
}
 
Example #8
Source File: CheckCloudSdkTask.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
/** Task entrypoint : Verify Cloud SDK installation. */
@TaskAction
public void checkCloudSdkAction()
    throws CloudSdkNotFoundException, CloudSdkVersionFileException, CloudSdkOutOfDateException,
        AppEngineJavaComponentsNotInstalledException {
  // These properties are only set by AppEngineCorePluginConfiguration if the correct config
  // params are set in the tools extension.
  if (Strings.isNullOrEmpty(version) || cloudSdk == null) {
    throw new GradleException(
        "Cloud SDK home path and version must be configured in order to run this task.");
  }

  if (!version.equals(cloudSdk.getVersion().toString())) {
    throw new GradleException(
        "Specified Cloud SDK version ("
            + version
            + ") does not match installed version ("
            + cloudSdk.getVersion()
            + ").");
  }

  cloudSdk.validateCloudSdk();
  if (requiresAppEngineJava) {
    cloudSdk.validateAppEngineJavaComponents();
  }
}
 
Example #9
Source File: DeployMojoIntegrationTest.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployStandard()
    throws IOException, VerificationException, CloudSdkNotFoundException,
        ProcessHandlerException {

  Verifier verifier = new StandardVerifier("testDeployStandard");

  // execute with staging directory not present
  verifier.executeGoal("package");
  verifier.executeGoal("appengine:deploy");

  // verify
  verifier.verifyErrorFreeLog();
  verifier.verifyTextInLog("Detected App Engine standard environment application");
  verifier.verifyTextInLog("GCLOUD: Deployed service");

  // cleanup
  deleteService("standard-project");
}
 
Example #10
Source File: AppEngineAppYamlPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeploy()
    throws CloudSdkNotFoundException, IOException, ProcessHandlerException,
        UnsupportedOsException {

  BuildResult buildResult =
      GradleRunner.create()
          .withProjectDir(testProjectDir.getRoot())
          .withPluginClasspath()
          .withArguments("appengineDeploy")
          .build();

  Assert.assertThat(
      buildResult.getOutput(), CoreMatchers.containsString("Deployed service [appyaml-project]"));

  deleteProject();
}
 
Example #11
Source File: DeployAllMojoIntegrationTest.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployAllStandard()
    throws IOException, VerificationException, CloudSdkNotFoundException,
        ProcessHandlerException {

  Verifier verifier = new StandardVerifier("testDeployStandard");

  // execute with staging directory not present
  verifier.executeGoals(Arrays.asList("package", "appengine:deployAll"));

  // verify
  verifier.verifyErrorFreeLog();
  verifier.verifyTextInLog("Detected App Engine standard environment application");
  verifier.verifyTextInLog("GCLOUD: Deployed service");
  verifier.verifyTextInLog("GCLOUD: Custom routings have been updated.");
  verifier.verifyTextInLog("GCLOUD: DoS protection has been updated.");
  verifier.verifyTextInLog("GCLOUD: Indexes are being rebuilt. This may take a moment.");
  verifier.verifyTextInLog("GCLOUD: Cron jobs have been updated.");
  verifier.verifyTextInLog("GCLOUD: Task queues have been updated.");

  // cleanup
  deleteService("standard-project");
}
 
Example #12
Source File: CloudSdk.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
void validateCloudSdkLocation() throws CloudSdkNotFoundException {
  if (!Files.isDirectory(sdkPath)) {
    throw new CloudSdkNotFoundException(
        "Validation Error: SDK location '" + sdkPath + "' is not a directory.");
  }
  if (!Files.isRegularFile(getGCloudPath())) {
    throw new CloudSdkNotFoundException(
        "Validation Error: gcloud location '" + getGCloudPath() + "' is not a file.");
  }
  if (!Files.isRegularFile(getDevAppServerPath())) {
    throw new CloudSdkNotFoundException(
        "Validation Error: dev_appserver.py location '"
            + getDevAppServerPath()
            + "' is not a file.");
  }
}
 
Example #13
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 #14
Source File: CloudSdkPreferenceResolverTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPreferenceInvalid() throws CloudSdkNotFoundException {
  // A path that almost certainly does not contain the SDK
  File root = File.listRoots()[0];
  IPreferenceStore preferences = mock(IPreferenceStore.class);
  when(preferences.getString(anyString())).thenReturn(root.toString());

  CloudSdkPreferenceResolver resolver = new CloudSdkPreferenceResolver(preferences);
  CloudSdk sdk = new CloudSdk.Builder()
      .resolvers(Collections.singletonList((CloudSdkResolver) resolver)).build();
  assertEquals("SDK should be found at invalid location", root.toPath(), sdk.getPath());
  try {
    sdk.validateCloudSdk();
    fail("root directory should not validate as a valid location");
  } catch (AppEngineException ex) {
    // ignore
  }
}
 
Example #15
Source File: CloudSdkProcessWrapper.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up a {@link CloudSdk} to be used for App Engine standard staging.
 *
 * @param javaHome JDK/JRE to 1) run {@code com.google.appengine.tools.admin.AppCfg} from
 *     {@code appengine-tools-api.jar}; and 2) compile JSPs during staging
 */
public AppEngineWebXmlProjectStaging getAppEngineStandardStaging(Path javaHome,
    MessageConsoleStream stdoutOutputStream, MessageConsoleStream stderrOutputStream) 
        throws CloudSdkNotFoundException {
  Preconditions.checkState(!initialized, "process wrapper already set up");
  initialized = true;

  CloudSdk cloudSdk = javaHome == null
      ? new CloudSdk.Builder().build()
      : new CloudSdk.Builder().javaHome(javaHome).build();

  ProcessHandler processHandler = LegacyProcessHandler.builder()
      .setStartListener(this::storeProcessObject)
      .setExitListener(this::recordProcessExitCode)
      .addStdOutLineListener(new MessageConsoleWriterListener(stdoutOutputStream))
      .addStdErrLineListener(new MessageConsoleWriterListener(stderrOutputStream))
      .build();

  return AppCfg.builder(cloudSdk).build().newStaging(processHandler);
}
 
Example #16
Source File: StandardStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void setUpProject(IProjectFacetVersion... facetVersions)
    throws CloudSdkNotFoundException {
  project = projectCreator.withFacets(facetVersions).getProject();
  safeWorkDirectory = project.getFolder("safe-work-directory").getLocation();
  stagingDirectory = project.getFolder("staging-result").getLocation();

  CloudSdk cloudSdk = new CloudSdk.Builder().build();
  LegacyProcessHandler processHandler = LegacyProcessHandler.builder()
      .addStdOutLineListener(line -> { System.out.println("    [Cloud SDK] " + line); })
      .addStdErrLineListener(line -> { System.out.println("    [Cloud SDK] " + line); })
      .setExitListener(exitCode -> { cloudSdkExitCode = exitCode; })
      .build();
  AppEngineWebXmlProjectStaging staging =
      AppCfg.builder(cloudSdk).build().newStaging(processHandler);

  when(cloudSdkWrapper.getAppEngineStandardStaging(
      any(Path.class), any(MessageConsoleStream.class), any(MessageConsoleStream.class)))
      .thenReturn(staging);
}
 
Example #17
Source File: Gcloud.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of Cloud SDK Components and their settings, reported by the current gcloud
 * installation. Unlike other methods in this class that call gcloud, this method always uses a
 * synchronous ProcessRunner and will block until the gcloud process returns.
 *
 * @throws ProcessHandlerException when process runner encounters an error
 * @throws JsonSyntaxException when the cloud SDK output cannot be parsed
 * @throws CloudSdkNotFoundException when the Cloud SDK is not installed where expected
 * @throws CloudSdkOutOfDateException when the installed Cloud SDK is too old
 */
public List<CloudSdkComponent> getComponents()
    throws ProcessHandlerException, JsonSyntaxException, CloudSdkNotFoundException,
        CloudSdkOutOfDateException, CloudSdkVersionFileException, IOException {
  sdk.validateCloudSdk();

  // gcloud components list --show-versions --format=json
  List<String> command =
      new ImmutableList.Builder<String>()
          .add("components", "list")
          .addAll(GcloudArgs.get("show-versions", true))
          .addAll(GcloudArgs.get("format", "json"))
          .build();

  String componentsJson = runCommand(command);
  return CloudSdkComponent.fromJsonList(componentsJson);
}
 
Example #18
Source File: CloudSdk.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to find the Google Cloud SDK in various places.
 *
 * @return the path to the root of the Google Cloud SDK
 * @throws CloudSdkNotFoundException if not found
 */
@Nonnull
private Path discoverSdkPath() throws CloudSdkNotFoundException {
  for (CloudSdkResolver resolver : getResolvers()) {
    try {
      Path discoveredSdkPath = resolver.getCloudSdkPath();
      if (discoveredSdkPath != null) {
        return discoveredSdkPath;
      }
    } catch (RuntimeException ex) {
      // prevent interference from exceptions in other resolvers
      logger.log(
          Level.SEVERE,
          resolver.getClass().getName()
              + ": exception thrown when searching for Google Cloud SDK",
          ex);
    }
  }
  throw new CloudSdkNotFoundException(
      "The Google Cloud SDK could not be found in the customary"
          + " locations and no path was provided.");
}
 
Example #19
Source File: ConfigReader.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
/** Return gcloud config property for project, or error out if not found. */
public String getProjectId() {
  try {
    String gcloudProject = gcloud.getConfig().getProject();
    if (gcloudProject == null || gcloudProject.trim().isEmpty()) {
      throw new RuntimeException("Project was not found in gcloud config");
    }
    return gcloudProject;
  } catch (CloudSdkNotFoundException
      | CloudSdkOutOfDateException
      | CloudSdkVersionFileException
      | IOException
      | ProcessHandlerException ex) {
    throw new RuntimeException("Failed to read project from gcloud config", ex);
  }
}
 
Example #20
Source File: StandardStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testStage() throws CloudSdkNotFoundException {
  setUpAppEngineStandard8Project();
  StagingDelegate delegate = new StandardStagingDelegate(project, null, cloudSdkWrapper);
  delegate.stage(stagingDirectory, safeWorkDirectory, null, null,
      new NullProgressMonitor());

  assertTrue(stagingDirectory.append("WEB-INF").toFile().exists());
  assertTrue(stagingDirectory.append("WEB-INF/appengine-generated").toFile().exists());
  assertTrue(stagingDirectory.append("META-INF").toFile().exists());
  assertTrue(stagingDirectory.append("app.yaml").toFile().exists());
}
 
Example #21
Source File: StandardStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetOptionalConfigurationFilesDirectory() throws CloudSdkNotFoundException {
  setUpAppEngineStandard8Project();
  StagingDelegate delegate = new StandardStagingDelegate(project, null, cloudSdkWrapper);
  delegate.stage(stagingDirectory, safeWorkDirectory, null, null,
      new NullProgressMonitor());

  assertEquals(stagingDirectory.append("WEB-INF/appengine-generated"),
      delegate.getOptionalConfigurationFilesDirectory());
}
 
Example #22
Source File: CloudSdkCheckerTest.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckCloudSdk_versionMismatch()
    throws CloudSdkVersionFileException, CloudSdkOutOfDateException, CloudSdkNotFoundException {
  when(sdk.getVersion()).thenReturn(new CloudSdkVersion("190.0.0"));
  try {
    cloudSdkChecker.checkCloudSdk(sdk, "191.0.0");
    Assert.fail();
  } catch (RuntimeException ex) {
    Assert.assertEquals(
        "Specified Cloud SDK version (191.0.0) does not match installed version (190.0.0).",
        ex.getMessage());
  }
}
 
Example #23
Source File: StandardStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetJavaHome() throws CloudSdkNotFoundException {
  setUpAppEngineStandard8Project();
  Path javaHome = Paths.get("/some/path");
  StagingDelegate delegate = new StandardStagingDelegate(project, javaHome, cloudSdkWrapper);
  delegate.stage(stagingDirectory, safeWorkDirectory, null, null,
      new NullProgressMonitor());

  verify(cloudSdkWrapper).getAppEngineStandardStaging(
      eq(javaHome), any(MessageConsoleStream.class), any(MessageConsoleStream.class));
}
 
Example #24
Source File: CloudSdkProcessWrapperTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAppEngineStandardStaging_cannotSetUpTwice() throws CloudSdkNotFoundException {
  wrapper.getAppEngineStandardStaging(null, null, null);
  try {
    wrapper.getAppEngineStandardStaging(null, null, null);
    fail();
  } catch (IllegalStateException ex) {
    assertEquals(ex.getMessage(), "process wrapper already set up");
  }
}
 
Example #25
Source File: StandardStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testStage_errorStatusReported() throws CloudSdkNotFoundException {
  setUpProject();
  StagingDelegate delegate = new StandardStagingDelegate(project, null, cloudSdkWrapper);
  IStatus status = delegate.stage(stagingDirectory, safeWorkDirectory,
      null, null, new NullProgressMonitor());

  assertFalse(status.isOK());
  assertEquals("problem publishing WAR", status.getMessage());
  cloudSdkExitCode = 0;  // Make the Cloud SDK check in tearDown() happy.
}
 
Example #26
Source File: CloudSdkStagingHelperTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private AppEngineWebXmlProjectStaging setUpAppEngineStaging()
    throws CloudSdkNotFoundException, CoreException {
  createFile("WebContent/WEB-INF/appengine-web.xml", APPENGINE_WEB_XML);
  createFile("WebContent/WEB-INF/web.xml", WEB_XML);
  createFile("WebContent/META-INF/MANIFEST.MF", "");

  CloudSdk cloudSdk = new CloudSdk.Builder().build();
  AppCfg appCfg = AppCfg.builder(cloudSdk).build();
  ProcessHandler processHandler = LegacyProcessHandler.builder().async(false).build();
  return appCfg.newStaging(processHandler);
}
 
Example #27
Source File: CloudSdkAppEngineFactory.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
static CloudSdk buildCloudSdk(
    CloudSdkMojo mojo,
    CloudSdkChecker cloudSdkChecker,
    CloudSdkDownloader cloudSdkDownloader,
    boolean requiresAppEngineComponents) {

  try {
    if (mojo.getCloudSdkHome() != null) {
      // if user defined
      CloudSdk cloudSdk = new CloudSdk.Builder().sdkPath(mojo.getCloudSdkHome()).build();

      if (mojo.getCloudSdkVersion() != null) {
        cloudSdkChecker.checkCloudSdk(cloudSdk, mojo.getCloudSdkVersion());
      }
      if (requiresAppEngineComponents) {
        cloudSdkChecker.checkForAppEngine(cloudSdk);
      }
      return cloudSdk;
    } else {
      // we need to use a managed cloud sdk
      List<SdkComponent> requiredComponents = new ArrayList<>();
      if (requiresAppEngineComponents) {
        requiredComponents.add(SdkComponent.APP_ENGINE_JAVA);
      }
      return new CloudSdk.Builder()
          .sdkPath(
              cloudSdkDownloader.downloadIfNecessary(
                  mojo.getCloudSdkVersion(),
                  mojo.getLog(),
                  requiredComponents,
                  mojo.getMavenSession().isOffline()))
          .build();
    }
  } catch (CloudSdkNotFoundException
      | CloudSdkVersionFileException
      | AppEngineJavaComponentsNotInstalledException
      | CloudSdkOutOfDateException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #28
Source File: CloudSdkPreferences.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/** Return {@code true} if the Cloud SDK is available. */
private static boolean isCloudSdkAvailable() {
  try {
    new CloudSdk.Builder().build();
    return true;
  } catch (CloudSdkNotFoundException ex) {
    return false;
  }
}
 
Example #29
Source File: CloudSdkChecker.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the cloud SDK installation.
 *
 * @param cloudSdk CloudSdk with a configured sdk home directory
 */
public void checkCloudSdk(CloudSdk cloudSdk, String version)
    throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException {
  if (!version.equals(cloudSdk.getVersion().toString())) {
    throw new RuntimeException(
        "Specified Cloud SDK version ("
            + version
            + ") does not match installed version ("
            + cloudSdk.getVersion()
            + ").");
  }

  cloudSdk.validateCloudSdk();
}
 
Example #30
Source File: CloudSdkCheckerTest.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckCloudSdk_callPluginsCoreChecks()
    throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException {
  when(sdk.getVersion()).thenReturn(new CloudSdkVersion("192.0.0"));

  cloudSdkChecker.checkCloudSdk(sdk, "192.0.0");

  verify(sdk).getVersion();
  verify(sdk).validateCloudSdk();
  verifyNoMoreInteractions(sdk);
}