Browse Source

无jira sonar修复

research/10.0
Hades 5 years ago
parent
commit
3b54e72008
  1. 15
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 25
      designer-base/src/main/java/com/fr/design/update/actions/FileDownloader.java
  3. 15
      designer-base/src/main/java/com/fr/design/update/factory/DirectoryOperationFactory.java
  4. 31
      designer-base/src/main/java/com/fr/design/update/ui/dialog/EncodingDetect.java
  5. 38
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  6. 19
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java
  7. 20
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java
  8. 18
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java
  9. 20
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManager.java

15
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -41,17 +41,12 @@ public class HistoryTemplateListCache implements CallbackEvent {
private List<JTemplate<?, ?>> historyList; private List<JTemplate<?, ?>> historyList;
private JTemplate<?, ?> editingTemplate; private JTemplate<?, ?> editingTemplate;
private static volatile HistoryTemplateListCache instacne;
public static HistoryTemplateListCache getInstance() { public static HistoryTemplateListCache getInstance() {
if (instacne == null) { return Holder.INSTANCE;
synchronized (HistoryTemplateListCache.class) { }
if (instacne == null) {
instacne = new HistoryTemplateListCache(); private static class Holder {
} private static final HistoryTemplateListCache INSTANCE = new HistoryTemplateListCache();
}
}
return instacne;
} }
private HistoryTemplateListCache() { private HistoryTemplateListCache() {

25
designer-base/src/main/java/com/fr/design/update/actions/FileDownloader.java

@ -80,22 +80,21 @@ public abstract class FileDownloader extends SwingWorker<Boolean, DownloadItem>
URLConnection connection = url.openConnection(); URLConnection connection = url.openConnection();
int total = connection.getContentLength(); int total = connection.getContentLength();
item.setTotalLength(total); item.setTotalLength(total);
InputStream reader = connection.getInputStream();
File tempFile = new File(StableUtils.pathJoin(saveDir, item.getName())); File tempFile = new File(StableUtils.pathJoin(saveDir, item.getName()));
StableUtils.makesureFileExist(tempFile); StableUtils.makesureFileExist(tempFile);
FileOutputStream writer = new FileOutputStream(tempFile); try ( InputStream reader = connection.getInputStream();
byte[] buffer = new byte[UpdateConstants.BYTE]; FileOutputStream writer = new FileOutputStream(tempFile)) {
int bytesRead = 0; byte[] buffer = new byte[UpdateConstants.BYTE];
int totalBytesRead = 0; int bytesRead = 0;
while ((bytesRead = reader.read(buffer)) != -1) { int totalBytesRead = 0;
writer.write(buffer, 0, bytesRead); while ((bytesRead = reader.read(buffer)) != -1) {
buffer = new byte[UpdateConstants.BYTE]; writer.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead; buffer = new byte[UpdateConstants.BYTE];
item.setDownloadLength(totalBytesRead); totalBytesRead += bytesRead;
publish(item); item.setDownloadLength(totalBytesRead);
publish(item);
}
} }
reader.close();
writer.close();
} }
/** /**

15
designer-base/src/main/java/com/fr/design/update/factory/DirectoryOperationFactory.java

@ -82,15 +82,12 @@ public class DirectoryOperationFactory {
} }
private static void copy(String path1, String path2) throws IOException { private static void copy(String path1, String path2) throws IOException {
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(path1))); try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(path1)));
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path2))); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path2)))) {
byte[] date = new byte[in.available()]; byte[] date = new byte[in.available()];
in.read(date);
in.read(date); out.write(date);
out.write(date); }
in.close();
out.close();
} }
/** /**

31
designer-base/src/main/java/com/fr/design/update/ui/dialog/EncodingDetect.java

@ -11,12 +11,12 @@ import java.io.FileInputStream;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* EncodingDetect.java<br> * EncodingDetect.java<br>
* 自动获取文件的编码 * 自动获取文件的编码
* @author Mata * @author Mata
* @since Create on 2018-08-23 * @since Create on 2018-08-23
* @version 1.0 * @version 1.0
*/ */
public class EncodingDetect { public class EncodingDetect {
/** /**
@ -25,11 +25,11 @@ public class EncodingDetect {
* @return 文件的编码 * @return 文件的编码
*/ */
public static String getJavaEncode(File file){ public static String getJavaEncode(File file){
BytesEncodingDetect s = new BytesEncodingDetect(); BytesEncodingDetect s = new BytesEncodingDetect();
String fileCode = BytesEncodingDetect.javaname[s.detectEncoding(file)]; String fileCode = BytesEncodingDetect.javaname[s.detectEncoding(file)];
return fileCode; return fileCode;
} }
} }
@ -75,17 +75,14 @@ class BytesEncodingDetect extends Encoding {
* type. The encoding type with the highest probability is returned. * type. The encoding type with the highest probability is returned.
*/ */
public int detectEncoding(File testfile) { public int detectEncoding(File testfile) {
FileInputStream chinesefile; byte[] rawtext = new byte[(int) testfile.length()];
byte[] rawtext; try(FileInputStream chinesefile = new FileInputStream(testfile)) {
rawtext = new byte[(int) testfile.length()]; chinesefile.read(rawtext);
try { chinesefile.close();
chinesefile = new FileInputStream(testfile); } catch (Exception e) {
chinesefile.read(rawtext); System.err.println("Error: " + e);
chinesefile.close(); }
} catch (Exception e) { return detectEncoding(rawtext);
System.err.println("Error: " + e);
}
return detectEncoding(rawtext);
} }
/** /**
@ -647,7 +644,7 @@ class BytesEncodingDetect extends Encoding {
* (byte)0xDF) == rawtext[i]) { // Two bytes if (i+1 < rawtextlen && (rawtext[i+1] & (byte)0xBF) == rawtext[i+1]) { * (byte)0xDF) == rawtext[i]) { // Two bytes if (i+1 < rawtextlen && (rawtext[i+1] & (byte)0xBF) == rawtext[i+1]) {
* goodbytes += 2; i++; } } else if ((rawtext[i] & (byte)0xEF) == rawtext[i]) { // Three bytes if (i+2 < rawtextlen && * goodbytes += 2; i++; } } else if ((rawtext[i] & (byte)0xEF) == rawtext[i]) { // Three bytes if (i+2 < rawtextlen &&
* (rawtext[i+1] & (byte)0xBF) == rawtext[i+1] && (rawtext[i+2] & (byte)0xBF) == rawtext[i+2]) { goodbytes += 3; i+=2; } } } * (rawtext[i+1] & (byte)0xBF) == rawtext[i+1] && (rawtext[i+2] & (byte)0xBF) == rawtext[i+2]) { goodbytes += 3; i+=2; } } }
* *
* score = (int)(100 * ((float)goodbytes/(float)rawtext.length)); // An all ASCII file is also a good UTF8 file, but I'd * score = (int)(100 * ((float)goodbytes/(float)rawtext.length)); // An all ASCII file is also a good UTF8 file, but I'd
* rather it // get identified as ASCII. Can delete following 3 lines otherwise if (goodbytes == asciibytes) { score = 0; } // * rather it // get identified as ASCII. Can delete following 3 lines otherwise if (goodbytes == asciibytes) { score = 0; } //
* If not above 90, reduce to zero to prevent coincidental matches if (score > 90) { return score; } else { return 0; } * If not above 90, reduce to zero to prevent coincidental matches if (score > 90) { return score; } else { return 0; }
@ -4551,5 +4548,5 @@ class BytesEncodingDetect extends Encoding {
nicename[ASCII] = "ASCII"; nicename[ASCII] = "ASCII";
nicename[OTHER] = "OTHER"; nicename[OTHER] = "OTHER";
} }
} }

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

@ -468,30 +468,28 @@ public class UpdateMainDialog extends UIDialog {
return; return;
} }
if (cacheFile.exists()) { if (cacheFile.exists()) {
InputStreamReader streamReader = new InputStreamReader(new FileInputStream(cacheFile), "UTF-8"); try (InputStreamReader streamReader = new InputStreamReader(new FileInputStream(cacheFile), "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) { String[] updateInfo = readStr.split("\\t");
String[] updateInfo = readStr.split("\\t"); if (updateInfo.length == 2) {
if (updateInfo.length == 2) { updateTimeStr = updateInfo[0];
updateTimeStr = updateInfo[0]; Date updateTime = CHANGELOG_FORMAT.parse(updateTimeStr);
Date updateTime = CHANGELOG_FORMAT.parse(updateTimeStr); //形如 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 (!ComparatorUtils.equals(keyword, StringUtils.EMPTY)) {
if (!ComparatorUtils.equals(keyword, StringUtils.EMPTY)) { if (!containsKeyword(UPDATE_INFO_TABLE_FORMAT.format(updateTime), keyword) && !containsKeyword(updateInfo[1], keyword)) {
if (!containsKeyword(UPDATE_INFO_TABLE_FORMAT.format(updateTime), keyword) && !containsKeyword(updateInfo[1], keyword)) { continue;
continue; }
}
if (isValidLogInfo(updateInfo[1])) {
updateInfoList.add(new Object[]{UPDATE_INFO_TABLE_FORMAT.format(updateTime), updateInfo[1], updateTime.after(curJarDate)});
} }
}
if (isValidLogInfo(updateInfo[1])) {
updateInfoList.add(new Object[]{UPDATE_INFO_TABLE_FORMAT.format(updateTime), updateInfo[1], updateTime.after(curJarDate)});
} }
} }
} }
br.close();
streamReader.close();
} }
} }

19
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java

@ -27,21 +27,20 @@ import java.net.URLEncoder;
* Created by XiaXiang on 2017/3/27. * Created by XiaXiang on 2017/3/27.
*/ */
public class PluginSearchManager implements AlphaFineSearchProvider { public class PluginSearchManager implements AlphaFineSearchProvider {
private static volatile PluginSearchManager instance;
private SearchResult lessModelList; private SearchResult lessModelList;
private SearchResult moreModelList; private SearchResult moreModelList;
private PluginSearchManager() {
}
public static PluginSearchManager getInstance() { public static PluginSearchManager getInstance() {
if (instance == null) { return Holder.INSTANCE;
synchronized (PluginSearchManager.class) {
if (instance == null) { }
instance = new PluginSearchManager();
}
}
}
return instance;
private static class Holder {
private static final PluginSearchManager INSTANCE = new PluginSearchManager();
} }
private static boolean isCompatibleCurrentEnv(String envVersion) { private static boolean isCompatibleCurrentEnv(String envVersion) {
@ -105,7 +104,7 @@ public class PluginSearchManager implements AlphaFineSearchProvider {
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Plugin_Addon"))); lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Plugin_Addon")));
return lessModelList; return lessModelList;
} }
SearchResult noConnectList = AlphaFineHelper.getNoConnectList(instance); SearchResult noConnectList = AlphaFineHelper.getNoConnectList(Holder.INSTANCE);
if(noConnectList != null){ if(noConnectList != null){
return noConnectList; return noConnectList;
} }

20
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

@ -25,22 +25,22 @@ import java.util.List;
* Created by XiaXiang on 2017/3/31. * Created by XiaXiang on 2017/3/31.
*/ */
public class RecommendSearchManager implements AlphaFineSearchProvider { public class RecommendSearchManager implements AlphaFineSearchProvider {
private static volatile RecommendSearchManager instance;
private SearchResult modelList = new SearchResult(); private SearchResult modelList = new SearchResult();
private SearchResult recommendModelList = new SearchResult(); private SearchResult recommendModelList = new SearchResult();
private SearchResult complementAdviceModelList; private SearchResult complementAdviceModelList;
private SearchResult moreModelList = new SearchResult(); private SearchResult moreModelList = new SearchResult();
private RecommendSearchManager() {
}
public static RecommendSearchManager getInstance() { public static RecommendSearchManager getInstance() {
if (instance == null) { return Holder.INSTANCE;
synchronized (RecentSearchManager.class) { }
if (instance == null) {
instance = new RecommendSearchManager(); private static class Holder {
} private static final RecommendSearchManager INSTANCE = new RecommendSearchManager();
}
}
return instance;
} }
@Override @Override
@ -51,7 +51,7 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
if (ArrayUtils.isEmpty(searchText)) { if (ArrayUtils.isEmpty(searchText)) {
return new SearchResult(); return new SearchResult();
} }
SearchResult noConnectList = AlphaFineHelper.getNoConnectList(instance); SearchResult noConnectList = AlphaFineHelper.getNoConnectList(Holder.INSTANCE);
if (noConnectList != null) { if (noConnectList != null) {
return noConnectList; return noConnectList;
} }

18
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java

@ -13,18 +13,18 @@ import java.util.regex.Pattern;
* Created by alex.sung on 2018/8/3. * Created by alex.sung on 2018/8/3.
*/ */
public class SegmentationManager { public class SegmentationManager {
private static volatile SegmentationManager segmentationManager = null;
private static final int MAX_CHINESE_CHARACTERS_NUM = 4; private static final int MAX_CHINESE_CHARACTERS_NUM = 4;
private SegmentationManager() {
}
public static SegmentationManager getInstance() { public static SegmentationManager getInstance() {
if (segmentationManager == null) { return Holder.INSTANCE;
synchronized (SegmentationManager.class) { }
if (segmentationManager == null) {
segmentationManager = new SegmentationManager(); private static class Holder {
} private static final SegmentationManager INSTANCE = new SegmentationManager();
}
}
return segmentationManager;
} }
/** /**

20
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManager.java

@ -18,19 +18,19 @@ import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
* Created by alex.sung on 2018/8/3. * Created by alex.sung on 2018/8/3.
*/ */
public class SimilarSearchManager implements AlphaFineSearchProvider { public class SimilarSearchManager implements AlphaFineSearchProvider {
private static volatile SimilarSearchManager instance;
private SearchResult lessModelList; private SearchResult lessModelList;
private SearchResult moreModelList = new SearchResult(); private SearchResult moreModelList = new SearchResult();
private SimilarSearchManager() {
}
public static SimilarSearchManager getInstance() { public static SimilarSearchManager getInstance() {
if (instance == null) { return Holder.INSTANCE;
synchronized (SimilarSearchManager.class) { }
if (instance == null) {
instance = new SimilarSearchManager(); private static class Holder {
} private static final SimilarSearchManager INSTANCE = new SimilarSearchManager();
}
}
return instance;
} }
@Override @Override
@ -40,7 +40,7 @@ public class SimilarSearchManager implements AlphaFineSearchProvider {
if (ArrayUtils.isEmpty(searchText)) { if (ArrayUtils.isEmpty(searchText)) {
return new SearchResult(); return new SearchResult();
} }
SearchResult noConnectList = AlphaFineHelper.getNoConnectList(instance); SearchResult noConnectList = AlphaFineHelper.getNoConnectList(Holder.INSTANCE);
if (noConnectList != null) { if (noConnectList != null) {
return noConnectList; return noConnectList;
} }

Loading…
Cancel
Save