Search in sources :

Example 11 with ProducerSpec

use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec 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 12 with ProducerSpec

use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec 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 13 with ProducerSpec

use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.

the class AbstractFPProvisionedCommand method getProvisionedFP.

public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecutionException {
    ProducerSpec producer = getProducer(session);
    if (producer == null) {
        return null;
    }
    ProvisioningConfig config = session.getState().getConfig();
    for (FeaturePackConfig dep : config.getFeaturePackDeps()) {
        if (dep.getLocation().getProducer().equals(producer)) {
            return dep;
        }
    }
    for (FeaturePackConfig dep : config.getTransitiveDeps()) {
        if (dep.getLocation().getProducer().equals(producer)) {
            return dep;
        }
    }
    return null;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 14 with ProducerSpec

use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.

the class CheckUpdatesCommand method getUpdatesTable.

static Updates getUpdatesTable(ProvisioningManager mgr, PmCommandInvocation session, boolean includeAll, String fp) throws ProvisioningException, CommandExecutionException {
    if (includeAll && fp != null) {
        throw new CommandExecutionException(CliErrors.onlyOneOptionOf(FP_OPTION_NAME, ALL_DEPENDENCIES_OPTION_NAME));
    }
    ProvisioningPlan plan;
    if (fp == null) {
        plan = mgr.getUpdates(includeAll);
    } else {
        String[] split = fp.split(",+");
        List<ProducerSpec> resolved = new ArrayList<>();
        List<FeaturePackLocation> locs = new ArrayList<>();
        for (String producer : split) {
            FeaturePackLocation loc = session.getPmSession().getResolvedLocation(mgr.getInstallationHome(), producer);
            if (loc.hasBuild()) {
                locs.add(loc);
            } else {
                resolved.add(loc.getProducer());
            }
        }
        if (!resolved.isEmpty()) {
            ProducerSpec[] arr = new ProducerSpec[resolved.size()];
            plan = mgr.getUpdates(resolved.toArray(arr));
        } else {
            plan = ProvisioningPlan.builder();
        }
        if (!locs.isEmpty()) {
            addCustomUpdates(plan, locs, mgr);
        }
    }
    Updates updates = new Updates();
    updates.plan = plan;
    if (plan.isEmpty()) {
        return updates;
    }
    boolean hasPatches = false;
    for (FeaturePackUpdatePlan p : plan.getUpdates()) {
        if (p.hasNewPatches()) {
            hasPatches = true;
            break;
        }
    }
    List<String> headers = new ArrayList<>();
    headers.add(Headers.PRODUCT);
    headers.add(Headers.CURRENT_BUILD);
    headers.add(Headers.UPDATE);
    if (hasPatches) {
        headers.add(Headers.PATCHES);
    }
    if (includeAll) {
        headers.add(Headers.DEPENDENCY);
    }
    headers.add(Headers.UPDATE_CHANNEL);
    updates.t = new Table(headers);
    for (FeaturePackUpdatePlan p : plan.getUpdates()) {
        FeaturePackLocation loc = p.getInstalledLocation();
        String update = p.hasNewLocation() ? p.getNewLocation().getBuild() : NONE;
        Cell patches = null;
        if (hasPatches) {
            patches = new Cell();
            if (p.hasNewPatches()) {
                for (FPID id : p.getNewPatches()) {
                    patches.addLine(id.getBuild());
                }
            } else {
                patches.addLine(NONE);
            }
        }
        List<Cell> line = new ArrayList<>();
        line.add(new Cell(loc.getProducerName()));
        line.add(new Cell(loc.getBuild()));
        line.add(new Cell(update));
        if (hasPatches) {
            line.add(patches);
        }
        if (includeAll) {
            line.add(new Cell(p.isTransitive() ? "Y" : "N"));
        }
        FeaturePackLocation newLocation = session.getPmSession().getExposedLocation(mgr.getInstallationHome(), p.getNewLocation());
        line.add(new Cell(StateInfoUtil.formatChannel(newLocation)));
        updates.t.addCellsLine(line);
    }
    updates.t.sort(Table.SortType.ASCENDANT);
    return updates;
}
Also used : ProvisioningPlan(org.jboss.galleon.layout.ProvisioningPlan) Table(org.jboss.galleon.cli.cmd.Table) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ArrayList(java.util.ArrayList) FeaturePackUpdatePlan(org.jboss.galleon.layout.FeaturePackUpdatePlan) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) Cell(org.jboss.galleon.cli.cmd.Table.Cell)

Example 15 with ProducerSpec

use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.

the class StateInfoUtil method buildOptionalPackages.

public static String buildOptionalPackages(PmSession session, FeatureContainer container, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    String optionValue = container.getProvisioningConfig().getOption(ProvisioningOption.OPTIONAL_PACKAGES.getName());
    if (optionValue == null) {
        optionValue = Constants.ALL;
    }
    Table.Tree t = null;
    boolean passivePresent = !container.getPassivePackages().isEmpty() || !container.getOrphanPassivePackages().isEmpty();
    Set<String> optionalProducers = container.getOptionalPackagesProducers();
    if (!optionalProducers.isEmpty()) {
        if (passivePresent) {
            t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE, Headers.PASSIVE);
        } else {
            t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE);
        }
        for (String producer : optionalProducers) {
            String displayProducer = producer;
            try {
                ProducerSpec pSpec = FeaturePackLocation.fromString(producer).getProducer();
                if (session.getUniverse().getBuiltinUniverseSpec().equals(pSpec.getUniverse())) {
                    displayProducer = pSpec.getName();
                }
            } catch (Exception ex) {
            // Not a producerSpec, keep original one.
            }
            Table.Node producerNode = new Table.Node(displayProducer);
            t.add(producerNode);
            Map<String, Set<String>> optionalPkgs = container.getOptionalPackages().get(producer);
            if (optionalPkgs != null && !optionalPkgs.isEmpty()) {
                for (Entry<String, Set<String>> entry : optionalPkgs.entrySet()) {
                    Table.Node feat = new Table.Node(entry.getKey());
                    producerNode.addNext(feat);
                    for (String p : entry.getValue()) {
                        Table.Node pkg = new Table.Node(p);
                        feat.addNext(pkg);
                        if (passivePresent) {
                            pkg.addNext(new Table.Node(""));
                        }
                    }
                    Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
                    if (passivePkgs != null) {
                        Set<String> passives = passivePkgs.get(entry.getKey());
                        if (passives != null) {
                            for (String p : passives) {
                                Table.Node pkg = new Table.Node(p);
                                feat.addNext(pkg);
                                pkg.addNext(new Table.Node("true"));
                            }
                        }
                    }
                }
            } else {
                Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
                if (passivePkgs != null && !passivePkgs.isEmpty()) {
                    for (Entry<String, Set<String>> entry : passivePkgs.entrySet()) {
                        Table.Node feat = new Table.Node(entry.getKey());
                        producerNode.addNext(feat);
                        for (String p : entry.getValue()) {
                            Table.Node pkg = new Table.Node(p);
                            feat.addNext(pkg);
                            pkg.addNext(new Table.Node("true"));
                        }
                    }
                }
            }
            Set<String> orphanOptionals = container.getOrphanOptionalPackages().get(producer);
            Set<String> orphanPassives = container.getOrphanPassivePackages().get(producer);
            if (orphanOptionals != null || orphanPassives != null) {
                Table.Node feat = new Table.Node("{no-feature}");
                producerNode.addNext(feat);
                if (orphanOptionals != null) {
                    for (String p : orphanOptionals) {
                        Table.Node pkg = new Table.Node(p);
                        feat.addNext(pkg);
                        if (passivePresent) {
                            pkg.addNext(new Table.Node(""));
                        }
                    }
                }
                if (orphanPassives != null) {
                    for (String p : orphanPassives) {
                        Table.Node pkg = new Table.Node(p);
                        feat.addNext(pkg);
                        pkg.addNext(new Table.Node("true"));
                    }
                }
            }
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Optional packages (Provisioning option: " + optionValue + ")" + Config.getLineSeparator());
    if (t == null) {
        builder.append(NO_OPTIONAL_PACKAGES);
    } else {
        builder.append(t.build());
    }
    return builder.toString();
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) PathParserException(org.jboss.galleon.cli.path.PathParserException) PathConsumerException(org.jboss.galleon.cli.path.PathConsumerException) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Aggregations

ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)9 ProvisioningException (org.jboss.galleon.ProvisioningException)8 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)8 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)5 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)2 Table (org.jboss.galleon.cli.cmd.Table)2 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)2 Path (java.nio.file.Path)1