Commit 00106ba0 authored by 王业明's avatar 王业明
Browse files

1、BAPIDE适配到1.8

2、BAPIDE支持sftp
3、BAPIDE集成git插件
parent 24329b75
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
*.ftl *.ftl
*.pkc *.pkc
bin/ bin/
.metadata/
...@@ -45,51 +45,51 @@ import cn.com.bankit.ide.bap.preferences.BapPreActivator; ...@@ -45,51 +45,51 @@ import cn.com.bankit.ide.bap.preferences.BapPreActivator;
import cn.com.bankit.ide.bap.preferences.controls.BapBooleanEditField; import cn.com.bankit.ide.bap.preferences.controls.BapBooleanEditField;
/** /**
* <DL> * <DL>
* <DT><B> 标题. </B></DT> * <DT><B> 标题. </B></DT>
* <p> * <p>
* <DD>详细介绍</DD> * <DD>详细介绍</DD>
* </DL> * </DL>
* <p> * <p>
* *
* <DL> * <DL>
* <DT><B>使用范例</B></DT> * <DT><B>使用范例</B></DT>
* <p> * <p>
* <DD>使用范例说明</DD> * <DD>使用范例说明</DD>
* </DL> * </DL>
* <p> * <p>
* *
* @author 朱克平 $Author$ * @author 朱克平 $Author$
* @author 浙江宇信班克信息技术有限公司 * @author 浙江宇信班克信息技术有限公司
* @version $Id$ * @version $Id$
*/ */
public class CGCCompilePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage public class CGCCompilePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
{
BapBooleanEditField filter; BapBooleanEditField filter;
Group filterGroup; Group filterGroup;
StringFieldEditor value; StringFieldEditor value;
public CGCCompilePreferencePage() public CGCCompilePreferencePage() {
{
super(GRID); super(GRID);
setPreferenceStore(BapPreActivator.getDefault().getPreferenceStore()); setPreferenceStore(BapPreActivator.getDefault().getPreferenceStore());
// setDescription(BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_NAME)); // setDescription(BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_NAME));
} }
protected void createFieldEditors() protected void createFieldEditors() {
{ ComboFieldEditor combo = new ComboFieldEditor(IBapConstants.BAP_PREF_CPL_CGC_VER,
ComboFieldEditor combo = new ComboFieldEditor(IBapConstants.BAP_PREF_CPL_CGC_VER, BapResource BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_CGC_VER),
.getPluginResource().getString(BapResource.BAP_PREF_CPL_CGC_VER), new String[][] { new String[][] {
{ BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_CGC_VER_V1_0_0), { BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_CGC_VER_V1_0_0),
IBapConstants.BAP_PREF_CPL_CGC_VER_V1_0_0 }}, getFieldEditorParent()); IBapConstants.BAP_PREF_CPL_CGC_VER_V1_0_0 },
{ BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_CGC_VER_V3_PY3),
IBapConstants.BAP_PREF_CPL_CGC_VER_V3_PY3 } },
getFieldEditorParent());
addField(combo); addField(combo);
addFilter(); addFilter();
// addDescriptor(); // addDescriptor();
} }
private void addFilter() private void addFilter() {
{
filterGroup = new Group(getFieldEditorParent(), SWT.NONE); filterGroup = new Group(getFieldEditorParent(), SWT.NONE);
filterGroup.setText(BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_NAME)); filterGroup.setText(BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_NAME));
filterGroup.setLayout(new FillLayout()); filterGroup.setLayout(new FillLayout());
...@@ -98,53 +98,45 @@ public class CGCCompilePreferencePage extends FieldEditorPreferencePage implemen ...@@ -98,53 +98,45 @@ public class CGCCompilePreferencePage extends FieldEditorPreferencePage implemen
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
filterGroup.setLayoutData(gd); filterGroup.setLayoutData(gd);
filter = new BapBooleanEditField(IBapConstants.BAP_PREF_CPL_FILTER_ENABLE, BapResource.getPluginResource() filter = new BapBooleanEditField(IBapConstants.BAP_PREF_CPL_FILTER_ENABLE,
.getString(BapResource.BAP_PREF_CPL_FILTER_ENABLE), filterGroup); BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_ENABLE), filterGroup);
value = new StringFieldEditor(IBapConstants.BAP_PREF_CPL_FILTER_VALUE, BapResource.getPluginResource() value = new StringFieldEditor(IBapConstants.BAP_PREF_CPL_FILTER_VALUE,
.getString(BapResource.BAP_PREF_CPL_FILTER_VALUE), filterGroup); BapResource.getPluginResource().getString(BapResource.BAP_PREF_CPL_FILTER_VALUE), filterGroup);
addField(filter); addField(filter);
addField(value); addField(value);
final Button button = (Button) filter.getChangeControl(filterGroup); final Button button = (Button) filter.getChangeControl(filterGroup);
button.addSelectionListener(new SelectionListener() button.addSelectionListener(new SelectionListener() {
{
@Override @Override
public void widgetSelected(SelectionEvent e) public void widgetSelected(SelectionEvent e) {
{
boolean bval = button.getSelection(); boolean bval = button.getSelection();
value.setEnabled(bval, filterGroup); value.setEnabled(bval, filterGroup);
} }
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) public void widgetDefaultSelected(SelectionEvent e) {
{
} }
}); });
} }
@Override @Override
public void init(IWorkbench workbench) public void init(IWorkbench workbench) {
{
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
protected void checkState() protected void checkState() {
{
// TODO Auto-generated method stub // TODO Auto-generated method stub
super.checkState(); super.checkState();
IPreferenceStore store = BapPreActivator.getDefault().getPreferenceStore(); IPreferenceStore store = BapPreActivator.getDefault().getPreferenceStore();
if (store.getBoolean(IBapConstants.BAP_PREF_CPL_FILTER_ENABLE)) if (store.getBoolean(IBapConstants.BAP_PREF_CPL_FILTER_ENABLE)) {
{
value.setEnabled(true, filterGroup); value.setEnabled(true, filterGroup);
} } else {
else
{
value.setEnabled(false, filterGroup); value.setEnabled(false, filterGroup);
} }
} }
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
</property> </property>
<property <property
name="aboutText" name="aboutText"
value="业务处理平台基础开发环境(BAP IDE)&#x0A;&#x0A;授权版本: V1.5.0 SMART&#x0A;发布日期: 20140513&#x0A;&#x0A;宇信班克版权所有 ©2011-2014"> value="业务处理平台基础开发环境(BAP IDE)&#x0A;&#x0A;授权版本: V1.5.0&#x0A;发布日期: 20140510&#x0A;&#x0A;宇信班克版权所有 ©2011-2014">
</property> </property>
<property <property
name="startupForegroundColor" name="startupForegroundColor"
...@@ -96,14 +96,14 @@ ...@@ -96,14 +96,14 @@
name="appName" name="appName"
value="Bap IDE"> value="Bap IDE">
</property> </property>
<property
name="preferenceCustomization"
value="plugin_customization.ini">
</property>
<property <property
name="aboutImage" name="aboutImage"
value="icons/splash.png"> value="icons/splash.png">
</property> </property>
<property
name="preferenceCustomization"
value="plugin_customization.ini">
</property>
</product> </product>
</extension> </extension>
<extension <extension
......
...@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui, ...@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.resources;bundle-version="3.7.100", org.eclipse.core.resources;bundle-version="3.7.100",
cn.com.bankit.ide.common.lib;bundle-version="1.0.0", cn.com.bankit.ide.common.lib;bundle-version="1.0.0",
cn.com.bankit.ide.common.resources;bundle-version="1.0.0", cn.com.bankit.ide.common.resources;bundle-version="1.0.0",
org.eclipse.core.filesystem;bundle-version="1.3.100" org.eclipse.core.filesystem;bundle-version="1.3.100",
com.jcraft.jsch;bundle-version="0.1.53"
Bundle-ClassPath: . Bundle-ClassPath: .
Export-Package: cn.com.bankit.ide.common.ftp, Export-Package: cn.com.bankit.ide.common.ftp,
cn.com.bankit.ide.common.ftp.actions, cn.com.bankit.ide.common.ftp.actions,
......
package cn.com.bankit.ide.common.ftp;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Properties;
import java.util.Vector;
public class SSHRemoteCall {
String home = "";
public static final int DEFAULT_PORT = 22;
private Session session;
public String getHome() {
return this.home;
}
public void sshRemoteCallLogin(String ipAddress, String userName, String password, int port) throws Exception {
JSch jSch = new JSch();
try {
this.session = jSch.getSession(userName, ipAddress, port);
this.session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
this.session.setConfig(config);
this.session.connect();
} catch (JSchException e) {
throw new Exception(
"主机登录失败, IP = " + ipAddress + ", USERNAME = " + userName + ", Exception:" + e.getMessage());
}
}
public void closeSession() {
if (this.session == null)
return;
this.session.disconnect();
}
public boolean uploadFile(String directory, File uploadFile, boolean flag) throws Exception {
boolean upload = false;
try {
ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp");
channelSftp.connect();
this.home = channelSftp.pwd();
String[] path = directory.split("/");
for (String p : path) {
if ("".equals(p))
continue;
try {
channelSftp.cd(p);
} catch (SftpException localSftpException) {
channelSftp.mkdir(p);
channelSftp.cd(p);
}
}
if (flag) {
channelSftp.put(new FileInputStream(uploadFile), uploadFile.getName(), 0);
upload = true;
} else {
Vector v = channelSftp.ls(uploadFile.getName());
if (v.isEmpty()) {
channelSftp.put(new FileInputStream(uploadFile), uploadFile.getName(), 0);
upload = true;
}
}
channelSftp.exit();
} catch (Exception e) {
throw e;
}
return upload;
}
public void fileDownload(String src, String dst) throws JSchException, SftpException {
ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp");
channelSftp.connect();
channelSftp.get(src, dst);
channelSftp.quit();
System.out.println("3、" + src + " ,下载文件成功.....");
}
public void deleteFile(String directoryFile) throws SftpException, JSchException {
ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp");
channelSftp.connect();
channelSftp.rm(directoryFile);
channelSftp.exit();
System.out.println("4、" + directoryFile + " 删除的文件.....");
}
public Vector listFiles(String directory) throws JSchException, SftpException {
ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp");
channelSftp.connect();
Vector ls = channelSftp.ls(directory);
System.out.println("5、" + ls);
channelSftp.exit();
return ls;
}
}
\ No newline at end of file
...@@ -51,44 +51,59 @@ import cn.com.bankit.ide.common.ftp.model.UploadModel; ...@@ -51,44 +51,59 @@ import cn.com.bankit.ide.common.ftp.model.UploadModel;
* @author 浙江宇信班克信息技术有限公司 * @author 浙江宇信班克信息技术有限公司
* @version 1.0.0 2012-2-13 上午11:40:59 * @version 1.0.0 2012-2-13 上午11:40:59
*/ */
public class FtpUploadJob extends Job implements IJobChangeListener public class FtpUploadJob extends Job implements IJobChangeListener {
{ protected List<UploadModel> list;
private List<UploadModel> list;
private ConnNode connNode; protected ConnNode connNode;
private FTPClient ftpClient; private FTPClient ftpClient;
// private volatile boolean isOverload = false; // private volatile boolean isOverload = false;
// //
// private volatile boolean isRemeber = false; // private volatile boolean isRemeber = false;
public static final int FTP_DEFAULT_TIMES = 1; public static final int FTP_DEFAULT_TIMES = 1;
public static final int UP_OW = 0;//上传成功,覆盖 public static final int UP_OW = 0;// 上传成功,覆盖
public static final int UP_UN_OW = 1;//文件存在,不覆盖。 public static final int UP_UN_OW = 1;// 文件存在,不覆盖。
public static final int UP_LOAD = 2;//上传成功,覆盖 public static final int UP_LOAD = 2;// 上传成功,覆盖
protected int total;
private int total, upcnt,owcnt, unowcnt; private int upcnt;
private int times = FTP_DEFAULT_TIMES;//默认为1次 private int owcnt;
public FtpUploadJob(String name) private int unowcnt;
{
private int times = FTP_DEFAULT_TIMES;// 默认为1次
public FtpUploadJob(String name) {
super(name); super(name);
} }
public FtpUploadJob(ConnNode connNode, List<UploadModel> list, int times) public FtpUploadJob(ConnNode connNode, List<UploadModel> list, int times) {
{
super(FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_ACTION_UPLOAD)); super(FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_ACTION_UPLOAD));
this.connNode = connNode; this.connNode = connNode;
this.list = list; this.list = list;
this.times = times; this.times = times;
} }
protected void doRun(IProgressMonitor monitor) throws Exception {
if ((this.connNode.getStatus() == 0) || (this.connNode.isModify())) {
this.connNode.aysconnect(false);
Thread.currentThread();
Thread.sleep(100L);
}
this.ftpClient = this.connNode.getFtpClient();
if (this.ftpClient != null)
uploadFile(monitor);
}
@Override @Override
protected IStatus run(IProgressMonitor monitor) protected IStatus run(IProgressMonitor monitor) {
{
monitor.beginTask(FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_OTHER_X_WAIT_MSG), monitor.beginTask(FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_OTHER_X_WAIT_MSG),
IProgressMonitor.UNKNOWN); IProgressMonitor.UNKNOWN);
...@@ -96,10 +111,8 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -96,10 +111,8 @@ public class FtpUploadJob extends Job implements IJobChangeListener
IStatus status = Status.OK_STATUS; IStatus status = Status.OK_STATUS;
total = owcnt = unowcnt = 0; total = owcnt = unowcnt = 0;
while (times > 0) while (times > 0) {
{ try {
try
{
if (null == list || list.size() <= 0) if (null == list || list.size() <= 0)
return status; return status;
...@@ -115,62 +128,54 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -115,62 +128,54 @@ public class FtpUploadJob extends Job implements IJobChangeListener
// } // }
// ftpClient.changeWorkingDirectory(remoteDir); // ftpClient.changeWorkingDirectory(remoteDir);
//ftpClient // ftpClient
try // try {
{ // ftpClient = connNode.getFtpClient();
ftpClient = connNode.getFtpClient(); // if (ftpClient.isAvailable()) {
if (ftpClient.isAvailable()) // connNode.setStatus(ConnNode.DISCONNECT);
{ // }
connNode.setStatus(ConnNode.DISCONNECT); // } catch (Exception e) {
} // e.printStackTrace();
}catch(Exception e) // connNode.setStatus(ConnNode.DISCONNECT);
{ // }
e.printStackTrace(); // if (connNode.getStatus() == ConnNode.DISCONNECT || connNode.isModify())
connNode.setStatus(ConnNode.DISCONNECT); //
} // // ftpClient = connNode.getFtpClient();
if (connNode.getStatus() == ConnNode.DISCONNECT || connNode.isModify()) // // if (null == ftpClient || ftpClient.isConnected())
// {
// ftpClient = connNode.getFtpClient(); // connNode.aysconnect(false);
// if (null == ftpClient || ftpClient.isConnected()) //
{ // Thread.currentThread();
connNode.aysconnect(false); // Thread.sleep(100);
// }
Thread.currentThread(); // ftpClient = connNode.getFtpClient();
Thread.sleep(100); //
} // if (ftpClient != null)
ftpClient = connNode.getFtpClient(); // uploadFile(monitor);
doRun(monitor);
if (ftpClient != null)
uploadFile(monitor);
connNode.setModify(false); connNode.setModify(false);
return status; return status;
} catch (Exception e) } catch (Exception e) {
{
if (status == Status.OK_STATUS) if (status == Status.OK_STATUS)
status = new Status(Status.ERROR, FtpActivator.PLUGIN_ID, status = new Status(Status.ERROR, FtpActivator.PLUGIN_ID,
FtpActivator.getPluginResource().getString( FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_J_D_E_UP_F) + "\n"
FtpConstants.FTP_I18N_J_D_E_UP_F) + e.getMessage());
+ "\n" + e.getMessage());
else else
e.printStackTrace(); e.printStackTrace();
// 服务器断开了传输通道连接, // 服务器断开了传输通道连接,
connNode.disConnect(); connNode.disConnect();
times--; times--;
} finally } finally {
{
monitor.done(); monitor.done();
if (this.total >= 0 && connNode.getStatus() != ConnNode.DISCONNECT) if (this.total >= 0 && connNode.getStatus() != ConnNode.DISCONNECT) {
{ Display.getDefault().asyncExec(new Runnable() {
Display.getDefault().asyncExec(new Runnable()
{
@Override @Override
public void run() public void run() {
{
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(connNode.getLabel()); sb.append(connNode.getLabel());
sb.append("[").append(connNode.getUsername()); sb.append("[").append(connNode.getUsername());
...@@ -180,13 +185,13 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -180,13 +185,13 @@ public class FtpUploadJob extends Job implements IJobChangeListener
sb.append(connNode.getPort()); sb.append(connNode.getPort());
sb.append("]-部署结果"); sb.append("]-部署结果");
MessageDialog.openInformation(new Shell(), sb.toString(), FtpActivator.getPluginResource() MessageDialog
.getString(FtpConstants.FTP_I18N_OTHER_X_TOTAL, new Object[] .openInformation(new Shell(), sb.toString(),
{ FtpActivator.getPluginResource()
FtpUploadJob.this.total, .getString(FtpConstants.FTP_I18N_OTHER_X_TOTAL,
FtpUploadJob.this.upcnt, new Object[] { FtpUploadJob.this.total,
FtpUploadJob.this.owcnt, FtpUploadJob.this.upcnt, FtpUploadJob.this.owcnt,
FtpUploadJob.this.unowcnt})); FtpUploadJob.this.unowcnt }));
// MessageDialog.openConfirm(Display.getDefault().getActiveShell(), // MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
// "ftp", FtpActivator // "ftp", FtpActivator
...@@ -215,21 +220,21 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -215,21 +220,21 @@ public class FtpUploadJob extends Job implements IJobChangeListener
} }
// if (connNode.getStatus() == ConnNode.DISCONNECT) // if (connNode.getStatus() == ConnNode.DISCONNECT)
// Display.getDefault().asyncExec(new Runnable() // Display.getDefault().asyncExec(new Runnable()
// { // {
// @Override // @Override
// public void run() // public void run()
// { // {
// MessageDialog.openError(Display.getDefault().getActiveShell(), "ftp", "服务器断开了连接,请重试"); // MessageDialog.openError(Display.getDefault().getActiveShell(), "ftp",
// } // "服务器断开了连接,请重试");
// }); // }
// });
return status; return status;
} }
private void uploadFile(IProgressMonitor monitor) throws Exception private void uploadFile(IProgressMonitor monitor) throws Exception {
{
if (monitor.isCanceled()) if (monitor.isCanceled())
return; return;
...@@ -242,90 +247,80 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -242,90 +247,80 @@ public class FtpUploadJob extends Job implements IJobChangeListener
int upType = UP_LOAD; int upType = UP_LOAD;
try try {
{ for (UploadModel up : list) {
for (UploadModel up : list)
{
upType = UP_LOAD; upType = UP_LOAD;
try try {
{
String remoteDir = null; String remoteDir = null;
boolean isExist = false; boolean isExist = false;
if (up.isAbsPath()) if (up.isAbsPath())
remoteDir = up.getRemotePath(); remoteDir = up.getRemotePath();
else else {
{
remoteDir = basePath + up.getRemotePath(); remoteDir = basePath + up.getRemotePath();
} }
// 判断上传目录是否为当前ftp目录,否则要cd到那个目录 // 判断上传目录是否为当前ftp目录,否则要cd到那个目录
if (!remoteDir.equals(ftpClient.printWorkingDirectory())) if (!remoteDir.equals(ftpClient.printWorkingDirectory())) {
{
ftpClient.enterLocalPassiveMode(); ftpClient.enterLocalPassiveMode();
// String chgPath = remoteDir.substring(0, remoteDir.lastIndexOf("/")); // String chgPath = remoteDir.substring(0,
// boolean ischg = ftpClient.changeWorkingDirectory(chgPath); // remoteDir.lastIndexOf("/"));
// boolean ischg =
// ftpClient.changeWorkingDirectory(chgPath);
// if (!ischg) // if (!ischg)
// { // {
// throw new RuntimeException(FtpActivator.getPluginResource().getString( // throw new
// FtpConstants.FTP_I18N_OTHER_IO_E_DIR_N) // RuntimeException(FtpActivator.getPluginResource().getString(
// + "\n" + chgPath); // FtpConstants.FTP_I18N_OTHER_IO_E_DIR_N)
// } // + "\n" + chgPath);
// }
// // 判断是否存在目录,如果不存在则创建 // // 判断是否存在目录,如果不存在则创建
// isExist = false; // isExist = false;
// //
// for (FTPFile rf : ftpClient.listFiles()) // for (FTPFile rf : ftpClient.listFiles())
// { // {
// // System.err.println(rf); // // System.err.println(rf);
// if (remoteDir.endsWith(rf.getName())) // if (remoteDir.endsWith(rf.getName()))
// { // {
// isExist = true; // isExist = true;
// } // }
// } // }
// if (!isExist) // if (!isExist)
// { // {
// ftpClient.makeDirectory(remoteDir); // ftpClient.makeDirectory(remoteDir);
// } // }
String dirPath = ""; String dirPath = "";
if (up.isAbsPath()) if (up.isAbsPath()) {
{
dirPath = up.getRemotePath(); dirPath = up.getRemotePath();
ftpClient.changeWorkingDirectory("/"); ftpClient.changeWorkingDirectory("/");
} } else {
else
{
dirPath = up.getRemotePath(); dirPath = up.getRemotePath();
ftpClient.changeWorkingDirectory(basePath); ftpClient.changeWorkingDirectory(basePath);
} }
for (String p : dirPath.split("/")) {
for(String p : dirPath.split("/"))
{
if (p.length() == 0) if (p.length() == 0)
continue; continue;
// System.out.println("path : " + p); // System.out.println("path : " + p);
isExist = ftpClient.changeWorkingDirectory(p); isExist = ftpClient.changeWorkingDirectory(p);
if (!isExist) if (!isExist) {
{ if (!ftpClient.makeDirectory(p)) {
if (!ftpClient.makeDirectory(p))
{
throw new RuntimeException(FtpActivator.getPluginResource().getString( throw new RuntimeException(FtpActivator.getPluginResource()
FtpConstants.FTP_I18N_OTHER_IO_MK_DIR_N) .getString(FtpConstants.FTP_I18N_OTHER_IO_MK_DIR_N) + "\n"
+ "\n" + ftpClient.printWorkingDirectory() + "/" + p); + ftpClient.printWorkingDirectory() + "/" + p);
} }
if (!ftpClient.changeWorkingDirectory(p)) if (!ftpClient.changeWorkingDirectory(p)) {
{ throw new RuntimeException(FtpActivator.getPluginResource()
throw new RuntimeException(FtpActivator.getPluginResource().getString( .getString(FtpConstants.FTP_I18N_OTHER_IO_E_DIR_N) + "\n"
FtpConstants.FTP_I18N_OTHER_IO_E_DIR_N) + ftpClient.printWorkingDirectory() + "/" + p);
+ "\n" + ftpClient.printWorkingDirectory() + "/" + p);
} }
} }
} }
...@@ -336,99 +331,91 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -336,99 +331,91 @@ public class FtpUploadJob extends Job implements IJobChangeListener
// ftpClient.setFileType(FTP.ASCII_FILE_TYPE); // ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
for (final FTPFile rf : ftpClient.listFiles()) {
for (final FTPFile rf : ftpClient.listFiles())
{
final File localFile = up.getLocalJavaFile(); final File localFile = up.getLocalJavaFile();
//如存在并且不覆盖,不上传。 // 如存在并且不覆盖,不上传。
if (rf.getName().equals(localFile.getName()) && !up.isOverWrite()) if (rf.getName().equals(localFile.getName()) && !up.isOverWrite()) {
{
upType = UP_UN_OW; upType = UP_UN_OW;
continue; continue;
} } else if (rf.getName().equals(localFile.getName()) && up.isOverWrite()) {
else if (rf.getName().equals(localFile.getName()) && up.isOverWrite())
{
upType = UP_OW; upType = UP_OW;
break; break;
} }
} }
// 判断是需要覆盖 // 判断是需要覆盖
// if (!isRemeber) // if (!isRemeber)
// { // {
// isOverload = false; // isOverload = false;
// isExist = false; // isExist = false;
// for (final FTPFile rf : ftpClient.listFiles()) // for (final FTPFile rf : ftpClient.listFiles())
// { // {
// final File localFile = up.getLocalJavaFile(); // final File localFile = up.getLocalJavaFile();
// if (rf.getName().equals(localFile.getName())) // if (rf.getName().equals(localFile.getName()))
// { // {
// isExist = true; // isExist = true;
// Display.getDefault().syncExec(new Runnable() // Display.getDefault().syncExec(new Runnable()
// { // {
// //
// @Override // @Override
// public void run() // public void run()
// { // {
// OverwriteDialog dialog = new OverwriteDialog( // OverwriteDialog dialog = new OverwriteDialog(
// Display.getDefault().getShells()[0], FtpActivator.getPluginResource() // Display.getDefault().getShells()[0],
// .getString(FtpConstants.FTP_I18N_ACTION_UPLOAD), localFile, rf); // FtpActivator.getPluginResource()
// // .getString(FtpConstants.FTP_I18N_ACTION_UPLOAD),
// int status = dialog.open(); // localFile, rf);
// isRemeber = dialog.getRemeber(); //
// // int status = dialog.open();
// if (status == IDialogConstants.OK_ID) // isRemeber = dialog.getRemeber();
// isOverload = true; //
// else // if (status == IDialogConstants.OK_ID)
// { // isOverload = true;
// isOverload = false; // else
// } // {
// } // isOverload = false;
// }); // }
// break; // }
// } // });
// } // break;
// }
// }
// 如果记住操作,并且取消上传 // 如果记住操作,并且取消上传
// if (isRemeber && !isOverload) // if (isRemeber && !isOverload)
// return; // return;
// //
// if (isExist && !isOverload) // if (isExist && !isOverload)
// continue; // continue;
// } // }
monitor.beginTask( monitor.beginTask(
FtpActivator.getPluginResource().getString( FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_OTHER_X_NOW,
FtpConstants.FTP_I18N_OTHER_X_NOW, new Object[] {
new Object[] FtpActivator.getPluginResource()
{ FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_ACTION_UPLOAD), .getString(FtpConstants.FTP_I18N_ACTION_UPLOAD),
up.getLocalFile().getFullPath().toString() }), (int) (up.getLocalJavaFile() up.getLocalFile().getFullPath().toString() }),
.length() / 1024)); (int) (up.getLocalJavaFile().length() / 1024));
out = ftpClient.storeFileStream(up.getLocalJavaFile().getName()); out = ftpClient.storeFileStream(up.getLocalJavaFile().getName());
if (out == null) if (out == null) {
{ throw new Exception(
throw new Exception(FtpActivator.getPluginResource().getString( FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_OTHER_IO_E_W));
FtpConstants.FTP_I18N_OTHER_IO_E_W));
} }
in = new FileInputStream(up.getLocalJavaFile()); in = new FileInputStream(up.getLocalJavaFile());
} catch (Exception e) } catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
try try {
{ if (null != out && null != in) {
if (null != out && null != in)
{
byte[] buf = new byte[FtpConstants.FTP_TRANS_PER_SIZE]; byte[] buf = new byte[FtpConstants.FTP_TRANS_PER_SIZE];
int count = 0; int count = 0;
int tail = 0; int tail = 0;
while ((count = in.read(buf)) > 0) while ((count = in.read(buf)) > 0) {
{
out.write(buf, 0, count); out.write(buf, 0, count);
out.flush(); out.flush();
tail += count % 1024; tail += count % 1024;
...@@ -438,39 +425,31 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -438,39 +425,31 @@ public class FtpUploadJob extends Job implements IJobChangeListener
return; return;
} }
} }
} catch (Exception e) } catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} finally } finally {
{ try {
try
{
if (null != in) if (null != in)
in.close(); in.close();
} catch (Exception e) } catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
try try {
{ if (null != out) {
if (null != out)
{
out.close(); out.close();
out = null; out = null;
if (ftpClient.completePendingCommand()) if (ftpClient.completePendingCommand()) {
{ if (upType == UP_OW)
if(upType == UP_OW)
this.owcnt++; this.owcnt++;
else if(upType == UP_LOAD) else if (upType == UP_LOAD)
this.upcnt ++; this.upcnt++;
else else
this.unowcnt ++; this.unowcnt++;
} }
} }
} catch (Exception e) } catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
// try // try
...@@ -488,42 +467,35 @@ public class FtpUploadJob extends Job implements IJobChangeListener ...@@ -488,42 +467,35 @@ public class FtpUploadJob extends Job implements IJobChangeListener
// } // }
} }
} }
} finally } finally {
{
// 变换为原来的目录 // 变换为原来的目录
ftpClient.changeWorkingDirectory(basePath); ftpClient.changeWorkingDirectory(basePath);
} }
} }
@Override @Override
public void aboutToRun(IJobChangeEvent event) public void aboutToRun(IJobChangeEvent event) {
{
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void awake(IJobChangeEvent event) public void awake(IJobChangeEvent event) {
{
} }
@Override @Override
public void done(IJobChangeEvent event) public void done(IJobChangeEvent event) {
{
} }
@Override @Override
public void running(IJobChangeEvent event) public void running(IJobChangeEvent event) {
{
} }
@Override @Override
public void scheduled(IJobChangeEvent event) public void scheduled(IJobChangeEvent event) {
{
} }
@Override @Override
public void sleeping(IJobChangeEvent event) public void sleeping(IJobChangeEvent event) {
{
} }
} }
package cn.com.bankit.ide.common.ftp.jobs;
import cn.com.bankit.ide.common.ftp.FtpActivator;
import cn.com.bankit.ide.common.ftp.FtpConstants;
import cn.com.bankit.ide.common.ftp.SSHRemoteCall;
import cn.com.bankit.ide.common.ftp.console.ConsoleFactory;
import cn.com.bankit.ide.common.ftp.model.ConnNode;
import cn.com.bankit.ide.common.ftp.model.UploadModel;
import cn.com.bankit.ide.common.resources.ResourceProvider;
import java.io.File;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class SFtpUploadJob extends FtpUploadJob {
private SSHRemoteCall ssh;
public SFtpUploadJob(ConnNode connNode, List<UploadModel> list, int times) {
super(connNode, list, times);
this.ssh = new SSHRemoteCall();
ConsoleFactory.regist(connNode);
}
protected void doRun(IProgressMonitor monitor) throws Exception {
uploadFile(monitor);
}
protected void uploadFile(IProgressMonitor monitor) throws Exception {
if (monitor.isCanceled()) {
return;
}
this.ssh.sshRemoteCallLogin(this.connNode.getHost(), this.connNode.getUsername(), this.connNode.getPassword(),
this.connNode.getPort());
this.total = this.list.size();
label244: for (UploadModel up : this.list)
try {
monitor.beginTask(
FtpActivator.getPluginResource()
.getString(FtpConstants.FTP_I18N_OTHER_X_NOW,
new Object[] {
FtpActivator.getPluginResource().getString(FtpConstants.FTP_I18N_ACTION_UPLOAD),
up.getLocalFile().getFullPath().toString() }),
1);
boolean upload = this.ssh.uploadFile(up.getRemotePath(), up.getLocalJavaFile(), up.isOverWrite());
monitor.worked(1);
if (upload) {
this.connNode.setConsoleMessage("文件 " + up.getLocalJavaFile().getAbsolutePath() + "上传到 "
+ this.ssh.getHome() + up.getRemotePath() + "成功");
}
if (!(monitor.isCanceled()))
break label244;
return;
} catch (Exception e) {
this.connNode.setConsoleError(e.getMessage());
throw e;
}
}
}
\ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<classpathentry exported="true" kind="lib" path="lib/wsdl4j-1.6.2.jar"/> <classpathentry exported="true" kind="lib" path="lib/wsdl4j-1.6.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.9.0.jar"/> <classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.9.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/XmlSchema-1.3.2.jar"/> <classpathentry exported="true" kind="lib" path="lib/XmlSchema-1.3.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jsch-0.1.54.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry exported="true" kind="lib" path=""/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
#Mon Sep 01 17:19:01 CST 2008
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.compliance=1.4 org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment