Skip to content

Commit 1c3335d

Browse files
Fix native-image build and add CLAUDE.md (#63)
* Add type hints to fix native-image reflection error BufferedWriter.write() calls used reflection which fails in GraalVM native-image closed-world analysis. Add ^java.io.Writer type hints at call sites so the compiler emits direct method invocations. * Add CLAUDE.md with agent guidelines * Address review feedback - Remove redundant (str header) — header is already a string - Add pre-commit hook install instructions to CLAUDE.md - Default branch is master (not main), no change needed * Fix pre-commit hook install command in CLAUDE.md Use cp + chmod to match the instructions in the hook script itself. * Use io alias consistently, remove unused trim import, add type hint comment
1 parent 650cb20 commit 1c3335d

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

CLAUDE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CLAUDE.md — Agent Guidelines for uap-clj
2+
3+
## Git Workflow
4+
5+
- **Never commit or push directly to `master`.** Always work on a feature branch.
6+
- Before any `git push`, verify the current branch with `git branch --show-current` and abort if on `master`.
7+
- Do not force-push or use `--no-verify` unless explicitly asked.
8+
9+
## Testing
10+
11+
- Run `clojure -T:build test` frequently — after any code change, before committing, and after merging.
12+
- All tests must pass before pushing.
13+
14+
## Build & Project
15+
16+
- Build system: deps.edn + tools.build (`build.clj`)
17+
- Key aliases: `:dev`, `:test`, `:build`, `:bench`
18+
- Build tasks: `clojure -T:build test`, `clojure -T:build uber`, `clojure -T:build native-image`
19+
- Formatting: cljstyle (runs via pre-commit hook in `hooks/pre-commit`; install with `cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit`)
20+
- Native image requires GraalVM with `native-image` on PATH
21+
22+
## Deploy
23+
24+
- Clojars deploy requires `-Djava.net.preferIPv4Stack=true` (already in `:build` alias JVM opts)
25+
- Use `clojure -T:build deploy` to publish to Clojars

src/uap_clj/core.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(:gen-class)
44
(:require
55
[clojure.java.io :as io]
6-
[clojure.string :as s :refer [join trim]]
6+
[clojure.string :as s :refer [join]]
77
[uap-clj.browser :refer [browser]]
88
[uap-clj.common :as common :refer :all]
99
[uap-clj.conf :refer [load-config]]
@@ -51,16 +51,18 @@
5151
'useragent_lookup.tsv' is the name of the default output file.
5252
"
5353
[in-file & opt-args]
54-
(with-open [rdr (clojure.java.io/reader in-file)]
54+
(with-open [rdr (io/reader in-file)]
5555
(let [out-file (or (first opt-args)
5656
(:output-filename cfg))
5757
results (doall
5858
(map useragent (line-seq rdr)))]
5959
(with-open
60-
[wtr (clojure.java.io/writer out-file :append false)]
61-
(.write wtr header)
60+
;; Type hints must be per-call: with-open macro expansion drops
61+
;; binding-level hints, causing reflection failures in native-image.
62+
[wtr (io/writer out-file :append false)]
63+
(.write ^java.io.Writer wtr header)
6264
(doseq [ua results]
63-
(.write wtr
65+
(.write ^java.io.Writer wtr
6466
(str (s/join \tab
6567
(map #(get-in ua %) columns))
6668
\newline)))))))

0 commit comments

Comments
 (0)