Skip to content

Commit

Permalink
Remove package support from FeatureInstaller (openhab#3634)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K committed May 27, 2023
1 parent 4d3535a commit c6a4dd2
Showing 1 changed file with 1 addition and 31 deletions.
Expand Up @@ -83,8 +83,6 @@ public class FeatureInstaller implements ConfigurationListener {
protected static final String CONFIG_URI = "system:addons";

public static final String PREFIX = "openhab-";
public static final String PREFIX_PACKAGE = "package-";
public static final String MINIMAL_PACKAGE = "minimal";

private static final String CFG_REMOTE = "remote";
private static final String PAX_URL_PID = "org.ops4j.pax.url.mvn";
Expand Down Expand Up @@ -191,13 +189,6 @@ private synchronized void processConfigQueue() {
waitForConfigUpdateEvent();
}

if (installPackage(config)) {
changed = true;
// our package selection has changed, so let's wait for the values to be available in config admin
// which we will receive as another call to modified
continue;
}

if (installAddons(config)) {
changed = true;
}
Expand Down Expand Up @@ -278,7 +269,7 @@ private void waitForConfigUpdateEvent() {
private void changeAddonConfig(String type, String id, BiFunction<Collection<String>, String, Boolean> method)
throws IOException {
Configuration cfg = configurationAdmin.getConfiguration(OpenHAB.ADDONS_SERVICE_PID, null);
Dictionary<String, Object> props = cfg.getProperties();
Dictionary<String, Object> props = Objects.requireNonNullElse(cfg.getProperties(), new Hashtable<>());
Object typeProp = props.get(type);
String[] addonIds = typeProp != null ? typeProp.toString().split(",") : new String[0];
Set<String> normalizedIds = new HashSet<>(); // sets don't allow duplicates
Expand Down Expand Up @@ -512,27 +503,6 @@ private void uninstallFeature(String name) {
}
}

private boolean installPackage(final Map<String, Object> config) {
boolean configChanged = false;
Object packageName = config.get(OpenHAB.CFG_PACKAGE);
if (packageName instanceof String currentPackage) {
String fullName = PREFIX + PREFIX_PACKAGE + currentPackage.strip();
if (!MINIMAL_PACKAGE.equals(currentPackage)) {
configChanged = installFeature(fullName);
}

// uninstall all other packages
try {
Stream.of(featuresService.listFeatures()).map(Feature::getName)
.filter(feature -> feature.startsWith(PREFIX + PREFIX_PACKAGE) && !feature.equals(fullName))
.forEach(this::uninstallFeature);
} catch (Exception e) {
logger.error("Failed retrieving features: {}", e.getMessage(), debugException(e));
}
}
return configChanged;
}

private void postInstalledEvent(String featureName) {
String extensionId = featureName.substring(PREFIX.length());
Event event = AddonEventFactory.createAddonInstalledEvent(extensionId);
Expand Down

0 comments on commit c6a4dd2

Please sign in to comment.