Browse Source

Merge pull request #26 in PF/design from ~KERRY/design-pf:9.0 to 9.0

* commit '0caa8c6a46dbc70ebdbd58317219d44ac195c425':
  REPORT-2354 将平台的插件管理和设计器的插件管理统一起来
master
superman 8 years ago
parent
commit
977a354a84
  1. 3
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  2. 6
      designer_base/src/com/fr/design/extra/PluginFromStorePane.java
  3. 85
      designer_base/src/com/fr/design/extra/PluginOperateUtils.java
  4. 15
      designer_base/src/com/fr/design/extra/PluginUpdatePane.java
  5. 15
      designer_base/src/com/fr/design/extra/PluginUtils.java
  6. 11
      designer_base/src/com/fr/design/extra/PluginWebBridge.java

3
designer_base/src/com/fr/design/extra/LoginWebBridge.java

@ -9,6 +9,8 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.bbs.BBSUserInfo;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
@ -320,6 +322,7 @@ public class LoginWebBridge {
DesignerEnvManager.getEnvManager().setBBSName(username);
DesignerEnvManager.getEnvManager().setInShowBBsName(username);
DesignerEnvManager.getEnvManager().setBBSPassword(password);
BBSPluginLogin.getInstance().login(new BBSUserInfo(username, password));
return LOGININ;//登录成功,0
} else if ($uid == -1) {
return USERNAME_NOT_EXSIT;//用户名不存在,-1

6
designer_base/src/com/fr/design/extra/PluginFromStorePane.java

@ -6,6 +6,7 @@ import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
@ -199,8 +200,9 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<List<Plug
try {
PluginMarker pluginMarker = PluginMarker.create(id, plugin.getVersion());
String latestPluginInfo = PluginUtils.getLatestPluginInfo(id);
PluginMarker toPluginMarker = PluginMarker.create(id, latestPluginInfo);
JSONObject latestPluginInfo = PluginUtils.getLatestPluginInfo(id);
String latestPluginVersion = (String)latestPluginInfo.get("version");
PluginMarker toPluginMarker = PluginMarker.create(id, latestPluginVersion);
PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);

85
designer_base/src/com/fr/design/extra/PluginOperateUtils.java

@ -6,7 +6,6 @@ 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.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject;
@ -14,12 +13,11 @@ 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 org.json.JSONArray;
import javax.swing.*;
import java.io.File;
import java.util.List;
@ -51,13 +49,8 @@ public class PluginOperateUtils {
if (BBSPluginLogin.getInstance().hasLogin()) {
for (int i = 0; i < pluginMarkerList.size(); i++) {
try {
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID());
if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
JSONObject resultArr = new JSONObject(latestPluginInfo);
String latestPluginVersion = (String) resultArr.get("version");
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));
@ -90,27 +83,39 @@ public class PluginOperateUtils {
}
public static void readUpdateOnline(JSCallback jsCallback) {
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);
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());
}
}
String result = jsonArray.toString();
jsCallback.execute(result);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}).start();
}
public static void searchPlugin(String keyword, JSCallback jsCallback) {
try {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword);
String result = httpClient.getResponseText();
jsCallback.execute(result);
new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword);
String result = httpClient.getResponseText();
jsCallback.execute(result);
}
}).start();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
@ -150,19 +155,25 @@ public class PluginOperateUtils {
}
public static void getPluginCategories(JSCallback jsCallback) {
String result;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category");
if (url != null) {
HttpClient httpClient = new HttpClient(url);
result = httpClient.getResponseText();
} else {
result = PluginConstants.CONNECTION_404;
}
jsCallback.execute(result);
new Thread(new Runnable() {
@Override
public void run() {
String result;
String url = SiteCenter.getInstance().acquireUrlByKind("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 getLoginInfo(JSCallback jsCallback) {
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
BBSUserInfo bbsUserInfo = BBSPluginLogin.getInstance().getUserInfo();
String username = bbsUserInfo == null ? "" : bbsUserInfo.getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
@ -172,11 +183,11 @@ public class PluginOperateUtils {
}
}
public static boolean pluginValidate(PluginView pluginView){
public static boolean pluginValidate(PluginView pluginView) {
return StringUtils.isNotEmpty(pluginView.getID())
&& StringUtils.isNotEmpty(pluginView.getName())
&& StringUtils.isNotEmpty(pluginView.getVersion())
&& StringUtils.isNotEmpty(pluginView.getEnvVersion());
}
}
}

15
designer_base/src/com/fr/design/extra/PluginUpdatePane.java

@ -8,6 +8,7 @@ import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
@ -179,11 +180,15 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<List<PluginV
LoginCheckContext.fireLoginCheckListener();
}
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginView plugin = controlPane.getSelectedPlugin();
PluginMarker pluginMarker = PluginMarker.create(plugin.getID(), plugin.getVersion());
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarker.getPluginID());
PluginMarker toPluginMarker = PluginMarker.create(pluginMarker.getPluginID(), latestPluginInfo);
PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
try{
PluginView plugin = controlPane.getSelectedPlugin();
PluginMarker pluginMarker = PluginMarker.create(plugin.getID(), plugin.getVersion());
JSONObject latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarker.getPluginID());
String latestPluginVersion = (String) latestPluginInfo.get("version");
PluginMarker toPluginMarker = PluginMarker.create(pluginMarker.getPluginID(), latestPluginVersion);
PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
}catch (Exception e){}
}
}

15
designer_base/src/com/fr/design/extra/PluginUtils.java

@ -38,7 +38,7 @@ public class PluginUtils {
return pluginMarker;
}
public static String getLatestPluginInfo(String pluginID){
public static JSONObject getLatestPluginInfo(String pluginID) throws Exception {
String result = "";
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.searchAPI");
if (StringUtils.isNotEmpty(plistUrl)) {
@ -48,6 +48,7 @@ public class PluginUtils {
}
try {
HttpClient httpClient = new HttpClient(url.toString());
httpClient.asGet();
result = httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
@ -55,7 +56,11 @@ public class PluginUtils {
} else {
result = PluginConstants.CONNECTION_404;
}
return result;
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 {
@ -69,7 +74,7 @@ public class PluginUtils {
return jsonArray.toString();
}
public static void downloadShopScripts(String id, String username, String password, Process<Double> p) throws Exception{
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();
@ -108,7 +113,7 @@ public class PluginUtils {
return resText;
}
public static boolean isPluginMatch(PluginView pluginView, String text){
public static boolean isPluginMatch(PluginView pluginView, String text) {
return StringUtils.contains(pluginView.getID(), text)
|| StringUtils.contains(pluginView.getName(), text)
|| StringUtils.contains(pluginView.getVersion(), text)
@ -119,7 +124,7 @@ public class PluginUtils {
}
public static String pluginToHtml(PluginView pluginView){
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");

11
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -4,10 +4,7 @@ import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.design.extra.exe.extratask.ExtraPluginTask;
import com.fr.design.extra.exe.extratask.UpdatePluginTask;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
@ -19,7 +16,6 @@ import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javafx.concurrent.Task;
import javafx.scene.web.WebEngine;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@ -488,8 +484,11 @@ public class PluginWebBridge {
* @param password
* @return
*/
public String defaultLogin(String username, String password) {
return LoginWebBridge.getHelper().pluginManageLogin(username, password, uiLabel);
public void defaultLogin(String username, String password, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
String result = LoginWebBridge.getHelper().pluginManageLogin(username, password, uiLabel);
jsCallback.execute(result);
}
/**

Loading…
Cancel
Save