-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor NLS messages #612
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
26a0cd9
c72ba15
218fc5d
f6ff615
474a11f
10a2825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,89 +10,56 @@ | |
| *******************************************************************************/ | ||
| package io.openliberty.tools.eclipse.messages; | ||
|
|
||
| import org.eclipse.osgi.util.NLS; | ||
| import java.text.MessageFormat; | ||
| import java.util.Locale; | ||
| import java.util.ResourceBundle; | ||
|
|
||
| /** | ||
| * Translated messages. | ||
| * Provides access to NLS Messages. | ||
| */ | ||
| public class Messages extends NLS { | ||
| public class Messages { | ||
|
|
||
| /** DebugModeHandler */ | ||
| public static String multiple_server_env; | ||
|
|
||
| /** DevModeOperations */ | ||
| public static String start_no_project_found; | ||
| public static String start_already_issued; | ||
| public static String start_general_error; | ||
|
|
||
| public static String start_container_no_project_found; | ||
| public static String start_container_already_issued; | ||
| public static String start_container_general_error; | ||
|
|
||
| public static String stop_no_project_found; | ||
| public static String stop_already_issued; | ||
| public static String stop_general_error; | ||
|
|
||
| public static String run_tests_no_project_found; | ||
| public static String run_tests_no_prior_start; | ||
| public static String run_tests_general_error; | ||
|
|
||
| public static String mvn_int_test_report_no_project_found; | ||
| public static String mvn_int_test_report_none_found; | ||
| public static String mvn_int_test_report_general_error; | ||
|
|
||
| public static String mvn_unit_test_report_no_project_found; | ||
| public static String mvn_unit_test_report_none_found; | ||
| public static String mvn_unit_test_report_general_error; | ||
|
|
||
| public static String gradle_test_report_no_project_found; | ||
| public static String gradle_test_report_none_found; | ||
| public static String gradle_test_report_general_error; | ||
|
|
||
| public static String issue_stop_prompt; | ||
| public static String plugin_stop_issue_error; | ||
| public static String plugin_stop_timeout; | ||
| public static String plugin_stop_failed; | ||
| public static String plugin_stop_general_error; | ||
|
|
||
| /** WorkspaceProjectsModel */ | ||
| public static String project_analyze_error; | ||
|
|
||
| /** DashboardView */ | ||
| public static String project_not_gradle_or_maven; | ||
| public static String image_descriptions_error; | ||
| public static String action_general_error; | ||
| public static String dashboard_refresh_error; | ||
|
|
||
| /** JRETab */ | ||
| public static String java_default_set_error; | ||
| public static String java_resolution_error; | ||
|
|
||
| /** LaunchConfigurationDelegateLauncher */ | ||
| public static String launch_config_error; | ||
|
|
||
| /** StartTab */ | ||
| public static String start_parm_retrieve_error; | ||
| public static String project_name_error; | ||
| public static String run_config_initialize_error; | ||
|
|
||
| /** All *Action classes */ | ||
| public static String launch_shortcut_error; | ||
|
|
||
| /** ExplorerMenuHandler */ | ||
| public static String project_not_valid; | ||
| public static String menu_command_retrieve_error; | ||
| public static String menu_command_process_error; | ||
|
|
||
| /** CommandBuilder */ | ||
| public static String maven_exec_not_found; | ||
| public static String gradle_exec_not_found; | ||
| /** Message Resource bundle */ | ||
| private static ResourceBundle NLS_BUNDLE; | ||
| static { | ||
| try { | ||
| NLS_BUNDLE = ResourceBundle.getBundle("io.openliberty.tools.eclipse.messages.Messages", Locale.getDefault()); | ||
| } catch (Exception e) { | ||
| NLS_BUNDLE = ResourceBundle.getBundle("io.openliberty.tools.eclipse.messages.Messages"); | ||
| } | ||
| } | ||
|
|
||
| /** Project */ | ||
| public static String determine_java_project_error; | ||
| public static String liberty_nature_add_error; | ||
| /** | ||
| * Returns a translated message with no arguments. | ||
| * | ||
| * @param key The message Key. | ||
| * | ||
| * @return The translated message without arguments. | ||
| */ | ||
| public static String getMessage(String key) { | ||
| return getMessage(key, (Object) null); | ||
| } | ||
|
|
||
| static { | ||
| NLS.initializeMessages("io.openliberty.tools.eclipse.messages.Messages", Messages.class); | ||
| /** | ||
| * Returns a translated message with arguments. | ||
| * | ||
| * @param key The message key. | ||
| * @param args The arguments associated with the message. | ||
| * | ||
| * @return A translated message with arguments. | ||
| */ | ||
| public static String getMessage(String key, Object... args) { | ||
| String msg = null; | ||
|
|
||
| try { | ||
| msg = NLS_BUNDLE.getString(key); | ||
| if (msg != null && args != null) { | ||
| msg = MessageFormat.format(msg, args); | ||
| } | ||
| } catch (Exception e) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we catch more specific exceptions here to give a finer grained reason for failure?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in all cases, the reason is pretty much that there is an issue with that particular message property. Either the key being used is wrong, or the value in the properties file is wrong. In either case, it's a bug in our code and the failed message lookup should be enough to indicate that. |
||
| msg = key; | ||
| } | ||
|
|
||
| return msg; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this could be null - if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the |
||
| } | ||
| } | ||
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.
is there a chance that both of these inti's could fail? at that point NLS_BUNDLE would be null - should we initialize it to an empty ResourceBundle?
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.
No, there shouldnt be a chance of that since we are using the fully qualified classname for this class. If the class is running within the bundle, we should be able to lookup the bundle based on the class.