Skip to content

Commit

Permalink
Merge pull request openhab#1 from kaikreuzer/package
Browse files Browse the repository at this point in the history
added possibility to select an installation package
  • Loading branch information
kaikreuzer committed Jan 1, 2016
2 parents f49795e + 4e88685 commit 441e0ca
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
20 changes: 20 additions & 0 deletions bundles/org.openhab.core.karaf/ESH-INF/config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<config-description:config-descriptions
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:config-description="http://eclipse.org/smarthome/schemas/config-description/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/config-description/v1.0.0
http://eclipse.org/smarthome/schemas/config-description-1.0.0.xsd">

<config-description uri="service:addons">
<parameter name="package" type="text" required="true">
<label>Package</label>
<description>The runtime package to use for this openHAB instance</description>
<options>
<option value="minimal">Minimal</option>
<option value="standard">Standard</option>
<option value="standard">Demo</option>
</options>
</parameter>
</config-description>

</config-description:config-descriptions>
5 changes: 4 additions & 1 deletion bundles/org.openhab.core.karaf/OSGI-INF/featureinstaller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
http://www.eclipse.org/legal/epl-v10.html
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" configuration-policy="require" name="org.openhab.addons">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" configuration-policy="require" modified="modified" name="org.openhab.addons">
<implementation class="org.openhab.core.karaf.internal.FeatureInstaller"/>
<reference bind="setFeaturesService" cardinality="1..1" interface="org.apache.karaf.features.FeaturesService" name="FeaturesService" policy="static" unbind="unsetFeaturesService"/>
<property name="service.pid" type="String" value="org.openhab.addons"/>
<property name="service.config.description.uri" type="String" value="service:addons"/>
<property name="service.config.label" type="String" value="Package"/>
<property name="service.config.category" type="String" value="core"/>
</scr:component>
3 changes: 2 additions & 1 deletion bundles/org.openhab.core.karaf/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
output.. = target/classes/
bin.includes = META-INF/,\
.,\
OSGI-INF/
OSGI-INF/,\
ESH-INF/
source.. = src/main/java/
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This service reads addons.cfg and installs listed addons (= Karaf features).
* This service reads addons.cfg and installs listed addons (= Karaf features) and the selected package.
*
* @author Kai Kreuzer
*/
public class FeatureInstaller {

public static final String PREFIX = "openhab-";

public static final String PREFIX_PACKAGE = "package-";

public static final String[] addonTypes = new String[] { "binding", "ui", "persistence", "action", "tts",
"transformation", "misc" };

Expand All @@ -41,28 +44,64 @@ protected void unsetFeaturesService(FeaturesService featuresService) {
}

protected void activate(final Map<String, Object> config) {
modified(config);
}

protected void modified(final Map<String, Object> config) {
ExecutorService scheduler = Executors.newSingleThreadExecutor();
scheduler.execute(new Runnable() {
@Override
public void run() {
installPackage(config);

// install addons
for (String type : addonTypes) {
Object install = config.get(type);
if (install instanceof String) {
installFeatures(type, (String) install);
}
}
}

});
}

private void installFeatures(String type, String install) {
for (String addon : install.split(",")) {
String name = PREFIX + type + "-" + addon.trim();
try {
featuresService.installFeature(name);
} catch (Exception e) {
logger.error("Failed installing feature '{}'", name);
installFeature(name);
}
}

private void installFeature(String name) {
try {
featuresService.installFeature(name);
logger.info("Installed '{}'", name);
} catch (Exception e) {
logger.error("Failed installing '{}': {}", name, e.getMessage());
}
}

private void installPackage(final Map<String, Object> config) {
Object packageName = config.get("package");
String name = PREFIX + PREFIX_PACKAGE + ((String) packageName).trim();
installFeature(name);

// uninstall all other packages
try {
for (Feature feature : featuresService.listFeatures()) {
if (feature.getName().startsWith(PREFIX + PREFIX_PACKAGE) && !feature.getName().equals(name)
&& featuresService.isInstalled(feature)) {
try {
featuresService.uninstallFeature(feature.getName());
} catch (Exception e) {
logger.error("Failed uninstalling '{}': {}", feature.getName(), e.getMessage());
}
}
}
} catch (Exception e) {
logger.error("Failed retrieving features: {}", e.getMessage());
}
}

}
16 changes: 12 additions & 4 deletions features/karaf/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
-->
<features name="${project.artifactId}-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">

<feature name="openhab-runtime-base" description="openHAB Minimal Runtime" version="${project.version}">
<feature name="openhab-runtime-base" description="openHAB Runtime Base" version="${project.version}">
<feature>shk-esh-base</feature>
<feature>shk-esh-io-console-karaf</feature>
<bundle start-level="90">mvn:org.openhab.core/org.openhab.core/${project.version}</bundle>
<feature dependency="true">shell</feature>
<bundle prerequisite="true">mvn:org.apache.karaf.shell/org.apache.karaf.shell.core/${dep.karaf.version}</bundle>
Expand All @@ -21,13 +22,20 @@
<bundle>mvn:org.openhab.core/org.openhab.core.karaf/${project.version}</bundle>
</feature>

<feature name="openhab-runtime" description="${project.name}" version="${project.version}">
<details>${project.description}</details>
<feature>shk-esh-io-console-karaf</feature>
<feature name="openhab-package-minimal" description="openHAB Minimal Package" version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-dashboard</feature>
<feature>openhab-misc-restdocs</feature>
</feature>

<feature name="openhab-package-standard" description="openHAB Standard Package" version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-dashboard</feature>
<feature>openhab-misc-restdocs</feature>
<feature>openhab-misc-certificate</feature>
<feature>openhab-ui-paper</feature>
<feature>openhab-ui-basic</feature>
<feature>openhab-ui-classic</feature>
</feature>

<feature name="openhab-runtime-compat1x" description="Compatibility layer for openHAB 1 addons" version="${project.version}">
Expand Down

0 comments on commit 441e0ca

Please sign in to comment.