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.lang.builder.ToStringBuilder;
026import org.apache.commons.lang.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    @XNode("winParameterString")
057    protected String winParameterString;
058
059    @XNode("winCommand")
060    protected String winCommand;
061
062    @XNode("tester")
063    protected String tester;
064
065    @XNode("readOutput")
066    protected boolean readOutput = true;
067
068    @XNode("installationDirective")
069    protected String installationDirective;
070
071    protected String installErrorMessage;
072
073    public String getInstallErrorMessage() {
074        return installErrorMessage;
075    }
076
077    public void setInstallErrorMessage(String installErrorMessage) {
078        this.installErrorMessage = installErrorMessage;
079    }
080
081    public String getName() {
082        if (name == null) {
083            return getCommand();
084        }
085        return name;
086    }
087
088    public boolean isEnabled() {
089        return enabled;
090    }
091
092    public String getCommand() {
093        if (SystemUtils.IS_OS_WINDOWS && winCommand != null) {
094            return winCommand;
095        }
096        return command;
097    }
098
099    public String getInstallationDirective() {
100        return installationDirective;
101    }
102
103    public String getTester() {
104        return tester;
105    }
106
107    public boolean isAvailable() {
108        return available;
109    }
110
111    public void setAvailable(boolean available) {
112        this.available = available;
113    }
114
115    public boolean getReadOutput() {
116        return readOutput;
117    }
118
119    public String getParametersString() {
120        if (SystemUtils.IS_OS_WINDOWS && winParameterString != null) {
121            return winParameterString;
122        }
123        return parameterString;
124    }
125
126    public String getExecutor() {
127        return CommandLineExecutorComponent.DEFAULT_EXECUTOR;
128    }
129
130    @Override
131    public String toString() {
132        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
133    }
134
135}