From 21563774b5066c9a05317669e593814cea2b17e3 Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Mon, 19 Aug 2024 14:26:47 +0800 Subject: [PATCH] =?UTF-8?q?SibTool=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=89=8B=E6=9C=BAios=E7=B3=BB=E7=BB=9F=E6=98=AF=E5=90=A6>=3D17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/bridge/ios/CompareVersionUtil.java | 37 ++++++++++++ .../cloud/sonic/agent/bridge/ios/SibTool.java | 10 ++++ .../bridge/ios/CompareVersionUtilTest.java | 60 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 src/main/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtil.java create mode 100644 src/test/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtilTest.java diff --git a/src/main/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtil.java b/src/main/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtil.java new file mode 100644 index 00000000..15929ed2 --- /dev/null +++ b/src/main/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtil.java @@ -0,0 +1,37 @@ +package org.cloud.sonic.agent.bridge.ios; + +/** + * Created by fengbincao on 2024/08/19 + */ +public class CompareVersionUtil { + + /** + * 比较版本号的大小,前者大则返回一个正数,后者大返回一个负数,相等则返回0 + * + * @param version1 第一个版本号 + * @param version2 第二个版本号 + * @return 前者大则返回一个正数, 后者大返回一个负数, 相等则返回0 + */ + public static int compareVersion(String version1, String version2) { + String[] v1 = version1.split("\\."), v2 = version2.split("\\."); + int index = 0; + for (; index < v1.length && index < v2.length; index++) { + int v1n = Integer.parseInt(v1[index]), v2n = Integer.parseInt(v2[index]); + if (v1n > v2n) return 1; + if (v1n < v2n) return -1; + } + if (index < v1.length) { + for (; index < v1.length; index++) { + int v1n = Integer.parseInt(v1[index]); + if (v1n > 0) return 1; + } + } + if (index < v2.length) { + for (; index < v2.length; index++) { + int v2n = Integer.parseInt(v2[index]); + if (v2n > 0) return -1; + } + } + return 0; + } +} diff --git a/src/main/java/org/cloud/sonic/agent/bridge/ios/SibTool.java b/src/main/java/org/cloud/sonic/agent/bridge/ios/SibTool.java index 4bb4785b..7cdeca8d 100755 --- a/src/main/java/org/cloud/sonic/agent/bridge/ios/SibTool.java +++ b/src/main/java/org/cloud/sonic/agent/bridge/ios/SibTool.java @@ -1005,4 +1005,14 @@ public static void startShare(String udId, int port) { e.printStackTrace(); } } + + public static boolean isUpperThanIos17(String udId) { + JSONObject deviceInfoObj = IOSInfoMap.getDetailMap().get(udId); + if (deviceInfoObj != null && deviceInfoObj.containsKey("productVersion")) { + String productVersion = deviceInfoObj.getString("productVersion"); + return CompareVersionUtil.compareVersion(productVersion, "17.0") >= 0; + } + return false; + } + } diff --git a/src/test/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtilTest.java b/src/test/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtilTest.java new file mode 100644 index 00000000..3835c639 --- /dev/null +++ b/src/test/java/org/cloud/sonic/agent/bridge/ios/CompareVersionUtilTest.java @@ -0,0 +1,60 @@ +package org.cloud.sonic.agent.bridge.ios; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by fengbincao on 2024/08/19 + */ +public class CompareVersionUtilTest { + @Test + public void compareVersion1() { + String version1 = "17.1.0"; + String version2 = "17.0.0"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0); + } + + @Test + public void compareVersion2() { + String version1 = "17.1.0"; + String version2 = "17"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0); + } + + @Test + public void compareVersion3() { + String version1 = "17.1"; + String version2 = "17.0"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0); + } + + @Test + public void compareVersion4() { + String version1 = "17.0.0"; + String version2 = "17"; + assertEquals(0, CompareVersionUtil.compareVersion(version1, version2)); + } + + @Test + public void compareVersion5() { + String version1 = "16.8"; + String version2 = "17.0"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) < 0); + } + + @Test + public void compareVersion6() { + String version1 = "16"; + String version2 = "17"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) < 0); + } + + @Test + public void compareVersion7() { + String version1 = "18.0.1"; + String version2 = "17.0"; + Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0); + } +} \ No newline at end of file