Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the intellij plugin when the bundled formatter is used #619

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-619.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Fix the intellij plugin when the bundled formatter is used
links:
- https://github.com/palantir/palantir-java-format/pull/619
7 changes: 4 additions & 3 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ apply plugin: 'org.jetbrains.intellij'

apply plugin: 'com.palantir.external-publish-jar'

def name = "palantir-java-format"
intellij {
pluginName = "palantir-java-format"
pluginName = name
updateSinceUntilBuild = true
version = "IU-202.6397.94"
plugins = ['java']
Expand Down Expand Up @@ -73,8 +74,8 @@ tasks.withType(org.jetbrains.intellij.tasks.PrepareSandboxTask) {
dependsOn configurations.runtimeClasspath

// Also pack the formatter in its own directory
into("${pluginName}/impl") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable was not resolved, so the current version was no longer included in our plugin!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! Interesting that this worked before!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure when it broke since it only failed when the idea plugin used a newer version than the repo

from configurations.formatter
into("${name}/impl") {
from configurations.formatter.filter { !configurations.runtimeClasspath.contains(it) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fawind you removed this .filter { !configurations.runtimeClasspath.contains(it) } in #562, do you recall why? It seems beneficial to dedup jars, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, I ran into issues where dependencies of the formatter where missing when loading the formatter from the impl directory.

Not sure if we have integration tests for this. Can quickly try if the intellij bundled formatter still works after this. Wouldn't be surprised if we can re-add this. I think me removing this filter was mostly a blind guess in trying to fix those issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that it works locally. I was worried that I was testing the wrong path, so I renamed the impl directory, restarted my IDE, and it failed to find the formatter impl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to revalidate using jdk16+ targets though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg, sorry for the merge then!

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ private static List<Path> getProvidedImplementationUrls(List<URI> implementation

private static List<Path> getBundledImplementationUrls() {
// Load from the jars bundled with the plugin.
Path pluginPath = PalantirCodeStyleManager.PLUGIN.getPluginPath();
Path implDir = pluginPath.resolve("impl");
// Directory appears to have been renamed from 'impl' to 'lib' in recent idea releases
Path pathToUse = Files.isDirectory(implDir) ? implDir : pluginPath.resolve("lib");

log.debug("Using palantir-java-format implementation bundled with plugin: {}", pathToUse);
return listDirAsUrlsUnchecked(pathToUse);
Path implDir = PalantirCodeStyleManager.PLUGIN.getPath().toPath().resolve("impl");
log.debug("Using palantir-java-format implementation bundled with plugin: {}", implDir);
return listDirAsUrlsUnchecked(implDir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverts a change that went in yesterday, which didn't do anything

}

private static List<Path> getImplementationUrls(
Expand Down