diff --git a/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt b/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt index a12c4e3c1b5a..41fd630be841 100644 --- a/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt +++ b/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt @@ -27,18 +27,21 @@ class DoNotSaveDefaultsTest { val app = ApplicationManager.getApplication() as ApplicationImpl val directory = app.stateStore.stateStorageManager.expandMacros(APP_CONFIG) val dirPath = Paths.get(directory) + val useModCountOldValue = System.getProperty("store.save.use.modificationCount") try { + System.setProperty("store.save.use.modificationCount", "false") app.doNotSave(false) runInEdtAndWait { app.saveAll() } } finally { + System.setProperty("store.save.use.modificationCount", useModCountOldValue ?: "false") app.doNotSave(true) } println(directory) - println(printDirectoryTree(dirPath.toFile())) + println(printDirectoryTree(dirPath)) } } diff --git a/platform/configuration-store-impl/testSrc/FileTreePrinter.kt b/platform/configuration-store-impl/testSrc/FileTreePrinter.kt index 5919805a9eeb..aa2c5a0a1333 100644 --- a/platform/configuration-store-impl/testSrc/FileTreePrinter.kt +++ b/platform/configuration-store-impl/testSrc/FileTreePrinter.kt @@ -1,9 +1,11 @@ package com.intellij.configurationStore -import java.io.File +import com.intellij.util.io.directoryStreamIfExists +import com.intellij.util.io.isDirectory +import java.nio.file.Path -fun printDirectoryTree(folder: File): String { - if (!folder.isDirectory) { +fun printDirectoryTree(folder: Path): String { + if (!folder.isDirectory()) { throw IllegalArgumentException("folder is not a Directory") } val indent = 0 @@ -12,17 +14,17 @@ fun printDirectoryTree(folder: File): String { return sb.toString() } -private fun printDirectoryTree(folder: File, indent: Int, sb: StringBuilder) { - if (!folder.isDirectory) { +private fun printDirectoryTree(dir: Path, indent: Int, sb: StringBuilder) { + if (!dir.isDirectory()) { throw IllegalArgumentException("folder is not a Directory") } getIndentString(indent, sb) sb.append("\u251c\u2500\u2500") - sb.append(folder.name) + sb.append(dir.fileName.toString()) sb.append("/") sb.append("\n") - for (file in folder.listFiles()!!) { - if (file.isDirectory) { + for (file in dir.directoryStreamIfExists { it.map { it } }!!) { + if (file.isDirectory()) { printDirectoryTree(file, indent + 1, sb) } else { @@ -31,10 +33,10 @@ private fun printDirectoryTree(folder: File, indent: Int, sb: StringBuilder) { } } -private fun printFile(file: File, indent: Int, sb: StringBuilder) { +private fun printFile(file: Path, indent: Int, sb: StringBuilder) { getIndentString(indent, sb) sb.append("\u251c\u2500\u2500") - sb.append(file.name) + sb.append(file.fileName.toString()) sb.append("\n") } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java index 07f4f77847d6..837fdf59a446 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/UsageStatisticsPersistenceComponent.java @@ -29,7 +29,6 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Map; import java.util.Set; @@ -66,9 +65,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste @Override public void loadState(final Element element) { - List groupsList = element.getChildren(GROUP_TAG); - for (Object project : groupsList) { - Element groupElement = (Element)project; + for (Element groupElement : element.getChildren(GROUP_TAG)) { String groupId = groupElement.getAttributeValue(GROUP_ID_ATTR); double groupPriority = getPriority(groupElement.getAttributeValue(GROUP_PRIORITY_ATTR)); @@ -76,14 +73,15 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) { try { getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData)); - } catch (AssertionError e) { + } + catch (AssertionError e) { //don't load incorrect groups } } } try { - setSentTime(Long.parseLong(element.getAttributeValue(LAST_TIME_ATTR))); + setSentTime(Long.parseLong(element.getAttributeValue(LAST_TIME_ATTR, "0"))); } catch (NumberFormatException e) { setSentTime(0); @@ -102,8 +100,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste public Element getState() { Element element = new Element("state"); - for (Map.Entry> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages()) - .entrySet()) { + for (Map.Entry> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages()).entrySet()) { Element projectElement = new Element(GROUP_TAG); projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId()); projectElement.setAttribute(GROUP_PRIORITY_ATTR, Double.toString(entry.getKey().getPriority())); @@ -112,10 +109,20 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste element.addContent(projectElement); } - element.setAttribute(LAST_TIME_ATTR, String.valueOf(getLastTimeSent())); - element.setAttribute(IS_ALLOWED_ATTR, String.valueOf(isAllowed())); - element.setAttribute(SHOW_NOTIFICATION_ATTR, String.valueOf(isShowNotification())); - element.setAttribute(PERIOD_ATTR, myPeriod.getName()); + long lastTimeSent = getLastTimeSent(); + if (lastTimeSent > 0) { + element.setAttribute(LAST_TIME_ATTR, String.valueOf(lastTimeSent)); + } + + if (isAllowed()) { + element.setAttribute(IS_ALLOWED_ATTR, "true"); + } + if (isShowNotification()) { + element.setAttribute(SHOW_NOTIFICATION_ATTR, "true"); + } + if (myPeriod != SendPeriod.WEEKLY) { + element.setAttribute(PERIOD_ATTR, myPeriod.getName()); + } return element; }