Skip to content

Extract shared Windows WMI logic into common base classes - #3276

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:refactor/windows-wmi-dedup
May 20, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:refactor/windows-wmi-dedup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 20, 2026 •

Copy link
Copy Markdown
Member

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-specific WmiQueryExecutor.

Changes

WindowsFirmware (commit 1)

  • New: oshi-common/.../WindowsFirmware.java (83 lines)
  • Simplified: WindowsFirmwareJNA (75→24 lines), WindowsFirmwareFFM (75→24 lines)

WindowsBaseboard (commit 2)

  • New: oshi-common/.../WindowsBaseboard.java (78 lines)
  • Simplified: WindowsBaseboardJNA (63→24 lines), WindowsBaseboardFFM (63→24 lines)

WindowsComputerSystem (commit 3)

  • New: oshi-common/.../WindowsComputerSystem.java (104 lines)
  • Simplified: WindowsComputerSystemJNA (109→36 lines), WindowsComputerSystemFFM (109→36 lines)

Pattern

Each common base class:

  1. Declares abstract WmiQueryExecutor getWmiQueryExecutor()
  2. Holds all shared WMI query logic and memoized getters
  3. Calls the common Win32* driver methods with the executor

Each JNA/FFM subclass:

  1. Implements getWmiQueryExecutor() returning the platform executor
  2. Overrides factory methods (createFirmware(), createBaseboard()) where needed

Testing

  • All existing tests pass
  • Full verification: spotless, checkstyle, install, forbiddenapis, javadoc all green
  • No public API changes

Net impact

  • -385 lines removed from JNA/FFM subclasses
  • +310 lines in common base classes
  • Net reduction: ~75 lines (but eliminates 100% of logic duplication across these 3 class families)

Summary by CodeRabbit

  • Refactor
    • Consolidated Windows hardware info retrieval so baseboard, firmware, and system identifiers are provided consistently across Windows implementations, improving reliability.
  • Bug Fixes
    • Blank or missing WMI fields are now normalized to a standard "unknown" value to avoid empty outputs.
  • Tests
    • Added tests verifying fallbacks when WMI returns no data.

Review Change Stack

dbwiddis added 2 commits May 20, 2026 00:44
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)
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f25091a4-65e3-469f-aaa9-df8f7f4486b6

📥 Commits

Reviewing files that changed from the base of the PR and between 42f755d and 12c44bd.

📒 Files selected for processing (4)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java
📜 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)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-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)

1-104: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java (1)

1-92: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java (1)

7-35: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java (1)

7-35: LGTM!


📝 Walkthrough

Walkthrough

Centralizes 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.

Changes

Windows WMI Hardware Identification Abstraction

Layer / File(s) Summary
Common platform abstractions
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsBaseboard.java, oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.java, oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsFirmware.java, oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java
Adds three abstract Windows-specific base classes that memoize WMI queries (baseboard Quartet, firmware Quintet, computer-system manufacturer/model and serial/UUID), normalize blank/missing fields to Constants.UNKNOWN, provide BIOS serial fallback, and define protected abstract WmiQueryExecutor getWmiQueryExecutor(). Tests validate UNKNOWN fallbacks and BIOS query behavior.
FFM platform refactoring
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareFFM.java
FFM classes now extend the new common abstractions and implement getWmiQueryExecutor() via WmiQueryExecutorFFM.createInstance(). Removed prior in-class memoized WMI query helpers and accessor overrides.
JNA platform refactoring
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareJNA.java
JNA classes refactored to extend the common Windows abstractions and implement getWmiQueryExecutor() via WmiQueryExecutorJNA.createInstance(). Duplicated WMI query and parsing logic removed from these subclasses.

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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • oshi/oshi#3266: Introduces the WmiQueryExecutor abstraction that these new base classes depend on via getWmiQueryExecutor().
  • oshi/oshi#3175: Prior FFM Windows hardware implementations that are further refactored here to delegate to common abstractions.
  • oshi/oshi#3267: Adds shared WMI helper methods and result parsing used by the common abstractions.

"I'm a rabbit in the code so spry,
I cached a WMI query on the fly,
Fields now return known names,
Duplicates hop out of the lanes,
Hooray for neat, shared supply!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Extract shared Windows WMI logic into common base classes' directly and clearly summarizes the main change: refactoring duplicated WMI query logic from JNA/FFM subclasses into new common abstract base classes (WindowsFirmware, WindowsBaseboard, WindowsComputerSystem).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.78261% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.82%. Comparing base (3e175cc) to head (12c44bd).

Files with missing lines Patch % Lines
...ware/common/platform/windows/WindowsBaseboard.java 72.72% 0 Missing and 6 partials ⚠️
...dware/common/platform/windows/WindowsFirmware.java 75.00% 0 Missing and 6 partials ⚠️
...common/platform/windows/WindowsComputerSystem.java 94.11% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
linux 39.82% <22.82%> (+0.32%) ⬆️
macos 40.47% <22.82%> (+0.33%) ⬆️
windows 48.18% <84.78%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis force-pushed the refactor/windows-wmi-dedup branch from abdaca2 to 42f755d Compare May 20, 2026 01:01
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)
@dbwiddis
dbwiddis force-pushed the refactor/windows-wmi-dedup branch from 42f755d to 12c44bd Compare May 20, 2026 01:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java (1)

90-94: ⚡ Quick win

Cover 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 when IDENTIFYINGNUMBER is 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

📥 Commits

Reviewing files that changed from the base of the PR and between abdaca2 and 42f755d.

📒 Files selected for processing (4)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsComputerSystem.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsComputerSystemTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
  • oshi-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!

@dbwiddis
dbwiddis merged commit f06494d into oshi:master May 20, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the refactor/windows-wmi-dedup branch May 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant