Repository navigation
Extract shared Windows WMI logic into common base classes - #3276
Conversation
Move WMI query logic and memoized getters into a common abstract WindowsFirmware class in oshi-common. JNA and FFM subclasses now only provide the WmiQueryExecutor. Partial fix for #3274 (Issue 1: JNA/FFM parallel implementations)
Move WMI query logic and memoized getters into a common abstract WindowsBaseboard class in oshi-common. JNA and FFM subclasses now only provide the WmiQueryExecutor. Partial fix for #3274 (Issue 1: JNA/FFM parallel implementations)
|
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 (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). (11)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (4)
📝 WalkthroughWalkthroughCentralizes Windows WMI hardware queries into three common abstractions (WindowsBaseboard, WindowsComputerSystem, WindowsFirmware) that memoize and normalize results; platform JNA/FFM subclasses now extend these and supply a WmiQueryExecutor. Tests validate UNKNOWN fallbacks and BIOS serial querying. ChangesWindows WMI Hardware Identification Abstraction
Sequence Diagram(s)sequenceDiagram
participant WindowsBaseboardFFM
participant WindowsBaseboard
participant WmiQueryExecutorFFM
WindowsBaseboardFFM->>WindowsBaseboard: call getManufacturer()/getModel()/...
WindowsBaseboard->>WmiQueryExecutorFFM: getWmiQueryExecutor().queryWin32BaseBoard()
WmiQueryExecutorFFM->>WindowsBaseboard: return Quartet(manufacturer, model, version, serial)
WindowsBaseboard-->>WindowsBaseboardFFM: normalized values (Constants.UNKNOWN if blank)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 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 #3276 +/- ##
============================================
+ Coverage 74.69% 74.82% +0.13%
Complexity 73 73
============================================
Files 407 410 +3
Lines 15958 15894 -64
Branches 2554 2534 -20
============================================
- Hits 11920 11893 -27
+ Misses 2558 2545 -13
+ Partials 1480 1456 -24
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:
|
abdaca2 to
42f755d
Compare
Move WMI query logic (manufacturer, model, serial number, UUID) and memoized getters into a common abstract WindowsComputerSystem class in oshi-common. JNA and FFM subclasses provide the WmiQueryExecutor and factory methods for Firmware/Baseboard. Partial fix for #3274 (Issue 1: JNA/FFM parallel implementations)
42f755d to
12c44bd
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java (1)
90-94: ⚡ Quick winCover the non-empty BIOS serial fallback path.
These tests prove the empty-result behavior, but they never assert that
getSerialNumber()actually uses the BIOS value whenIDENTIFYINGNUMBERis blank. Add a case for that branch so the new shared fallback logic can’t regress silently.🤖 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-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java` around lines 90 - 94, Add a new unit test in WindowsComputerSystemTest that exercises the fallback path: construct a WindowsComputerSystem (similar to createWithEmptyExecutor/createWithExecutor variants) where the WMI Win32_ComputerSystem IDENTIFYINGNUMBER is blank but querySerialFromBios() returns a non-empty string, then assert that getSerialNumber() returns the BIOS value; reference the existing test name testQuerySerialFromBiosReturnsNullWhenEmpty and the methods getSerialNumber(), querySerialFromBios(), and the IDENTIFYINGNUMBER field to locate where to add the new test.
🤖 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.
Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java`:
- Around line 90-94: Add a new unit test in WindowsComputerSystemTest that
exercises the fallback path: construct a WindowsComputerSystem (similar to
createWithEmptyExecutor/createWithExecutor variants) where the WMI
Win32_ComputerSystem IDENTIFYINGNUMBER is blank but querySerialFromBios()
returns a non-empty string, then assert that getSerialNumber() returns the BIOS
value; reference the existing test name
testQuerySerialFromBiosReturnsNullWhenEmpty and the methods getSerialNumber(),
querySerialFromBios(), and the IDENTIFYINGNUMBER field to locate where to add
the new test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8b88b109-96fa-4c9b-94f2-d7ab6a65faff
📒 Files selected for processing (4)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.javaoshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.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). (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.java
📚 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/windows/WindowsComputerSystemJNA.java
🔇 Additional comments (4)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.java (1)
32-103: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java (1)
25-79: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java (1)
20-35: LGTM!oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java (1)
20-35: LGTM!
Summary
Addresses Issue 1 (JNA ↔ FFM Parallel Implementations) from #3274 for three simple WMI-only consumer classes.
Extracts duplicated WMI query logic and memoized getters into common abstract base classes in
oshi-common. JNA and FFM subclasses are reduced to thin wrappers that provide the platform-specificWmiQueryExecutor.Changes
WindowsFirmware (commit 1)
oshi-common/.../WindowsFirmware.java(83 lines)WindowsFirmwareJNA(75→24 lines),WindowsFirmwareFFM(75→24 lines)WindowsBaseboard (commit 2)
oshi-common/.../WindowsBaseboard.java(78 lines)WindowsBaseboardJNA(63→24 lines),WindowsBaseboardFFM(63→24 lines)WindowsComputerSystem (commit 3)
oshi-common/.../WindowsComputerSystem.java(104 lines)WindowsComputerSystemJNA(109→36 lines),WindowsComputerSystemFFM(109→36 lines)Pattern
Each common base class:
abstract WmiQueryExecutor getWmiQueryExecutor()Win32*driver methods with the executorEach JNA/FFM subclass:
getWmiQueryExecutor()returning the platform executorcreateFirmware(),createBaseboard()) where neededTesting
Net impact
Summary by CodeRabbit