Skip to content

Intellij uses the native image from .gradle/palantir-java-formatter-caches #1306

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

Merged
merged 11 commits into from
Jul 18, 2025

Conversation

crogoz
Copy link
Contributor

@crogoz crogoz commented May 23, 2025

Before this PR

Unused artifact transforms are cleaned up by Gradle every 7 days. This could lead to situation - if people do not refresh the Gradle project in Intellij - where the formatter would fail to run because:

Caused by: java.io.IOException: Cannot run program "~/.gradle/caches/8.12.1/transforms/8b5bfec0f342b9bc0fee275f271594d7/transformed/palantir-java-format-native-2.63.0-nativeImage-macos_aarch64.bin.executable" (in directory "/~/.gradle/caches/8.12.1/transforms/8b5bfec0f342b9bc0fee275f271594d7/transformed"): error=2, No such file or directory

internal slack thread here

After this PR

==COMMIT_MSG==
Intellij uses the native image from .gradle/palantir-java-formatter-caches
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented May 23, 2025

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Intellij uses the native image from .gradle/palantir-java-formatter-caches

Check the box to generate changelog(s)

  • Generate changelog entry

@crogoz
Copy link
Contributor Author

crogoz commented May 23, 2025

adding do not merge until I finish testing the last commit

import java.util.Comparator;
import java.util.stream.Stream;

public final class FileUtils {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as in gradle-jdks


private static Logger logger = Logging.getLogger(PalantirJavaFormatIdeaPlugin.class);

public static URI copyToCacheDir(URI srcUri) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

similar to the logic in gradle-jdks https://github.com/palantir/gradle-jdks/blob/develop/gradle-jdks-setup/src/main/java/com/palantir/gradle/jdks/setup/GradleJdkInstallationSetup.java#L114 with a few modification eg. not copying a directory, but a file


Optional<Configuration> nativeImplConfiguration = maybeGetNativeImplConfiguration(rootProject);

configureLegacyIdea(rootProject, implConfiguration, nativeImplConfiguration);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the configureLegacyIdea logic completely. I see that we did that in gradle-idea-configuration as well but happy to bring it back if you think this might be problematic for some usecases.

Choose a reason for hiding this comment

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

let's drop it!

Comment on lines -103 to -112
if (!Boolean.getBoolean("idea.active")) {
return;
}
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 am not sure here - do we still need to check the idea.active and run this when the idea plugin is applied ?

@crogoz crogoz requested a review from CRogers May 26, 2025 08:51
Comment on lines 88 to 89
return Path.of(Optional.ofNullable(System.getenv("GRADLE_USER_HOME"))
.orElseGet(() -> System.getenv("HOME") + "/.gradle"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use project.getGradle().getGradleUserHomeDir() instead

Comment on lines 51 to 56
TaskProvider<UpdatePalantirJavaFormatIdeaXmlFile> updatePalantirJavaFormatIpr = rootProject
.getTasks()
.register("updatePalantirJavaFormatIpr", UpdatePalantirJavaFormatIdeaXmlFile.class, task -> {
task.getOutputFile().set(rootProject.file(rootProject.getName() + ".ipr"));
task.getShouldCreateOutputIfAbsent().set(false);
});

Choose a reason for hiding this comment

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

do we still need this? I don't have any .ipr files in my directories anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could probably drop the old way now. We've had the huge warning via baseline for ages now, and it's super deprecated.

Comment on lines 77 to 82
TaskProvider<UpdateWorkspaceXmlFile> updateWorkspaceIwsXml = rootProject
.getTasks()
.register("updateWorkspaceIwsXml", UpdateWorkspaceXmlFile.class, task -> {
task.getOutputFile().set(rootProject.file(rootProject.getName() + ".iws"));
task.getShouldCreateOutputIfAbsent().set(false);
});

Choose a reason for hiding this comment

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

similarly here, isn't this just the idea logic?

Comment on lines 47 to 48
@OutputDirectory
public abstract RegularFileProperty getCacheDir();
Copy link
Contributor

Choose a reason for hiding this comment

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

This cache dir can have multiple different formatters in it right? If so, we should just have a single output that is the file we expect it to be in, otherwise Gradle will regard this task not up-to-date as extra stuff gets added to it.

Comment on lines 54 to 56
java.util.Optional<URI> nativeUri = getNativeImageConfig().isEmpty()
? java.util.Optional.empty()
: java.util.Optional.of(getNativeImageConfig().getSingleFile().toURI())
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably preferentially import java.util.Optional and fully qualify the org.gradle.api.tasks.Optional to make this a bit more readable.

Comment on lines 53 to 56
getImplementationConfig().getFiles().stream().map(File::toURI).collect(Collectors.toList());
java.util.Optional<URI> nativeUri = getNativeImageConfig().isEmpty()
? java.util.Optional.empty()
: java.util.Optional.of(getNativeImageConfig().getSingleFile().toURI())
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this, you can use getImplementationConfig().getFiles().stream().findFirst().map(File::toUri)

@crogoz crogoz requested a review from CRogers July 18, 2025 13:32
@bulldozer-bot bulldozer-bot bot merged commit e58c1d9 into develop Jul 18, 2025
9 of 10 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/fix-missing-native-image-dir branch July 18, 2025 14:00
@autorelease3
Copy link

autorelease3 bot commented Jul 18, 2025

Released 2.72.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants