Allow to override plugin version with system property

Need this during testing and development.
This commit is contained in:
Nikolay Krasko
2019-03-04 18:24:35 +03:00
parent 9ea39d2b7c
commit ddc9d0eba1
4 changed files with 52 additions and 3 deletions
@@ -14,24 +14,45 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
public class KotlinPluginUtil {
public static final PluginId KOTLIN_PLUGIN_ID;
private static final String PATCHED_PLUGIN_VERSION;
private static final String PATCHED_PLUGIN_VERSION_KEY = "kotlin.plugin.version";
static {
PluginId pluginId = PluginManagerCore.getPluginByClassName(KotlinPluginUtil.class.getName());
if (pluginId == null) {
pluginId = PluginId.getId("org.jetbrains.kotlin");
}
KOTLIN_PLUGIN_ID = pluginId;
PATCHED_PLUGIN_VERSION = System.getProperty(PATCHED_PLUGIN_VERSION_KEY, null);
}
@NotNull
public static String getPluginVersion() {
if (PATCHED_PLUGIN_VERSION != null) {
assert isPatched();
return PATCHED_PLUGIN_VERSION;
}
//noinspection deprecation
return getPluginVersionFromIdea();
}
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
@NotNull
public static String getPluginVersionFromIdea() {
IdeaPluginDescriptor plugin = PluginManager.getPlugin(KOTLIN_PLUGIN_ID);
assert plugin != null : "Kotlin plugin not found: " + Arrays.toString(PluginManagerCore.getPlugins());
return plugin.getVersion();
}
public static boolean isPatched() {
return PATCHED_PLUGIN_VERSION != null;
}
public static boolean isSnapshotVersion() {
return "@snapshot@".equals(getPluginVersion());
}