Browse Source

无JIRA任务,sonar问题修复

research/10.0
alex.sung 5 years ago
parent
commit
ed5a2a5347
  1. 13
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 11
      designer-base/src/main/java/com/fr/design/RestartHelper.java
  3. 43
      designer-base/src/main/java/com/fr/design/extra/PluginUtils.java
  4. 10
      designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java
  5. 7
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

13
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -310,8 +310,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
private void createEnvFile(File envFile) { private void createEnvFile(File envFile) {
FileWriter fileWriter = null;
try { try {
FileWriter fileWriter = new FileWriter(envFile); fileWriter = new FileWriter(envFile);
File oldEnvFile = new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "6-1" + "Env.xml"); File oldEnvFile = new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "6-1" + "Env.xml");
File envFile80 = new File(getEnvHome(VERSION_80) + File.separator + getEnvFile().getName()); File envFile80 = new File(getEnvHome(VERSION_80) + File.separator + getEnvFile().getName());
if (oldEnvFile.exists()) { if (oldEnvFile.exists()) {
@ -327,9 +328,17 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
Utils.copyCharTo(stringReader, fileWriter); Utils.copyCharTo(stringReader, fileWriter);
stringReader.close(); stringReader.close();
} }
fileWriter.close();
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if (null != fileWriter) {
try {
fileWriter.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} }
} }

11
designer-base/src/main/java/com/fr/design/RestartHelper.java

@ -154,12 +154,12 @@ public class RestartHelper {
deleteWhenDebug(); deleteWhenDebug();
return; return;
} }
RandomAccessFile randomAccessFile = null;
try { try {
try { try {
File restartLockFile = new File(StableUtils.pathJoin(StableUtils.getInstallHome(), "restart.lock")); File restartLockFile = new File(StableUtils.pathJoin(StableUtils.getInstallHome(), "restart.lock"));
StableUtils.makesureFileExist(restartLockFile); StableUtils.makesureFileExist(restartLockFile);
RandomAccessFile randomAccessFile = new RandomAccessFile(restartLockFile,"rw"); randomAccessFile = new RandomAccessFile(restartLockFile,"rw");
FileChannel restartLockFC = randomAccessFile.getChannel(); FileChannel restartLockFC = randomAccessFile.getChannel();
FileLock restartLock = restartLockFC.tryLock(); FileLock restartLock = restartLockFC.tryLock();
if(restartLock == null) { if(restartLock == null) {
@ -176,6 +176,13 @@ public class RestartHelper {
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally { } finally {
try {
if (null != randomAccessFile) {
randomAccessFile.close();
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
DesignerContext.getDesignerFrame().exit(); DesignerContext.getDesignerFrame().exit();
} }
} }

43
designer-base/src/main/java/com/fr/design/extra/PluginUtils.java

@ -85,24 +85,35 @@ public class PluginUtils {
public static void downloadShopScripts(String id, Process<Double> p) throws Exception { public static void downloadShopScripts(String id, Process<Double> p) throws Exception {
HttpClient httpClient = new HttpClient(getDownloadPath(id)); HttpClient httpClient = new HttpClient(getDownloadPath(id));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
int totalSize = httpClient.getContentLength(); InputStream reader = null;
InputStream reader = httpClient.getResponseStream(); FileOutputStream writer = null;
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); try {
StableUtils.makesureFileExist(new File(temp)); int totalSize = httpClient.getContentLength();
FileOutputStream writer = new FileOutputStream(temp); reader = httpClient.getResponseStream();
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
int bytesRead = 0; StableUtils.makesureFileExist(new File(temp));
int totalBytesRead = 0; writer = new FileOutputStream(temp);
byte[] buffer = new byte[PluginConstants.BYTES_NUM];
int bytesRead = 0;
int totalBytesRead = 0;
while ((bytesRead = reader.read(buffer)) > 0) { while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead); writer.write(buffer, 0, bytesRead);
buffer = new byte[PluginConstants.BYTES_NUM]; buffer = new byte[PluginConstants.BYTES_NUM];
totalBytesRead += bytesRead; totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize); p.process(totalBytesRead / (double) totalSize);
}
}catch (Exception e){
throw new Exception();
}finally {
if(null != reader){
reader.close();
}
if(null != writer){
writer.flush();
writer.close();
}
} }
reader.close();
writer.flush();
writer.close();
} else { } else {
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error"));
} }

10
designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java

@ -174,7 +174,7 @@ public final class FunctionConstants {
jarPath = StringUtils.perfectStart(jarPath, "/"); jarPath = StringUtils.perfectStart(jarPath, "/");
} }
ZipFile zip; ZipFile zip = null;
try { try {
zip = new ZipFile(jarPath); zip = new ZipFile(jarPath);
Enumeration entries = zip.entries(); Enumeration entries = zip.entries();
@ -193,6 +193,14 @@ public final class FunctionConstants {
} }
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if(null != zip){
try {
zip.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} }
} else { } else {
File dir = new File(filePath); File dir = new File(filePath);

7
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

@ -276,8 +276,9 @@ public class CodeTemplateManager {
temp.addAll(templates); temp.addAll(templates);
for (int i=0; i<newCount; i++) { for (int i=0; i<newCount; i++) {
XMLDecoder d = null;
try { try {
XMLDecoder d = new XMLDecoder(new BufferedInputStream( d = new XMLDecoder(new BufferedInputStream(
new FileInputStream(files[i]))); new FileInputStream(files[i])));
Object obj = d.readObject(); Object obj = d.readObject();
if (!(obj instanceof CodeTemplate)) { if (!(obj instanceof CodeTemplate)) {
@ -291,6 +292,10 @@ public class CodeTemplateManager {
// an XML file not in the format expected by XMLDecoder. // an XML file not in the format expected by XMLDecoder.
// (e.g. CodeTemplates in an old format). // (e.g. CodeTemplates in an old format).
e.printStackTrace(); e.printStackTrace();
} finally {
if(null != d){
d.close();
}
} }
} }
templates = temp; templates = temp;

Loading…
Cancel
Save