Skip to content

清理 CPU 名称#3928

Merged
Glavo merged 12 commits into
HMCL-dev:mainfrom
Glavo:cpu-name
May 21, 2025
Merged

清理 CPU 名称#3928
Glavo merged 12 commits into
HMCL-dev:mainfrom
Glavo:cpu-name

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented May 21, 2025

No description provided.

@Glavo Glavo requested a review from Copilot May 21, 2025 05:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a standardized way to clean and normalize CPU model names across platforms, adds a whitespace-normalization utility, and covers both with unit tests.

  • Add CentralProcessor.cleanName to strip extraneous tokens from CPU names.
  • Update Windows and Linux detectors to apply cleanName before setting the CPU name.
  • Introduce StringUtils.normalizeWhitespaces and corresponding tests.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/hardware/CentralProcessor.java Add cleanName method to normalize CPU names
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows/WindowsCPUDetector.java Apply cleanName in Windows CPU detection
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxCPUDetector.java Apply cleanName in Linux CPU detection
HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java Add normalizeWhitespaces utility
HMCLCore/src/test/java/org/jackhuang/hmcl/util/platform/hardware/CentralProcessorTest.java Add tests for cleanName covering various CPU strings
HMCLCore/src/test/java/org/jackhuang/hmcl/util/StringUtilsTest.java Add tests for whitespace normalization

@Glavo Glavo requested review from Copilot and removed request for Copilot May 21, 2025 06:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a cleanName utility to normalize CPU model strings, integrates it into Windows/Linux detectors, and provides tests for both CPU name cleaning and whitespace normalization.

  • Introduce CentralProcessor.cleanName to strip extraneous suffixes and trademarks
  • Update Windows and Linux detectors to call cleanName when setting CPU names
  • Add JUnit tests for cleanName and StringUtils.normalizeWhitespaces

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CentralProcessor.java New cleanName method to sanitize raw CPU name strings
WindowsCPUDetector.java Apply cleanName when setting builder.name
LinuxCPUDetector.java Apply cleanName and handle additional “Model name” key
StringUtils.java New normalizeWhitespaces to trim/collapse whitespace
CentralProcessorTest.java Tests covering various CPU name inputs
StringUtilsTest.java Tests covering whitespace normalization
Comments suppressed due to low confidence (2)

HMCLCore/src/test/java/org/jackhuang/hmcl/util/platform/hardware/CentralProcessorTest.java:31

  • There’s no test asserting how cleanName handles a null input. Consider adding assertNull(cleanName(null)) or similar to codify expected behavior.
public void testCleanName() {

HMCLCore/src/test/java/org/jackhuang/hmcl/util/StringUtilsTest.java:30

  • Add a test for normalizeWhitespaces(null) to verify that passing null returns an empty string as implemented.
public void testNormalizeWhitespaces() {

* @author Glavo
*/
public final class CentralProcessor {

Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

The cleanName method lacks a JavaDoc explaining its normalization rules and null behavior. Consider adding a description of input/output expectations and examples.

Suggested change
/**
* Normalizes a processor name by removing unnecessary details and standardizing the format.
* <p>
* This method handles specific patterns for Intel, AMD, and Loongson processors, removing
* redundant information such as core counts, trademarks, and other suffixes. If the input
* is {@code null}, the method returns {@code null}.
* </p>
*
* <p><b>Examples:</b></p>
* <ul>
* <li>Input: {@code "Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz"} → Output: {@code "Intel Core i7-9700K"}</li>
* <li>Input: {@code "AMD Ryzen 5 3600 6-Core Processor"} → Output: {@code "AMD Ryzen 5 3600"}</li>
* <li>Input: {@code "Loongson-3A R4 (Loongson-3A3000)"} → Output: {@code "Loongson-3A3000"}</li>
* <li>Input: {@code null} → Output: {@code null}</li>
* </ul>
*
* @param name the original processor name, or {@code null}
* @return the normalized processor name, or {@code null} if the input is {@code null}
*/

Copilot uses AI. Check for mistakes.

public static String cleanName(String name) {
if (name == null)
return null;
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

cleanName returns null when input is null but its signature doesn’t reflect that. Consider annotating the method with @Nullable or returning an empty string for consistency with normalizeWhitespaces.

Suggested change
return null;
return "";

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 942f7b7 into HMCL-dev:main May 21, 2025
2 checks passed
@Glavo Glavo deleted the cpu-name branch May 21, 2025 06:22
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.

2 participants