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