简体   繁体   中英

REXEC Equivalent in Gradle

I'm working on a build that I'm converting from Ant to Gradle. In it, it has to interact with an IBM iSeries system to package a file and then download it back to the machine that does the build (Windows). The FTP part is fine, but where I'm running into problems is the rexec bit.

In Ant, we have the ability to use the rexec task and that works great. However, I don't see an alternative on the Gradle side. Is this something I'm going to have to try and script with Groovy? Or is there some alternative that I'm missing?

If Gradle doesn't offer some functionality, there is usually a plugin for it. Take a look at this Gradle SSH plugin . It offers both password and certificate authentication.

Further research showed that rexec is not SSH. It's a separate remote protocol that's mostly used for interacting with the iSeries.

It turns out what I had to do was write a small program that mimics the functionality of REXEC. It utilizes the IBM JT tools :

package com.myco.mypackage;

import java.beans.PropertyVetoException;
import java.io.IOException;
import com.ibm.as400.access.*;

public class RemoteCommandExecutor {

    private String system;
    private String user;
    private String password;
    private String command;

    public RemoteCommandExecutor(String system, String user, String password, String command) {
        this.system = system;
        this.user = user;
        this.password = password;
        this.command = command;
    }

    public void doCmd (){
        AS400 theSys = new AS400(this.getSystem(), this.getUser(), this.getPassword());
        CommandCall cmd = new CommandCall(theSys);
        try {
            cmd.run(this.getCommand());
             AS400Message[] messageList = cmd.getMessageList();
              for (int i = 0; i < messageList.length; i++) {
                 System.out.println(messageList[i].getText()); 
              }
        } catch (AS400SecurityException 
                | ErrorCompletingRequestException 
                | IOException 
                | InterruptedException
                | PropertyVetoException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        RemoteCommandExecutor exec = new RemoteCommandExecutor(args[0],args[1],args[2], args[3]);
        exec.doCmd();
    }

    /**
     * @return the system
     */
    public String getSystem() {
        return system;
    }

    /**
     * @param system the system to set
     */
    public void setSystem(String system) {
        this.system = system;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the command
     */
    public String getCommand() {
        return command;
    }

    /**
     * @param command the command to set
     */
    public void setCommand(String command) {
        this.command = command;
    }

}

Then from build.gradle, make an exec closure...assumes the jar file's in the project:

exec{
      commandLine "java", "-jar", "RemoteCommandExecutor.jar", project.ext.props.get("system"), project.ext.props.get("user"),project.ext.props.get("password"), project.ext.props.get("command.to.run")
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM