Search in sources :

Example 6 with FeatureContainerPathConsumer

use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.

the class AbstractPathCompleter method getItems.

List<String> getItems(PmCompleterInvocation completerInvocation) {
    PmSession session = completerInvocation.getPmSession();
    try {
        FeatureContainer container = getContainer(completerInvocation);
        if (container == null) {
            return Collections.emptyList();
        }
        if (session.getCurrentPath() == null && completerInvocation.getGivenCompleteValue().isEmpty()) {
            return Arrays.asList("" + PathParser.PATH_SEPARATOR);
        }
        String buffer = completerInvocation.getGivenCompleteValue();
        if (!buffer.startsWith("" + PathParser.PATH_SEPARATOR)) {
            String currentPath = getCurrentPath(completerInvocation);
            if (currentPath != null) {
                boolean completePath = currentPath.endsWith("" + PathParser.PATH_SEPARATOR);
                buffer = currentPath + (completePath ? "" : "" + PathParser.PATH_SEPARATOR) + buffer;
            }
        }
        FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(container, true);
        PathParser.parse(buffer, consumer);
        List<String> candidates = consumer.getCandidates(buffer);
        filterCandidates(consumer, candidates);
        return candidates;
    } catch (Exception ex) {
        CliLogging.log.errorf("Exception while completing: {0}", ex.getLocalizedMessage());
    }
    return Collections.emptyList();
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) PmSession(org.jboss.galleon.cli.PmSession) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer)

Example 7 with FeatureContainerPathConsumer

use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer 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 FeatureContainerPathConsumer

use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer 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 FeatureContainerPathConsumer

use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer 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)

Example 10 with FeatureContainerPathConsumer

use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.

the class ConfigurationUtil method getConfig.

private static ConfigInfo getConfig(PmSession session, FPID fpid, String configuration) throws ProvisioningException, IOException, PathParserException, PathConsumerException {
    String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + configuration + PathParser.PATH_SEPARATOR;
    FeatureContainer full = FeatureContainers.fromFeaturePackId(session, fpid, null);
    ConfigInfo ci = null;
    try {
        FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(full, false);
        PathParser.parse(path, consumer);
        ci = consumer.getConfig();
    } catch (PathParserException | PathConsumerException ex) {
    // XXX OK, return null
    }
    return ci;
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) PathParserException(org.jboss.galleon.cli.path.PathParserException) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) PathConsumerException(org.jboss.galleon.cli.path.PathConsumerException)

Aggregations

FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)12 ProvisioningException (org.jboss.galleon.ProvisioningException)7 Group (org.jboss.galleon.cli.model.Group)7 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)5 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)3 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)3 PmSession (org.jboss.galleon.cli.PmSession)2 PathConsumerException (org.jboss.galleon.cli.path.PathConsumerException)2 PathParserException (org.jboss.galleon.cli.path.PathParserException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FeatureInfo (org.jboss.galleon.cli.model.FeatureInfo)1 PackageInfo (org.jboss.galleon.cli.model.PackageInfo)1