Search in sources :

Example 1 with CommandExecutionException

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

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

the class ImportCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation commandInvocation) throws CommandExecutionException {
    try {
        FeaturePackLocation fpl = commandInvocation.getPmSession().getLayoutFactory().addLocal(path.toPath(), install == null ? true : install);
        commandInvocation.println(fpl + " imported.");
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.importFeaturePackFailed(), ex);
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 3 with CommandExecutionException

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

the class CdCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation session) throws CommandExecutionException {
    if (path == null) {
        return;
    }
    Path p = path.toPath();
    if (path.getName().equals("-")) {
        Path previous = session.getPmSession().getPreviousDirectory();
        if (previous == null) {
            return;
        }
        p = previous;
    }
    try {
        session.getPmSession().setCurrentDirectory(p);
        session.setPrompt(session.getPmSession().buildPrompt());
    } catch (IOException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
}
Also used : Path(java.nio.file.Path) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 4 with CommandExecutionException

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

the class SetHistoryLimitCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        int s;
        try {
            s = Integer.parseInt(limit);
        } catch (NumberFormatException ex) {
            throw new CommandExecutionException(CliErrors.invalidHistoryLimit(limit));
        }
        getManager(invoc.getPmSession()).setStateHistoryLimit(s);
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.setHistoryLimitFailed(), ex);
    }
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 5 with CommandExecutionException

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

the class CheckUpdatesCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation session) throws CommandExecutionException {
    try {
        ProvisioningManager mgr = getManager(session.getPmSession());
        Updates updates = getUpdatesTable(mgr, session, includeAll, fp);
        if (updates.plan.isEmpty()) {
            session.println(UP_TO_DATE);
        } else {
            session.println(UPDATES_AVAILABLE);
            session.println(updates.t.build());
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(session.getPmSession(), CliErrors.checkForUpdatesFailed(), ex);
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Aggregations

CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)37 ProvisioningException (org.jboss.galleon.ProvisioningException)25 IOException (java.io.IOException)18 Path (java.nio.file.Path)11 ProvisioningManager (org.jboss.galleon.ProvisioningManager)8 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)7 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)6 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)6 State (org.jboss.galleon.cli.model.state.State)5 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)5 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 ArrayList (java.util.ArrayList)3 Group (org.jboss.galleon.cli.model.Group)3 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)3 PathConsumerException (org.jboss.galleon.cli.path.PathConsumerException)3 PathParserException (org.jboss.galleon.cli.path.PathParserException)3 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2