|
public BapSshClient createClient(final BPBuildInfo buildInfo, final boolean connectSftp) {
final JSch ssh = createJSch();
final Session session = createSession(buildInfo, ssh);
final BapSshClient bapClient = new BapSshClient(buildInfo, session, isEffectiveDisableExec());
try {
final BapSshKeyInfo keyInfo = getEffectiveKeyInfo(buildInfo);
final Properties sessionProperties = getSessionProperties();
Properties properties = new Properties();
// 得到jar包所在的路径
String jarPath = BapSshHostConfiguration.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String sep = File.separator;
int lastIndex = jarPath.lastIndexOf(File.separator);
// 读取配置文件
FileInputStream fileInputStream = new FileInputStream(jarPath.substring(0,lastIndex)+ sep +"configure.properties");
properties.load(fileInputStream);
String enableHttpProxy = properties.getProperty("enable_http_proxy");
String proxyServer = properties.getProperty("http_proxy_server");
String proxyPort = properties.getProperty("http_proxy_port");
if (keyInfo.useKey()) {
setKey(buildInfo, ssh, keyInfo);
sessionProperties.put(CONFIG_KEY_PREFERRED_AUTHENTICATIONS, "publickey");
} else {
session.setPassword(Util.fixNull(keyInfo.getPassphrase()));
sessionProperties.put(CONFIG_KEY_PREFERRED_AUTHENTICATIONS, "keyboard-interactive,password");
}
session.setConfig(sessionProperties);
if ("1".equals(enableHttpProxy)){
session.setProxy(new ProxyHTTP(proxyServer,Integer.parseInt(proxyPort)));
}
connect(buildInfo, session);
if (connectSftp) setupSftp(buildInfo, bapClient);
return bapClient;
} catch (IOException ioe) {
bapClient.disconnectQuietly();
throw new BapPublisherException(Messages.exception_failedToCreateClient(ioe.getLocalizedMessage()), ioe);
} catch (RuntimeException re) {
bapClient.disconnectQuietly();
throw re;
}
}
|
|
|