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
018package org.apache.commons.exec.launcher;
019
020import java.io.IOException;
021import java.util.Map;
022
023import org.apache.commons.exec.CommandLine;
024
025/**
026 * A command launcher that proxies another command launcher. Sub-classes override exec(args, env, workdir)
027 */
028public abstract class CommandLauncherProxy extends CommandLauncherImpl {
029
030    /** The command launcher to use. */
031    private final CommandLauncher launcher;
032
033    /**
034     * Constructs a new instance.
035     *
036     * @param launcher the command launcher to use.
037     */
038    public CommandLauncherProxy(final CommandLauncher launcher) {
039        this.launcher = launcher;
040    }
041
042    /**
043     * Launches the given command in a new process. Delegates this method to the proxied launcher.
044     *
045     * @param cmd the command line to execute as an array of strings.
046     * @param env the environment to set as an array of strings.
047     * @throws IOException forwarded from the exec method of the command launcher.
048     */
049    @Override
050    public Process exec(final CommandLine cmd, final Map<String, String> env) throws IOException {
051        return launcher.exec(cmd, env);
052    }
053}