com.google.cloud.tools.appengine.operations.cloudsdk.serialization.CloudSdkVersion Java Examples

The following examples show how to use com.google.cloud.tools.appengine.operations.cloudsdk.serialization.CloudSdkVersion. 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: CloudSdkUpdateNotificationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotTriggeredOnFade() {
  Runnable trigger = mock(Runnable.class);
  CloudSdkUpdateNotification notification =
      new CloudSdkUpdateNotification(workbench, new CloudSdkVersion("178.0.0"), trigger);
  // simulate fade away
  notification.open();
  notification.getShell().setAlpha(0);
  notification.close();
  verify(trigger, never()).run();
}
 
Example #2
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);
}
 
Example #3
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 #4
Source File: CloudSdkUpdateNotification.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
CloudSdkUpdateNotification(
    IWorkbench workbench, CloudSdkVersion sdkVersion, Runnable updateRunnable) {
  super(workbench.getDisplay());
  this.workbench = workbench;
  this.sdkVersion = sdkVersion;
  this.updateRunnable = updateRunnable;
}
 
Example #5
Source File: CloudSdkUpdateNotification.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Asynchronously shows a notification that an update is available.
 *
 * @param updateTrigger the action to take when selected; assumed to be short-lived
 */
public static void showNotification(
    IWorkbench workbench, CloudSdkVersion currentVersion, Runnable updateTrigger) {
  workbench
      .getDisplay()
      .asyncExec(
          () -> {
            CloudSdkUpdateNotification popup =
                new CloudSdkUpdateNotification(workbench, currentVersion, updateTrigger);
            popup.open(); // doesn't wait
          });
}
 
Example #6
Source File: ManagedCloudSdkStartup.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #7
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 #8
Source File: BugReportCommandHandlerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormatReportUrl() throws MalformedURLException {
  URL url = new URL(BugReportCommandHandler.formatReportUrl());

  assertEquals("https", url.getProtocol());
  assertEquals("github.com", url.getHost());
  assertEquals("/GoogleCloudPlatform/google-cloud-eclipse/issues/new", url.getPath());

  // check that values are properly filled in
  Pattern pattern =
      Pattern.compile(
          "body="
              + "%3C%21--%0ABefore\\+reporting\\+a\\+possible\\+bug%3A%0A%0A"
              + "1.\\+Please\\+ensure\\+you\\+are\\+running\\+the\\+latest\\+version\\+of\\+CT4E\\+with\\+_Help\\+%3E\\+Check\\+for\\+Updates_%0A"
              + "2.\\+If\\+the\\+problem\\+occurs\\+when\\+you\\+deploy\\+or\\+after\\+the\\+application\\+has\\+been\\+deployed%2C\\+try\\+deploying\\+from\\+the\\+command\\+line\\+using\\+gcloud\\+or\\+Maven."
              + "\\+If\\+the\\+problem\\+does\\+not\\+go\\+away%2C\\+then\\+the\\+issue\\+is\\+likely\\+not\\+with\\+Cloud\\+Tools\\+for\\+Eclipse.%0A--%3E%0A"
              + "-\\+Cloud\\+Tools\\+for\\+Eclipse\\+version%3A\\+(?<toolVersion>.*)%0A"
              + "-\\+Google\\+Cloud\\+SDK\\+version%3A\\+(?<gcloudVersion>[\\d.]*)\\+%28non-managed%29%0A"
              + "-\\+Eclipse\\+version%3A\\+(?<eclipseVersion>.*)%0A"
              + "-\\+OS%3A\\+(?<os>.*)%0A"
              + "-\\+Java\\+version%3A\\+(?<javaVersion>.*)%0A%0A"
              + "\\*\\*What\\+did\\+you\\+do%3F\\*\\*%0A%0A"
              + "\\*\\*What\\+did\\+you\\+expect\\+to\\+see%3F\\*\\*%0A%0A"
              + "\\*\\*What\\+did\\+you\\+see\\+instead%3F\\*\\*%0A%0A"
              + "%3C%21--\\+Screenshots\\+and\\+stacktraces\\+are\\+helpful.\\+--%3E");
  String query = url.getQuery();
  Matcher matcher = pattern.matcher(query);
  assertTrue(query, matcher.matches());
  String toolVersion = matcher.group("toolVersion");
  String gcloudVersion = matcher.group("gcloudVersion");
  String eclipseVersion = matcher.group("eclipseVersion");
  String os = matcher.group("os");
  String javaVersion = matcher.group("javaVersion");

  assertTrue(Pattern.compile("^\\d+\\.\\d+\\.\\d+").matcher(toolVersion).find());
  assertThat(javaVersion, anyOf(startsWith("1.7."), startsWith("1.8."), is("11"), startsWith("11.")));
  assertThat(os, anyOf(startsWith("Linux"), startsWith("Mac"), startsWith("Windows")));
  assertTrue(Pattern.compile("^\\d+\\.\\d+").matcher(eclipseVersion).find());
  new CloudSdkVersion(gcloudVersion); // throws IllegalArgumentException if invalid
}
 
Example #9
Source File: LocalAppEngineServerBehaviour.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * @return a short pithy description of this server suitable for use in UI elements
 */
public String getDescription() {
  if (cloudSdk != null) {
    try {
      CloudSdkVersion version = cloudSdk.getVersion();
      return Messages.getString("cloudsdk.server.description.version", version); //$NON-NLS-1$
    } catch (AppEngineException ex) {
      logger.log(Level.WARNING, "Unable to obtain CloudSdk version", ex); //$NON-NLS-1$
    }
  }
  return Messages.getString("cloudsdk.server.description"); //$NON-NLS-1$
}
 
Example #10
Source File: MessagesTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloudSdkUpdateNotificationMessage() {
  Assert.assertEquals(
      "<a href=\"update\">Update now</a> or from the Google Cloud Tools preference page."
          + " See the <a href=\"https://cloud.google.com/sdk/docs/release-notes\">release notes</a> for changes since 1.9.0.",
      Messages.getString("CloudSdkUpdateNotificationMessage", new CloudSdkVersion("1.9.0")));
}
 
Example #11
Source File: CloudSdkUpdateNotificationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotTriggeredOnCloseButton() {
  Runnable trigger = mock(Runnable.class);
  CloudSdkUpdateNotification notification =
      new CloudSdkUpdateNotification(workbench, new CloudSdkVersion("178.0.0"), trigger);
  notification.open();
  notification.close();
  verify(trigger, never()).run();
}
 
Example #12
Source File: CheckCloudSdkTaskTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: CloudSdkUpdateNotificationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testTriggeredOnUpdateLink() {
  Runnable trigger = mock(Runnable.class);
  CloudSdkUpdateNotification notification =
      new CloudSdkUpdateNotification(workbench, new CloudSdkVersion("178.0.0"), trigger);
  notification.linkSelected("update");
  verify(trigger).run();
}
 
Example #14
Source File: CloudSdkOutOfDateExceptionTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: CloudSdkOutOfDateExceptionTest.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: CloudSdkOutOfDateException.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
/**
 * Installed version is too old.
 *
 * @param installedVersion version of the Cloud SDK we found
 * @param requiredVersion minimum version of the Cloud SDK we want
 */
public CloudSdkOutOfDateException(
    CloudSdkVersion installedVersion, CloudSdkVersion requiredVersion) {
  super(
      "Requires version " + requiredVersion + " or later but found version " + installedVersion);
  this.requiredVersion = Preconditions.checkNotNull(requiredVersion);
  this.installedVersion = Preconditions.checkNotNull(installedVersion);
}
 
Example #17
Source File: CheckCloudSdkTaskTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: CheckCloudSdkTaskTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: CloudSdkTest.java    From appengine-plugins-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testMinimumCloudSdkVersion() {
  // 160.0 through 170.0 have serious bugs on Windows
  assertTrue(CloudSdk.MINIMUM_VERSION.compareTo(new CloudSdkVersion("181.0.0")) > 0);
}
 
Example #20
Source File: CloudSdkOutOfDateException.java    From appengine-plugins-core with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the version of the local cloud SDK if known, otherwise null.
 *
 * @return actual version of the Cloud SDK, or null if it's really old.
 */
@Nullable
public CloudSdkVersion getInstalledVersion() {
  return installedVersion;
}
 
Example #21
Source File: CloudSdkOutOfDateException.java    From appengine-plugins-core with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the minimum required version of the cloud SDK for the current operation.
 *
 * @return minimum acceptable version of the Cloud SDK
 */
public CloudSdkVersion getRequiredVersion() {
  return requiredVersion;
}
 
Example #22
Source File: CloudSdkOutOfDateException.java    From appengine-plugins-core with Apache License 2.0 2 votes vote down vote up
/**
 * Installed version predates version files in the Cloud SDK.
 *
 * @param requiredVersion minimum version of the Cloud SDK we want
 */
public CloudSdkOutOfDateException(CloudSdkVersion requiredVersion) {
  super(String.format(MESSAGE, requiredVersion.toString()));
  this.requiredVersion = requiredVersion;
}