Browse Source

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

* commit '8a56c817a56c004a9a8065c5d9b083e19f549133':
  KERNEL-418 更新升级重构
  KERNEL-418 更新升级重构
  KERNEL-418 更新升级重构
research/11.0
Bryant 5 years ago
parent
commit
d3de555122
  1. 19
      designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java
  2. 54
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  3. 26
      designer-base/src/test/java/com/fr/design/update/ui/dialog/RestoreResultDialogTest.java

19
designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java

@ -12,7 +12,6 @@ import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JDialog; import javax.swing.JDialog;
@ -25,6 +24,7 @@ import java.awt.Font;
import java.awt.Frame; 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.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -92,9 +92,7 @@ public class RestoreResultDialog extends JDialog {
jarProgressLabel.setVisible(true); jarProgressLabel.setVisible(true);
progressLabelPane.add(jarProgressLabel); progressLabelPane.add(jarProgressLabel);
pane.add(progressLabelPane, BorderLayout.CENTER); pane.add(progressLabelPane, BorderLayout.CENTER);
deletePreviousPropertyFile();
UpdateMainDialog.deletePreviousPropertyFile();
putJarBackupFiles(); putJarBackupFiles();
restartButton.setEnabled(true); restartButton.setEnabled(true);
restartLaterButton.setEnabled(true); restartLaterButton.setEnabled(true);
@ -102,6 +100,15 @@ public class RestoreResultDialog extends JDialog {
this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Jar_Restore")); this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Jar_Restore"));
} }
public static 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 initOldVersionRestoreComps() { private void initOldVersionRestoreComps() {
this.setResizable(false); this.setResizable(false);
JPanel pane = new JPanel(); JPanel pane = new JPanel();
@ -151,8 +158,8 @@ public class RestoreResultDialog extends JDialog {
} }
private void putJarBackupFiles() { private void putJarBackupFiles() {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<>();
java.util.List<String> list = new ArrayList<String>(); java.util.List<String> list = new ArrayList<>();
String installHome = StableUtils.getInstallHome(); String installHome = StableUtils.getInstallHome();
putJarBackupFilesToInstallLib(installHome, map, list); putJarBackupFilesToInstallLib(installHome, map, list);

54
designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java

@ -25,7 +25,6 @@ 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.*; import com.fr.general.*;
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;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
@ -36,6 +35,9 @@ 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.stable.project.ProjectConstants;
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.WorkContext;
import com.sun.java.swing.plaf.motif.MotifProgressBarUI; import com.sun.java.swing.plaf.motif.MotifProgressBarUI;
@ -47,6 +49,7 @@ import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -55,6 +58,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import static java.nio.charset.StandardCharsets.*;
/** /**
* Created by XINZAI on 2018/8/21. * Created by XINZAI on 2018/8/21.
*/ */
@ -380,6 +385,8 @@ public class UpdateMainDialog extends UIDialog {
return new SwingWorker<JSONArray, Void>() { return new SwingWorker<JSONArray, Void>() {
@Override @Override
protected JSONArray doInBackground() { protected JSONArray doInBackground() {
CloseableHttpClient httpClient;
CloseableHttpResponse response;
try { try {
getUpdateInfoSuccess = false; getUpdateInfoSuccess = false;
//step1:read from cache file //step1:read from cache file
@ -388,16 +395,15 @@ public class UpdateMainDialog extends UIDialog {
if (downloadFileConfig == null) { if (downloadFileConfig == null) {
throw new Exception("network error."); throw new Exception("network error.");
} }
HttpClient hc = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("changelog10") + "&start=" + lastUpdateCacheTime + "&end=" + getLatestJARTimeStr()); HttpGet get = new HttpGet(CloudCenter.getInstance().acquireUrlByKind("changelog10") + "&start=" + lastUpdateCacheTime + "&end=" + getLatestJARTimeStr());
hc.asGet(); httpClient = HttpToolbox.getHttpClient(CloudCenter.getInstance().acquireUrlByKind("changelog10") + "&start=" + lastUpdateCacheTime + "&end=" + getLatestJARTimeStr());
hc.setTimeout(UpdateConstants.CONNECTION_TIMEOUT * 2); response = httpClient.execute(get);
String responseText = hc.getResponseText(); String responseText = CommonIOUtils.inputStream2String(response.getEntity().getContent(),EncodeConstants.ENCODING_UTF_8).trim();
JSONArray array = JSONArray.create(); JSONArray array = JSONArray.create();
//假如返回"-1",说明socket出错了 //假如返回"-1",说明socket出错了
if (!ComparatorUtils.equals(responseText, "-1")) { if (!ComparatorUtils.equals(responseText, "-1")) {
array = new JSONArray(responseText); array = new JSONArray(responseText);
} }
hc.release();
return array; return array;
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage()); FineLoggerFactory.getLogger().error(e.getMessage());
@ -438,7 +444,7 @@ public class UpdateMainDialog extends UIDialog {
return; return;
} }
if (cacheFile.exists()) { if (cacheFile.exists()) {
try (InputStreamReader streamReader = new InputStreamReader(new FileInputStream(cacheFile), "UTF-8"); try (InputStreamReader streamReader = new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(streamReader)) { BufferedReader br = new BufferedReader(streamReader)) {
String readStr, updateTimeStr; String readStr, updateTimeStr;
while ((readStr = br.readLine()) != null) { while ((readStr = br.readLine()) != null) {
@ -483,13 +489,14 @@ public class UpdateMainDialog extends UIDialog {
if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) { if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) {
return; return;
} }
try (OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), EncodeConstants.ENCODING_UTF_8); try (OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), UTF_8)) {
BufferedWriter bufferWriter = new BufferedWriter(writerStream)) { try (BufferedWriter bufferWriter = new BufferedWriter(writerStream)) {
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = (JSONObject) jsonArray.get(i); JSONObject jo = (JSONObject) jsonArray.get(i);
bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title")); bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title"));
bufferWriter.newLine(); bufferWriter.newLine();
bufferWriter.flush(); bufferWriter.flush();
}
} }
} }
lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS; lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS;
@ -507,6 +514,9 @@ public class UpdateMainDialog extends UIDialog {
//形如 Build#release-2018.07.31.03.03.52.80 //形如 Build#release-2018.07.31.03.03.52.80
String currentNO = GeneralUtils.readBuildNO(); String currentNO = GeneralUtils.readBuildNO();
Date curJarDate = UPDATE_INFO_TABLE_FORMAT.parse(currentNO, new ParsePosition(currentNO.indexOf("-") + 1)); Date curJarDate = UPDATE_INFO_TABLE_FORMAT.parse(currentNO, new ParsePosition(currentNO.indexOf("-") + 1));
if (curJarDate == null) {
curJarDate = updateTime;
}
if (!ComparatorUtils.equals(keyword, StringUtils.EMPTY)) { if (!ComparatorUtils.equals(keyword, StringUtils.EMPTY)) {
if (!containsKeyword(UPDATE_INFO_TABLE_FORMAT.format(updateTime), keyword) && !containsKeyword(updateTitle, keyword)) { if (!containsKeyword(UPDATE_INFO_TABLE_FORMAT.format(updateTime), keyword) && !containsKeyword(updateTitle, keyword)) {
continue; continue;
@ -579,7 +589,7 @@ public class UpdateMainDialog extends UIDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
backup(); backup();
int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"),2); int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"), JOptionPane.OK_CANCEL_OPTION);
if (a == 0) { if (a == 0) {
progressBar.setVisible(true); progressBar.setVisible(true);
progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message")); progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message"));
@ -612,13 +622,13 @@ public class UpdateMainDialog extends UIDialog {
String installHome = StableUtils.getInstallHome(); String installHome = StableUtils.getInstallHome();
//jar包备份文件的目录为"backup/"+jar包当前版本号 //jar包备份文件的目录为"backup/"+jar包当前版本号
String todayBackupDir = StableUtils.pathJoin(installHome, getBackupDirectory(), (GeneralUtils.readBuildNO())); String todayBackupDir = StableUtils.pathJoin(installHome, getBackupDirectory(), (GeneralUtils.readBuildNO()));
backupFilesFromInstallEnv(installHome, todayBackupDir, UpdateConstants.JARS_FOR_SERVER_X); backupFilesFromInstallEnv(installHome, todayBackupDir);
backupFilesFromInstallLib(installHome, todayBackupDir, UpdateConstants.JARS_FOR_DESIGNER_X); backupFilesFromInstallLib(installHome, todayBackupDir);
jarCurrentLabel.setText(downloadFileConfig.optString("buildNO")); jarCurrentLabel.setText(downloadFileConfig.optString("buildNO"));
} }
private void backupFilesFromInstallEnv(String installHome, String todayBackupDir, List<String> files) { private void backupFilesFromInstallEnv(String installHome, String todayBackupDir) {
for (String file : files) { for (String file : UpdateConstants.JARS_FOR_SERVER_X) {
try { try {
IOUtils.copy( IOUtils.copy(
new File(StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)), new File(StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)),
@ -629,8 +639,8 @@ public class UpdateMainDialog extends UIDialog {
} }
} }
private void backupFilesFromInstallLib(String installHome, String todayBackupDir, List<String> files) { private void backupFilesFromInstallLib(String installHome, String todayBackupDir) {
for (String file : files) { for (String file : UpdateConstants.JARS_FOR_DESIGNER_X) {
try { try {
IOUtils.copy( IOUtils.copy(
new File(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)), new File(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)),
@ -692,10 +702,8 @@ public class UpdateMainDialog extends UIDialog {
/** /**
* 检查有效性 * 检查有效性
* *
* @throws Exception
*/ */
@Override @Override
public void checkValid() throws Exception { public void checkValid() throws Exception {
} }
} }

26
designer-base/src/test/java/com/fr/design/update/ui/dialog/RestoreResultDialogTest.java

@ -0,0 +1,26 @@
package com.fr.design.update.ui.dialog;
import com.fr.design.RestartHelper;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
public class RestoreResultDialogTest {
@Test
public void testDeletePreviousPropertyFile() {
File moveFile = new File(RestartHelper.MOVE_FILE);
File recordFile = new File(RestartHelper.RECORD_FILE);
try {
StableUtils.makesureFileExist(moveFile);
StableUtils.makesureFileExist(recordFile);
Assert.assertTrue(RestoreResultDialog.deletePreviousPropertyFile());
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(),e);
}
}
}
Loading…
Cancel
Save