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

Clean openApiGenerate output dir before generating #2502

Conversation

gerlowskija
Copy link
Contributor

@gerlowskija gerlowskija commented Jun 6, 2024

Description

Before compiling SolrJ, the gradle build creates an OpenAPI Spec ("OAS") describing our JAX-RS v2 APIs and then uses that spec to generate SolrRequest ".java" files. The responsible task (solr:solrj:openApiGenerate) adds newly generated code to solrj/build/generated, but it doesn't (by default) wipe the directory at the start of each invocation.

This can cause generated files to "leak" across branches - sticking around in solrj/build/generated even when the developer has changed to a branch that shouldn't contain the file.

These leaks can cause compilation issues, as pointed out by @dsmiley recently on the dev list.

Solution

The solution is to have the solr:solrj:openApiGenerate task clear its output directory each time it runs. Luckily the OpenAPI tooling supports this, and it's a one-line change in build.gradle.

Tests

Manual build testing.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.

This commit fixes a problem in the Solr build whereby files generated
from our OpenAPI spec could "leak" between branches and cause
compilation issues.

In short, generated SolrRequest implementations were not being
overwritten or cleaned up after switching branches.  This caused
compilation problems whenever the new branch didn't have other classes
(typically 'model' POJOs) that the generated file relied on.

This commit uses the openApiGenerate task's "cleanupOutput" option to
prevent this from happening.
Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

It's "safe" and will reduce user annoyance (as I've experienced / felt) so I approve.

I don't know if there is a notable negative performance impact, as there would be if this was a java compiler, which knows not to re-generate unchanged things. Update: I did a little trivial experimentation just now with this and I don't think it's a big concern.

@HoustonPutman
Copy link
Contributor

This looks good to me.

It will be even better when OpenAPITools/openapi-generator#17380 is fixed, which will stop the task from running as often as it is (the task will be skipped since the input & output will be unchanged).

@gerlowskija gerlowskija merged commit 32418ee into apache:main Jun 7, 2024
4 checks passed
@gerlowskija gerlowskija deleted the cleanup-generated-files-before-regenerating branch June 7, 2024 14:50
gerlowskija added a commit that referenced this pull request Jun 7, 2024
This commit fixes a problem in the Solr build whereby files generated
from our OpenAPI spec could "leak" between branches and cause
compilation issues.

In short, generated SolrRequest implementations were not being
overwritten or cleaned up after switching branches.  This caused
compilation problems whenever the new branch didn't have other classes
(typically 'model' POJOs) that the generated file relied on.

This commit uses the openApiGenerate task's "cleanupOutput" option to
prevent this from happening.
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