From 0b9f538bd81c8bbe89e1cfc9019c4a534dfde5b2 Mon Sep 17 00:00:00 2001 From: pengda Date: Wed, 2 Jun 2021 22:51:43 +0800 Subject: [PATCH 1/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 9 +- .../java/com/fr/design/VersionCheckUtils.java | 429 ++++++++++++++++++ .../fr/design/update/actions/FileProcess.java | 8 +- .../java/com/fr/env/CheckServiceDialog.java | 421 ++++++++++++++--- .../src/main/java/com/fr/env/ErrorDialog.java | 73 +++ .../com/fr/env/SyncFailedPluginsDialog.java | 119 +++++ .../com/fr/env/VersionCheckMessageDialog.java | 100 ++++ .../com/fr/design/EnvChangeEntranceTest.java | 2 +- .../module/DesignerWorkspaceProvider.java | 8 +- 9 files changed, 1094 insertions(+), 75 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/VersionCheckUtils.java create mode 100644 designer-base/src/main/java/com/fr/env/ErrorDialog.java create mode 100644 designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java create mode 100644 designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index 5196c783aa..c71dc34716 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -22,6 +22,7 @@ import com.fr.env.CheckServiceDialog; import com.fr.env.EnvListPane; import com.fr.env.RemoteWorkspaceURL; import com.fr.env.TestConnectionResult; +import com.fr.env.VersionCheckMessageDialog; import com.fr.exit.DesignerExiter; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; @@ -96,6 +97,10 @@ public class EnvChangeEntrance { */ public void switch2Env(final String envName) { switch2Env(envName, PopTipStrategy.LATER); + if(!VersionCheckUtils.versionCheck(envName)){ + VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),envName); + versionCheckMessageDialog.setVisible(true); + } } /** @@ -145,7 +150,6 @@ public class EnvChangeEntrance { if (template != null) { template.refreshToolArea(); } - showServiceDialog(selectedEnv); pluginErrorRemind(); } catch (WorkspaceAuthException | RegistEditionException e) { // String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); @@ -294,8 +298,7 @@ public class EnvChangeEntrance { if(StringUtils.isEmpty(areaText)){ return; } - CheckServiceDialog dialog = new CheckServiceDialog(DesignerContext.getDesignerFrame(), areaText, localBranch, remoteBranch); - dialog.setVisible(true); + } } } diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java new file mode 100644 index 0000000000..2af000f86b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -0,0 +1,429 @@ +package com.fr.design; + +import com.fr.base.FRContext; +import com.fr.decision.update.data.UpdateConstants; +import com.fr.decision.update.exception.UpdateException; +import com.fr.decision.update.info.UpdateCallBack; +import com.fr.decision.update.info.UpdateProcessBean; +import com.fr.design.env.DesignerWorkspaceInfo; +import com.fr.design.env.DesignerWorkspaceType; +import com.fr.design.env.RemoteWorkspace; +import com.fr.design.i18n.Toolkit; +import com.fr.general.CommonIOUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralUtils; +import com.fr.general.IOUtils; +import com.fr.general.http.HttpToolbox; +import com.fr.invoke.Reflect; +import com.fr.json.JSONArray; +import com.fr.json.JSONObject; +import com.fr.locale.InterProviderFactory; +import com.fr.log.FineLoggerFactory; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskCallback; +import com.fr.plugin.manage.control.PluginTaskResult; +import com.fr.plugin.manage.control.ProgressCallback; +import com.fr.rpc.Result; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; +import com.fr.third.org.apache.http.client.methods.HttpGet; +import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; +import com.fr.workspace.WorkContext; +import com.fr.workspace.base.WorkspaceAPI; +import com.fr.workspace.connect.WorkspaceConnectionInfo; +import com.fr.workspace.engine.base.FineObjectPool; +import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; +import com.fr.workspace.engine.exception.WorkspaceConnectionException; +import com.fr.workspace.engine.rpc.WorkspaceProxyPool; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.net.ProtocolException; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; + +/** + * @author pengda + * @version 10.0 + * Created by Bryant on 2021-06-02 + */ +public class VersionCheckUtils { + private static final String SYNCPLUGINLIB = StableUtils.getInstallHome() + "/logs/syncLib/plugins/"; + private static final String SYNCLIB = StableUtils.getInstallHome() + "/logs/syncLib/"; + private static final String ZIP = ".zip"; + public static final String INCONSISTENCY = "inconsistency"; + public static final String MISSING = "missing"; + private static final String ID = "id"; + private static final String VERSION = "version"; + private static final String NAME = "name"; + + + public static boolean versionCheck(String envName) { + return checkLocalAndRemoteJartime(envName) && checkLocalAndRemotePlugin().size() == 0; + } + + public static boolean versionCheck(DesignerWorkspaceInfo selectedEnv) { + return checkLocalAndRemoteJartime(selectedEnv) && checkLocalAndRemotePlugin().size() == 0; + } + + public static boolean checkLocalAndRemoteJartime(String envName) { + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + return checkLocalAndRemoteJartime(selectedEnv); + } + + public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv){ + //是否需要做服务校验 + if (needCheckBranch(selectedEnv)) { + String localBranch; + String remoteBranch = getRemoteBranch(selectedEnv); + localBranch = GeneralUtils.readFullBuildNO(); + //通过是否包含#来避免当前版本为非安装版本(主要是内部开发版本) + if (localBranch.contains("#") && ComparatorUtils.equals(localBranch, remoteBranch)) { + //说明版本一致,仅做日志记录 + FineLoggerFactory.getLogger().info("Remote Designer version consistency"); + return true; + } else { + return false; + } + } + return true; + } + + public static List getNoExistServiceDescription(String envName) { + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection(); + List noExistServiceDescription = new ArrayList<>(); + Set noExistServiceSet = getNoExistServiceSet(connectionInfo); + for (Class clazz : noExistServiceSet) { + WorkspaceAPI workspaceAPI = (WorkspaceAPI) clazz.getAnnotation(WorkspaceAPI.class); + if (workspaceAPI == null) { + FineLoggerFactory.getLogger().info("workspace service {} get annotation failed", clazz); + continue; + } + if (workspaceAPI.ignore()) { + continue; + } + String descriptionOfCN = InterProviderFactory.getProvider().getLocText(workspaceAPI.description()); + noExistServiceDescription.add(descriptionOfCN); + } + return noExistServiceDescription; + } + + public static String getRemoteBranch(String envName) { + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + return getRemoteBranch(selectedEnv); + } + + public static String getRemoteBranch(DesignerWorkspaceInfo selectedEnv) { + String remoteBranch = StringUtils.EMPTY; + WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection(); + try { + remoteBranch = new FunctionalHttpRequest(connectionInfo).getServerBranch(); + } catch (WorkspaceConnectionException e) { + remoteBranch = Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Is_Old") + formatBranch(GeneralUtils.readFullBuildNO()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return remoteBranch; + } + + /** + * 获取不存在的服务列表 + * + * @param info 环境连接信息 + * @return 以Set形式返回不存在的服务 + */ + public static Set getNoExistServiceSet(WorkspaceConnectionInfo info) { + Set noExistServiceSet = new HashSet(); + Set remoteServiceSet = new HashSet(); + Set localServiceSet = FineObjectPool.getInstance().getServerPool().keySet(); + + try { + JSONArray serviceArray = new FunctionalHttpRequest(info).getServiceList(); + for (int i = 0; i < serviceArray.size(); i++) { + try { + Class clazz = Class.forName((String) serviceArray.get(i)); + remoteServiceSet.add(clazz); + } catch (Exception e) { + continue; + } + } + noExistServiceSet.addAll(localServiceSet); + noExistServiceSet.removeAll(remoteServiceSet); + return noExistServiceSet; + } catch (WorkspaceConnectionException e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + //根据本地的服务列表做逐一检测 + for (Class clazz : localServiceSet) { + Method testMethod = Reflect.on(Method.class).create(clazz, "connectTest", new Class[0], String.class, new Class[0], 1025, 8, null, null, null, null).get(); + WorkspaceProxyPool proxyPool = (WorkspaceProxyPool) (((RemoteWorkspace) WorkContext.getCurrent()).getClient()).getPool(); + Result result = proxyPool.testInvoker(testMethod); + Exception invokeException = (Exception) result.getException(); + if (invokeException != null) { + Exception cause = (Exception) invokeException.getCause(); + //获取被包装最底层的异常 + while (cause != null) { + invokeException = cause; + cause = (Exception) invokeException.getCause(); + } + //该异常表示服务不存在 + if (invokeException instanceof ClassNotFoundException) { + noExistServiceSet.add(clazz); + } + } + } + return noExistServiceSet; + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return noExistServiceSet; + } + } + + /** + * 格式化分支版本号 + * + * @param branch 初始的分支版本号 + * @return 格式化后的版本号 + */ + private static String formatBranch(String branch) { + if (branch.contains("#")) { + return branch.substring(branch.lastIndexOf("-") + 1, branch.length() - 13); + } + return branch; + } + + private static boolean needCheckBranch(DesignerWorkspaceInfo selectedEnv) { + if (selectedEnv.getType() == DesignerWorkspaceType.Remote) { + return true; + } + return false; + } + + public static JSONArray checkLocalAndRemotePlugin() { + JSONArray differentPlugins = new JSONArray(); + JSONArray remotePlugins = FRContext.getCommonOperator().getPluginStatus(); + Map localPluginsMap = new HashMap<>(); + List localPlugins = PluginManager.getContexts(); + for (PluginContext pluginContext : localPlugins) { + localPluginsMap.put(pluginContext.getID(), pluginContext); + } + JSONObject remotePlugin; + for (int i = 0; i < remotePlugins.size(); i++) { + remotePlugin = remotePlugins.getJSONObject(i); + if (localPluginsMap.containsKey(remotePlugin.getString(ID))) { + if (ComparatorUtils.equals(localPluginsMap.get(remotePlugin.getString(ID)).getVersion(), remotePlugin.getString(VERSION))) { + continue; + } else { + if (remotePlugin.getString(NAME) == null) { + remotePlugin.put(NAME, localPluginsMap.get(remotePlugin.getString(ID)).getName()); + } + remotePlugin.put("type", INCONSISTENCY); + } + } + remotePlugin.put("type", MISSING); + if (remotePlugin.getString(NAME) == null) { + remotePlugin.put(NAME, remotePlugin.getString("id")); + } + differentPlugins.put(remotePlugin); + } + return differentPlugins; + } + + public static JSONArray syncPlugins(JSONArray differentPlugins, UpdateCallBack callBack) { + Set uninstallFailed = uninstallPlugins(differentPlugins); + Map downloadURL = getPluginsDownloadURL(differentPlugins, uninstallFailed); + downloadPlugins(downloadURL, callBack); + return installPlugins(differentPlugins); + } + + private static Set uninstallPlugins(JSONArray differentPlugins) { + Map localPluginsMap = new HashMap<>(); + List localPlugins = PluginManager.getContexts(); + for (PluginContext pluginContext : localPlugins) { + localPluginsMap.put(pluginContext.getID(), pluginContext); + } + Set uninstallFailedID = new HashSet<>(); + for (int i = 0; i < differentPlugins.size(); i++) { + String id = differentPlugins.getJSONObject(i).getString(ID); + if (localPluginsMap.containsKey(id)) { + PluginManager.getController().uninstall(localPluginsMap.get(id).getMarker(), true, new PluginTaskCallback() { + @Override + public void done(PluginTaskResult result) { + if (!result.isSuccess()) { + FineLoggerFactory.getLogger().error("uninstall plugin:" + id + " failed"); + uninstallFailedID.add(id); + } + } + }); + } + } + return uninstallFailedID; + } + + private static JSONArray installPlugins(JSONArray differentPlugins) { + File file = new File(SYNCPLUGINLIB); + JSONArray syncFailedPlugins = JSONArray.create(); + if (file.isDirectory()) { + File[] plugins = file.listFiles(); + if (plugins != null && plugins.length > 0) { + CountDownLatch latch = new CountDownLatch(plugins.length); + for (File plugin : plugins) { + if (plugin.getName().endsWith(ZIP)) { + PluginManager.getController().install(plugin, new ProgressCallback() { + @Override + public void updateProgress(String description, double progress) { + } + @Override + public void done(PluginTaskResult result) { + latch.countDown(); + } + }); + } + } + try { + latch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + List localPlugins = PluginManager.getContexts(); + Map localPluginsInfo = new HashMap<>(); + for (int i = 0; i < localPlugins.size(); i++) { + localPluginsInfo.put(localPlugins.get(i).getID(), localPlugins.get(i).getVersion()); + } + for (int i = 0; i < differentPlugins.size(); i++) { + JSONObject plugin = differentPlugins.getJSONObject(i); + String id = plugin.getString(ID); + if (localPluginsInfo.containsKey(id) && ComparatorUtils.equals(plugin.getString(VERSION), localPluginsInfo.get(id))) { + continue; + } + syncFailedPlugins.add(plugin); + } + return syncFailedPlugins; + } + + private static void downloadPlugins(Map urls, UpdateCallBack callBack) { + CommonIOUtils.deleteFile(new File(SYNCLIB)); + UpdateProcessBean bean = new UpdateProcessBean(); + FileOutputStream fos = null; + CloseableHttpClient httpClient; + CloseableHttpResponse httpResponse; + HttpGet httpGet = new HttpGet(); + InputStream in = null; + try { + for (String idAndVersion : urls.keySet()) { + try { + httpGet.setURI(URI.create(urls.get(idAndVersion))); + httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); + String target = SYNCPLUGINLIB + idAndVersion + ZIP; + httpResponse = httpClient.execute(httpGet); + if (httpResponse.getStatusLine().getStatusCode() != 200) { + FineLoggerFactory.getLogger().error("download plugin error :" + urls.get(idAndVersion)); + continue; + } + long totalSize = httpResponse.getEntity().getContentLength(); + in = httpResponse.getEntity().getContent(); + //保存文件 + File saveDir = new File(target); + StableUtils.makesureFileExist(saveDir); + + bean.setDownloadedFiles(bean.getDownloadedFiles() + 1); + bean.setName(idAndVersion); + bean.setTotalLength((int) totalSize); + bean.setDownloadLength(0); + callBack.updateProgress(bean); + fos = new FileOutputStream(saveDir); + int bytesRead; + int totalBytesRead = 0; + byte[] getData = new byte[UpdateConstants.BYTE]; + while ((bytesRead = in.read(getData)) != -1) { + fos.write(getData, 0, bytesRead); + getData = new byte[UpdateConstants.BYTE]; + totalBytesRead += bytesRead; + bean.setDownloadLength(totalBytesRead); + callBack.updateProgress(bean); + } + } catch (ProtocolException e) { + UpdateException exception = new UpdateException(e.getMessage() + " downloadPluginZip Exception in network"); + FineLoggerFactory.getLogger().error(exception.getErrorMessage(), e); + } catch (IOException e) { + UpdateException exception = new UpdateException(e.getMessage() + " downloadPluginZip Exception in download"); + FineLoggerFactory.getLogger().error(exception.getErrorMessage(), e); + } + } + } finally { + CommonIOUtils.close(fos); + CommonIOUtils.close(in); + } + } + + + private static Map getPluginsDownloadURL(JSONArray differentPlugins, Set uninstallFailed) { + Map downloadURL = new HashMap<>(); + JSONObject differentPlugin; + String id; + String version; + try { + for (int i = 0; i < differentPlugins.size(); i++) { + String url = null; + differentPlugin = differentPlugins.getJSONObject(i); + id = differentPlugin.getString(ID); + if (uninstallFailed.contains(id)) { + continue; + } + version = differentPlugin.getString(VERSION); + try { + //url = CloudCenter.getInstance().acquireUrlByKind("sync10.plugin"); + url = "http://192.168.5.83:3008/api/v1/plugin/download/history?pluginId={}&version={}"; + url = StringUtils.messageFormat(url, id, version); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + + downloadURL.put(id + "-" + version, url); + } + } catch (Exception e) { + + } + return getPluginZipDownloadURL(downloadURL); + } + + private static Map getPluginZipDownloadURL(Map urls) { + CloseableHttpClient httpClient; + CloseableHttpResponse httpResponse; + HttpGet httpGet = new HttpGet(); + InputStream in = null; + try { + for (String idAndVersion : urls.keySet()) { + httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); + httpGet.setURI(URI.create(urls.get(idAndVersion))); + httpResponse = httpClient.execute(httpGet); + in = httpResponse.getEntity().getContent(); + JSONObject urlJson = new JSONObject(IOUtils.inputStream2String(in)); + String downloadURL = urlJson.getString("result"); + if (downloadURL != null) { + urls.replace(idAndVersion, urlJson.getString("result")); + } + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + CommonIOUtils.close(in); + } + return urls; + } +} diff --git a/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java b/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java index 2ed0801dca..c9556bd77d 100644 --- a/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java +++ b/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java @@ -15,14 +15,20 @@ import java.util.concurrent.ExecutionException; public abstract class FileProcess extends SwingWorker { private UpdateCallBack callBack; + private String fullBuildNo = null; public FileProcess(UpdateCallBack callBack) { this.callBack = callBack; } + public FileProcess(UpdateCallBack callBack,String fullBuildNo) { + this.callBack = callBack; + this.fullBuildNo = fullBuildNo; + } + @Override protected Boolean doInBackground() throws Exception { - return UpdateExecutor.getInstance().execute(callBack); + return UpdateExecutor.getInstance().execute(callBack,fullBuildNo); } @Override diff --git a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index efee9bfdfc..30c6ec15a9 100644 --- a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -1,32 +1,68 @@ package com.fr.env; -import com.fr.design.DesignerEnvManager; -import com.fr.design.env.RemoteDesignerWorkspaceInfo; +import com.fr.decision.update.data.UpdateConstants; +import com.fr.decision.update.info.UpdateCallBack; +import com.fr.decision.update.info.UpdateProgressCallBack; +import com.fr.design.RestartHelper; +import com.fr.design.VersionCheckUtils; +import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.update.actions.FileProcess; +import com.fr.design.update.ui.dialog.RestoreResultDialog; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.env.utils.DisplayUtils; +import com.fr.general.CloudCenter; +import com.fr.general.CloudCenterConfig; +import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; +import com.fr.general.http.HttpToolbox; +import com.fr.json.JSONArray; +import com.fr.json.JSONObject; +import com.fr.log.FineLoggerFactory; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; +import com.fr.stable.CommonUtils; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; +import com.sun.java.swing.plaf.motif.MotifProgressBarUI; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.util.List; +import java.util.concurrent.ExecutionException; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.JTextPane; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.Locale; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingWorker; +import javax.swing.UIManager; + + +import static javax.swing.JOptionPane.QUESTION_MESSAGE; /** * @author: Maksim @@ -36,11 +72,34 @@ import java.util.Locale; public class CheckServiceDialog extends JDialog implements ActionListener { private JPanel topPanel; private JPanel centerPanel; - private JPanel bottomPanel; - private UICheckBox remindBox; + private UIButton ignoreButton; + private UIButton syncButton; + private JProgressBar progressBar; + private String remoteBuildNo; + private static final Dimension PROGRESSBAR = new Dimension(120, 15); + private JSONArray differentPlugins; + private UILabel affectedFunctionsLabel; + private UILabel jarCheckResultLabel; + private UILabel jarCheckTitleLabel; + private UILabel pluginCheckTitleLabel; + + private JPanel affectedFunctionsDetailsPane; + private JPanel pluginsCheckResultPanel; + private JPanel detailsInnerPane; + private JPanel detailsPane; + private JScrollPane jScrollPane; + private Component[][] detailsComponents; + private Component[][] hideAffectedFunctionsComponents; + private boolean showAffectedFunctions = true; + private boolean jarConsistency; + private double p = TableLayout.PREFERRED; + private double f = TableLayout.FILL; - public CheckServiceDialog(Frame parent, String areaText, String localBranch, String remoteBranch){ - super(parent,true); + public CheckServiceDialog(Frame parent, String localBranch, String remoteBranch, List noExistServiceDescription) { + super(parent, true); + this.remoteBuildNo = remoteBranch; + this.differentPlugins = VersionCheckUtils.checkLocalAndRemotePlugin(); + this.jarConsistency = ComparatorUtils.equals(localBranch, remoteBranch); //上面的标签面板 topPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); JPanel imagePanel = new JPanel(); @@ -49,90 +108,314 @@ public class CheckServiceDialog extends JDialog implements ActionListener { JLabel imageLabel = new JLabel(); imageLabel.setIcon(icon); imagePanel.add(imageLabel); - imagePanel.setPreferredSize(new Dimension(110,100)); + imagePanel.setPreferredSize(new Dimension(110, 100)); JPanel verticalPanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); FRFont font = FRFont.getInstance(); font = font.applySize(15).applyStyle(1); - JLabel label = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Inconsistency")); + UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Branch_Inconsistency")); label.setFont(font); - label.setPreferredSize(new Dimension(650,30)); - - String text = Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Local_Designer") + localBranch - + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remote_Server") + - Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Is_Old") + - localBranch; - String delimiter = DisplayUtils.getDisplayLength(text) > 70? "
":"/"; - JLabel label2 = new JLabel(""+Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Local_Designer") - + localBranch + delimiter + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remote_Server") + - Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Is_Old")+ localBranch +""); - label2.setPreferredSize(new Dimension(600,30)); - - JTextPane tipsPane = new JTextPane(); - tipsPane.setEditable(false); - tipsPane.setBackground(verticalPanel.getBackground()); - tipsPane.setPreferredSize(new Dimension(500,40)); - tipsPane.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Need_Update")); + label.setPreferredSize(new Dimension(650, 30)); + UILabel label2 = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Inconsistency_Risk")); + label2.setPreferredSize(new Dimension(600, 30)); verticalPanel.add(label); verticalPanel.add(label2); - verticalPanel.add(tipsPane); - topPanel.add(imagePanel,BorderLayout.WEST); - topPanel.add(verticalPanel,BorderLayout.CENTER); - topPanel.setBorder(BorderFactory.createEmptyBorder(10,10,0,10)); + topPanel.add(imagePanel, BorderLayout.WEST); + topPanel.add(verticalPanel, BorderLayout.CENTER); + topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); //中间的文本域面板 centerPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); - centerPanel.setBorder(BorderFactory.createEmptyBorder(0,10,10,10)); - centerPanel.setPreferredSize(new Dimension(480,320)); - - JLabel titleLabel = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Affected_Function")); - titleLabel.setPreferredSize(new Dimension(400,40)); - JTextArea checkArea = new JTextArea(areaText); - checkArea.setEnabled(false); - centerPanel.add(titleLabel,BorderLayout.NORTH); - centerPanel.add(checkArea,BorderLayout.CENTER); - - //下面的按钮面板 - remindBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remind_Show")); - remindBox.addActionListener(remindCheckboxListener); - UIButton okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Button_Confirm")); - JPanel buttonPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); - buttonPanel.setBorder(BorderFactory.createEmptyBorder(0,10,10,10)); - buttonPanel.add(remindBox, BorderLayout.WEST); - buttonPanel.add(okButton,BorderLayout.EAST); - okButton.addActionListener(this ); - bottomPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); - bottomPanel.add(buttonPanel); + centerPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + centerPanel.setPreferredSize(new Dimension(480, 320)); + + UILabel titleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Details")); + titleLabel.setPreferredSize(new Dimension(400, 40)); + //详情面板 + detailsPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); + detailsPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 0)); + detailsPane.setBackground(Color.WHITE); + + jarCheckTitleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_JAR_Check_title")); + jarCheckTitleLabel.setBackground(Color.WHITE); + + + //插件的检测结果相关面板 + pluginCheckTitleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Plugin_Check_title")); + pluginCheckTitleLabel.setBackground(Color.WHITE); + initPluginsCheckResultPanel(differentPlugins); + + //jar包检测结果相关面板 + initJarCheckResultPanel(remoteBranch, noExistServiceDescription); + + double[] detailsRowSize; + double[] detailsColumnSize = {f}; + + detailsComponents = new Component[][]{{jarCheckTitleLabel}, {jarCheckResultLabel}, {affectedFunctionsLabel}, {affectedFunctionsDetailsPane}, {pluginCheckTitleLabel}, {pluginsCheckResultPanel}}; + hideAffectedFunctionsComponents = new Component[][]{{jarCheckTitleLabel}, {jarCheckResultLabel}, {affectedFunctionsLabel}, {pluginCheckTitleLabel}, {pluginsCheckResultPanel}}; + if (noExistServiceDescription.size() > 0 && !ComparatorUtils.equals(remoteBranch, localBranch)) { + detailsRowSize = new double[]{p, p, p, p,p,p}; + detailsInnerPane = TableLayoutHelper.createTableLayoutPane(detailsComponents, detailsRowSize, detailsColumnSize); + } else { + detailsRowSize = new double[]{p, p, 0, 0, p, p}; + detailsInnerPane = TableLayoutHelper.createTableLayoutPane(detailsComponents, detailsRowSize, detailsColumnSize); + } + detailsInnerPane.setBackground(Color.WHITE); + jScrollPane = new JScrollPane(detailsInnerPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + jScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + detailsPane.add(jScrollPane); + centerPanel.add(titleLabel, BorderLayout.NORTH); + centerPanel.add(detailsPane, BorderLayout.CENTER); + JPanel buttonPanel = FRGUIPaneFactory.createBorderLayout_M_Pane(); + buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + if (isOnline()) { + ignoreButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Sync_Ignore")); + ignoreButton.addActionListener(this); + syncButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Sync_To_Local")); + syncButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Sync_To_Local_Tip")); + syncButton.addMouseListener(syncButtonClickListener); + progressBar = new JProgressBar(); + progressBar.setUI(new MotifProgressBarUI()); + progressBar.setForeground(UpdateConstants.BAR_COLOR); + progressBar.setVisible(false); + progressBar.setStringPainted(true); + progressBar.setPreferredSize(PROGRESSBAR); + buttonPanel.add(ignoreButton, BorderLayout.WEST); + buttonPanel.add(progressBar, BorderLayout.CENTER); + buttonPanel.add(syncButton, BorderLayout.EAST); + } else { + UILabel adviceLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Suggestion")); + centerPanel.add(adviceLabel, BorderLayout.SOUTH); + UIButton okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Button_Confirm")); + okButton.addActionListener(this); + buttonPanel.add(okButton, BorderLayout.EAST); + } this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Title_Hint")); this.setResizable(false); - - this.add(topPanel,BorderLayout.NORTH); + this.add(topPanel, BorderLayout.NORTH); this.add(centerPanel, BorderLayout.CENTER); - this.add(buttonPanel,BorderLayout.SOUTH); - this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US)? 750:600, 500)); - + this.add(buttonPanel, BorderLayout.SOUTH); + this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US) ? 750 : 600, 500)); GUICoreUtils.centerWindow(this); } + + /** + * 插件检测的结果 + */ + private void initPluginsCheckResultPanel(JSONArray differentPlugins) { + + if (differentPlugins.size() > 0) { + int size = differentPlugins.size(); + Component[][] pluginCheckResultComponents = new Component[size][1]; + double[] pluginCheckResultColumnSize = new double[size]; + for (int i = 0; i < size; i++) { + JSONObject plugin = differentPlugins.getJSONObject(i); + JLabel pluginLabel; + if (ComparatorUtils.equals(VersionCheckUtils.INCONSISTENCY, plugin.getString("type"))) { + pluginLabel = new JLabel("\"" + plugin.getString("name") + "\"" + Toolkit.i18nText("Fine-Design_Basic_Sync_Plugin_Inconsistency_Info") + plugin.getString("version")); + } else if (ComparatorUtils.equals(VersionCheckUtils.MISSING, plugin.getString("type"))) { + pluginLabel = new JLabel("\"" + plugin.getString("name") + "\"" + Toolkit.i18nText("Fine-Design_Basic_Sync_Plugin_Missing_Info") + plugin.getString("version")); + } else { + continue; + } + pluginLabel.setIcon(IOUtils.readIcon("com/fr/design/icon/versioncheck/fail.png")); + pluginCheckResultComponents[i][0] = pluginLabel; + pluginCheckResultColumnSize[i] = p; + } + double[] pluginCheckResultRowSize = {f}; + pluginsCheckResultPanel = TableLayoutHelper.createTableLayoutPane(pluginCheckResultComponents, pluginCheckResultColumnSize, pluginCheckResultRowSize); + } else { + UILabel pluginCheckResultLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Plugin_Consistency")); + pluginCheckResultLabel.setIcon(IOUtils.readIcon("com/fr/design/icon/versioncheck/success.png")); + pluginsCheckResultPanel = TableLayoutHelper.createTableLayoutPane(new Component[][]{{pluginCheckResultLabel}}, new double[]{p}, new double[]{f}); + } + pluginsCheckResultPanel.setBackground(Color.WHITE); + } + + /** + * jar包检测的结果 + */ + private void initJarCheckResultPanel(String remoteBranch, List noExistServiceDescription) { + jarCheckResultLabel = new UILabel(); + jarCheckResultLabel.setBackground(Color.WHITE); + if (jarConsistency) { + jarCheckResultLabel.setText(Toolkit.i18nText("Fine-Design_Basic_Sync_JAR_Consistency")); + jarCheckResultLabel.setIcon(IOUtils.readIcon("com/fr/design/icon/versioncheck/success.png")); + } else { + jarCheckResultLabel.setText(Toolkit.i18nText("Fine-Design_Basic_Sync_JAR_Inconsistency_Info") + remoteBranch); + jarCheckResultLabel.setIcon(IOUtils.readIcon("com/fr/design/icon/versioncheck/fail.png")); + Component[][] noExistServiceComponents; + int noExistService = noExistServiceDescription.size(); + if (noExistService > 0) { + affectedFunctionsLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Affected_Function")); + affectedFunctionsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.down")); + affectedFunctionsLabel.setBackground(Color.WHITE); + affectedFunctionsLabel.addMouseListener(affectedFunctionsClickListener); + noExistServiceComponents = new Component[noExistServiceDescription.size()][1]; + double[] noExistServiceColumnSize = new double[noExistService]; + for (int i = 0; i < noExistService; i++) { + JLabel noExitServiceLabel = new JLabel(" " + noExistServiceDescription.get(i)); + noExistServiceComponents[i][0] = noExitServiceLabel; + noExistServiceColumnSize[i] = p; + } + double[] noExistServiceRowSize = {f}; + affectedFunctionsDetailsPane = TableLayoutHelper.createTableLayoutPane(noExistServiceComponents, noExistServiceColumnSize, noExistServiceRowSize); + affectedFunctionsDetailsPane.setBackground(Color.WHITE); + } + } + } + @Override public void actionPerformed(ActionEvent e) { this.dispose(); } + private boolean isOnline() { + if (CloudCenterConfig.getInstance().isOnline()) { + String ping = CloudCenter.getInstance().acquireConf("ping", StringUtils.EMPTY); + if (StringUtils.isNotEmpty(ping)) { + try { + return StringUtils.isEmpty(HttpToolbox.get(ping)); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return false; + } + } + } + return false; + } - private ActionListener remindCheckboxListener = new ActionListener() { + private MouseListener affectedFunctionsClickListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (showAffectedFunctions) { + showAffectedFunctions = false; + detailsInnerPane.removeAll(); + affectedFunctionsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.right")); + TableLayoutHelper.addComponent2ResultPane(hideAffectedFunctionsComponents, new double[]{p, p, p, p, p}, new double[]{f}, detailsInnerPane); + jScrollPane.validate(); + jScrollPane.repaint(); + } else { + showAffectedFunctions = true; + detailsInnerPane.removeAll(); + affectedFunctionsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.down")); + TableLayoutHelper.addComponent2ResultPane(detailsComponents, new double[]{p, p, p, p, p, p}, new double[]{f}, detailsInnerPane); + jScrollPane.validate(); + jScrollPane.repaint(); + } + } + }; + private MouseListener syncButtonClickListener = new MouseAdapter() { @Override - public void actionPerformed(ActionEvent e) { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - String remindTime = format.format(new Date()); - //环境已切换,通过当前环境获取,一定是远程环境 - String currentEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); - RemoteDesignerWorkspaceInfo currentEnv = (RemoteDesignerWorkspaceInfo)DesignerEnvManager.getEnvManager().getWorkspaceInfo(currentEnvName); - currentEnv.setRemindTime(remindBox.isSelected()? remindTime : ""); + public void mouseClicked(MouseEvent e) { + String[] option = {Toolkit.i18nText("Fine-Design_Report_Yes"), Toolkit.i18nText("Fine-Design_Report_No")}; + int a = JOptionPane.showOptionDialog(getParent(), Toolkit.i18nText("Fine-Design_Basic_Sync_Info_Information"), + Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_OPTION, QUESTION_MESSAGE, IOUtils.readIcon("com/fr/design/icon/versioncheck/question.png"), option, 1); + if (0 == a) { + //jar包一致的话只更新插件 + UpdateCallBack callBack = new UpdateProgressCallBack(progressBar); + progressBar.setVisible(true); + progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message")); + syncButton.setEnabled(false); + if (!jarConsistency) { + deletePreviousPropertyFile(); + final String installLib = StableUtils.pathJoin(StableUtils.getInstallHome(), ProjectConstants.LOGS_NAME, UpdateConstants.INSTALL_LIB); + final JFrame frame = DesignerContext.getDesignerFrame(); + final RestartHelper helper = new RestartHelper(); + FineProcessContext.getParentPipe().fire(FineProcessEngineEvent.DESTROY); + new FileProcess(callBack, remoteBuildNo) { + @Override + public void onDownloadSuccess() { + deleteForDesignerUpdate(installLib); + //主jar下载成功之后再卸载安装插件 + new SwingWorker() { + + @Override + protected JSONArray doInBackground() { + return VersionCheckUtils.syncPlugins(differentPlugins, callBack); + } + + @Override + protected void done() { + progressBar.setVisible(false); + JSONArray syncFailedPlugins = null; + try { + syncFailedPlugins = get(); + } catch (Exception ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + if (syncFailedPlugins != null && syncFailedPlugins.size() > 0) { + SyncFailedPluginsDialog syncFailedPluginsDialog = new SyncFailedPluginsDialog(DesignerContext.getDesignerFrame(), syncFailedPlugins); + syncFailedPluginsDialog.setVisible(true); + } + helper.restartForUpdate(frame); + } + }.execute(); + } + + @Override + public void onDownloadFailed() { + progressBar.setVisible(false); + deleteForDesignerUpdate(installLib); + ErrorDialog errorDialog = new ErrorDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Sync_Fail")); + errorDialog.setVisible(true); + helper.restartForUpdate(frame); + } + }.execute(); + } else { + //到这边说明主jar是一致的,就只尝试同步插件 + new SwingWorker() { + + @Override + protected JSONArray doInBackground() { + return VersionCheckUtils.syncPlugins(differentPlugins, callBack); + } + + @Override + protected void done() { + progressBar.setVisible(false); + JSONArray syncFailedPlugins = null; + try { + syncFailedPlugins = get(); + } catch (Exception ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + if (syncFailedPlugins != null && syncFailedPlugins.size() > 0) { + SyncFailedPluginsDialog syncFailedPluginsDialog = new SyncFailedPluginsDialog(DesignerContext.getDesignerFrame(), syncFailedPlugins); + syncFailedPluginsDialog.setVisible(true); + } else { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("同步成功"), + Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), + FineJOptionPane.INFORMATION_MESSAGE); + } + close(); + } + }.execute(); + } + } } }; + private boolean deletePreviousPropertyFile() { + File moveFile = new File(RestartHelper.MOVE_FILE); + File delFile = new File(RestartHelper.RECORD_FILE); + if (StableUtils.mkdirs(moveFile) && StableUtils.mkdirs(delFile)) { + return StableUtils.deleteFile(moveFile) && StableUtils.deleteFile(delFile); + } + return false; + } + + private void close() { + this.dispose(); + } + + private void deleteForDesignerUpdate(String installLib) { + File dir = new File(installLib); + CommonUtils.deleteFile(dir); + } } diff --git a/designer-base/src/main/java/com/fr/env/ErrorDialog.java b/designer-base/src/main/java/com/fr/env/ErrorDialog.java new file mode 100644 index 0000000000..be91955f2f --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/ErrorDialog.java @@ -0,0 +1,73 @@ +package com.fr.env; + +import com.fr.design.dialog.link.MessageWithLink; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.CloudCenter; +import com.fr.general.GeneralContext; +import com.fr.general.IOUtils; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Locale; +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JPanel; + +/** + * 主jar下载失败的弹出框 + * + * */ + +public class ErrorDialog extends JDialog implements ActionListener { + public ErrorDialog(Frame parent, String message) { + super(parent, true); + init(message); + } + + private void init(String message){ + //主体内容 + JPanel centerPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + + //带超链的提示信息 + JPanel messagePanel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + messagePanel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); + + MessageWithLink messageWithLink = new MessageWithLink(message + ",", Toolkit.i18nText("Fine-Design_Basic_Sync_Help"), CloudCenter.getInstance().acquireUrlByKind("help.replacejars", "https://help.fanruan.com/finereport/doc-view-3268.html")); + messageWithLink.setPreferredSize(new Dimension(108, 20)); + JPanel messageLinkPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + messageLinkPane.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 0)); + messageLinkPane.add(messageWithLink); + + //错误提示图标 + UILabel imageLabel = new UILabel(IOUtils.readIcon("com/fr/design/icon/versioncheck/bigfail.png")); + messagePanel.add(imageLabel); + messagePanel.add(messageLinkPane); + + //确定按钮 + UIButton ok = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Button_OK")); + ok.addActionListener(this); + ok.setSize(new Dimension(44, 20)); + JPanel okPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + okPanel.add(ok); + + centerPanel.add(messagePanel, BorderLayout.CENTER); + centerPanel.add(okPanel, BorderLayout.SOUTH); + + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Tool_Tips")); + this.setResizable(false); + this.add(centerPanel, BorderLayout.CENTER); + this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US) ? 282 : 262, 118)); + GUICoreUtils.centerWindow(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + this.dispose(); + } +} diff --git a/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java b/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java new file mode 100644 index 0000000000..1171e05728 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java @@ -0,0 +1,119 @@ +package com.fr.env; + +import com.fr.design.RestartHelper; +import com.fr.design.dialog.link.MessageWithLink; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextarea.UITextArea; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.CloudCenter; +import com.fr.general.GeneralContext; +import com.fr.general.IOUtils; +import com.fr.json.JSONArray; +import com.fr.json.JSONObject; +import com.fr.stable.StringUtils; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Locale; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.UIManager; + +/** + * @author pengda + * @version 10.0 + * Created by Bryant on 2021-06-02 + */ +public class SyncFailedPluginsDialog extends JDialog { + private UILabel detailsLabel; + private JScrollPane scrollPane; + public SyncFailedPluginsDialog(Frame parent, JSONArray syncFailedPlugins) { + super(parent, true); + JPanel body = FRGUIPaneFactory.createBorderLayout_L_Pane(); + + JPanel northPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + northPane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); + JPanel imagePanel = new JPanel(); + Icon icon = IOUtils.readIcon("com/fr/design/icon/versioncheck/warning.png"); + JLabel imageLabel = new JLabel(); + imageLabel.setIcon(icon); + imagePanel.add(imageLabel); + imagePanel.setPreferredSize(new Dimension(20, 20)); + + JPanel messagePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + MessageWithLink messageWithLink = new MessageWithLink(Toolkit.i18nText("Fine-Design_Basic_Sync_Plugin_Fail_Suggestion"),Toolkit.i18nText("Fine-Design_Basic_Sync_Deal_Immediately"), + CloudCenter.getInstance().acquireUrlByKind("help.installplugins", "https://help.fanruan.com/finereport/doc-view-2198.html")); + messageWithLink.setPreferredSize(new Dimension(316, 20)); + + messagePane.add(messageWithLink); + messagePane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0)); + + northPane.add(imageLabel, BorderLayout.WEST); + northPane.add(messagePane, BorderLayout.CENTER); + + JPanel centerPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + detailsLabel = new UILabel(Toolkit.i18nText("Fine_Designer_Look_Detail")); + detailsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.down")); + detailsLabel.addMouseListener(detailsLabelClickListener); + JPanel detailsTitlePanel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + detailsTitlePanel.add(detailsLabel); + detailsTitlePanel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); + + UITextArea detailsTextArea = new UITextArea(); + StringBuilder detailsText = new StringBuilder(StringUtils.EMPTY); + for (int i = 0; i < syncFailedPlugins.size(); i++) { + JSONObject plugin = syncFailedPlugins.getJSONObject(i); + detailsText.append(plugin.getString("name")).append(",").append(Toolkit.i18nText("Fine-Design_Basic_Sync_Server_Version")).append(plugin.getString("version")).append("\n"); + } + detailsTextArea.setText(detailsText.toString()); + scrollPane = new JScrollPane(detailsTextArea); + centerPanel.add(detailsTitlePanel,BorderLayout.NORTH); + centerPanel.add(scrollPane,BorderLayout.CENTER); + + JPanel southPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + UIButton restartButton = new UIButton(Toolkit.i18nText("Fine-Design_Updater_Restart_Designer")); + restartButton.addMouseListener(restartButtonClickListener); + southPane.add(restartButton); + + body.add(northPane,BorderLayout.NORTH); + body.add(centerPanel,BorderLayout.CENTER); + body.add(southPane,BorderLayout.SOUTH); + + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Tool_Tips")); + this.setResizable(false); + this.add(body, BorderLayout.CENTER); + this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US) ? 400 : 380, 225)); + GUICoreUtils.centerWindow(this); + } + + private MouseListener detailsLabelClickListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if(scrollPane.isVisible()){ + scrollPane.setVisible(false); + detailsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.right")); + }else{ + scrollPane.setVisible(true); + detailsLabel.setIcon(UIManager.getIcon("OptionPane.narrow.down")); + } + } + }; + + private MouseListener restartButtonClickListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + RestartHelper.restartForUpdate(DesignerContext.getDesignerFrame()); + } + }; +} diff --git a/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java new file mode 100644 index 0000000000..ebbd3a9beb --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java @@ -0,0 +1,100 @@ +package com.fr.env; + +import com.fr.design.VersionCheckUtils; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralContext; +import com.fr.general.GeneralUtils; +import com.fr.general.IOUtils; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JPanel; + +/** + * @author pengda + * @version 10.0 + * Created by Bryant on 2021-06-02 + */ +public class VersionCheckMessageDialog extends JDialog implements ActionListener { + private UILabel imageLabel; + private UILabel detailLabel; + private JPanel centerPanel; + private JPanel detailPanel; + private JPanel body; + private String envName; + + public VersionCheckMessageDialog(Frame parent, String message, String envName) { + super(parent, true); + this.envName = envName; + init(message); + } + + private void init(String message) { + JPanel imagePanel = new JPanel(); + imageLabel = new UILabel(IOUtils.readIcon("com/fr/design/images/warnings/warning32.png")); + imagePanel.add(imageLabel); + JPanel messagePanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); + UILabel messageText = new UILabel(); + messageText.setText("" + message + ""); + messagePanel.add(messageText); + + centerPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + centerPanel.setBorder(BorderFactory.createEmptyBorder(15, 10, 10, 10)); + centerPanel.add(imagePanel, BorderLayout.WEST); + centerPanel.add(messagePanel, BorderLayout.CENTER); + + detailLabel = new UILabel(); + detailLabel.setText(Toolkit.i18nText("Fine_Designer_Look_Detail")); + detailLabel.setForeground(Color.BLUE); + + detailPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + detailPanel.add(detailLabel, BorderLayout.EAST); + + String localBranch = GeneralUtils.readFullBuildNO(); + String remoteBranch = VersionCheckUtils.getRemoteBranch(envName); + List noExistServiceDescription; + if(ComparatorUtils.equals(localBranch,remoteBranch)) { + noExistServiceDescription = new ArrayList<>(); + }else{ + noExistServiceDescription = VersionCheckUtils.getNoExistServiceDescription(this.envName); + } + detailPanel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + CheckServiceDialog checkServiceDialog = new CheckServiceDialog(DesignerContext.getDesignerFrame(), localBranch, remoteBranch, noExistServiceDescription); + checkServiceDialog.setVisible(true); + } + }); + + body = FRGUIPaneFactory.createBorderLayout_S_Pane(); + body.add(centerPanel, BorderLayout.CENTER); + body.add(detailPanel, BorderLayout.SOUTH); + + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Sync_Prompt")); + this.setResizable(false); + this.add(body, BorderLayout.NORTH); + this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US) ? 300 : 280, 135)); + GUICoreUtils.centerWindow(this); + } + + + @Override + public void actionPerformed(ActionEvent e) { + this.dispose(); + } +} diff --git a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java index 07a1d54f84..090838fd0c 100644 --- a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java +++ b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java @@ -60,7 +60,7 @@ public class EnvChangeEntranceTest { EasyMock.replay(request, selectedEnv, connectionInfo); PowerMock.replayAll(); - entrance.showServiceDialog(selectedEnv); + //entrance.showServiceDialog(selectedEnv); }catch (Exception e){ Assert.fail(); diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java index 0a572e6721..0068c6b47a 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java @@ -2,6 +2,7 @@ package com.fr.start.module; import com.fr.design.DesignerEnvManager; import com.fr.design.EnvChangeEntrance; +import com.fr.design.VersionCheckUtils; import com.fr.design.constants.DesignerLaunchStatus; import com.fr.design.editlock.ConnectionLockChangeChecker; import com.fr.design.editlock.ServerTableDataLockChangeChecker; @@ -9,7 +10,9 @@ import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.LocalDesignerWorkspaceInfo; import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; import com.fr.env.TestConnectionResult; +import com.fr.env.VersionCheckMessageDialog; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -69,7 +72,10 @@ public class DesignerWorkspaceProvider extends Activator { @Override public void on(Event event, Null aNull) { try { - EnvChangeEntrance.getInstance().showServiceDialog(selectEnv); + if(!VersionCheckUtils.versionCheck(selectEnv)){ + VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),selectEnv.getName()); + versionCheckMessageDialog.setVisible(true); + } } catch (Exception e) { FineLoggerFactory.getLogger().warn("Check Service Failed"); } From 3982a473681e2fd9fad2b24536506797d44c6457 Mon Sep 17 00:00:00 2001 From: pengda Date: Wed, 2 Jun 2021 22:57:53 +0800 Subject: [PATCH 2/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/icon/versioncheck/arrowright.png | Bin 0 -> 179 bytes .../com/fr/design/icon/versioncheck/bigfail.png | Bin 0 -> 722 bytes .../com/fr/design/icon/versioncheck/fail.png | Bin 0 -> 377 bytes .../com/fr/design/icon/versioncheck/question.png | Bin 0 -> 1257 bytes .../com/fr/design/icon/versioncheck/success.png | Bin 0 -> 410 bytes .../com/fr/design/icon/versioncheck/warning.png | Bin 0 -> 942 bytes 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/arrowright.png create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/bigfail.png create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/fail.png create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/question.png create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/success.png create mode 100644 designer-base/src/main/resources/com/fr/design/icon/versioncheck/warning.png diff --git a/designer-base/src/main/resources/com/fr/design/icon/versioncheck/arrowright.png b/designer-base/src/main/resources/com/fr/design/icon/versioncheck/arrowright.png new file mode 100644 index 0000000000000000000000000000000000000000..faa3f898dab29b208aa7b174e98938905076ba29 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;8o-U3d z7J|tM5>pZ$9np+CV%5Vr`%wM=f4Ohp&%e{)%NNVDno+>@|LaaemVQQsWDaSk0}O}S z1QHqQoI6YyQaH*SmN548wzlr%z0sp^h~dsGM>Zh?hW%+wYy#JM&Uz;p22C>ZbAF-5 Z$Y3d@_*Hp%|3aXx44$rjF6*2UngBc*ISBv& literal 0 HcmV?d00001 diff --git a/designer-base/src/main/resources/com/fr/design/icon/versioncheck/bigfail.png b/designer-base/src/main/resources/com/fr/design/icon/versioncheck/bigfail.png new file mode 100644 index 0000000000000000000000000000000000000000..0f09b2cba112fd140f171b4bcf8ec8b7b5c47e08 GIT binary patch literal 722 zcmV;@0xkWCP)F%y`Y2zBUv!@ijdunYXps5f@|VEo^Nn2bLZ}T>;tE{cV@oxeRIytoH!A9QXbCDF>{B79-i%Q zzjR~acckFA`cm_dhR;Rla%fPd&rBaGRK0bo*Vzv7DZ!maW0fL$B}6Ae@Hl-X-XlZT z7rWhc-!35tF%f=4A{8Gr@jvq+v#j}|v7im34BOLs7A_8+R=9e}h1WQM-Lomf=(zkZ z900c)vx4?CPIy2ZQQjAa4;sK&K^*-ogX2#g)9KbaRhO5uAa)KIV6&RjU|i}ya`Z6^ z2%@=KjiQ4C`f=wT4L3IvP%Px+v!`U{=jo{5r`?s+#Jt}*#&Z{q%^?10@c;Av11knX z5c{6`VptHcc@0{;Q*XT07+=i;hQ#m`&3TsPeaNW^;hhRLJDR%Ahm&DH6vaHehS>Mp zcjhgYR9AqH$#gND@t0Esmsd65O4#klU>O_Uz-nbwT6F==om zi@oj@;Np9T8bsCiij2pd2Pe3lT`Xu{WUWC+%K|q!^%q>q>0W#A#e(Rd_CO6X3s1oj z)-x$VCyE*baYuiW23v6W#gpUFg=Dw?RtSenm}RN|7ko2VpC~8)YybcN07*qoM6N<$ Eg6-8x4*&oF literal 0 HcmV?d00001 diff --git a/designer-base/src/main/resources/com/fr/design/icon/versioncheck/fail.png b/designer-base/src/main/resources/com/fr/design/icon/versioncheck/fail.png new file mode 100644 index 0000000000000000000000000000000000000000..611cab720ab6912a00cd0eb71cf9f6143b721e4e GIT binary patch literal 377 zcmV-<0fzpGP)5PjyGlbr5S>}0UIZ-!!9qxpKq|p+5NjX5V3|7cBh)&jzhJzj zia%i$&>~-oUQ(3Go zUv7;??@nhAUYf0aq4|}FG#!gKGmn|l>CX810k{cGB;WV4$fF>}N*3m&1Bltmn|(gk z{S<|W@pDnE>?ZUSMca3`w03fw`G|q}0T-GEi5xkI`)x3w&5QF4A)fTla&CbRPleQq z==6GMsf#DQK23)=k%CU!sfzrOaUOi-u|e3A(4M2{$;#88bP~C2uf%w&QDG`|;aRxR z?OIQu!BbH75T7 X6iAVn?w%lT00000NkvXXu0mjf>6)ZA literal 0 HcmV?d00001 diff --git a/designer-base/src/main/resources/com/fr/design/icon/versioncheck/question.png b/designer-base/src/main/resources/com/fr/design/icon/versioncheck/question.png new file mode 100644 index 0000000000000000000000000000000000000000..cf46cd468f8d941fd5c46e521ec74bff7b91e8df GIT binary patch literal 1257 zcmV=P)l*G1|ovm4>EGNmr#U)X+jJMW_^7cDs9z*+q!6vvgrnt`4stOSiGu*O zfjPIbgNOm{;#sM^CqOd`AQU14M`N7;+HxW4OKKo=1~40++(T@oC19Nnm8o+)`{y5q!J?c>b#pbn1UHS zlfeEF#?%dSKv)jo)mlQ!t@=9ai3sEMLB_f3#zU|aKx-B7VvV#c6@P^p9U)F^5hI6X z04lt|q5B9PNge&rRYuj@S4%BcP^!+7bp)N($rCsZcc$0a{AAaLHm zlfe=IYx99a_3DUzI3mz}DRm^@^${LequvHDhXj6~H75G={l5iUpuPlnZ-W}Zo2LbS zzLHwZzPkyVR;vL#Js@x)+cKcc6EALRp(n4-H$KUu+!N0jf;XvPUW+kWj&q`6GHO_o z0eYN`cZhp@lsFBN#}5;XcZLmAZ`Bsi3ZOb4c>69w%__C{uwXoYiVZD*mel|)0DOhO zZXaQdM=hS2v1gd^{oh(<(r4p{El^Vc?5`sf$!hVlF~;6uM(>n9VOp&n0pNoTgt`*7 z_`w;*TSJVouvR(x?Q92dZ!z%xM)eVSa+>kRX~vw;FG|l9wgYId2A*201aLXRcy@qs z-DL5OD1y7z6CS)pnf{-R3Vb}OCyvXvwLJs&`Unk4E${9jVM@hMg~@gRkCp+q6(}>H zcZzZL+VZ2S=StfF=yBEzTU!AX%0O*_T2}o2VARB;@Bb^>3Sd(SurI}3;!l%|U1yE$ z`IpKb7l0Md1D2xiW`Mf|R(K7lE&z5`sc(YL%rd^YY{sFdp3~MMXpO|1ui^r*^AvD1 zzySo@E#Pi}6u%4w`gsS0_`(4hYQ77Sv@_U9U(P=r`foJ%v7bo%YX0i>ufQDJ(&P8` zDFC!~u{^PkLtysV@1ltw5Dk|9Np;FwFn#N;N^syt2 z-V+N>sCv@oV_Yr?(H?(a0HDS91sJF%@Rs!6)3*Q&{4qQIis>yl@xFkNq=P*TG@*Pr zlK$$1g~tC99|$(dFKC?75oVhIx|J3H(J$jg6bRK(#1YCgI$;a|##l5@YUpjCiyGH; zj9KOYh{6(6;KwG)$|E#$0E~{HU;fB3A=T+frU0_8=q2-6K7cGOdd2`Cj76pFEP9y( z$nv6>Ie;uLdYJ(rdN{aQ?$B9i9c`|;2nPD+eB*`r=d!KSOGjTbfOHdO>-YZx&!M4T Tvqru%00000NkvXXu0mjfc{WFI literal 0 HcmV?d00001 diff --git a/designer-base/src/main/resources/com/fr/design/icon/versioncheck/success.png b/designer-base/src/main/resources/com/fr/design/icon/versioncheck/success.png new file mode 100644 index 0000000000000000000000000000000000000000..f88e68ecef2879baf1bcd679f8c7312c4aaa023d GIT binary patch literal 410 zcmV;L0cHM)P)5Pjy-Gt-4E~aHDLP062X%6=;3U3)Ac%iU?I6BDpTWm)b8xGR zlWuoa1i=Ro97O3NE=m`xpdj88lWWu7UMhkYE;-4U?<6Pr2!(IqsyWe(-MuKZt>Ib^ zYBNb%fKNK>p-v1rJH z@j*neD!!Ri-Pxigp@^-zv$kn4M57p#D%gO8qAiMX=g*Pdi8aaYWM(!Sa$o11@B7_z z&$)L9bG&Gd{V^keY%d0lnh|%>K*`X`%z)G8G$E&w#1 z&kS&rqGgP*5TOB>K~_r5m3+k{GeV#Ie!7te90npZfR&7GWTKyu^ zFQdez+d&`#SHRL^KQidUAff=DP&DJCAhCe}%u~^|5OnVO*a2escK}JQ2itJ^cTVuj z%?g^8xN+VO!WV#dKv?x^KY;p)Vp7W)(7YF2|0n;#?s<2L7hjeKj1{y4&U6sI0G6(9 zV&KqJ5oui)sPZ)z;Njn}&wgCs!>~6;v`asf48T7(&bPDjFaxg?0IWF-T2SKx+`j?) z{O3h{_?{fGtLdHJ|MP;FwgRTEb^zE~ELp_%K`eAHLud3)IL4R7J%~D#_{Fb71B|7j zRT7J<0Ol11SouA~qGlIhmm>uVBC6PHhHK@RV zyCGST*kyp;n6`VXKZUexb3Vkreh575_XhD5IcvO08(>e=EdaMo>T!-kM0G8yRBJUPN$+}zA6A1OQ|(7^B{vFfxH*gLcH$Ye$K5f;Qmmc zG=Q@LJp#Yi@K)!A*ik9i6@z-t;Ky4U+GQ Date: Wed, 2 Jun 2021 23:18:27 +0800 Subject: [PATCH 3/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/VersionCheckUtils.java | 2 +- .../src/main/java/com/fr/env/SyncFailedPluginsDialog.java | 2 +- .../src/main/java/com/fr/env/VersionCheckMessageDialog.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index 2af000f86b..8492dadf55 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -55,7 +55,7 @@ import java.util.concurrent.CountDownLatch; /** * @author pengda * @version 10.0 - * Created by Bryant on 2021-06-02 + * Created on 2021-06-02 */ public class VersionCheckUtils { private static final String SYNCPLUGINLIB = StableUtils.getInstallHome() + "/logs/syncLib/plugins/"; diff --git a/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java b/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java index 1171e05728..b9046e1535 100644 --- a/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java +++ b/designer-base/src/main/java/com/fr/env/SyncFailedPluginsDialog.java @@ -33,7 +33,7 @@ import javax.swing.UIManager; /** * @author pengda * @version 10.0 - * Created by Bryant on 2021-06-02 + * Created on 2021-06-02 */ public class SyncFailedPluginsDialog extends JDialog { private UILabel detailsLabel; diff --git a/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java index ebbd3a9beb..6232c05d55 100644 --- a/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java +++ b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java @@ -28,7 +28,7 @@ import javax.swing.JPanel; /** * @author pengda * @version 10.0 - * Created by Bryant on 2021-06-02 + * Created on 2021-06-02 */ public class VersionCheckMessageDialog extends JDialog implements ActionListener { private UILabel imageLabel; From 319988ecf58a4bfee926e6fcf8cfccaa078ca153 Mon Sep 17 00:00:00 2001 From: pengda Date: Wed, 2 Jun 2021 23:43:21 +0800 Subject: [PATCH 4/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/VersionCheckUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index 8492dadf55..d823ea6d2e 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -9,6 +9,7 @@ import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.RemoteWorkspace; import com.fr.design.i18n.Toolkit; +import com.fr.general.CloudCenter; import com.fr.general.CommonIOUtils; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; @@ -387,9 +388,7 @@ public class VersionCheckUtils { } version = differentPlugin.getString(VERSION); try { - //url = CloudCenter.getInstance().acquireUrlByKind("sync10.plugin"); - url = "http://192.168.5.83:3008/api/v1/plugin/download/history?pluginId={}&version={}"; - url = StringUtils.messageFormat(url, id, version); + url = StringUtils.messageFormat(CloudCenter.getInstance().acquireUrlByKind("sync10.plugin"), id, version); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } From da6bb600f14f92fa74439ff268ac97b0e8a110ad Mon Sep 17 00:00:00 2001 From: pengda Date: Thu, 3 Jun 2021 14:57:07 +0800 Subject: [PATCH 5/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/VersionCheckUtils.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index d823ea6d2e..754b8a8b18 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -52,6 +52,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; /** * @author pengda @@ -287,6 +288,7 @@ public class VersionCheckUtils { @Override public void updateProgress(String description, double progress) { } + @Override public void done(PluginTaskResult result) { latch.countDown(); @@ -295,9 +297,9 @@ public class VersionCheckUtils { } } try { - latch.await(); + latch.await(5000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } } } @@ -314,6 +316,7 @@ public class VersionCheckUtils { } syncFailedPlugins.add(plugin); } + CommonIOUtils.deleteFile(new File(SYNCLIB)); return syncFailedPlugins; } @@ -378,7 +381,7 @@ public class VersionCheckUtils { JSONObject differentPlugin; String id; String version; - try { + if (differentPlugins != null) { for (int i = 0; i < differentPlugins.size(); i++) { String url = null; differentPlugin = differentPlugins.getJSONObject(i); @@ -392,11 +395,10 @@ public class VersionCheckUtils { } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } - - downloadURL.put(id + "-" + version, url); + if (url != null) { + downloadURL.put(id + "-" + version, url); + } } - } catch (Exception e) { - } return getPluginZipDownloadURL(downloadURL); } @@ -406,6 +408,7 @@ public class VersionCheckUtils { CloseableHttpResponse httpResponse; HttpGet httpGet = new HttpGet(); InputStream in = null; + HashMap downloadURLs = new HashMap<>(); try { for (String idAndVersion : urls.keySet()) { httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); @@ -415,7 +418,7 @@ public class VersionCheckUtils { JSONObject urlJson = new JSONObject(IOUtils.inputStream2String(in)); String downloadURL = urlJson.getString("result"); if (downloadURL != null) { - urls.replace(idAndVersion, urlJson.getString("result")); + downloadURLs.put(idAndVersion,downloadURL); } } } catch (Exception e) { @@ -423,6 +426,6 @@ public class VersionCheckUtils { } finally { CommonIOUtils.close(in); } - return urls; + return downloadURLs; } } From d2b176ccdc482604c37a4ceae090242ee0e3b40f Mon Sep 17 00:00:00 2001 From: pengda Date: Thu, 3 Jun 2021 15:54:28 +0800 Subject: [PATCH 6/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 5 +--- .../java/com/fr/design/VersionCheckUtils.java | 29 ++++++++++++------- .../module/DesignerWorkspaceProvider.java | 7 +---- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index c71dc34716..c5a4a7dd2e 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -97,10 +97,7 @@ public class EnvChangeEntrance { */ public void switch2Env(final String envName) { switch2Env(envName, PopTipStrategy.LATER); - if(!VersionCheckUtils.versionCheck(envName)){ - VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),envName); - versionCheckMessageDialog.setVisible(true); - } + VersionCheckUtils.showVersionCheckDialog(envName); } /** diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index 754b8a8b18..70b95c2dc7 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -9,6 +9,8 @@ import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.RemoteWorkspace; import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.env.VersionCheckMessageDialog; import com.fr.general.CloudCenter; import com.fr.general.CommonIOUtils; import com.fr.general.ComparatorUtils; @@ -45,7 +47,10 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.net.ProtocolException; import java.net.URI; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -78,6 +83,13 @@ public class VersionCheckUtils { return checkLocalAndRemoteJartime(selectedEnv) && checkLocalAndRemotePlugin().size() == 0; } + public static void showVersionCheckDialog(String envName){ + if(!VersionCheckUtils.versionCheck(envName)){ + VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),envName); + versionCheckMessageDialog.setVisible(true); + } + } + public static boolean checkLocalAndRemoteJartime(String envName) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); @@ -197,14 +209,13 @@ public class VersionCheckUtils { /** * 格式化分支版本号 * - * @param branch 初始的分支版本号 + * @param buildNO 初始的分支版本号 * @return 格式化后的版本号 */ - private static String formatBranch(String branch) { - if (branch.contains("#")) { - return branch.substring(branch.lastIndexOf("-") + 1, branch.length() - 13); - } - return branch; + private static String formatBranch(String buildNO) { + Date jarDate = (new SimpleDateFormat("yyyy.MM.dd")).parse(buildNO, new ParsePosition(buildNO.indexOf("-") + 1)); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + return df.format(jarDate); } private static boolean needCheckBranch(DesignerWorkspaceInfo selectedEnv) { @@ -361,12 +372,8 @@ public class VersionCheckUtils { bean.setDownloadLength(totalBytesRead); callBack.updateProgress(bean); } - } catch (ProtocolException e) { - UpdateException exception = new UpdateException(e.getMessage() + " downloadPluginZip Exception in network"); - FineLoggerFactory.getLogger().error(exception.getErrorMessage(), e); } catch (IOException e) { - UpdateException exception = new UpdateException(e.getMessage() + " downloadPluginZip Exception in download"); - FineLoggerFactory.getLogger().error(exception.getErrorMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } } } finally { diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java index 0068c6b47a..4c759822bd 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java @@ -10,9 +10,7 @@ import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.LocalDesignerWorkspaceInfo; import com.fr.design.i18n.Toolkit; -import com.fr.design.mainframe.DesignerContext; import com.fr.env.TestConnectionResult; -import com.fr.env.VersionCheckMessageDialog; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -72,10 +70,7 @@ public class DesignerWorkspaceProvider extends Activator { @Override public void on(Event event, Null aNull) { try { - if(!VersionCheckUtils.versionCheck(selectEnv)){ - VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),selectEnv.getName()); - versionCheckMessageDialog.setVisible(true); - } + VersionCheckUtils.showVersionCheckDialog(selectEnv.getName()); } catch (Exception e) { FineLoggerFactory.getLogger().warn("Check Service Failed"); } From 8fe4ad250f9052d9a9f4f3a6f63b879298d0c81f Mon Sep 17 00:00:00 2001 From: pengda Date: Fri, 4 Jun 2021 10:59:45 +0800 Subject: [PATCH 7/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/VersionCheckUtils.java | 67 +++++-------------- .../fr/design/update/actions/FileProcess.java | 8 +-- .../update/actions/SyncFileProcess.java | 50 ++++++++++++++ .../java/com/fr/env/CheckServiceDialog.java | 7 +- 4 files changed, 70 insertions(+), 62 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index 70b95c2dc7..c3d8d94e22 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -1,10 +1,9 @@ package com.fr.design; import com.fr.base.FRContext; -import com.fr.decision.update.data.UpdateConstants; -import com.fr.decision.update.exception.UpdateException; import com.fr.decision.update.info.UpdateCallBack; import com.fr.decision.update.info.UpdateProcessBean; +import com.fr.decision.update.util.UpdateFileUtils; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.RemoteWorkspace; @@ -83,9 +82,9 @@ public class VersionCheckUtils { return checkLocalAndRemoteJartime(selectedEnv) && checkLocalAndRemotePlugin().size() == 0; } - public static void showVersionCheckDialog(String envName){ - if(!VersionCheckUtils.versionCheck(envName)){ - VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),envName); + public static void showVersionCheckDialog(String envName) { + if (!VersionCheckUtils.versionCheck(envName)) { + VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"), envName); versionCheckMessageDialog.setVisible(true); } } @@ -96,7 +95,7 @@ public class VersionCheckUtils { return checkLocalAndRemoteJartime(selectedEnv); } - public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv){ + public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv) { //是否需要做服务校验 if (needCheckBranch(selectedEnv)) { String localBranch; @@ -334,55 +333,21 @@ public class VersionCheckUtils { private static void downloadPlugins(Map urls, UpdateCallBack callBack) { CommonIOUtils.deleteFile(new File(SYNCLIB)); UpdateProcessBean bean = new UpdateProcessBean(); - FileOutputStream fos = null; - CloseableHttpClient httpClient; - CloseableHttpResponse httpResponse; - HttpGet httpGet = new HttpGet(); - InputStream in = null; - try { - for (String idAndVersion : urls.keySet()) { - try { - httpGet.setURI(URI.create(urls.get(idAndVersion))); - httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); - String target = SYNCPLUGINLIB + idAndVersion + ZIP; - httpResponse = httpClient.execute(httpGet); - if (httpResponse.getStatusLine().getStatusCode() != 200) { - FineLoggerFactory.getLogger().error("download plugin error :" + urls.get(idAndVersion)); - continue; - } - long totalSize = httpResponse.getEntity().getContentLength(); - in = httpResponse.getEntity().getContent(); - //保存文件 - File saveDir = new File(target); - StableUtils.makesureFileExist(saveDir); - bean.setDownloadedFiles(bean.getDownloadedFiles() + 1); - bean.setName(idAndVersion); - bean.setTotalLength((int) totalSize); - bean.setDownloadLength(0); - callBack.updateProgress(bean); - fos = new FileOutputStream(saveDir); - int bytesRead; - int totalBytesRead = 0; - byte[] getData = new byte[UpdateConstants.BYTE]; - while ((bytesRead = in.read(getData)) != -1) { - fos.write(getData, 0, bytesRead); - getData = new byte[UpdateConstants.BYTE]; - totalBytesRead += bytesRead; - bean.setDownloadLength(totalBytesRead); - callBack.updateProgress(bean); - } - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + for (String idAndVersion : urls.keySet()) { + try { + String url = urls.get(idAndVersion); + if (null == url) { + continue; } + String target = SYNCPLUGINLIB + idAndVersion + ZIP; + UpdateFileUtils.downloadFile(url, target, callBack, bean,idAndVersion); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - } finally { - CommonIOUtils.close(fos); - CommonIOUtils.close(in); } } - private static Map getPluginsDownloadURL(JSONArray differentPlugins, Set uninstallFailed) { Map downloadURL = new HashMap<>(); JSONObject differentPlugin; @@ -415,7 +380,7 @@ public class VersionCheckUtils { CloseableHttpResponse httpResponse; HttpGet httpGet = new HttpGet(); InputStream in = null; - HashMap downloadURLs = new HashMap<>(); + HashMap downloadURLs = new HashMap<>(); try { for (String idAndVersion : urls.keySet()) { httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); @@ -425,7 +390,7 @@ public class VersionCheckUtils { JSONObject urlJson = new JSONObject(IOUtils.inputStream2String(in)); String downloadURL = urlJson.getString("result"); if (downloadURL != null) { - downloadURLs.put(idAndVersion,downloadURL); + downloadURLs.put(idAndVersion, downloadURL); } } } catch (Exception e) { diff --git a/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java b/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java index c9556bd77d..2ed0801dca 100644 --- a/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java +++ b/designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java @@ -15,20 +15,14 @@ import java.util.concurrent.ExecutionException; public abstract class FileProcess extends SwingWorker { private UpdateCallBack callBack; - private String fullBuildNo = null; public FileProcess(UpdateCallBack callBack) { this.callBack = callBack; } - public FileProcess(UpdateCallBack callBack,String fullBuildNo) { - this.callBack = callBack; - this.fullBuildNo = fullBuildNo; - } - @Override protected Boolean doInBackground() throws Exception { - return UpdateExecutor.getInstance().execute(callBack,fullBuildNo); + return UpdateExecutor.getInstance().execute(callBack); } @Override diff --git a/designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java b/designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java new file mode 100644 index 0000000000..1614d1084c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java @@ -0,0 +1,50 @@ +package com.fr.design.update.actions; + +import com.fr.decision.update.SyncExecutor; +import com.fr.decision.update.info.UpdateCallBack; +import com.fr.log.FineLoggerFactory; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingWorker; + +public abstract class SyncFileProcess extends SwingWorker { + private UpdateCallBack callBack; + private String buildNo; + + public SyncFileProcess(UpdateCallBack callBack,String buildNo) { + this.callBack = callBack; + this.buildNo = buildNo; + } + + @Override + protected Boolean doInBackground() throws Exception { + return SyncExecutor.getInstance().execute(callBack,buildNo); + } + + @Override + protected void done() { + boolean success = false; + try { + success = get(); + } catch (InterruptedException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + if (success) { + onDownloadSuccess(); + } else { + onDownloadFailed(); + } + } + + /** + * 下载成功 + */ + public abstract void onDownloadSuccess(); + + /** + * 下载失败 + */ + public abstract void onDownloadFailed(); +} diff --git a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index 30c6ec15a9..fc991eddd5 100644 --- a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -13,8 +13,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.update.actions.FileProcess; -import com.fr.design.update.ui.dialog.RestoreResultDialog; +import com.fr.design.update.actions.SyncFileProcess; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.CloudCenter; import com.fr.general.CloudCenterConfig; @@ -327,7 +326,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener { final JFrame frame = DesignerContext.getDesignerFrame(); final RestartHelper helper = new RestartHelper(); FineProcessContext.getParentPipe().fire(FineProcessEngineEvent.DESTROY); - new FileProcess(callBack, remoteBuildNo) { + new SyncFileProcess(callBack, remoteBuildNo) { @Override public void onDownloadSuccess() { deleteForDesignerUpdate(installLib); @@ -389,7 +388,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener { syncFailedPluginsDialog.setVisible(true); } else { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), - Toolkit.i18nText("同步成功"), + Toolkit.i18nText("Fine-Design_Basic_Sync_Success"), Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), FineJOptionPane.INFORMATION_MESSAGE); } From cd749ed515ca896183f7ac767b5ecb82fc9c1ac5 Mon Sep 17 00:00:00 2001 From: pengda Date: Fri, 4 Jun 2021 16:52:08 +0800 Subject: [PATCH 8/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/VersionCheckUtils.java | 188 ++++++------------ .../java/com/fr/env/CheckServiceDialog.java | 8 +- 2 files changed, 68 insertions(+), 128 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java index c3d8d94e22..17dcd51a13 100644 --- a/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/VersionCheckUtils.java @@ -1,37 +1,28 @@ package com.fr.design; import com.fr.base.FRContext; -import com.fr.decision.update.info.UpdateCallBack; -import com.fr.decision.update.info.UpdateProcessBean; -import com.fr.decision.update.util.UpdateFileUtils; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.RemoteWorkspace; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.env.VersionCheckMessageDialog; -import com.fr.general.CloudCenter; -import com.fr.general.CommonIOUtils; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; -import com.fr.general.IOUtils; -import com.fr.general.http.HttpToolbox; import com.fr.invoke.Reflect; import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.locale.InterProviderFactory; import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; +import com.fr.plugin.context.PluginMarker; import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginControllerHelper; import com.fr.plugin.manage.control.PluginTaskCallback; import com.fr.plugin.manage.control.PluginTaskResult; import com.fr.plugin.manage.control.ProgressCallback; import com.fr.rpc.Result; -import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; -import com.fr.third.org.apache.http.client.methods.HttpGet; -import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; import com.fr.workspace.WorkContext; import com.fr.workspace.base.WorkspaceAPI; import com.fr.workspace.connect.WorkspaceConnectionInfo; @@ -39,13 +30,7 @@ import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import com.fr.workspace.engine.exception.WorkspaceConnectionException; import com.fr.workspace.engine.rpc.WorkspaceProxyPool; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Method; -import java.net.ProtocolException; -import java.net.URI; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -64,9 +49,6 @@ import java.util.concurrent.TimeUnit; * Created on 2021-06-02 */ public class VersionCheckUtils { - private static final String SYNCPLUGINLIB = StableUtils.getInstallHome() + "/logs/syncLib/plugins/"; - private static final String SYNCLIB = StableUtils.getInstallHome() + "/logs/syncLib/"; - private static final String ZIP = ".zip"; public static final String INCONSISTENCY = "inconsistency"; public static final String MISSING = "missing"; private static final String ID = "id"; @@ -254,65 +236,68 @@ public class VersionCheckUtils { return differentPlugins; } - public static JSONArray syncPlugins(JSONArray differentPlugins, UpdateCallBack callBack) { + public static JSONArray syncPlugins(JSONArray differentPlugins) { Set uninstallFailed = uninstallPlugins(differentPlugins); - Map downloadURL = getPluginsDownloadURL(differentPlugins, uninstallFailed); - downloadPlugins(downloadURL, callBack); - return installPlugins(differentPlugins); + List plugins = getSyncPlugins(differentPlugins, uninstallFailed); + installPlugins(plugins); + return getPluginsSyncFailed(differentPlugins); + } + + private static List getSyncPlugins(JSONArray differentPlugins, Set uninstallFailed) { + JSONObject differentPlugin; + String id; + String version; + List plugins = new ArrayList<>(); + if (differentPlugins != null) { + for (int i = 0; i < differentPlugins.size(); i++) { + differentPlugin = differentPlugins.getJSONObject(i); + id = differentPlugin.getString(ID); + if (uninstallFailed.contains(id)) { + continue; + } + version = differentPlugin.getString(VERSION); + plugins.add(PluginMarker.create(id, version)); + } + } + return plugins; } private static Set uninstallPlugins(JSONArray differentPlugins) { + Set pluginsNeedUninstall = new HashSet<>(); Map localPluginsMap = new HashMap<>(); List localPlugins = PluginManager.getContexts(); for (PluginContext pluginContext : localPlugins) { localPluginsMap.put(pluginContext.getID(), pluginContext); } - Set uninstallFailedID = new HashSet<>(); for (int i = 0; i < differentPlugins.size(); i++) { String id = differentPlugins.getJSONObject(i).getString(ID); if (localPluginsMap.containsKey(id)) { - PluginManager.getController().uninstall(localPluginsMap.get(id).getMarker(), true, new PluginTaskCallback() { - @Override - public void done(PluginTaskResult result) { - if (!result.isSuccess()) { - FineLoggerFactory.getLogger().error("uninstall plugin:" + id + " failed"); - uninstallFailedID.add(id); - } - } - }); + pluginsNeedUninstall.add(localPluginsMap.get(id).getMarker()); } } - return uninstallFailedID; - } - - private static JSONArray installPlugins(JSONArray differentPlugins) { - File file = new File(SYNCPLUGINLIB); - JSONArray syncFailedPlugins = JSONArray.create(); - if (file.isDirectory()) { - File[] plugins = file.listFiles(); - if (plugins != null && plugins.length > 0) { - CountDownLatch latch = new CountDownLatch(plugins.length); - for (File plugin : plugins) { - if (plugin.getName().endsWith(ZIP)) { - PluginManager.getController().install(plugin, new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - } - - @Override - public void done(PluginTaskResult result) { - latch.countDown(); - } - }); + Set uninstallFailedID = new HashSet<>(); + CountDownLatch latch = new CountDownLatch(pluginsNeedUninstall.size()); + for (PluginMarker pluginMarker : pluginsNeedUninstall) { + PluginManager.getController().uninstall(pluginMarker, true, new PluginTaskCallback() { + @Override + public void done(PluginTaskResult result) { + latch.countDown(); + if (!result.isSuccess()) { + uninstallFailedID.add(pluginMarker.getPluginID()); } } - try { - latch.await(5000, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } + }); + } + try { + latch.await(5000, TimeUnit.MILLISECONDS); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } + return uninstallFailedID; + } + + private static JSONArray getPluginsSyncFailed(JSONArray differentPlugins){ + JSONArray pluginsNeedSync = JSONArray.create(); List localPlugins = PluginManager.getContexts(); Map localPluginsInfo = new HashMap<>(); for (int i = 0; i < localPlugins.size(); i++) { @@ -324,80 +309,31 @@ public class VersionCheckUtils { if (localPluginsInfo.containsKey(id) && ComparatorUtils.equals(plugin.getString(VERSION), localPluginsInfo.get(id))) { continue; } - syncFailedPlugins.add(plugin); + pluginsNeedSync.add(plugin); } - CommonIOUtils.deleteFile(new File(SYNCLIB)); - return syncFailedPlugins; + return pluginsNeedSync; } - private static void downloadPlugins(Map urls, UpdateCallBack callBack) { - CommonIOUtils.deleteFile(new File(SYNCLIB)); - UpdateProcessBean bean = new UpdateProcessBean(); + private static void installPlugins(List plugins) { + CountDownLatch latch = new CountDownLatch(plugins.size()); + for (int i = 0; i < plugins.size(); i++) { + PluginControllerHelper.installOnline(plugins.get(i), new ProgressCallback() { + @Override + public void updateProgress(String description, double progress) { - for (String idAndVersion : urls.keySet()) { - try { - String url = urls.get(idAndVersion); - if (null == url) { - continue; } - String target = SYNCPLUGINLIB + idAndVersion + ZIP; - UpdateFileUtils.downloadFile(url, target, callBack, bean,idAndVersion); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - } - private static Map getPluginsDownloadURL(JSONArray differentPlugins, Set uninstallFailed) { - Map downloadURL = new HashMap<>(); - JSONObject differentPlugin; - String id; - String version; - if (differentPlugins != null) { - for (int i = 0; i < differentPlugins.size(); i++) { - String url = null; - differentPlugin = differentPlugins.getJSONObject(i); - id = differentPlugin.getString(ID); - if (uninstallFailed.contains(id)) { - continue; - } - version = differentPlugin.getString(VERSION); - try { - url = StringUtils.messageFormat(CloudCenter.getInstance().acquireUrlByKind("sync10.plugin"), id, version); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - if (url != null) { - downloadURL.put(id + "-" + version, url); + @Override + public void done(PluginTaskResult result) { + latch.countDown(); } - } + }); } - return getPluginZipDownloadURL(downloadURL); - } - - private static Map getPluginZipDownloadURL(Map urls) { - CloseableHttpClient httpClient; - CloseableHttpResponse httpResponse; - HttpGet httpGet = new HttpGet(); - InputStream in = null; - HashMap downloadURLs = new HashMap<>(); try { - for (String idAndVersion : urls.keySet()) { - httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion)); - httpGet.setURI(URI.create(urls.get(idAndVersion))); - httpResponse = httpClient.execute(httpGet); - in = httpResponse.getEntity().getContent(); - JSONObject urlJson = new JSONObject(IOUtils.inputStream2String(in)); - String downloadURL = urlJson.getString("result"); - if (downloadURL != null) { - downloadURLs.put(idAndVersion, downloadURL); - } - } - } catch (Exception e) { + latch.await(); + } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); - } finally { - CommonIOUtils.close(in); } - return downloadURLs; + } } diff --git a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index fc991eddd5..b64708659a 100644 --- a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -331,11 +331,13 @@ public class CheckServiceDialog extends JDialog implements ActionListener { public void onDownloadSuccess() { deleteForDesignerUpdate(installLib); //主jar下载成功之后再卸载安装插件 + progressBar.setString(Toolkit.i18nText("Fine-Design_Basic_Sync_Plugins")); + progressBar.setValue(0); new SwingWorker() { @Override protected JSONArray doInBackground() { - return VersionCheckUtils.syncPlugins(differentPlugins, callBack); + return VersionCheckUtils.syncPlugins(differentPlugins); } @Override @@ -367,11 +369,13 @@ public class CheckServiceDialog extends JDialog implements ActionListener { }.execute(); } else { //到这边说明主jar是一致的,就只尝试同步插件 + progressBar.setString(Toolkit.i18nText("Fine-Design_Basic_Sync_Plugins")); + progressBar.setValue(0); new SwingWorker() { @Override protected JSONArray doInBackground() { - return VersionCheckUtils.syncPlugins(differentPlugins, callBack); + return VersionCheckUtils.syncPlugins(differentPlugins); } @Override From 80fdf1f17da3c985fac6ad7d3974bea2cc986ce1 Mon Sep 17 00:00:00 2001 From: pengda Date: Mon, 7 Jun 2021 11:54:36 +0800 Subject: [PATCH 9/9] =?UTF-8?q?REPORT-51958=20=E8=BF=9C=E7=A8=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E5=8F=8A=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/env/CheckServiceDialog.java | 2 +- .../main/java/com/fr/env/VersionCheckMessageDialog.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index b64708659a..3a46126992 100644 --- a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -312,7 +312,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener { @Override public void mouseClicked(MouseEvent e) { String[] option = {Toolkit.i18nText("Fine-Design_Report_Yes"), Toolkit.i18nText("Fine-Design_Report_No")}; - int a = JOptionPane.showOptionDialog(getParent(), Toolkit.i18nText("Fine-Design_Basic_Sync_Info_Information"), + int a = FineJOptionPane.showOptionDialog(getParent(), Toolkit.i18nText("Fine-Design_Basic_Sync_Info_Information"), Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_OPTION, QUESTION_MESSAGE, IOUtils.readIcon("com/fr/design/icon/versioncheck/question.png"), option, 1); if (0 == a) { //jar包一致的话只更新插件 diff --git a/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java index 6232c05d55..657b13e0a3 100644 --- a/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java +++ b/designer-base/src/main/java/com/fr/env/VersionCheckMessageDialog.java @@ -73,9 +73,11 @@ public class VersionCheckMessageDialog extends JDialog implements ActionListener }else{ noExistServiceDescription = VersionCheckUtils.getNoExistServiceDescription(this.envName); } + detailPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { + hideDialog(); CheckServiceDialog checkServiceDialog = new CheckServiceDialog(DesignerContext.getDesignerFrame(), localBranch, remoteBranch, noExistServiceDescription); checkServiceDialog.setVisible(true); } @@ -92,9 +94,12 @@ public class VersionCheckMessageDialog extends JDialog implements ActionListener GUICoreUtils.centerWindow(this); } + private void hideDialog(){ + this.dispose(); + } @Override public void actionPerformed(ActionEvent e) { - this.dispose(); + hideDialog(); } }