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

Port PropertyResourceBundle from Stapler #6

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,10 @@
package io.jenkins.plugins.localization.support.stapler;

import io.jenkins.plugins.localization.support.LocalizationContributor;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.PropertyResourceBundle;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.jelly.ResourceBundle;
Expand Down Expand Up @@ -68,7 +72,16 @@ protected Properties wrapUp(String locale, Properties props) {
URL url = LocalizationContributor.findResource(name, getClass());
if (url != null) {
try (InputStream stream = url.openStream()) {
props.load(stream);
PropertyResourceBundle propertyResourceBundle = new PropertyResourceBundle(stream);
Enumeration<String> keys = propertyResourceBundle.getKeys();
// TODO Java 9+ can use 'asIterator' and get rid of below collections conversion
List<String> keysAsSaneType = Collections.list(keys);

for (String localKey : keysAsSaneType) {
String value = propertyResourceBundle.getString(localKey);
props.setProperty(localKey, value);
}

} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Failed to load localized resources file " + name, ex);
}
Expand Down