MISC: fix potential bug - misuse concurrency object & unrelease resource 98/18598/1
authorjungwook.ryu <jungwook.ryu@samsung.com>
Thu, 27 Mar 2014 05:15:46 +0000 (14:15 +0900)
committerjungwook.ryu <jungwook.ryu@samsung.com>
Thu, 27 Mar 2014 05:19:04 +0000 (14:19 +0900)
Change-Id: I774edaa32bcfc2d1071f929b0d86ce74fd07dde8
Signed-off-by: jungwook.ryu <jungwook.ryu@samsung.com>
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/DALog.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/communication/DAServerManager.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/launch/TizenNativeApplicationDADelegate.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/launch/TizenNativeApplicationDAShortcut.java

index 94b9672..9b880b1 100755 (executable)
@@ -70,7 +70,10 @@ public class DALog {
                                        .append(File.separatorChar).append("logs");//$NON-NLS-1$
                        File logsSaveFolderPath = new File(logPath.toString());
                        if (!logsSaveFolderPath.exists()) {
-                               logsSaveFolderPath.mkdirs();
+                               if (!logsSaveFolderPath.mkdirs()) {
+                                       // if it failed creating folder
+                                       return false;
+                               }
                        }
 
                        if(manageIDELogFileCount(logsSaveFolderPath)){
@@ -107,7 +110,9 @@ public class DALog {
                List<File> listLogFile = sortIDELogFile(logFiles);
                int logSize = listLogFile.size();
                for (int i = IDE_LOG_SAVE_COUNT - 1; i < logSize; i++) {
-                       listLogFile.get(i).delete();
+                       if (!listLogFile.get(i).delete()) {
+                               // if it failed deleting the file, do nothing this time. it will try again later.
+                       }
                }
                return true;
        }
index 1ca1d7d..67d508f 100644 (file)
@@ -44,7 +44,7 @@ import org.tizen.dynamicanalysis.ide.eplugin.DALog;
 import org.tizen.dynamicanalysis.ide.eplugin.nl.Labels;
 
 public class DAServerManager extends Thread {
-       private final int MAXBUFSIZE = 1024;
+       private final static int MAXBUFSIZE = 1024;
 
        private static DAServerManager instance;
 
@@ -158,7 +158,10 @@ public class DAServerManager extends Thread {
 
                File folder = new File(savePath.toString());
                if (!folder.exists()) {
-                       folder.mkdirs();
+                       if (!folder.mkdirs()) {
+                               // if it failed creating folder
+                               return false;
+                       }
                }
                
                savePath.append(ACTIVE_DA_PLUGIN);
@@ -169,21 +172,16 @@ public class DAServerManager extends Thread {
                File file = new File(savePath.toString());
                try {
                        fchannel = new RandomAccessFile(file, "rw").getChannel();//$NON-NLS-1$
+                       fileLock = fchannel.tryLock();
+                       if (fileLock == null) {
+                               isActiveDA = true;
+                       }
                } catch (FileNotFoundException e1) {
                        e1.printStackTrace();
-                       return false;           // when creating file channel, it consider DA is not activated.
-               }
-               try {
-                       fileLock = fchannel.tryLock();
                } catch (IOException e) {
                        e.printStackTrace();
-               }
-
-               if (fileLock == null) {
-                       isActiveDA = true;
-               } else {
-                       isActiveDA = false;
-                       if (null != fchannel) {
+               } finally {
+                       if (fchannel != null) {
                                try {
                                        fchannel.close();
                                } catch (IOException e) {
@@ -239,9 +237,12 @@ public class DAServerManager extends Thread {
                                .append(File.separatorChar).append(DANAIC_ANALYZER)
                                .append(File.separatorChar).append(SAVE);
 
-               File logs = new File(savePath.toString());
-               if (!logs.exists()) {
-                       logs.mkdirs();
+               File saveDir = new File(savePath.toString());
+               if (!saveDir.exists()) {
+                       if (!saveDir.mkdirs()) {
+                               // if it failed creating folder, Do nothing. 
+                               // Exception should be handled in caller.
+                       }
                }
 
                savePath.append(File.separatorChar).append(CURRENT_ACTIVE_IDE_PORT);
index 1dfae79..cf1daae 100644 (file)
@@ -80,9 +80,9 @@ import org.tizen.sdblib.service.SyncResult;
 
 public class TizenNativeApplicationDADelegate extends
                AbstractTizenCLaunchDelegate {
-       private final String TOOLS = "tools";// $NON_NLS-1$
-       private final String DYNAMIC_ANALYZER = "dynamic-analyzer";// $NON_NLS-1$
-       private final String PKG_TYPE = CommonProjectDependentPackager.DEFAULT;
+       private final static String TOOLS = "tools";// $NON_NLS-1$
+       private final static String DYNAMIC_ANALYZER = "dynamic-analyzer";// $NON_NLS-1$
+       private final static String PKG_TYPE = CommonProjectDependentPackager.DEFAULT;
        private boolean bSuccessBuild = true;
 
        private static class ExtFilter implements FilenameFilter {
@@ -161,7 +161,7 @@ public class TizenNativeApplicationDADelegate extends
                                                        CommonProjectDependentPackager packager = ProjectTypeManager
                                                                        .getProjectPackagerInstance(project);
                                                        
-                                                       RdsDeployer rdsDeployer= null;
+                                                       RdsDeployer rdsDeployer = null;
                                                        try {
                                                                if (RdsPreferencePage.isRdsMode(project)) {
                                                                        TizenLaunchCommand tizenCommand = new TizenLaunchCommand(
@@ -193,13 +193,19 @@ public class TizenNativeApplicationDADelegate extends
                                                                }
                                                                LaunchUtils.touchExecutableFile(project);
                                                        } catch (CoreException e) {
-                                                               if (rdsDeployer != null) {
-                                                                       rdsDeployer.cleanDeltaInfo();
-                                                               }
                                                                DALog.dlgErrorMessage(Labels.MESSAGE_ERROR,
                                                                                e.getMessage());
                                                                bSuccessBuild = false;
                                                                monitor.done();
+                                                       } finally {
+                                                               if (rdsDeployer != null) {
+                                                                       try {
+                                                                               rdsDeployer.close();
+                                                                       } catch (IOException e) {
+                                                                               DALog.dlgErrorMessage("Failed to close RDSDeployer", 
+                                                                                               e.getMessage());
+                                                                       }
+                                                               }
                                                        }
                                                        
                                                        if(monitor.isCanceled()) {
index b009a5a..c132504 100755 (executable)
@@ -138,52 +138,6 @@ public class TizenNativeApplicationDAShortcut extends TizenLaunchShortcut {
                }
        }
 
-       private ILaunchConfiguration createLaunchConfiguration(IProject project)
-                       throws CoreException {
-               IDevice device = LaunchUtils.getCurrentDeployDevice();
-
-               String projectName = project.getName();
-               String configName = ProjectUtil.getLaunchConfigurationName(project);
-
-               ILaunchConfigurationType configType = getCLaunchConfigType();
-
-               ILaunchConfigurationWorkingCopy wc = configType.newInstance(null,
-                               getLaunchManager().generateLaunchConfigurationName(configName));
-
-               TizenLaunchConfiguration tc = new TizenLaunchConfiguration(wc, device);
-               tc.setDefaults();
-
-               String programName = ProjectUtil.getDefaultConfiguration(project)
-                               .getName()
-                               + File.separatorChar
-                               + ProjectUtil.getBinaryName(project);
-               wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME,
-                               programName);
-               wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
-                               projectName);
-               wc.setMappedResources(new IResource[] { project });
-               wc.setAttribute(
-                               ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "");//$NON-NLS-1$
-               LaunchUtils.setDeviceToLaunchConfiguration(wc, device);
-
-               setStopAtMain(wc, project);
-
-               ICProjectDescription projDes = CCorePlugin.getDefault()
-                               .getProjectDescription(project);
-               if (projDes != null) {
-                       String buildConfigID = projDes.getActiveConfiguration().getId();
-                       wc.setAttribute(
-                                       ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID,
-                                       buildConfigID);
-                       String buildConfigName = projDes.getActiveConfiguration().getName();
-                       wc.setAttribute(
-                                       TizenLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_NAME,
-                                       buildConfigName);
-               }
-
-               return wc.doSave();
-       }
-
        private ILaunchConfiguration createLaunchConfiguration(GomLaunchData data) {
                ILaunchConfiguration config = null;
                IProject project = data.getProject();