Repository navigation
Hoist BSD/Mac OperatingSystem version, session, and boot-time queries into bases - #3470
Conversation
… into bases The FreeBSD, DragonFly, OpenBSD, and Mac OperatingSystem twins duplicated queryFamilyVersionInfo (sysctl kern.ostype/osrelease/version), getSessions (who/getutxent), and boot-time logic between their JNA and FFM backends, differing only in the native call. Hoist those into the per-platform bases behind small native hooks (querySysctl, queryWhoSessions, queryKernBoottimeSeconds), with the shared version-info parse (buildFamilyVersionInfo) and boot-time command fallback (queryBootTimeFromCommand) as static helpers on BsdOperatingSystem. The helpers add no abstract methods, so the command-line NetBSD implementation is untouched. Each twin now provides only its native hook implementations plus the irreducible factories and getpid/getThreadId. The genuinely-divergent native capability detection twins (Solaris kstat2, Linux udev/gettid, Windows registry perf counters) are intentionally left as is. Behavior-preserving refactor; no CHANGELOG.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (14)
📜 Recent review details⏰ Context from checks skipped due to timeout. (12)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (22)
📝 WalkthroughWalkthroughmacOS and BSD common classes now centralize OS version, session, and boot-time orchestration. JNA and FFM implementations provide protected native-query hooks, while obsolete public overrides and command-parsing paths are removed. A Checkstyle suppression range is updated for the macOS additions. ChangesOS query hook refactor
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CommonOperatingSystem
participant NativeBackend
participant NativeAPI
CommonOperatingSystem->>NativeBackend: querySysctl or queryWhoSessions
NativeBackend->>NativeAPI: invoke native sysctl or who access
NativeAPI-->>NativeBackend: values or sessions
NativeBackend-->>CommonOperatingSystem: return query result
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3470 +/- ##
============================================
- Coverage 75.26% 75.15% -0.11%
Complexity 76 76
============================================
Files 589 589
Lines 21528 21511 -17
Branches 3592 3593 +1
============================================
- Hits 16202 16167 -35
- Misses 3371 3391 +20
+ Partials 1955 1953 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Part of the cross-OS consistency/dedup audit (OperatingSystem subsystem, follow-on to the AIX base extraction #3469). The FreeBSD, DragonFly, OpenBSD, and Mac
OperatingSystemJNA/FFM twins duplicated three methods whose logic is identical and differs only in the native backend.What's hoisted
queryFamilyVersionInfo— thekern.ostype/kern.osrelease/kern.version(Mac:kern.osversion) sysctl reads plus the shared buildNumber parse.getSessions— theUSE_WHO_COMMAND ? super : who.getutxent()selection.kern.boottimesysctl read plus thesysctl -n kern.boottimecommand fallback (FreeBSD/DragonFly).These move into the per-platform bases behind small native hooks —
querySysctl,queryWhoSessions,queryKernBoottimeSeconds— and each twin now provides only those hook implementations plus the irreducibleFileSystem/NetworkParams/InternetProtocolStats/OSProcessfactories andgetpid/getThreadId.The shared version-info parse (
buildFamilyVersionInfo) and boot-time command fallback (queryBootTimeFromCommand) live as static helpers onBsdOperatingSystem— no new abstract methods — so the command-line NetBSD implementation is untouched. OpenBSD's mib-based sysctl is handled by aquerySysctl(int[], String)hook with the MIB identifiers defined on the OpenBSD base.Left as-is (deliberate)
The Solaris (
HAS_KSTAT2kstat2 probing), Linux (HAS_UDEV/HAS_GETTIDauxv/udev/gettid detection), and Windows (registry perf-counter suppliers) twins diverge in genuine native capability detection, not shareable logic — the same hard axis as the COM/PDH and Mac struct-reading cases.No CHANGELOG entry: behavior is identical.
Local gate: spotless, checkstyle, forbiddenapis, javadoc, and a clean full-reactor build all pass; oshi-common and oshi-core tests pass. Mac runtime is validated locally —
NativeComparisonTest.operatingSystemInfo()andsessions()(JNA==FFM) pass on Apple Silicon. FreeBSD and OpenBSD run on the pull-request CI; DragonFly is validated via a manualunix.yamldispatch (it isn't part of the PR workflow).Summary by CodeRabbit
New Features
Bug Fixes