mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (update info classes API)
This commit is contained in:
+6
-17
@@ -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;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
@@ -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<String> = node.getChildren("code").map { it.value.trim() }.toSet()
|
||||
val channels: List<UpdateChannel> = 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
|
||||
|
||||
+3
-21
@@ -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)
|
||||
|
||||
//<editor-fold desc="Deprecated stuff.">
|
||||
|
||||
@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)
|
||||
//</editor-fold>
|
||||
}
|
||||
@@ -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() {
|
||||
<patch from="145.258" exclusions="win,mac,unix"/>
|
||||
</build>
|
||||
</channel>""")
|
||||
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`() {
|
||||
|
||||
Reference in New Issue
Block a user