From 54276bc2fcc9af48bb215e1fac840ff4db074764 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 14 Apr 2015 14:33:42 +0300 Subject: [PATCH] [groovy] recognize "-minimal" jars in library --- .../groovy/config/AbstractConfigUtils.java | 17 +++++++++++------ .../groovy/config/GroovyConfigUtils.java | 12 +++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java index a8178a3f505b..4450f6345820 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java @@ -87,17 +87,24 @@ public abstract class AbstractConfigUtils { return getSDKJarVersion(jarPath, Pattern.compile(jarRegex), manifestPath); } + + @Nullable + public static String getSDKJarVersion(String jarPath, final Pattern jarPattern, String manifestPath) { + return getSDKJarVersion(jarPath, jarPattern, manifestPath, 1); + } + /** * Return value of Implementation-Version attribute in jar manifest *

* * @param jarPath directory containing jar file - * @param jarPattern filename pattern for jar file + * @param jarPattern filename pattern for jar file * @param manifestPath path to manifest file in jar file + * @param versionGroup group number to get from matcher * @return value of Implementation-Version attribute, null if not found */ @Nullable - public static String getSDKJarVersion(String jarPath, final Pattern jarPattern, String manifestPath) { + public static String getSDKJarVersion(String jarPath, final Pattern jarPattern, String manifestPath, int versionGroup) { try { File[] jars = LibrariesUtil.getFilesInDirectoryByPattern(jarPath, jarPattern); if (jars.length != 1) { @@ -123,8 +130,8 @@ public abstract class AbstractConfigUtils { } final Matcher matcher = jarPattern.matcher(jars[0].getName()); - if (matcher.matches() && matcher.groupCount() == 1) { - return matcher.group(1); + if (matcher.matches() && matcher.groupCount() >= versionGroup) { + return matcher.group(versionGroup); } return null; } @@ -165,6 +172,4 @@ public abstract class AbstractConfigUtils { public Library[] getSDKLibrariesByModule(final Module module) { return LibrariesUtil.getLibrariesByCondition(module, LIB_SEARCH_CONDITION); } - - } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/GroovyConfigUtils.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/GroovyConfigUtils.java index 8b8d9f0e7cfe..4420833d0181 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/GroovyConfigUtils.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/GroovyConfigUtils.java @@ -40,7 +40,9 @@ import java.util.regex.Pattern; * @author ilyas */ public abstract class GroovyConfigUtils extends AbstractConfigUtils { - @NonNls public static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-(\\d(\\.\\d)*))?\\.jar"); + + @NonNls public static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-minimal)?(-(\\d+(\\.\\d+)*))?\\.jar"); + public static final int VERSION_GROUP_NUMBER = 3; // version will be in third group in GROOVY_ALL_JAR_PATTERN @NonNls public static final Pattern GROOVY_JAR_PATTERN = Pattern.compile("groovy(-(\\d(\\.\\d)*))?\\.jar"); public static final String NO_VERSION = ""; @@ -79,15 +81,15 @@ public abstract class GroovyConfigUtils extends AbstractConfigUtils { @Override @NotNull public String getSDKVersion(@NotNull final String path) { - String groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_JAR_PATTERN, MANIFEST_PATH); + String groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_JAR_PATTERN, MANIFEST_PATH, VERSION_GROUP_NUMBER); if (groovyJarVersion == null) { - groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH); + groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH, VERSION_GROUP_NUMBER); } if (groovyJarVersion == null) { - groovyJarVersion = getSDKJarVersion(path + "/embeddable", GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH); + groovyJarVersion = getSDKJarVersion(path + "/embeddable", GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH, VERSION_GROUP_NUMBER); } if (groovyJarVersion == null) { - groovyJarVersion = getSDKJarVersion(path, GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH); + groovyJarVersion = getSDKJarVersion(path, GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH, VERSION_GROUP_NUMBER); } return groovyJarVersion == null ? UNDEFINED_VERSION : groovyJarVersion; }