Search in sources :

Example 46 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier = new Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer>() {

            public FeatureContainer apply(ProvisioningLayout<FeaturePackLayout> layout) {
                try {
                    return getFeatureContainer(invoc.getPmSession(), layout);
                } catch (CommandExecutionException | ProvisioningException | IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
        };
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        StateInfoUtil.displayInfo(invoc, mgr.getInstallationHome(), mgr.getProvisioningConfig(), type, supplier);
    } catch (ProvisioningException | CommandExecutionException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.infoFailed(), ex);
    }
}
Also used : Function(java.util.function.Function) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException) ProvisioningLayout(org.jboss.galleon.layout.ProvisioningLayout)

Example 47 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class InstallCommand method getId.

@Override
protected String getId(PmSession session) throws CommandExecutionException {
    String filePath = (String) getValue(FILE_OPTION_NAME);
    if (filePath == null) {
        filePath = getOptionValue(FILE_OPTION_NAME);
        if (filePath == null) {
            return super.getId(session);
        }
    }
    Path path;
    try {
        path = Util.resolvePath(session.getAeshContext(), filePath);
    } catch (IOException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
    if (!Files.exists(path)) {
        return null;
    }
    try {
        return FeaturePackDescriber.readSpec(path).getFPID().toString();
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(session, CliErrors.retrieveFeaturePackID(), ex);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 48 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ListFeaturePacksCommand method runCommand.

@Override
public void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    Map<UniverseSpec, Table> tables = new HashMap<>();
    Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
    // 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;
    UniverseVisitor visitor = new UniverseVisitor() {

        @Override
        public void visit(Producer<?> producer, FeaturePackLocation loc) {
            if (loc.getFrequency() == null) {
                return;
            }
            if (allFrequencies || loc.getFrequency().equals(producer.getDefaultFrequency())) {
                Table table = tables.get(loc.getUniverse());
                if (table == null) {
                    table = new Table(Headers.PRODUCT, Headers.UPDATE_CHANNEL, Headers.LATEST_BUILD);
                    tables.put(loc.getUniverse(), table);
                }
                loc = invoc.getPmSession().getExposedLocation(finalPath, loc);
                table.addLine(producer.getName(), StateInfoUtil.formatChannel(loc), (loc.getBuild() == null ? NONE : loc.getBuild()));
            }
        }

        @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());
        }
    };
    try {
        if (fromUniverse != null) {
            invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
        } else {
            invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.resolvedUniverseFailed(), ex);
    }
    FindCommand.printExceptions(invoc, exceptions);
    for (Entry<UniverseSpec, Table> entry : tables.entrySet()) {
        Table table = entry.getValue();
        table.sort(Table.SortType.ASCENDANT);
        invoc.println(table.build());
    }
}
Also used : Path(java.nio.file.Path) Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) Producer(org.jboss.galleon.universe.Producer) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec) UniverseVisitor(org.jboss.galleon.cli.UniverseManager.UniverseVisitor)

Example 49 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ProvisionCommand method doRunCommand.

@Override
protected void doRunCommand(PmCommandInvocation invoc, Map<String, String> options) throws CommandExecutionException {
    String file = getFile();
    if (file == null) {
        throw new CommandExecutionException("No provisioning file provided.");
    }
    try {
        final Path provisioningFile = getAbsolutePath(file, invoc.getConfiguration().getAeshContext());
        if (!Files.exists(provisioningFile)) {
            throw new CommandExecutionException("Failed to locate provisioning file " + provisioningFile.toAbsolutePath());
        }
        getManager(invoc).provision(provisioningFile, options);
    } catch (ProvisioningException | IOException e) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.provisioningFailed(), e);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 50 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class StateProvisionCommand method doRunCommand.

@Override
protected void doRunCommand(PmCommandInvocation invoc, Map<String, String> options) throws CommandExecutionException {
    State state = invoc.getPmSession().getState();
    try {
        getManager(invoc).provision(state.getConfig(), options);
    } catch (ProvisioningException | IOException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.provisioningFailed(), ex);
    }
    Path home = getInstallationDirectory(invoc.getConfiguration().getAeshContext());
    if (home != null && Files.exists(home)) {
        try {
            invoc.println("Installation done in " + home.toFile().getCanonicalPath());
        } catch (IOException ex) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.retrievePath(), ex);
        }
    } else {
        invoc.println("Nothing to install");
    }
}
Also used : Path(java.nio.file.Path) State(org.jboss.galleon.cli.model.state.State) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Aggregations

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6