/*
 * Copyright 2011 Andreas Sahlbach
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sahlbach.maven.delivery.exec;

import com.sahlbach.maven.delivery.Exec;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.StringUtils;

import java.util.List;

/**
 * User: Andreas Sahlbach
 * Date: 20.08.11
 * Time: 21:34
 */
public class SshExecutor extends Executor{
    @Override
    public void execute (List<String> commands, String targetPath, Exec exec)
        throws MojoFailureException, MojoExecutionException {
        if (StringUtils.isNotEmpty(exec.getExecutable())) {
            externalExec(commands, targetPath, exec);
        } else {
            internalExec(commands, targetPath, exec);
        }
    }

    private void internalExec (List<String> commands, String targetPath, Exec exec) {
        // TODO: implement

    }

    private void externalExec (List<String> commands, String targetPath, Exec exec) {
        // TODO: implement

    }
}

@@ -637,16 +637,40 @@
 .exec;%0A%0A
+import java.util.List;%0A%0A
 import c
@@ -702,16 +702,16 @@
 y.Exec;%0A
-
 import o
@@ -855,38 +855,228 @@
 gUtils;%0A
-%0A
 import 
-java.util.List
+org.codehaus.plexus.util.cli.CommandLineException;%0Aimport org.codehaus.plexus.util.cli.CommandLineUtils;%0Aimport org.codehaus.plexus.util.cli.Commandline;%0Aimport org.codehaus.plexus.util.cli.DefaultConsumer
 ;%0A%0A/**%0A 
@@ -1745,37 +1745,1440 @@
 ec) 
-%7B%0A        // TODO: implement%0A
+throws MojoExecutionException %7B%0A        for (String commandLine : commands) %7B%0A            try %7B%0A                getLogger().debug(%22Executing %22 + commandLine);%0A                Commandline cmd = new Commandline();%0A%0A                cmd.setExecutable(exec.getExecutable());%0A%0A                if (exec.getPort() != 0) %7B%0A                    cmd.createArg().setValue(%22-p%22);%0A                    cmd.createArg().setValue(Integer.toString(exec.getPort()));%0A                %7D%0A%0A                cmd.createArg().setValue(exec.getUsername()+%22@%22+exec.getServer());%0A                if(targetPath != null) %7B%0A                    cmd.createArg().setValue(%22cd %22);%0A                    cmd.createArg().setValue(targetPath);%0A                    cmd.createArg().setValue(%22;%22);%0A                %7D%0A                cmd.createArg().setValue(commandLine);%0A%0A                getLogger().debug(%22Executing: %22+cmd);%0A                int exitCode = CommandLineUtils.executeCommandLine(cmd, null, new DefaultConsumer(), new DefaultConsumer());%0A%0A                if ( exitCode != 0 ) %7B%0A                    throw new MojoExecutionException( %22Exit code: %22 + exitCode );%0A                %7D%0A                if (getLogger().isDebugEnabled()) %7B%0A                    getLogger().info(%22Executed: %22 + cmd);%0A                %7D%0A%09        %7D%0A%09        catch ( CommandLineException e ) %7B%0A%09            throw new MojoExecutionException( %22Unable to execute command%22, e );%0A            %7D%0A%0A        %7D
 %0A   

work in progress