Refactor CompileTask and CreateDependencyGraphTask to add balToolToml check #44345
+6
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Currently, Ballerina tool packages that do not contain any
.balfiles failbal buildandbal testcommands with the error "package is empty. Please add at least one .bal file." This occurs despitebal packworking as expected for such packages. This fix addresses this discrepancy, allowing tool packages without.balfiles to be built and tested successfully.Fixes #44292
Approach
The issue was identified in
io.ballerina.cli.task.CompileTask.javaandio.ballerina.cli.task.CreateDependencyGraphTask.java, where a check for an empty package (ProjectUtils.isProjectEmpty(project)) was being performed without considering if the package was a tool package (i.e., containing aBalTool.toml).The approach taken is to modify the conditional check in both
CompileTask.javaandCreateDependencyGraphTask.java. The condition now explicitly checks ifproject.currentPackage().balToolToml().isEmpty()is true in addition toProjectUtils.isProjectEmpty(project). This ensures that if a package is identified as a tool package (by the presence ofBalTool.toml), it is not considered "empty" even if it lacks.balsource files, thus preventing the erroneous compilation and test failures.Samples
This change primarily affects the build and test behavior of tool packages without
.balfiles. Existing test cases for tool packages should now pass, and new test cases specifically covering this scenario (a tool package withBalTool.tomlbut no.balfiles) would further validate the fix.Remarks
N/A
Check List
bal testcommand fails for tool packages without.balfiles #44292)