From 466f27cd185057174ee6b45cd3ffeafa9aa3956e Mon Sep 17 00:00:00 2001 From: Bryant Date: Fri, 27 Sep 2019 17:56:13 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-418=20=E6=9B=B4=E6=96=B0=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/update/domain/UpdateConstants.java | 6 +- .../update/ui/dialog/UpdateMainDialog.java | 89 +++++++++--------- .../java/com/fr/design/upm/UpmShowDialog.java | 2 +- .../java/com/fr/design/upm/UpmShowPane.java | 94 ++++++++++++------- 4 files changed, 111 insertions(+), 80 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/update/domain/UpdateConstants.java b/designer-base/src/main/java/com/fr/design/update/domain/UpdateConstants.java index 737deafe6..54522c5f7 100644 --- a/designer-base/src/main/java/com/fr/design/update/domain/UpdateConstants.java +++ b/designer-base/src/main/java/com/fr/design/update/domain/UpdateConstants.java @@ -23,14 +23,12 @@ public interface UpdateConstants { String CHANGELOG_X_START = "2018-07-11"; String DEFAULT_APP_NAME = "FineReport"; - String DOWNLOAD_DIR = "update"; String DESIGNER_BACKUP_DIR = "designerbackup"; String UPDATE_CACHE_CONFIG_X = "updateCacheConfig10"; String UPDATE_CACHE_INFO_X = "updateCacheInfo10"; - - int BYTE = 153600; + String JXBROWSER = "jxbrowser"; List JARS_FOR_SERVER_X = Collections.unmodifiableList(Arrays.asList(new String[]{ "fine-activator-10.0.jar", @@ -51,8 +49,6 @@ public interface UpdateConstants { "fine-report-designer-10.0.jar", "aspectjrt.jar" })); - - List LOG_TYPE = Collections.unmodifiableList(Arrays.asList(new String[]{ "REPORT", "MOBILE", "CHART", "PFC", "BI" })); diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java index 9e83e40dd..45728505c 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java @@ -9,6 +9,7 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; @@ -23,12 +24,7 @@ import com.fr.design.update.ui.widget.UpdateInfoTableCellRender; import com.fr.design.update.ui.widget.UpdateInfoTableModel; import com.fr.design.update.ui.widget.UpdateInfoTextAreaCellRender; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.CloudCenter; -import com.fr.general.ComparatorUtils; -import com.fr.general.DateUtils; -import com.fr.general.GeneralContext; -import com.fr.general.GeneralUtils; -import com.fr.general.SiteCenter; +import com.fr.general.*; import com.fr.general.http.HttpClient; import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; @@ -39,6 +35,7 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; import com.sun.java.swing.plaf.motif.MotifProgressBarUI; @@ -46,21 +43,10 @@ import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.table.TableRowSorter; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dialog; -import java.awt.Dimension; -import java.awt.Frame; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; +import java.io.*; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -121,8 +107,6 @@ public class UpdateMainDialog extends UIDialog { //搜索更新信息关键词文本框 private UITextField searchUpdateInfoKeyword; - private boolean updateSuccessful; - private UpdateInfoTable updateInfoTable; private ArrayList updateInfoList; @@ -248,12 +232,12 @@ public class UpdateMainDialog extends UIDialog { updateInfoTable.setShowGrid(false); updateInfoTable.setCellSelectionEnabled(false); - TableRowSorter sorter = new TableRowSorter(updateInfoTable.getDataModel()); + TableRowSorter sorter = new TableRowSorter<>(updateInfoTable.getDataModel()); sorter.setSortable(updateTimeColIndex, true); sorter.setSortable(updateTitleColIndex, false); sorter.setSortable(updateSignColIndex, false); updateInfoTable.setRowSorter(sorter); - List sortKeys = new ArrayList(); + List sortKeys = new ArrayList<>(); sortKeys.add(new RowSorter.SortKey(updateTimeColIndex, SortOrder.DESCENDING)); sorter.setSortKeys(sortKeys); @@ -367,6 +351,7 @@ public class UpdateMainDialog extends UIDialog { try { downloadFileConfig = get(); showDownLoadInfo(); + afterInit(); } catch (InterruptedException e) { stopLoading(); Thread.currentThread().interrupt(); @@ -380,7 +365,7 @@ public class UpdateMainDialog extends UIDialog { } private SwingWorker getUpdateInfo(final String keyword) { - updateInfoList = new ArrayList(); + updateInfoList = new ArrayList<>(); lastUpdateCacheTime = UpdateConstants.CHANGELOG_X_START; String cacheConfigPath = getUpdateCacheConfig(); cacheProperty = new UpdateInfoCachePropertyManager(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), "resources", "offlineres", cacheConfigPath)); @@ -430,7 +415,6 @@ public class UpdateMainDialog extends UIDialog { getUpdateInfoSuccess = true; //step4:update cache file,start from cacheRecordTime,end latest server jartime updateCachedInfoFile(jsonArray); - afterInit(); } catch (Exception e) { getUpdateInfoSuccess = true; FineLoggerFactory.getLogger().error(e.getMessage()); @@ -532,7 +516,7 @@ public class UpdateMainDialog extends UIDialog { updateInfoList.add(new Object[]{UPDATE_INFO_TABLE_FORMAT.format(updateTime), updateTitle, updateTime.after(curJarDate)}); } } - return new ArrayList(updateInfoList); + return new ArrayList<>(updateInfoList); } private boolean containsKeyword(String str, String keyword) { @@ -594,12 +578,12 @@ public class UpdateMainDialog extends UIDialog { updateButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (updateSuccessful) { - RestartHelper.restart(); - } else { + backup(); + int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"),2); + if (a == 0) { progressBar.setVisible(true); + progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message")); UpdateCallBack callBack = new UpdateProgressCallBack(progressBar); - deletePreviousPropertyFile(); updateButton.setEnabled(false); updateLabel.setVisible(false); new FileProcess(callBack) { @@ -607,12 +591,13 @@ public class UpdateMainDialog extends UIDialog { public void onDownloadSuccess() { updateButton.setEnabled(true); progressBar.setVisible(false); - updateSuccessful = true; - updateButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Restart_Designer")); + RestartHelper.restart(); } @Override public void onDownloadFailed() { progressBar.setVisible(false); + JOptionPane.showMessageDialog(getParent(),"Update Failed"); + RestartHelper.restart(); } }.execute(); } @@ -621,20 +606,40 @@ public class UpdateMainDialog extends UIDialog { } /** - * 确保升级更新之前删除以前的配置文件 + * Jar还原按钮兼容 */ - public static void deletePreviousPropertyFile() { - //在进行更新升级之前确保move和delete.properties删除 - File moveFile = new File(RestartHelper.MOVE_FILE); - File delFile = new File(RestartHelper.RECORD_FILE); - if ((moveFile.exists()) && (!moveFile.delete())) { - FineLoggerFactory.getLogger().error(RestartHelper.MOVE_FILE + "delete failed!"); - } - if ((delFile.exists()) && (!delFile.delete())) { - FineLoggerFactory.getLogger().error(RestartHelper.RECORD_FILE + "delete failed!"); + private void backup() { + String installHome = StableUtils.getInstallHome(); + //jar包备份文件的目录为"backup/"+jar包当前版本号 + String todayBackupDir = StableUtils.pathJoin(installHome, getBackupDirectory(), (GeneralUtils.readBuildNO())); + backupFilesFromInstallEnv(installHome, todayBackupDir, UpdateConstants.JARS_FOR_SERVER_X); + backupFilesFromInstallLib(installHome, todayBackupDir, UpdateConstants.JARS_FOR_DESIGNER_X); + jarCurrentLabel.setText(downloadFileConfig.optString("buildNO")); + } + + private void backupFilesFromInstallEnv(String installHome, String todayBackupDir, List files) { + for (String file : files) { + try { + IOUtils.copy( + new File(StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)), + new File(StableUtils.pathJoin(todayBackupDir))); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage()); + } } } + private void backupFilesFromInstallLib(String installHome, String todayBackupDir, List files) { + for (String file : files) { + try { + IOUtils.copy( + new File(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)), + new File(StableUtils.pathJoin(todayBackupDir))); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage()); + } + } + } //获取备份目录 private String getBackupDirectory() { diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmShowDialog.java b/designer-base/src/main/java/com/fr/design/upm/UpmShowDialog.java index 704e01121..d5f132e98 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmShowDialog.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmShowDialog.java @@ -3,7 +3,6 @@ package com.fr.design.upm; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.stable.StableUtils; import javax.swing.*; import java.awt.*; @@ -30,5 +29,6 @@ public class UpmShowDialog extends UIDialog { @Override public void checkValid() throws Exception { + } } diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java b/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java index 57b225920..834600e53 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java @@ -1,16 +1,26 @@ package com.fr.design.upm; import com.fr.design.dialog.BasicPane; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.ui.ModernUIPane; +import com.fr.design.update.domain.UpdateConstants; +import com.fr.design.update.ui.dialog.UpdateMainDialog; import com.fr.design.upm.event.DownloadEvent; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StableUtils; +import com.fr.stable.project.ProjectConstants; import com.teamdev.jxbrowser.chromium.JSValue; import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; +import javax.swing.*; import java.awt.*; +import java.io.File; +import java.io.FileNotFoundException; /** * @author richie @@ -27,41 +37,61 @@ public class UpmShowPane extends BasicPane { return "UPM"; } - public UpmShowPane() { + UpmShowPane() { setLayout(new BorderLayout()); - if (UpmFinder.checkUPMResourcesExist()) { - modernUIPane = new ModernUIPane.Builder<>() - .prepare(new ScriptContextAdapter() { - @Override - public void onScriptContextCreated(ScriptContextEvent event) { - JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); - window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); - } - }) - .withURL(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()) - .build(); - EventDispatcher.listen(DownloadEvent.UPDATE, new Listener() { - @Override - public void on(Event event, String param) { - modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); + boolean flag = false; + File file = new File(StableUtils.pathJoin(StableUtils.getInstallHome(),ProjectConstants.LIB_NAME)); + File[] files = file.listFiles(); + if (files != null) { + for (File file1 : files) { + if (file1.getName().contains(UpdateConstants.JXBROWSER)) { + flag = true; + break; } - }); + } + }else { + FineLoggerFactory.getLogger().error("Designer lib can not be null"); + } + if (flag) { + if (UpmFinder.checkUPMResourcesExist()) { + modernUIPane = new ModernUIPane.Builder<>() + .prepare(new ScriptContextAdapter() { + @Override + public void onScriptContextCreated(ScriptContextEvent event) { + JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); + window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); + } + }) + .withURL(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()) + .build(); + EventDispatcher.listen(DownloadEvent.UPDATE, new Listener() { + @Override + public void on(Event event, String param) { + modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); + } + }); + } else { + modernUIPane = new ModernUIPane.Builder<>() + .withComponent(WarnComponent.KEY) + .prepare(new ScriptContextAdapter() { + @Override + public void onScriptContextCreated(ScriptContextEvent event) { + JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); + window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); + } + }).build(); + EventDispatcher.listen(DownloadEvent.SUCCESS, new Listener() { + @Override + public void on(Event event, String param) { + modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); + } + }); + } } else { - modernUIPane = new ModernUIPane.Builder<>() - .withComponent(WarnComponent.KEY) - .prepare(new ScriptContextAdapter() { - @Override - public void onScriptContextCreated(ScriptContextEvent event) { - JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); - window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); - } - }).build(); - EventDispatcher.listen(DownloadEvent.SUCCESS, new Listener() { - @Override - public void on(Event event, String param) { - modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); - } - }); + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Update_Info_Plugin_Message")); + UpdateMainDialog dialog = new UpdateMainDialog(DesignerContext.getDesignerFrame()); + dialog.setAutoUpdateAfterInit(); + dialog.showDialog(); } add(modernUIPane, BorderLayout.CENTER); }