Repository navigation
Extract shared BSD parsers and add cross-platform unit tests - #3312
Conversation
OpenBSD and NetBSD shipped near-identical copies of disklabel and systat
sensor parsing; consolidate them under oshi.driver.unix.bsd so the
parsing logic has a single home and is reachable from any OS for test
coverage. Split the FstatUtil/ProcstatUtil parsing loops out of their
ExecutingCommand wrappers so each pure-parse method takes a List<String>
and can be exercised with sample command output.
- New oshi.driver.unix.bsd.disk.Disklabel replaces the per-OS copies in
oshi.driver.unix.{openbsd,netbsd}.disk; partition parsing accepts an
injectable major/minor lookup. totalSectors parses as long for both
platforms (OpenBSD copy previously used getFirstIntValue, which would
overflow for >2 TiB disks at 512-byte sectors).
- New oshi.driver.unix.bsd.Systat exposes parseSensors,
parsePowerSourceNames, parseBatteryFields and an immutable
BatteryFields holder. OpenBsdSensors/NetBsdSensors shrink to thin
AbstractSensors subclasses that delegate to Systat::querySensors;
OpenBsdPowerSource/NetBsdPowerSource use Systat.queryBatteryFields for
the systat sensor portion.
- FstatUtil (netbsd, openbsd) and ProcstatUtil (dragonflybsd, freebsd)
now have parseCwdFromFstat / parseOpenFiles / parseCwdMap / parseCwd
static methods called by the existing public methods, so command
execution and parsing are separable.
Tests:
- DisklabelTest, SystatTest exercise the new parsers with sample
disklabel and systat output; live-system smoke tests remain gated to
OpenBSD/NetBSD/DragonFly.
- FstatUtilTest and ProcstatUtilTest in netbsd/openbsd/freebsd/
dragonflybsd packages add parse-method coverage that runs on any CI
platform.
- module-info.test adds opens for oshi.driver.unix.bsd[.disk] and
oshi.util.platform.unix.dragonflybsd; removes the now-empty per-OS
disk opens.
|
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 (6)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughThis PR centralizes BSD sensor and disk parsing into shared drivers (Systat, Disklabel), migrates NetBSD/OpenBSD platform code to use them, extracts parsing helpers from several platform utilities, and adds unit and gated live tests. ChangesBSD Utility Consolidation and Parsing Extraction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 #3312 +/- ##
============================================
+ Coverage 71.77% 72.30% +0.52%
Complexity 76 76
============================================
Files 433 434 +1
Lines 16846 16879 +33
Branches 2748 2746 -2
============================================
+ Hits 12092 12204 +112
+ Misses 3268 3177 -91
- Partials 1486 1498 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java (1)
52-62:⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
parseOpenFilesreturns-1for empty input, breaking the non-negative open-files contract.Unlike the NetBSD/DragonFlyBSD counterparts (which guard with
size() > 1/fd > 0 ? fd - 1 : 0), this method subtracts the header unconditionally. Iffstat -sp <pid>returns no lines (command failure, dead process),fdstays0and the method returns-1. That value flows straight throughgetOpenFiles(int)intoOpenBsdOSProcess.getOpenFiles(), surfacing a negative count to callers.Guard the subtraction as the sibling parsers do.
🛡️ Proposed fix
- // subtract 1 for header row - return fd - 1; + // subtract 1 for header row, but never go negative on empty/failed output + return fd > 0 ? fd - 1 : 0;Note:
testParseOpenFilesEmptyinFstatUtilTestcurrently assertsis(-1L)and would need to be updated tois(0L)after this change.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java` around lines 52 - 62, parseOpenFiles currently always subtracts 1 for a header and can return -1 for empty input; change parseOpenFiles in FstatUtil so it guards the header subtraction (e.g., only subtract when fd > 0 or when fstatLines.size() > 1) and return 0 instead of negative values, ensuring callers like getOpenFiles(int) and OpenBsdOSProcess.getOpenFiles() never see a negative count; also update the FstatUtilTest.testParseOpenFilesEmpty expectation from -1L to 0L.
🧹 Nitpick comments (2)
oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java (2)
86-91: ⚡ Quick winResolve major/minor only for rows that become partitions.
majorMinorLookup.apply(...)runs before thesplit.length > 4guard, so the default lookup (getMajorMinor) spawns astat -fprocess for rows that are subsequently discarded (e.g. thec"entire disk" row and short rows likei:). Move the lookup inside the guard to avoid the extra external command per filtered row.♻️ Proposed change
String[] split = ParseUtil.whitespaces.split(line.trim(), 9); String name = split[0].substring(0, 1); - Pair<Integer, Integer> majorMinor = majorMinorLookup.apply(diskName, name); if (split.length > 4) { + Pair<Integer, Integer> majorMinor = majorMinorLookup.apply(diskName, name); partitions.add(new HWPartition(diskName + name, name, split[3], duid + "." + name, ParseUtil.parseLongOrDefault(split[1], 0L) * bytesPerSector, majorMinor.getA(), majorMinor.getB(), split.length > 5 ? split[split.length - 1] : "")); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java` around lines 86 - 91, The code calls majorMinorLookup.apply(diskName, name) before checking split.length > 4, causing unnecessary external stat calls for non-partition rows; move the majorMinorLookup.apply(...) invocation inside the guard that builds partitions (the if (split.length > 4) block) and use its returned Pair<Integer,Integer> when constructing the HWPartition (same block that calls new HWPartition(...)) so only rows that become partitions trigger the major/minor lookup (referencing majorMinorLookup.apply, the split.length > 4 guard, and the HWPartition construction).
41-48: 💤 Low valueFix/clarify fallback behavior in Disklabel.getDiskParams when disklabel returns only header metadata
Disklabel.getDiskParamsfalls back toparseDfFallbackwheneverdisklabel -nyields an empty partition list (result.getD().isEmpty()). Even ifparseDiskParamssuccessfully parsed header fields (label,duid, and total size fromtotal sectors:/bytes/sector:),parseDfFallbackreplaces the whole quartet withConstants.UNKNOWN/0L, discarding that metadata. OpenBSD and NetBSD both route through this same sharedDisklabel.getDiskParams, so the all-or-nothing fallback behavior is consistent across both OSes.If the goal is “use
dfonly to fill missing partitions”, consider preserving thelabel/duid/sizefrom thedisklabelparse and only swapping the partition list when it’s empty.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java` around lines 41 - 48, getDiskParams currently discards any header metadata parsed by parseDiskParams (label/duid/size) whenever result.getD().isEmpty() by calling parseDfFallback which returns a whole Quartet of UNKNOWN/0L; change this so that when parseDiskParams returns a Quartet with non-empty header fields but an empty partition list, you call parseDfFallback only to obtain partitions and then construct/return a new Quartet combining the original label/duid/size from the parseDiskParams result with the partition list from parseDfFallback instead of replacing the entire Quartet; update the logic around result = parseDiskParams(...), the result.getD().isEmpty() branch, and the use of parseDfFallback so only the D element (List<HWPartition>) is replaced when appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java`:
- Around line 1-4: Update the license header in package-info.java to match
Spotless’ template by removing the "(c)" so it reads "Copyright 2026 The OSHI
Project Contributors" (aligning with the $YEAR format used elsewhere) and keep
the SPDX-License-Identifier: MIT line; modify the header in the
package-info.java file containing the BSD disk driver package declaration to
exactly match the template used by other files like Disklabel.java.
In
`@oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java`:
- Around line 48-58: getPowerSources() currently calls
Systat.queryPowerSourceNames() then repeatedly calls getPowerSource(name) which
invokes Systat.queryBatteryFields(name), causing "systat -ab sensors" to run for
each battery; instead run the sensor command once and reuse its parsed output:
modify Systat to expose a single method (e.g., querySensorLines() or the command
string) that returns all lines or parsed blocks, call that once in
getPowerSources(), use existing parse* helpers to build BatteryFields for each
name, and change getPowerSource(String) to accept parsed data (or lookup into
the cached parse) so Systat.queryBatteryFields(name) is not re-invoked per power
source.
In
`@oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.java`:
- Around line 48-58: getPowerSources currently calls
Systat.queryPowerSourceNames() then calls Systat.queryBatteryFields(name) for
each name, causing Systat (systat -ab sensors) to be run N+1 times; instead run
the systat command once, capture its output, parse names and battery fields from
that single output, and pass the parsed data into
getPowerSource/getPowerSources. Concretely: modify Systat to expose a method
that returns the raw systat output (or a parsed token list), call that once in
OpenBsdPowerSource.getPowerSources, derive the list of names from that captured
output (instead of calling queryPowerSourceNames()), and change or add versions
of queryBatteryFields/parseBatteryFields that take the captured output (or
parsed tokens) so getPowerSource(name) uses the in-memory output to build
BatteryFields without spawning the command repeatedly.
---
Outside diff comments:
In `@oshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.java`:
- Around line 52-62: parseOpenFiles currently always subtracts 1 for a header
and can return -1 for empty input; change parseOpenFiles in FstatUtil so it
guards the header subtraction (e.g., only subtract when fd > 0 or when
fstatLines.size() > 1) and return 0 instead of negative values, ensuring callers
like getOpenFiles(int) and OpenBsdOSProcess.getOpenFiles() never see a negative
count; also update the FstatUtilTest.testParseOpenFilesEmpty expectation from
-1L to 0L.
---
Nitpick comments:
In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java`:
- Around line 86-91: The code calls majorMinorLookup.apply(diskName, name)
before checking split.length > 4, causing unnecessary external stat calls for
non-partition rows; move the majorMinorLookup.apply(...) invocation inside the
guard that builds partitions (the if (split.length > 4) block) and use its
returned Pair<Integer,Integer> when constructing the HWPartition (same block
that calls new HWPartition(...)) so only rows that become partitions trigger the
major/minor lookup (referencing majorMinorLookup.apply, the split.length > 4
guard, and the HWPartition construction).
- Around line 41-48: getDiskParams currently discards any header metadata parsed
by parseDiskParams (label/duid/size) whenever result.getD().isEmpty() by calling
parseDfFallback which returns a whole Quartet of UNKNOWN/0L; change this so that
when parseDiskParams returns a Quartet with non-empty header fields but an empty
partition list, you call parseDfFallback only to obtain partitions and then
construct/return a new Quartet combining the original label/duid/size from the
parseDiskParams result with the partition list from parseDfFallback instead of
replacing the entire Quartet; update the logic around result =
parseDiskParams(...), the result.getD().isEmpty() branch, and the use of
parseDfFallback so only the D element (List<HWPartition>) is replaced when
appropriate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1ccaf3c4-8837-4d10-81c2-ba5c920e1035
📒 Files selected for processing (27)
oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.javaoshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.javaoshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.javaoshi-core/src/main/java/oshi/driver/unix/bsd/package-info.javaoshi-core/src/main/java/oshi/driver/unix/netbsd/disk/Disklabel.javaoshi-core/src/main/java/oshi/driver/unix/netbsd/disk/package-info.javaoshi-core/src/main/java/oshi/driver/unix/openbsd/disk/Disklabel.javaoshi-core/src/main/java/oshi/driver/unix/openbsd/disk/package-info.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.javaoshi-core/src/main/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/freebsd/ProcstatUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/netbsd/FstatUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/openbsd/FstatUtil.javaoshi-core/src/test/java/module-info.testoshi-core/src/test/java/oshi/driver/unix/bsd/SystatTest.javaoshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.javaoshi-core/src/test/java/oshi/driver/unix/netbsd/disk/DisklabelTest.javaoshi-core/src/test/java/oshi/driver/unix/openbsd/disk/DisklabelTest.javaoshi-core/src/test/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtilTest.javaoshi-core/src/test/java/oshi/util/platform/unix/freebsd/ProcstatUtilTest.javaoshi-core/src/test/java/oshi/util/platform/unix/netbsd/FstatUtilTest.javaoshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java
💤 Files with no reviewable changes (6)
- oshi-core/src/test/java/oshi/driver/unix/openbsd/disk/DisklabelTest.java
- oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/package-info.java
- oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/package-info.java
- oshi-core/src/test/java/oshi/driver/unix/netbsd/disk/DisklabelTest.java
- oshi-core/src/main/java/oshi/driver/unix/openbsd/disk/Disklabel.java
- oshi-core/src/main/java/oshi/driver/unix/netbsd/disk/Disklabel.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdPowerSource.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdPowerSource.java
🔇 Additional comments (16)
oshi-core/src/test/java/oshi/util/platform/unix/openbsd/FstatUtilTest.java (1)
53-58: This test pins the-1Lreturn for empty input, which is the latent negative-count bug flagged at the root cause inFstatUtil.parseOpenFiles. Once that method is guarded, update this assertion tois(0L).oshi-core/src/main/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtil.java (1)
64-82: LGTM!Also applies to: 101-121
oshi-core/src/main/java/oshi/util/platform/unix/freebsd/ProcstatUtil.java (1)
32-51: LGTM!Also applies to: 60-78, 87-106
oshi-core/src/main/java/oshi/util/platform/unix/netbsd/FstatUtil.java (1)
33-50: LGTM!Also applies to: 60-75
oshi-core/src/test/java/oshi/util/platform/unix/dragonflybsd/ProcstatUtilTest.java (1)
32-91: LGTM!oshi-core/src/test/java/oshi/util/platform/unix/freebsd/ProcstatUtilTest.java (1)
33-98: LGTM!oshi-core/src/test/java/oshi/util/platform/unix/netbsd/FstatUtilTest.java (1)
29-73: LGTM!oshi-core/src/test/java/module-info.test (1)
27-30: LGTM!Also applies to: 36-36
oshi-core/src/main/java/oshi/driver/unix/bsd/Systat.java (1)
35-151: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdSensors.java (1)
13-39: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdSensors.java (1)
13-39: LGTM!oshi-core/src/test/java/oshi/driver/unix/bsd/SystatTest.java (1)
29-154: LGTM!oshi-core/src/main/java/oshi/driver/unix/bsd/package-info.java (1)
1-4: Same license header format concern as inoshi/driver/unix/bsd/disk/package-info.java(Copyright (c) 2026vs the project'sCopyright 2026 The OSHI Project Contributors).oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHWDiskStore.java (1)
17-17: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java (1)
17-17: LGTM!oshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.java (1)
46-160: LGTM!
| /* | ||
| * Copyright (c) 2026 The OSHI Project Contributors | ||
| * SPDX-License-Identifier: MIT | ||
| */ |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n '^ \* Copyright' --type=java | sed -E 's/[0-9]{4}(-[0-9]{4})?//' | sort | uniq -c | sort -rnRepository: oshi/oshi
Length of output: 50366
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Inspect the exact header in the file under review
FILE="oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java"
echo "---- $FILE (lines 1-10) ----"
sed -n '1,10p' "$FILE" || true
# 2) Count how many Java files use "(c)" vs not (based on the "Copyright" header line)
echo "---- Count: Java files with 'Copyright (c)' ----"
rg -n --type java '^ \* Copyright \(c\)' . | wc -l
echo "---- Count: Java files with 'Copyright' but NOT '(c)' ----"
rg -n --type java '^ \* Copyright(?! \(c\))' . | wc -l
# 3) Find likely license/header enforcement configuration
echo "---- Search build for license/header enforcement ----"
rg -n --hidden --glob '!.git/**' -S \
'spotless|license|rat|license-maven-plugin|maven-enforcer-plugin|header|copyright' \
pom.xml build.gradle* build.gradle.kts* settings.gradle* settings.gradle.kts* .github . | head -n 200Repository: oshi/oshi
Length of output: 766
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Recompute counts without lookaround
TOTAL=$(rg -n --type java '^ \* Copyright' . | wc -l)
WITHC=$(rg -n --type java '^ \* Copyright \(c\)' . | wc -l)
NONC=$((TOTAL-WITHC))
echo "---- Count: Java files with 'Copyright' (any) ----"
echo "$TOTAL"
echo "---- Count: Java files with 'Copyright (c)' ----"
echo "$WITHC"
echo "---- Derived: Java files with 'Copyright' but NOT '(c)' ----"
echo "$NONC"
# Locate build/header enforcement configuration
echo "---- Search build for header/license enforcement ----"
rg -n --hidden -S \
'spotless|license|rat|license-maven-plugin|license-header|header-check|enforcer|maven-enforcer-plugin|apache-rat|licenseHeader' \
pom.xml build.gradle* build.gradle.kts* settings.gradle* settings.gradle.kts* \
.github/workflows . | head -n 200Repository: oshi/oshi
Length of output: 21502
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "---- pom.xml: Spotless licenseHeader section (context) ----"
# Print around the known lines from earlier grep output
sed -n '440,560p' pom.xml
echo "---- config/license-header.txt ----"
ls -la config/license-header.txt || true
sed -n '1,120p' config/license-header.txt || trueRepository: oshi/oshi
Length of output: 6426
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="oshi-core/src/main/java/oshi/driver/unix/bsd/disk/Disklabel.java"
echo "---- $FILE (lines 1-10) ----"
sed -n '1,10p' "$FILE" || trueRepository: oshi/oshi
Length of output: 359
Fix the license header in this file to match Spotless’ template
pom.xml configures Spotless to enforce config/license-header.txt, whose expected header is * Copyright $YEAR The OSHI Project Contributors (no (c)). This file uses * Copyright (c) 2026 The OSHI Project Contributors, so the header check may fail—update it to match the template (and align the year format with other BSD disk headers like Disklabel.java).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@oshi-core/src/main/java/oshi/driver/unix/bsd/disk/package-info.java` around
lines 1 - 4, Update the license header in package-info.java to match Spotless’
template by removing the "(c)" so it reads "Copyright 2026 The OSHI Project
Contributors" (aligning with the $YEAR format used elsewhere) and keep the
SPDX-License-Identifier: MIT line; modify the header in the package-info.java
file containing the BSD disk driver package declaration to exactly match the
template used by other files like Disklabel.java.
…abel - Systat: add public querySensorLines() returning the raw `systat -ab sensors` output; the existing single-purpose query* methods now route through it. OpenBsdPowerSource and NetBsdPowerSource take the lines once in getPowerSources() and pass them to a per-battery getPowerSource(name, lines) that uses Systat.parseBatteryFields, eliminating the N+1 systat invocations the previous wiring produced when multiple batteries were present. - FstatUtil (openbsd) parseOpenFiles: guard the header-row subtraction so empty or single-row input returns 0 instead of -1. Callers (OpenBsdOSProcess.getOpenFiles / NetBsdOSProcess.getOpenFiles) propagate the return value directly. Existing test updated. - Disklabel (bsd): move the major/minor lookup inside the split.length > 4 (parseDiskParams) and split.length > 5 (parseDfFallback) guards so non-partition rows don't trigger a stat(1) call. - Disklabel.getDiskParams: when disklabel returned header metadata but no partitions, preserve the label/DUID/size and replace only the partition list with the df fallback result, instead of returning the entirely-UNKNOWN fallback Quartet.
Summary
oshi.driver.unix.{openbsd,netbsd}into a new sharedoshi.driver.unix.bsdpackage, so the parsing logic lives in one place and is reachable from any OS for test coverage.FstatUtil(openbsd/netbsd) andProcstatUtil(freebsd/dragonflybsd) so each pure-parse method takes aList<String>and can be exercised against sample command output without needing the live OS.What changed
New shared driver package:
oshi.driver.unix.bsdbsd.disk.Disklabelreplaces the per-OS Disklabel copies; partition parsing accepts an injectable(disk,name) -> (major,minor)lookup so tests don't shell out tostat.totalSectorsis parsed aslongfor both platforms (the OpenBSD copy previously usedgetFirstIntValue, which would overflow for >2 TiB disks at 512-byte sectors — NetBSD's copy already had this fix).bsd.SystatexposesparseSensors,parsePowerSourceNames,parseBatteryFieldsand an immutableBatteryFieldsholder.OpenBsdSensors/NetBsdSensorsshrink to thinAbstractSensorssubclasses that delegate toSystat::querySensors;OpenBsdPowerSource/NetBsdPowerSourceuseSystat.queryBatteryFieldsfor the systat sensor portion of their battery query.Parse-method split in existing utils
FstatUtil(netbsd, openbsd) —parseCwdFromFstat,parseOpenFilesstatic methods called by the existing public methods.ProcstatUtil(dragonflybsd, freebsd) —parseCwdFromFstat/parseCwdMap/parseCwd/parseOpenFilesstatic methods called by the existing public methods.Tests
DisklabelTest,SystatTest: exercise the new shared parsers against sample disklabel / systat output. Live-system smoke tests remain gated to OpenBSD/NetBSD.FstatUtilTest(netbsd, openbsd) andProcstatUtilTest(dragonflybsd, freebsd): add parse-method coverage that runs on any CI platform; per-OS integration tests are gated as before.module-info.test: add opens foroshi.driver.unix.bsd[.disk]andoshi.util.platform.unix.dragonflybsd; remove the now-empty per-OS disk opens.Why
The recent DragonFly/NetBSD ports landed by copy-rename from the FreeBSD/OpenBSD code, leaving near-byte-identical parsing classes side by side. The previously added OS-gated tests don't run on the linux/mac/win CI runners, so codecov shows 0% coverage for the new code. Extracting the pure parsing into a shared, OS-agnostic location lets us write tests that run on every platform and cover the parsing logic for both OpenBSD and NetBSD at once.
Net effect
Test plan
mvn -pl oshi-core verifypasses (compile, spotless, checkstyle, forbiddenapis, tests)oshi.driver.unix.bsdpackage and the refactored fstat/procstat utilsSummary by CodeRabbit
New Features
Refactor
Tests