Support multi bundle bindings in i18n-maven-plugin (#2748)

* Support multi bundle bindings in i18n-maven-plugin

The plugin did not generate translations for bundles of bindings that do not have a binding.xml file.
With this change it should also be possible to generate the default translations of the modbus and mqtt bindings.

Related to openhab/openhab-addons#12220

Signed-off-by: Wouter Born <github@maindrain.net>
pull/2788/head
Wouter Born 2022-02-20 11:57:18 +01:00 committed by GitHub
parent 7997e2636a
commit c300410fd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 10 deletions

View File

@ -33,12 +33,21 @@ import org.openhab.core.thing.xml.internal.ThingTypeXmlResult;
@NonNullByDefault @NonNullByDefault
public class BundleInfo { public class BundleInfo {
private String bindingId = "";
private @Nullable BindingInfoXmlResult bindingInfoXml; private @Nullable BindingInfoXmlResult bindingInfoXml;
private List<ConfigDescription> configDescriptions = new ArrayList<>(5); private List<ConfigDescription> configDescriptions = new ArrayList<>(5);
private List<ChannelGroupTypeXmlResult> channelGroupTypesXml = new ArrayList<>(5); private List<ChannelGroupTypeXmlResult> channelGroupTypesXml = new ArrayList<>(5);
private List<ChannelTypeXmlResult> channelTypesXml = new ArrayList<>(5); private List<ChannelTypeXmlResult> channelTypesXml = new ArrayList<>(5);
private List<ThingTypeXmlResult> thingTypesXml = new ArrayList<>(5); private List<ThingTypeXmlResult> thingTypesXml = new ArrayList<>(5);
public String getBindingId() {
return bindingId;
}
public void setBindingId(String bindingId) {
this.bindingId = bindingId;
}
public @Nullable BindingInfoXmlResult getBindingInfoXml() { public @Nullable BindingInfoXmlResult getBindingInfoXml() {
return bindingInfoXml; return bindingInfoXml;
} }
@ -79,11 +88,6 @@ public class BundleInfo {
this.thingTypesXml = thingTypesXml; this.thingTypesXml = thingTypesXml;
} }
public String getBindingId() {
BindingInfoXmlResult localBindingInfoXml = bindingInfoXml;
return localBindingInfoXml == null ? "" : localBindingInfoXml.getBindingInfo().getUID();
}
public Optional<ConfigDescription> getConfigDescription(@Nullable URI uri) { public Optional<ConfigDescription> getConfigDescription(@Nullable URI uri) {
if (uri == null) { if (uri == null) {
return Optional.empty(); return Optional.empty();

View File

@ -68,6 +68,7 @@ public class BundleInfoReader {
try { try {
BindingInfoXmlResult bindingInfoXml = reader.readFromXML(path.toUri().toURL()); BindingInfoXmlResult bindingInfoXml = reader.readFromXML(path.toUri().toURL());
if (bindingInfoXml != null) { if (bindingInfoXml != null) {
bundleInfo.setBindingId(bindingInfoXml.getBindingInfo().getUID());
bundleInfo.setBindingInfoXml(bindingInfoXml); bundleInfo.setBindingInfoXml(bindingInfoXml);
} }
} catch (ConversionException | MalformedURLException e) { } catch (ConversionException | MalformedURLException e) {
@ -102,11 +103,23 @@ public class BundleInfoReader {
} }
for (Object type : types) { for (Object type : types) {
if (type instanceof ThingTypeXmlResult) { if (type instanceof ThingTypeXmlResult) {
bundleInfo.getThingTypesXml().add((ThingTypeXmlResult) type); ThingTypeXmlResult result = (ThingTypeXmlResult) type;
bundleInfo.getThingTypesXml().add(result);
if (bundleInfo.getBindingId().isBlank()) {
bundleInfo.setBindingId(result.getUID().getBindingId());
}
} else if (type instanceof ChannelGroupTypeXmlResult) { } else if (type instanceof ChannelGroupTypeXmlResult) {
bundleInfo.getChannelGroupTypesXml().add((ChannelGroupTypeXmlResult) type); ChannelGroupTypeXmlResult result = (ChannelGroupTypeXmlResult) type;
bundleInfo.getChannelGroupTypesXml().add(result);
if (bundleInfo.getBindingId().isBlank()) {
bundleInfo.setBindingId(result.getUID().getBindingId());
}
} else if (type instanceof ChannelTypeXmlResult) { } else if (type instanceof ChannelTypeXmlResult) {
bundleInfo.getChannelTypesXml().add((ChannelTypeXmlResult) type); ChannelTypeXmlResult result = (ChannelTypeXmlResult) type;
bundleInfo.getChannelTypesXml().add(result);
if (bundleInfo.getBindingId().isBlank()) {
bundleInfo.setBindingId(result.toChannelType().getUID().getBindingId());
}
} }
} }
} catch (ConversionException | MalformedURLException e) { } catch (ConversionException | MalformedURLException e) {

View File

@ -51,8 +51,8 @@ import org.openhab.core.types.StateDescription;
public class XmlToTranslationsConverter { public class XmlToTranslationsConverter {
public Translations convert(BundleInfo bundleInfo) { public Translations convert(BundleInfo bundleInfo) {
BindingInfoXmlResult bindingInfoXml = bundleInfo.getBindingInfoXml(); String bindingId = bundleInfo.getBindingId();
return bindingInfoXml == null ? configTranslations(bundleInfo) : bindingTranslations(bundleInfo); return bindingId.isBlank() ? configTranslations(bundleInfo) : bindingTranslations(bundleInfo);
} }
private Translations bindingTranslations(BundleInfo bundleInfo) { private Translations bindingTranslations(BundleInfo bundleInfo) {