Search in sources :

Example 11 with FPID

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

the class StateInfoUtil method buildDependencies.

public static String buildDependencies(List<FeaturePackLocation> dependencies, Map<FPID, FeaturePackConfig> configs) {
    if (!dependencies.isEmpty()) {
        boolean showPatches = configs == null ? false : showPatches(configs.values());
        List<String> headers = new ArrayList<>();
        headers.add(Headers.DEPENDENCY);
        headers.add(Headers.BUILD);
        if (showPatches) {
            headers.add(Headers.PATCHES);
        }
        headers.add(Headers.UPDATE_CHANNEL);
        Table table = new Table(headers);
        for (FeaturePackLocation d : dependencies) {
            List<Cell> line = new ArrayList<>();
            line.add(new Cell(d.getProducerName()));
            line.add(new Cell(d.getBuild()));
            if (showPatches) {
                FeaturePackConfig config = configs.get(d.getFPID());
                if (config != null && config.hasPatches()) {
                    Cell patches = new Cell();
                    for (FPID p : config.getPatches()) {
                        patches.addLine(p.getBuild());
                    }
                    line.add(patches);
                }
            }
            line.add(new Cell(formatChannel(d)));
            table.addCellsLine(line);
        }
        table.sort(Table.SortType.ASCENDANT);
        return table.build();
    }
    return null;
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Cell(org.jboss.galleon.cli.cmd.Table.Cell) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 12 with FPID

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

the class StateInfoUtil method buildFeaturePacks.

private static String buildFeaturePacks(PmCommandInvocation commandInvocation, Path installation, Collection<FeaturePackConfig> fps) {
    boolean showPatches = showPatches(fps);
    List<String> headers = new ArrayList<>();
    headers.add(Headers.PRODUCT);
    headers.add(Headers.BUILD);
    if (showPatches) {
        headers.add(Headers.PATCHES);
    }
    headers.add(Headers.UPDATE_CHANNEL);
    Table t = new Table(headers);
    for (FeaturePackConfig c : fps) {
        FeaturePackLocation loc = commandInvocation.getPmSession().getExposedLocation(installation, c.getLocation());
        List<Cell> line = new ArrayList<>();
        line.add(new Cell(loc.getProducer().getName()));
        line.add(new Cell(loc.getBuild()));
        if (showPatches) {
            if (c.hasPatches()) {
                Cell patches = new Cell();
                for (FPID p : c.getPatches()) {
                    patches.addLine(p.getBuild());
                }
                line.add(patches);
            }
        }
        line.add(new Cell(formatChannel(loc)));
        t.addCellsLine(line);
    }
    if (!t.isEmpty()) {
        t.sort(Table.SortType.ASCENDANT);
        return t.build();
    } else {
        return null;
    }
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Cell(org.jboss.galleon.cli.cmd.Table.Cell) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 13 with FPID

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

the class ProvisioningXmlWriter method writeFeaturePackConfig.

static void writeFeaturePackConfig(ElementNode fp, FeaturePackLocation location, FeaturePackConfig featurePack, String origin) {
    final String ns = fp.getNamespace();
    addAttribute(fp, Attribute.LOCATION, location.toString());
    if (origin != null) {
        addElement(fp, Element.ORIGIN.getLocalName(), ns).addChild(new TextNode(origin));
    }
    if (featurePack.hasPatches()) {
        final ElementNode patches = addElement(fp, Element.PATCHES.getLocalName(), ns);
        for (FPID patchId : featurePack.getPatches()) {
            final ElementNode patch = addElement(patches, Element.PATCH.getLocalName(), ns);
            addAttribute(patch, Attribute.ID, patchId.toString());
        }
    }
    writeConfigCustomizations(fp, ns, featurePack);
    ElementNode packages = null;
    final Boolean inheritPackages = featurePack.getInheritPackages();
    if (inheritPackages != null) {
        packages = addElement(fp, Element.PACKAGES.getLocalName(), ns);
        addAttribute(packages, Attribute.INHERIT, String.valueOf(inheritPackages));
    }
    if (featurePack.hasExcludedPackages()) {
        if (packages == null) {
            packages = addElement(fp, Element.PACKAGES.getLocalName(), ns);
        }
        for (String excluded : featurePack.getExcludedPackages()) {
            final ElementNode exclude = addElement(packages, Element.EXCLUDE.getLocalName(), ns);
            addAttribute(exclude, Attribute.NAME, excluded);
        }
    }
    if (featurePack.hasIncludedPackages()) {
        if (packages == null) {
            packages = addElement(fp, Element.PACKAGES.getLocalName(), ns);
        }
        for (String included : featurePack.getIncludedPackages()) {
            final ElementNode include = addElement(packages, Element.INCLUDE.getLocalName(), ns);
            addAttribute(include, Attribute.NAME, included);
        }
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) TextNode(org.jboss.galleon.xml.util.TextNode) ElementNode(org.jboss.galleon.xml.util.ElementNode)

Example 14 with FPID

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

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

the class FindCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    if (pattern == null && layerPattern == null) {
        throw new CommandExecutionException(CliErrors.missingPattern());
    } else {
        if (pattern == null) {
            pattern = ".Final";
        }
        Map<UniverseSpec, Set<Result>> results = new HashMap<>();
        Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
        if (!pattern.endsWith("*")) {
            pattern = pattern + "*";
        }
        pattern = pattern.replaceAll("\\*", ".*");
        List<Pattern> layersCompiledPatterns = new ArrayList<>();
        if (layerPattern != null) {
            for (String l : layerPattern.split(",")) {
                if (!l.endsWith("*")) {
                    l = l + "*";
                }
                l = l.replaceAll("\\*", ".*");
                layersCompiledPatterns.add(Pattern.compile(l));
            }
        }
        boolean containsFrequency = pattern.contains("" + FeaturePackLocation.FREQUENCY_START);
        Pattern compiledPattern = Pattern.compile(pattern);
        Integer[] numResults = new Integer[1];
        numResults[0] = 0;
        ProgressTracker<FPID> track = null;
        if (invoc.getPmSession().isTrackersEnabled()) {
            track = ProgressTrackers.newFindTracker(invoc);
        }
        ProgressTracker<FPID> tracker = track;
        invoc.getPmSession().unregisterTrackers();
        // Search for an installation in the context
        Path installation = null;
        try {
            installation = Util.lookupInstallationDir(invoc.getConfiguration().getAeshContext(), null);
        } catch (ProvisioningException ex) {
        // XXX OK, no installation.
        }
        Path finalPath = installation;
        try {
            Comparator<Result> locComparator = new Comparator<Result>() {

                @Override
                public int compare(Result o1, Result o2) {
                    return o1.location.toString().compareTo(o2.location.toString());
                }
            };
            UniverseVisitor visitor = new UniverseVisitor() {

                @Override
                public void visit(Producer<?> producer, FeaturePackLocation loc) {
                    try {
                        if (resolvedOnly && !producer.getChannel(loc.getChannelName()).isResolved(loc)) {
                            return;
                        }
                    } catch (ProvisioningException ex) {
                        exception(loc.getUniverse(), ex);
                        return;
                    }
                    if (tracker != null) {
                        tracker.processing(loc.getFPID());
                    }
                    // Universe could have been set in the pattern, matches on
                    // the canonical and exposed (named universe).
                    FeaturePackLocation exposedLoc = invoc.getPmSession().getExposedLocation(finalPath, loc);
                    boolean canonicalMatch = compiledPattern.matcher(loc.toString()).matches();
                    boolean exposedMatch = compiledPattern.matcher(exposedLoc.toString()).matches();
                    // If no frequency set, matches FPL that don't contain a frequency.
                    if (canonicalMatch || exposedMatch) {
                        if ((containsFrequency && loc.getFrequency() != null) || (!containsFrequency && loc.getFrequency() == null)) {
                            Result result;
                            if (exposedMatch) {
                                result = new Result(exposedLoc);
                            } else {
                                result = new Result(loc);
                            }
                            if (!layersCompiledPatterns.isEmpty()) {
                                try {
                                    FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
                                    ProvisioningConfig provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
                                    Set<ConfigId> layers = new HashSet<>();
                                    try (ProvisioningLayout<FeaturePackLayout> layout = invoc.getPmSession().getLayoutFactory().newConfigLayout(provisioning)) {
                                        for (FeaturePackLayout l : layout.getOrderedFeaturePacks()) {
                                            layers.addAll(l.loadLayers());
                                        }
                                    }
                                    for (ConfigId l : layers) {
                                        for (Pattern p : layersCompiledPatterns) {
                                            if (p.matcher(l.getName()).matches()) {
                                                result.layers.add(l);
                                            }
                                        }
                                    }
                                    if (!result.layers.isEmpty()) {
                                        Set<Result> locations = results.get(loc.getUniverse());
                                        if (locations == null) {
                                            locations = new TreeSet<>(locComparator);
                                            results.put(loc.getUniverse(), locations);
                                        }
                                        locations.add(result);
                                        numResults[0] = numResults[0] + 1;
                                    }
                                } catch (IOException | ProvisioningException ex) {
                                    exception(loc.getUniverse(), ex);
                                }
                            } else {
                                Set<Result> locations = results.get(loc.getUniverse());
                                if (locations == null) {
                                    locations = new TreeSet<>(locComparator);
                                    results.put(loc.getUniverse(), locations);
                                }
                                locations.add(result);
                                numResults[0] = numResults[0] + 1;
                            }
                        }
                    }
                }

                @Override
                public void exception(UniverseSpec spec, Exception ex) {
                    Set<String> set = exceptions.get(spec);
                    if (set == null) {
                        set = new HashSet<>();
                        exceptions.put(spec, set);
                    }
                    set.add(ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage());
                }
            };
            if (tracker != null) {
                tracker.starting(-1);
            }
            if (fromUniverse == null) {
                invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
            } else {
                invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
            }
            if (tracker != null) {
                tracker.complete();
            }
            printExceptions(invoc, exceptions);
            invoc.println(Config.getLineSeparator() + "Found " + numResults[0] + " feature pack location" + (numResults[0] > 1 ? "s." : "."));
            for (Entry<UniverseSpec, Set<Result>> entry : results.entrySet()) {
                for (Result loc : entry.getValue()) {
                    invoc.println(loc.toString());
                }
            }
        } catch (ProvisioningException ex) {
            throw new CommandExecutionException(ex.getLocalizedMessage());
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Comparator(java.util.Comparator) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigId(org.jboss.galleon.config.ConfigId) UniverseVisitor(org.jboss.galleon.cli.UniverseManager.UniverseVisitor) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig) HashSet(java.util.HashSet) Path(java.nio.file.Path) Pattern(java.util.regex.Pattern) IOException(java.io.IOException) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Producer(org.jboss.galleon.universe.Producer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Aggregations

FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)23 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)14 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)11 ArrayList (java.util.ArrayList)8 ProvisioningException (org.jboss.galleon.ProvisioningException)8 IOException (java.io.IOException)5 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)5 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)4 Table (org.jboss.galleon.cli.cmd.Table)4 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)4 HashSet (java.util.HashSet)3 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)3 Cell (org.jboss.galleon.cli.cmd.Table.Cell)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2