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

Only process each buildscript once in JavaGradleProjectResolver #2983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
@Order(ExternalSystemConstants.UNORDERED)
public final class JavaGradleProjectResolver extends AbstractProjectResolverExtension {

private final IdentityHashMap<GradleBuildScriptClasspathModel, List<BuildScriptClasspathData.ClasspathEntry>> buildScriptEntriesMap =
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused by the explicit usage of IdentityHashMap here. Are the instances of GradleBuildScriptClasspathModel internalized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, it was my experience that they were always the same, but I don't fully understand why. I can dig deeper to understand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Storing state here will cause memory leak, as this class is a long-living service. It is not re-created on each sync.

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 will apply your suggestion from the other PR here too.

new IdentityHashMap<>();

@Override
public void populateProjectExtraModels(@NotNull IdeaProject gradleProject, @NotNull DataNode<ProjectData> ideProject) {
populateJavaProjectCompilerSettings(gradleProject, ideProject);
Expand Down Expand Up @@ -149,10 +152,10 @@ private void populateBuildScriptClasspathData(@NotNull IdeaModule gradleModule,
buildScriptClasspathModel = resolverCtx.getExtraProject(gradleModule, GradleBuildScriptClasspathModel.class);
final List<BuildScriptClasspathData.ClasspathEntry> classpathEntries;
if (buildScriptClasspathModel != null) {
classpathEntries = ContainerUtil.map(
classpathEntries = buildScriptEntriesMap.computeIfAbsent(buildScriptClasspathModel, it -> ContainerUtil.map(
buildScriptClasspathModel.getClasspath(),
(Function<ClasspathEntryModel, BuildScriptClasspathData.ClasspathEntry>)model -> BuildScriptClasspathData.ClasspathEntry
.create(model.getClasses(), model.getSources(), model.getJavadoc()));
.create(model.getClasses(), model.getSources(), model.getJavadoc())));
}
else {
classpathEntries = ContainerUtil.emptyList();
Expand Down