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: Dont generate the same file multiple times & fix CreateTextFile #4356

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

pstreef
Copy link
Contributor

@pstreef pstreef commented Jul 25, 2024

What's changed?

generate no longer creates files at the same path multiple times

What's your motivation?

Currently the same file can be created multiple times, causing instabilities in recipe execution. For instance
running CreateTextFile twice in the same run causes multiple cycles changing back and forth from 1 text to the other, even if overwriteExisting is false

Anything in particular you'd like reviewers to focus on?

This is a change in the core recipe running and might have unwanted side-effects

Anyone you would like to review specifically?

@sambsnyd @timtebeek

Have you considered any alternatives or workarounds?

Fixing it on the recipe level alone, but this would require "rescanning" during the edit phase.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-gradle/src/main/groovy/RewriteSettings.groovy
    • lines 31-36

@timtebeek timtebeek marked this pull request as draft July 25, 2024 12:41
@timtebeek timtebeek added the bug Something isn't working label Jul 25, 2024
@pstreef pstreef changed the title fix: CreateTestFile overrides file created in same run fix: Dont generate the same file multiple times & fix CreateTextFile Jul 25, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-gradle/src/main/groovy/RewriteSettings.groovy
    • lines 31-36

@pstreef pstreef marked this pull request as ready for review July 25, 2024 13:21
@timtebeek timtebeek self-requested a review July 25, 2024 13:58
@@ -86,7 +86,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor(AtomicBoolean created) {
@Override
public SourceFile visit(@Nullable Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) requireNonNull(tree);
if ((created.get() || Boolean.TRUE.equals(overwriteExisting)) && path.equals(sourceFile.getSourcePath())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird how we were overwriting the content again, even after already initializing with file contents.

Comment on lines 115 to 119
for (SourceFile source : generated) {
if (acc.stream().noneMatch(s -> s.getSourcePath().equals(source.getSourcePath()))) {
acc.add(source);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Gave me a bit of pause to loop over all generated files in a list before adding a new entry, but I think it's tolerable given the expected low volume of generated files.

Copy link
Member

Choose a reason for hiding this comment

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

Change the reduction operation to use a Set generated from a TreeMap whose comparator is the source path.

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 updated to using TreeSet. This does mean that the insertion order is no longer guaranteed to be the resulting order, although I can imagine that the LST order is also similarly ordered anyway?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-gradle/src/main/groovy/RewriteSettings.groovy
    • lines 31-36

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-gradle/src/main/groovy/RewriteSettings.groovy
    • lines 31-36

@pstreef pstreef merged commit 84f5858 into main Jul 25, 2024
2 checks passed
@pstreef pstreef deleted the fix/create-text-file-overrides branch July 25, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants