Search in sources :

Example 1 with PmSession

use of org.jboss.galleon.cli.PmSession in project galleon by wildfly.

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation commandInvocation) throws CommandExecutionException {
    if (fpl != null && file != null) {
        throw new CommandExecutionException("File and location can't be both set");
    }
    if (fpl == null && file == null) {
        throw new CommandExecutionException("File or location must be set");
    }
    PmSession session = commandInvocation.getPmSession();
    FeaturePackLayout product = null;
    List<FeaturePackLocation> dependencies = new ArrayList<>();
    ProvisioningConfig provisioning;
    ProvisioningLayout<FeaturePackLayout> layout = null;
    try {
        try {
            if (fpl != null) {
                FeaturePackLocation loc;
                loc = session.getResolvedLocation(null, fpl);
                FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
                provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
                layout = session.getLayoutFactory().newConfigLayout(provisioning);
            } else {
                layout = session.getLayoutFactory().newConfigLayout(file.toPath(), true);
            }
            for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) {
                boolean isProduct = true;
                for (FeaturePackLayout fpLayout2 : layout.getOrderedFeaturePacks()) {
                    if (fpLayout2.getSpec().hasTransitiveDep(fpLayout.getFPID().getProducer()) || fpLayout2.getSpec().getFeaturePackDep(fpLayout.getFPID().getProducer()) != null) {
                        isProduct = false;
                        break;
                    }
                }
                if (isProduct) {
                    product = fpLayout;
                } else {
                    dependencies.add(session.getExposedLocation(null, fpLayout.getFPID().getLocation()));
                }
            }
        } catch (ProvisioningException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
        if (product == null) {
            throw new CommandExecutionException("No feature-pack found");
        }
        commandInvocation.println("");
        StateInfoUtil.printFeaturePack(commandInvocation, session.getExposedLocation(null, product.getFPID().getLocation()));
        try {
            final FPID patchFor = product.getSpec().getPatchFor();
            if (patchFor != null) {
                commandInvocation.println("");
                commandInvocation.println(PATCH_FOR + patchFor);
            }
        } catch (ProvisioningException e) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), e);
        }
        try {
            if (type != null) {
                commandInvocation.println("");
                switch(type) {
                    case ALL:
                        {
                            if (displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println("");
                            }
                            if (displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayLayers(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            displayOptions(commandInvocation, layout);
                            break;
                        }
                    case CONFIGS:
                        {
                            if (!displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_CONFIGURATIONS);
                            }
                            break;
                        }
                    case DEPENDENCIES:
                        {
                            if (!displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println(StateInfoUtil.NO_DEPENDENCIES);
                            }
                            break;
                        }
                    case LAYERS:
                        {
                            if (!displayLayers(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_LAYERS);
                            }
                            break;
                        }
                    case OPTIONS:
                        {
                            if (!displayOptions(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONS);
                            }
                            break;
                        }
                    case OPTIONAL_PACKAGES:
                        {
                            if (!displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONAL_PACKAGES);
                            }
                            break;
                        }
                    default:
                        {
                            throw new CommandExecutionException(CliErrors.invalidInfoType());
                        }
                }
            }
        } catch (ProvisioningException | IOException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
    } finally {
        if (layout != null) {
            layout.close();
        }
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) PmSession(org.jboss.galleon.cli.PmSession) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 2 with PmSession

use of org.jboss.galleon.cli.PmSession 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 3 with PmSession

use of org.jboss.galleon.cli.PmSession in project galleon by wildfly.

the class FPLocationCompleter method doComplete.

private void doComplete(PmCompleterInvocation completerInvocation) throws ProvisioningException {
    // Legacy completer first
    PmSession pmSession = completerInvocation.getPmSession();
    UniverseManager resolver = pmSession.getUniverse();
    installation = completerInvocation.getCommand() instanceof CommandWithInstallationDirectory ? ((CommandWithInstallationDirectory) completerInvocation.getCommand()).getInstallationDirectory(completerInvocation.getAeshContext()) : null;
    UniverseSpec defaultUniverse = pmSession.getUniverse().getDefaultUniverseSpec(installation);
    Set<String> aliases = pmSession.getUniverse().getUniverseNames(installation);
    // producer[@universe]:channel/frequency#build
    // producer[@factory-id/location]:channel/frequency#build
    String buffer = completerInvocation.getGivenCompleteValue();
    List<String> candidates = new ArrayList<>();
    FPLocationParser.ParsedFPLocation loc = null;
    try {
        if (buffer.isEmpty()) {
            if (defaultUniverse != null) {
                getAllProducers(null, defaultUniverse, resolver.getUniverse(defaultUniverse), candidates);
            }
            for (String name : aliases) {
                UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
                if (u.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
                    continue;
                }
                if (!u.equals(defaultUniverse)) {
                    getAllProducers(u.toString(), u, resolver.getUniverse(u), candidates);
                }
            }
        } else {
            loc = FPLocationParser.parse(buffer, new FPLocationParser.FPLocationCompletionConsumer() {

                @Override
                public void completeProducer(String producer) throws FPLocationParserException, ProvisioningException {
                    // Lookup in all universes for a producer, we don't know the universe yet
                    if (defaultUniverse != null) {
                        getProducers(producer, null, resolver.getUniverse(defaultUniverse), candidates);
                    }
                    for (String name : aliases) {
                        UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (!u.equals(defaultUniverse)) {
                            getProducers(producer, name, resolver.getUniverse(u), candidates);
                        }
                    }
                }

                @Override
                public void completeUniverse(FPLocationParser.ParsedFPLocation parsedLocation, String universe) throws FPLocationParserException, ProvisioningException {
                    for (String name : aliases) {
                        UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (spec != null && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
                            if (name.equals(universe)) {
                                candidates.add(name + FeaturePackLocation.CHANNEL_START);
                            } else if (name.startsWith(universe)) {
                                candidates.add(name);
                            }
                        }
                    }
                }

                @Override
                public void completeUniverseLocation(FPLocationParser.ParsedFPLocation parsedLocation, String universeLocation) throws FPLocationParserException, ProvisioningException {
                    for (String name : aliases) {
                        UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (spec == null || spec.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
                            continue;
                        }
                        if (!candidates.contains(spec.getLocation())) {
                            if (spec.getFactory().equals(parsedLocation.getUniverseFactory()) && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
                                if (spec.getLocation().equals(universeLocation)) {
                                    candidates.add(spec.getLocation() + FeaturePackLocation.UNIVERSE_LOCATION_END);
                                } else if (spec.getLocation().startsWith(universeLocation)) {
                                    candidates.add(spec.getLocation());
                                }
                                break;
                            }
                        }
                    }
                }

                @Override
                public void completeChannel(FPLocationParser.ParsedFPLocation parsedLocation, String channel) throws FPLocationParserException, ProvisioningException {
                    Producer<?> p = getProducer(parsedLocation, pmSession);
                    if (p == null) {
                        return;
                    }
                    for (Channel c : p.getChannels()) {
                        if (c.getName().equals(channel)) {
                            // Do nothing, do not inline separators. Separators are to be added explicitly
                            // this could be revisited.
                            candidates.add(channel);
                        } else if (c.getName().startsWith(channel)) {
                            candidates.add(c.getName());
                        }
                    }
                }

                @Override
                public void completeFrequency(FPLocationParser.ParsedFPLocation parsedLocation, String frequency) throws FPLocationParserException, ProvisioningException {
                    Producer<?> p = getProducer(parsedLocation, pmSession);
                    if (p == null) {
                        return;
                    }
                    for (String freq : p.getFrequencies()) {
                        if (freq.equals(frequency)) {
                            // Do not inline the build separator, separator is to be added explicitly
                            // this could be revisited.
                            candidates.add(freq);
                        } else if (freq.startsWith(frequency)) {
                            candidates.add(freq);
                        }
                    }
                }

                @Override
                public void completeChannelSeparator(FPLocationParser.ParsedFPLocation parsedLocation) throws FPLocationParserException, ProvisioningException {
                    candidates.add("" + FeaturePackLocation.CHANNEL_START);
                }

                @Override
                public void completeBuild(FPLocationParser.ParsedFPLocation parsedLocation, String build) throws FPLocationParserException, ProvisioningException {
                    UniverseSpec spec = null;
                    if (parsedLocation.getUniverseName() != null) {
                        spec = pmSession.getUniverse().getUniverseSpec(installation, parsedLocation.getUniverseName());
                    } else if (parsedLocation.getUniverseFactory() == null) {
                        spec = pmSession.getUniverse().getDefaultUniverseSpec(installation);
                    } else {
                        spec = new UniverseSpec(parsedLocation.getUniverseFactory(), parsedLocation.getUniverseLocation());
                    }
                    if (spec != null) {
                        String latestBuild = null;
                        // FPID
                        if (parsedLocation.getFrequency() == null) {
                            FeaturePackLocation.FPID id = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), null, null).getFPID();
                            latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(id);
                        } else {
                            FeaturePackLocation loc = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), parsedLocation.getFrequency(), null);
                            latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(loc);
                        }
                        if (latestBuild != null) {
                            if (latestBuild.startsWith(build)) {
                                candidates.add(latestBuild);
                            }
                        }
                    }
                }
            });
        }
    } catch (Exception ex) {
        CliLogging.completionException(ex);
        return;
    }
    completerInvocation.addAllCompleterValues(candidates);
    if (candidates.size() == 1) {
        if (completerInvocation.getGivenCompleteValue().endsWith(candidates.get(0))) {
            completerInvocation.setAppendSpace(true);
        } else {
            completerInvocation.setAppendSpace(false);
        }
        completerInvocation.setOffset(completerInvocation.getGivenCompleteValue().length() - (loc == null ? 0 : (loc.getMarker() + 1)));
    }
}
Also used : UniverseManager(org.jboss.galleon.cli.UniverseManager) Channel(org.jboss.galleon.universe.Channel) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningException(org.jboss.galleon.ProvisioningException) PmSession(org.jboss.galleon.cli.PmSession) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Example 4 with PmSession

use of org.jboss.galleon.cli.PmSession in project galleon by wildfly.

the class StateFullPathCompleter method getContainer.

@Override
protected FeatureContainer getContainer(PmCompleterInvocation completerInvocation) {
    PmSession session = completerInvocation.getPmSession();
    FeatureContainer container = session.getContainer();
    return container;
}
Also used : PmSession(org.jboss.galleon.cli.PmSession) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer)

Example 5 with PmSession

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

Aggregations

PmSession (org.jboss.galleon.cli.PmSession)5 ArrayList (java.util.ArrayList)2 ProvisioningException (org.jboss.galleon.ProvisioningException)2 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)2 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)2 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2 IOException (java.io.IOException)1 UniverseManager (org.jboss.galleon.cli.UniverseManager)1 Group (org.jboss.galleon.cli.model.Group)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)1 Channel (org.jboss.galleon.universe.Channel)1 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)1 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)1