com.google.cloud.tools.managedcloudsdk.ManagedCloudSdk Java Examples

The following examples show how to use com.google.cloud.tools.managedcloudsdk.ManagedCloudSdk. 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: CloudSdkPreferenceResolver.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public Path getCloudSdkPath() {
  // We only consult the Managed Cloud SDK when it has been explicitly configured, which
  // is done in CloudSdkPreferences.
  if (CloudSdkPreferences.isAutoManaging()) {
    try {
      // It is assumed that clients do not get and use "CloudSdk" while it is being modified.
      return ManagedCloudSdk.newManagedSdk().getSdkHome();
    } catch (UnsupportedOsException ex) {
      logger.log(Level.SEVERE, "Google Cloud SDK not available", ex); // $NON-NLS-1$
      return null;
    }
  }
  String value = preferences.getString(CloudSdkPreferences.CLOUD_SDK_PATH);
  if (!Strings.isNullOrEmpty(value)) {
    return Paths.get(value);
  }
  return null;
}
 
Example #2
Source File: AppEngineAppYamlPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
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 #3
Source File: AppEngineStandardPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: ManagedCloudSdkFactory.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
/** Build a new ManagedCloudSdk from a given version. */
public ManagedCloudSdk newManagedSdk()
    throws UnsupportedOsException, BadCloudSdkVersionException {
  if (Strings.isNullOrEmpty(version)) {
    return ManagedCloudSdk.newManagedSdk();
  } else {
    return ManagedCloudSdk.newManagedSdk(new Version(version));
  }
}
 
Example #5
Source File: ManagedCloudSdkFactoryTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #6
Source File: CloudSdkInstallJobTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private CloudSdkInstallJob newCloudSdkInstallJob() {
  return new CloudSdkInstallJob(consoleStream, new ReentrantReadWriteLock(), IStatus.WARNING) {
    @Override
    protected ManagedCloudSdk getManagedCloudSdk() throws UnsupportedOsException {
      return managedCloudSdk;
    }
  };
}
 
Example #7
Source File: CloudSdkUpdateJobTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private CloudSdkUpdateJob newCloudSdkUpdateJob() {
  return new CloudSdkUpdateJob(consoleStream, new ReentrantReadWriteLock()) {
    @Override
    protected ManagedCloudSdk getManagedCloudSdk() throws UnsupportedOsException {
      return managedCloudSdk;
    }
  };
}
 
Example #8
Source File: ManagedCloudSdkStartup.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void checkInstallation(
    CloudSdkManager manager, ManagedCloudSdk installation, IProgressMonitor monitor)
    throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException {
  if (!installation.isInstalled()) {
    CloudSdkInstallNotification.showNotification(workbench, manager::installManagedSdkAsync);
  } else if (!installation.isUpToDate()) {
    CloudSdkVersion currentVersion = getVersion(installation.getSdkHome());
    CloudSdkUpdateNotification.showNotification(
        workbench, currentVersion, manager::updateManagedSdkAsync);
  }
}
 
Example #9
Source File: CloudSdkDownloader.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
static Function<String, ManagedCloudSdk> newManagedSdkFactory() {
  return (version) -> {
    try {
      if (Strings.isNullOrEmpty(version)) {
        return ManagedCloudSdk.newManagedSdk();
      } else {
        return ManagedCloudSdk.newManagedSdk(new Version(version));
      }
    } catch (UnsupportedOsException | BadCloudSdkVersionException ex) {
      throw new RuntimeException(ex);
    }
  };
}
 
Example #10
Source File: CloudSdkDownloaderTest.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewManagedSdk_specific()
    throws UnsupportedOsException, BadCloudSdkVersionException {
  ManagedCloudSdk sdk = CloudSdkDownloader.newManagedSdkFactory().apply("191.0.0");
  Assert.assertEquals(
      ManagedCloudSdk.newManagedSdk(new Version("191.0.0")).getSdkHome(), sdk.getSdkHome());
}
 
Example #11
Source File: DownloadCloudSdkTask.java    From app-gradle-plugin with Apache License 2.0 4 votes vote down vote up
public void setManagedCloudSdk(ManagedCloudSdk managedCloudSdk) {
  this.managedCloudSdk = managedCloudSdk;
}
 
Example #12
Source File: ManagedCloudSdkFactoryTest.java    From app-gradle-plugin with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example #13
Source File: CloudSdkModifyJob.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected ManagedCloudSdk getManagedCloudSdk() throws UnsupportedOsException {
  return ManagedCloudSdk.newManagedSdk();
}
 
Example #14
Source File: CloudSdkDownloader.java    From app-maven-plugin with Apache License 2.0 4 votes vote down vote up
public CloudSdkDownloader(Function<String, ManagedCloudSdk> managedCloudSdkFactory) {
  this.managedCloudSdkFactory = managedCloudSdkFactory;
}
 
Example #15
Source File: CloudSdkDownloader.java    From app-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Downloads/installs/updates the Cloud SDK.
 *
 * @return The cloud SDK installation directory
 */
public Path downloadIfNecessary(
    String version, Log log, List<SdkComponent> components, boolean offline) {
  ManagedCloudSdk managedCloudSdk = managedCloudSdkFactory.apply(version);
  if (offline) { // in offline mode, don't download anything
    return managedCloudSdk.getSdkHome();
  }
  try {
    ProgressListener progressListener = new NoOpProgressListener();
    ConsoleListener consoleListener = new CloudSdkDownloaderConsoleListener(log);

    if (!managedCloudSdk.isInstalled()) {
      managedCloudSdk.newInstaller().install(progressListener, consoleListener);
    }

    // install requested components
    if (components != null) {
      for (SdkComponent component : components) {
        if (!managedCloudSdk.hasComponent(component)) {
          managedCloudSdk
              .newComponentInstaller()
              .installComponent(component, progressListener, consoleListener);
        }
      }
    }

    if (!managedCloudSdk.isUpToDate()) {
      managedCloudSdk.newUpdater().update(progressListener, consoleListener);
    }

    return managedCloudSdk.getSdkHome();
  } catch (IOException
      | SdkInstallerException
      | ManagedSdkVersionMismatchException
      | InterruptedException
      | CommandExecutionException
      | CommandExitException
      | ManagedSdkVerificationException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #16
Source File: CloudSdkDownloaderTest.java    From app-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testNewManagedSdk_null() throws UnsupportedOsException {
  // There's no way of testing for direct ManagedCloudSdk equality, so compare home paths
  ManagedCloudSdk sdk = CloudSdkDownloader.newManagedSdkFactory().apply(null);
  Assert.assertEquals(ManagedCloudSdk.newManagedSdk().getSdkHome(), sdk.getSdkHome());
}