[INST] Install Manager performance tunning code 90/20490/1 custom
authorMoonkyu Kang <moonkyu82.kang@samsung.com>
Thu, 8 May 2014 07:35:56 +0000 (16:35 +0900)
committerMoonkyu Kang <moonkyu82.kang@samsung.com>
Thu, 8 May 2014 07:35:56 +0000 (16:35 +0900)
Change-Id: I66b66d804eefaf28fa5610ee21731bb98d17adc8
Signed-off-by: Moonkyu Kang <moonkyu82.kang@samsung.com>
InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/core/Installer.java
InstallManager_java/src/org/tizen/installmanager/lib/win/WindowsSDKPackageFormat.java

index 43047af..9b12ddb 100644 (file)
@@ -60,6 +60,7 @@ import org.tizen.installmanager.util.ShellUtil;
  * instance.
  * 
  * @author Shihyun Kim <shihyun.kim@samsung.com>
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com> 
  */
 public class InstallManager {
 
@@ -732,8 +733,10 @@ public class InstallManager {
                        return false;
                }
                
-               mConfig.setTargetDir(targetDir);
-               mConfig.setSdkDatatDir(Registry.sdkDataPath);
+               // kmk - Just do same job in "initializeTargetDir(targetDir);" 
+//             mConfig.setTargetDir(targetDir);
+//             mConfig.setSdkDatatDir(Registry.sdkDataPath);
+               
                
                // Temporary code for installing intel haxm package for the first time.
                initializeTargetDir(targetDir);
index c53e396..c42fabe 100644 (file)
@@ -60,6 +60,7 @@ import org.tizen.installmanager.util.ShellUtil;
  * This class manages lowlevel install/uninstall operations
  * 
  * @author Shihyun Kim <shihyun.kim@samsung.com>
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com> 
  */
 public class Installer {
        /**
@@ -110,12 +111,15 @@ public class Installer {
                                        ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
                }
 
-               List<File> missingFiles = findMissingFiles(pack);
-               if (missingFiles.size() > 0) {
-                       Log.err("Some files are not moved properly: " + missingFiles);
-//                     throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);
-               } else {
-                       Log.log("All files moved properly.");
+               // kmk - do finding missing files when platform is not windows
+               if(!Platform.isWindows()){
+                       List<File> missingFiles = findMissingFiles(pack);
+                       if (missingFiles.size() > 0) {
+                               Log.err("Some files are not moved properly: " + missingFiles);
+                               // throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);
+                       } else {
+                               Log.log("All files moved properly.");
+                       }
                }
 
                if (!executeInstallScript(pack, monitor, tempDir)) {
index 8efb885..c30a98f 100644 (file)
 package org.tizen.installmanager.lib.win;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
 
 import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.ErrorController;
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;
 import org.tizen.installmanager.lib.IIMProgressMonitor;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.util.PathUtil;
 
 
 /**
  * Manages to unpack package of tizen sdk for windows.
  * @author Shihyun Kim <shihyun.kim@samsung.com>
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
  *
  */
 public class WindowsSDKPackageFormat extends SDKPackageFormat{
@@ -69,184 +72,145 @@ public class WindowsSDKPackageFormat extends SDKPackageFormat{
                return ERROR;
         }
         Log.log(fileFullPath + " exists.");
-               
-               if (targetDir == null || !targetDir.isAbsolute()) {
-                       return ERROR;
-               }
-               
-               Log.log(targetDir + " is not null and absolute.");
-               
-               if (!targetDir.exists()) {
-                       Log.log(targetDir + " does not exist. InstallManager will make target directory.");
-                       if (targetDir.mkdirs()) {
-                               Log.log("Success to create directory ==> " + targetDir);
-                       } else {
-                               Log.err("Fail to create directory ==> " + targetDir);
-                       }
-               }
-
-               long ret = unZipPackage(fileFullPath, targetDir, monitor);
-        
-        closeFileOutput(); 
-        return ret;
+               return unZipPackage(fileFullPath, targetDir, monitor);
     }
-    
-       private long unZipPackage(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
-               ZipInputStream zipInStream = null;
-               FileOutputStream zipOutput = null;
-               ZipEntry zipEntry = null;
-
-               try {
-                       zipInStream = new ZipInputStream(new FileInputStream(fileFullPath));
-                       zipEntry = zipInStream.getNextEntry();
-
-                       long totalUnZipSize = 0;
-                       while (zipEntry != null) {
-                               if (monitor != null) {
-                                       String fileName = PathUtil.getFileName(zipEntry.getName());
-                                       monitor.workedSubTitle(fileName);
-                               }
-
-                               String targetPath = targetDir.getAbsolutePath() + File.separator + zipEntry.getName();
-
-                               // make directory
-                               File targetFile = new File(targetPath);
-                               if (targetFile.exists() && targetFile.isDirectory()) {
-                                       writeFileList(zipEntry.getName());
-                                       zipEntry = zipInStream.getNextEntry();
-                                       continue;
-                               }
-
-                               File parentFile = targetFile.getParentFile();
-                               if (!parentFile.exists()) {
-                                       if (parentFile.mkdirs()) {
-                                               Log.log("Success to create parent directory ==> " + parentFile);
-                                       } else {
-                                               Log.err("Fail to create parent directory ==> " + parentFile);
-                                       }
-                               }
-
-                               if (targetPath.endsWith("/")) {// zipEntry.isDirectory
-                                       File target = new File(targetPath);
-                                       if (target.mkdir()) {
-                                               Log.log("Success to create target directory ==> " + target);
-                                       } else {
-                                               Log.err("Fail to create target directory ==> " + target);
-                                       }
-                                       zipInStream.closeEntry();
-                                       writeFileList(zipEntry.getName());
-                                       zipEntry = zipInStream.getNextEntry();
-                                       continue;
-                               }
-
-                               zipOutput = new FileOutputStream(targetPath);
-
-                               byte[] zipBuf = new byte[BUF_SIZE];
-                               int readByte = 0;
-
-                               while ((readByte = zipInStream.read(zipBuf)) >= 0) {
-                                       zipOutput.write(zipBuf, 0, readByte);
-                                       totalUnZipSize += readByte;
-                               }
-
-                               writeFileList(zipEntry.getName());
 
-                               if (zipOutput != null) {
-                                       zipOutput.close();
-                               }
-
-                               if (zipEntry != null) {
-                                       zipInStream.closeEntry();
-                               }
-                               zipEntry = zipInStream.getNextEntry();
-                       }
-
-                       return totalUnZipSize;
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       if (zipEntry != null) {
-                               Log.err("Fail to unpack " + zipEntry.getName());
-                       }
-                       
-                       return ERROR;
-               } catch (Throwable e) {
-                       Log.ExceptionLog(e);
-                       return ERROR;
-               } finally {
-                       try {
-                               if (zipOutput != null) {
-                                       zipOutput.flush();
-                                       zipOutput.close();
-                               }
-                       } catch (IOException e) {
-                               if (zipEntry != null) {
-                                       Log.err("Fail to close output stream : "
-                                               + zipEntry.getName());
-                               } else {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-
-                       try {
-                               if (zipInStream != null) {
-                                       zipInStream.closeEntry();
-                               }
-                       } catch (IOException e) {
-                               if (zipEntry != null) {
-                                       Log.err("Fail to close output stream : "
-                                               + zipEntry.getName());
-                               } else {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-                       
-                       if (zipInStream != null) {
-                               try {
-                                       zipInStream.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-
-                       try {
-                               if (mFileOutput != null) {
-                                       mFileOutput.close();
-                               }
-                       } catch (IOException e) {
-                               if (zipEntry != null) {
-                                       Log.err("Fail to close output stream : "
-                                               + zipEntry.getName());
-                               } else {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
+    private long unZipPackage(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
+               
+               ZipFile zipFile = null;
+               FileOutputStream zipOutStream = null;
+               InputStream zis = null;
+               long totalUnZipSize = 0;
+               List<String> installedFileList = new ArrayList<String>(); 
+               
+               try {
+                       zipFile = new ZipFile(fileFullPath);
+                       @SuppressWarnings("unchecked")
+                       Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile
+                                       .entries();
+                       while (entries.hasMoreElements()) {
+                               ZipEntry zipEntry = entries.nextElement();
+       
+                               if (zipEntry.isDirectory()) {
+                                       installedFileList.add(zipEntry.getName());
+                                       continue;
+                               } else {
+                                       // Unzip files in "data" directory to target directory
+                                       String targetPathWithOutTempDir = targetDir.getParent();
+                                       String targetPath = null;
+                                       if (zipEntry.getName().startsWith("data/")) {
+                                               String fileName = zipEntry.getName().substring(5);
+                                               targetPath = targetPathWithOutTempDir + File.separator
+                                                               + fileName;
+                                       } else {
+                                               targetPath = targetDir.getAbsolutePath()
+                                                               + File.separator + zipEntry.getName();
+                                       }
+
+                                       // Prepare file for write
+                                       File targetFile = new File(targetPath);
+
+                                       // create parent directory
+                                       File parentFile = targetFile.getParentFile();
+                                       if (!parentFile.exists()) {
+                                               if (parentFile.mkdirs()) {
+                                                       Log.log("Success to create parent directory ==> "
+                                                                       + parentFile);
+                                               } else {
+                                                       Log.err("Fail to create parent directory ==> "
+                                                                       + parentFile);
+                                               }
+                                       }
+
+                                       // Write zip file to target File
+
+                                       zipOutStream = new FileOutputStream(targetPath);
+                                       zis = zipFile.getInputStream(zipEntry);
+                                       byte[] zipBuf = new byte[BUF_SIZE];
+                                       int readByte = 0;
+
+                                       while ((readByte = zis.read(zipBuf)) >= 0) {
+                                               zipOutStream.write(zipBuf, 0, readByte);
+                                               totalUnZipSize += readByte;
+                                       }
+
+                                       installedFileList.add(zipEntry.getName());
+
+                                       if (zipOutStream != null) {
+                                               zipOutStream.close();
+                                       }
+
+                                       if (zis != null) {
+                                               zis.close();
+                                       }
+                               }
+                       }
+                       writeFileList(installedFileList);
+               } catch (ZipException e1) {                     
+                       Log.ExceptionLog(e1);
+               } catch (IOException e1) {
+                       Log.ExceptionLog(e1);
+               }finally{
+                       try {
+                               if(zis != null && zis.available() > 0){
+                                       try {
+                                               zis.close();
+                                       } catch (IOException e) {
+                                               Log.ExceptionLog(e);
+                                       }
+                               }
+                       } catch (IOException e) {
+                               Log.ExceptionLog(e);
+                       }
+                       
+                       if(zipFile != null){
+                               try {
+                                       zipFile.close();
+                               } catch (IOException e) {
+                                       Log.ExceptionLog(e);
+                               }
+                       }
+                       if(zipOutStream != null){
+                               try {
+                                       zipOutStream.flush();
+                                       zipOutStream.close();
+                               } catch (IOException e) {
+                                       Log.ExceptionLog(e);
+                               }
+                       }       
+                       closeFileOutput();
+               }       
+               closeFileOutput();
+               return totalUnZipSize;
+       }
 
-                       closeFileOutput();
-               }
-       }
     
-    private void writeFileList(String filePath) {
-       if (filePath == null || filePath.equals("")) {
-               return;
-       }
-       
-       filePath = removeDataDirectory(filePath);
-       if (filePath == null || filePath.equals("")) {
-               return;
-       }
-       
-       if (mFileOutput == null) {
-               return;
-       }
-       
-       try {
-                       mFileOutput.write((filePath + "\n").getBytes());
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       Log.err("Fail to unpack " + filePath);
-            throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
-               }
-    }
+    private void writeFileList(List<String> installedFileList) {
+               
+       for (String filePath : installedFileList) {
+               if (filePath == null || filePath.equals("")) {
+                       continue;
+               }
+               
+               filePath = removeDataDirectory(filePath);
+               if (filePath == null || filePath.equals("")) {
+                       continue;
+               }
+               
+               if (mFileOutput == null) {
+                       continue;
+               }
+               
+               try {
+                       mFileOutput.write((filePath + "\n").getBytes());
+               } catch (IOException e) {
+                       Log.ExceptionLog(e);
+                       Log.err("Fail to unpack " + filePath);
+                throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
+               }
+               }               
+       }
+
     
     private String removeDataDirectory(String filePath) {
        if (filePath == null || filePath.equals("")) {