forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[conf]: Modify the name of the properties file #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MatheMatrix
wants to merge
1
commit into
feature-5.4.6-nexavm
Choose a base branch
from
sync/haoyu.ding/fix-80219@@3
base: feature-5.4.6-nexavm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Bootstrap configuration for ZStack | ||
| This file determines which properties file to load at startup | ||
|
|
||
| The propertiesFile value can be replaced by build script for OEM customization: | ||
| - Default: zstack.properties | ||
| - Custom: will be replaced by Ant during build (e.g., myapp.properties) | ||
| --> | ||
| <bootstrap> | ||
| <!-- BUILD_REPLACE_MARKER: Do not modify manually, will be replaced during build --> | ||
| <propertiesFile>zstack.properties</propertiesFile> | ||
| </bootstrap> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package org.zstack.core.config; | ||
|
|
||
| import org.w3c.dom.Document; | ||
| import org.w3c.dom.NodeList; | ||
| import org.zstack.utils.path.PathUtil; | ||
|
|
||
| import javax.xml.parsers.DocumentBuilder; | ||
| import javax.xml.parsers.DocumentBuilderFactory; | ||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Centralized configuration reader for app_config.xml | ||
| * This class provides a single source of truth for the properties file name | ||
| * All other components should use this class instead of hardcoding "zstack.properties" | ||
| */ | ||
| public class AppConfig { | ||
| private static final String DEFAULT_PROPERTIES_FILE = "zstack.properties"; | ||
| private static volatile String propertiesFileName = null; | ||
|
|
||
| /** | ||
| * Get the properties file name from app_config.xml | ||
| * This method is thread-safe and caches the result | ||
| * | ||
| * @return properties file name (e.g., "zstack.properties", "myapp.properties") | ||
| */ | ||
| public static String getPropertiesFileName() { | ||
| if (propertiesFileName == null) { | ||
| synchronized (AppConfig.class) { | ||
| if (propertiesFileName == null) { | ||
| propertiesFileName = loadPropertiesFileNameFromConfig(); | ||
| } | ||
| } | ||
| } | ||
| return propertiesFileName; | ||
| } | ||
|
|
||
| /** | ||
| * Load properties file name from app_config.xml | ||
| * Falls back to "zstack.properties" if app_config.xml is not found or cannot be parsed | ||
| */ | ||
| private static String loadPropertiesFileNameFromConfig() { | ||
| try { | ||
| File appConfigFile = PathUtil.findFileOnClassPath("app_config.xml", true); | ||
| DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
| DocumentBuilder builder = factory.newDocumentBuilder(); | ||
| Document doc = builder.parse(appConfigFile); | ||
|
|
||
| NodeList nodes = doc.getElementsByTagName("propertiesFile"); | ||
| if (nodes.getLength() > 0) { | ||
| String fileName = nodes.item(0).getTextContent().trim(); | ||
| System.out.println("[AppConfig] Using properties file: " + fileName); | ||
| return fileName; | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("[AppConfig] Failed to load app_config.xml, using default: " + DEFAULT_PROPERTIES_FILE); | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| return DEFAULT_PROPERTIES_FILE; | ||
| } | ||
|
|
||
| /** | ||
| * Reset cached value (mainly for testing) | ||
| */ | ||
| public static void reset() { | ||
| propertiesFileName = null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1449
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 184
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 511
移除 Platform.java 中未使用的 XML 导入。
DocumentBuilder、DocumentBuilderFactory、Document和NodeList这些 XML 解析类在 Platform.java 中并未使用。XML 解析逻辑完全封装在 AppConfig 类内部。Platform.java 仅通过调用AppConfig.getPropertiesFileName()与之交互,无需这些导入。请移除第 56-59 行的这四个 XML 相关导入。🤖 Prompt for AI Agents