Package org.apache.karaf.features

Examples of org.apache.karaf.features.Feature


     * @throws Exception
     */
    private Feature getFeatureForDependency(Dependency dependency) throws Exception {
        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 : installed.keySet()) {
            if (f.getName().equals(dependency.getName())) {
                Version v = VersionTable.getVersion(f.getVersion());
                if (range.contains(v)) {
                    if (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0) {
                        fi = f;
                    }
                }
            }
        }
        if (fi == null) {
            Map<String, Feature> avail = getFeatures().get(dependency.getName());
            if (avail != null) {
                for (Feature f : avail.values()) {
                    Version v = VersionTable.getVersion(f.getVersion());
                    if (range.contains(v)) {
                        if (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0) {
                            fi = f;
                        }
                    }
                }
            }
View Full Code Here


     * @return
     */
    private boolean dependenciesSatisfied(List<? extends Dependency> dependencies, InstallationState state) throws Exception {
       boolean satisfied = true;
       for (Dependency dep : dependencies) {
           Feature f = getFeatureForDependency(dep);
           if (f != null && !isInstalled(f) && (state != null && !state.features.keySet().contains(f))) {
               satisfied = false;
           }
       }
       return satisfied;
View Full Code Here

    private String getConditionId() {
        StringBuilder sb = new StringBuilder();
        Iterator<Feature> di = getCondition().iterator();
        while (di.hasNext()) {
            Feature dependency = di.next();
            sb.append(dependency.getName()).append("_").append(dependency.getVersion());
            if (di.hasNext()) {
                sb.append("_");
            }
        }
        return sb.toString();
View Full Code Here

            System.out.println("Feature has no conditionals.");
        } else {
            System.out.println("Feature contains followed conditionals:");
            for (Conditional featureConditional : conditionals) {
                String conditionDescription = getConditionDescription(featureConditional);
                Feature wrappedConditional = featureConditional.asFeature(feature.getName(), feature.getVersion());
                if (config) {
                    displayConfigInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
                    displayConfigFileInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
                }
View Full Code Here

    private String getConditionDescription(Conditional cond) {
        StringBuffer sb = new StringBuffer();
        Iterator<? extends Feature> di = cond.getCondition().iterator();
        while (di.hasNext()) {
            Feature dep = di.next();
            sb.append(dep.getName()).append("/").append(dep.getVersion());
            if (di.hasNext()) {
                sb.append(" ");
            }
        }
        return sb.toString();
View Full Code Here

    @Option(name = "-t", aliases={"--tree"}, description="Display feature tree", required = false, multiValued = false)
    private boolean tree;

    protected void doExecute(FeaturesService admin) throws Exception {
        Feature feature = null;

        if (version != null && version.length() > 0) {
            feature = admin.getFeature(name, version);
        } else {
            feature = admin.getFeature(name);
        }

        if (feature == null) {
            System.out.println("Feature not found");
            return;
        }

        // default behavior
        if (!config && !dependency && !bundle && !conditional) {
            config = true;
            dependency = true;
            bundle = true;
            conditional = true;
        }

        System.out.println("Description of " + feature.getName() + " " + feature.getVersion() + " feature");
        if(feature.getDescription() != null && feature.getDescription().length() > 0) {
            System.out.println(" " + feature.getDescription());
        }
        System.out.println("----------------------------------------------------------------");
        if(feature.getDetails() != null && feature.getDetails().length() >0) {
           System.out.print(feature.getDetails());
           System.out.println("----------------------------------------------------------------");
        }
        if (config) {
            displayConfigInformation(feature, FEATURE_CONTENT);
            displayConfigFileInformation(feature, FEATURE_CONTENT);
        }

        if (dependency) {
            displayDependencyInformation(feature, FEATURE_CONTENT);
        }

        if (bundle) {
            displayBundleInformation(feature, FEATURE_CONTENT);
        }

        if(conditional) {
           displayConditionalInfo(feature);
        }

        if (tree) {
            if (config || dependency || bundle) {
                System.out.println("\nFeature tree");
            }

            int unresolved = displayFeatureTree(admin, feature.getName(), feature.getVersion(), "");
            if (unresolved > 0) {
                System.out.println("Tree contains " + unresolved + " unresolved dependencies");
                System.out.println(" * means that node declares dependency but the dependant feature is not available.");
            }
        }
View Full Code Here


    private int displayFeatureTree(FeaturesService admin, String featureName, String featureVersion, String prefix) throws Exception {
        int unresolved = 0;

        Feature resolved = admin.getFeature(featureName, featureVersion);
        if (resolved != null) {
            System.out.println(prefix + " " + resolved.getName() + " " + resolved.getVersion());
        } else {
            System.out.println(prefix + " " + featureName + " " + featureVersion + " *");
            unresolved++;
        }

        if (resolved != null) {
            if (bundle) {
                List<String> bundleLocation = new LinkedList<String>();
                List<BundleInfo> bundles = resolved.getBundles();
                for (BundleInfo bundleInfo : bundles) {
                    bundleLocation.add(bundleInfo.getLocation());
                }

                if (conditional) {
                    for (Conditional cond : resolved.getConditional()) {
                        List<? extends Feature> condition = cond.getCondition();
                        List<BundleInfo> conditionalBundles = cond.getBundles();
                        for (BundleInfo bundleInfo : conditionalBundles) {
                            bundleLocation.add(bundleInfo.getLocation() + "(condition:"+condition+")");
                        }
                    }
                }
                for (int i = 0, j = bundleLocation.size(); i < j; i++) {
                    System.out.println(prefix + " " + (i + 1 == j ? "\\" : "+") + " " + bundleLocation.get(i));
                }
            }
            prefix += "   ";
            List<Feature> dependencies = resolved.getDependencies();
            for (int i = 0, j = dependencies.size(); i < j; i++) {
                Feature toDisplay =  dependencies.get(i);
                unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix +1);
            }

            if (conditional) {
                for (Conditional cond : resolved.getConditional()) {
                    List<Feature> conditionDependencies = cond.getDependencies();
                    for (int i = 0, j = conditionDependencies.size(); i < j; i++) {
                        Feature toDisplay =  dependencies.get(i);
                        unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix +1);
                    }
                }
            }
        }

View Full Code Here

     * @param version the version of the feature.
     * @param options the installation options.
     * @throws Exception in case of install failure.
     */
    public void installFeature(String name, String version, EnumSet<Option> options) throws Exception {
        Feature f = getFeature(name, version);
        if (f == null) {
            throw new Exception("No feature named '" + name
                + "' with version '" + version + "' available");
        }
        installFeature(f, options);
View Full Code Here

        }
    }

    private void installFeatureDependency(Dependency dependency, InstallationState state, boolean verbose)
            throws Exception {
        Feature fi = getFeatureForDependency(dependency);
        if (fi == null) {
            throw new Exception("No feature named '" + dependency.getName()
                    + "' with version '" + dependency.getVersion() + "' available");
        }
        if (state.features.containsKey(fi)) {
            LOGGER.debug("Feature {} with version {} is already being installed", fi.getName(), fi.getVersion());
        } else {
            doInstallFeature(state, fi, verbose);
        }
    }
View Full Code Here

        }
        uninstallFeature(name, versions.get(0));
    }
   
    public void uninstallFeature(String name, String version) throws Exception {
      Feature feature = getFeature(name, version);
        if (feature == null || !installed.containsKey(feature)) {
            throw new Exception("Feature named '" + name
                + "' with version '" + version + "' is not installed");
        }
        // Grab all the bundles installed by this feature
        // and remove all those who will still be in use.
        // This gives this list of bundles to uninstall.
        Set<Long> bundles = installed.remove(feature);

        //Also remove bundles installed as conditionals
        for (Conditional conditional : feature.getConditional()) {
            Feature conditionalFeature = conditional.asFeature(feature.getName(),feature.getVersion());
            if (installed.containsKey(conditionalFeature)) {
              bundles.addAll(installed.remove(conditionalFeature));
            } else {
              LOGGER.info("Conditional feature {}, hasn't been installed!");
            }
View Full Code Here

TOP

Related Classes of org.apache.karaf.features.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.