devkit: don't suggest to use '*' in until-build for plugins targeting old IDE version...
authornik <Nikolay.Chashnikov@jetbrains.com>
Wed, 29 Jun 2016 16:07:45 +0000 (19:07 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Wed, 29 Jun 2016 16:08:11 +0000 (19:08 +0300)
plugins/devkit/src/inspections/PluginXmlDomInspection.java
plugins/devkit/testData/codeInsight/pluginForOldIdeWith9999InUntilBuild.xml [new file with mode: 0644]
plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.groovy

index 3622a6a74f07348e4b7414f3971fcaecb2332a08..b0a9c5067fecaa9b6d1d90acb24ac7e324229f49 100644 (file)
@@ -48,6 +48,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author mike
@@ -153,7 +154,7 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
 
   private static void highlightUntilBuild(IdeaVersion ideaVersion, DomElementAnnotationHolder holder) {
     String untilBuild = ideaVersion.getUntilBuild().getStringValue();
-    if (untilBuild != null) {
+    if (untilBuild != null && isStarSupported(ideaVersion.getSinceBuild().getStringValue())) {
       Matcher matcher = IdeaPluginDescriptorImpl.EXPLICIT_BIG_NUMBER_PATTERN.matcher(untilBuild);
       if (matcher.matches()) {
         holder.createProblem(ideaVersion.getUntilBuild(), "Don't use '" + matcher.group(2) + "' in 'until-build', use '*' instead",
@@ -169,6 +170,19 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
     }
   }
 
+  private static final Pattern BASE_LINE_EXTRACTOR = Pattern.compile("(?:\\p{javaLetter}+-)?(\\d+)(?:\\..*)?");
+  private static final int FIRST_BRANCH_SUPPORTING_STAR = 131;
+
+  private static boolean isStarSupported(String buildNumber) {
+    if (buildNumber == null) return false;
+    Matcher matcher = BASE_LINE_EXTRACTOR.matcher(buildNumber);
+    if (matcher.matches()) {
+      int branch = Integer.parseInt(matcher.group(1));
+      return branch >= FIRST_BRANCH_SUPPORTING_STAR;
+    }
+    return false;
+  }
+
   private static void annotateExtension(Extension extension, DomElementAnnotationHolder holder) {
     final ExtensionPoint extensionPoint = extension.getExtensionPoint();
     if (extensionPoint == null) return;
diff --git a/plugins/devkit/testData/codeInsight/pluginForOldIdeWith9999InUntilBuild.xml b/plugins/devkit/testData/codeInsight/pluginForOldIdeWith9999InUntilBuild.xml
new file mode 100644 (file)
index 0000000..de4e8d5
--- /dev/null
@@ -0,0 +1,4 @@
+<idea-plugin>
+  <id>test</id>
+  <idea-version since-build="129.0" until-build="129.9999"/>
+</idea-plugin>
index e28bdd30e2c94dfd2fe2df34084b477277cb4b0e..8adb4847724cd8f5ae57f39f49fed6096afe1f21 100644 (file)
@@ -319,6 +319,10 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
     myFixture.testHighlighting("pluginWith9999InUntilBuild.xml");
   }
 
+  public void testPluginForOldIdeWith9999InUntilBuild() {
+    myFixture.testHighlighting("pluginForOldIdeWith9999InUntilBuild.xml");
+  }
+
   public void testPluginWith10000InUntilBuild()  {
     myFixture.testHighlighting("pluginWith10000InUntilBuild.xml");
   }