Repository navigation
feat(maven-plugin): add posthog-maven-plugin to upload jvm sources with hog - #1011
ablaszkiewicz wants to merge 15 commits into
Conversation
The upload-sources goal runs posthog-cli jvm upload on the project's sources and the source directories of kotlin-maven-plugin, and packages the id they were uploaded under in posthog-meta.properties, which posthog-server reads. The release version defaults to the git commit. When posthog-cli is missing or too old, or no credentials are set, the goal skips with a warning unless requireUpload is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
|
@PostHog review --deep |
|
@ablaszkiewicz PostHog Review is reviewing this pull request. |
PostHog Review · Deep · reviewed
|
| Step | Status | Result |
|---|---|---|
| Prepare the diff | done | 14 files, 2 chunks |
| Pick perspectives | done | 3 perspectives |
| Run review passes | done | 7 issues (+2 blind-spot) |
| Merge overlapping findings | done | 9 → 9 |
| Validate findings | done | 4 kept, 5 dismissed |
| Publish | done | 4 posted (view review) |
There was a problem hiding this comment.
See this review and its findings in PostHog Review.
- Run upload-sources in process-classes, after compilation, so the sources that annotation processors generate are uploaded. The id goes straight into the classes directory, because process-resources has already run. - Upload UTF-8 copies of Java sources whose declared encoding is not UTF-8. posthog-cli reads every file as UTF-8 and skips the others. - Put the CLI's directory and node's directory on the child PATH, so an npm launcher found outside PATH can start node. - On Windows, run the native binary of the npm package instead of its .cmd shim, so no argument passes through cmd. When only the shim can run, refuse values that hold cmd operators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
Parentheses start no command in cmd, and versions such as 1.0(5) hold them. Refuse the same characters as the Gradle plugin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
PR overviewAdds a PostHog Maven plugin to upload JVM sources with hog, including UTF-8 staging for sources using other encodings. One issue has been addressed, and one remains open in source staging. When staging is enabled for non-UTF-8 sources, Java or Kotlin symlinks can cause unrelated local files to be copied into the upload, potentially exposing credentials or other files outside the source tree. Exploitation requires a source symlink and a build configured to use staging. Open issues (1)
Fixed/addressed: 1 · PR risk: 6/10 Reviews |
Without the native binary, the plugin ran the bare name through cmd, and cmd looks in the project directory before PATH. The plugin now treats the shim as no install, so the build skips or fails with the install hint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
posthog-cli now uploads the sources without a release, so unchanged sources in a new release reuse the existing upload, and writes the release id into posthog-meta.properties for posthog-server to send with each exception. The README, the goal's javadoc and the changeset now say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5
dustinbyrne
left a comment
There was a problem hiding this comment.
Clean pure-Java, zero-runtime-dependency Maven plugin design; we verified locally with Apache Maven 3.9.11 (JDK 17.0.16) that the generated META-INF/maven/plugin.xml, <packaging>maven-plugin</packaging> POM, process-classes execution, and <pluginManagement> compiler encoding inheritance work end-to-end.
Leaving a COMMENT review for one breaking bug and a few concerns to address before approval:
- Breaking:
Utf8Sources.copydoes not normalize paths (.,..), which breaks thetarget//utf8-sources/skip guard and causes self-copying with mojibake corruption. - Concerns: release sequencing while
PostHog/posthog#144749andPostHog/posthog-android#1019are still open drafts; missing automatedMETA-INF/maven/plugin.xml/ Maven packaging test; contradictory multi-modulesourceRootsguidance inposthog-maven-plugin/README.md; Windows JDK 8–17 unset encoding skipping UTF-8 transcoding; and asymmetric behavior for missing explicit<sourceRoots>withrequireUpload=truevs empty existingsrc/main/javaonce credentials are set. - Follow-up (outside this repo): once
posthog-cli,posthog-server, andposthog-maven-pluginrelease, add JVM Maven source-upload documentation inPostHog/posthog.com(contents/docs/error-tracking/upload-source-maps/andcontents/docs/libraries/java/index.mdx), and optionally addposthog-maven-plugintoRELEASING.mdand rootCHANGELOG.md.
AI-assisted review.
…load A failed upload failed the build even without requireUpload, so a PostHog outage, a revoked key or rate limiting broke deploys. It now warns and ships no id. Local builds uploaded too, so a developer who ran posthog-cli login uploaded work in progress on every mvn test or mvn install, and could not build offline. Without requireUpload, the goal now uploads only from a CI build, not offline, and not in a module that another module of the build depends on, whose posthog-meta.properties could replace the application's on the classpath. requireUpload uploads from every build and fails it when the upload can't run, for deploy builds such as a Dockerfile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5
- Normalize source roots, so ${project.basedir}/. no longer makes the
UTF-8 copy walk into the build directory and copy itself.
- Add additionalSourceRoots, which adds to the default roots, for the
other modules of a multi-module build. sourceRoots still replaces
them.
- A configured source root that does not exist warns, and fails a
required upload.
- An unset source encoding falls back to the platform charset, which
javac also uses, so windows-1252 sources on Java 17 get UTF-8 copies.
- The help probe calls the CLI too old only when clap rejects the
command, and otherwise reports the exit code and first output line.
- Resolve a relative cliExecutable against the project, report a
configured path that does not exist, look for the CLI in nvm, strip
quotes from Windows PATH entries, and refuse a cmd line that would
cut a path with spaces short.
- Compile with --release 8, and test the generated plugin.xml in the
jar.
- Test the session checks through two hooks instead of the deprecated
MavenSession constructor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5
|
Thanks for the thorough review. Every inline point is addressed in f82d858, with a reply on each thread. The PR is back in draft until |
…upload-sources-hog
The upload-sources goal now runs `hog error-tracking process --kind jvm` instead of `posthog-cli jvm upload`, since only hog has the command. - Find hog the way the Android Gradle plugin does: PATH, then ~/.local/bin, nvm, /usr/local/bin and /opt/homebrew/bin, then the project's node_modules/.bin when node is installed. On Windows, search PATH with PATHEXT as cmd does, then ~/.local/bin/hog.exe, and run the hog.exe of the npm platform package instead of the hog.cmd shim. - Pass the dotenv file as HOG_DOTENV_FILE. - A missing hog skips with the install commands. Exit 3 skips as missing credentials, and exit 2, which an older hog returns for --kind jvm and --meta-out, skips with a `hog upgrade` hint. Every failure fails the build only when requireUpload is set. - Drop the plugin's deletes of posthog-meta.properties after a failed run, which hog guarantees. Keep the delete for builds that never start hog, and keep the UTF-8 copies, because hog skips non-UTF-8 files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename PostHogCli to Hog, the cliExecutable parameter to hogExecutable (property posthog.hogExecutable), and the tests and helpers that named the CLI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Call the tool hog without code formatting, keep code formatting for the `hog error-tracking process` command and `posthog.hogExecutable`, and list credentials as a requirement instead of only a personal API key, since hog also logs in with a CI job's OIDC token or `hog auth login`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- One blank-string helper, Hog.isBlank, instead of four copies. - One environment key lookup behind pathKey and variable. - One cmd rejection message, and firstUnsafeForCmd takes the executable and its arguments. - Both hog exit codes in Hog, one branch for every non-zero exit with the `hog upgrade` hint only for exit 2, and a shorter credentials message. - skipOrFail(String), metaPropertiesFile() and home() helpers, and hog resolved from the mojo's environment field. - Look node up once for a project launcher. - Decode with new String, which already replaces unmappable bytes, and create the target folder once per copied file. - Tests: an assertThrows helper for required uploads, one helper that writes executable scripts, the meta file name from the constant, and no duplicate success test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run `hog --version` before the upload. posthog-cli, or a hog older than MIN_HOG_VERSION (1.1.0, the first release with `hog error-tracking bundle`), skips the upload with a warning that says how to install or update hog, and fails it with requireUpload. The upload never runs with either. Versions compare numerically and ignore a prerelease suffix, and output without a version counts as too old. The exit 2 hint stays as a fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UTF-8 copies keep only Java and Kotlin files, so hog can't see the build files that mark a build output folder inside a copy. A broad root with a non-UTF-8 encoding could then upload generated sources that the same build without the copy skips. The copy now applies hog's folder skips to the original tree: hidden folders, node_modules, test source sets under src, and build, target and out folders next to a build file or src. A root is always copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A module counted as a library whenever another module of the build depended on it, so an application with an integration test, coverage or distribution module skipped the upload in CI with only an info line. Only a dependent module that runs the goal on sources of its own makes a module a library now. - A failed UTF-8 copy warns instead of failing a build whose upload is optional. - The UTF-8 copies keep a Java file that is valid UTF-8 already, so the sources of a module with another encoding stay readable. - The version check finds the version below a launcher warning on stderr. - The README says how a dotenv path resolves in a multi-module build, how a generated timestamp defeats reuse, and that hog now keeps a file that isn't UTF-8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| throws IOException { | ||
| String name = file.getFileName().toString(); | ||
| boolean java = name.endsWith(".java"); | ||
| if (!java && !name.endsWith(".kt")) { |
There was a problem hiding this comment.
Medium: UTF-8 staging follows source symlinks
When a non-UTF-8 encoding enables staging, walkFileTree passes symlinks to this visitor and readAllBytes/Files.copy dereference them, so a .java or .kt link to an unrelated local file becomes a regular staged file submitted for upload. Reject non-regular entries using the supplied no-follow attributes before reading or copying to prevent credentials or other files outside the source tree from being included.
| if (!java && !name.endsWith(".kt")) { | |
| if (!attributes.isRegularFile() || (!java && !name.endsWith(".kt"))) { |
Source code for JVM server exceptions, in release order:
hog error-tracking process --kind jvm(merged)posthog-meta.propertiescom.posthog.jvm: upload the sources at build timeWhat each step waits for:
💡 Motivation and Context
Maven teams need a build step that uploads their sources and packages the upload's id, so error tracking shows code on the frames of exceptions
posthog-servercaptures. This addscom.posthog:posthog-maven-pluginwith one goal,upload-sources.hog error-tracking process --kind jvm(feat(cli): bundle and upload jvm sources with hog posthog#144749) inprocess-classes, after compilation, and writesposthog-meta.propertiesinto the classes directory. feat(server): read the map id and release id from posthog-meta.properties #1019 makes the SDK read it.<sourceDirs>ofkotlin-maven-plugin, which mixed Java and Kotlin projects use.additionalSourceRootsadds other modules' directories, andsourceRootsreplaces the defaults. Java sources in a non-UTF-8 encoding, also the platform default when none is set, are uploaded as UTF-8 copies. A file that is valid UTF-8 already stays as it is, so another module's UTF-8 sources keep their characters.posthog.hogExecutable. On Windows it runs the npm package'shog.exeinstead of the.cmdshim, so arguments never pass through cmd. A shim without that binary counts as no install, and a configured.cmdpath refuses values with cmd operators.releaseVersionoverrides it.mvn testandmvn installon a laptop never upload work in progress or need the network. Offline builds skip too.posthog-meta.propertiescould replace the application's on the classpath. An integration-test or distribution module that depends on the app does not make the app skip.hog --versionfirst and needs hog 1.1.0 or newer. An older hog gets "runhog upgrade". A posthog-cli install never runs the upload, and its warning gives the hog install commands.requireUploaduploads from every build, also a Dockerfile outside CI, and turns each of those problems into a failure.settings.gradle.kts, the release workflow, the Makefile and the pnpm workspace. The first release is 0.1.0.💚 How did you test it?
META-INF/maven/plugin.xmlfrom the built jar and checks the goal, phase, properties and dependencies Maven reads.additionalSourceRoots, and the umlauts show correctly. Before the fix in this PR, the app skipped too.kotlin-maven-pluginproject with<sourceDirs>and mixed Java and Kotlin.requireUploadwithout credentials fails the build.Earlier runs with posthog-cli, before the move to hog
target/generated-sources/annotations, and the fat jar carries the id.kotlin-maven-pluginsetups, and a multi-stage Docker build against a local PostHog.posthog-cli0.18.10 (too old),requireUpload, and a 113 MB bundle.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset fileThe changeset
.changeset/maven-plugin-upload-sources.md(minor) was written by hand in the same format.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
hog upgrade.masteris 1.0.2, and its pending minor changeset makes the next release 1.1.0, whichHog.MIN_HOG_VERSIONalready requires.