Search in sources :

Example 21 with ProvisioningException

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

the class ProvisioningLayoutFactory method resolveFeaturePack.

public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException {
    final Path fpDir = resolveFeaturePackDir(location);
    final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
    if (!Files.exists(fpXml)) {
        throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
    }
    try (BufferedReader reader = Files.newBufferedReader(fpXml)) {
        final FeaturePackSpec fpSpec = FeaturePackXmlParser.getInstance().parse(reader);
        if (location.isMavenCoordinates()) {
            final FPID specId = fpSpec.getFPID();
            final FeaturePackLocation fpl = new FeaturePackLocation(specId.getUniverse(), specId.getProducer().getName(), specId.getChannel().getName(), location.getFrequency(), specId.getBuild());
            synchronized (this) {
                cachedPacks.put(fpl.getFPID(), cachedPacks.get(location.getFPID()));
            }
            location = fpl;
        }
        return factory.newFeaturePack(location, fpSpec, fpDir, type);
    } catch (IOException | XMLStreamException e) {
        throw new ProvisioningException(Errors.parseXml(fpXml), e);
    }
}
Also used : Path(java.nio.file.Path) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 22 with ProvisioningException

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

the class ProvisioningLayout method uninstall.

private ProvisioningConfig.Builder uninstall(FPID fpid, ProvisioningConfig.Builder configBuilder) throws ProvisioningException {
    if (allPatches.containsKey(fpid)) {
        final F patchFp = allPatches.get(fpid);
        final ProducerSpec patchTarget = patchFp.getSpec().getPatchFor().getProducer();
        FeaturePackConfig targetConfig = config.getFeaturePackDep(patchTarget);
        if (targetConfig == null) {
            targetConfig = config.getTransitiveDep(patchTarget);
            if (targetConfig == null) {
                throw new ProvisioningException("Target feature-pack for patch " + fpid + " could not be found");
            }
        }
        return configBuilder.updateFeaturePackDep(FeaturePackConfig.builder(targetConfig).removePatch(fpid).build());
    }
    final F installedFp = featurePacks.get(fpid.getProducer());
    if (installedFp == null) {
        throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
    }
    if (fpid.getBuild() != null && !installedFp.getFPID().getBuild().equals(fpid.getBuild())) {
        throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
    }
    final FeaturePackConfig fpConfig = config.getFeaturePackDep(fpid.getProducer());
    if (fpConfig == null) {
        throw new ProvisioningException(Errors.unsatisfiedFeaturePackDep(fpid.getProducer()));
    }
    configBuilder.removeFeaturePackDep(fpid.getLocation());
    if (!configBuilder.hasFeaturePackDeps()) {
        configBuilder.clearFeaturePackDeps();
        configBuilder.clearOptions();
    }
    return configBuilder;
}
Also used : ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 23 with ProvisioningException

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

the class ProvisioningLayout method apply.

public void apply(ProvisioningPlan plan, Map<String, String> pluginOptions) throws ProvisioningException {
    if (plan.isEmpty()) {
        return;
    }
    final ProvisioningConfig.Builder configBuilder = ProvisioningConfig.builder(config);
    if (plan.hasUpdates()) {
        Map<ProducerSpec, FeaturePackUpdatePlan> updates = plan.getUpdateMap();
        Set<ProducerSpec> processed = new HashSet<>(updates.size());
        for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (!fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Location in the update plan " + fpPlan.getInstalledLocation() + " does not match the installed location " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.builder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        for (FeaturePackConfig fpConfig : config.getTransitiveDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (fpConfig.getLocation().getBuild() != null && !fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Update plan build " + fpPlan.getInstalledLocation() + " does not match the installed build " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        if (processed.size() < updates.size()) {
            for (Map.Entry<ProducerSpec, FeaturePackUpdatePlan> entry : updates.entrySet()) {
                if (processed.contains(entry.getKey())) {
                    continue;
                }
                final FeaturePackUpdatePlan update = entry.getValue();
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(update.getNewLocation());
                if (update.hasNewPatches()) {
                    for (FPID patchId : update.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.addFeaturePackDep(fpBuilder.build());
            }
        }
    }
    if (plan.hasInstall()) {
        for (FeaturePackConfig fpConfig : plan.getInstall()) {
            install(fpConfig, configBuilder);
        }
    }
    if (plan.hasUninstall()) {
        for (ProducerSpec producer : plan.getUninstall()) {
            uninstall(producer.getLocation().getFPID(), configBuilder);
        }
    }
    final ProvisioningConfig config = configBuilder.build();
    initBuiltInOptions(config, pluginOptions);
    rebuild(config, true);
    initPluginOptions(pluginOptions, plan.hasUninstall());
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 24 with ProvisioningException

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

the class ProvisioningLayout method processOptions.

private void processOptions(Iterable<? extends ProvisioningOption> pluginOptions, Map<String, String> extraOptions, final Map<String, ProvisioningOption> recognizedOptions, final List<ProvisioningOption> overridenOptions) throws ProvisioningException {
    for (ProvisioningOption pluginOption : pluginOptions) {
        final String optionName = pluginOption.getName();
        if (!options.containsKey(optionName)) {
            if (pluginOption.isRequired()) {
                throw new ProvisioningException(Errors.pluginOptionRequired(optionName));
            }
            continue;
        }
        final ProvisioningOption existing = recognizedOptions.put(optionName, pluginOption);
        // doesn't override a persistent one
        if (existing != null && existing.isPersistent() && !pluginOption.isPersistent()) {
            recognizedOptions.put(existing.getName(), existing);
        } else if (pluginOption.isPersistent() || extraOptions.containsKey(optionName) && config.hasOption(optionName)) {
            overridenOptions.add(pluginOption);
        }
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) ProvisioningOption(org.jboss.galleon.ProvisioningOption)

Example 25 with ProvisioningException

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

the class ResolvedFeatureSpec method resolveIdFromForeignKey.

ResolvedFeatureId resolveIdFromForeignKey(ResolvedFeatureId parentId, String parentRef, Map<String, String> params) throws ProvisioningException {
    if (!xmlSpec.hasId()) {
        return null;
    }
    if (parentId == null) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to initialize foreign key parameters of ").append(id).append(": the referenced feature has not ID ");
        throw new ProvisioningException(buf.toString());
    }
    if (parentRef == null) {
        parentRef = parentId.specId.name;
    }
    final List<FeatureParameterSpec> idParamSpecs = xmlSpec.getIdParams();
    final Map<String, Object> resolvedParams = new HashMap<>(idParamSpecs.size());
    final FeatureReferenceSpec refSpec = xmlSpec.getFeatureRef(parentRef);
    try {
        if (refSpec.hasMappedParams()) {
            for (Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) {
                final FeatureParameterSpec param = xmlSpec.getParam(mapping.getKey());
                if (!param.isFeatureId()) {
                    continue;
                }
                final Object idValue = parentId.params.get(mapping.getValue());
                if (idValue == null) {
                    throw new ProvisioningDescriptionException(id + " expects ID parameter '" + mapping.getValue() + "' in " + parentId);
                }
                resolvedParams.put(mapping.getKey(), idValue);
            }
            for (FeatureParameterSpec idParamSpec : idParamSpecs) {
                String configValue = params.get(idParamSpec.getName());
                if (configValue != null) {
                    final Object childValue = paramFromString(idParamSpec.getName(), configValue);
                    final Object idValue = resolvedParams.put(idParamSpec.getName(), childValue);
                    if (idValue != null && !idValue.equals(childValue)) {
                        throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, idValue));
                    }
                    continue;
                }
                if (resolvedParams.containsKey(idParamSpec.getName())) {
                    continue;
                }
                final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
                if (childValue == null) {
                    throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
                }
                resolvedParams.put(idParamSpec.getName(), childValue);
            }
        } else {
            for (FeatureParameterSpec idParamSpec : idParamSpecs) {
                final Object parentValue = parentId.params.get(idParamSpec.getName());
                String configValue = params.get(idParamSpec.getName());
                if (configValue != null) {
                    final Object childValue = paramFromString(idParamSpec.getName(), configValue);
                    if (parentValue != null && !parentValue.equals(childValue)) {
                        throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, parentValue));
                    }
                    resolvedParams.put(idParamSpec.getName(), childValue);
                    continue;
                }
                if (parentValue != null) {
                    resolvedParams.put(idParamSpec.getName(), parentValue);
                    continue;
                }
                final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue;
                if (childValue == null) {
                    throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName()));
                }
                resolvedParams.put(idParamSpec.getName(), childValue);
            }
        }
        return new ResolvedFeatureId(id, resolvedParams);
    } catch (ProvisioningException e) {
        final StringBuilder buf = new StringBuilder();
        buf.append("Failed to initialize foreign key parameters of ").append(id).append(" spec referencing feature ").append(parentId).append(" with parameters ");
        StringUtils.append(buf, params.entrySet());
        throw new ProvisioningException(Errors.failedToInitializeForeignKeyParams(id, parentId, params), e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeatureReferenceSpec(org.jboss.galleon.spec.FeatureReferenceSpec) FeatureParameterSpec(org.jboss.galleon.spec.FeatureParameterSpec) ProvisioningException(org.jboss.galleon.ProvisioningException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6