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

Include Spotless Gradle precommit hook #104

Closed
AlexRuiz7 opened this issue Oct 15, 2024 · 3 comments · Fixed by #105
Closed

Include Spotless Gradle precommit hook #104

AlexRuiz7 opened this issue Oct 15, 2024 · 3 comments · Fixed by #105
Assignees
Labels
level/task Task issue request/operational Operational requests type/enhancement Enhancement issue

Comments

@AlexRuiz7
Copy link
Member

Description

OpenSearch's codebase, and by inheritance Wazuh Indexer's, uses a precommit hook to format and lint the Java code using Spotless. In order to guarantee that our plugin's code is consistent and well maintained, we will include this precommit hook to our plugin's build.gradle.

The code conventions to be used are the ones defined in the Developer Guide. We will inherit the code and naming conventions from OpenSearch to keep all the codebase consistent.

Explore if we can add a root Grade project to simplify the configuration. The subprojects (each plugin's Gradle project), will inherit the precommit hook from the root project.

Functional requirements

  • Spotless Gradle plugin can be invoked from any of the plugins in this repository.
  • Spotless adds missing license headers.
  • Spotless runs automatically as a precommit hook.

Implementation restrictions

  • Spotless is added as a Gradle plugin.
  • *To avoid duplication, Spotless is added to a root Gradle project. Each of the plugins will be subprojects and will inherit the settings.
  • Spotless configuration is decoupled in a separate file (gradle/formatting.gradle).
  • License headers are imported from a separate file (license-header.txt).
  • Only code whose group is com.wazuh is processed.

* Optional

Resources

@AlexRuiz7 AlexRuiz7 added level/task Task issue type/enhancement Enhancement issue labels Oct 15, 2024
@AlexRuiz7 AlexRuiz7 added the request/operational Operational requests label Oct 15, 2024
@wazuhci wazuhci moved this to In progress in Release 5.0.0 Oct 15, 2024
@QU3B1M
Copy link
Member

QU3B1M commented Oct 15, 2024

Gradle offers this documentation that could be useful for the implementation of the generic build.gradle to run for all the subprojects (plugins).

For now we will work on a basic implementation of the functionality, so this improvement will be worked on later.

@QU3B1M
Copy link
Member

QU3B1M commented Oct 15, 2024

The spotless tool is applied and working correctly with the gradlew commands, but not the pre-commit hook, for now the implementation is only working on the plugin command-manager.

The problem with the hook is that it seems to require org.opensearch.gradle.BuildPlugin that is not present on our plugins repository, for what I can see on the OpenSearch plugins' repositories that class is not present neither, so I have to re-evaluate the implementation of the pre-commit hook, maybe for the plugins we can have a more "typical" and basic solution, something like this

Once the pre-commit hook is working successfully, I will apply the required changes to the other plugin.

@QU3B1M
Copy link
Member

QU3B1M commented Oct 16, 2024

Spotless was implemented altogether with a git pre-commit hook, also a root Gradle project was initialized to handle generic actions for all the plugins (subprojects)

@wazuhci wazuhci moved this from In progress to Pending review in Release 5.0.0 Oct 16, 2024
@wazuhci wazuhci moved this from Pending review to Done in Release 5.0.0 Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue request/operational Operational requests type/enhancement Enhancement issue
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants