This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new b01e700 BZ-65089 support setting arbitrary configs for JSch Session
b01e700 is described below
commit b01e7008bacb6efbd0d33eb8d27c9343db3def19
Author: Stefan Bodewig <[email protected]>
AuthorDate: Sun Mar 7 10:43:26 2021 +0100
BZ-65089 support setting arbitrary configs for JSch Session
---
WHATSNEW | 5 ++++
manual/Tasks/scp.html | 25 ++++++++++++++++++++
manual/Tasks/sshexec.html | 27 ++++++++++++++++++++++
manual/Tasks/sshsession.html | 25 ++++++++++++++++++++
.../tools/ant/taskdefs/optional/ssh/SSHBase.java | 21 +++++++++++++----
5 files changed, 99 insertions(+), 4 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 35f8ec8..790ac94 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -56,6 +56,11 @@ Other changes:
individually before concatenating them.
Bugzilla Report 64855
+ * the ssh tasks now share a new nested element additionalConfig that
+ can be used to set config values for the jsch Session used by the
+ task.
+ Bugzilla Report 65089
+
Changes from Ant 1.10.8 TO Ant 1.10.9
=====================================
diff --git a/manual/Tasks/scp.html b/manual/Tasks/scp.html
index a9a95a1..e9e4a33 100644
--- a/manual/Tasks/scp.html
+++ b/manual/Tasks/scp.html
@@ -217,6 +217,31 @@ set.</p>
<p>Prior to Ant 1.9.7 only <code><fileset></code> has been supported as
a nested element.</p>
+<h4 id="additionalConfig">additionalConfig</h4>
+
+<p><em>since Ant 1.10.10</em></p>
+
+<p>Adds configuration settings for the JSch Session created that are
+ not directly supported by specific Ant attributes.</p>
+
+<table class="attr">
+ <tr>
+ <th scope="col">Attribute</th>
+ <th scope="col">Description</th>
+ <th scope="col">Required</th>
+ </tr>
+ <tr>
+ <td>key</td>
+ <td>The key of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <td>value</td>
+ <td>The value of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+</table>
+
<h3>Examples</h3>
<p>Copy a single local file to a remote machine:</p>
<pre><scp file="myfile.txt"
todir="user:password@somehost:/home/chuck"/></pre>
diff --git a/manual/Tasks/sshexec.html b/manual/Tasks/sshexec.html
index 6437b46..f0a0e9c 100644
--- a/manual/Tasks/sshexec.html
+++ b/manual/Tasks/sshexec.html
@@ -230,6 +230,33 @@ JSCh earlier than 0.1.28.</p>
</tr>
</table>
+<h3>Parameters specified as nested elements</h3>
+
+<h4 id="additionalConfig">additionalConfig</h4>
+
+<p><em>since Ant 1.10.10</em></p>
+
+<p>Adds configuration settings for the JSch Session created that are
+ not directly supported by specific Ant attributes.</p>
+
+<table class="attr">
+ <tr>
+ <th scope="col">Attribute</th>
+ <th scope="col">Description</th>
+ <th scope="col">Required</th>
+ </tr>
+ <tr>
+ <td>key</td>
+ <td>The key of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <td>value</td>
+ <td>The value of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+</table>
+
<h3>Examples</h3>
<p>Run a command on a remote machine using password authentication</p>
diff --git a/manual/Tasks/sshsession.html b/manual/Tasks/sshsession.html
index 6f557bb..c8cf291 100644
--- a/manual/Tasks/sshsession.html
+++ b/manual/Tasks/sshsession.html
@@ -186,6 +186,31 @@ both sets of tunnels will be established.</p>
</tr>
</table>
+<h4 id="additionalConfig">additionalConfig</h4>
+
+<p><em>since Ant 1.10.10</em></p>
+
+<p>Adds configuration settings for the JSch Session created that are
+ not directly supported by specific Ant attributes.</p>
+
+<table class="attr">
+ <tr>
+ <th scope="col">Attribute</th>
+ <th scope="col">Description</th>
+ <th scope="col">Required</th>
+ </tr>
+ <tr>
+ <td>key</td>
+ <td>The key of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <td>value</td>
+ <td>The value of the configuration setting.</td>
+ <td>Yes</td>
+ </tr>
+</table>
+
<h4 id="Sequential">sequential</h4>
<p>The <code>sequential</code> element is a required parameter. It is a
container for nested Tasks
which are to be executed once the SSH connection is established and all local
and/or remote tunnels
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
index 4987d05..9677901 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
@@ -20,12 +20,15 @@ package org.apache.tools.ant.taskdefs.optional.ssh;
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import com.jcraft.jsch.ConfigRepository;
import com.jcraft.jsch.OpenSSHConfig;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Environment.Variable;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
@@ -50,6 +53,7 @@ public abstract class SSHBase extends Task implements
LogListener {
private String sshConfig;
private int serverAliveCountMax = 3;
private int serverAliveIntervalSeconds = 0;
+ private final Map<String, String> additionalConfig = new HashMap<>();
/**
* Constructor for SSHBase.
@@ -247,6 +251,10 @@ public abstract class SSHBase extends Task implements
LogListener {
return port;
}
+ public void addConfiguredAdditionalConfig(final Variable v) {
+ additionalConfig.put(v.getKey(), v.getValue());
+ }
+
/**
* Initialize the task.
* This initializes the known hosts and sets the default port.
@@ -268,7 +276,7 @@ public abstract class SSHBase extends Task implements
LogListener {
if (!new File(sshConfig).exists()) {
throw new BuildException("The SSH configuration file specified
doesn't exist: " + sshConfig);
}
-
+
log("Loading SSH configuration file " + sshConfig,
Project.MSG_DEBUG);
ConfigRepository.Config config = null;
try {
@@ -276,15 +284,15 @@ public abstract class SSHBase extends Task implements
LogListener {
} catch (IOException e) {
throw new BuildException("Failed to load the SSH configuration
file " + sshConfig, e);
}
-
+
if (config.getHostname() != null) {
host = config.getHostname();
}
-
+
if (userInfo.getName() == null) {
userInfo.setName(config.getUser());
}
-
+
if (userInfo.getKeyfile() == null) {
log("Using SSH key file " + config.getValue("IdentityFile") +
" for host " + host, Project.MSG_INFO);
userInfo.setKeyfile(config.getValue("IdentityFile"));
@@ -332,6 +340,11 @@ public abstract class SSHBase extends Task implements
LogListener {
session.setServerAliveInterval(getServerAliveIntervalSeconds() *
1000);
}
+ additionalConfig.forEach((k,v) -> {
+ log("Setting additional config value " + k, Project.MSG_DEBUG);
+ session.setConfig(k, v);
+ });
+
log("Connecting to " + host + ":" + port);
session.connect();
return session;