private Set<String> getAllAddonsOfType(FeaturesService featuresService, String type) { Set<String> addons = new HashSet<>(); String prefix = FeatureInstaller.PREFIX + type + "-"; try { for (Feature feature : featuresService.listFeatures()) { if (feature.getName().startsWith(prefix)) { addons.add(feature.getName().substring(prefix.length())); } } } catch (Exception e) { logger.error("Failed retrieving features: {}", e.getMessage()); } return addons; }
private Set<String> getFeatureLocations() throws Exception { Set<String> bundleLocations = new LinkedHashSet<String>(); for (Feature feature : featuresService.listFeatures()) { try { for (BundleInfo info : feature.getBundles()) { bundleLocations.add(info.getLocation()); } } catch (Exception e) { //Ignore } } return bundleLocations; }
private Set<String> getFeatureLocations() throws Exception { Set<String> bundleLocations = new LinkedHashSet<String>(); for (Feature feature : featuresService.listFeatures()) { try { for (BundleInfo info : feature.getBundles()) { bundleLocations.add(info.getLocation()); } } catch (Exception e) { //Ignore } } return bundleLocations; }
@Override public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) { try { for (Feature feature : featuresService.listFeatures()) { if (acceptsFeature(feature)) { add(candidates, feature); } } } catch (Exception e) { // Ignore } }
@Override public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) { try { for (Feature feature : featuresService.listFeatures()) { if (acceptsFeature(feature)) { add(candidates, feature); } } } catch (Exception e) { // Ignore } }
/** * {@inheritDoc} */ public TabularData getFeatures() throws Exception { try { List<Feature> allFeatures = Arrays.asList(featuresService.listFeatures()); List<Feature> insFeatures = Arrays.asList(featuresService.listInstalledFeatures()); ArrayList<JmxFeature> features = new ArrayList<>(); for (Feature feature : allFeatures) { try { features.add(new JmxFeature(feature, insFeatures.contains(feature), featuresService.isRequired(feature))); } catch (Throwable t) { t.printStackTrace(); } } return JmxFeature.tableFrom(features); } catch (Throwable t) { t.printStackTrace(); return null; } }
/** * Get the list of features where the bundle is belonging. * * @param bundleLocation the bundle location. * @return the list of feature where the bundle is present. * @throws Exception in case of retrieval failure. */ protected List<Feature> retrieveFeature(String bundleLocation) throws Exception { Feature[] features = featuresService.listFeatures(); List<Feature> matchingFeatures = new ArrayList<Feature>(); for (Feature feature : features) { List<BundleInfo> bundles = feature.getBundles(); for (BundleInfo bundleInfo : bundles) { String location = bundleInfo.getLocation(); if (location.equalsIgnoreCase(bundleLocation)) { matchingFeatures.add(feature); LOGGER.debug("CELLAR BUNDLE: found a feature {} containing bundle {}", feature.getName(), bundleLocation); } } } return matchingFeatures; }
/** * Get the list of features where the bundle is belonging. * * @param bundleLocation the bundle location. * @return the list of feature where the bundle is present. * @throws Exception in case of retrieval failure. */ protected List<Feature> retrieveFeature(String bundleLocation) throws Exception { Feature[] features = featuresService.listFeatures(); List<Feature> matchingFeatures = new ArrayList<Feature>(); for (Feature feature : features) { List<BundleInfo> bundles = feature.getBundles(); for (BundleInfo bundleInfo : bundles) { String location = bundleInfo.getLocation(); if (location.equalsIgnoreCase(bundleLocation)) { matchingFeatures.add(feature); LOGGER.debug("CELLAR BUNDLE: found a feature {} containing bundle {}", feature.getName(), bundleLocation); } } } return matchingFeatures; }
@Override public List<Extension> getExtensions(Locale locale) { List<Extension> extensions = new LinkedList<>(); try { for (Feature feature : featuresService.listFeatures()) { if (feature.getName().startsWith(FeatureInstaller.PREFIX) && Arrays.asList(FeatureInstaller.addonTypes).contains(getType(feature.getName()))) { Extension extension = getExtension(feature); // for simple packaging, we filter out all openHAB 1 add-ons as they cannot be used through the UI if (!"simple".equals(featureInstaller.getCurrentPackage()) || !extension.getVersion().startsWith("1.")) { extensions.add(extension); } } } } catch (Exception e) { logger.error("Exception while retrieving features: {}", e.getMessage()); return Collections.emptyList(); } // let's sort the result alphabetically Collections.sort(extensions, new Comparator<Extension>() { @Override public int compare(Extension ext1, Extension ext2) { return ext1.getLabel().compareTo(ext2.getLabel()); } }); return extensions; }
private synchronized boolean installPackage(FeaturesService featuresService, final Map<String, Object> config) { boolean configChanged = false; Object packageName = config.get(OpenHAB.CFG_PACKAGE); if (packageName instanceof String) { currentPackage = (String) packageName; String fullName = PREFIX + PREFIX_PACKAGE + ((String) packageName).trim(); if (currentPackage.equals(MINIMAL_PACKAGE)) { // no changes are done to the add-ons list, so the installer should proceed configChanged = false; } else { if (installFeature(featuresService, fullName)) { configChanged = true; } } // uninstall all other packages try { for (Feature feature : featuresService.listFeatures()) { if (feature.getName().startsWith(PREFIX + PREFIX_PACKAGE) && !feature.getName().equals(fullName)) { uninstallFeature(featuresService, feature.getName()); } } } catch (Exception e) { logger.error("Failed retrieving features: {}", e.getMessage()); } } return configChanged; }
/** * {@inheritDoc} */ protected void writeDump(OutputStreamWriter outputStreamWriter) throws Exception { // creates header outputStreamWriter.write("Repositories:\n"); // list repositories for (Repository repo : features.listRepositories()) { outputStreamWriter.write(repo.getURI() + " (" + repo.getName() + ")\n"); } // list features outputStreamWriter.write("\nfeatures:\n"); for (Feature feature : features.listFeatures()) { outputStreamWriter.write(feature.getName() + " " + feature.getVersion()); outputStreamWriter.write(" installed: " + features.isInstalled(feature)); outputStreamWriter.write("\nBundles:\n"); for (BundleInfo bundle : feature.getBundles()) { outputStreamWriter.write("\t" + bundle.getLocation()); if (bundle.getStartLevel() != 0) { outputStreamWriter.write(" start level " + bundle.getStartLevel()); } outputStreamWriter.write("\n\n"); } } // flush & close stream outputStreamWriter.close(); }
for (Feature feature : features.listFeatures()) { outputStreamWriter.write(feature.getName() + " " + feature.getVersion()); outputStreamWriter.write(" installed: " + features.isInstalled(feature));
@Override public boolean matches(DependencyTree dependencyTree) { boolean result = false; if (!getDependencyTreeFilter().matches(dependencyTree)) { try { Feature feature = Features.getFeatureForBundle(service.listFeatures(), dependencyTree); if (feature != null) { String replacement = String.format("%s/%s", feature.getName(), feature.getVersion()); features.add(replacement); LOG.info(String.format("Installing feature %s for maven dependency %s/%s/%s", replacement, dependencyTree.getGroupId(), dependencyTree.getArtifactId(), dependencyTree.getVersion())); result = true; } } catch (Exception e) { LOG.debug(String.format("Unable to retrieve features information while processing dependency %s", dependencyTree.getArtifactId()), e); } } return result; } }
@Override public boolean matches(DependencyTree dependencyTree) { boolean result = false; if (!getDependencyTreeFilter().matches(dependencyTree)) { try { Feature feature = Features.getFeatureForBundle(service.listFeatures(), dependencyTree); if (feature != null) { String replacement = String.format("%s/%s", feature.getName(), feature.getVersion()); features.add(replacement); LOG.info(String.format("Installing feature %s for maven dependency %s/%s/%s", replacement, dependencyTree.getGroupId(), dependencyTree.getArtifactId(), dependencyTree.getVersion())); result = true; } } catch (Exception e) { LOG.debug(String.format("Unable to retrieve features information while processing dependency %s", dependencyTree.getArtifactId()), e); } } return result; } }
protected Feature extractFeatureFromDependency(Dependency dependency) throws Exception { Feature[] features = featuresService.listFeatures(); VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency.getVersion()) ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true); Feature fi = null; for(Feature f: features) { if (f.getName().equals(dependency.getName())) { Version v = VersionTable.getVersion(f.getVersion()); if (range.contains(v) && (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0)) { fi = f; break; } } } return fi; }
for (Feature feature : featuresService.listFeatures()) { String key = feature.getName() + "/" + feature.getVersion(); if (features.containsKey(key)) {
for (Feature feature : featuresService.listFeatures()) { String key = feature.getName() + "/" + feature.getVersion(); if (features.containsKey(key)) {
for (Feature feature : featuresService.listFeatures()) { String key = feature.getName() + "/" + feature.getVersion(); if (features.containsKey(key)) {
for (Feature feature : featuresService.listFeatures()) { String key = feature.getName() + "/" + feature.getVersion(); if (features.containsKey(key)) {
featuresList = featuresService.listFeatures(); } catch (Exception e) { LOGGER.error("CELLAR FEATURE: error listing features", e);