Search in sources :

Example 6 with Group

use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.

the class StateSearchCommand method findFeatures.

private Set<ResolvedSpecId> findFeatures(PackageInfo spec, FeatureContainer container) {
    Set<ResolvedSpecId> fspecs = new HashSet<>();
    for (Entry<ResolvedSpecId, FeatureSpecInfo> features : container.getAllSpecs().entrySet()) {
        for (PackageInfo info : features.getValue().getPackages()) {
            Group grp = container.getAllPackages().get(info.getIdentity());
            Set<Identity> identities = new HashSet<>();
            visitPkg(grp, identities);
            if (identities.contains(spec.getIdentity())) {
                fspecs.add(features.getKey());
                break;
            }
        }
    }
    return fspecs;
}
Also used : Group(org.jboss.galleon.cli.model.Group) ResolvedSpecId(org.jboss.galleon.runtime.ResolvedSpecId) PackageInfo(org.jboss.galleon.cli.model.PackageInfo) FeatureSpecInfo(org.jboss.galleon.cli.model.FeatureSpecInfo) Identity(org.jboss.galleon.cli.model.Identity) HashSet(java.util.HashSet)

Example 7 with Group

use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.

the class StateInfoUtil method printContentPath.

public static void printContentPath(PmCommandInvocation session, FeatureContainer fp, String path) throws ProvisioningException, PathParserException, PathConsumerException, IOException {
    FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(fp, false);
    PathParser.parse(path, consumer);
    Group grp = consumer.getCurrentNode(path);
    if (grp != null) {
        // entered some content
        if (grp.getFeature() != null) {
            displayFeature(session, grp);
        } else if (grp.getSpec() != null) {
            displayFeatureSpec(session, grp);
        } else if (grp.getPackage() != null) {
            displayPackage(session, grp);
        } else if (!grp.getGroups().isEmpty()) {
            displayContainmentGroup(session, grp);
        }
    }
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group)

Example 8 with Group

use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.

the class StateCdCommand method cdFp.

private void cdFp(PmCommandInvocation session) throws CommandExecutionException, PathParserException, PathConsumerException {
    PmSession pm = session.getPmSession();
    String currentPath = pm.getCurrentPath();
    FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(pm.getContainer(), true);
    if (path.startsWith("" + PathParser.PATH_SEPARATOR)) {
        pm.setCurrentPath(null);
    } else if (path.equals("..")) {
        if (currentPath == null) {
            throw new CommandExecutionException("No path entered");
        }
        if (currentPath.equals("" + PathParser.PATH_SEPARATOR)) {
            return;
        }
        currentPath = currentPath.substring(0, currentPath.length() - 1);
        int i = currentPath.lastIndexOf("" + PathParser.PATH_SEPARATOR);
        if (i < 0) {
            path = "" + PathParser.PATH_SEPARATOR;
        } else {
            path = currentPath.substring(0, i);
        }
        if (path.isEmpty()) {
            path = "" + PathParser.PATH_SEPARATOR;
        }
        pm.setCurrentPath(null);
    } else {
        path = currentPath + path;
    }
    PathParser.parse(path, consumer);
    Group grp = consumer.getCurrentNode(path);
    if (grp == null) {
        return;
    } else {
        if (!path.endsWith("" + PathParser.PATH_SEPARATOR)) {
            path += PathParser.PATH_SEPARATOR;
        }
        pm.setCurrentPath(path);
    }
    String prompt;
    if (FeatureContainerPathConsumer.ROOT.equals(grp.getIdentity().getName())) {
        prompt = "" + PathParser.PATH_SEPARATOR;
    } else {
        prompt = grp.getIdentity().getName() + PathParser.PATH_SEPARATOR;
    }
    session.setPrompt(session.getPmSession().buildPrompt(prompt));
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group) PmSession(org.jboss.galleon.cli.PmSession) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 9 with Group

use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.

the class StateSearchCommand method run.

private void run(FeatureContainer container, PmCommandInvocation invoc, boolean dependencySearch) throws PathParserException, PathConsumerException, ProvisioningException {
    if (pkg != null) {
        PackageInfo spec = getPackage(dependencySearch ? container : new AbstractPackageCommand.AllPackagesContainer(container), pkg);
        invoc.println(Config.getLineSeparator() + "As a direct dependency of a package:");
        StringBuilder pBuilder = new StringBuilder();
        for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
            Group root = pkgs.getValue();
            for (Group g : root.getGroups()) {
                for (Group dep : g.getGroups()) {
                    if (dep.getIdentity().equals(spec.getIdentity())) {
                        pBuilder.append("  " + g.getIdentity()).append(Config.getLineSeparator());
                        break;
                    }
                }
            }
        }
        if (pBuilder.length() != 0) {
            invoc.println(pBuilder.toString());
        } else {
            invoc.println("NONE");
        }
        Set<ResolvedSpecId> fspecs = findFeatures(spec, container);
        invoc.println("Reachable from features:");
        if (fspecs.isEmpty()) {
            invoc.println("NONE");
        } else {
            for (ResolvedSpecId id : fspecs) {
                List<FeatureInfo> features = container.getAllFeatures().get(id);
                // Can be null if we have all specs whatever the set of features.
                if (features != null) {
                    for (FeatureInfo fi : features) {
                        invoc.println("  " + fi.getPath());
                    }
                } else {
                    invoc.println("      [spec only] " + toPath(id));
                }
            }
        }
        return;
    }
    invoc.println(Config.getLineSeparator() + "Packages:");
    StringBuilder pBuilder = new StringBuilder();
    for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
        Group root = pkgs.getValue();
        for (Group g : root.getGroups()) {
            PackageInfo p = g.getPackage();
            if (p.getIdentity().toString().contains(query)) {
                pBuilder.append("  " + FeatureContainerPathConsumer.PACKAGES_PATH + p.getIdentity()).append(Config.getLineSeparator());
                if (!dependencySearch) {
                    pBuilder.append("    Reachable from features:").append(Config.getLineSeparator());
                    Set<ResolvedSpecId> fspecs = findFeatures(p, container);
                    if (fspecs.isEmpty()) {
                        pBuilder.append("      NONE" + Config.getLineSeparator());
                    }
                    for (ResolvedSpecId id : fspecs) {
                        List<FeatureInfo> features = container.getAllFeatures().get(id);
                        // Can be null if we have all specs whatever the set of features.
                        if (features != null) {
                            for (FeatureInfo fi : features) {
                                pBuilder.append("      " + fi.getPath()).append(Config.getLineSeparator());
                            }
                        } else {
                            pBuilder.append("  [spec only] " + toPath(id)).append(Config.getLineSeparator());
                        }
                    }
                }
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    invoc.println(Config.getLineSeparator() + "Package dependencies:");
    for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
        Group root = pkgs.getValue();
        for (Group g : root.getGroups()) {
            StringBuilder depBuilder = new StringBuilder();
            for (Group dep : g.getGroups()) {
                if (dep.getIdentity().toString().contains(query)) {
                    depBuilder.append("  " + dep.getIdentity()).append(Config.getLineSeparator());
                    break;
                }
            }
            if (depBuilder.length() != 0) {
                pBuilder.append("  Found as a direct dependencies of " + g.getIdentity()).append(Config.getLineSeparator());
                pBuilder.append(depBuilder);
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    invoc.println(Config.getLineSeparator() + "Package content:");
    for (Entry<String, Group> entry : container.getPackages().entrySet()) {
        Group root = entry.getValue();
        for (Group g : root.getGroups()) {
            PackageInfo pkginfo = g.getPackage();
            StringBuilder contentBuilder = new StringBuilder();
            for (String c : pkginfo.getContent()) {
                if (c.contains(query)) {
                    contentBuilder.append(c).append(Config.getLineSeparator());
                }
            }
            if (contentBuilder.length() != 0) {
                pBuilder.append("  Found in content of " + g.getIdentity()).append(Config.getLineSeparator());
                pBuilder.append(contentBuilder);
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    // Features?
    invoc.println(Config.getLineSeparator() + "Features:");
    for (Entry<ResolvedSpecId, List<FeatureInfo>> features : container.getAllFeatures().entrySet()) {
        ResolvedSpecId id = features.getKey();
        List<FeatureInfo> fs = features.getValue();
        if (fs == null) {
            if (id.getName().contains(query)) {
                pBuilder.append("  [spec only] " + toPath(id)).append(Config.getLineSeparator());
            }
        } else {
            for (FeatureInfo fi : fs) {
                if (fi.getPath().contains(query)) {
                    pBuilder.append("  " + fi.getPath()).append(Config.getLineSeparator());
                }
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
}
Also used : Group(org.jboss.galleon.cli.model.Group) ResolvedSpecId(org.jboss.galleon.runtime.ResolvedSpecId) PackageInfo(org.jboss.galleon.cli.model.PackageInfo) FeatureInfo(org.jboss.galleon.cli.model.FeatureInfo) List(java.util.List)

Example 10 with Group

use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.

the class StateSearchCommand method getPackage.

private PackageInfo getPackage(FeatureContainer container, String id) throws PathParserException, PathConsumerException, ProvisioningException {
    String path = FeatureContainerPathConsumer.PACKAGES_PATH + id;
    FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(container, false);
    PathParser.parse(path, consumer);
    Group grp = consumer.getCurrentNode(path);
    if (grp == null) {
        throw new ProvisioningException("Invalid path");
    }
    if (grp.getPackage() == null) {
        throw new ProvisioningException("Path is not a package");
    }
    return grp.getPackage();
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group) ProvisioningException(org.jboss.galleon.ProvisioningException)

Aggregations

Group (org.jboss.galleon.cli.model.Group)12 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 ProvisioningException (org.jboss.galleon.ProvisioningException)4 PackageInfo (org.jboss.galleon.cli.model.PackageInfo)4 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)3 FeatureInfo (org.jboss.galleon.cli.model.FeatureInfo)2 Identity (org.jboss.galleon.cli.model.Identity)2 ResolvedSpecId (org.jboss.galleon.runtime.ResolvedSpecId)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 PmSession (org.jboss.galleon.cli.PmSession)1 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)1 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)1 FeatureSpecInfo (org.jboss.galleon.cli.model.FeatureSpecInfo)1 PathConsumerException (org.jboss.galleon.cli.path.PathConsumerException)1 PathParserException (org.jboss.galleon.cli.path.PathParserException)1