build(gradle): add build-time validation for prefabs and JSON assets #4986#5326
Open
mmruii wants to merge 2 commits into
Open
build(gradle): add build-time validation for prefabs and JSON assets #4986#5326mmruii wants to merge 2 commits into
mmruii wants to merge 2 commits into
Conversation
Registers a ValidateJsonAssets Gradle task that parses all JSON-based asset files (*.prefab, *.block, *.ui, *.json) under the assets directory at build time, failing the build with a descriptive message if any file contains malformed JSON. - Add ValidateJsonAssets task class to build-logic - Add org.json:json dependency to build-logic for JSON parsing - Hook validateJsonAssets into processResources for modules - Hook validateJsonAssets into processResources for engine Closes MovingBlocks#4986
Tests cover: - Task registration on a Gradle project - Valid JSON/prefab files pass without errors - Malformed JSON files fail the build with a descriptive message mentioning the offending file - Projects with no assets directory succeed gracefully Also refactor ValidateJsonAssets to use ConfigurableFileCollection with @SkipWhenEmpty for proper Gradle up-to-date checking, and replace deprecated createTempDir() with Files.createTempDirectory().
Member
|
Hi there, welcome, and thank you 👍 It looks like you already triggered a good looking test in the Jenkins build :-) That's encouraging! Although it does need a quick fix in that actual file - great example though 😁 And I see tests, also good! I'll try to find time to test and review a bit later, but one thing that stuck out is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements build-time validation for all JSON-based assets (such as .prefab, .block, .ui, and .json files) in both engine and modules.
It introduces a custom Gradle task that parses each asset and fails the build with a descriptive error if any file contains malformed JSON.
Modified files:
ValidateJsonAssets.kt:
New Gradle task that validates JSON assets at build time.
build.gradle.kts:
Adds the org.json dependency and test dependencies for the new task.
terasology-module.gradle.kts:
Registers the validation task for all modules and hooks it into the build process.
build.gradle.kts:
Registers the validation task for engine assets and hooks it into the build process.
build-logic/src/test/kotlin/org/terasology/gradology/ValidateJsonAssetsTest.kt:
Unit tests for the validation task, covering valid, invalid, and missing asset scenarios.
How to test:
Run a build (./gradlew build) with valid and invalid JSON assets to confirm that the build fails on malformed files and succeeds otherwise.
Run the included unit tests for the validation task.
Outstanding before merging:
Review if additional asset types should be included.
Documentation update if needed.
Closes #4986