Skip to content

Commit

Permalink
Fix the compatibility check to work with JetBrains 2020.2.1 (which re…
Browse files Browse the repository at this point in the history
…ports the minor version as 2.1, which is a bug) and Android Studio 4.0; bug #214
  • Loading branch information
groboclown committed Aug 28, 2020
1 parent 3ca1c71 commit f8221d1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
15 changes: 4 additions & 11 deletions plugin-v3/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<idea-plugin>
<name>Perforce IDEA Community Integration</name>
<id>PerforceIC</id>
<version>0.11.1</version>
<version>0.11.2</version>
<!-- see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html -->
<idea-version since-build="171"/>
<category>VCS Integration</category>
<change-notes><![CDATA[
<ul>
<li><em>0.11.2</em><ul>
<li>Fixed compatiblity check to handle JetBrains 2020.2.1 and Android Studio 4.0.</li>
</ul></li>
<li><em>0.11.1</em><ul>
<li>Fixed a bug related to an NPE on a cached component.</li>
<li>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.</li>
</ul></li>
<li><em>0.11.0</em><ul>
<li>Added a warning for users with an IDE before 2018.2. Compatibility with these versions will be removed soon.</li>
<li>Upgraded many library dependency versions.</li>
<li>Created a bill of materials.</li>
<li>Added some <tt>p4ignore</tt> compatibility.</li>
<li>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 (<tt>P4CHARSET</tt>).</li>
<li>Various build improvements.</li>
</ul></li>
</ul>
]]></change-notes>
<description><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,4 +724,4 @@ user.prefs.prefer-server-charset=Server Charset
user.prefs.prefer-config-charset=Client Configuration Charset
user.prefs.charset_display=Submit File Character Set Behavior
ide.compatibility.title=IDE Version Support Warning
ide.compatibility.message=Your IDE version ({0}.{1}) will be removed from supported versions in the next major version. Please upgrade your IDE to at least version {2}, or open a ticket with the project to recommend continued support.
ide.compatibility.message=Your IDE version ({0}.{1}, build {2}-{3}) will be removed from supported versions in the plugin's next major version. Please upgrade your IDE to at least build {2}-{4}, or open a ticket with the project to recommend continued support.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package net.groboclown.p4plugin.messages;

import com.intellij.openapi.util.BuildNumber;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -22,8 +23,11 @@ class CompatibilityCheckTest {
@Test
void checkAllOldVersionParsing() {
// pulled from http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
assertTrue(CompatibilityCheck.isIdeaVersionValid("2018", "2"));
assertFalse(CompatibilityCheck.isIdeaVersionValid("2017", "3"));
assertFalse(CompatibilityCheck.isIdeaVersionValid("2018", "1"));
assertTrue(CompatibilityCheck.isIdeaVersionValid("2018", "2",
new BuildNumber("CI", 182, 2122)));
assertFalse(CompatibilityCheck.isIdeaVersionValid("2017", "3",
new BuildNumber("AI", 173, 22331)));
assertFalse(CompatibilityCheck.isIdeaVersionValid("2018", "1",
new BuildNumber("CI", 181, 22331)));
}
}

0 comments on commit f8221d1

Please sign in to comment.