001/* 002 * (C) Copyright 2012-2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * mguillaume, jcarsique 018 */ 019 020package org.nuxeo.launcher.info; 021 022import java.util.ArrayList; 023import java.util.List; 024 025import javax.xml.bind.annotation.XmlAccessType; 026import javax.xml.bind.annotation.XmlAccessorType; 027import javax.xml.bind.annotation.XmlElement; 028import javax.xml.bind.annotation.XmlRootElement; 029 030import org.apache.commons.logging.Log; 031import org.apache.commons.logging.LogFactory; 032 033@XmlAccessorType(XmlAccessType.NONE) 034@XmlRootElement(name = "commands") 035/** 036 * @since 5.6 037 */ 038public class CommandSetInfo { 039 040 static final Log log = LogFactory.getLog(CommandSetInfo.class); 041 042 public CommandSetInfo() { 043 } 044 045 @XmlElement(name = "command") 046 public List<CommandInfo> commands = new ArrayList<>(); 047 048 /** 049 * @param cmdType Command type. See constants in {@link CommandInfo} 050 * @return new {@link CommandInfo} added to commands 051 */ 052 public CommandInfo newCommandInfo(String cmdType) { 053 CommandInfo cmdInfo = new CommandInfo(cmdType); 054 commands.add(cmdInfo); 055 return cmdInfo; 056 } 057 058 /** 059 * Log commands in error 060 * 061 * @since 5.7 062 */ 063 public void log() { 064 log(false); 065 } 066 067 /** 068 * Log full content of the command set (parse commands and their content) 069 * 070 * @since 5.7 071 */ 072 public void log(boolean debug) { 073 if (commands.isEmpty()) { 074 return; 075 } 076 if (debug) { 077 log.debug("\nCommands debug dump:"); 078 } else { 079 log.error("\nFailed commands:"); 080 } 081 for (CommandInfo commandInfo : commands) { 082 commandInfo.log(debug); 083 } 084 } 085}