Skip to content

Commit ee02c4c

Browse files
authored
Fix pluginVersion discovery (#1247)
Fix pluginVersion discovery
1 parent 0dc0bee commit ee02c4c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

changelog/@unreleased/pr-1247.v2.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: fix
2+
fix:
3+
description: Fix pluginVersion discovery
4+
links:
5+
- https://github.com/palantir/palantir-java-format/pull/1247

idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@
5454
final class FormatterProvider {
5555
private static final Logger log = LoggerFactory.getLogger(FormatterProvider.class);
5656

57-
private static final String PLUGIN_ID = "palantir-java-format";
57+
static final String PLUGIN_ID = "palantir-java-format";
5858

5959
// Cache to avoid creating a URLClassloader every time we want to format from IntelliJ
6060
private final LoadingCache<FormatterCacheKey, Optional<FormatterService>> implementationCache =
6161
Caffeine.newBuilder().maximumSize(1).build(FormatterProvider::createFormatter);
6262

63+
static IdeaPluginDescriptor getPluginDescriptor() {
64+
return Preconditions.checkNotNull(
65+
PluginManager.getPlugin(PluginId.getId(PLUGIN_ID)), "Couldn't find our own plugin: %s", PLUGIN_ID);
66+
}
67+
6368
Optional<FormatterService> get(Project project, PalantirJavaFormatSettings settings) {
6469
return implementationCache.get(new FormatterCacheKey(
6570
project,
@@ -117,8 +122,7 @@ private static List<Path> getProvidedImplementationUrls(List<URI> implementation
117122
@SuppressWarnings("for-rollout:Slf4jLogsafeArgs")
118123
private static List<Path> getBundledImplementationUrls() {
119124
// Load from the jars bundled with the plugin.
120-
IdeaPluginDescriptor ourPlugin = Preconditions.checkNotNull(
121-
PluginManager.getPlugin(PluginId.getId(PLUGIN_ID)), "Couldn't find our own plugin: %s", PLUGIN_ID);
125+
IdeaPluginDescriptor ourPlugin = getPluginDescriptor();
122126
Path implDir = ourPlugin.getPath().toPath().resolve("impl");
123127
log.debug("Using palantir-java-format implementation bundled with plugin: {}", implDir);
124128
return listDirAsUrlsUnchecked(implDir);

idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.palantir.javaformat.intellij;
1818

19-
import com.google.common.base.Strings;
2019
import com.intellij.openapi.components.PersistentStateComponent;
2120
import com.intellij.openapi.components.ServiceManager;
2221
import com.intellij.openapi.components.State;
@@ -112,8 +111,7 @@ boolean injectedVersionIsOutdated() {
112111
}
113112

114113
Optional<String> getImplementationVersion() {
115-
return Optional.ofNullable(Strings.emptyToNull(
116-
PalantirJavaFormatConfigurable.class.getPackage().getImplementationVersion()));
114+
return Optional.ofNullable(FormatterProvider.getPluginDescriptor().getVersion());
117115
}
118116

119117
Optional<String> computeFormatterVersion() {

0 commit comments

Comments
 (0)