Validate JVM code snippets in documentation at compile time#330
Open
Validate JVM code snippets in documentation at compile time#330
Conversation
Fix all Refactor Also support kotlin Add code to create a baseline Revert docs change
# Conflicts: # docs/sdks/android/label-capture/get-started.md
There was a problem hiding this comment.
Pull request overview
This PR adds a CI-backed validation pipeline that extracts Kotlin/Java code fences from the Android documentation, wraps them into compilable sources, and verifies they compile against the real Scandit SDK classpath resolved via a minimal Gradle “test bed”.
Changes:
- Add Python-based snippet extraction + caching/baseline orchestration and language plugins for Kotlin/Java compilation.
- Introduce a minimal Gradle JVM project that resolves Android/Scandit dependencies and exports a compiler classpath.
- Add hidden “# …” context lines in docs and a Docusaurus remark plugin to strip those lines from rendered Java/Kotlin code blocks.
Reviewed changes
Copilot reviewed 27 out of 29 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
validation/validate-code-snippets.py |
CLI entrypoint: extract snippets from docs/MDX imports, apply baseline/caching, generate sources, compile, and report. |
validation/kotlin/plugin.py |
Kotlin wrapping + compilation logic for generated snippet sources. |
validation/kotlin/__init__.py |
Exposes the Kotlin plugin instance for the validator CLI. |
validation/java/plugin.py |
Java wrapping + parallel javac compilation logic for generated snippet sources. |
validation/java/__init__.py |
Exposes the Java plugin instance for the validator CLI. |
validation/config.json |
Configures MDX import exclusions during snippet collection. |
validation/baselines/baseline-kotlin.json |
Baseline of known Kotlin snippet compilation failures to keep CI green initially. |
validation/base/__init__.py |
Shared base types for snippets, failures, results, and plugin interface. |
validation/android/__init__.py |
Shared Gradle/classpath/caching utilities for JVM compilation. |
validation/android-test-bed/settings.gradle.kts |
Gradle settings for the validation test-bed project. |
validation/android-test-bed/gradlew.bat |
Windows Gradle wrapper script for the test-bed. |
validation/android-test-bed/gradlew |
POSIX Gradle wrapper script for the test-bed. |
validation/android-test-bed/gradle/wrapper/gradle-wrapper.properties |
Pins Gradle wrapper version for the test-bed. |
validation/android-test-bed/gradle/wrapper/gradle-wrapper.jar |
Gradle wrapper JAR for the test-bed. |
validation/android-test-bed/gradle.properties |
Gradle properties (AndroidX + JVM args) for the test-bed. |
validation/android-test-bed/build.gradle.kts |
Root build config for the test-bed (Kotlin JVM plugin). |
validation/android-test-bed/app/build.gradle.kts |
Resolves Scandit SDK + Android stubs; exports compile classpath; AAR→JAR transform. |
validation/android-test-bed/app/src/main/kotlin/com/scandit/validation/ValidationBaseKotlin.kt |
Kotlin base class providing commonly referenced SDK variables for snippet compilation. |
validation/android-test-bed/app/src/main/kotlin/com/scandit/validation/ValidationBaseJava.java |
Java base class providing commonly referenced SDK variables for snippet compilation. |
validation/android-test-bed/.gitignore |
Ignores generated sources and build outputs in the test-bed project. |
src/plugins/remark-hide-comments.ts |
Remark plugin that removes # … hidden context lines from rendered java/kotlin code blocks. |
docusaurus.config.ts |
Registers remarkHideComments for docs rendering. |
docs/sdks/android/barcode-selection/get-started.md |
Adds hidden imports/context lines to Kotlin snippets. |
docs/sdks/android/barcode-generator.md |
Adds hidden imports/context lines to Kotlin snippets. |
docs/sdks/android/barcode-capture/get-started.md |
Adds hidden imports/context lines to Kotlin snippets (including additional context declarations). |
docs/sdks/android/barcode-capture/configure-barcode-symbologies.md |
Adds hidden imports/context lines to Kotlin snippets. |
docs/partials/get-started/_create-data-capture-context-android.mdx |
Adds hidden import line to Kotlin snippet in shared partial. |
.gitignore |
Ignores Python bytecode and the validation cache directory. |
.github/workflows/validate-code-snippets.yml |
CI workflow to run Kotlin/Java snippet validation and cache Gradle + snippet results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 29 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Summary
Introduces a validation pipeline that extracts Kotlin and Java code snippets from the Android SDK documentation and verifies they compile against the real Scandit SDK.
Validation infrastructure
validation/validate-code-snippets.py): Extracts code blocks from markdown docs, wraps each in a compilable class, and runs the Kotlin/Java compiler against the SDK classpath. Supports baselines for known failures, caching by content hash, and a plugin architecture per language.validation/kotlin/plugin.py,validation/java/plugin.py): Handle language-specific wrapping, import injection, compilation, and error parsing. Share common Gradle infrastructure viavalidation/android/__init__.py.validation/android-test-bed/): A minimal Android project using Robolectric (no device/emulator needed) that resolves the Scandit SDK classpath for compilation.validation/baselines/baseline-kotlin.json): Records currently-known compilation failures by snippet hash so CI stays green while docs are incrementally fixed..github/workflows/validate-code-snippets.yml): Runs on PRs tomain/release/**and pushes tomain. Sets up JDK 17, Python 3.12, caches Gradle, and runs both Kotlin and Java validation.Hidden import comments
Code snippets now include
# import ...and# lateinit var ...comment lines that give the compiler necessary context (imports, declarations, enclosing classes). A new Docusaurus remark plugin (src/plugins/remark-hide-comments.ts) strips lines starting with#fromkotlinandjavacode blocks at render time, so they are invisible to readers.Documentation changes
Added hidden import/context comments to Kotlin snippets in:
docs/sdks/android/barcode-capture/get-started.mddocs/sdks/android/barcode-capture/configure-barcode-symbologies.mddocs/sdks/android/barcode-generator.mddocs/sdks/android/barcode-selection/get-started.mddocs/partials/get-started/_create-data-capture-context-android.mdx