Merge pull request #1 from kaikreuzer/package

added possibility to select an installation package
This commit is contained in:
Kai Kreuzer 2016-01-01 23:00:15 +01:00
commit 441e0ca57b
5 changed files with 83 additions and 12 deletions

View File

@ -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>

View File

@ -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>

View File

@ -1,5 +1,6 @@
output.. = target/classes/
bin.includes = META-INF/,\
.,\
OSGI-INF/
OSGI-INF/,\
ESH-INF/
source.. = src/main/java/

View File

@ -12,12 +12,13 @@ import java.util.Map;
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
*/
@ -25,6 +26,8 @@ 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" };
@ -41,10 +44,17 @@ public class FeatureInstaller {
}
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) {
@ -52,17 +62,46 @@ public class FeatureInstaller {
}
}
}
});
}
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());
}
}
}

View File

@ -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>
@ -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}">