Add gradle task for generating state machine diagrams#839
Conversation
|
Maybe you could add a toggle similar to?:
But:
|
0ffa5b6 to
d916a94
Compare
|
@codex review (from discord: Testing to see if a non owner of the PR can kick off a review with their own credits) |
|
To use Codex here, create a Codex account and connect to github. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d916a94f4a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import com.github.javaparser.JavaParser; | ||
| import com.github.javaparser.ParserConfiguration; |
There was a problem hiding this comment.
Add JavaParser to the plugin dependencies
This new task imports com.github.javaparser.*, but the commit does not add a JavaParser artifact to build.gradle (repo-wide search only finds these new imports/usages). As a result, a clean build of the plugin fails before users can run any GradleRIO task with package com.github.javaparser does not exist; please add the dependency to the plugin compile classpath.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
JavaParser is a builtin dependency to the java-gradle-plugin
| var stateMachineDef = stateMachineDefs.getFirst().getVariable(0).getInitializer().orElseThrow(); | ||
| var rawGraphName = stateMachineDef.asObjectCreationExpr().getArgument(0); |
There was a problem hiding this comment.
Avoid Java 21-only collection APIs
GradleRIO is still configured with Java 17 compatibility, but List.getFirst() is a Java 21 API. In environments building or running the plugin on JDK 17, this either fails to compile or produces a plugin that can throw NoSuchMethodError; use get(0) or another Java 17-compatible access pattern here and at the other new getFirst() calls.
Useful? React with 👍 / 👎.
Uses javaparser to statically analyze state machine returning methods annotated with @MakeStateMachineGraph, and generates mermaid diagrams that map all of the possible states as well as the transitions between them. The mermaid files are generated inside of the deploy directory, allowing them to be logged in real-time or referenced as an asset by the user.
Here is an example of a state machine diagram generated by the gradle task (visualized in AdvantageScope):
Feedback would be appreciated in how this should be bundled with the wpilib java extension. Currently, the gradle task isn't linked to compileJava because the task itself analyzes every java file the user has, meaning that it might add add unwanted build time for users not using this feature.
Tangential PRs: