Skip to content

feat: add Java framework support - #948

Merged
sarahxsanders merged 8 commits into
mainfrom
posthog-code/java-framework-support
Aug 21, 2026
Merged

sarahxsanders merged 8 commits into
mainfrom
posthog-code/java-framework-support

Conversation

@sarahxsanders

@sarahxsanders sarahxsanders commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related PRs:

Adds Java (server) as a supported framework. Java is the one language here whose manifest collides with existing frameworks — Android and KMP both claim gradle projects — so detection is deliberately conservative:

  • Integration.java enum entry ordered after kmp/swift/android (they claim gradle projects first, enforced by a new enum-order test) and before the language fallbacks
  • JAVA_AGENT_CONFIG in src/frameworks/java/ — claims pom.xml unconditionally (Maven is unambiguously a JVM backend); claims root gradle files only when they carry no Android/KMP plugin markers and no AndroidManifest.xml exists anywhere in the tree (mirroring the Android detector's own strategies, so a direct detect() call can never claim their projects); Flutter's pubspec.yaml guard included
  • gatherContext records the build tool (maven | gradle) for analytics tags and the agent prompt
  • detectJavaPackageManagers — a real detector (Maven via pom.xml, otherwise the existing gradlePackageManager); install guidance is manual-edit-then-resolve since neither tool has a single add verb, pinning com.posthog:posthog-server from Maven Central
  • Prompt context warns the agent that posthog-android is a different library, and covers the client lifecycle (close() on shutdown, flush() in serverless)
  • No bash-fence changes: mvn/mvnw and gradle/gradlew grammars already exist from Android/KMP
  • Pins framework: java on a new integration-java entry in the variant-resolution contract test, matching the context-mill PR above

Why: the wizard docs page lists Java as "Coming soon"; instead of removing the label (posthog.com#18797), we're making the wizard actually support it.

Verification: pnpm build ✅, pnpm test ✅ (1560 tests, incl. 7 new java detect cases + enum-order + package-manager detection tests), pnpm fix ✅


Created with PostHog Code

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

@sarahxsanders
sarahxsanders force-pushed the posthog-code/rust-framework-support branch from 700cbba to 6cad9a7 Compare July 22, 2026 20:41
@sarahxsanders
sarahxsanders force-pushed the posthog-code/java-framework-support branch from ffc03e7 to de69e22 Compare July 22, 2026 20:41
@sarahxsanders
sarahxsanders changed the base branch from posthog-code/rust-framework-support to main July 22, 2026 20:42
Adds Java (server) as a supported framework, stacked on the Rust framework PR:

- Integration.java enum entry ordered after kmp/swift/android — those claim gradle projects first — and before the language fallbacks
- JAVA_AGENT_CONFIG in src/frameworks/java/ — claims pom.xml unconditionally (Maven is unambiguously JVM backend) and root gradle files only when they carry no Android/KMP plugin markers and no AndroidManifest.xml subtree exists; gathers buildTool (maven | gradle) as agent context; installs by editing the build file with com.posthog:posthog-server then resolving with mvn install / gradle build
- detectJavaPackageManagers detector (Maven via pom.xml, Gradle fallback reusing gradlePackageManager) + FRAMEWORK_REGISTRY entry
- No bash-fence changes needed: mvn/mvnw and gradle/gradlew grammars already exist from Android/KMP
- Pins framework: java on a new integration-java entry in the variant-resolution contract test, matching context-mill PR #270 which must release before this merges
- Marks pom.xml as a real framework target in the agentic manifest comment, leaving .NET as the only manifest without a target

Generated-By: PostHog Code
Task-Id: 9c949855-7611-48f2-b8b5-7aa4112543e5
@sarahxsanders
sarahxsanders force-pushed the posthog-code/java-framework-support branch from de69e22 to c8c2d59 Compare July 22, 2026 20:43
@sarahxsanders
sarahxsanders marked this pull request as ready for review July 24, 2026 15:16
@sarahxsanders
sarahxsanders requested a review from a team as a code owner July 24, 2026 15:16
Additive conflicts against the Flutter work: both kept; drops the pre-rename
duplicate of the Flutter detection test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
projectTypeDetection:
'This is a Java server project. Look for pom.xml (Maven) or build.gradle/build.gradle.kts (Gradle), src/main/java/, and the framework in use (Spring Boot, Quarkus, Micronaut, plain servlets) to confirm.',
packageInstallation:
'Neither Maven nor Gradle has a single add command. Add the com.posthog:posthog-server dependency (pinned to the latest release on Maven Central) to pom.xml or build.gradle(.kts), matching the existing dependency format, then run `mvn install` or `gradle build` to resolve it.',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High: Repository-defined code execution

An attacker can execute arbitrary commands on a developer's machine by placing an execution plugin in pom.xml or code in a Gradle build script: this prompt directs the agent to run mvn install or gradle build, and both commands are permitted by the Bash fence without user approval. Add the dependency by editing the manifest, but do not automatically execute a project lifecycle; the mvn install value returned by detectJavaPackageManagers must also be removed or made non-executable so the generic package-manager instructions cannot trigger the same path.

function readRootGradleFiles(installDir: string): string[] {
return GRADLE_FILES.map((name) => path.join(installDir, name))
.filter((p) => fs.existsSync(p))
.map((p) => fs.readFileSync(p, 'utf-8'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low: Unbounded project scanning

An attacker can exhaust memory or stall the wizard by supplying oversized root Gradle files or a large or symlinked tree of AndroidManifest.xml files. Use readProjectFile for the build files and boundedGlob with limit: 1 for the manifest check; these helpers enforce file-size, traversal, match-count, and deadline bounds.

@veria-ai

veria-ai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

PR overview

This pull request adds Java framework support to the wizard agent, including detection of Maven, Gradle, and Android projects and instructions for adding dependencies.

Three security issues remain open, with none addressed so far. A malicious repository could cause arbitrary commands to run through Maven or Gradle lifecycle execution, while symlinked manifests could expose local secret files to the agent. Unbounded file and directory scanning also creates a denial-of-service risk.

Open issues (3)

Fixed/addressed: 0 · PR risk: 8/10

@gewenyu99

Copy link
Copy Markdown
Collaborator

Full e2e run of this PR pair (wizard #948 + context-mill #270, both with main merged in) against spring-projects/spring-petclinic.

Set up, one honest conflict — the runner has no JRE so the agent could not self-verify. Idiomatic Spring: @Bean(destroyMethod = "close") for shutdown flush, blank config disables cleanly, posthog-server 2.7.0 added to both pom.xml and build.gradle, exception handler wired, null-safe capture helper.

Dashboard and notebook created through prod MCP. Compiles clean, but petclinic's own spring-javaformat gate fails on PetController.java — shipped unverified because the runner lacks a JRE.

Note: the context-mill branch as filed fails at the dashboard step — its agent prompts predate the posthog_exec tool grant on main; works once main is merged (currently blocked on unsigned commits).

All 25 TUI frames 01-intro.png 02-run.png 03-run.png 04-run.png 05-run.png 06-run.png 07-run.png 08-run.png 09-run.png 10-run.png 11-run.png 12-run.png 13-run.png 14-run.png 15-run.png 16-run.png 17-run.png 18-run.png 19-run.png 20-run.png 21-outro.png 22-outro.png 23-mcp.png 24-slack-connect.png 25-keep-skills.png

gewenyu99 and others added 2 commits August 20, 2026 18:49
The result JSON parsed package.json and pubspec.yaml only, so Go, Rust, Java,
and Elixir runs reported hasPosthogDep false; a *.env file like gotify's also
failed the .env prefix check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…sitive

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
sarahxsanders and others added 2 commits August 20, 2026 20:42
Go framework support landed on main in parallel, so most conflicts were two
frameworks claiming the same list. Kept both sides, with java staying after
kmp/swift/android so those keep first claim on gradle projects.

Also restores the "a Flutter project resolves to flutter" detection test, which
this branch overwrote with its Maven test. Main still has it, so the merge is
the right place to bring it back.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

if (fs.existsSync(path.join(installDir, 'pom.xml'))) {
return true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High: Symlinked manifests bypass secret-file fencing

An attacker can commit pom.xml as a symlink to .env. When the victim has that file, this check classifies the repository as Java, and the integration instructions subsequently make the agent read pom.xml before editing it; the tool gate sees the benign basename rather than .env, so the secret contents enter the model context. Reject symlinks and require each Java manifest's resolved path to remain inside installDir before using it for detection; apply the same check to the Gradle files.

@sarahxsanders
sarahxsanders enabled auto-merge (squash) August 21, 2026 14:26
sarahxsanders and others added 2 commits August 21, 2026 10:30
Elixir support (#946) landed on main, so the conflicts were java and elixir
claiming the same lists. Kept both sides throughout.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rust support (#947) landed on main, so the conflicts were java and rust
claiming the same lists. Kept both sides, with java staying after
kmp/swift/android so those keep first claim on gradle projects.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sarahxsanders
sarahxsanders merged commit c56a894 into main Aug 21, 2026
17 checks passed
@sarahxsanders
sarahxsanders deleted the posthog-code/java-framework-support branch August 21, 2026 14:41
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