|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.fr.design.extra.plugindependence; |
|
|
|
package com.fr.design.extra.plugindependence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.design.extra.PluginConstants; |
|
|
|
import com.fr.design.extra.PluginConstants; |
|
|
|
import com.fr.design.extra.PluginHelper; |
|
|
|
import com.fr.design.extra.PluginHelper; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
@ -7,6 +8,8 @@ import com.fr.general.IOUtils; |
|
|
|
import com.fr.general.Inter; |
|
|
|
import com.fr.general.Inter; |
|
|
|
import com.fr.general.SiteCenter; |
|
|
|
import com.fr.general.SiteCenter; |
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
|
|
|
|
import com.fr.plugin.dependence.PluginDependenceException; |
|
|
|
|
|
|
|
import com.fr.plugin.dependence.PluginDependenceUnit; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
|
@ -21,7 +24,8 @@ import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by hufan on 2016/9/5. |
|
|
|
* Created by hufan on 2016/9/5. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -43,8 +47,7 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
|
|
|
|
|
|
|
|
//安装环境相关信息
|
|
|
|
//安装环境相关信息
|
|
|
|
private String currentID; |
|
|
|
private String currentID; |
|
|
|
private String dependenceID; |
|
|
|
private List<PluginDependenceUnit> list = null; |
|
|
|
private String dependenceDir; |
|
|
|
|
|
|
|
//安装结果
|
|
|
|
//安装结果
|
|
|
|
private boolean result = false; |
|
|
|
private boolean result = false; |
|
|
|
//链接服务器的客户端
|
|
|
|
//链接服务器的客户端
|
|
|
@ -54,13 +57,11 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
//文件总长度
|
|
|
|
//文件总长度
|
|
|
|
private int totalSize = 0; |
|
|
|
private int totalSize = 0; |
|
|
|
|
|
|
|
|
|
|
|
public DownLoadDependenceUI(String ID, String dir) { |
|
|
|
public DownLoadDependenceUI() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public DownLoadDependenceUI(String currentID, List<PluginDependenceUnit> list) { |
|
|
|
public DownLoadDependenceUI(String currentID, String dependenceID, String dependenceDir) { |
|
|
|
|
|
|
|
this.currentID = currentID; |
|
|
|
this.currentID = currentID; |
|
|
|
this.dependenceID = dependenceID; |
|
|
|
this.list = list; |
|
|
|
this.dependenceDir = dependenceDir; |
|
|
|
|
|
|
|
this.totalSize = getFileLength(); |
|
|
|
this.totalSize = getFileLength(); |
|
|
|
init(); |
|
|
|
init(); |
|
|
|
} |
|
|
|
} |
|
|
@ -89,7 +90,7 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
timer = new Timer(100, this); |
|
|
|
timer = new Timer(100, this); |
|
|
|
|
|
|
|
|
|
|
|
frame = new JDialog(DesignerContext.getDesignerFrame(), true); |
|
|
|
frame = new JDialog(DesignerContext.getDesignerFrame(), true); |
|
|
|
frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online") + dependenceID); |
|
|
|
frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online")); |
|
|
|
frame.setSize(LOAD_WIDTH, LOAD_HEIGHT); |
|
|
|
frame.setSize(LOAD_WIDTH, LOAD_HEIGHT); |
|
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
|
frame.setLocation(screenSize.width / 2 - LOAD_WIDTH / 2, screenSize.height / 2 - LOAD_HEIGHT / 2); |
|
|
|
frame.setLocation(screenSize.width / 2 - LOAD_WIDTH / 2, screenSize.height / 2 - LOAD_HEIGHT / 2); |
|
|
@ -112,17 +113,29 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
|
|
|
|
|
|
|
|
//是否可以连接服务器
|
|
|
|
//是否可以连接服务器
|
|
|
|
private boolean connectToServer() { |
|
|
|
private boolean connectToServer() { |
|
|
|
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID)); |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
return httpClient.getResponseCode() == HttpURLConnection.HTTP_OK; |
|
|
|
PluginDependenceUnit dependenceUnit = list.get(i); |
|
|
|
|
|
|
|
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceUnit.getDependenceID())); |
|
|
|
|
|
|
|
if (httpClient.getResponseCode() != HttpURLConnection.HTTP_OK){ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取依赖文件大小
|
|
|
|
//获取依赖文件大小
|
|
|
|
private int getFileLength() { |
|
|
|
private int getFileLength(){ |
|
|
|
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID)); |
|
|
|
int size = 0; |
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
return httpClient.getContentLength(); |
|
|
|
PluginDependenceUnit dependenceUnit = list.get(i); |
|
|
|
|
|
|
|
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceUnit.getDependenceID())); |
|
|
|
|
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
|
|
|
|
size += httpClient.getContentLength(); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return -1; |
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//安装
|
|
|
|
//安装
|
|
|
@ -143,7 +156,7 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
try { |
|
|
|
try { |
|
|
|
thread.join(); |
|
|
|
thread.join(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
FRContext.getLogger().error(e.getMessage()); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
//停止时钟
|
|
|
|
//停止时钟
|
|
|
@ -151,55 +164,78 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String downloadPluginDependenceFile() throws Exception { |
|
|
|
/** |
|
|
|
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID)); |
|
|
|
* 下载和安装不分开是因为,本地如果只安装好了一个依赖,下次就不需要重复下载了 |
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
* 如果下载依赖后不安装,则后面的插件会把前面的插件覆盖,故而下载好了一个安装一个 |
|
|
|
InputStream reader = httpClient.getResponseStream(); |
|
|
|
* @return |
|
|
|
String temp = StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE); |
|
|
|
* @throws Exception |
|
|
|
StableUtils.makesureFileExist(new File(temp)); |
|
|
|
*/ |
|
|
|
FileOutputStream writer = new FileOutputStream(temp); |
|
|
|
private void downloadAndInstallPluginDependenceFile() throws Exception { |
|
|
|
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
totalBytesRead = 0; |
|
|
|
int bytesRead = 0; |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
totalBytesRead = 0; |
|
|
|
PluginDependenceUnit dependenceUnit = list.get(i); |
|
|
|
|
|
|
|
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceUnit.getDependenceID())); |
|
|
|
while ((bytesRead = reader.read(buffer)) > 0 && flag) { |
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
writer.write(buffer, 0, bytesRead); |
|
|
|
InputStream reader = httpClient.getResponseStream(); |
|
|
|
buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
String temp = StableUtils.pathJoin(PluginHelper.DEPENDENCE_DOWNLOAD_PATH, PluginHelper.TEMP_FILE); |
|
|
|
totalBytesRead += bytesRead; |
|
|
|
StableUtils.makesureFileExist(new File(temp)); |
|
|
|
} |
|
|
|
FileOutputStream writer = new FileOutputStream(temp); |
|
|
|
reader.close(); |
|
|
|
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
writer.flush(); |
|
|
|
int bytesRead = 0; |
|
|
|
writer.close(); |
|
|
|
while ((bytesRead = reader.read(buffer)) > 0 && flag) { |
|
|
|
|
|
|
|
writer.write(buffer, 0, bytesRead); |
|
|
|
|
|
|
|
buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
|
|
|
|
totalBytesRead += bytesRead; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
reader.close(); |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
|
|
|
|
writer.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下载被取消
|
|
|
|
|
|
|
|
if (flag == false) { |
|
|
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//安装文件
|
|
|
|
|
|
|
|
IOUtils.unzip(new File(temp), FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); |
|
|
|
|
|
|
|
|
|
|
|
//下载被取消
|
|
|
|
} else { |
|
|
|
if (flag == false) { |
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
return StringUtils.EMPTY; |
|
|
|
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
|
|
|
} |
|
|
|
} |
|
|
|
return temp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//所有依赖都正常安装下载完毕,则结果为true
|
|
|
|
|
|
|
|
result = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void installDependenceOnline() { |
|
|
|
public void installDependenceOnline() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
String filePath = downloadPluginDependenceFile(); |
|
|
|
//下载并安装文件
|
|
|
|
if (!StringUtils.EMPTY.equals(filePath)) { |
|
|
|
downloadAndInstallPluginDependenceFile(); |
|
|
|
//安装文件
|
|
|
|
|
|
|
|
installPluginDependenceFile(filePath); |
|
|
|
|
|
|
|
result = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
result = false; |
|
|
|
|
|
|
|
FRContext.getLogger().error(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//安装已经下载好的文件
|
|
|
|
//安装已经下载好的文件,如果是服务文件,则需要复制一份到安装目录下,
|
|
|
|
private void installPluginDependenceFile(String filePath) { |
|
|
|
//以便切换远程时,使用本地的服务
|
|
|
|
IOUtils.unzip(new File(filePath), dependenceDir); |
|
|
|
//如果是服务器环境,则只会安装一份
|
|
|
|
|
|
|
|
private void installPluginDependenceFile(List<String> filePathList){ |
|
|
|
|
|
|
|
if (filePathList.isEmpty()){ |
|
|
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(int i = 0; i < filePathList.size(); i++) { |
|
|
|
|
|
|
|
if (StringUtils.EMPTY.equals(filePathList.get(i))){ |
|
|
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PluginDependenceUnit dependenceUnit = list.get(i); |
|
|
|
|
|
|
|
IOUtils.unzip(new File(filePathList.get(i)), FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); |
|
|
|
|
|
|
|
result = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
@ -214,23 +250,22 @@ public class DownLoadDependenceUI implements ActionListener { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean installOnline() { |
|
|
|
public void installOnline()throws PluginDependenceException { |
|
|
|
int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + currentID + Inter.getLocText("FR-Designer-Need") + " " + dependenceID + " " + Inter.getLocText("FR-Designer-Support") + "," + Inter.getLocText("FR-Designer-Dependence_Need_Install") + " " + dependenceID + " " + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION); |
|
|
|
int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + Inter.getLocText("FR-Designer-Need") + Inter.getLocText("FR-Designer-Dependence") + Inter.getLocText("FR-Designer-Support") + "," + Inter.getLocText("FR-Designer-Dependence_Need_Install") + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION); |
|
|
|
if (choose == 0) {//下载安装
|
|
|
|
if (choose == 0) {//下载安装
|
|
|
|
if (!connectToServer()) { |
|
|
|
if (!connectToServer()) { |
|
|
|
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE); |
|
|
|
//JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE);
|
|
|
|
return false; |
|
|
|
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error")); |
|
|
|
} |
|
|
|
} |
|
|
|
//安装依赖环境
|
|
|
|
//安装依赖环境
|
|
|
|
if (install()) { |
|
|
|
if (install()) { |
|
|
|
JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!"); |
|
|
|
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!"); |
|
|
|
return true; |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE); |
|
|
|
//JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE);
|
|
|
|
return false; |
|
|
|
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
|
|
|
} |
|
|
|
} |
|
|
|
} else {//不安装。无需为用户准备环境
|
|
|
|
}else {//不选择下载,则不安装图标插件
|
|
|
|
return true; |
|
|
|
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|