Search in sources :

Example 6 with Dependency

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

the class FeatureResource method build.

/**
 * Constructs {@link Resource} for given non-conditional feature.
 */
public static FeatureResource build(Feature feature, String featureRange, Map<String, ? extends Resource> locToRes) throws BundleException {
    FeatureResource resource = new FeatureResource(feature);
    for (BundleInfo info : feature.getBundles()) {
        if (!info.isDependency() && !info.isBlacklisted()) {
            Resource res = locToRes.get(info.getLocation());
            if (res == null) {
                throw new IllegalStateException("Resource not found for url " + info.getLocation());
            }
            addIdentityRequirement(resource, res);
        }
    }
    for (Dependency dep : feature.getDependencies()) {
        if (!dep.isDependency()) {
            addDependency(resource, dep, featureRange);
        }
    }
    for (org.apache.karaf.features.Capability cap : feature.getCapabilities()) {
        resource.addCapabilities(ResourceBuilder.parseCapability(resource, cap.getValue()));
    }
    for (org.apache.karaf.features.Requirement req : feature.getRequirements()) {
        resource.addRequirements(ResourceBuilder.parseRequirement(resource, req.getValue()));
    }
    return resource;
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) Resource(org.osgi.resource.Resource) Dependency(org.apache.karaf.features.Dependency)

Example 7 with Dependency

use of org.apache.karaf.features.Dependency 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);
            }
            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);
                    }
                }
            }
        }
    }
    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 8 with Dependency

use of org.apache.karaf.features.Dependency in project controller by opendaylight.

the class ChildAwareFeatureWrapper method getChildFeatures.

/*
     * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
     * from the underlying Feature Config files and those of its children recursively
     */
public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
    List<Dependency> dependencies = feature.getDependencies();
    Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
    if (dependencies != null) {
        for (Dependency dependency : dependencies) {
            Feature fi = extractFeatureFromDependency(dependency);
            if (fi != null) {
                if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
                    LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
                } else {
                    ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
                    childFeatures.add(wrappedFeature);
                }
            }
        }
    }
    return childFeatures;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature)

Example 9 with Dependency

use of org.apache.karaf.features.Dependency in project ddf by codice.

the class ApplicationServiceBeanTest method testGetInstallationProfiles.

/**
 * Tests the {@link ApplicationServiceBean#getInstallationProfiles()} method
 *
 * @throws Exception
 */
@Test
public void testGetInstallationProfiles() throws Exception {
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Dependency testDependency1 = mock(Dependency.class);
    Dependency testDependency2 = mock(Dependency.class);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testDependency1.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testDependency2.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testFeature1.getDescription()).thenReturn(TEST_FEATURE_DESCRIPTION);
    when(testFeature2.getDescription()).thenReturn(TEST_FEATURE_DESCRIPTION);
    List<Dependency> dependencies1 = new ArrayList<>();
    dependencies1.add(testDependency1);
    List<Dependency> dependencies2 = new ArrayList<>();
    dependencies2.add(testDependency2);
    when(testFeature1.getDependencies()).thenReturn(dependencies1);
    when(testFeature2.getDependencies()).thenReturn(dependencies2);
    List<Feature> featureList = new ArrayList<>();
    featureList.add(testFeature1);
    featureList.add(testFeature2);
    when(testAppService.getInstallationProfiles()).thenReturn(featureList);
    ApplicationServiceBean serviceBean = newApplicationServiceBean();
    List<Map<String, Object>> result = serviceBean.getInstallationProfiles();
    assertThat("Should contain the nodes set up previously.", (String) result.get(0).get("name"), is(TEST_FEATURE_NAME));
    assertThat("Should have two entries.", result.size(), is(2));
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with Dependency

use of org.apache.karaf.features.Dependency in project ddf by codice.

the class ProfileListCommandTest method createMockDependency.

private Dependency createMockDependency(String name) {
    Dependency dependency = mock(Dependency.class);
    when(dependency.getName()).thenReturn(name);
    when(dependency.getVersion()).thenReturn("0.0.0");
    return dependency;
}
Also used : Dependency(org.apache.karaf.features.Dependency)

Aggregations

Dependency (org.apache.karaf.features.Dependency)19 Feature (org.apache.karaf.features.Feature)14 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 BundleInfo (org.apache.karaf.features.BundleInfo)4 Conditional (org.apache.karaf.features.Conditional)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Test (org.junit.Test)3 SecurityServiceException (ddf.security.service.SecurityServiceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 Repository (org.apache.karaf.features.Repository)2 ResourceUtils.addIdentityRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement)2 ResourceUtils.toFeatureRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement)2 Application (org.codice.ddf.admin.application.service.Application)2 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 Requirement (org.osgi.resource.Requirement)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1