From d981f624e259b25e1af88baf7ff3532cdf475d47 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 23 Jul 2018 19:05:02 +0200 Subject: [PATCH] Cleanup (update info classes API) --- .../impl/CheckForUpdateResult.java | 23 +++++------------- .../updateSettings/impl/UpdateChecker.kt | 4 ++-- .../openapi/updateSettings/impl/UpdateInfo.kt | 12 ++++++---- .../updateSettings/impl/UpdateStrategy.kt | 24 +++---------------- .../ide/updates/UpdateStrategyTest.kt | 6 ++--- 5 files changed, 21 insertions(+), 48 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java index e7a26c3324f7..9f89ee472c76 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateResult.java @@ -1,8 +1,6 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.updateSettings.impl; -import com.intellij.openapi.util.BuildNumber; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,42 +10,33 @@ public class CheckForUpdateResult { private final UpdateChannel myUpdatedChannel; private final Exception myError; - public CheckForUpdateResult(@Nullable BuildInfo newBuild, @Nullable UpdateChannel updatedChannel) { + CheckForUpdateResult(@Nullable BuildInfo newBuild, @Nullable UpdateChannel updatedChannel) { myState = UpdateStrategy.State.LOADED; myNewBuild = newBuild; myUpdatedChannel = updatedChannel; myError = null; } - public CheckForUpdateResult(@NotNull UpdateStrategy.State state, @Nullable Exception e) { + CheckForUpdateResult(@NotNull UpdateStrategy.State state, @Nullable Exception e) { myState = state; myNewBuild = null; myUpdatedChannel = null; myError = e; } - @NotNull - public UpdateStrategy.State getState() { + public @NotNull UpdateStrategy.State getState() { return myState; } - @Nullable - public BuildInfo getNewBuild() { + public @Nullable BuildInfo getNewBuild() { return myNewBuild; } - @Nullable - public PatchInfo findPatchForBuild(@NotNull BuildNumber build) { - return myNewBuild == null ? null : ContainerUtil.find(myNewBuild.getPatches(), p -> p.isAvailable() && p.getFromBuild().compareTo(build) == 0); - } - - @Nullable - public UpdateChannel getUpdatedChannel() { + public @Nullable UpdateChannel getUpdatedChannel() { return myUpdatedChannel; } - @Nullable - public Exception getError() { + public @Nullable Exception getError() { return myError; } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt index 4f36d88a1457..954ceb4404f5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt @@ -390,7 +390,7 @@ object UpdateChecker { if (updatedChannel != null && newBuild != null) { val runnable = { - val patch = checkForUpdateResult.findPatchForBuild(ApplicationInfo.getInstance().build) + val patch = newBuild.patch(ApplicationInfo.getInstance().build) val forceHttps = updateSettings.canUseSecureConnection() UpdateInfoDialog(updatedChannel, newBuild, patch, enableLink, forceHttps, updatedPlugins, incompatiblePlugins).show() } @@ -561,7 +561,7 @@ object UpdateChecker { val checkForUpdateResult = strategy.checkForUpdates() channel = checkForUpdateResult.updatedChannel newBuild = checkForUpdateResult.newBuild - patch = checkForUpdateResult.findPatchForBuild(ApplicationInfo.getInstance().build) + patch = newBuild?.patch(ApplicationInfo.getInstance().build) } if (channel != null && newBuild != null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfo.kt b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfo.kt index 40e05559e670..89a5deeecc90 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfo.kt +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfo.kt @@ -17,7 +17,7 @@ class UpdatesInfo(node: Element) { operator fun get(code: String): Product? = products.find { code in it.codes } } -class Product(node: Element) { +class Product internal constructor (node: Element) { val name: String = node.getMandatoryAttributeValue("name") val codes: Set = node.getChildren("code").map { it.value.trim() }.toSet() val channels: List = node.getChildren("channel").map(::UpdateChannel) @@ -25,7 +25,7 @@ class Product(node: Element) { override fun toString(): String = codes.firstOrNull() ?: "-" } -class UpdateChannel(node: Element) { +class UpdateChannel internal constructor (node: Element) { companion object { const val LICENSING_EAP: String = "eap" const val LICENSING_RELEASE: String = "release" @@ -40,7 +40,7 @@ class UpdateChannel(node: Element) { override fun toString(): String = id } -class BuildInfo(node: Element) { +class BuildInfo internal constructor (node: Element) { val number: BuildNumber = parseBuildNumber(node.getMandatoryAttributeValue("fullNumber", "number")) val apiVersion: BuildNumber = BuildNumber.fromStringWithProductCode(node.getAttributeValue("apiVersion"), number.productCode) ?: number val version: String = node.getAttributeValue("version") ?: "" @@ -72,10 +72,12 @@ class BuildInfo(node: Element) { val downloadUrl: String? get() = buttons.find(ButtonInfo::isDownload)?.url + fun patch(to: BuildNumber) = patches.find { it.isAvailable && it.fromBuild.compareTo(to) == 0 } + override fun toString(): String = "${number}/${version}" } -class ButtonInfo(node: Element) { +class ButtonInfo internal constructor (node: Element) { val name: String = node.getMandatoryAttributeValue("name") val url: String = node.getMandatoryAttributeValue("url") val isDownload: Boolean = node.getAttributeValue("download") != null // a button marked with this attribute is hidden when a patch is available @@ -83,7 +85,7 @@ class ButtonInfo(node: Element) { override fun toString(): String = name } -class PatchInfo(node: Element) { +class PatchInfo internal constructor (node: Element) { val fromBuild: BuildNumber = BuildNumber.fromString(node.getMandatoryAttributeValue("fullFrom", "from")) val size: String? = node.getAttributeValue("size") val isAvailable: Boolean = node.getAttributeValue("exclusions")?.splitToSequence(",")?.none { it.trim() == osSuffix } ?: true diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.kt b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.kt index 516c9444f73e..1a578cb8318e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.kt +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.updateSettings.impl import com.intellij.openapi.updateSettings.UpdateStrategyCustomization @@ -56,13 +42,11 @@ class UpdateStrategy(private val currentBuild: BuildNumber, private val updates: else n1.compareTo(n2) // - @Deprecated("use {@link #UpdateStrategy(BuildNumber, UpdatesInfo, UserUpdateSettings)}") constructor(@Suppress("UNUSED_PARAMETER") majorVersion: Int, @Suppress("UNUSED_PARAMETER") currentBuild: BuildNumber, @Suppress("UNUSED_PARAMETER") updatesInfo: UpdatesInfo, - @Suppress("UNUSED_PARAMETER") updateSettings: UserUpdateSettings) : this(currentBuild, updatesInfo, updateSettings) { - } + @Suppress("UNUSED_PARAMETER") updateSettings: UserUpdateSettings) : this(currentBuild, updatesInfo, updateSettings) @Deprecated("use {@link #UpdateStrategy(BuildNumber, UpdatesInfo, UserUpdateSettings)}") @@ -70,8 +54,6 @@ class UpdateStrategy(private val currentBuild: BuildNumber, private val updates: @Suppress("UNUSED_PARAMETER") currentBuild: BuildNumber, @Suppress("UNUSED_PARAMETER") updatesInfo: UpdatesInfo, @Suppress("UNUSED_PARAMETER") updateSettings: UserUpdateSettings, - @Suppress("UNUSED_PARAMETER") customization: UpdateStrategyCustomization) : this(currentBuild, updatesInfo, updateSettings) { - } - + @Suppress("UNUSED_PARAMETER") customization: UpdateStrategyCustomization) : this(currentBuild, updatesInfo, updateSettings) // } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt index 93eb379f23c5..11a15b3a73aa 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/updates/UpdateStrategyTest.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.updates import com.intellij.openapi.updateSettings.impl.* @@ -36,8 +36,8 @@ class UpdateStrategyTest : BareTestFixtureTestCase() { """) - assertNotNull(result.findPatchForBuild(BuildNumber.fromString("145.596"))) - assertNull(result.findPatchForBuild(BuildNumber.fromString("145.258"))) + assertNotNull(result.newBuild?.patch(BuildNumber.fromString("145.596"))) + assertNull(result.newBuild?.patch(BuildNumber.fromString("145.258"))) } @Test fun `order of builds does not matter`() {