Skip to content

Validate JVM code snippets in documentation at compile time#330

Open
redwarp wants to merge 20 commits intomainfrom
feature/verify-jvm-snippets
Open

Validate JVM code snippets in documentation at compile time#330
redwarp wants to merge 20 commits intomainfrom
feature/verify-jvm-snippets

Conversation

@redwarp
Copy link
Contributor

@redwarp redwarp commented Mar 23, 2026

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 script (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.
  • Language plugins (validation/kotlin/plugin.py, validation/java/plugin.py): Handle language-specific wrapping, import injection, compilation, and error parsing. Share common Gradle infrastructure via validation/android/__init__.py.
  • Gradle test bed (validation/android-test-bed/): A minimal Android project using Robolectric (no device/emulator needed) that resolves the Scandit SDK classpath for compilation.
  • Baseline (validation/baselines/baseline-kotlin.json): Records currently-known compilation failures by snippet hash so CI stays green while docs are incrementally fixed.
  • CI workflow (.github/workflows/validate-code-snippets.yml): Runs on PRs to main/release/** and pushes to main. 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 # from kotlin and java code 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.md
  • docs/sdks/android/barcode-capture/configure-barcode-symbologies.md
  • docs/sdks/android/barcode-generator.md
  • docs/sdks/android/barcode-selection/get-started.md
  • docs/partials/get-started/_create-data-capture-context-android.mdx

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

redwarp and others added 2 commits March 23, 2026 11:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants