forked from fanruan/design
Browse Source
* commit 'd4facae0b3fb887bdceecd552d4680e92200b3b9': (54 commits) merge: ba-9.0 => pf-9.0 fix fix 调试几个设计器插件,挺多地方有缓存需要添加监听的 插件改变时刷新 插件改变时刷新 插件改变时刷新 设计器论坛登陆要先从DesignerEnvManager获取 bug fix:getName有可能是null PMD PMD REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 fix PMD REPORT-2354 将平台的插件管理和设计器的插件管理统一起来 ...master
78 changed files with 2667 additions and 2543 deletions
@ -0,0 +1,15 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/25. |
||||
*/ |
||||
public class PluginConstants { |
||||
public static final int BYTES_NUM = 1024; |
||||
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; |
||||
public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; |
||||
//插件依赖的下载位置
|
||||
public static final String DEPENDENCE_DOWNLOAD_PATH = System.getProperty("user.dir") + "/download/dependence"; |
||||
public static final String TEMP_FILE = "temp.zip"; |
||||
public static final String CONNECTION_404 = "404"; |
||||
|
||||
} |
@ -1,359 +0,0 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.Env; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.extra.plugindependence.DownLoadDependenceUI; |
||||
import com.fr.general.*; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.plugin.Plugin; |
||||
import com.fr.plugin.PluginConfigManager; |
||||
import com.fr.stable.plugin.PluginConstants; |
||||
import com.fr.plugin.PluginLoader; |
||||
import com.fr.plugin.PluginManagerHelper; |
||||
import com.fr.plugin.dependence.PluginDependence; |
||||
import com.fr.plugin.dependence.PluginDependenceException; |
||||
import com.fr.plugin.dependence.PluginDependenceUnit; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.stable.xml.XMLTools; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.*; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URLDecoder; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @date 2015-03-10 |
||||
* @since 8.0 |
||||
*/ |
||||
public class PluginHelper { |
||||
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; |
||||
public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; |
||||
//插件依赖的下载位置
|
||||
public static final String DEPENDENCE_DOWNLOAD_PATH = System.getProperty("user.dir") + "/download/dependence"; |
||||
public static final String TEMP_FILE = "temp.zip"; |
||||
public static final String CONNECTION_404 = "404"; |
||||
|
||||
/** |
||||
* 下载插件 |
||||
* |
||||
* @param id 插件id |
||||
* @param p 下载百分比处理 |
||||
*/ |
||||
public static void downloadPluginFile(String id, String username, String password, Process<Double> p) throws Exception { |
||||
HttpClient httpClient = new HttpClient(getDownloadPath(id, username, password)); |
||||
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
||||
int totalSize = httpClient.getContentLength(); |
||||
InputStream reader = httpClient.getResponseStream(); |
||||
String temp = StableUtils.pathJoin(DOWNLOAD_PATH, TEMP_FILE); |
||||
StableUtils.makesureFileExist(new File(temp)); |
||||
FileOutputStream writer = new FileOutputStream(temp); |
||||
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
int bytesRead = 0; |
||||
int totalBytesRead = 0; |
||||
|
||||
while ((bytesRead = reader.read(buffer)) > 0) { |
||||
writer.write(buffer, 0, bytesRead); |
||||
buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
totalBytesRead += bytesRead; |
||||
p.process(totalBytesRead / (double) totalSize); |
||||
} |
||||
reader.close(); |
||||
writer.flush(); |
||||
writer.close(); |
||||
} else { |
||||
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error")); |
||||
} |
||||
} |
||||
|
||||
private static boolean invalidUser(String id, String username, String password) { |
||||
if (StringUtils.isEmpty(id)) { |
||||
return false; |
||||
} else if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){ |
||||
return false; |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
private static String getDownloadPath(String id, String username, String password) throws Exception { |
||||
HashMap<String, String> map = new HashMap<String, String>(); |
||||
map.put("id", id); |
||||
map.put("username", username); |
||||
map.put("password", password); |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.download"), map); |
||||
String resText = httpClient.getResponseText(); |
||||
String charSet = EncodeConstants.ENCODING_UTF_8; |
||||
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); |
||||
|
||||
return resText; |
||||
} |
||||
|
||||
public static File getDownloadTempFile() { |
||||
return new File(StableUtils.pathJoin(DOWNLOAD_PATH, TEMP_FILE)); |
||||
} |
||||
|
||||
/** |
||||
* 从压缩文件中读取插件信息 |
||||
* |
||||
* @param chosenFile 选择的压缩文件 |
||||
* @return 返回插件对象 |
||||
* @throws Exception 读取插件信息失败则抛出异常 |
||||
*/ |
||||
public static Plugin readPlugin(File chosenFile) throws Exception { |
||||
// 需要先删除临时目录保证加压出来的文件不会和安装失败的文件混合到一起
|
||||
StableUtils.deleteFile(new File(TEMP_PATH)); |
||||
|
||||
IOUtils.unzip(chosenFile, TEMP_PATH); |
||||
File pluginFileDir = getTempPluginFileDirectory(); |
||||
if (pluginFileDir == null) { |
||||
return null; |
||||
} |
||||
Plugin plugin = null; |
||||
if (pluginFileDir.isDirectory()) { |
||||
File[] pluginFiles = pluginFileDir.listFiles(); |
||||
if (ArrayUtils.isNotEmpty(pluginFiles)) { |
||||
for (File f : pluginFiles) { |
||||
if (f.getName().equals("plugin.xml")) { |
||||
plugin = new Plugin(); |
||||
InputStream inputStream = plugin.readEncryptXml(new FileInputStream(f)); |
||||
XMLTools.readInputStreamXML(plugin, inputStream); |
||||
//检查是否需要准备插件依赖环境
|
||||
checkDependenceEnv(plugin); |
||||
if (!plugin.isValidate()) { |
||||
return null; |
||||
} |
||||
inputStream.close(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return plugin; |
||||
} |
||||
|
||||
//将所有未配置好的资源文件依赖准备好
|
||||
private static void checkDependenceEnv(Plugin plugin) throws PluginDependenceException { |
||||
PluginDependence dependence = plugin.getDependence(); |
||||
if (dependence == null) { |
||||
return; |
||||
} |
||||
|
||||
List<PluginDependenceUnit> needInstallDependence = new ArrayList<PluginDependenceUnit>(); |
||||
|
||||
String currentID = dependence.getCurrentPluginID(); |
||||
List<PluginDependenceUnit> list = dependence.getDependPlugins(); |
||||
for (int i = 0; list != null && i < list.size(); i++) { |
||||
PluginDependenceUnit dependenceUnit = list.get(i); |
||||
if (!dependenceUnit.checkFileEnv()) { |
||||
needInstallDependence.add(dependenceUnit); |
||||
} |
||||
} |
||||
|
||||
if (needInstallDependence.isEmpty()) { |
||||
return; |
||||
} |
||||
|
||||
//安装插件依赖
|
||||
installDependenceOnline(currentID, needInstallDependence); |
||||
} |
||||
|
||||
/** |
||||
* 构造一个下载UI |
||||
* |
||||
* @param currentID |
||||
* @param list |
||||
* @throws PluginDependenceException |
||||
*/ |
||||
private static void installDependenceOnline(String currentID, List<PluginDependenceUnit> list) throws PluginDependenceException { |
||||
DownLoadDependenceUI ui = new DownLoadDependenceUI(currentID, list); |
||||
ui.installOnline(); |
||||
} |
||||
|
||||
/** |
||||
* 从选中的压缩文件中安装插件 |
||||
* |
||||
* @param chosenFile 选择的压缩文件 |
||||
* @param after 操作完成事件 |
||||
* @throws Exception 安装失败则抛出异常 |
||||
*/ |
||||
public static void installPluginFromDisk(File chosenFile, After after) throws Exception { |
||||
Plugin plugin = readPlugin(chosenFile); |
||||
installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, after); |
||||
} |
||||
|
||||
/** |
||||
* 从压缩文件中复制Restart*.class和restart.exe到bin目录下 |
||||
* |
||||
* @param file 插件文件 |
||||
* @param plugin 插件 |
||||
* @throws Exception |
||||
*/ |
||||
public static void copyFilesToBinFolder(File file, Plugin plugin) throws Exception { |
||||
File[] pluginFiles = file.listFiles(); |
||||
for (File restartFile : pluginFiles) { |
||||
if (restartFile.getAbsolutePath().endsWith(".class")) { |
||||
String installHome = StableUtils.getInstallHome(); |
||||
IOUtils.copy(restartFile, new File(StableUtils.pathJoin(new String[]{installHome, "bin"}))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 从插件压缩包解压到得临时文件中安装插件 |
||||
* |
||||
* @param env 报表运行环境 |
||||
* @param plugin 插件 |
||||
* @param after 操作完成事件 |
||||
* @throws Exception |
||||
*/ |
||||
public static void installPluginFromUnzippedTempDir(Env env, final Plugin plugin, final After after) throws Exception { |
||||
validPlugin(plugin); |
||||
if (plugin.isValidate()) { |
||||
File file = getTempPluginFileDirectory(); |
||||
env.copyFilesToPluginAndLibFolder(file, plugin); |
||||
copyFilesToBinFolder(file, plugin); |
||||
env.movePluginEmbFile(file, plugin); |
||||
} |
||||
// 删除放解压文件的临时文件夹
|
||||
StableUtils.deleteFile(new File(TEMP_PATH)); |
||||
PluginConfigManager.getProviderInstance().pushNewPlugin(plugin); |
||||
PluginConfigManager.getProviderInstance().syncPluginConfig(); |
||||
new SwingWorker<String, Void>() { |
||||
|
||||
@Override |
||||
protected String doInBackground() throws Exception { |
||||
return sendInstalledPluginInfo(plugin); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
String text = get(); |
||||
FRLogger.getLogger().info("plugin install:" + text); |
||||
} catch (InterruptedException e) { |
||||
FRLogger.getLogger().error(e.getMessage(), e); |
||||
} catch (ExecutionException e) { |
||||
FRLogger.getLogger().error(e.getMessage(), e); |
||||
} |
||||
if (after != null) { |
||||
after.done(); |
||||
} |
||||
} |
||||
}.execute(); |
||||
} |
||||
|
||||
private static void validPlugin(Plugin plugin) throws Exception { |
||||
if (plugin == null) { |
||||
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip_Cannot_Be_Install")); |
||||
} |
||||
if (PluginLoader.getLoader().isInstalled(plugin)) { |
||||
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Has_Been_Installed")); |
||||
} |
||||
if (plugin.checkIfJarExpired()) { |
||||
String jarExpiredInfo = Inter.getLocText(new String[]{"FR-Designer-Plugin_Jar_Expired", ",", "FR-Designer-Plugin_Install_Failed", ",", "FR-Designer-Plugin_Please_Update_Jar", plugin.getRequiredJarTime()}); |
||||
FRLogger.getLogger().error(jarExpiredInfo); |
||||
throw new com.fr.plugin.PluginVerifyException(jarExpiredInfo); |
||||
} |
||||
File fileToCheck = getTempPluginFileDirectory(); |
||||
File oldfile = new File(StableUtils.pathJoin(FRContext.getCurrentEnv().getPath(), ProjectConstants.PLUGINS_NAME, "plugin-" + plugin.getId())); |
||||
if (!PluginManagerHelper.checkLic(plugin, fileToCheck)) { |
||||
if (!PluginManagerHelper.checkLic(plugin, oldfile)) {//安装时,在安装目录下和压缩包里都没有才弹框
|
||||
String checkLicFail = Inter.getLocText("FR-Designer-PluginLicense_Check_Failed"); |
||||
FRLogger.getLogger().error(checkLicFail); |
||||
throw new com.fr.plugin.PluginVerifyException(checkLicFail); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取插件解压的临时文件夹 |
||||
* |
||||
* @return 临时文件 |
||||
*/ |
||||
public static File getTempPluginFileDirectory() { |
||||
File file = new File(TEMP_PATH); |
||||
if (file.isDirectory() && !file.getName().startsWith(".")) { |
||||
File[] files = file.listFiles(); |
||||
if (ArrayUtils.isNotEmpty(files)) { |
||||
for (File f : files) { |
||||
if (foundConfigFile(f)) { |
||||
return f; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static boolean foundConfigFile(File dir) { |
||||
if (!dir.isDirectory()) { |
||||
return false; |
||||
} |
||||
File[] files = dir.listFiles(); |
||||
if (ArrayUtils.isNotEmpty(files)) { |
||||
for (File f : files) { |
||||
if ("plugin.xml".equals(f.getName())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 从运行环境中卸载插件 |
||||
* |
||||
* @param env 报表运行环境 |
||||
* @param plugin 插件 |
||||
* @return 返回没有删除掉的文件的集合 |
||||
* @throws Exception 卸载出错的时候抛出此异常 |
||||
*/ |
||||
public static String[] uninstallPlugin(Env env, Plugin plugin) throws Exception { |
||||
if (plugin == null || env == null) { |
||||
return ArrayUtils.EMPTY_STRING_ARRAY; |
||||
} |
||||
//卸载前监听
|
||||
plugin.preUninstall(); |
||||
PluginLoader.getLoader().deletePlugin(plugin); |
||||
return env.deleteFileFromPluginAndLibFolder(plugin); |
||||
} |
||||
|
||||
/** |
||||
* 比较插件的版本,这里简单的比价字符串,不需要用数字作为标号 |
||||
* 版本号相同也认为是更新 |
||||
* |
||||
* @param plugin 当前的插件 |
||||
* @param oldPlugin 老的插件 |
||||
* @return 当前插件比老的插件版本高则返回true,否则返回false |
||||
*/ |
||||
public static boolean isNewThan(Plugin plugin, Plugin oldPlugin) { |
||||
return ComparatorUtils.compare(plugin.getVersion(), oldPlugin.getVersion()) >= 0; |
||||
} |
||||
|
||||
private static String sendInstalledPluginInfo(final Plugin plugin) { |
||||
if (StableUtils.isDebug()) { |
||||
return "debug status"; |
||||
} |
||||
HashMap<String, String> map = new HashMap<String, String>(); |
||||
map.put("key", DesignerEnvManager.getEnvManager().getActivationKey()); |
||||
map.put("detail", plugin.toJSONObject().toString()); |
||||
map.put("build", GeneralUtils.readBuildNO()); |
||||
//第三个参数encode, nodejs服务器那边如果参数不encode, 带了空格会报错, 直接用urlconnection也是一样, jetty没能还原.
|
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.install"), map, true); |
||||
httpClient.setTimeout(TIME_OUT); |
||||
httpClient.asGet(); |
||||
return httpClient.getResponseText(); |
||||
} |
||||
|
||||
private static final int TIME_OUT = 5000; |
||||
} |
@ -0,0 +1,266 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.extra.exe.callback.*; |
||||
import com.fr.design.extra.exe.extratask.InstallPluginTask; |
||||
import com.fr.design.extra.exe.extratask.UpdatePluginTask; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.bbs.BBSPluginLogin; |
||||
import com.fr.plugin.manage.bbs.BBSUserInfo; |
||||
import com.fr.plugin.manage.control.PluginTaskCallback; |
||||
import com.fr.plugin.view.PluginView; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.io.File; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public class PluginOperateUtils { |
||||
|
||||
public static void installPluginOnline(final String pluginInfo, JSCallback jsCallback) { |
||||
//下载插件
|
||||
if (!BBSPluginLogin.getInstance().hasLogin()) { |
||||
LoginCheckContext.fireLoginCheckListener(); |
||||
} |
||||
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); |
||||
if (BBSPluginLogin.getInstance().hasLogin()) { |
||||
PluginManager.getController().download(pluginMarker, new DownloadCallback(new InstallPluginTask(pluginMarker, jsCallback), jsCallback)); |
||||
} |
||||
} |
||||
|
||||
public static void installPluginFromDisk(File zipFile, JSCallback jsCallback) { |
||||
PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); |
||||
} |
||||
|
||||
public static void updatePluginOnline(List<PluginMarker> pluginMarkerList, JSCallback jsCallback) { |
||||
if (!(BBSPluginLogin.getInstance().hasLogin())) { |
||||
LoginCheckContext.fireLoginCheckListener(); |
||||
} |
||||
if (BBSPluginLogin.getInstance().hasLogin()) { |
||||
for (int i = 0; i < pluginMarkerList.size(); i++) { |
||||
try { |
||||
JSONObject latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID()); |
||||
String latestPluginVersion = (String) latestPluginInfo.get("version"); |
||||
PluginMarker pluginMarker = pluginMarkerList.get(i); |
||||
PluginMarker toPluginMarker = PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion); |
||||
PluginManager.getController().download(pluginMarkerList.get(i), new DownloadCallback(new UpdatePluginTask(pluginMarker, toPluginMarker, jsCallback), jsCallback)); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void updatePluginFromDisk(final String filePath, JSCallback jsCallback) { |
||||
PluginManager.getController().update(new File(filePath), new UpdateFromDiskCallback(new File(filePath), jsCallback)); |
||||
} |
||||
|
||||
public static void setPluginActive(String pluginInfo, JSCallback jsCallback) { |
||||
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); |
||||
PluginContext plugin = PluginManager.getContext(pluginMarker); |
||||
boolean active = plugin.isActive(); |
||||
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active, jsCallback); |
||||
if (active) { |
||||
PluginManager.getController().forbid(pluginMarker, modifyStatusCallback); |
||||
} else { |
||||
PluginManager.getController().enable(pluginMarker, modifyStatusCallback); |
||||
} |
||||
} |
||||
|
||||
public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) { |
||||
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); |
||||
PluginManager.getController().uninstall(pluginMarker, isForce, new UninstallPluginCallback(pluginMarker, jsCallback)); |
||||
} |
||||
|
||||
public static void readUpdateOnline(JSCallback jsCallback) { |
||||
|
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
try { |
||||
List<PluginView> plugins = PluginsReaderFromStore.readPluginsForUpdate(); |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (PluginView plugin : plugins) { |
||||
org.json.JSONObject jsonObject = new org.json.JSONObject(); |
||||
jsonObject.put("pluginid", plugin.getID()); |
||||
jsonArray.put(jsonObject); |
||||
} |
||||
String result = jsonArray.toString(); |
||||
jsCallback.execute(result); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
}).start(); |
||||
|
||||
|
||||
} |
||||
|
||||
public static void searchPlugin(String keyword, JSCallback jsCallback) { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
try { |
||||
if (StringUtils.isBlank(keyword)) { |
||||
getRecommendPlugins(jsCallback); |
||||
return; |
||||
} |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("shop.plugin.store") + "&keyword=" + keyword); |
||||
httpClient.asGet(); |
||||
String result = httpClient.getResponseText(); |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("result"); |
||||
jsCallback.execute(jsonArray.toString()); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
}).start(); |
||||
|
||||
} |
||||
|
||||
public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback) { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("shop.plugin.plist") + "?"; |
||||
boolean getRecommend = StringUtils.isEmpty(category) && StringUtils.isEmpty(seller) && StringUtils.isEmpty(fee); |
||||
if (getRecommend) { |
||||
getRecommendPlugins(jsCallback); |
||||
return; |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(plistUrl)) { |
||||
StringBuilder url = new StringBuilder(); |
||||
url.append(plistUrl); |
||||
dealParams(url, category, seller, fee); |
||||
try { |
||||
HttpClient httpClient = new HttpClient(url.toString()); |
||||
httpClient.asGet(); |
||||
String result = httpClient.getResponseText(); |
||||
JSONObject resultJSONObject = new JSONObject(result); |
||||
JSONArray resultArr = resultJSONObject.getJSONArray("result"); |
||||
jsCallback.execute(resultArr.toString()); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} else { |
||||
String result = PluginConstants.CONNECTION_404; |
||||
jsCallback.execute(result); |
||||
} |
||||
} |
||||
|
||||
}).start(); |
||||
|
||||
} |
||||
|
||||
public static void getRecommendPlugins(JSCallback jsCallback) { |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("shop.plugin.feature"); |
||||
try { |
||||
HttpClient httpClient = new HttpClient(plistUrl.toString()); |
||||
String result = httpClient.getResponseText(); |
||||
jsCallback.execute(result); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
|
||||
} |
||||
|
||||
public static void dealParams(StringBuilder url, String category, String seller, String fee) { |
||||
if (StringUtils.isNotBlank(category)) { |
||||
url.append("cid=").append(category.split("-")[1]); |
||||
} else { |
||||
url.append("cid=").append(""); |
||||
} |
||||
if (StringUtils.isNotBlank(seller)) { |
||||
switch (seller.split("-")[1]) { |
||||
case "finereport": |
||||
url.append("&seller=").append(1); |
||||
break; |
||||
case "developer": |
||||
url.append("&seller=").append(2); |
||||
break; |
||||
default: |
||||
url.append("&seller=").append(""); |
||||
} |
||||
} |
||||
if (StringUtils.isNotBlank(fee)) { |
||||
switch (fee.split("-")[1]) { |
||||
case "free": |
||||
url.append("&fee=").append(1); |
||||
break; |
||||
case "charge": |
||||
url.append("&fee=").append(2); |
||||
break; |
||||
default: |
||||
url.append("&fee=").append(""); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void getPluginCategories(JSCallback jsCallback) { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
String result; |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("shop.plugin.category"); |
||||
if (url != null) { |
||||
HttpClient httpClient = new HttpClient(url); |
||||
result = httpClient.getResponseText(); |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
jsCallback.execute(result); |
||||
} |
||||
}).start(); |
||||
} |
||||
|
||||
public static void getPluginPrefix(JSCallback jsCallback) { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
String result = SiteCenter.getInstance().acquireUrlByKind("plugin.url.prefix"); |
||||
jsCallback.execute(result); |
||||
} |
||||
}).start(); |
||||
} |
||||
|
||||
public static void getLoginInfo(JSCallback jsCallback) { |
||||
|
||||
if (!BBSPluginLogin.getInstance().hasLogin()) { |
||||
String userName = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); |
||||
if (StringUtils.isNotBlank(userName)) { |
||||
BBSPluginLogin.getInstance().login(new BBSUserInfo(userName, password)); |
||||
} |
||||
} |
||||
BBSUserInfo bbsUserInfo = BBSPluginLogin.getInstance().getUserInfo(); |
||||
String username = bbsUserInfo == null ? "" : bbsUserInfo.getUserName(); |
||||
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); |
||||
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { |
||||
return; |
||||
} else { |
||||
String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; |
||||
jsCallback.execute(result); |
||||
} |
||||
} |
||||
|
||||
public static boolean pluginValidate(PluginView pluginView) { |
||||
return StringUtils.isNotEmpty(pluginView.getID()) |
||||
&& StringUtils.isNotEmpty(pluginView.getName()) |
||||
&& StringUtils.isNotEmpty(pluginView.getVersion()) |
||||
&& StringUtils.isNotEmpty(pluginView.getEnvVersion()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,161 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
|
||||
import com.fr.plugin.view.PluginView; |
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URLDecoder; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/25. |
||||
*/ |
||||
public class PluginUtils { |
||||
|
||||
|
||||
public static PluginMarker createPluginMarker(String pluginInfo) { |
||||
//todo 判空
|
||||
String[] plugin = pluginInfo.split("_"); |
||||
PluginMarker pluginMarker = PluginMarker.create(plugin[0], plugin[1]); |
||||
return pluginMarker; |
||||
} |
||||
|
||||
public static JSONObject getLatestPluginInfo(String pluginID) throws Exception { |
||||
String result = ""; |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.searchAPI"); |
||||
if (StringUtils.isNotEmpty(plistUrl)) { |
||||
StringBuilder url = new StringBuilder(plistUrl); |
||||
if (StringUtils.isNotBlank(pluginID)) { |
||||
url.append("?keyword=").append(pluginID); |
||||
} |
||||
try { |
||||
HttpClient httpClient = new HttpClient(url.toString()); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
JSONObject resultJSONObject = new JSONObject(result); |
||||
JSONArray resultArr = resultJSONObject.getJSONArray("result"); |
||||
JSONObject latestPluginInfo = JSONObject.create(); |
||||
latestPluginInfo = (JSONObject) resultArr.get(0); |
||||
return latestPluginInfo; |
||||
} |
||||
|
||||
public static String transPluginsToString(List<PluginContext> plugins) throws Exception { |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (PluginContext plugin : plugins) { |
||||
JSONObject jo = new JSONObject(); |
||||
jo.put("id", plugin.getID()); |
||||
jo.put("version", plugin.getVersion()); |
||||
jsonArray.put(jo); |
||||
} |
||||
return jsonArray.toString(); |
||||
} |
||||
|
||||
public static void downloadShopScripts(String id, String username, String password, Process<Double> p) throws Exception { |
||||
HttpClient httpClient = new HttpClient(getDownloadPath(id, username, password)); |
||||
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
||||
int totalSize = httpClient.getContentLength(); |
||||
InputStream reader = httpClient.getResponseStream(); |
||||
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); |
||||
StableUtils.makesureFileExist(new File(temp)); |
||||
FileOutputStream writer = new FileOutputStream(temp); |
||||
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
int bytesRead = 0; |
||||
int totalBytesRead = 0; |
||||
|
||||
while ((bytesRead = reader.read(buffer)) > 0) { |
||||
writer.write(buffer, 0, bytesRead); |
||||
buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
totalBytesRead += bytesRead; |
||||
p.process(totalBytesRead / (double) totalSize); |
||||
} |
||||
reader.close(); |
||||
writer.flush(); |
||||
writer.close(); |
||||
} else { |
||||
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error")); |
||||
} |
||||
} |
||||
|
||||
private static String getDownloadPath(String id, String username, String password) throws Exception { |
||||
HashMap<String, String> map = new HashMap<String, String>(); |
||||
map.put("id", id); |
||||
map.put("username", username); |
||||
map.put("password", password); |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.download"), map); |
||||
String resText = httpClient.getResponseText(); |
||||
String charSet = EncodeConstants.ENCODING_UTF_8; |
||||
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); |
||||
|
||||
return resText; |
||||
} |
||||
|
||||
public static boolean isPluginMatch(PluginView pluginView, String text) { |
||||
return StringUtils.contains(pluginView.getID(), text) |
||||
|| StringUtils.contains(pluginView.getName(), text) |
||||
|| StringUtils.contains(pluginView.getVersion(), text) |
||||
|| StringUtils.contains(pluginView.getEnvVersion(), text) |
||||
|| StringUtils.contains(pluginView.getVendor(), text) |
||||
|| StringUtils.contains(pluginView.getDescription(), text) |
||||
|| StringUtils.contains(pluginView.getChangeNotes(), text); |
||||
|
||||
} |
||||
|
||||
public static String pluginToHtml(PluginView pluginView) { |
||||
String pluginName = Inter.getLocText("FR-Plugin-Plugin_Name"); |
||||
String pluginVersion = Inter.getLocText("FR-Plugin-Plugin_Version"); |
||||
String startVersion = Inter.getLocText("FR-Plugin-Start_Version"); |
||||
String developer = Inter.getLocText("FR-Plugin_Developer"); |
||||
String desc = Inter.getLocText("FR-Plugin-Function_Description"); |
||||
String updateLog = Inter.getLocText("FR-Plugin-Update_Log"); |
||||
Map<String, String> map = new HashMap<String, String>(); |
||||
|
||||
map.put("name", pluginName); |
||||
map.put("name_value", pluginView.getName()); |
||||
|
||||
map.put("version", pluginVersion); |
||||
map.put("version_value", pluginView.getVersion()); |
||||
|
||||
map.put("env", startVersion); |
||||
map.put("env_value", pluginView.getEnvVersion()); |
||||
|
||||
map.put("dev", developer); |
||||
map.put("dev_value", pluginView.getVendor()); |
||||
|
||||
map.put("fun", desc); |
||||
map.put("fun_value", pluginView.getDescription()); |
||||
|
||||
map.put("update", updateLog); |
||||
map.put("update_value", pluginView.getDescription()); |
||||
|
||||
try { |
||||
return TemplateUtils.renderTemplate("/com/fr/plugin/plugin.html", map); |
||||
} catch (IOException e) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,39 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by lp on 2016/8/16. |
||||
*/ |
||||
public class GetLoginInfoExecutor implements Executor { |
||||
private String result = "[]"; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); |
||||
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { |
||||
}else { |
||||
result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,42 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
|
||||
/** |
||||
* Created by vito on 16/5/16. |
||||
*/ |
||||
public class GetPluginCategoriesExecutor implements Executor { |
||||
private String result = "[]"; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); |
||||
if (url != null) { |
||||
HttpClient httpClient = new HttpClient(url); |
||||
result = httpClient.getResponseText(); |
||||
} else { |
||||
result = PluginHelper.CONNECTION_404; |
||||
} |
||||
|
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,68 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/18. |
||||
* 获取插件分类信息 |
||||
*/ |
||||
public class GetPluginFromStoreExecutor implements Executor { |
||||
private String result = "[]"; |
||||
private String category; |
||||
private String seller; |
||||
private String fee; |
||||
|
||||
public GetPluginFromStoreExecutor(String category, String seller, String fee) { |
||||
this.category = category; |
||||
this.seller = seller; |
||||
this.fee = fee; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); |
||||
if (StringUtils.isNotBlank(plistUrl)) { |
||||
StringBuilder url = new StringBuilder(); |
||||
url.append(plistUrl); |
||||
if (StringUtils.isNotBlank(category)) { |
||||
url.append("&cid=").append(category.split("-")[1]); |
||||
} |
||||
if (StringUtils.isNotBlank(seller)) { |
||||
url.append("&seller=").append(seller.split("-")[1]); |
||||
} |
||||
if (StringUtils.isNotBlank(fee)) { |
||||
url.append("&fee=").append(fee.split("-")[1]); |
||||
} |
||||
try { |
||||
HttpClient httpClient = new HttpClient(url.toString()); |
||||
result = httpClient.getResponseText(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} else { |
||||
result = PluginHelper.CONNECTION_404; |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,69 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.After; |
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.PluginWebBridge; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.PluginVerifyException; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class InstallFromDiskExecutor implements Executor { |
||||
private String filePath; |
||||
|
||||
public InstallFromDiskExecutor(String filePath) { |
||||
this.filePath = filePath; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return "已成功安装"; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return "正在解压文件" + filePath; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<java.lang.String> process) { |
||||
|
||||
} |
||||
}, |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return "正在安装"; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
PluginHelper.installPluginFromDisk(new File(filePath), new After() { |
||||
@Override |
||||
public void done() { |
||||
FRLogger.getLogger().info("插件安装成功"); |
||||
PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful")); |
||||
} |
||||
}); |
||||
} catch (PluginVerifyException e) { |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,104 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.RestartHelper; |
||||
import com.fr.design.extra.After; |
||||
import com.fr.design.extra.LoginCheckContext; |
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.PluginVerifyException; |
||||
import com.fr.plugin.dependence.PluginDependenceException; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class InstallOnlineExecutor implements Executor { |
||||
|
||||
private String pluginID; |
||||
|
||||
public InstallOnlineExecutor(String pluginID) { |
||||
this.pluginID = pluginID; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return "task succeed"; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return "正在下载插件:" + pluginID; |
||||
} |
||||
|
||||
@Override |
||||
public void run(final Process<String> process) { |
||||
//下载插件
|
||||
if(StringUtils.isBlank(DesignerEnvManager.getEnvManager().getBBSName())){ |
||||
LoginCheckContext.fireLoginCheckListener(); |
||||
} |
||||
if(StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) { |
||||
String username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); |
||||
try { |
||||
PluginHelper.downloadPluginFile(pluginID, username, password, new Process<Double>() { |
||||
@Override |
||||
public void process(Double integer) { |
||||
process.process(Math.round(integer * 100) + "%"); |
||||
} |
||||
}); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return "正在安装插件:" + pluginID; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { |
||||
@Override |
||||
public void done() { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Install_Successful"), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.OK_OPTION) { |
||||
RestartHelper.restart(); |
||||
} |
||||
} |
||||
}); |
||||
} catch (PluginVerifyException e) { |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} catch (PluginDependenceException e){ |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} catch (InterruptedException e) { |
||||
e.printStackTrace(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,53 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.extra.PluginWebBridge; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.Plugin; |
||||
import com.fr.plugin.PluginLoader; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class ModifyStatusExecutor implements Executor { |
||||
|
||||
private String pluginID; |
||||
private boolean active; |
||||
private Plugin plugin; |
||||
|
||||
public ModifyStatusExecutor(String pluginID) { |
||||
this.pluginID = pluginID; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"); |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
plugin = PluginLoader.getLoader().getPluginById(pluginID); |
||||
active = !plugin.isActive(); |
||||
plugin.setActive(active); |
||||
try { |
||||
FRContext.getCurrentEnv().writePlugin(plugin); |
||||
PluginWebBridge.getHelper().showRestartMessage(plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled")); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,49 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.LoginWebBridge; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
|
||||
/** |
||||
* Created by Slpire on 2016/11/7. |
||||
*/ |
||||
public class PluginLoginExecutor implements Executor { |
||||
|
||||
private String result = "[]"; |
||||
|
||||
private String username; |
||||
private String password; |
||||
private UILabel uiLabel; |
||||
|
||||
public PluginLoginExecutor(String username, String password, UILabel uiLabel) { |
||||
this.username = username; |
||||
this.password = password; |
||||
this.uiLabel = uiLabel; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[] { |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String loginResult = LoginWebBridge.getHelper().login(username, password, uiLabel); |
||||
if (Integer.valueOf(loginResult) == 0) { |
||||
LoginWebBridge.getHelper().updateMessageCount(); |
||||
} |
||||
result = loginResult; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,51 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginsReaderFromStore; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
|
||||
import com.fr.plugin.Plugin; |
||||
import com.fr.stable.StringUtils; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/19. |
||||
*/ |
||||
public class ReadUpdateOnlineExecutor implements Executor { |
||||
private Plugin[] plugins; |
||||
private String result; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
plugins = PluginsReaderFromStore.readPluginsForUpdate(); |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (Plugin plugin : plugins) { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("pluginid", plugin.getId()); |
||||
jsonArray.put(jsonObject); |
||||
} |
||||
result = jsonArray.toString(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,47 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by vito on 16/4/18. |
||||
*/ |
||||
public class SearchOnlineExecutor implements Executor { |
||||
private String result; |
||||
private String keyword; |
||||
|
||||
public SearchOnlineExecutor(String keyword) { |
||||
this.keyword = keyword; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
try { |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword); |
||||
result = httpClient.getResponseText(); |
||||
|
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,74 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.RestartHelper; |
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.Plugin; |
||||
import com.fr.plugin.PluginLoader; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class UninstallExecutor implements Executor { |
||||
|
||||
private String[] pluginIDs; |
||||
private String result = "undo"; |
||||
|
||||
public UninstallExecutor(String[] pluginIDs) { |
||||
this.pluginIDs = pluginIDs; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), |
||||
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later"), |
||||
Inter.getLocText("FR-Designer-Basic_Cancel") |
||||
}, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
for (String pluginID : pluginIDs) { |
||||
try { |
||||
Plugin plugin = PluginLoader.getLoader().getPluginById(pluginID); |
||||
String[] filesToBeDelete = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), plugin); |
||||
RestartHelper.saveFilesWhichToDelete(filesToBeDelete); |
||||
} catch (Exception e) { |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
result = "done"; |
||||
if (rv == JOptionPane.OK_OPTION) { |
||||
RestartHelper.restart(); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,40 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.extra.PluginWebBridge; |
||||
import com.fr.design.extra.Process; |
||||
|
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class UpdateFromDiskExecutor implements Executor { |
||||
|
||||
private String filePath; |
||||
|
||||
public UpdateFromDiskExecutor(String filePath) { |
||||
this.filePath = filePath; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return "插件更新操作结束"; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath)); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -1,116 +0,0 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.RestartHelper; |
||||
import com.fr.design.extra.After; |
||||
import com.fr.design.extra.LoginCheckContext; |
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.extra.Process; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.Plugin; |
||||
import com.fr.plugin.PluginLoader; |
||||
import com.fr.plugin.PluginVerifyException; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by richie on 16/3/19. |
||||
*/ |
||||
public class UpdateOnlineExecutor implements Executor { |
||||
|
||||
private String[] pluginIDs; |
||||
private static final int PERCENT_100 = 100; |
||||
|
||||
public UpdateOnlineExecutor(String[] pluginIDs) { |
||||
this.pluginIDs = pluginIDs; |
||||
} |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return "task succeed"; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
if (StringUtils.isBlank(DesignerEnvManager.getEnvManager().getBBSName())) { |
||||
LoginCheckContext.fireLoginCheckListener(); |
||||
} |
||||
if (StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) { |
||||
try { |
||||
for (int i = 0; i < pluginIDs.length; i++) { |
||||
try { |
||||
Plugin plugin = PluginLoader.getLoader().getPluginById(pluginIDs[i]); |
||||
String id = null; |
||||
if (plugin != null) { |
||||
id = plugin.getId(); |
||||
} |
||||
String username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); |
||||
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() { |
||||
@Override |
||||
public void process(Double integer) { |
||||
} |
||||
}); |
||||
updateFileFromDisk(PluginHelper.getDownloadTempFile()); |
||||
process.process(PERCENT_100 / pluginIDs.length * (i + 1) + "%"); |
||||
} catch (PluginVerifyException e) { |
||||
throw e; |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Update_Successful"), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), |
||||
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later") |
||||
}, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.OK_OPTION) { |
||||
RestartHelper.restart(); |
||||
} |
||||
} catch (PluginVerifyException e) { |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
private void updateFileFromDisk(File fileOnDisk) throws Exception { |
||||
Plugin plugin = PluginHelper.readPlugin(fileOnDisk); |
||||
if (plugin == null) { |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
return; |
||||
} |
||||
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId()); |
||||
if (oldPlugin != null) { |
||||
String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin); |
||||
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() { |
||||
@Override |
||||
public void done() { |
||||
} |
||||
}); |
||||
} else { |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.manage.control.ProgressCallback; |
||||
|
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public abstract class AbstractPluginTaskCallback implements ProgressCallback{ |
||||
|
||||
protected PluginMarker pluginMarker; |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.design.extra.exe.extratask.ExtraPluginTask; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public class DownloadCallback extends AbstractPluginTaskCallback { |
||||
private ExtraPluginTask extraPluginTask; |
||||
private JSCallback jsCallback; |
||||
private static int HUNDRED_PERCENT = 100; |
||||
|
||||
public DownloadCallback(final ExtraPluginTask extraPluginTask, final JSCallback jsCallback) { |
||||
this.extraPluginTask = extraPluginTask; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); |
||||
} |
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
if (result.isSuccess()) { |
||||
extraPluginTask.doExtraPluginTask(); |
||||
} else { |
||||
jsCallback.execute("failed"); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public class InstallFromDiskCallback extends AbstractPluginTaskCallback { |
||||
private File zipFile; |
||||
private JSCallback jsCallback; |
||||
private static int HUNDRED_PERCENT = 100; |
||||
|
||||
public InstallFromDiskCallback(final File zipFile, final JSCallback jsCallback) { |
||||
this.zipFile = zipFile; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
jsCallback.execute("success"); |
||||
if (result.isSuccess()) { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Success")); |
||||
} else if (result.errorCode() == PluginErrorCode.NeedInstallInterPluginDependency) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public class InstallOnlineCallback extends AbstractPluginTaskCallback { |
||||
protected JSCallback jsCallback; |
||||
private static int HUNDRED_PERCENT = 100; |
||||
|
||||
public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){ |
||||
this.pluginMarker = pluginMarker; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
jsCallback.execute("success"); |
||||
if (result.isSuccess()) { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Success")); |
||||
} else if (result.errorCode() == PluginErrorCode.NeedInstallInterPluginDependency) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
//执行JS回调
|
||||
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
import javafx.application.Platform; |
||||
import javafx.beans.value.ChangeListener; |
||||
import javafx.beans.value.ObservableValue; |
||||
import javafx.concurrent.Task; |
||||
import javafx.scene.web.WebEngine; |
||||
import netscape.javascript.JSObject; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class JSCallback<T> extends Task<T> { |
||||
|
||||
|
||||
public JSCallback(final WebEngine webEngine, final JSObject callback) { |
||||
init(webEngine, callback); |
||||
} |
||||
|
||||
public void init(final WebEngine webEngine, final JSObject callback){ |
||||
messageProperty().addListener(new ChangeListener<String>() { |
||||
@Override |
||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { |
||||
Platform.runLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; |
||||
try { |
||||
webEngine.executeScript(fun); |
||||
} catch (Exception e) { |
||||
webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
@Override |
||||
protected T call() throws Exception { |
||||
return null; |
||||
} |
||||
|
||||
public void execute(String newValue) { |
||||
updateMessage(newValue); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")") |
||||
* 执行脚本,所以原来规范的json格式也会在拼接字符串后可能抛出参数异常,需要转换掉一些会造成错误的特殊字符, |
||||
* 选择在java端替换的原因是异常抛出自executeScript方法的参数. |
||||
* <p> |
||||
* 1.""中的""必须转义 |
||||
* 2.js字符串中的\n会导致js字符串变成多行,而js字符串不支持多行拼接 |
||||
* 3.由JSONObject.toString()得到的字符串中html标签的属性会自动加上\造成替换难度加大, |
||||
* 这边建议去除所有的html标签 |
||||
* 字符\在java中实际存储的是\\,替换字符串\\n, 需要用\\\\n |
||||
* "\t"和"\n" 都要转义成" " 不然会解析出错 |
||||
* "\\"需要转换成"\" |
||||
* 过滤掉html标签及内容 |
||||
* |
||||
* @param old 原始字符串 |
||||
* @return 处理之后的字符串 |
||||
*/ |
||||
private String trimText(String old) { |
||||
if (StringUtils.isNotBlank(old)) { |
||||
String a = filterHtmlTag(old, "a"); |
||||
String b = filterHtmlTag(a, "font"); |
||||
return b.replaceAll("\\\\n", "").replaceAll("\\\\t", "").replaceAll("\"", "\\\\\"").replaceAll("\'", "\\\\\'").replaceAll("\\\\\\\\", "\\\\"); |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
/** |
||||
* 进行html标签过滤 |
||||
* @param origin 原始字符串 |
||||
* @param tag html标签 |
||||
* @return 处理之后的字符串 |
||||
*/ |
||||
private String filterHtmlTag(String origin, String tag) { |
||||
String matter1 = "<" + tag; |
||||
String matter2 = tag + ">"; |
||||
int a = origin.indexOf(matter1); |
||||
int b = origin.indexOf(matter2); |
||||
while (a != -1 && b != -1) { |
||||
origin = origin.substring(0, a) + origin.substring(b + matter2.length(), origin.length()); |
||||
a = origin.indexOf(matter1); |
||||
b = origin.indexOf(matter2); |
||||
} |
||||
return origin; |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,31 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.manage.control.PluginTaskCallback; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class ModifyStatusCallback implements PluginTaskCallback{ |
||||
private boolean isActive; |
||||
private JSCallback jsCallback; |
||||
|
||||
public ModifyStatusCallback (boolean isActive, JSCallback jsCallback){ |
||||
this.isActive = isActive; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
if (result.isSuccess()) { |
||||
jsCallback.execute("success"); |
||||
String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Disabled") : Inter.getLocText("FR-Designer-Plugin_Actived"); |
||||
JOptionPane.showMessageDialog(null, modifyMessage); |
||||
} else { |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class UninstallPluginCallback extends AbstractPluginTaskCallback { |
||||
private JSCallback jsCallback; |
||||
|
||||
public UninstallPluginCallback(PluginMarker pluginMarker, JSCallback jsCallback){ |
||||
this.jsCallback = jsCallback; |
||||
this.pluginMarker = pluginMarker; |
||||
} |
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
if (result.isSuccess()) { |
||||
jsCallback.execute("success"); |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Delete_Success")); |
||||
}else if (result.errorCode() == PluginErrorCode.NeedInstallInterPluginDependency) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Delete_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
PluginManager.getController().uninstall(pluginMarker, true, new UninstallPluginCallback(pluginMarker, jsCallback)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { |
||||
private File zipFile; |
||||
private JSCallback jsCallback; |
||||
private static int HUNDRED_PERCENT = 100; |
||||
|
||||
public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) { |
||||
this.zipFile = zipFile; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
jsCallback.execute("success"); |
||||
if (result.isSuccess()) { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
} else if (result.errorCode() == PluginErrorCode.NeedInstallInterPluginDependency) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Update_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
PluginManager.getController().update(zipFile, new UpdateFromDiskCallback(zipFile, jsCallback)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/26. |
||||
*/ |
||||
public class UpdateOnlineCallback extends AbstractPluginTaskCallback { |
||||
public PluginMarker toPluginMarker; |
||||
protected JSCallback jsCallback; |
||||
private static int HUNDRED_PERCENT = 100; |
||||
|
||||
public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { |
||||
this.pluginMarker = pluginMarker; |
||||
this.toPluginMarker = toPluginMarker; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); |
||||
} |
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
jsCallback.execute("success"); |
||||
if (result.isSuccess()) { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
} else if (result.errorCode() == PluginErrorCode.NeedInstallInterPluginDependency) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Update_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.design.extra.exe.extratask; |
||||
|
||||
import com.fr.plugin.context.PluginMarker; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public abstract class AbstractExtraPluginTask implements ExtraPluginTask { |
||||
protected PluginMarker pluginMarker; |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.design.extra.exe.extratask; |
||||
|
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public interface ExtraPluginTask { |
||||
|
||||
void doExtraPluginTask(); |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.design.extra.exe.extratask; |
||||
|
||||
|
||||
import com.fr.design.extra.exe.callback.InstallOnlineCallback; |
||||
import com.fr.design.extra.exe.callback.JSCallback; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
|
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class InstallPluginTask extends AbstractExtraPluginTask { |
||||
protected JSCallback jsCallback; |
||||
|
||||
|
||||
public InstallPluginTask(PluginMarker pluginMarker, JSCallback jsCallback) { |
||||
this.pluginMarker = pluginMarker; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void doExtraPluginTask() { |
||||
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.design.extra.exe.extratask; |
||||
|
||||
import com.fr.design.extra.exe.callback.JSCallback; |
||||
import com.fr.design.extra.exe.callback.UpdateOnlineCallback; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public class UpdatePluginTask extends AbstractExtraPluginTask { |
||||
|
||||
public PluginMarker toPluginMarker; |
||||
protected JSCallback jsCallback; |
||||
|
||||
public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { |
||||
this.pluginMarker = pluginMarker; |
||||
this.toPluginMarker = toPluginMarker; |
||||
this.jsCallback = jsCallback; |
||||
} |
||||
|
||||
@Override |
||||
public void doExtraPluginTask() { |
||||
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback)); |
||||
} |
||||
} |
@ -1,281 +0,0 @@
|
||||
package com.fr.design.extra.plugindependence; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.extra.PluginHelper; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
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.StringUtils; |
||||
import com.fr.stable.plugin.PluginConstants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.WindowAdapter; |
||||
import java.awt.event.WindowEvent; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.InputStream; |
||||
import java.net.HttpURLConnection; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by hufan on 2016/9/5. |
||||
*/ |
||||
public class DownLoadDependenceUI implements ActionListener { |
||||
//进度显示界面
|
||||
private JDialog frame = null; |
||||
//进度条
|
||||
private JProgressBar progressbar; |
||||
//进度信息
|
||||
private JLabel label; |
||||
//进度条更新时钟
|
||||
private Timer timer; |
||||
//是否继续下载
|
||||
private boolean flag = true; |
||||
|
||||
// 定义加载窗口大小
|
||||
private static final int LOAD_WIDTH = 455; |
||||
|
||||
private static final int INCIDENT_WIDTH = 15; |
||||
|
||||
private static final int LOAD_HEIGHT = 295; |
||||
|
||||
|
||||
//安装环境相关信息
|
||||
private String currentID; |
||||
private List<PluginDependenceUnit> list = null; |
||||
//安装结果
|
||||
private boolean result = false; |
||||
//链接服务器的客户端
|
||||
private HttpClient httpClient; |
||||
//已读文件字节数
|
||||
private int totalBytesRead = 0; |
||||
//文件总长度
|
||||
private int totalSize = 0; |
||||
|
||||
public DownLoadDependenceUI() { |
||||
} |
||||
public DownLoadDependenceUI(String currentID, List<PluginDependenceUnit> list) { |
||||
this.currentID = currentID; |
||||
this.list = list; |
||||
this.totalSize = getFileLength(); |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
// 创建标签,并在标签上放置一张图片
|
||||
BufferedImage image = IOUtils.readImage("/com/fr/design/extra/plugindependence/image/background.png"); |
||||
ImageIcon imageIcon = new ImageIcon(image); |
||||
label = new UILabel(imageIcon); |
||||
label.setBounds(0, 0, LOAD_WIDTH, LOAD_HEIGHT - INCIDENT_WIDTH); |
||||
|
||||
progressbar = new JProgressBar(); |
||||
// 显示当前进度值信息
|
||||
progressbar.setStringPainted(true); |
||||
// 设置进度条边框不显示
|
||||
progressbar.setBorderPainted(false); |
||||
// 设置进度条的前景色
|
||||
progressbar.setForeground(new Color(0x38aef5)); |
||||
// 设置进度条的背景色
|
||||
progressbar.setBackground(new Color(188, 190, 194)); |
||||
progressbar.setBounds(0, LOAD_HEIGHT - INCIDENT_WIDTH, LOAD_WIDTH, INCIDENT_WIDTH); |
||||
progressbar.setMinimum(0); |
||||
progressbar.setMaximum(totalSize); |
||||
progressbar.setValue(0); |
||||
|
||||
timer = new Timer(100, this); |
||||
|
||||
frame = new JDialog(DesignerContext.getDesignerFrame(), true); |
||||
frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online")); |
||||
frame.setSize(LOAD_WIDTH, LOAD_HEIGHT); |
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
||||
frame.setLocation(screenSize.width / 2 - LOAD_WIDTH / 2, screenSize.height / 2 - LOAD_HEIGHT / 2); |
||||
frame.setResizable(false); |
||||
// 设置布局为空
|
||||
frame.setLayout(new BorderLayout(0, 0)); |
||||
frame.getContentPane().add(label, BorderLayout.CENTER); |
||||
frame.getContentPane().add(progressbar, BorderLayout.SOUTH); |
||||
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
||||
frame.addWindowListener(new WindowAdapter() { |
||||
public void windowClosing(WindowEvent e) { |
||||
//取消下载
|
||||
flag = false; |
||||
frame.dispose(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
//是否可以连接服务器
|
||||
private boolean connectToServer() { |
||||
for (int i = 0; i < list.size(); i++) { |
||||
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(){ |
||||
int size = 0; |
||||
for (int i = 0; i < list.size(); i++) { |
||||
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 size; |
||||
} |
||||
|
||||
//安装
|
||||
private boolean install() { |
||||
//开始时钟
|
||||
timer.start(); |
||||
//开始下载
|
||||
Thread thread = new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
installDependenceOnline(); |
||||
} |
||||
}); |
||||
thread.start(); |
||||
|
||||
frame.setVisible(true); |
||||
//等待下载线程处理结束
|
||||
try { |
||||
thread.join(); |
||||
} catch (InterruptedException e) { |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
//停止时钟
|
||||
timer.stop(); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 下载和安装不分开是因为,本地如果只安装好了一个依赖,下次就不需要重复下载了 |
||||
* 如果下载依赖后不安装,则后面的插件会把前面的插件覆盖,故而下载好了一个安装一个 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private void downloadAndInstallPluginDependenceFile() throws Exception { |
||||
totalBytesRead = 0; |
||||
for (int i = 0; i < list.size(); i++) { |
||||
PluginDependenceUnit dependenceUnit = list.get(i); |
||||
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceUnit.getDependenceID())); |
||||
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
||||
InputStream reader = httpClient.getResponseStream(); |
||||
String temp = StableUtils.pathJoin(PluginHelper.DEPENDENCE_DOWNLOAD_PATH, PluginHelper.TEMP_FILE); |
||||
StableUtils.makesureFileExist(new File(temp)); |
||||
FileOutputStream writer = new FileOutputStream(temp); |
||||
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
int bytesRead = 0; |
||||
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.unZipFilesGBK(temp, FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); |
||||
|
||||
} else { |
||||
result = false; |
||||
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
||||
} |
||||
} |
||||
//所有依赖都正常安装下载完毕,则结果为true
|
||||
result = true; |
||||
} |
||||
|
||||
public void installDependenceOnline() { |
||||
try { |
||||
//下载并安装文件
|
||||
downloadAndInstallPluginDependenceFile(); |
||||
} catch (Exception e) { |
||||
result = false; |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
//安装已经下载好的文件,如果是服务文件,则需要复制一份到安装目录下,
|
||||
//以便切换远程时,使用本地的服务
|
||||
//如果是服务器环境,则只会安装一份
|
||||
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) { |
||||
if (e.getSource() == timer) { |
||||
int value = progressbar.getValue(); |
||||
if (value < totalSize) { |
||||
progressbar.setValue(totalBytesRead); |
||||
} else { |
||||
timer.stop(); |
||||
frame.dispose(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void installOnline()throws PluginDependenceException { |
||||
|
||||
int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_DownLoadMessage", showFileLength()), "install tooltip", JOptionPane.YES_NO_OPTION); |
||||
if (choose == 0) {//下载安装
|
||||
if (!connectToServer()) { |
||||
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error")); |
||||
} |
||||
//安装依赖环境
|
||||
if (install()) { |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!"); |
||||
} else { |
||||
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
||||
} |
||||
}else {//不选择下载,则不安装图标插件
|
||||
throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); |
||||
} |
||||
} |
||||
|
||||
private String showFileLength(){ |
||||
double len = totalSize / Math.pow(10, 6); |
||||
String lenStr = String.format("%.2f", len); |
||||
return totalSize == -1 ? "NAN" : lenStr; |
||||
} |
||||
} |
Before Width: | Height: | Size: 105 KiB |
@ -0,0 +1,55 @@
|
||||
package com.fr.design.extra.tradition.callback; |
||||
|
||||
import com.fr.design.extra.PluginStatusCheckCompletePane; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
import com.fr.plugin.manage.control.ProgressCallback; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/31. |
||||
*/ |
||||
public class UpdateOnlineCallback implements ProgressCallback { |
||||
private PluginStatusCheckCompletePane pane; |
||||
private PluginMarker pluginMarker; |
||||
private PluginMarker toPluginMarker; |
||||
|
||||
public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, PluginStatusCheckCompletePane pane){ |
||||
this.pluginMarker = pluginMarker; |
||||
this.toPluginMarker = toPluginMarker; |
||||
this.pane = pane; |
||||
} |
||||
public void updateProgress(String description, double progress){ |
||||
pane.setProgress(progress); |
||||
} |
||||
|
||||
public void done(PluginTaskResult result){ |
||||
if (result.isSuccess()) { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); |
||||
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport) { |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), |
||||
Inter.getLocText("FR-Designer-Plugin_Install_Success"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { |
||||
return; |
||||
} |
||||
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane)); |
||||
} else { |
||||
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed")); |
||||
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,109 @@
|
||||
package com.fr.design.fun.impl; |
||||
|
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.fun.GlobalListenerProvider; |
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.context.PluginRuntime; |
||||
import com.fr.plugin.injectable.PluginModule; |
||||
import com.fr.plugin.manage.PluginFilter; |
||||
import com.fr.plugin.observer.PluginEvent; |
||||
import com.fr.plugin.observer.PluginEventListener; |
||||
import com.fr.plugin.observer.PluginEventType; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.event.AWTEventListener; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* Created by juhaoyu on 2017/6/15. |
||||
* 管理正在运行中插件的GlobalListenerProvider接口 |
||||
*/ |
||||
public class GlobalListenerProviderManager { |
||||
|
||||
private static final GlobalListenerProviderManager INSTANCE = new GlobalListenerProviderManager(); |
||||
|
||||
private Map<GlobalListenerProvider, AWTEventListener> map = new HashMap<>(); |
||||
|
||||
private GlobalListenerProviderManager() {} |
||||
|
||||
public static GlobalListenerProviderManager getInstance() { |
||||
|
||||
return INSTANCE; |
||||
} |
||||
|
||||
public void init() { |
||||
|
||||
Set<GlobalListenerProvider> providers = ExtraDesignClassManager.getInstance().getArray(GlobalListenerProvider.XML_TAG); |
||||
addAWTEventListeners(providers); |
||||
listenPlugin(); |
||||
} |
||||
|
||||
private void listenPlugin() { |
||||
|
||||
PluginFilter filter = new PluginFilter() { |
||||
|
||||
@Override |
||||
public boolean accept(PluginContext context) { |
||||
|
||||
return context.contain(PluginModule.ExtraDesign, GlobalListenerProvider.XML_TAG); |
||||
} |
||||
}; |
||||
PluginEventListener onRun = new PluginEventListener() { |
||||
|
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
|
||||
PluginRuntime runtime = event.getContext().getRuntime(); |
||||
Set<GlobalListenerProvider> providers = runtime.get(PluginModule.ExtraDesign, GlobalListenerProvider.XML_TAG); |
||||
addAWTEventListeners(providers); |
||||
} |
||||
}; |
||||
PluginEventListener onStop = new PluginEventListener() { |
||||
|
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
|
||||
PluginRuntime runtime = event.getContext().getRuntime(); |
||||
Set<GlobalListenerProvider> providers = runtime.get(PluginModule.ExtraDesign, GlobalListenerProvider.XML_TAG); |
||||
removeAWTEventListeners(providers); |
||||
} |
||||
}; |
||||
GeneralContext.listenPlugin(PluginEventType.AfterRun, onRun, filter); |
||||
GeneralContext.listenPlugin(PluginEventType.BeforeStop, onStop, filter); |
||||
|
||||
|
||||
} |
||||
|
||||
private void addAWTEventListeners(Set<GlobalListenerProvider> providers) { |
||||
|
||||
AWTEventListener listener; |
||||
for (GlobalListenerProvider provider : providers) { |
||||
listener = provider.listener(); |
||||
Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK); |
||||
add(provider, listener); |
||||
} |
||||
} |
||||
|
||||
private void removeAWTEventListeners(Set<GlobalListenerProvider> providers) { |
||||
|
||||
AWTEventListener listener; |
||||
for (GlobalListenerProvider provider : providers) { |
||||
listener = pop(provider); |
||||
Toolkit.getDefaultToolkit().removeAWTEventListener(listener); |
||||
} |
||||
} |
||||
|
||||
private synchronized void add(GlobalListenerProvider provider, AWTEventListener listener) { |
||||
|
||||
map.put(provider, listener); |
||||
} |
||||
|
||||
private synchronized AWTEventListener pop(GlobalListenerProvider provider) { |
||||
|
||||
return map.remove(provider); |
||||
} |
||||
|
||||
} |
@ -1,128 +0,0 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.file.XMLFileManager; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* Author : daisy |
||||
* Version: 6.5.6 |
||||
* Date: 13-12-20 |
||||
* Time: 下午5:05 |
||||
*/ |
||||
public class PluginManager extends XMLFileManager { |
||||
|
||||
private static PluginManager pluginManager = null; |
||||
|
||||
private String extensionPoint = StringUtils.EMPTY; |
||||
|
||||
private ArrayList<UpdateAction> resultList = new ArrayList<UpdateAction>(); |
||||
|
||||
|
||||
public synchronized static PluginManager getInstance() { |
||||
if (pluginManager == null) { |
||||
pluginManager = new PluginManager(); |
||||
} |
||||
return pluginManager; |
||||
} |
||||
|
||||
|
||||
public PluginManager() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 文件名 |
||||
* @return 文件名 |
||||
*/ |
||||
public String fileName() { |
||||
return "plugin.xml"; |
||||
} |
||||
|
||||
|
||||
public void setExtensionPoint(String point) { |
||||
extensionPoint = point; |
||||
resultList.clear(); |
||||
pluginManager.readXMLFile(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (extensionPoint == StringUtils.EMPTY) { |
||||
return; |
||||
} |
||||
if (reader.getTagName().equals("PluginManager")) { |
||||
reader.readXMLObject(new XMLReadable() { |
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
readExtension(reader); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
private void readExtension(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
if (reader.getTagName().equals("Extension")) { |
||||
String name = null, tmpVal = null; |
||||
if ((tmpVal = reader.getAttrAsString("position", null)) != null) { |
||||
name = tmpVal; |
||||
} |
||||
if (!ComparatorUtils.equals(name, extensionPoint)) { |
||||
return; |
||||
} |
||||
reader.readXMLObject(new XMLReadable() { |
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
readActions(reader); |
||||
} |
||||
}); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
private void readActions(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
if (reader.getTagName().equals("Action")) { |
||||
String name = null, tmpVal = null; |
||||
if ((tmpVal = reader.getAttrAsString("class", null)) != null) { |
||||
name = tmpVal; |
||||
} |
||||
//读取模板数据集菜单
|
||||
if (name.isEmpty()) { |
||||
return; |
||||
} |
||||
try { |
||||
UpdateAction action = (UpdateAction) GeneralUtils.classForName(name).newInstance(); |
||||
PluginManager.this.resultList.add(action); |
||||
} catch (Exception exp) { |
||||
FRLogger.getLogger().error(exp.getMessage(), exp); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
public ArrayList<UpdateAction> getResultList() { |
||||
return resultList; |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
} |
||||
|
||||
} |
@ -1,31 +0,0 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.chart.charttypes.ChartTypeManager; |
||||
import com.fr.plugin.proxy.CloseableInvocationHandler; |
||||
|
||||
/** |
||||
* Created by juhaoyu on 2016/12/27. |
||||
*/ |
||||
public class ChartTypeInterfaceCloseableHandler extends CloseableInvocationHandler { |
||||
|
||||
|
||||
private final String plotID; |
||||
|
||||
public ChartTypeInterfaceCloseableHandler(String plotID) throws NoSuchMethodException { |
||||
|
||||
super(); |
||||
this.plotID = plotID; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean invokeIsClosed() { |
||||
|
||||
//UI对应的chart如果关闭或者不存在,则UI关闭
|
||||
return super.invokeIsClosed() || !containsChart(); |
||||
} |
||||
|
||||
private boolean containsChart() { |
||||
|
||||
return ChartTypeManager.getInstance().containsPlot(plotID); |
||||
} |
||||
} |
Loading…
Reference in new issue