001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.exec; 018 019 import java.io.File; 020 import java.io.InputStream; 021 import java.io.Serializable; 022 import java.util.ArrayList; 023 import java.util.Collections; 024 import java.util.List; 025 026 import static org.apache.camel.util.ObjectHelper.notNull; 027 028 /** 029 * Value object that describes the command to be executed. 030 */ 031 public class ExecCommand implements Serializable { 032 033 private static final long serialVersionUID = 1755094616849607573L; 034 035 /** 036 * @see ExecBinding#EXEC_COMMAND_EXECUTABLE 037 */ 038 private final String executable; 039 040 /** 041 * @see ExecBinding#EXEC_COMMAND_ARGS 042 */ 043 private final List<String> args; 044 045 /** 046 * @see ExecBinding#EXEC_COMMAND_WORKING_DIR 047 */ 048 private final String workingDir; 049 050 /** 051 * @see ExecBinding#EXEC_COMMAND_TIMEOUT 052 */ 053 private final long timeout; 054 055 /** 056 * @see ExecBinding#EXEC_COMMAND_OUT_FILE 057 */ 058 private final File outFile; 059 060 /** 061 * The input of the executable 062 */ 063 private final InputStream input; 064 065 private final boolean useStderrOnEmptyStdout; 066 067 public ExecCommand(String executable, List<String> args, String workingDir, Long timeout, 068 InputStream input, File outFile, boolean useStderrOnEmptyStdout) { 069 notNull(executable, "command executable"); 070 this.executable = executable; 071 this.args = unmodifiableOrEmptyList(args); 072 this.workingDir = workingDir; 073 this.timeout = timeout; 074 this.input = input; 075 this.outFile = outFile; 076 this.useStderrOnEmptyStdout = useStderrOnEmptyStdout; 077 } 078 079 public List<String> getArgs() { 080 return args; 081 } 082 083 public String getExecutable() { 084 return executable; 085 } 086 087 public InputStream getInput() { 088 return input; 089 } 090 091 public File getOutFile() { 092 return outFile; 093 } 094 095 public long getTimeout() { 096 return timeout; 097 } 098 099 public String getWorkingDir() { 100 return workingDir; 101 } 102 103 public boolean isUseStderrOnEmptyStdout() { 104 return useStderrOnEmptyStdout; 105 } 106 107 @Override 108 public String toString() { 109 String dirToPrint = workingDir == null ? "null" : workingDir; 110 String outFileToPrint = outFile == null ? "null" : outFile.getPath(); 111 return "ExecCommand [args=" + args + ", executable=" + executable + ", timeout=" + timeout + ", outFile=" 112 + outFileToPrint + ", workingDir=" + dirToPrint + ", useStderrOnEmptyStdout=" + useStderrOnEmptyStdout + "]"; 113 } 114 115 private <T> List<T> unmodifiableOrEmptyList(List<T> list) { 116 return Collections.unmodifiableList(list == null ? new ArrayList<T>() : list); 117 } 118 119 }