@Nullable @Override public Path getSdkHomePath() { switch (sdkStatus) { case READY: return managedCloudSdk.getSdkHome(); default: return null; } }
/** Mocks managed SDK as if installed and having App Engine Component. */ private void makeMockSdkInstalled(Path mockSdkPath) { try { when(mockManagedCloudSdk.isInstalled()).thenReturn(true); when(mockManagedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA)).thenReturn(true); when(mockManagedCloudSdk.getSdkHome()).thenReturn(mockSdkPath); } catch (Exception ex) { // shouldn't happen in the tests. throw new AssertionError(ex); } }
/** Mocks successful installation process with all steps included (SDK, App Engine Java). */ private void emulateMockSdkInstallationProcess(Path mockSdkPath) { try { when(mockManagedCloudSdk.isInstalled()).thenReturn(false); SdkInstaller mockInstaller = mock(SdkInstaller.class); when(mockManagedCloudSdk.newInstaller()).thenReturn(mockInstaller); when(mockInstaller.install(any(), any())).thenReturn(mockSdkPath); when(mockManagedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA)).thenReturn(false); SdkComponentInstaller mockComponentInstaller = mock(SdkComponentInstaller.class); when(mockManagedCloudSdk.newComponentInstaller()).thenReturn(mockComponentInstaller); when(mockManagedCloudSdk.getSdkHome()).thenReturn(mockSdkPath); } catch (Exception ex) { // shouldn't happen in the tests. throw new AssertionError(ex); } }
@Test public void testNewManagedSdk_null() throws UnsupportedOsException, BadCloudSdkVersionException { // There's no way of testing for direct ManagedCloudSdk equality, so compare home paths ManagedCloudSdk sdk = new ManagedCloudSdkFactory(null).newManagedSdk(); Assert.assertEquals(ManagedCloudSdk.newManagedSdk().getSdkHome(), sdk.getSdkHome()); }
@Test public void testNewManagedSdk_specific() throws UnsupportedOsException, BadCloudSdkVersionException { ManagedCloudSdk sdk = new ManagedCloudSdkFactory("191.0.0").newManagedSdk(); Assert.assertEquals( ManagedCloudSdk.newManagedSdk(new Version("191.0.0")).getSdkHome(), sdk.getSdkHome()); } }
private void configureFactories() { project.afterEvaluate( projectAfterEvaluated -> { try { if (toolsExtension.getCloudSdkHome() == null) { managedCloudSdk = new ManagedCloudSdkFactory(toolsExtension.getCloudSdkVersion()).newManagedSdk(); toolsExtension.setCloudSdkHome(managedCloudSdk.getSdkHome().toFile()); } } catch (UnsupportedOsException ex) { throw new RuntimeException(ex.getMessage(), ex); } catch (BadCloudSdkVersionException ex) { throw new RuntimeException( "Failed to auto-configure Cloud Sdk at cloudSdkVersion = '" + toolsExtension.getCloudSdkVersion() + "': " + ex.getMessage(), ex); } try { cloudSdkOperations = new CloudSdkOperations( toolsExtension.getCloudSdkHome(), toolsExtension.getServiceAccountKeyFile()); } catch (CloudSdkNotFoundException ex) { // this should never happen, not found exception only occurs when auto-discovery fails, // but we don't use that mechanism anymore. throw new AssertionError("Failed when attempting to discover SDK: ", ex); } }); }
return managedCloudSdk.getSdkHome(); } catch (IOException | SdkInstallerException