001/*
002 * (C) Copyright 2006-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 *     Nuxeo - initial API and implementation
016 *
017 */
018
019package org.nuxeo.ecm.platform.commandline.executor.service;
020
021import java.io.Serializable;
022
023import org.apache.commons.lang.builder.ToStringBuilder;
024import org.apache.commons.lang.builder.ToStringStyle;
025import org.apache.commons.lang3.SystemUtils;
026
027import org.nuxeo.common.xmap.annotation.XNode;
028import org.nuxeo.common.xmap.annotation.XObject;
029
030/**
031 * XMap descriptor for a CommandLine.
032 *
033 * @author tiry
034 */
035@XObject("command")
036public class CommandLineDescriptor implements Serializable {
037
038    private static final long serialVersionUID = 1L;
039
040    @XNode("@name")
041    protected String name;
042
043    @XNode("@enabled")
044    protected boolean enabled;
045
046    protected boolean available;
047
048    @XNode("commandLine")
049    protected String command;
050
051    @XNode("parameterString")
052    protected String parameterString = "";
053
054    @XNode("winParameterString")
055    protected String winParameterString;
056
057    @XNode("winCommand")
058    protected String winCommand;
059
060    @XNode("tester")
061    protected String tester;
062
063    @XNode("readOutput")
064    protected boolean readOutput = true;
065
066    @XNode("installationDirective")
067    protected String installationDirective;
068
069    protected String installErrorMessage;
070
071    public String getInstallErrorMessage() {
072        return installErrorMessage;
073    }
074
075    public void setInstallErrorMessage(String installErrorMessage) {
076        this.installErrorMessage = installErrorMessage;
077    }
078
079    public String getName() {
080        if (name == null) {
081            return getCommand();
082        }
083        return name;
084    }
085
086    public boolean isEnabled() {
087        return enabled;
088    }
089
090    public String getCommand() {
091        if (SystemUtils.IS_OS_WINDOWS && winCommand != null) {
092            return winCommand;
093        }
094        return command;
095    }
096
097    public String getInstallationDirective() {
098        return installationDirective;
099    }
100
101    public String getTester() {
102        return tester;
103    }
104
105    public boolean isAvailable() {
106        return available;
107    }
108
109    public void setAvailable(boolean available) {
110        this.available = available;
111    }
112
113    public boolean getReadOutput() {
114        return readOutput;
115    }
116
117    public String getParametersString() {
118        if (SystemUtils.IS_OS_WINDOWS && winParameterString != null) {
119            return winParameterString;
120        }
121        return parameterString;
122    }
123
124    public String getExecutor() {
125        return CommandLineExecutorComponent.DEFAULT_EXECUTOR;
126    }
127
128    @Override
129    public String toString() {
130        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
131    }
132
133}