Skip to content
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

add one param to set charset when read Properties file #93

Conversation

mamh2021
Copy link

@mamh2021 mamh2021 commented Mar 24, 2021

Signed-off-by: bright.ma RMSH06 bright.ma@blackshark.com

add one param to set charset when read Properties file

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

By default the jvm states that property files should be in ISO 8859-1 character encoding.

If you need to deviate from that standard I suggest adding an encoding parameter to the step.

@mamh2021 mamh2021 force-pushed the add-encoding-to-uft-8-when-read-Properties-file branch from 69bf86a to 35c44b8 Compare April 11, 2021 04:09
@mamh2021 mamh2021 changed the title java: add encoding to uft-8 when read Properties file java: add param encoding when read Properties file Apr 11, 2021
if(StringUtils.isEmpty(step.getEncoding())){
properties.load(is);
} else {
properties.load( new BufferedReader(new InputStreamReader(is, step.getEncoding())));
Copy link
Member

Choose a reason for hiding this comment

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

You need to close the streams or it will break things, especially on windows.
Something like above:

Suggested change
properties.load( new BufferedReader(new InputStreamReader(is, step.getEncoding())));
try(InputStreamReader is = new InputStreamReader(is, step.getEncoding()); BufferedReader br = new BufferedReader(is)) {
properties.load(br);
}

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

Sorry, I missed it last time; there is a config.jelly you need to add the new parameter to as well, so that the snippet generator works.

Besides that it all looks good.

@mamh2021 mamh2021 force-pushed the add-encoding-to-uft-8-when-read-Properties-file branch 2 times, most recently from 78a344d to fb0f2c4 Compare November 3, 2022 07:34
@mamh2021 mamh2021 changed the title java: add param encoding when read Properties file add one param to set charset when read Properties file Nov 3, 2022
</f:entry>
<f:entry title="${%interpolate.title}" field="interpolate" description="${%interpolate.description}">
<f:checkbox />
</f:entry>
Copy link
Member

Choose a reason for hiding this comment

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

added everything but the charset parameter?

bright.ma RMSH06 and others added 6 commits March 25, 2024 22:53
Signed-off-by: bright.ma RMSH06 <bright.ma@blackshark.com>
or it will break things, especially on windows.

Change-Id: Icc7a9a393d4fae9d546239f3545caf256f3a5b78
Signed-off-by: bright.ma <bright.ma@blackshark.com>
Keep the style same as WriteYamlStep
resources: update ReadPropertiesStep config.jelly for snippet generator
Change-Id: I5e2952cd3c4c92f7966bb7bc3be47a7042af27f3
@mamh2021 mamh2021 force-pushed the add-encoding-to-uft-8-when-read-Properties-file branch from fb0f2c4 to de2145a Compare March 25, 2024 15:03
@mamh2021 mamh2021 requested a review from a team as a code owner March 25, 2024 15:03
@rsandell rsandell merged commit 7fe33bc into jenkinsci:master Jun 24, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants