com.google.cloud.tools.appengine.operations.cloudsdk.CloudSdkOutOfDateException Java Examples
The following examples show how to use
com.google.cloud.tools.appengine.operations.cloudsdk.CloudSdkOutOfDateException.
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: DeployTargetResolver.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: CheckCloudSdkTask.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** 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 #3
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 6 votes |
@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 #4
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 6 votes |
@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 #5
Source File: ConfigReader.java From app-maven-plugin with Apache License 2.0 | 6 votes |
/** 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 #6
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: CloudSdkCheckerTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@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); }
Example #8
Source File: CloudSdkCheckerTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@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 #9
Source File: CloudSdkAppEngineFactory.java From app-maven-plugin with Apache License 2.0 | 5 votes |
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 #10
Source File: CloudSdkChecker.java From app-maven-plugin with Apache License 2.0 | 5 votes |
/** * 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 #11
Source File: CloudSdkOutOfDateExceptionTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Test public void testInstalledVersion() { CloudSdkVersion installedVersion = new CloudSdkVersion("131.0.0"); CloudSdkVersion requiredVersion = new CloudSdkVersion("133.0.0"); CloudSdkOutOfDateException ex = new CloudSdkOutOfDateException(installedVersion, requiredVersion); Assert.assertEquals(installedVersion, ex.getInstalledVersion()); Assert.assertEquals(requiredVersion, ex.getRequiredVersion()); Assert.assertEquals( "Requires version 133.0.0 or later but found version 131.0.0", ex.getMessage()); }
Example #12
Source File: CloudSdkOutOfDateExceptionTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Test public void testNoInstalledVersion() { CloudSdkVersion requiredVersion = new CloudSdkVersion("132.4.5"); CloudSdkOutOfDateException ex = new CloudSdkOutOfDateException(requiredVersion); Assert.assertNull(ex.getInstalledVersion()); Assert.assertEquals(requiredVersion, ex.getRequiredVersion()); Assert.assertEquals("Cloud SDK versions before 132.4.5 are not supported", ex.getMessage()); }
Example #13
Source File: CloudSdkTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Test public void testValidateCloudSdk_versionFileContentInvalid() throws IOException, CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException { String fileContents = "this is not a valid version string"; writeVersionFile(fileContents); root.resolve("bin").toFile().mkdir(); // fake SDK contents root.resolve("bin/gcloud").toFile().createNewFile(); root.resolve("bin/gcloud.cmd").toFile().createNewFile(); // for Windows root.resolve("bin/dev_appserver.py").toFile().createNewFile(); sdk.validateCloudSdk(); }
Example #14
Source File: GcloudRunner.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
/** * Launch an external process that runs gcloud. * * @param workingDirectory if null then the working directory of current Java process */ void run(List<String> arguments, @Nullable Path workingDirectory) throws ProcessHandlerException, CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException, IOException { sdk.validateCloudSdk(); List<String> command = new ArrayList<>(); command.add(sdk.getGCloudPath().toAbsolutePath().toString()); command.addAll(arguments); if (outputFormat != null) { command.addAll(GcloudArgs.get("format", outputFormat)); } if (credentialFile != null) { command.addAll(GcloudArgs.get("credential-file-override", credentialFile)); } if (flagsFiles != null) { for (Path flagFile : flagsFiles) { command.addAll(GcloudArgs.get("flags-file", flagFile)); } } logger.info("submitting command: " + Joiner.on(" ").join(command)); ProcessBuilder processBuilder = processBuilderFactory.newProcessBuilder(); processBuilder.command(command); if (workingDirectory != null) { processBuilder.directory(workingDirectory.toFile()); } processBuilder.environment().putAll(getGcloudCommandEnvironment()); Process process = processBuilder.start(); processHandler.handleProcess(process); }
Example #15
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
/** * Returns a representation of gcloud config, it makes a synchronous call to gcloud config list to * do so. */ public CloudSdkConfig getConfig() throws CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException, IOException, ProcessHandlerException { sdk.validateCloudSdk(); List<String> command = new ImmutableList.Builder<String>() .add("config", "list") .addAll(GcloudArgs.get("format", "json")) .build(); String configJson = runCommand(command); return CloudSdkConfig.fromJson(configJson); }
Example #16
Source File: CheckCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Test public void testCheckCloudSdkAction_callPluginsCoreChecksSkipJava() throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException, AppEngineJavaComponentsNotInstalledException { checkCloudSdkTask.setVersion("192.0.0"); when(sdk.getVersion()).thenReturn(new CloudSdkVersion("192.0.0")); checkCloudSdkTask.checkCloudSdkAction(); Mockito.verify(sdk).getVersion(); Mockito.verify(sdk).validateCloudSdk(); Mockito.verify(sdk, Mockito.never()).validateAppEngineJavaComponents(); Mockito.verifyNoMoreInteractions(sdk); }
Example #17
Source File: CheckCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Test public void testCheckCloudSdkAction_callPluginsCoreChecks() throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException, AppEngineJavaComponentsNotInstalledException { checkCloudSdkTask.setVersion("192.0.0"); checkCloudSdkTask.requiresAppEngineJava(true); when(sdk.getVersion()).thenReturn(new CloudSdkVersion("192.0.0")); checkCloudSdkTask.checkCloudSdkAction(); Mockito.verify(sdk).getVersion(); Mockito.verify(sdk).validateCloudSdk(); Mockito.verify(sdk).validateAppEngineJavaComponents(); Mockito.verifyNoMoreInteractions(sdk); }
Example #18
Source File: CheckCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Test public void testCheckCloudSdkAction_versionMismatch() throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException, AppEngineJavaComponentsNotInstalledException { checkCloudSdkTask.setVersion("191.0.0"); when(sdk.getVersion()).thenReturn(new CloudSdkVersion("190.0.0")); try { checkCloudSdkTask.checkCloudSdkAction(); Assert.fail(); } catch (GradleException ex) { Assert.assertEquals( "Specified Cloud SDK version (191.0.0) does not match installed version (190.0.0).", ex.getMessage()); } }
Example #19
Source File: CheckCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Test public void testCheckCloudSdkAction_nullVersion() throws CloudSdkNotFoundException, CloudSdkVersionFileException, CloudSdkOutOfDateException, AppEngineJavaComponentsNotInstalledException { checkCloudSdkTask.setVersion(null); try { checkCloudSdkTask.checkCloudSdkAction(); Assert.fail(); } catch (GradleException ex) { Assert.assertEquals( "Cloud SDK home path and version must be configured in order to run this task.", ex.getMessage()); } }
Example #20
Source File: DeployTargetResolverTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Before public void setup() throws CloudSdkNotFoundException, ProcessHandlerException, CloudSdkOutOfDateException, CloudSdkVersionFileException, IOException { Mockito.when(cloudSdkOperations.getGcloud()).thenReturn(gcloud); Mockito.when(gcloud.getConfig()).thenReturn(cloudSdkConfig); Mockito.when(cloudSdkConfig.getProject()).thenReturn(PROJECT_GCLOUD); }
Example #21
Source File: CloudSdkTest.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
@Test public void testValidateCloudSdk_doesNotThrowInvalidJdkException() throws CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException { new CloudSdk.Builder().javaHome(Paths.get("/fake/path")).build().validateCloudSdk(); }
Example #22
Source File: GcloudRunnerTest.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
@Test public void testRun_builtFromFactory() throws CloudSdkOutOfDateException, CloudSdkNotFoundException, ProcessHandlerException, CloudSdkVersionFileException, IOException { GcloudRunner gcloudRunner = new GcloudRunner.Factory(processBuilderFactory) .newRunner( sdk, "intellij", // metrics env "99", // metrics env version credentialFile, // credential file flagsFiles, // gcloud flags file(s) "some-format", // output format "always", // show structured logs processHandler); gcloudRunner.run(ImmutableList.of("some", "command"), workingDirectory); Mockito.verify(processBuilder).environment(); Mockito.verify(processEnv).putAll(gcloudRunner.getGcloudCommandEnvironment()); Mockito.verify(processBuilder).directory(workingDirectory.toFile()); Mockito.verify(processHandler).handleProcess(process); Mockito.verify(processBuilder) .command( ImmutableList.of( gcloudPath.toString(), "some", "command", "--format", "some-format", "--credential-file-override", credentialFile.toAbsolutePath().toString(), "--flags-file", flagsFiles.get(0).toAbsolutePath().toString(), "--flags-file", flagsFiles.get(1).toAbsolutePath().toString())); Mockito.verify(processBuilder).start(); Mockito.verifyNoMoreInteractions(processBuilder); Mockito.verify(processHandler).handleProcess(process); }
Example #23
Source File: CloudSdkTest.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
@Test public void testValidateCloudSdk() throws CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException { new CloudSdk.Builder().build().validateCloudSdk(); }
Example #24
Source File: CloudSdk.java From appengine-plugins-core with Apache License 2.0 | 2 votes |
/** * Checks whether the Cloud SDK path and version are valid. * * @throws CloudSdkNotFoundException when Cloud SDK is not installed where expected * @throws CloudSdkOutOfDateException when Cloud SDK is out of date * @throws CloudSdkVersionFileException VERSION file could not be read */ public void validateCloudSdk() throws CloudSdkNotFoundException, CloudSdkOutOfDateException, CloudSdkVersionFileException { validateCloudSdkLocation(); validateCloudSdkVersion(); }