com.google.cloud.tools.appengine.operations.CloudSdk Java Examples
The following examples show how to use
com.google.cloud.tools.appengine.operations.CloudSdk.
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: 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 #2
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 #3
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void testBuildCloudSdk_offlinePassthrough() { when(mojoMock.getCloudSdkHome()).thenReturn(null); when(mojoMock.getCloudSdkVersion()).thenReturn(null); when(mavenSession.isOffline()).thenReturn(true); // invoke CloudSdk sdk = CloudSdkAppEngineFactory.buildCloudSdk(mojoMock, cloudSdkChecker, cloudSdkDownloader, true); Assert.assertEquals(INSTALL_SDK_PATH, sdk.getPath()); verify(cloudSdkDownloader) .downloadIfNecessary(null, logMock, ImmutableList.of(SdkComponent.APP_ENGINE_JAVA), true); verify(mavenSession).isOffline(); verifyNoMoreInteractions(cloudSdkChecker); }
Example #4
Source File: CloudSdkProcessWrapper.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: CloudSdkPreferenceResolverTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@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 #6
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void testBuildCloudSdk_downloadWithVersion() { when(mojoMock.getCloudSdkHome()).thenReturn(null); when(mojoMock.getCloudSdkVersion()).thenReturn(CLOUD_SDK_VERSION); // invoke CloudSdk sdk = CloudSdkAppEngineFactory.buildCloudSdk(mojoMock, cloudSdkChecker, cloudSdkDownloader, true); // verify Assert.assertEquals(INSTALL_SDK_PATH, sdk.getPath()); verify(cloudSdkDownloader) .downloadIfNecessary( CLOUD_SDK_VERSION, logMock, ImmutableList.of(SdkComponent.APP_ENGINE_JAVA), false); verifyNoMoreInteractions(cloudSdkChecker); }
Example #7
Source File: LocalAppEngineServerBehaviour.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
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 #8
Source File: StandardStagingDelegateTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
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 #9
Source File: AbstractMojoIntegrationTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
protected void deleteService(String service) throws CloudSdkNotFoundException, IOException, ProcessHandlerException { CloudSdk cloudSdk = new CloudSdk.Builder().build(); Gcloud.builder(cloudSdk) .build() .runCommand(Arrays.asList("app", "services", "delete", service)); }
Example #10
Source File: CloudSdkPreferences.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** 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 #11
Source File: BugReportCommandHandler.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static String getCloudSdkVersion() { try { CloudSdk sdk = new CloudSdk.Builder().build(); return sdk.getVersion().toString(); } catch (AppEngineException ex) { return ex.toString(); } }
Example #12
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 #13
Source File: CloudSdkAppEngineFactory.java From app-maven-plugin with Apache License 2.0 | 5 votes |
private CloudSdk buildCloudSdkMinimal() { return buildCloudSdk( mojo, new CloudSdkChecker(), new CloudSdkDownloader(CloudSdkDownloader.newManagedSdkFactory()), false); }
Example #14
Source File: CloudSdkAppEngineFactory.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@VisibleForTesting CloudSdk buildCloudSdkWithAppEngineComponents() { return buildCloudSdk( mojo, new CloudSdkChecker(), new CloudSdkDownloader(CloudSdkDownloader.newManagedSdkFactory()), true); }
Example #15
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 #16
Source File: CloudSdkPreferenceArea.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static Path getDefaultSdkLocation() { try { return new CloudSdk.Builder().build().getPath(); } catch (AppEngineException ex) { return null; } }
Example #17
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@Test public void testBuildCloudSdk_downloadWithoutVersion() { when(mojoMock.getCloudSdkHome()).thenReturn(null); when(mojoMock.getCloudSdkVersion()).thenReturn(null); // invoke CloudSdk sdk = CloudSdkAppEngineFactory.buildCloudSdk(mojoMock, cloudSdkChecker, cloudSdkDownloader, true); // verify Assert.assertEquals(INSTALL_SDK_PATH, sdk.getPath()); verify(cloudSdkDownloader) .downloadIfNecessary(null, logMock, ImmutableList.of(SdkComponent.APP_ENGINE_JAVA), false); verifyNoMoreInteractions(cloudSdkChecker); }
Example #18
Source File: CloudSdkAppEngineFactoryTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@Test public void testBuildCloudSdk_noCheck() { when(mojoMock.getCloudSdkHome()).thenReturn(CLOUD_SDK_HOME); when(mojoMock.getCloudSdkVersion()).thenReturn(null); // invoke CloudSdk sdk = CloudSdkAppEngineFactory.buildCloudSdk( mojoMock, cloudSdkChecker, cloudSdkDownloader, false); // verify Assert.assertEquals(CLOUD_SDK_HOME, sdk.getPath()); verifyNoMoreInteractions(cloudSdkDownloader); verifyNoMoreInteractions(cloudSdkChecker); }
Example #19
Source File: ManagedCloudSdkStartup.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Return the version of the Google Cloud SDK at the given location, or {@code null} if it cannot * be determined. */ private static CloudSdkVersion getVersion(Path sdkHome) { try { CloudSdk sdk = new CloudSdk.Builder().sdkPath(sdkHome).build(); return sdk.getVersion(); } catch (CloudSdkVersionFileException | CloudSdkNotFoundException ex) { return null; } }
Example #20
Source File: AppEngineAppYamlPluginIntegrationTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
private static void deleteProject() throws UnsupportedOsException, CloudSdkNotFoundException, IOException, ProcessHandlerException { Path sdkHome = ManagedCloudSdk.newManagedSdk().getSdkHome(); CloudSdk cloudSdk = new CloudSdk.Builder().sdkPath(sdkHome).build(); Gcloud.builder(cloudSdk) .build() .runCommand(Arrays.asList("app", "services", "delete", "appyaml-project", "--quiet")); }
Example #21
Source File: CloudSdkPreferenceArea.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static String getSdkVersion(Path path) { if (!Files.exists(path) || !Files.isDirectory(path)) { return Messages.getString("NoSdkFound"); //$NON-NLS-1$ } try { return new CloudSdk.Builder().sdkPath(path).build().getVersion().toString(); } catch (CloudSdkVersionFileException | CloudSdkNotFoundException ex) { return Messages.getString("NoSdkFound"); //$NON-NLS-1$ } }
Example #22
Source File: CloudSdkStagingHelperTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
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 #23
Source File: BaseProjectTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { // verify we can find the Google Cloud SDK new CloudSdk.Builder().build().validateCloudSdk(); bot = new SWTWorkbenchBot(); try { SwtBotWorkbenchActions.closeWelcome(bot); } catch (WidgetNotFoundException ex) { // may receive WNFE: "There is no active view" } }
Example #24
Source File: LocalAppEngineServerWizardFragment.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private String getCloudSdkLocation() { try { CloudSdk cloudSdk = new CloudSdk.Builder().build(); return cloudSdk.getPath().toString(); } catch (AppEngineException ex) { return null; } }
Example #25
Source File: CloudSdkPreferenceResolverTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** Verify that the preference resolver is not last (that is, overrides PathResolver). */ @Test public void testPreferenceResolverNotLast() { List<CloudSdkResolver> resolvers = new CloudSdk.Builder().getResolvers(); // we should have at least our CloudSdkPreferenceResolver, located via ServiceLoader, and // the default PathResolver assertTrue(resolvers.size() > 1); CloudSdkResolver lastResolver = resolvers.get(resolvers.size() - 1); assertNotEquals(CloudSdkPreferenceResolver.class.getName(), lastResolver.getClass().getName()); }
Example #26
Source File: CloudSdkPreferenceResolverTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** Verify that the preference resolver is found by default. */ @Test public void testPreferenceResolverFound() { CloudSdk.Builder builder = new CloudSdk.Builder(); List<CloudSdkResolver> resolvers = builder.getResolvers(); int found = 0; for (CloudSdkResolver resolver : resolvers) { // Can't just compare classes as class likely loaded from // different classloaders if (CloudSdkPreferenceResolver.class.getName().equals(resolver.getClass().getName())) { found++; } } assertEquals("Could not find CloudSdkPreferenceResolver", 1, found); }
Example #27
Source File: CloudSdkProcessWrapper.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Sets up a {@link CloudSdk} to be used for App Engine deploy. */ public Deployment getAppEngineDeployment(Path credentialFile, MessageConsoleStream normalOutputStream) throws CloudSdkNotFoundException { Preconditions.checkNotNull(credentialFile, "credential required for deploying"); Preconditions.checkArgument(Files.exists(credentialFile), "non-existing credential file"); Preconditions.checkState(!initialized, "process wrapper already set up"); initialized = true; CloudSdk cloudSdk = new CloudSdk.Builder().build(); Gcloud gcloud = Gcloud.builder(cloudSdk) .setCredentialFile(credentialFile.toFile().toPath()) .setMetricsEnvironment(CloudToolsInfo.METRICS_NAME, CloudToolsInfo.getToolsVersion()) .setShowStructuredLogs("always") // turns on gcloud structured log .setOutputFormat("json") // Deploy result will be in JSON. .build(); // Gcloud sends structured deploy result (in JSON format) to stdout, so prepare to capture that. stdOutCaptor = StringBuilderProcessOutputLineListener.newListenerWithNewlines(); // Gcloud sends structured gcloud logs (in JSON format) to stderr, so prepare to capture them. gcloudErrorMessageCollector = new GcloudStructuredLogErrorMessageCollector(); ProcessHandler processHandler = LegacyProcessHandler.builder() .setStartListener(this::storeProcessObject) .setExitListener(this::recordProcessExitCode) // Gcloud sends normal operation output to stderr. .addStdErrLineListener(new MessageConsoleWriterListener(normalOutputStream)) .addStdErrLineListener(gcloudErrorMessageCollector) .addStdOutLineListener(stdOutCaptor) .build(); return gcloud.newDeployment(processHandler); }
Example #28
Source File: CloudSdkOperations.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
/** * Operations factory for Cloud Sdk based actions. * * @param cloudSdkHome path to cloud sdk * @param credentialFile optional path to a credential file * @throws CloudSdkNotFoundException when cloud sdk path cannot be validated */ public CloudSdkOperations(File cloudSdkHome, File credentialFile) throws CloudSdkNotFoundException { cloudSdk = new CloudSdk.Builder().sdkPath(cloudSdkHome.toPath()).build(); gcloud = Gcloud.builder(cloudSdk) .setCredentialFile(NullSafe.convert(credentialFile, File::toPath)) .setMetricsEnvironment( getClass().getPackage().getImplementationTitle(), getClass().getPackage().getImplementationVersion()) .build(); }
Example #29
Source File: AppEngineStandardPluginIntegrationTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
private static void deleteProject() throws UnsupportedOsException, CloudSdkNotFoundException, IOException, ProcessHandlerException { Path sdkHome = ManagedCloudSdk.newManagedSdk().getSdkHome(); CloudSdk cloudSdk = new CloudSdk.Builder().sdkPath(sdkHome).build(); Gcloud.builder(cloudSdk) .build() .runCommand(Arrays.asList("app", "services", "delete", "standard-project", "--quiet")); }
Example #30
Source File: CloudSdkModifyJob.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
/** Retrieve the version of the Cloud SDK at the provided location. */ protected static String getVersion(Path sdkPath) throws CloudSdkVersionFileException, CloudSdkNotFoundException { CloudSdk sdk = new CloudSdk.Builder().sdkPath(sdkPath).build(); return sdk.getVersion().toString(); }