ballerina-lang
ballerina-lang copied to clipboard
[Improvement]: Update the project which is in ToolContext after each tool config execute
Description
We've observed that the Ballerina.toml file isn't being updated with each tool configuration run. This becomes problematic when there are interdependent tool configurations relying on the details updated in the TOML file.
ex: Let's say we have configurations for tools A and B in Ballerina.toml. Tool B depends on changes made by Tool A. However, with the current existing tool context, we received the initial Ballerina.toml file, which has not been updated after the changes made by Tool A.
Describe your problem(s)
No response
Describe your solution(s)
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
Had an offline discussion with @azinneera. The suggested requirement can be facilitated by loading the project after running each tool, before the next tool execution.
However, the original intended design was to run the tasks independently of each other. Furthermore, we do not guarantee the order of execution of the tools. So we decided not to follow through with this design unless there is no feasible alternative approach.
The suggested alternative approach is to use the tool cache to record if the tool is already executed. @lnash94 please check if this is feasible from your end. The other method is to reload the project from the tool side.
@gayaldassanayake @azinneera Let me explain the actual problem here.
We can have multiple OpenAPI tool configurations in the Ballerina.toml where each one can update the existing Ballerina.toml file with some Java platform dependencies.
We are checking the existence of this dependency by getting the manifest from the project, and if it already there, we are skipping the toml update.
Since we are not loading the project after updating the Ballerina.toml, the above check returns false for the second time and it ends up in updating the Ballerina.toml with two same dependencies. This makes the build fail because of the duplicate entries of the same dependency.
Actually, we can read the Ballerina.toml file in our tool to check the dependency, rather than using the manifest. But we used that because we don't want to use a toml parser or some toml parsing logic by ourself. (This is a common use case in persist also, but currently they are reading the file in their tool side)
So we are not concerned about the order of the tool execution, but we expect the project to be updated with the previous tool changes. If that is not a viable solution, can you suggest a different approach to read and update the Ballerina.toml via some lang/tool functions?
@TharmiganK you can load the project within the tool by using BuildProject.load(toolContext.currentPackage().project().sourceRoot()) and then load the manifest to check if the entry is already there.