Search in sources :

Example 1 with Conditional

use of org.apache.karaf.features.Conditional in project karaf by apache.

the class InfoFeatureCommand method displayFeatureTree.

/**
     * Called originally with featureName and featureVersion that have already been resolved successfully.
     *
     * @param admin
     * @param featureName
     * @param featureVersion
     * @param prefix
     * @return
     * @throws Exception
     */
private int displayFeatureTree(FeaturesService admin, String featureName, String featureVersion, String prefix) throws Exception {
    int unresolved = 0;
    Feature[] resolvedFeatures = admin.getFeatures(featureName, featureVersion);
    for (Feature resolved : resolvedFeatures) {
        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<>();
                List<BundleInfo> bundles = resolved.getBundles();
                for (BundleInfo bundleInfo : bundles) {
                    bundleLocation.add(bundleInfo.getLocation());
                }
                if (conditional) {
                    for (Conditional cond : resolved.getConditional()) {
                        List<String> 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<Dependency> dependencies = resolved.getDependencies();
            for (Dependency toDisplay : dependencies) {
                unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix + 1);
            }
            if (conditional) {
                for (Conditional cond : resolved.getConditional()) {
                    List<Dependency> conditionDependencies = cond.getDependencies();
                    for (int i = 0, j = conditionDependencies.size(); i < j; i++) {
                        Dependency toDisplay = dependencies.get(i);
                        unresolved += displayFeatureTree(admin, toDisplay.getName(), toDisplay.getVersion(), prefix + 1);
                    }
                }
            }
        }
    }
    return unresolved;
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) Conditional(org.apache.karaf.features.Conditional) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) LinkedList(java.util.LinkedList)

Example 2 with Conditional

use of org.apache.karaf.features.Conditional in project karaf by apache.

the class InfoFeatureCommand method displayConditionalInfo.

private void displayConditionalInfo(Feature feature) {
    List<? extends Conditional> conditionals = feature.getConditional();
    if (conditionals.isEmpty()) {
        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();
            if (config) {
                displayConfigInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
                displayConfigFileInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
            }
            if (dependency) {
                displayDependencyInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
            }
            if (bundle) {
                displayBundleInformation(wrappedConditional, String.format(CONDITIONAL_CONTENT, conditionDescription));
            }
        }
    }
}
Also used : Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.Feature)

Example 3 with Conditional

use of org.apache.karaf.features.Conditional in project karaf by apache.

the class AbstractFeatureMojo method resolveFeatures.

protected Set<Feature> resolveFeatures() throws MojoExecutionException {
    Set<Feature> featuresSet = new HashSet<>();
    try {
        Set<String> artifactsToCopy = new HashSet<>();
        Map<String, Feature> featuresMap = new HashMap<>();
        for (String uri : descriptors) {
            retrieveDescriptorsRecursively(uri, artifactsToCopy, featuresMap);
        }
        // no features specified, handle all of them
        if (features == null) {
            features = new ArrayList<>(featuresMap.keySet());
        }
        addFeatures(features, featuresSet, featuresMap, addTransitiveFeatures);
        getLog().info("Using local repository at: " + localRepo.getUrl());
        for (Feature feature : featuresSet) {
            try {
                for (Bundle bundle : feature.getBundle()) {
                    resolveArtifact(bundle.getLocation());
                }
                for (Conditional conditional : feature.getConditional()) {
                    for (BundleInfo bundle : conditional.getBundles()) {
                        if (ignoreDependencyFlag || (!ignoreDependencyFlag && !bundle.isDependency())) {
                            resolveArtifact(bundle.getLocation());
                        }
                    }
                }
                for (ConfigFile configfile : feature.getConfigfile()) {
                    resolveArtifact(configfile.getLocation());
                }
            } catch (RuntimeException e) {
                throw new RuntimeException("Error resolving feature " + feature.getName() + "/" + feature.getVersion(), e);
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error populating repository", e);
    }
    return featuresSet;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) Bundle(org.apache.karaf.features.internal.model.Bundle) Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.internal.model.Feature) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleInfo(org.apache.karaf.features.BundleInfo) HashSet(java.util.HashSet)

Example 4 with Conditional

use of org.apache.karaf.features.Conditional in project karaf by apache.

the class AddToRepositoryMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Set<Feature> featuresSet = resolveFeatures();
    for (Artifact descriptor : descriptorArtifacts) {
        copy(descriptor, repository);
    }
    for (Feature feature : featuresSet) {
        copyBundlesToDestRepository(feature.getBundle());
        for (Conditional conditional : feature.getConditional()) {
            copyBundlesConditionalToDestRepository(conditional.getBundles());
        }
        copyConfigFilesToDestRepository(feature.getConfigfile());
    }
    copyFileBasedDescriptorsToDestRepository();
}
Also used : Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.internal.model.Feature) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with Conditional

use of org.apache.karaf.features.Conditional in project karaf by apache.

the class Subsystem method doBuild.

private void doBuild(Collection<Feature> features, boolean mandatory) throws Exception {
    for (Subsystem child : children) {
        child.doBuild(features, true);
    }
    if (feature != null) {
        for (Dependency dep : feature.getDependencies()) {
            Subsystem ss = this;
            while (!ss.isAcceptDependencies()) {
                ss = ss.getParent();
            }
            ss.requireFeature(dep.getName(), dep.getVersion(), false);
        }
        for (Conditional cond : feature.getConditional()) {
            Feature fcond = cond.asFeature();
            String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
            Subsystem fs = getChild(ssName);
            if (fs == null) {
                fs = new Subsystem(ssName, fcond, this, true);
                fs.doBuild(features, false);
                installable.add(fs);
                children.add(fs);
            }
        }
    }
    List<Requirement> processed = new ArrayList<>();
    while (true) {
        List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
        requirements.addAll(dependentFeatures);
        requirements.removeAll(processed);
        if (requirements.isEmpty()) {
            break;
        }
        for (Requirement requirement : requirements) {
            String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
            String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
            VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
            if (TYPE_FEATURE.equals(type)) {
                for (Feature feature : features) {
                    if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
                        if (feature != this.feature) {
                            String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
                            Subsystem fs = getChild(ssName);
                            if (fs == null) {
                                fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
                                fs.build(features);
                                installable.add(fs);
                                children.add(fs);
                            }
                        }
                    }
                }
            }
            processed.add(requirement);
        }
    }
}
Also used : ResourceUtils.addIdentityRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement) ResourceUtils.toFeatureRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) Conditional(org.apache.karaf.features.Conditional) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature)

Aggregations

Conditional (org.apache.karaf.features.Conditional)7 BundleInfo (org.apache.karaf.features.BundleInfo)4 Feature (org.apache.karaf.features.Feature)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 Dependency (org.apache.karaf.features.Dependency)2 Feature (org.apache.karaf.features.internal.model.Feature)2 Requirement (org.osgi.resource.Requirement)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1