001/*
002 * (C) Copyright 2012-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     mguillaume, jcarsique
016 */
017
018package org.nuxeo.launcher.info;
019
020import java.util.ArrayList;
021import java.util.List;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlElement;
026import javax.xml.bind.annotation.XmlRootElement;
027
028import org.apache.commons.logging.Log;
029import org.apache.commons.logging.LogFactory;
030
031@XmlAccessorType(XmlAccessType.NONE)
032@XmlRootElement(name = "commands")
033/**
034 * @since 5.6
035 */
036public class CommandSetInfo {
037
038    static final Log log = LogFactory.getLog(CommandSetInfo.class);
039
040    public CommandSetInfo() {
041    }
042
043    @XmlElement(name = "command")
044    public List<CommandInfo> commands = new ArrayList<>();
045
046    /**
047     * @param cmdType Command type. See constants in {@link CommandInfo}
048     * @return new {@link CommandInfo} added to commands
049     */
050    public CommandInfo newCommandInfo(String cmdType) {
051        CommandInfo cmdInfo = new CommandInfo(cmdType);
052        commands.add(cmdInfo);
053        return cmdInfo;
054    }
055
056    /**
057     * Log commands in error
058     *
059     * @since 5.7
060     */
061    public void log() {
062        log(false);
063    }
064
065    /**
066     * Log full content of the command set (parse commands and their content)
067     *
068     * @since 5.7
069     */
070    public void log(boolean debug) {
071        if (commands.isEmpty()) {
072            return;
073        }
074        if (debug) {
075            log.debug("\nCommands debug dump:");
076        } else {
077            log.error("\nFailed commands:");
078        }
079        for (CommandInfo commandInfo : commands) {
080            commandInfo.log(debug);
081        }
082    }
083}