From f8221d1e8708b94bf64d437cbf241c25b456ba8b Mon Sep 17 00:00:00 2001 From: Groboclown Date: Fri, 28 Aug 2020 12:11:46 -0500 Subject: [PATCH] Fix the compatibility check to work with JetBrains 2020.2.1 (which reports the minor version as 2.1, which is a bug) and Android Studio 4.0; bug #214 --- CHANGES.md | 11 +++++ .../groboclown/p4plugin/extension/P4Vcs.java | 4 +- .../p4plugin/messages/CompatibilityCheck.java | 44 +++++++++---------- .../src/main/resources/META-INF/plugin.xml | 15 ++----- .../groboclown/p4plugin/P4Bundle.properties | 2 +- .../messages/CompatibilityCheckTest.java | 10 +++-- 6 files changed, 46 insertions(+), 40 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 65ba37fa..efbab341 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,17 @@ # IDEA Community VCS Integration for Perforce +## ::v0.11.2:: + +### Overview + +* Bug fixes + +### Details + +* Fixed the version compatibility check to work with IDE 2020.2.1 (minor version was reported as "2.1") and with Android Studio 4.0. Now, the check instead informs the user about the build number, which should be universal across IDEs. + + ## ::v0.11.1:: ### Overview diff --git a/plugin-v3/src/main/java/net/groboclown/p4plugin/extension/P4Vcs.java b/plugin-v3/src/main/java/net/groboclown/p4plugin/extension/P4Vcs.java index fdb3058a..fdc00ac0 100644 --- a/plugin-v3/src/main/java/net/groboclown/p4plugin/extension/P4Vcs.java +++ b/plugin-v3/src/main/java/net/groboclown/p4plugin/extension/P4Vcs.java @@ -286,7 +286,9 @@ protected void activate() { appMessageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(); CompatibilityCheck.checkCompatibility(myProject, - ApplicationInfo.getInstance().getMajorVersion(), ApplicationInfo.getInstance().getMinorVersion()); + ApplicationInfo.getInstance().getMajorVersion(), + ApplicationInfo.getInstance().getMinorVersion(), + ApplicationInfo.getInstance().getBuild()); // If additional actions need to happen at plugin startup time, add them here to execute in // a background thread. diff --git a/plugin-v3/src/main/java/net/groboclown/p4plugin/messages/CompatibilityCheck.java b/plugin-v3/src/main/java/net/groboclown/p4plugin/messages/CompatibilityCheck.java index a9ed61fc..815c9540 100644 --- a/plugin-v3/src/main/java/net/groboclown/p4plugin/messages/CompatibilityCheck.java +++ b/plugin-v3/src/main/java/net/groboclown/p4plugin/messages/CompatibilityCheck.java @@ -17,6 +17,7 @@ import com.intellij.notification.NotificationType; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.BuildNumber; import net.groboclown.p4plugin.P4Bundle; import org.jetbrains.annotations.NotNull; @@ -28,39 +29,34 @@ public class CompatibilityCheck { private static final Logger LOG = Logger.getInstance(CompatibilityCheck.class); - // These major version / minor version use the "2018.2" format, rather than the "182.0" format. - private static final int DEPRECATED_SUPPORT__MAJOR = 2018; - private static final int DEPRECATED_SUPPORT__MINOR = 2; - private static final String MINIMUM_VERSION = DEPRECATED_SUPPORT__MAJOR + "." + DEPRECATED_SUPPORT__MINOR; + // Baseline is the API version, which is compatible across Android Studio and the JetBrains tools. + // Android uses a "4.0" style numbering for major / minor, while JetBrains uses "2018.2" format. + private static final int DEPRECATED_SUPPORT__BASELINE = 182; - public static void checkCompatibility(@NotNull Project project, String majorVersion, String minorVersion) { - if (!isIdeaVersionValid(majorVersion, minorVersion)) { + public static void checkCompatibility(@NotNull Project project, String majorVersion, String minorVersion, + BuildNumber build) { + if (!isIdeaVersionValid(majorVersion, minorVersion, build)) { UserMessage.showNotification(project, UserMessage.WARNING, - P4Bundle.message("ide.compatibility.message", majorVersion, minorVersion, MINIMUM_VERSION), + P4Bundle.message("ide.compatibility.message", + majorVersion, minorVersion, build.getProductCode(), build.getBaselineVersion(), + DEPRECATED_SUPPORT__BASELINE), P4Bundle.message("ide.compatibility.title"), NotificationType.WARNING); } } - static boolean isIdeaVersionValid(String majorStr, String minorStr) { - LOG.warn("IDE version: " + majorStr + "." + minorStr); - try { - int major = Integer.parseInt(majorStr); - int minor = Integer.parseInt(minorStr); - if (major > DEPRECATED_SUPPORT__MAJOR) { - // It's a supported version for a while. - return true; - } - if (major == DEPRECATED_SUPPORT__MAJOR && minor >= DEPRECATED_SUPPORT__MINOR) { - // It's a supported version for a while - return true; - } - return false; - } catch (NumberFormatException e) { - LOG.error("Invalid IDE version numbers: " + majorStr + "." + minorStr); - return false; + static boolean isIdeaVersionValid(String majorStr, String minorStr, BuildNumber build) { + LOG.warn("IDE version: " + majorStr + "." + minorStr + "; product version " + + build.getProductCode() + "-" + build.getBaselineVersion()); + if (build.getBaselineVersion() > DEPRECATED_SUPPORT__BASELINE) { + return true; } + + // It's been noticed that the minor version can include a patch. That's probably an IDE bug, + // but we still need to account for it. + // That said, the baseline version of the build is sufficient to check. + return false; } } diff --git a/plugin-v3/src/main/resources/META-INF/plugin.xml b/plugin-v3/src/main/resources/META-INF/plugin.xml index 99a746a0..21e3b9cb 100644 --- a/plugin-v3/src/main/resources/META-INF/plugin.xml +++ b/plugin-v3/src/main/resources/META-INF/plugin.xml @@ -1,26 +1,19 @@ Perforce IDEA Community Integration PerforceIC - 0.11.1 + 0.11.2 VCS Integration +
  • 0.11.2
      +
    • Fixed compatiblity check to handle JetBrains 2020.2.1 and Android Studio 4.0.
    • +
  • 0.11.1
    • Fixed a bug related to an NPE on a cached component.
    • Fixed a bug where the encoding from the Perforce server wasn't supported by Java (specifically, `utf8-bom`). It now tries to strip the "-bom" off, then will resort to the default enocding of the local computer.
  • -
  • 0.11.0
      -
    • Added a warning for users with an IDE before 2018.2. Compatibility with these versions will be removed soon.
    • -
    • Upgraded many library dependency versions.
    • -
    • Created a bill of materials.
    • -
    • Added some p4ignore compatibility.
    • -
    • Improved charset interpretation. Now, there's a user preference to select the setting of file encoding - - the default is to use whatever the server has. Other options are to use what the IDE thinks is the file - encoding, or use the client configured value (P4CHARSET).
    • -
    • Various build improvements.
    • -
  • ]]>