IDEA-156257: Show warning when a plain branch number is specified in 'until-build' attribute in plugin.xml

This commit is contained in:
nik
2016-05-19 10:24:06 +03:00
parent e4c7d35018
commit b4907ef886
3 changed files with 17 additions and 2 deletions
@@ -148,10 +148,10 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
private static void annotateIdeaVersion(IdeaVersion ideaVersion, DomElementAnnotationHolder holder) {
highlightNotUsedAnymore(ideaVersion.getMin(), holder);
highlightNotUsedAnymore(ideaVersion.getMax(), holder);
highlightBigNumbersInUntilBuild(ideaVersion, holder);
highlightUntilBuild(ideaVersion, holder);
}
private static void highlightBigNumbersInUntilBuild(IdeaVersion ideaVersion, DomElementAnnotationHolder holder) {
private static void highlightUntilBuild(IdeaVersion ideaVersion, DomElementAnnotationHolder holder) {
String untilBuild = ideaVersion.getUntilBuild().getStringValue();
if (untilBuild != null) {
Matcher matcher = IdeaPluginDescriptorImpl.EXPLICIT_BIG_NUMBER_PATTERN.matcher(untilBuild);
@@ -159,6 +159,13 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
holder.createProblem(ideaVersion.getUntilBuild(), "Don't use '" + matcher.group(2) + "' in 'until-build', use '*' instead",
new CorrectUntilBuildAttributeFix(IdeaPluginDescriptorImpl.convertExplicitBigNumberInUntilBuildToStar(untilBuild)));
}
if (untilBuild.matches("\\d+")) {
int branch = Integer.parseInt(untilBuild);
String corrected = (branch - 1) + ".*";
String message = "Plain numbers in 'until-build' attribute may be misleading. '" + untilBuild + "' means the same as '" + untilBuild
+ ".0', so the plugin won't be compatible with " + untilBuild + ".* builds. It's better to specify '" + corrected + " instead.";
holder.createProblem(ideaVersion.getUntilBuild(), message, new CorrectUntilBuildAttributeFix(corrected));
}
}
}
@@ -0,0 +1,4 @@
<idea-plugin>
<id>test</id>
<idea-version since-build="145" until-build="<error descr="Plain numbers in 'until-build' attribute may be misleading. '145' means the same as '145.0', so the plugin won't be compatible with 145.* builds. It's better to specify '144.* instead.">145</error>"/>
</idea-plugin>
@@ -320,6 +320,10 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
myFixture.testHighlighting("pluginWithStarInUntilBuild.xml");
}
public void testPluginWithBranchNumberInUntilBuild() {
myFixture.testHighlighting("pluginWithBranchNumberInUntilBuild.xml");
}
public void testReplaceBigNumberInUntilBuildWithStarQuickFix() {
myFixture.enableInspections(PluginXmlDomInspection.class)
myFixture.configureByFile("pluginWithBigNumberInUntilBuild_before.xml")