Search in sources :

Example 21 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class ProvisioningXmlParser30 method parseConfigModelRef.

private static void parseConfigModelRef(XMLExtendedStreamReader reader, ConfigCustomizationsBuilder<?> fpBuilder, boolean include) throws XMLStreamException {
    String name = null;
    String model = null;
    Boolean namedConfigsOnly = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart());
        switch(attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case MODEL:
                model = reader.getAttributeValue(i);
                break;
            case NAMED_MODELS_ONLY:
                namedConfigsOnly = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    try {
        if (include) {
            if (name == null) {
                fpBuilder.includeConfigModel(model);
            } else {
                fpBuilder.includeDefaultConfig(new ConfigId(model, name));
            }
        } else if (name == null) {
            if (namedConfigsOnly != null) {
                fpBuilder.excludeConfigModel(model, namedConfigsOnly);
            } else {
                fpBuilder.excludeConfigModel(model);
            }
        } else {
            fpBuilder.excludeDefaultConfig(model, name);
        }
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException(e);
    }
    ParsingUtils.parseNoContent(reader);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ConfigId(org.jboss.galleon.config.ConfigId) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 22 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class ProvisioningXmlParser30 method doReadFeaturePackDep.

private static void doReadFeaturePackDep(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> builder, boolean transitive) throws XMLStreamException {
    FeaturePackLocation location = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart());
        switch(attribute) {
            case LOCATION:
                location = parseFpl(reader, i);
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    if (location == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.LOCATION));
    }
    location = resolveUniverse(builder, location);
    String origin = null;
    final FeaturePackConfig.Builder depBuilder = transitive ? FeaturePackConfig.transitiveBuilder(location) : FeaturePackConfig.builder(location);
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                {
                    try {
                        builder.addFeaturePackDep(origin, depBuilder.build());
                    } catch (ProvisioningDescriptionException e) {
                        final StringBuilder buf = new StringBuilder();
                        buf.append("Failed to add ").append(location).append(" as a ");
                        if (transitive) {
                            buf.append("transitive ");
                        }
                        buf.append(" feature-pack dependency");
                        throw new XMLStreamException(ParsingUtils.error(buf.toString(), reader.getLocation()), e);
                    }
                    return;
                }
            case XMLStreamConstants.START_ELEMENT:
                {
                    final Element element = Element.of(reader.getName().getLocalPart());
                    switch(element) {
                        case PACKAGES:
                            try {
                                FeaturePackPackagesConfigParser10.readPackages(reader, depBuilder);
                            } catch (ProvisioningDescriptionException e) {
                                throw new XMLStreamException("Failed to parse " + Element.PACKAGES.getLocalName() + ": " + e.getLocalizedMessage(), reader.getLocation(), e);
                            }
                            break;
                        case ORIGIN:
                            origin = reader.getElementText();
                            break;
                        case DEFAULT_CONFIGS:
                            ProvisioningXmlParser30.parseDefaultConfigs(reader, depBuilder);
                            break;
                        case CONFIG:
                            final ConfigModel.Builder config = ConfigModel.builder();
                            ConfigXml.readConfig(reader, config);
                            try {
                                depBuilder.addConfig(config.build());
                            } catch (ProvisioningDescriptionException e) {
                                throw new XMLStreamException("Failed to parse config element", reader.getLocation(), e);
                            }
                            break;
                        case PATCHES:
                            readPatches(reader, depBuilder, builder);
                            break;
                        default:
                            throw ParsingUtils.unexpectedContent(reader);
                    }
                    break;
                }
            default:
                {
                    throw ParsingUtils.unexpectedContent(reader);
                }
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FeaturePackDepsConfigBuilder(org.jboss.galleon.config.FeaturePackDepsConfigBuilder) ConfigCustomizationsBuilder(org.jboss.galleon.config.ConfigCustomizationsBuilder) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 23 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class FeatureGroupXml method readFeatureGroupDependency.

private static FeatureGroup readFeatureGroupDependency(String origin, XMLExtendedStreamReader reader) throws XMLStreamException {
    String name = null;
    Boolean inheritFeatures = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch(attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case INHERIT_FEATURES:
                inheritFeatures = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null && inheritFeatures != null) {
        throw new XMLStreamException(Attribute.INHERIT_FEATURES + " attribute can't be used w/o attribute " + Attribute.NAME);
    }
    final FeatureGroup.Builder depBuilder = FeatureGroup.builder(name).setOrigin(origin);
    if (inheritFeatures != null) {
        depBuilder.setInheritFeatures(inheritFeatures);
    }
    readFeatureGroupConfigBody(reader, depBuilder);
    try {
        return depBuilder.build();
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse feature group dependency", reader.getLocation(), e);
    }
}
Also used : FeatureGroup(org.jboss.galleon.config.FeatureGroup) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 24 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class FeaturePackRuntimeBuilder method getFeatureGroupSpec.

FeatureGroup getFeatureGroupSpec(String name) throws ProvisioningException {
    if (fgSpecs != null) {
        final FeatureGroup fgSpec = fgSpecs.get(name);
        if (fgSpec != null) {
            return fgSpec;
        }
    }
    final Path specXml = dir.resolve(Constants.FEATURE_GROUPS).resolve(name + ".xml");
    if (!Files.exists(specXml)) {
        return null;
    }
    try (BufferedReader reader = Files.newBufferedReader(specXml)) {
        final FeatureGroup fgSpec = FeatureGroupXmlParser.getInstance().parse(reader);
        if (!fgSpec.getName().equals(name)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " feature group " + fgSpec.getName() + " does not match the requested feature group name " + name);
        }
        if (fgSpecs == null) {
            fgSpecs = new HashMap<>();
        }
        fgSpecs.put(name, fgSpec);
        return fgSpec;
    } catch (Exception e) {
        throw new ProvisioningException(Errors.parseXml(specXml), e);
    }
}
Also used : Path(java.nio.file.Path) FeatureGroup(org.jboss.galleon.config.FeatureGroup) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 25 with ProvisioningDescriptionException

use of org.jboss.galleon.ProvisioningDescriptionException in project galleon by wildfly.

the class FeaturePackRuntimeBuilder method resolvePackage.

boolean resolvePackage(String pkgName, ProvisioningRuntimeBuilder rt, PackageRuntime.Builder parent, int type) throws ProvisioningException {
    PackageRuntime.Builder pkgBuilder = pkgBuilders.get(pkgName);
    if (pkgBuilder == null) {
        final Path pkgDir = LayoutUtils.getPackageDir(dir, pkgName, false);
        if (!Files.exists(pkgDir)) {
            return false;
        }
        final Path pkgXml = pkgDir.resolve(Constants.PACKAGE_XML);
        if (!Files.exists(pkgXml)) {
            throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(pkgXml));
        }
        try (BufferedReader reader = Files.newBufferedReader(pkgXml)) {
            pkgBuilder = PackageRuntime.builder(this, PackageXmlParser.getInstance().parse(reader), pkgDir, ++rt.pkgsTotal);
        } catch (IOException | XMLStreamException e) {
            throw new ProvisioningException(Errors.parseXml(pkgXml), e);
        }
        if (!pkgBuilder.spec.getName().equals(pkgName)) {
            throw new ProvisioningDescriptionException("Feature-pack " + getFPID() + " package spec name " + pkgBuilder.spec.getName() + " does not match the requested package name " + pkgName);
        }
        pkgBuilders = CollectionUtils.put(pkgBuilders, pkgName, pkgBuilder);
    }
    pkgBuilder.referencedAs(type);
    if (parent == null) {
        pkgBuilder.setFlag(PackageRuntime.ROOT);
        if (type == PackageDependencySpec.REQUIRED) {
            pkgBuilder.include();
        }
    } else if (!parent.isFlagOn(PackageRuntime.SCHEDULED)) {
        parent.addPackageDep(pkgBuilder, type, rt.includedPkgDeps);
    }
    if (!rt.addToPkgDepBranch(pkgBuilder)) {
        // to avoid stack overflow processing circular dependencies
        return true;
    }
    if (pkgBuilder.spec.hasPackageDeps()) {
        final FeaturePackRuntimeBuilder currentOrigin = rt.setOrigin(this);
        try {
            rt.processPackageDeps(pkgBuilder.spec, pkgBuilder);
        } catch (UnsatisfiedPackageDependencyException e) {
            throw new UnsatisfiedPackageDependencyException(getFPID(), pkgName, e);
        } catch (ProvisioningException e) {
            throw new ProvisioningException(Errors.resolvePackage(getFPID(), pkgName), e);
        } finally {
            rt.setOrigin(currentOrigin);
        }
    }
    return true;
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) UnsatisfiedPackageDependencyException(org.jboss.galleon.UnsatisfiedPackageDependencyException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Aggregations

ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)41 XMLStreamException (javax.xml.stream.XMLStreamException)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)9 ProvisioningException (org.jboss.galleon.ProvisioningException)8 BufferedReader (java.io.BufferedReader)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)5 HashMap (java.util.HashMap)4 FeatureGroup (org.jboss.galleon.config.FeatureGroup)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UnsatisfiedPackageDependencyException (org.jboss.galleon.UnsatisfiedPackageDependencyException)3 ConfigId (org.jboss.galleon.config.ConfigId)3 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)3 Reader (java.io.Reader)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 FeatureConfig (org.jboss.galleon.config.FeatureConfig)2