From 45bfd042154f2cbae33462a18a7ff61cd52febf1 Mon Sep 17 00:00:00 2001 From: "Mata.Li" Date: Mon, 22 Oct 2018 16:49:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20findbugs?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onlineupdate/domain/UpdateConstants.java | 16 +++++---- .../ui/dialog/RestoreResultDialog.java | 5 +-- .../ui/dialog/UpdateMainDialog.java | 36 +++++++++---------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/onlineupdate/domain/UpdateConstants.java b/designer-base/src/main/java/com/fr/design/onlineupdate/domain/UpdateConstants.java index c132dcc03f..853b8576e6 100644 --- a/designer-base/src/main/java/com/fr/design/onlineupdate/domain/UpdateConstants.java +++ b/designer-base/src/main/java/com/fr/design/onlineupdate/domain/UpdateConstants.java @@ -4,7 +4,11 @@ package com.fr.design.onlineupdate.domain; * Created by XINZAI on 2018/8/21. */ +import com.fr.third.org.apache.commons.collections4.collection.UnmodifiableCollection; +import com.fr.third.org.apache.commons.collections4.list.UnmodifiableList; + import java.awt.Color; +import java.util.Arrays; /** * 更新升级的常量 @@ -28,7 +32,7 @@ public interface UpdateConstants { int BYTE = 153600; - String[] JARS_FOR_SERVER_X = new String[]{ + UnmodifiableList JARS_FOR_SERVER_X = new UnmodifiableList(Arrays.asList(new String[]{ "fine-activator-10.0.jar", "fine-core-10.0.jar", "fine-report-engine-10.0.jar", @@ -41,16 +45,16 @@ public interface UpdateConstants { "fine-datasource-10.0.jar", "fine-third-10.0.jar", "fine-accumulator-10.0.jar" - }; + })); - String[] JARS_FOR_DESIGNER_X = new String[]{ + UnmodifiableList JARS_FOR_DESIGNER_X = new UnmodifiableList(Arrays.asList(new String[]{ "fine-report-designer-10.0.jar", "aspectjrt.jar" - }; + })); - String[] LOG_TYPE = new String[]{ + UnmodifiableList LOG_TYPE = new UnmodifiableList(Arrays.asList(new String[]{ "REPORT", "MOBILE", "CHART", "PFC", "BI" - }; + })); } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/RestoreResultDialog.java b/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/RestoreResultDialog.java index 787a88ea87..680d3190dc 100644 --- a/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/RestoreResultDialog.java +++ b/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/RestoreResultDialog.java @@ -27,6 +27,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -161,7 +162,7 @@ public class RestoreResultDialog extends JDialog { } private void putJarBackupFilesToInstallLib(String installHome, Map map, java.util.List list) { - String[] files = UpdateConstants.JARS_FOR_DESIGNER_X; + List files = UpdateConstants.JARS_FOR_DESIGNER_X; String backupDir = UpdateConstants.DESIGNER_BACKUP_DIR; for (String file : files) { map.put(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, file), @@ -171,7 +172,7 @@ public class RestoreResultDialog extends JDialog { } private void putJarBackupFilesToInstallEnv(String installHome, Map map, java.util.List list) { - String[] files = UpdateConstants.JARS_FOR_SERVER_X; + List files = UpdateConstants.JARS_FOR_SERVER_X; String backupDir = UpdateConstants.DESIGNER_BACKUP_DIR; for (String file : files) { map.put(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, file), diff --git a/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/UpdateMainDialog.java index 3f99543a37..e4f44086af 100644 --- a/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/onlineupdate/ui/dialog/UpdateMainDialog.java @@ -58,12 +58,7 @@ import java.awt.Dimension; import java.awt.Frame; 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.FileReader; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -443,8 +438,8 @@ public class UpdateMainDialog extends UIDialog { return; } if (cacheFile.exists()) { - FileReader reader = new FileReader(cacheFile); - BufferedReader br = new BufferedReader(reader); + InputStreamReader streamReader = new InputStreamReader(new FileInputStream(cacheFile), "UTF-8"); + BufferedReader br = new BufferedReader(streamReader); String readStr, updateTimeStr; while ((readStr = br.readLine()) != null) { @@ -466,7 +461,7 @@ public class UpdateMainDialog extends UIDialog { } } br.close(); - reader.close(); + streamReader.close(); } } @@ -490,8 +485,8 @@ public class UpdateMainDialog extends UIDialog { if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) { return; } - FileWriter fileWriter = new FileWriter(cacheFile, true); - BufferedWriter bufferWriter = new BufferedWriter(fileWriter); + OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), "UTF-8"); + BufferedWriter bufferWriter = new BufferedWriter(writerStream); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jo = (JSONObject) jsonArray.get(i); bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title")); @@ -499,7 +494,7 @@ public class UpdateMainDialog extends UIDialog { bufferWriter.flush(); } bufferWriter.close(); - fileWriter.close(); + writerStream.close(); lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS; lastUpdateCacheTime = endTime; cacheProperty.updateProperty("updateTime", lastUpdateCacheTime); @@ -678,7 +673,7 @@ public class UpdateMainDialog extends UIDialog { jarCurrentLabel.setText(downloadFileConfig.optString("buildNO")); } - private void backupFilesFromInstallEnv(String installHome, String todayBackupDir, String[] files) { + private void backupFilesFromInstallEnv(String installHome, String todayBackupDir, List files) { for (String file : files) { try { IOUtils.copy( @@ -690,7 +685,7 @@ public class UpdateMainDialog extends UIDialog { } } - private void backupFilesFromInstallLib(String installHome, String todayBackupDir, String[] files) { + private void backupFilesFromInstallLib(String installHome, String todayBackupDir, List files) { for (String file : files) { try { IOUtils.copy( @@ -734,21 +729,22 @@ public class UpdateMainDialog extends UIDialog { } //获取服务器jar包列表 - private String[] getJARList4Server() { + private List getJARList4Server() { return UpdateConstants.JARS_FOR_SERVER_X; } //获取设计器jar包列表 - private String[] getJARList4Designer() { + private List getJARList4Designer() { return UpdateConstants.JARS_FOR_DESIGNER_X; } //获取服务器jar包下载列表 private String[] getDownLoadJAR4Server() { ArrayList jarList = new ArrayList(); + List serverItems = getJARList4Server(); for (DownloadItem downloadItem : downloadItems) { String downloadItemName = downloadItem.getName(); - if (ArrayUtils.contains(getJARList4Server(), downloadItemName)) { + if (serverItems.contains(downloadItemName)) { jarList.add(downloadItemName); } } @@ -758,9 +754,10 @@ public class UpdateMainDialog extends UIDialog { //获取设计器jar包下载列表 private String[] getDownLoadJAR4Designer() { ArrayList jarList = new ArrayList(); + List designerJarItems = getJARList4Designer(); for (DownloadItem downloadItem : downloadItems) { String downloadItemName = downloadItem.getName(); - if (ArrayUtils.contains(getJARList4Designer(), downloadItemName)) { + if (designerJarItems.contains(downloadItemName)) { jarList.add(downloadItemName); } } @@ -791,7 +788,8 @@ public class UpdateMainDialog extends UIDialog { //判断是否是有效的日志内容 private boolean isValidLogInfo(String logContent) { String log = logContent.toUpperCase(); - for (String s : UpdateConstants.LOG_TYPE) { + List logType = UpdateConstants.LOG_TYPE; + for (String s : logType) { if (log.startsWith(s)) { return true; }