Browse Source

Merge pull request #1158 in DESIGN/design from ~BRYANT/design:feature/10.0 to feature/10.0

* commit '466f27cd185057174ee6b45cd3ffeafa9aa3956e':
  KERNEL-418 更新升级重构
research/11.0
Bryant 5 years ago
parent
commit
eea689ba0f
  1. 6
      designer-base/src/main/java/com/fr/design/update/domain/UpdateConstants.java
  2. 87
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  3. 2
      designer-base/src/main/java/com/fr/design/upm/UpmShowDialog.java
  4. 32
      designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java

6
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 CHANGELOG_X_START = "2018-07-11";
String DEFAULT_APP_NAME = "FineReport"; String DEFAULT_APP_NAME = "FineReport";
String DOWNLOAD_DIR = "update";
String DESIGNER_BACKUP_DIR = "designerbackup"; String DESIGNER_BACKUP_DIR = "designerbackup";
String UPDATE_CACHE_CONFIG_X = "updateCacheConfig10"; String UPDATE_CACHE_CONFIG_X = "updateCacheConfig10";
String UPDATE_CACHE_INFO_X = "updateCacheInfo10"; String UPDATE_CACHE_INFO_X = "updateCacheInfo10";
String JXBROWSER = "jxbrowser";
int BYTE = 153600;
List<String> JARS_FOR_SERVER_X = Collections.unmodifiableList(Arrays.asList(new String[]{ List<String> JARS_FOR_SERVER_X = Collections.unmodifiableList(Arrays.asList(new String[]{
"fine-activator-10.0.jar", "fine-activator-10.0.jar",
@ -51,8 +49,6 @@ public interface UpdateConstants {
"fine-report-designer-10.0.jar", "fine-report-designer-10.0.jar",
"aspectjrt.jar" "aspectjrt.jar"
})); }));
List<String> LOG_TYPE = Collections.unmodifiableList(Arrays.asList(new String[]{ List<String> LOG_TYPE = Collections.unmodifiableList(Arrays.asList(new String[]{
"REPORT", "MOBILE", "CHART", "PFC", "BI" "REPORT", "MOBILE", "CHART", "PFC", "BI"
})); }));

87
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.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; 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.UpdateInfoTableModel;
import com.fr.design.update.ui.widget.UpdateInfoTextAreaCellRender; import com.fr.design.update.ui.widget.UpdateInfoTextAreaCellRender;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.CloudCenter; import com.fr.general.*;
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.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
@ -39,6 +35,7 @@ import com.fr.stable.EncodeConstants;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.sun.java.swing.plaf.motif.MotifProgressBarUI; import com.sun.java.swing.plaf.motif.MotifProgressBarUI;
@ -46,21 +43,10 @@ import javax.swing.*;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.table.TableRowSorter; import javax.swing.table.TableRowSorter;
import java.awt.BorderLayout; import java.awt.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.BufferedReader; import java.io.*;
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.text.ParsePosition; import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -121,8 +107,6 @@ public class UpdateMainDialog extends UIDialog {
//搜索更新信息关键词文本框 //搜索更新信息关键词文本框
private UITextField searchUpdateInfoKeyword; private UITextField searchUpdateInfoKeyword;
private boolean updateSuccessful;
private UpdateInfoTable updateInfoTable; private UpdateInfoTable updateInfoTable;
private ArrayList<Object[]> updateInfoList; private ArrayList<Object[]> updateInfoList;
@ -248,12 +232,12 @@ public class UpdateMainDialog extends UIDialog {
updateInfoTable.setShowGrid(false); updateInfoTable.setShowGrid(false);
updateInfoTable.setCellSelectionEnabled(false); updateInfoTable.setCellSelectionEnabled(false);
TableRowSorter<UpdateInfoTableModel> sorter = new TableRowSorter<UpdateInfoTableModel>(updateInfoTable.getDataModel()); TableRowSorter<UpdateInfoTableModel> sorter = new TableRowSorter<>(updateInfoTable.getDataModel());
sorter.setSortable(updateTimeColIndex, true); sorter.setSortable(updateTimeColIndex, true);
sorter.setSortable(updateTitleColIndex, false); sorter.setSortable(updateTitleColIndex, false);
sorter.setSortable(updateSignColIndex, false); sorter.setSortable(updateSignColIndex, false);
updateInfoTable.setRowSorter(sorter); updateInfoTable.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); List<RowSorter.SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new RowSorter.SortKey(updateTimeColIndex, SortOrder.DESCENDING)); sortKeys.add(new RowSorter.SortKey(updateTimeColIndex, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys); sorter.setSortKeys(sortKeys);
@ -367,6 +351,7 @@ public class UpdateMainDialog extends UIDialog {
try { try {
downloadFileConfig = get(); downloadFileConfig = get();
showDownLoadInfo(); showDownLoadInfo();
afterInit();
} catch (InterruptedException e) { } catch (InterruptedException e) {
stopLoading(); stopLoading();
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
@ -380,7 +365,7 @@ public class UpdateMainDialog extends UIDialog {
} }
private SwingWorker<JSONArray, Void> getUpdateInfo(final String keyword) { private SwingWorker<JSONArray, Void> getUpdateInfo(final String keyword) {
updateInfoList = new ArrayList<Object[]>(); updateInfoList = new ArrayList<>();
lastUpdateCacheTime = UpdateConstants.CHANGELOG_X_START; lastUpdateCacheTime = UpdateConstants.CHANGELOG_X_START;
String cacheConfigPath = getUpdateCacheConfig(); String cacheConfigPath = getUpdateCacheConfig();
cacheProperty = new UpdateInfoCachePropertyManager(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), "resources", "offlineres", cacheConfigPath)); cacheProperty = new UpdateInfoCachePropertyManager(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), "resources", "offlineres", cacheConfigPath));
@ -430,7 +415,6 @@ public class UpdateMainDialog extends UIDialog {
getUpdateInfoSuccess = true; getUpdateInfoSuccess = true;
//step4:update cache file,start from cacheRecordTime,end latest server jartime //step4:update cache file,start from cacheRecordTime,end latest server jartime
updateCachedInfoFile(jsonArray); updateCachedInfoFile(jsonArray);
afterInit();
} catch (Exception e) { } catch (Exception e) {
getUpdateInfoSuccess = true; getUpdateInfoSuccess = true;
FineLoggerFactory.getLogger().error(e.getMessage()); 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)}); updateInfoList.add(new Object[]{UPDATE_INFO_TABLE_FORMAT.format(updateTime), updateTitle, updateTime.after(curJarDate)});
} }
} }
return new ArrayList<Object[]>(updateInfoList); return new ArrayList<>(updateInfoList);
} }
private boolean containsKeyword(String str, String keyword) { private boolean containsKeyword(String str, String keyword) {
@ -594,12 +578,12 @@ public class UpdateMainDialog extends UIDialog {
updateButton.addActionListener(new ActionListener() { updateButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (updateSuccessful) { backup();
RestartHelper.restart(); int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"),2);
} else { if (a == 0) {
progressBar.setVisible(true); progressBar.setVisible(true);
progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message"));
UpdateCallBack callBack = new UpdateProgressCallBack(progressBar); UpdateCallBack callBack = new UpdateProgressCallBack(progressBar);
deletePreviousPropertyFile();
updateButton.setEnabled(false); updateButton.setEnabled(false);
updateLabel.setVisible(false); updateLabel.setVisible(false);
new FileProcess(callBack) { new FileProcess(callBack) {
@ -607,12 +591,13 @@ public class UpdateMainDialog extends UIDialog {
public void onDownloadSuccess() { public void onDownloadSuccess() {
updateButton.setEnabled(true); updateButton.setEnabled(true);
progressBar.setVisible(false); progressBar.setVisible(false);
updateSuccessful = true; RestartHelper.restart();
updateButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Restart_Designer"));
} }
@Override @Override
public void onDownloadFailed() { public void onDownloadFailed() {
progressBar.setVisible(false); progressBar.setVisible(false);
JOptionPane.showMessageDialog(getParent(),"Update Failed");
RestartHelper.restart();
} }
}.execute(); }.execute();
} }
@ -621,20 +606,40 @@ public class UpdateMainDialog extends UIDialog {
} }
/** /**
* 确保升级更新之前删除以前的配置文件 * Jar还原按钮兼容
*/ */
public static void deletePreviousPropertyFile() { private void backup() {
//在进行更新升级之前确保move和delete.properties删除 String installHome = StableUtils.getInstallHome();
File moveFile = new File(RestartHelper.MOVE_FILE); //jar包备份文件的目录为"backup/"+jar包当前版本号
File delFile = new File(RestartHelper.RECORD_FILE); String todayBackupDir = StableUtils.pathJoin(installHome, getBackupDirectory(), (GeneralUtils.readBuildNO()));
if ((moveFile.exists()) && (!moveFile.delete())) { backupFilesFromInstallEnv(installHome, todayBackupDir, UpdateConstants.JARS_FOR_SERVER_X);
FineLoggerFactory.getLogger().error(RestartHelper.MOVE_FILE + "delete failed!"); backupFilesFromInstallLib(installHome, todayBackupDir, UpdateConstants.JARS_FOR_DESIGNER_X);
jarCurrentLabel.setText(downloadFileConfig.optString("buildNO"));
}
private void backupFilesFromInstallEnv(String installHome, String todayBackupDir, List<String> 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());
} }
if ((delFile.exists()) && (!delFile.delete())) {
FineLoggerFactory.getLogger().error(RestartHelper.RECORD_FILE + "delete failed!");
} }
} }
private void backupFilesFromInstallLib(String installHome, String todayBackupDir, List<String> 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() { private String getBackupDirectory() {

2
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.BasicPane;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.StableUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -30,5 +29,6 @@ public class UpmShowDialog extends UIDialog {
@Override @Override
public void checkValid() throws Exception { public void checkValid() throws Exception {
} }
} }

32
designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java

@ -1,16 +1,26 @@
package com.fr.design.upm; package com.fr.design.upm;
import com.fr.design.dialog.BasicPane; 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.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.design.upm.event.DownloadEvent;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
import com.fr.event.Listener; 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.JSValue;
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
/** /**
* @author richie * @author richie
@ -27,8 +37,22 @@ public class UpmShowPane extends BasicPane {
return "UPM"; return "UPM";
} }
public UpmShowPane() { UpmShowPane() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
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()) { if (UpmFinder.checkUPMResourcesExist()) {
modernUIPane = new ModernUIPane.Builder<>() modernUIPane = new ModernUIPane.Builder<>()
.prepare(new ScriptContextAdapter() { .prepare(new ScriptContextAdapter() {
@ -63,6 +87,12 @@ public class UpmShowPane extends BasicPane {
} }
}); });
} }
} else {
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); add(modernUIPane, BorderLayout.CENTER);
} }

Loading…
Cancel
Save