Search in sources :

Example 1 with FeatureDependencySpec

use of org.jboss.galleon.spec.FeatureDependencySpec in project galleon by wildfly.

the class FeatureSpecXmlWriter method toElement.

protected ElementNode toElement(FeatureSpec featureSpec) {
    final ElementNode specE = addElement(null, Element.FEATURE_SPEC);
    addAttribute(specE, Attribute.NAME, featureSpec.getName());
    if (featureSpec.hasAnnotations()) {
        for (FeatureAnnotation fa : featureSpec.getAnnotations()) {
            final ElementNode annotationE = addElement(specE, Element.ANNOTATION);
            addAttribute(annotationE, Attribute.NAME, fa.getName());
            if (fa.hasElements()) {
                for (Map.Entry<String, String> entry : fa.getElements().entrySet()) {
                    final ElementNode elemE = addElement(annotationE, Element.ELEM);
                    addAttribute(elemE, Attribute.NAME, entry.getKey());
                    if (entry.getValue() != null) {
                        addAttribute(elemE, Attribute.VALUE, entry.getValue());
                    }
                }
            }
        }
    }
    if (featureSpec.providesCapabilities()) {
        writeCaps(addElement(specE, Element.PROVIDES), featureSpec.getProvidedCapabilities());
    }
    if (featureSpec.requiresCapabilities()) {
        writeCaps(addElement(specE, Element.REQUIRES), featureSpec.getRequiredCapabilities());
    }
    if (featureSpec.hasFeatureDeps()) {
        final ElementNode depsE = addElement(specE, Element.DEPENDENCIES);
        for (FeatureDependencySpec dep : featureSpec.getFeatureDeps()) {
            final ElementNode depE = addElement(depsE, Element.DEPENDENCY);
            addAttribute(depE, Attribute.FEATURE_ID, dep.getFeatureId().toString());
            if (dep.getOrigin() != null) {
                addAttribute(depE, Attribute.DEPENDENCY, dep.getOrigin());
            }
            if (dep.isInclude()) {
                addAttribute(depE, Attribute.INCLUDE, TRUE);
            }
        }
    }
    if (featureSpec.hasFeatureRefs()) {
        final ElementNode refsE = addElement(specE, Element.REFERENCES);
        for (FeatureReferenceSpec ref : featureSpec.getFeatureRefs()) {
            final ElementNode refE = addElement(refsE, Element.REFERENCE);
            final String feature = ref.getFeature().toString();
            if (ref.getOrigin() != null) {
                addAttribute(refE, Attribute.DEPENDENCY, ref.getOrigin());
            }
            addAttribute(refE, Attribute.FEATURE, feature);
            if (!feature.equals(ref.getName())) {
                addAttribute(refE, Attribute.NAME, ref.getName());
            }
            if (ref.isNillable()) {
                addAttribute(refE, Attribute.NILLABLE, TRUE);
            }
            if (ref.isInclude()) {
                addAttribute(refE, Attribute.INCLUDE, TRUE);
            }
            for (Map.Entry<String, String> mapping : ref.getMappedParams().entrySet()) {
                final ElementNode paramE = addElement(refE, Element.PARAMETER);
                addAttribute(paramE, Attribute.NAME, mapping.getKey());
                addAttribute(paramE, Attribute.MAPS_TO, mapping.getValue());
            }
        }
    }
    if (featureSpec.hasParams()) {
        final ElementNode paramsE = addElement(specE, Element.PARAMETERS);
        for (FeatureParameterSpec paramSpec : featureSpec.getParams().values()) {
            final ElementNode paramE = addElement(paramsE, Element.PARAMETER);
            addAttribute(paramE, Attribute.NAME, paramSpec.getName());
            if (paramSpec.isFeatureId()) {
                addAttribute(paramE, Attribute.FEATURE_ID, TRUE);
            } else if (paramSpec.isNillable()) {
                addAttribute(paramE, Attribute.NILLABLE, TRUE);
            }
            if (paramSpec.hasDefaultValue()) {
                addAttribute(paramE, Attribute.DEFAULT, paramSpec.getDefaultValue());
            }
            if (paramSpec.getType() != null && !Constants.BUILT_IN_TYPE_STRING.equals(paramSpec.getType())) {
                addAttribute(paramE, Attribute.TYPE, paramSpec.getType());
            }
        }
    }
    if (featureSpec.hasPackageDeps()) {
        PackageXmlWriter.writePackageDeps(featureSpec, addElement(specE, Element.PACKAGES));
    }
    return specE;
}
Also used : FeatureReferenceSpec(org.jboss.galleon.spec.FeatureReferenceSpec) FeatureParameterSpec(org.jboss.galleon.spec.FeatureParameterSpec) FeatureDependencySpec(org.jboss.galleon.spec.FeatureDependencySpec) ElementNode(org.jboss.galleon.xml.util.ElementNode) Map(java.util.Map) FeatureAnnotation(org.jboss.galleon.spec.FeatureAnnotation)

Example 2 with FeatureDependencySpec

use of org.jboss.galleon.spec.FeatureDependencySpec in project galleon by wildfly.

the class FeatureGroupXmlWriter method addFeatureConfigBody.

private static void addFeatureConfigBody(ElementNode fcE, FeatureId id, FeatureConfig fc, String ns) {
    if (fc.hasFeatureDeps()) {
        for (FeatureDependencySpec depSpec : fc.getFeatureDeps()) {
            final ElementNode depE = addElement(fcE, Element.DEPENDS.getLocalName(), ns);
            if (depSpec.getOrigin() != null) {
                addAttribute(depE, Attribute.ORIGIN, depSpec.getOrigin());
            }
            addAttribute(depE, Attribute.FEATURE_ID, depSpec.getFeatureId().toString());
            if (depSpec.isInclude()) {
                addAttribute(depE, Attribute.INCLUDE, TRUE);
            }
        }
    }
    if (fc.hasParams()) {
        for (Map.Entry<String, String> param : fc.getParams().entrySet()) {
            final String name = param.getKey();
            if (id != null && id.hasParam(name)) {
                continue;
            }
            final ElementNode paramE = addElement(fcE, Element.PARAM.getLocalName(), ns);
            addAttribute(paramE, Attribute.NAME, name);
            addAttribute(paramE, Attribute.VALUE, param.getValue());
        }
    }
    if (fc.hasResetParams()) {
        for (String param : fc.getResetParams()) {
            final ElementNode paramE = addElement(fcE, Element.RESET_PARAM.getLocalName(), ns);
            addAttribute(paramE, Attribute.PARAM, param);
        }
    }
    if (fc.hasUnsetParams()) {
        for (String param : fc.getUnsetParams()) {
            final ElementNode paramE = addElement(fcE, Element.UNSET_PARAM.getLocalName(), ns);
            addAttribute(paramE, Attribute.PARAM, param);
        }
    }
    writeFeatureGroupSpecBody(fcE, fc, ns);
}
Also used : FeatureDependencySpec(org.jboss.galleon.spec.FeatureDependencySpec) ElementNode(org.jboss.galleon.xml.util.ElementNode) Map(java.util.Map)

Example 3 with FeatureDependencySpec

use of org.jboss.galleon.spec.FeatureDependencySpec in project galleon by wildfly.

the class StateInfoUtil method displayFeatureSpec.

private static void displayFeatureSpec(PmCommandInvocation session, Group grp) throws IOException {
    FeatureSpecInfo f = grp.getSpec();
    session.println("");
    session.println("Feature type       : " + f.getSpecId().getName());
    session.println("Feature origin     : " + f.getSpecId().getProducer());
    session.println("Feature description: " + f.getDescription());
    if (!f.isEnabled()) {
        session.println("WARNING! The feature is not enabled.");
        session.println("Missing packages");
        for (Identity m : f.getMissingPackages()) {
            session.println(m.toString());
        }
    }
    List<FeatureParameterSpec> idparams = f.getSpec().getIdParams();
    String tab = "  ";
    session.println(Config.getLineSeparator() + "Feature Id parameters");
    if (idparams.isEmpty()) {
        session.println("NONE");
    } else {
        for (FeatureParameterSpec param : idparams) {
            StringBuilder builder = new StringBuilder();
            builder.append(tab + param.getName()).append(Config.getLineSeparator());
            builder.append(tab + tab + "description  : " + "no description available").append(Config.getLineSeparator());
            builder.append(tab + tab + "type         : " + param.getType()).append(Config.getLineSeparator());
            builder.append(tab + tab + "default-value: " + param.getDefaultValue()).append(Config.getLineSeparator());
            builder.append(tab + tab + "nillable     : " + param.isNillable()).append(Config.getLineSeparator());
            session.print(builder.toString());
        }
    }
    // Add spec parameters
    session.println(Config.getLineSeparator() + "Feature parameters");
    Map<String, FeatureParameterSpec> params = f.getSpec().getParams();
    if (params.isEmpty()) {
        session.println("NONE");
    } else {
        for (Entry<String, FeatureParameterSpec> entry : params.entrySet()) {
            FeatureParameterSpec param = entry.getValue();
            if (!param.isFeatureId()) {
                StringBuilder builder = new StringBuilder();
                builder.append(tab + param.getName()).append(Config.getLineSeparator());
                builder.append(tab + tab + "description  : " + "no description available").append(Config.getLineSeparator());
                builder.append(tab + tab + "type         : " + param.getType()).append(Config.getLineSeparator());
                builder.append(tab + tab + "default-value: " + param.getDefaultValue()).append(Config.getLineSeparator());
                builder.append(tab + tab + "nillable     : " + param.isNillable()).append(Config.getLineSeparator());
                session.println(builder.toString());
            }
        }
    }
    session.println(Config.getLineSeparator() + "Packages");
    if (f.getPackages().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (PackageInfo p : f.getPackages()) {
            session.println(p.getIdentity().toString());
        }
    }
    session.println(Config.getLineSeparator() + "Provided capabilities");
    if (f.getSpec().getProvidedCapabilities().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (CapabilitySpec c : f.getSpec().getProvidedCapabilities()) {
            session.println(tab + c.toString());
        }
    }
    session.println(Config.getLineSeparator() + "Consumed capabilities");
    if (f.getSpec().getRequiredCapabilities().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (CapabilitySpec c : f.getSpec().getRequiredCapabilities()) {
            session.println(tab + c.toString());
        }
    }
    session.println(Config.getLineSeparator() + "Features dependencies");
    if (f.getSpec().getFeatureDeps().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (FeatureDependencySpec c : f.getSpec().getFeatureDeps()) {
            session.println(tab + c.getFeatureId().toString());
        }
    }
    session.println(Config.getLineSeparator() + "Features references");
    if (f.getSpec().getFeatureRefs().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (FeatureReferenceSpec c : f.getSpec().getFeatureRefs()) {
            session.println(tab + c.getFeature());
        }
    }
    session.println(Config.getLineSeparator() + "Features Annotations");
    if (f.getSpec().getAnnotations().isEmpty()) {
        session.println(tab + "NONE");
    } else {
        for (FeatureAnnotation c : f.getSpec().getAnnotations()) {
            session.println(tab + c.toString());
        }
    }
}
Also used : CapabilitySpec(org.jboss.galleon.spec.CapabilitySpec) PackageInfo(org.jboss.galleon.cli.model.PackageInfo) FeatureDependencySpec(org.jboss.galleon.spec.FeatureDependencySpec) FeatureReferenceSpec(org.jboss.galleon.spec.FeatureReferenceSpec) FeatureParameterSpec(org.jboss.galleon.spec.FeatureParameterSpec) FeatureSpecInfo(org.jboss.galleon.cli.model.FeatureSpecInfo) Identity(org.jboss.galleon.cli.model.Identity) FeatureAnnotation(org.jboss.galleon.spec.FeatureAnnotation)

Example 4 with FeatureDependencySpec

use of org.jboss.galleon.spec.FeatureDependencySpec in project galleon by wildfly.

the class ProvisioningRuntimeBuilder method resolveFeatureDeps.

private Map<ResolvedFeatureId, FeatureDependencySpec> resolveFeatureDeps(ConfigModelStack configStack, Collection<FeatureDependencySpec> featureDeps, final ResolvedFeatureSpec spec) throws ProvisioningException {
    Map<ResolvedFeatureId, FeatureDependencySpec> resolvedDeps = spec.resolveFeatureDeps(this, featureDeps);
    if (!resolvedDeps.isEmpty()) {
        for (Map.Entry<ResolvedFeatureId, FeatureDependencySpec> dep : resolvedDeps.entrySet()) {
            if (!dep.getValue().isInclude()) {
                continue;
            }
            final ResolvedFeatureId depId = dep.getKey();
            if (configStack.includes(depId) || configStack.isFilteredOut(depId.specId, depId)) {
                continue;
            }
            final FeatureDependencySpec depSpec = dep.getValue();
            final FeaturePackRuntimeBuilder originalFp = setOrigin(depSpec.getOrigin());
            try {
                resolveFeatureDepsAndRefs(configStack, getFeatureSpec(depId.getSpecId().getName()), depId, Collections.emptyMap(), Collections.emptyList());
            } finally {
                setOrigin(originalFp);
            }
        }
    }
    return resolvedDeps;
}
Also used : FeatureDependencySpec(org.jboss.galleon.spec.FeatureDependencySpec) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with FeatureDependencySpec

use of org.jboss.galleon.spec.FeatureDependencySpec in project galleon by wildfly.

the class ResolvedFeatureSpec method resolveFeatureDeps.

Map<ResolvedFeatureId, FeatureDependencySpec> resolveFeatureDeps(ProvisioningRuntimeBuilder rt, final Collection<FeatureDependencySpec> depSpecs) throws ProvisioningException {
    if (depSpecs.isEmpty()) {
        return resolveSpecDeps(rt);
    }
    final Map<ResolvedFeatureId, FeatureDependencySpec> resolvedSpecDeps = resolveSpecDeps(rt);
    final Map<ResolvedFeatureId, FeatureDependencySpec> result;
    if (resolvedSpecDeps.isEmpty()) {
        if (depSpecs.size() == 1) {
            final FeatureDependencySpec depSpec = depSpecs.iterator().next();
            final FeaturePackRuntimeBuilder depFp = depSpec.getOrigin() == null ? rt.layout.getFeaturePack(id.producer) : rt.getOrigin(depSpec.getOrigin());
            final ResolvedFeatureSpec depResolvedSpec = rt.getFeatureSpec(depFp, depSpec.getFeatureId().getSpec().getName());
            return Collections.singletonMap(depResolvedSpec.resolveFeatureId(depSpec.getFeatureId().getParams()), depSpec);
        }
        result = new LinkedHashMap<>(depSpecs.size());
    } else {
        result = new LinkedHashMap<>(resolvedSpecDeps.size() + depSpecs.size());
        result.putAll(resolvedSpecDeps);
    }
    final FeaturePackRuntimeBuilder ownFp = rt.layout.getFeaturePack(id.producer);
    for (FeatureDependencySpec userDep : depSpecs) {
        final FeaturePackRuntimeBuilder depFp = userDep.getOrigin() == null ? ownFp : rt.getOrigin(userDep.getOrigin());
        final ResolvedFeatureSpec depResolvedSpec = rt.getFeatureSpec(depFp, userDep.getFeatureId().getSpec().getName());
        final ResolvedFeatureId depId = depResolvedSpec.resolveFeatureId(userDep.getFeatureId().getParams());
        final FeatureDependencySpec specDep = result.put(depId, userDep);
        if (specDep != null) {
            if (!userDep.isInclude() && specDep.isInclude()) {
                result.put(depId, specDep);
            }
        }
    }
    return result;
}
Also used : FeatureDependencySpec(org.jboss.galleon.spec.FeatureDependencySpec)

Aggregations

FeatureDependencySpec (org.jboss.galleon.spec.FeatureDependencySpec)5 Map (java.util.Map)3 FeatureAnnotation (org.jboss.galleon.spec.FeatureAnnotation)2 FeatureParameterSpec (org.jboss.galleon.spec.FeatureParameterSpec)2 FeatureReferenceSpec (org.jboss.galleon.spec.FeatureReferenceSpec)2 ElementNode (org.jboss.galleon.xml.util.ElementNode)2 LinkedHashMap (java.util.LinkedHashMap)1 FeatureSpecInfo (org.jboss.galleon.cli.model.FeatureSpecInfo)1 Identity (org.jboss.galleon.cli.model.Identity)1 PackageInfo (org.jboss.galleon.cli.model.PackageInfo)1 CapabilitySpec (org.jboss.galleon.spec.CapabilitySpec)1