diff --git a/TICKETS.md b/TICKETS.md index b6946c0c..af32f1de 100644 --- a/TICKETS.md +++ b/TICKETS.md @@ -145,7 +145,7 @@ worker (ops); `v2`→`master` (explicit git promote only). **F-094** stays `bloc | F-102 | done | Navigation abstraction design | GH **#46** — **done (design):** [`docs/NAVIGATION-ABSTRACTION.md`](docs/NAVIGATION-ABSTRACTION.md) — Layer A presentation ports (no androidx.navigation in feature impl/VM) vs Layer B existing Path B `navigationRes` only; v1 = Jetpack behind root adapter; reject engine router DSL / plugin shopping / impl→impl / dual happy paths. Implement split: **F-111** sample, **F-112** progressive example. | | F-111 | done | Sample navigation ports + root adapter | GH **#46** implement — `core/navigation/api` ports + `root-app` Jetpack adapter + `core/navigation/android-util` home-shell binder; feature `impl`/VM Nav-free; `navigationRes` kept; feature→`core/navigation/res` stripped. | | F-112 | done | Progressive example: navigation ports | GH **#46** teach — `examples/android/12-navigation-ports` per F-102 §4.4; ladder + README; minimal graph; ports vs adapter vs `navigationRes`. Prefer before or with F-111. | -| F-103 | todo | Hybrid targets example (flat dir / api+impl co-location) | GH **#44** — teaching example: simplified flat layout (api/impl/stub mental model, easy multi-module nav). May use includer layout + progressive example; align with F-084/F-088 fleet layout. No restore of `androidLibrary`. | +| F-103 | done | Hybrid targets example (flat dir / api+impl co-location) | GH **#44** — `examples/android/15-hybrid-targets`: co-located `feature/{hello,world}/{api,impl,stub-impl}` (stub role = `impl` type; `-impl` suffix required). Roots wire api+impl; manual stub swap documented (F-104 separate). No `androidLibrary`, no engine churn. | | F-104 | todo | Hybrid configuration / stub targets for IDE sync | GH **#43** — stub targets + deps API so IDE sync can swap `impl`→`stub` (compileOnly/runtimeOnly pattern) via **one project-global flag**, not per-module hacks. Design+spike; depend on F-101/`target` APIs. Keep matrix truth. | | F-113 | done | Android first-party library examples complete | Close ladder gaps: real `androidTestUtil` usage in 09; `androidNative` step **13** + matrix edges (`androidUtil`/`app`/`binary`→`native`); `test*`/`androidTest*` deps = `FormaDependency` so project targets work; docs/skills/matrix aligned. | | F-114 | done | Google 1P libraries coverage + Firebase usage | Audit Architecture Components/Room/Nav/Compose/Material/Dagger/Play/Gson vs real sample usage; add `docs/GOOGLE-LIBRARIES.md`; progressive **14-google-firebase** (Path A `firebaseBinary` + dummy GMS JSON + Crashlytics/Analytics API use); fix `PlatformDependency + NamedDependency` dropping BOM platforms. | @@ -153,7 +153,7 @@ worker (ops); `v2`→`master` (explicit git promote only). **F-094** stays `bloc ## P11 — Kotlin Multiplatform (Stepan 2026-07-25) Third Gradle platform on forma-core (`tools.forma.kmp`). **Design:** [`docs/KMP-TARGETS.md`](docs/KMP-TARGETS.md). -**P11 v1 complete (F-105…F-110).** **F-100…F-102 done** (F-102 = navigation design only). **F-111 + F-112 done** (sample + progressive nav ports). Next board priority is **P10** top `todo` (**F-103** hybrid targets, then **F-104**…) unless +**P11 v1 complete (F-105…F-110).** **F-100…F-102 done** (F-102 = navigation design only). **F-111 + F-112 done** (sample + progressive nav ports). **F-103 done** (hybrid targets example 15). Next board priority is **P10** top `todo` (**F-104** IDE stub swap…) unless Stepan reprioritizes. v1 = **jvm + android** shared libraries only; type-owned MPP; **no** per-module target shopping; composition stays at Android/JVM roots. iOS/JS/Wasm = later phase. diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 083a0dc5..6db82973 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -2,6 +2,25 @@ Newest entries first. +## 2026-07-27 — F-103: Hybrid targets progressive example + +- **Ticket:** F-103 → `done` +- **Branch:** `forma/F-103-hybrid-targets` (from `origin/v2`) +- **Actions:** + - Added `examples/android/15-hybrid-targets` — co-located `feature/{hello,world}/{api,impl,stub-impl}` + - Stubs are real `impl` modules in `stub-impl/` dirs (`packageName` `…stub`) — bare `stub/` fails self-type suffix (`Allowed name suffix(es): impl`); documented in example README + - Composition roots default to **api + impl**; commented manual swap to `stub-impl` → F-104 teaser + - `configureondemand=false` so unused stub-impl siblings still configure/validate + - Curriculum: example README, `docs/PROGRESSIVE-EXAMPLES.md` row 15, `examples/README.md` ladder + fix stale 01→11 wording, `examples/agent-skills/forma-project-layout.md` hybrid section + - No `plugins/` engine changes; no `androidLibrary`; matrix rules unchanged (`impl` ↛ `impl`) +- **Build verification:** + - `./gradlew :binary:assembleDebug` → **BUILD SUCCESSFUL** + - `./gradlew :feature-hello-stub-impl:compileDebugKotlin :feature-world-stub-impl:compileDebugKotlin` → green +- **Commits/PRs:** this branch +- **Blockers:** none +- **Next step:** F-104 (IDE sync swap impl→stub via project-global flag) + + ## 2026-07-26 — F-111: Sample navigation ports + root adapter - **Ticket:** F-111 → `done` (GH #46 sample implement; design F-102 + teach F-112 already done) diff --git a/docs/PROGRESSIVE-EXAMPLES.md b/docs/PROGRESSIVE-EXAMPLES.md index fc50ad51..e13310f8 100644 --- a/docs/PROGRESSIVE-EXAMPLES.md +++ b/docs/PROGRESSIVE-EXAMPLES.md @@ -36,6 +36,7 @@ narrative tutorials when you want a **minimal buildable project per concept**. | Navigation ports (presentation ports + adapter; Jetpack behind root) | **12** | — | — | forma-android-targets + [NAVIGATION-ABSTRACTION.md](NAVIGATION-ABSTRACTION.md) | | `androidNative` + JNI via `androidUtil` | **13** | — | — | forma-android-targets | | Google Firebase (Crashlytics + Analytics, Path A `firebaseBinary`) | **14** | — | — | forma-target-plugins + [GOOGLE-LIBRARIES.md](GOOGLE-LIBRARIES.md) | +| Hybrid flat layout (`feature//{api,impl,stub-impl}`) | **15** | — | — | forma-project-layout | | `kmpLibrary` + `kmpProjectConfiguration` | — | — | 01 | forma-kmp-targets | | JVM/Android → `kmp.*` consumer edge | — | — | 01 (JVM binary) | forma-kmp-targets | | Fleet check/generate/migrate (`tools.forma.core.fleet`) | docs | docs | — | forma-fleet-tooling | diff --git a/examples/README.md b/examples/README.md index e35d0759..20c9171b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -9,7 +9,7 @@ Gold-standard product apps remain [`application/`](../application/) (Android) an | Track | Path | Steps | |-------|------|-------| | JVM | [`jvm/`](jvm/) | 01 hello-binary → 05 test-util | -| Android | [`android/`](android/) | 01 hello-apk → 11 metro-di | +| Android | [`android/`](android/) | 01 hello-apk → 15 hybrid-targets | | KMP | [`kmp/`](kmp/) | 01 shared-library (kmpLibrary + JVM binary) | | Agent skills | [`agent-skills/`](agent-skills/) | SKILL docs for coding agents | | User index | [`docs/PROGRESSIVE-EXAMPLES.md`](../docs/PROGRESSIVE-EXAMPLES.md) | narrative + feature coverage matrix | @@ -42,6 +42,7 @@ Gold-standard product apps remain [`application/`](../application/) (Android) an | 12 | `android/12-navigation-ports` | Presentation `Navigator` ports + root adapter; Jetpack/Safe Args only at root; Path B `navigationRes` | | 13 | `android/13-android-native` | `androidNative` (CMake) + JNI `androidUtil` consumer | | 14 | `android/14-google-firebase` | Firebase Crashlytics + Analytics via Path A `firebaseBinary` | +| 15 | `android/15-hybrid-targets` | Co-located `feature//{api,impl,stub-impl}`; multi-feature; manual stub swap teaser (F-104) | ### KMP (`tools.forma.kmp`) diff --git a/examples/agent-skills/forma-project-layout.md b/examples/agent-skills/forma-project-layout.md index 436f6a62..b9d02d91 100644 --- a/examples/agent-skills/forma-project-layout.md +++ b/examples/agent-skills/forma-project-layout.md @@ -24,3 +24,22 @@ Roots **must** depend on each feature’s `api` and `impl` explicitly. Examples gold standards: `docs/SAMPLE-APP.md`, `docs/JVM-SAMPLE.md`. Teaching ladders: `examples/**`. + + +## Hybrid co-located roles (api + impl + stub) + +Optional fleet layout for easier multi-module navigation (GH #44 / F-103): + +``` +feature//{api,impl,stub-impl}/ +``` + +- Same Forma types as the ladder (`api`, `impl`). A **stub** is a real `impl` module + in directory `stub-impl/` (name must end with `-impl` for the type suffix rule) + with `packageName` `…stub` and a lightweight stand-in of the same `api`. +- Gradle projects: `:feature--api`, `:feature--impl`, `:feature--stub-impl`. + Forma paths: `target(":feature::api|impl|stub-impl")`. +- Composition roots depend on **api + one of impl/stub-impl** (default: **impl**). + Do not depend on both. Manual swap is documented; automated IDE swap is **F-104**. +- No `androidLibrary`. No `impl` → `impl`. No engine dual path — layout convention only. +- Teaching example: [`examples/android/15-hybrid-targets`](../android/15-hybrid-targets). diff --git a/examples/android/15-hybrid-targets/README.md b/examples/android/15-hybrid-targets/README.md new file mode 100644 index 00000000..7e5b4014 --- /dev/null +++ b/examples/android/15-hybrid-targets/README.md @@ -0,0 +1,126 @@ +# 15 — hybrid targets (flat api / impl / stub co-location) + +**Goal:** Teach a **hybrid / flat co-located feature layout** where `api`, `impl`, and +a **stub** sibling live under one feature folder. Easy multi-module navigation +(GH [#44](https://github.com/formatools/forma/issues/44)) without restoring +`androidLibrary`, without engine changes, and without F-104 IDE swap wiring. + +## Features introduced + +- Co-located `feature//{api,impl,stub-impl}/` (same mental model as 02/07, flatter nav) +- Real **stub** modules that implement the same `api` with lightweight stand-ins +- Multi-feature composition (hello + world) at the root — same rules as 07 +- Manual `impl` → `stub-impl` dependency swap as a **preview of F-104** (not automated) + +## Layout + +``` +15-hybrid-targets/ + binary/ # androidBinary composition root + root-app/ # androidApp composition root + root-res/ + feature/ + hello/ + api/ # api(...) contracts + impl/ # impl(...) production + stub-impl/ # impl(...) lightweight stand-in (same api) + world/ + api/ + impl/ + stub-impl/ +``` + +### Why `stub-impl` (not bare `stub/`)? + +Forma target types are **suffix-typed**: an `impl { }` module’s Gradle project name +must end with `-impl` (self-type / matrix checks). Includer derives the name from +the directory path, so the role folder is `stub-impl/`: + +| Role (mental model) | Directory | Gradle project | `target()` path | +|---------------------|-----------|----------------|-----------------| +| api | `feature/hello/api` | `:feature-hello-api` | `:feature:hello:api` | +| impl (production) | `feature/hello/impl` | `:feature-hello-impl` | `:feature:hello:impl` | +| stub (stand-in) | `feature/hello/stub-impl` | `:feature-hello-stub-impl` | `:feature:hello:stub-impl` | + +The **role** is still “stub”; the **type** remains `impl` with `packageName` `…stub`. +No new target type and no engine change — layout convention only. F-104 may later +add project-global swap tooling; it does not need a bare `-stub` suffix for this +teaching example. + +Includer discovers each role directory (`arbitraryBuildScriptNames = true`). + +### Why this eases IDE navigation + +Deep ladders scatter related roles across distant trees. Co-location keeps **one +folder per feature** with role-named children — open `feature/hello/` and see +api + impl + stub together. Optional browsing symlinks (e.g. top-level +`hello-api` → `feature/hello/api`) are fine if they help humans, but **includer +must still discover real `projectDir`s** and `target(":feature:…")` remains the +supported path. This example does **not** require symlinks. + +### api / impl / stub mental model + +| Role | Target type | Depends on | Purpose | +|------|-------------|------------|---------| +| `api` | `api` | (none / shared libs) | Public contracts | +| `impl` | `impl` | `api` of same feature | Production implementation | +| `stub` | `impl` (dir `stub-impl`, package `…stub`) | `api` of same feature | Lightweight stand-in for IDE/sync/demo | + +Rules that still hold: + +- **No `androidLibrary`** — roles stay typed +- **`impl` ↛ `impl`** — stubs do not depend on production impls (or each other) +- Composition **only at roots** (`androidBinary` / `androidApp`) +- Roots depend on **api + one of impl/stub-impl** — never both (duplicate bindings) + +Default wiring uses **impl**. Stubs compile as real modules so you can prove the +layout; they are not on the production classpath unless you swap deps. +This example sets `org.gradle.configureondemand=false` so stub-impl siblings are +always configured and validated even when unused by the default root graph. + +## Manual stub swap (teaser → F-104) + +1. In `root-app/build.gradle.kts` and `binary/build.gradle.kts`, replace + `target(":feature:hello:impl")` with `target(":feature:hello:stub-impl")` + (same for `world`). +2. In `HelloActivity`, import `StubHelloMessage` / `StubWorldMessage` instead of + the `Default*` classes. +3. `./gradlew :binary:assembleDebug` — UI text becomes `HelloStub WorldStub`. + +**F-104** will automate impl→stub via a **project-global flag** (IDE sync / +compileOnly+runtimeOnly style). This step only teaches the **physical layout** +and keeps stubs wireable by hand. + +## Build + +```bash +source ../../../scripts/env-mac.sh +printf 'sdk.dir=%s\n' "$ANDROID_HOME" > local.properties +./gradlew :binary:assembleDebug +# Optional: prove stubs compile without swapping roots +./gradlew :feature-hello-stub-impl:compileDebugKotlin :feature-world-stub-impl:compileDebugKotlin +``` + +Expect **BUILD SUCCESSFUL**. Default APK shows combined hello + world messages +from **impl** (`Hello World`). + +## Principles + +1. Bazel-like types — call sites are attributes only (`api` / `impl` / roots) +2. One global way — co-located `{api,impl,stub-impl}` is a **layout convention**, not a + second target DSL +3. Explicit structure — role folders declare boundaries; matrix unchanged + +## Non-goals + +- F-104 IDE configuration substitution APIs +- Forma engine / dependency-matrix changes (including a dedicated `stub` type/suffix) +- Restoring `androidLibrary` +- Changing gold `application/` sample layout + +## Related + +- Step 02 — minimal api+impl +- Step 07 — multi-feature composition +- F-104 — automated stub swap for IDE sync +- Agent skill: `examples/agent-skills/forma-project-layout.md` diff --git a/examples/android/15-hybrid-targets/binary/build.gradle.kts b/examples/android/15-hybrid-targets/binary/build.gradle.kts new file mode 100644 index 00000000..b79f0488 --- /dev/null +++ b/examples/android/15-hybrid-targets/binary/build.gradle.kts @@ -0,0 +1,18 @@ +androidBinary( + packageName = "tools.forma.examples.android.hybrid", + versionCode = 1, + versionName = "0.1.0", + dependencies = deps( + target(":root-app"), + // Production path: api + impl (not stub). Do not wire both impl and stub-impl. + target(":feature:hello:api"), + target(":feature:hello:impl"), + target(":feature:world:api"), + target(":feature:world:impl"), + // Manual stub swap preview (F-104 will automate via project-global flag): + // target(":feature:hello:api"), + // target(":feature:hello:stub-impl"), + // target(":feature:world:api"), + // target(":feature:world:stub-impl"), + ) +) diff --git a/examples/android/15-hybrid-targets/binary/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/binary/src/main/AndroidManifest.xml new file mode 100644 index 00000000..839c8a97 --- /dev/null +++ b/examples/android/15-hybrid-targets/binary/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/examples/android/15-hybrid-targets/build.gradle.kts b/examples/android/15-hybrid-targets/build.gradle.kts new file mode 100644 index 00000000..18f086e0 --- /dev/null +++ b/examples/android/15-hybrid-targets/build.gradle.kts @@ -0,0 +1,9 @@ +buildscript { + androidProjectConfiguration( + project = rootProject, + minSdk = 23, + targetSdk = 37, + compileSdk = 37, + agpVersion = "9.3.0", + ) +} diff --git a/examples/android/15-hybrid-targets/feature/hello/api/build.gradle.kts b/examples/android/15-hybrid-targets/feature/hello/api/build.gradle.kts new file mode 100644 index 00000000..e4d13b27 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/api/build.gradle.kts @@ -0,0 +1,3 @@ +api( + packageName = "tools.forma.examples.android.hybrid.feature.hello.api" +) diff --git a/examples/android/15-hybrid-targets/feature/hello/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/api/HelloMessage.kt b/examples/android/15-hybrid-targets/feature/hello/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/api/HelloMessage.kt new file mode 100644 index 00000000..50b2c2d9 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/api/HelloMessage.kt @@ -0,0 +1,5 @@ +package tools.forma.examples.android.hybrid.feature.hello.api + +interface HelloMessage { + fun text(): String +} diff --git a/examples/android/15-hybrid-targets/feature/hello/impl/build.gradle.kts b/examples/android/15-hybrid-targets/feature/hello/impl/build.gradle.kts new file mode 100644 index 00000000..a48c185b --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/impl/build.gradle.kts @@ -0,0 +1,6 @@ +impl( + packageName = "tools.forma.examples.android.hybrid.feature.hello.impl", + dependencies = deps( + target(":feature:hello:api") + ) +) diff --git a/examples/android/15-hybrid-targets/feature/hello/impl/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/feature/hello/impl/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8072ee00 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/impl/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/examples/android/15-hybrid-targets/feature/hello/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/impl/DefaultHelloMessage.kt b/examples/android/15-hybrid-targets/feature/hello/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/impl/DefaultHelloMessage.kt new file mode 100644 index 00000000..a6aff11d --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/impl/DefaultHelloMessage.kt @@ -0,0 +1,7 @@ +package tools.forma.examples.android.hybrid.feature.hello.impl + +import tools.forma.examples.android.hybrid.feature.hello.api.HelloMessage + +class DefaultHelloMessage : HelloMessage { + override fun text(): String = "Hello" +} diff --git a/examples/android/15-hybrid-targets/feature/hello/stub-impl/build.gradle.kts b/examples/android/15-hybrid-targets/feature/hello/stub-impl/build.gradle.kts new file mode 100644 index 00000000..e56bcfa6 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/stub-impl/build.gradle.kts @@ -0,0 +1,10 @@ +// Real module implementing the same api with a lightweight stand-in. +// Target type is impl — Gradle/Forma name must end with -impl (hence stub-impl/). +// packageName uses …stub so sources stay distinct from production impl. +// Not wired by default — see root deps comments. F-104 will swap impl→stub via flag. +impl( + packageName = "tools.forma.examples.android.hybrid.feature.hello.stub", + dependencies = deps( + target(":feature:hello:api") + ) +) diff --git a/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8072ee00 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/stub/StubHelloMessage.kt b/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/stub/StubHelloMessage.kt new file mode 100644 index 00000000..9c39c59c --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/hello/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/hello/stub/StubHelloMessage.kt @@ -0,0 +1,8 @@ +package tools.forma.examples.android.hybrid.feature.hello.stub + +import tools.forma.examples.android.hybrid.feature.hello.api.HelloMessage + +/** Lightweight stand-in for [tools.forma.examples.android.hybrid.feature.hello.impl.DefaultHelloMessage]. */ +class StubHelloMessage : HelloMessage { + override fun text(): String = "HelloStub" +} diff --git a/examples/android/15-hybrid-targets/feature/world/api/build.gradle.kts b/examples/android/15-hybrid-targets/feature/world/api/build.gradle.kts new file mode 100644 index 00000000..46f634d4 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/api/build.gradle.kts @@ -0,0 +1,3 @@ +api( + packageName = "tools.forma.examples.android.hybrid.feature.world.api" +) diff --git a/examples/android/15-hybrid-targets/feature/world/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/api/WorldMessage.kt b/examples/android/15-hybrid-targets/feature/world/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/api/WorldMessage.kt new file mode 100644 index 00000000..c39788ce --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/api/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/api/WorldMessage.kt @@ -0,0 +1,5 @@ +package tools.forma.examples.android.hybrid.feature.world.api + +interface WorldMessage { + fun text(): String +} diff --git a/examples/android/15-hybrid-targets/feature/world/impl/build.gradle.kts b/examples/android/15-hybrid-targets/feature/world/impl/build.gradle.kts new file mode 100644 index 00000000..0efc64d5 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/impl/build.gradle.kts @@ -0,0 +1,6 @@ +impl( + packageName = "tools.forma.examples.android.hybrid.feature.world.impl", + dependencies = deps( + target(":feature:world:api") + ) +) diff --git a/examples/android/15-hybrid-targets/feature/world/impl/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/feature/world/impl/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8072ee00 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/impl/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/examples/android/15-hybrid-targets/feature/world/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/impl/DefaultWorldMessage.kt b/examples/android/15-hybrid-targets/feature/world/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/impl/DefaultWorldMessage.kt new file mode 100644 index 00000000..5acff734 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/impl/DefaultWorldMessage.kt @@ -0,0 +1,7 @@ +package tools.forma.examples.android.hybrid.feature.world.impl + +import tools.forma.examples.android.hybrid.feature.world.api.WorldMessage + +class DefaultWorldMessage : WorldMessage { + override fun text(): String = "World" +} diff --git a/examples/android/15-hybrid-targets/feature/world/stub-impl/build.gradle.kts b/examples/android/15-hybrid-targets/feature/world/stub-impl/build.gradle.kts new file mode 100644 index 00000000..a1b06cd8 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/stub-impl/build.gradle.kts @@ -0,0 +1,8 @@ +// Sibling stub for the world feature — same matrix rules as impl (depends on api only). +// Directory name stub-impl satisfies the impl type suffix rule. +impl( + packageName = "tools.forma.examples.android.hybrid.feature.world.stub", + dependencies = deps( + target(":feature:world:api") + ) +) diff --git a/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8072ee00 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/stub/StubWorldMessage.kt b/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/stub/StubWorldMessage.kt new file mode 100644 index 00000000..d29c19d6 --- /dev/null +++ b/examples/android/15-hybrid-targets/feature/world/stub-impl/src/main/kotlin/tools/forma/examples/android/hybrid/feature/world/stub/StubWorldMessage.kt @@ -0,0 +1,8 @@ +package tools.forma.examples.android.hybrid.feature.world.stub + +import tools.forma.examples.android.hybrid.feature.world.api.WorldMessage + +/** Lightweight stand-in for [tools.forma.examples.android.hybrid.feature.world.impl.DefaultWorldMessage]. */ +class StubWorldMessage : WorldMessage { + override fun text(): String = "WorldStub" +} diff --git a/examples/android/15-hybrid-targets/gradle.properties b/examples/android/15-hybrid-targets/gradle.properties new file mode 100644 index 00000000..735c029e --- /dev/null +++ b/examples/android/15-hybrid-targets/gradle.properties @@ -0,0 +1,11 @@ +# Progressive Android example +org.gradle.jvmargs=-Xmx2048m -XX:+UseParallelGC +org.gradle.parallel=true +org.gradle.caching=true +# Configure all modules so co-located stub-impl siblings are validated even when +# not on the default production classpath (api+impl path). +org.gradle.configureondemand=false +android.useAndroidX=true +android.enableJetifier=false +kotlin.code.style=official +android.nonTransitiveRClass=true diff --git a/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.jar b/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..7f93135c Binary files /dev/null and b/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.properties b/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..a351597e --- /dev/null +++ b/examples/android/15-hybrid-targets/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/android/15-hybrid-targets/gradlew b/examples/android/15-hybrid-targets/gradlew new file mode 100755 index 00000000..0adc8e1a --- /dev/null +++ b/examples/android/15-hybrid-targets/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/examples/android/15-hybrid-targets/gradlew.bat b/examples/android/15-hybrid-targets/gradlew.bat new file mode 100644 index 00000000..93e3f59f --- /dev/null +++ b/examples/android/15-hybrid-targets/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/android/15-hybrid-targets/root-app/build.gradle.kts b/examples/android/15-hybrid-targets/root-app/build.gradle.kts new file mode 100644 index 00000000..0643713e --- /dev/null +++ b/examples/android/15-hybrid-targets/root-app/build.gradle.kts @@ -0,0 +1,16 @@ +androidApp( + packageName = "tools.forma.examples.android.hybrid.root", + dependencies = deps( + target(":root-res"), + // Production path: api + impl. Swap impl → stub-impl manually to exercise stubs. + target(":feature:hello:api"), + target(":feature:hello:impl"), + target(":feature:world:api"), + target(":feature:world:impl"), + // Stub alternative (comment impl lines above; uncomment these): + // target(":feature:hello:api"), + // target(":feature:hello:stub-impl"), + // target(":feature:world:api"), + // target(":feature:world:stub-impl"), + ) +) diff --git a/examples/android/15-hybrid-targets/root-app/src/main/AndroidManifest.xml b/examples/android/15-hybrid-targets/root-app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..fff2a820 --- /dev/null +++ b/examples/android/15-hybrid-targets/root-app/src/main/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/examples/android/15-hybrid-targets/root-app/src/main/kotlin/tools/forma/examples/android/hybrid/root/HelloActivity.kt b/examples/android/15-hybrid-targets/root-app/src/main/kotlin/tools/forma/examples/android/hybrid/root/HelloActivity.kt new file mode 100644 index 00000000..1ab0bf72 --- /dev/null +++ b/examples/android/15-hybrid-targets/root-app/src/main/kotlin/tools/forma/examples/android/hybrid/root/HelloActivity.kt @@ -0,0 +1,26 @@ +package tools.forma.examples.android.hybrid.root + +import android.app.Activity +import android.os.Bundle +import android.widget.TextView +import tools.forma.examples.android.hybrid.feature.hello.api.HelloMessage +import tools.forma.examples.android.hybrid.feature.hello.impl.DefaultHelloMessage +import tools.forma.examples.android.hybrid.feature.world.api.WorldMessage +import tools.forma.examples.android.hybrid.feature.world.impl.DefaultWorldMessage + +/** + * Composition root wires hello + world from **impl** defaults. + * To try stubs: swap root-app/binary deps to `:…:stub-impl` and import + * [tools.forma.examples.android.hybrid.feature.hello.stub.StubHelloMessage] / + * [tools.forma.examples.android.hybrid.feature.world.stub.StubWorldMessage]. + */ +class HelloActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val hello: HelloMessage = DefaultHelloMessage() + val world: WorldMessage = DefaultWorldMessage() + val tv = TextView(this) + tv.text = hello.text() + " " + world.text() + setContentView(tv) + } +} diff --git a/examples/android/15-hybrid-targets/root-res/build.gradle.kts b/examples/android/15-hybrid-targets/root-res/build.gradle.kts new file mode 100644 index 00000000..63ccb403 --- /dev/null +++ b/examples/android/15-hybrid-targets/root-res/build.gradle.kts @@ -0,0 +1,3 @@ +androidRes( + packageName = "tools.forma.examples.android.hybrid.res" +) diff --git a/examples/android/15-hybrid-targets/root-res/src/main/res/values/strings.xml b/examples/android/15-hybrid-targets/root-res/src/main/res/values/strings.xml new file mode 100644 index 00000000..89088744 --- /dev/null +++ b/examples/android/15-hybrid-targets/root-res/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Forma 15 hybrid-targets + diff --git a/examples/android/15-hybrid-targets/settings.gradle.kts b/examples/android/15-hybrid-targets/settings.gradle.kts new file mode 100644 index 00000000..503fef69 --- /dev/null +++ b/examples/android/15-hybrid-targets/settings.gradle.kts @@ -0,0 +1,21 @@ +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + apply(from = "../../../build-settings/conventions/src/main/kotlin/convention-plugins.settings.gradle.kts") + includeBuild("../../../build-settings") + includeBuild("../../../plugins") + includeBuild("../../../includer") +} + +plugins { + id("convention-dependencies") + id("tools.forma.includer") + id("tools.forma.android") +} + +includer { arbitraryBuildScriptNames = true } + +rootProject.name = "15-hybrid-targets"