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

Add dependencies in JVMTestSuite dependency block #5000

Merged
merged 32 commits into from
Feb 18, 2025

Conversation

MBoegers
Copy link
Contributor

@MBoegers MBoegers commented Feb 7, 2025

What's changed?

If a dependency is added in a dependencies block inside a not standard sourceSet, the prefix mechanism in org.openrewrite.gradle.AddDependency Line 180 produces unexpected namings.

What's your motivation?

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

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

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

@@ -1345,6 +1303,58 @@ void addUnconditionally() {
);
}

@Test
@Issue("https://github.com/moderneinc/customer-requests/issues/792")
void addScoped() {
Copy link
Contributor

@shanman190 shanman190 Feb 8, 2025

Choose a reason for hiding this comment

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

Note that this is actually a combination of two distinct features. You've got a custom source set (which the configurations are created at the project level also), but the JVM Test Suites feature as well.

AddDependency hasn't yet been adapted to understand how to add dependencies to JVM Test Suite instances yet, so it's going to attempt to add the dependency like below which should still work, but doesn't match the test assertions.

dependencies {
    integrationTestImplementation "com.google.guava:guava:29.0-jre"
}

Both forms are still valid.

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 rename this test to something like addToJVMTestSuite which more clearly aligns to the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clearing whats used here, that will help implementing. Its true AddDependency doesn't work as the expextation.
Is the nested dependency block a JVMTestSuite specific feature or possible in other combinations?

Copy link
Contributor

@shanman190 shanman190 Feb 8, 2025

Choose a reason for hiding this comment

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

There are four main forms of declaring dependencies which are nested at a deeper level than normal that I can recall.

  • buildscript: to declare plugins; plugins blocks are preferred in modern versions
  • allprojects: discouraged in modern versions and breaks configuration cache/project isolation
  • subprojects: also discouraged in modern versions and breaks configuration cache/project isolation
  • JVM Test Suites (as shown here)

Of course programmatically adding dependencies via the configuration is possible as well, but I'm leaving that off since we're really talking about DSL forms.

Since we handle plugins separately, so far we've ignored buildscript as well. Which leaves the last three above remaining, two of which are discouraged (and also complicated to deal with with respect to OpenRewrite's LST marker shape).

With JVM Test Suites, it's really wrapping up the historic logic that was necessary to create a source set for the tests to reside in -- which then inherently created the necessary configurations -- and tries to go a step further to encapsulate the test suite itself into a more use case specific and succinct form. But to answer your question, the declaration you have there in the test assertions is a JVM Test Suite specific feature.

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-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java
    • lines 255-256
  • rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java
    • lines 363-364
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/AnnotationTemplateGenerator.java
    • lines 158-159
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java
    • lines 281-282
    • lines 669-669
  • rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyClasses.java
    • lines 57-57
  • rewrite-xml/src/main/java/org/openrewrite/xml/internal/XmlPrinter.java
    • lines 106-106
  • rewrite-yaml/src/main/java/org/openrewrite/yaml/cleanup/RemoveUnusedVisitor.java
    • lines 76-76

@MBoegers MBoegers changed the title Add dependencies correct in nested dependency block Add dependencies in JVMTestSuite dependency block Feb 10, 2025
@MBoegers MBoegers marked this pull request as ready for review February 11, 2025 12:48
Copy link
Contributor

@shanman190 shanman190 left a comment

Choose a reason for hiding this comment

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

Lots of good stuff here, @MBoegers! I've left a few comments that we can discuss about possibly implementing, but some are certainly more complex than others and we can of course handle those via future PRs should we want to take them on.

Co-authored-by: Shannon Pamperl <[email protected]>
@MBoegers
Copy link
Contributor Author

@shanman190 thanks for educating me here 🙏

github-actions[bot]

This comment was marked as outdated.

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-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java
    • lines 255-256
  • rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java
    • lines 363-364
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/AnnotationTemplateGenerator.java
    • lines 158-159
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java
    • lines 281-282
    • lines 669-669
  • rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyClasses.java
    • lines 57-57
  • rewrite-xml/src/main/java/org/openrewrite/xml/internal/XmlPrinter.java
    • lines 106-106
  • rewrite-yaml/src/main/java/org/openrewrite/yaml/cleanup/RemoveUnusedVisitor.java
    • lines 76-76

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-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java
    • lines 255-256
  • rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java
    • lines 363-364
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/AnnotationTemplateGenerator.java
    • lines 158-159
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java
    • lines 281-282
    • lines 669-669
  • rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyClasses.java
    • lines 57-57
  • rewrite-xml/src/main/java/org/openrewrite/xml/internal/XmlPrinter.java
    • lines 106-106
  • rewrite-yaml/src/main/java/org/openrewrite/yaml/cleanup/RemoveUnusedVisitor.java
    • lines 76-76

@timtebeek timtebeek self-requested a review February 17, 2025 09:13
@timtebeek timtebeek added the enhancement New feature or request label Feb 17, 2025
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Can't say I've read all the earlier review threads; do let me know if I missed anything!

I like what you did with the separate Find recipe here. Did you intentionally leave out adding the data table row earlier?

Copy link
Contributor

@shanman190 shanman190 left a comment

Choose a reason for hiding this comment

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

Just one comment, but great work @MBoegers!

@MBoegers
Copy link
Contributor Author

@timtebeek I can recall seeing an NPE, I think because using the findmethod (static context) does not initialize the data table properly, right?

@timtebeek
Copy link
Contributor

@timtebeek I can recall seeing an NPE, I think because using the findmethod (static context) does not initialize the data table properly, right?

Ah yes that was solved in f4ecc97

@MBoegers MBoegers merged commit dfae406 into main Feb 18, 2025
2 checks passed
@MBoegers MBoegers deleted the fix/792-adddependency-nested branch February 18, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants