SdkUpdaterConfigurable implements SearchableConfigurable { @VisibleForTesting static Pair<HtmlBuilder, HtmlBuilder> getDiskUsageMessages(@Nullable File sdkRoot, long fullInstallationsDownloadSize, long patchesDownloadSize, long spaceToBeFreedUp) { HtmlBuilder message = new HtmlBuilder(); message.add("Disk usage:\n"); boolean issueDiskSpaceWarning = false; message.beginList(); if (spaceToBeFreedUp > 0) { message.listItem().add("Disk space that will be freed: " + new Storage(spaceToBeFreedUp).toUiString()); } long totalDownloadSize = patchesDownloadSize + fullInstallationsDownloadSize; if (totalDownloadSize > 0) { message.listItem().add("Estimated download size: " + new Storage(totalDownloadSize).toUiString()); long sdkRootUsageAfterInstallation = patchesDownloadSize + ESTIMATED_ZIP_DECOMPRESSION_RATE * fullInstallationsDownloadSize - spaceToBeFreedUp; message.listItem().add("Estimated disk space to be additionally occupied on SDK partition after installation: " + new Storage(sdkRootUsageAfterInstallation).toUiString()); if (sdkRoot != null) { long sdkRootUsableSpace = sdkRoot.getUsableSpace(); message.listItem().add(String.format("Currently available disk space in SDK root (%1$s): %2$s", sdkRoot.getAbsolutePath(), new Storage(sdkRootUsableSpace).toUiString())); long totalSdkUsableSpace = sdkRootUsableSpace + spaceToBeFreedUp; issueDiskSpaceWarning = (totalSdkUsableSpace < sdkRootUsageAfterInstallation); } } message.endList(); if (issueDiskSpaceWarning) { HtmlBuilder warningMessage = new HtmlBuilder(); warningMessage.beginColor(JBColor.RED) .addBold("WARNING: There might be insufficient disk space to perform this operation. ") .newline().newline() .add("Estimated disk usage is presented below. ") .add("Consider freeing up more disk space before proceeding. ") .endColor() .newline().newline(); return Pair.of(message, warningMessage); } return Pair.of(message, null); }  @NotNull @Override String getId(); @Nls @Override String getDisplayName(); @Nullable @Override String getHelpTopic(); @Nullable @Override JComponent createComponent(); @Override boolean isModified(); @Override void apply(); @Override void reset(); @Override void disposeUIResources();  }
@Test public void testDiskSpaceMessagesFullAndPatchAndUninstall() throws Exception { final long fullInstallationDownloadSize = 70 * 1024 * 1024L + 42; final long patchesDownloadSize = 20 * 1024 * 1024L + 42; final long spaceToBeFreedUp = 10 * 1024 * 1024L + 42; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE, "10.0 MB", "90.0 MB", "290.0 MB", "1.0 GB"), messages.getFirst().getHtml()); assertNull(messages.getSecond()); }
@Test public void testDiskSpaceMessagesFullAndUninstall() throws Exception { final long fullInstallationDownloadSize = 70 * 1024 * 1024L + 42; final long patchesDownloadSize = 0; final long spaceToBeFreedUp = 10 * 1024 * 1024L + 42; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE, "10.0 MB", "70.0 MB", "270.0 MB", "1.0 GB"), messages.getFirst().getHtml()); assertNull(messages.getSecond()); }
@Test public void testDiskSpaceMessagesPatchAndUninstall() throws Exception { final long fullInstallationDownloadSize = 0; final long patchesDownloadSize = 20 * 1024 * 1024L + 42; final long spaceToBeFreedUp = 9 * 1024 * 1024L + 42; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE, "9.0 MB", "20.0 MB", "11.0 MB", "1.0 GB"), messages.getFirst().getHtml()); assertNull(messages.getSecond()); }
@Test public void testDiskSpaceMessagesPatchAndUninstallWhenInsufficientSpace() throws Exception { final long fullInstallationDownloadSize = 0; final long patchesDownloadSize = 1200 * 1024 * 1024L + 42; final long spaceToBeFreedUp = 9 * 1024 * 1024L + 42; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE, "9.0 MB", "1.2 GB", "1.2 GB", "1.0 GB"), messages.getFirst().getHtml()); assertEquals(WARNING_HTML, messages.getSecond().getHtml()); }
@Test public void testDiskSpaceMessagesPatchWhenInsufficientSpace() throws Exception { final long fullInstallationDownloadSize = 0; final long patchesDownloadSize = 1200*1024*1024L + 42; final long spaceToBeFreedUp = 0; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE_WITHOUT_SPACE_TO_FREE_UP, "1.2 GB", "1.2 GB", "1.0 GB"), messages.getFirst().getHtml()); assertEquals(WARNING_HTML, messages.getSecond().getHtml()); }
@Test public void testDiskSpaceMessagesUninstallOnly() throws Exception { final long fullInstallationDownloadSize = 0; final long patchesDownloadSize = 0; final long spaceToBeFreedUp = 800*1024*1024L + 42; Pair<HtmlBuilder, HtmlBuilder> messages = SdkUpdaterConfigurable.getDiskUsageMessages(mySdkRoot, fullInstallationDownloadSize, patchesDownloadSize, spaceToBeFreedUp); assertEquals(String.format(DISK_USAGE_HTML_TEMPLATE_WITHOUT_DOWNLOADS, "800.0 MB"), messages.getFirst().getHtml()); assertNull(messages.getSecond()); }