Skip to content

Commit

Permalink
Revert "Fix addon name localisation before installation (#3908)"
Browse files Browse the repository at this point in the history
This reverts commit 708a954
but with some modifications

Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Jan 21, 2025
1 parent ce37425 commit 2659c4c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ private Addon getAddon(Bundle bundle, @Nullable Locale locale) {
AddonInfo addonInfo = addonInfoRegistry.getAddonInfo(uid, locale);

if (addonInfo != null) {
if (addonInfo.isMasterAddonInfo()) {
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription());
} else {
addon = addon.withLabel(name);
}
addon = addon.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
// only enrich if this add-on is installed, otherwise wrong data might be added
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription())
.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
.withLink(getDefaultDocumentationLink(type, name))
.withConfigDescriptionURI(addonInfo.getConfigDescriptionURI());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
@NonNullByDefault
public class AddonInfo implements Identifiable<String> {

public static final String NA = "n/a";

private static final Set<String> SUPPORTED_ADDON_TYPES = Set.of("automation", "binding", "misc", "persistence",
"transformation", "ui", "voice");

Expand All @@ -48,13 +50,10 @@ public class AddonInfo implements Identifiable<String> {
private @Nullable String sourceBundle;
private @Nullable List<AddonDiscoveryMethod> discoveryMethods;

private boolean masterAddonInfo = true;

private AddonInfo(String id, String type, @Nullable String uid, String name, String description,
@Nullable String connection, List<String> countries, @Nullable String configDescriptionURI,
@Nullable String serviceId, @Nullable String sourceBundle,
@Nullable List<AddonDiscoveryMethod> discoveryMethods, boolean isMasterAddonInfo)
throws IllegalArgumentException {
@Nullable List<AddonDiscoveryMethod> discoveryMethods) throws IllegalArgumentException {
// mandatory fields
if (id.isBlank()) {
throw new IllegalArgumentException("The ID must neither be null nor empty!");
Expand Down Expand Up @@ -82,8 +81,6 @@ private AddonInfo(String id, String type, @Nullable String uid, String name, Str
this.serviceId = Objects.requireNonNullElse(serviceId, type + "." + id);
this.sourceBundle = sourceBundle;
this.discoveryMethods = discoveryMethods;

this.masterAddonInfo = isMasterAddonInfo;
}

/**
Expand Down Expand Up @@ -158,10 +155,6 @@ public List<AddonDiscoveryMethod> getDiscoveryMethods() {
return discoveryMethods != null ? discoveryMethods : List.of();
}

public boolean isMasterAddonInfo() {
return masterAddonInfo;
}

public static Builder builder(String id, String type) {
return new Builder(id, type);
}
Expand All @@ -184,8 +177,6 @@ public static class Builder {
private @Nullable String sourceBundle;
private @Nullable List<AddonDiscoveryMethod> discoveryMethods;

private boolean masterAddonInfo = true;

private Builder(String id, String type) {
this.id = id;
this.type = type;
Expand All @@ -203,7 +194,6 @@ private Builder(AddonInfo addonInfo) {
this.serviceId = addonInfo.serviceId;
this.sourceBundle = addonInfo.sourceBundle;
this.discoveryMethods = addonInfo.discoveryMethods;
this.masterAddonInfo = addonInfo.masterAddonInfo;
}

public Builder withUID(@Nullable String uid) {
Expand Down Expand Up @@ -256,11 +246,6 @@ public Builder withDiscoveryMethods(@Nullable List<AddonDiscoveryMethod> discove
return this;
}

public Builder isMasterAddonInfo(boolean masterAddonInfo) {
this.masterAddonInfo = masterAddonInfo;
return this;
}

/**
* Build an {@link AddonInfo} from this builder
*
Expand All @@ -269,7 +254,7 @@ public Builder isMasterAddonInfo(boolean masterAddonInfo) {
*/
public AddonInfo build() throws IllegalArgumentException {
return new AddonInfo(id, type, uid, name, description, connection, countries, configDescriptionURI,
serviceId, sourceBundle, discoveryMethods, masterAddonInfo);
serviceId, sourceBundle, discoveryMethods);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public void removeAddonInfoProvider(AddonInfoProvider addonInfoProvider) {
return a;
}
AddonInfo.Builder builder = AddonInfo.builder(a);
if (a.isMasterAddonInfo()) {
builder.withName(a.getName());
builder.withDescription(a.getDescription());
} else {
if (AddonInfo.NA.equals(a.getName())) {
builder.withName(b.getName());
builder.withDescription(b.getDescription());
} else if (AddonInfo.NA.equals(b.getName())) {
builder.withName(a.getName());
}
if (!a.isMasterAddonInfo() && b.isMasterAddonInfo()) {
builder.isMasterAddonInfo(true);
if (AddonInfo.NA.equals(a.getDescription())) {
builder.withDescription(b.getDescription());
} else if (AddonInfo.NA.equals(b.getDescription())) {
builder.withDescription(a.getDescription());
}
if (a.getConnection() == null && b.getConnection() != null) {
builder.withConnection(b.getConnection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Locale;
import java.util.Set;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -94,8 +93,7 @@ private void initialize() {
try {
String xml = Files.readString(file.toPath());
if (xml != null && !xml.isBlank()) {
addonInfos.addAll(reader.readFromXML(xml).getAddons().stream()
.map(a -> AddonInfo.builder(a).isMasterAddonInfo(false).build()).collect(Collectors.toSet()));
addonInfos.addAll(reader.readFromXML(xml).getAddons());
} else {
logger.warn("File '{}' contents are null or empty", file.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ private Addon getAddon(Feature feature, @Nullable Locale locale) {
AddonInfo addonInfo = addonInfoRegistry.getAddonInfo(uid, locale);

if (addonInfo != null) {
if (addonInfo.isMasterAddonInfo()) {
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription());
} else {
addon = addon.withLabel(feature.getDescription());
}
addon = addon.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
addon = addon.withLabel(addonInfo.getName()).withDescription(addonInfo.getDescription())
.withConnection(addonInfo.getConnection()).withCountries(addonInfo.getCountries())
.withLink(getDefaultDocumentationLink(type, name))
.withConfigDescriptionURI(addonInfo.getConfigDescriptionURI());
} else {
Expand Down

0 comments on commit 2659c4c

Please sign in to comment.