[Inst] Remove prevent issues. 47/13847/1
authoryongsung1.kim <yongsung1.kim@samsung.com>
Tue, 17 Dec 2013 08:40:56 +0000 (17:40 +0900)
committeryongsung1.kim <yongsung1.kim@samsung.com>
Tue, 17 Dec 2013 08:40:56 +0000 (17:40 +0900)
InstallManager project has many prevent issues. So, we need to get rid
of these which are critical and major severity.

Change-Id: I7c4cb6d602e9e112c9a5212c7d641b70901dd130
Signed-off-by: yongsung1.kim <yongsung1.kim@samsung.com>
13 files changed:
InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java
InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/lib/Downloader.java
InstallManager_java/src/org/tizen/installmanager/lib/OldRegistry.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java
InstallManager_java/src/org/tizen/installmanager/pkg/model/Package.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java
InstallManager_java/src/org/tizen/installmanager/ui/page/ViewController.java
InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java
InstallManager_java/src/org/tizen/installmanager/util/ShellUtil.java

index bec35c7..5e39fd9 100644 (file)
@@ -74,7 +74,7 @@ public class InstallManagerNoUI {
                        unzipSDKImage();
                }
                
-               if (Registry.getInstalledPath() != "") {
+               if (!Registry.getInstalledPath().equals("")) {
                        List<String> all = new ArrayList<String>();
                        all.add("all");
                        if (cliUninstall(all)) {
@@ -126,7 +126,7 @@ public class InstallManagerNoUI {
        }
        
        public static boolean cliNetworkInstall(List<String> packageNames) throws IMExitException {
-               if (Registry.getInstalledPath() != "") {
+               if (!Registry.getInstalledPath().equals("")) {
                        String installRepo = Config.getInstance().getConfigFile().getRepository();
                        String installDist = Config.getInstance().getConfigFile().getDistribution();
                        String remoteRepo = Options.repository;
@@ -170,7 +170,7 @@ public class InstallManagerNoUI {
        }
        
        public static boolean cliUninstall(List<String> packageNames) throws IMExitException {
-               if (Registry.getInstalledPath() == "") {
+               if (Registry.getInstalledPath().equals("")) {
                        System.out.println("Tizen SDK was not installed.");
                        return false;
                } else {
index 6cbf6b0..1231ce6 100644 (file)
@@ -426,7 +426,7 @@ public class InstallManager {
         */
        private void checkOldSDK() {
                Log.log("Check old SDK.");
-               if (Registry.getOldInstalledPath() != "") { // Old SDK is installed.
+               if (!Registry.getOldInstalledPath().equals("")) { // Old SDK is installed.
                        if (Registry.getInstalledPath() != null && !Registry.getInstalledPath().isEmpty()) {
                                // Old SDK is installed but new SDK is also installed, so environment does not need to
                                // set new SDK environment.
index ef49aeb..c87f6cd 100644 (file)
@@ -56,7 +56,7 @@ public class InstallManagerConstants {
        }
        
        static String getSDKDataPath() {
-               if (Config.getInstance().getSdkDataDir() == "") {
+               if (Config.getInstance().getSdkDataDir().equals("")) {
                        if (Platform.isLinux() || Platform.isMacOS()) {
                                return PathUtil.getFromHome(SDK_DATA_DIR_NAME);
                        } else if (Platform.isWindows()) {
index b9d3bb1..0e90f9a 100644 (file)
@@ -285,7 +285,7 @@ public class Options {
                                if(iter.hasNext()) {
                                        snapshot = true;
                                        snapshotPath = iter.next();
-                                       Log.log("User-provided repository: " + repository);
+                                       Log.log("User-provided snapshot path: " + snapshotPath);
                                } else {
                                        Log.err("-snapShot requires repository description");
                                        throw new IMFatalException(ErrorCode.USESNAPSHOT_REPOSITORY_NOT_PROVIDED);
@@ -546,7 +546,7 @@ public class Options {
                                                                }
                                                        }
                                                }
-                                               if (suPass == "") {
+                                               if (suPass.equals("")) {
                                                        throw new IMFatalException(ErrorCode.WRONG_OPTION);
                                                }
                                        } else if (Platform.isWindows()) {
index 379b295..c9511f1 100644 (file)
@@ -476,7 +476,7 @@ public class Downloader {
                boolean bRet = false;
 
                String proxyType = Config.getInstance().getConfigFile().getProxyType();
-               if (proxyType == "") { // InstallManager uses a system proxy as default.
+               if (proxyType.equals("")) { // InstallManager uses a system proxy as default.
                        proxyType = ProxyType.AUTOMATIC.toString();
                }
                
index 24a7d7b..bb44bfe 100644 (file)
@@ -56,7 +56,7 @@ public class OldRegistry{
        List<RegistryInfo> oldRegistryInfo = new ArrayList<RegistryInfo>();
        RegistryInfo mCurrentRegistry = null;
        
-       private class RegistryInfo {
+       private static class RegistryInfo {
                String mRegistryPath = "";
                String mPathKey = "";
                String mTargetPath = "";
index 0650f09..6af28b1 100644 (file)
@@ -378,9 +378,11 @@ public abstract class PackageManager {
                                        }
                                }
                                
-                               packageListURL = PathUtil.addURLPath(url,
+                               if (snapshotPath != null) {
+                                       packageListURL = PathUtil.addURLPath(url,
                                                    snapshotPath, 
                                                    getPackageListFileName());
+                               }
                        } else {
                                packageListURL = PathUtil.addURLPath(url, getPackageListFileName());
                        }
@@ -1664,12 +1666,16 @@ public abstract class PackageManager {
         */
        private long getTotalSize(PackageSet pkgs, boolean isUncompressed) {
                long totalSize = 0;
-               for (Package depPkg : pkgs) {
-                       if (isUncompressed) {
-                               totalSize += depPkg.getUncompressedPackageSize();                               
-                       } else {
-                               totalSize += depPkg.getPackageSize();                           
-                       }
+               if (pkgs != null) {
+                       for (Package depPkg : pkgs) {
+                               if (isUncompressed) {
+                                       totalSize += depPkg.getUncompressedPackageSize();                               
+                               } else {
+                                       totalSize += depPkg.getPackageSize();                           
+                               }
+                       }                       
+               } else {
+                       Log.log("Cannot caculate packages' total size because of empty or null packages.");
                }
                
                return totalSize;
@@ -1832,7 +1838,7 @@ public abstract class PackageManager {
        public static PackageManager getInstance(File installed, Collection<String> repoPackagesUrls) throws IOException {
                if (Options.platForm == null) {
                        if (Config.isSupportMultiSDK) {
-                               if (Registry.targetPath != "") {
+                               if (!Registry.targetPath.equals("")) {
                                        pm = null;
                                        if (Platform.isLinux()) {
                                                pm = new LinuxPackageManager(installed, repoPackagesUrls);
index c86f6e8..536bf00 100644 (file)
@@ -149,7 +149,9 @@ public class PropertyParser {
                                                        pFieldList.add(tempProperty);
                                                        pField = tempProperty;
                                                } else {
-                                                       pField.setValue(pField.getValue()+'\n'+sReadData.trim());
+                                                       if (pField != null) {
+                                                               pField.setValue(pField.getValue()+'\n'+sReadData.trim());                                                               
+                                                       }
                                                }
                                        } else {
                                                Log.err("Cannot parse name and value from installmanager.conf. (read line => " + sReadData + ")");
index e71942e..5f0e32c 100644 (file)
@@ -117,11 +117,12 @@ public class Package {
        public Package(Properties properties, String repoBaseUrl) {
                this(properties);
                try {
-                       if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // data from file dialog for local installing
-                               this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
-                       } else { // data from snapshot and normal 'next' case
-                               this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));                             
-                       }
+                       this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
+//                     if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // data from file dialog for local installing
+//                             this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
+//                     } else { // data from snapshot and normal 'next' case
+//                             this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));                             
+//                     }
                } catch (MalformedURLException e) {
                        Log.err("Invalid package url: "+repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
                        throw new IMFatalException(ErrorCode.WRONG_PACKAGE_URL);
index 02e913b..fd6831f 100644 (file)
@@ -599,7 +599,7 @@ public class ConfigurationDialog extends Dialog {
                                        log = snapshotLog.getSnapshotLog(item.getText(TABLE_NAME));     
                                }
                                
-                               if (log == null) {
+                               if (log == null && item != null) {
                                        MessageBoxDlg.showDlg(
                                                        getShell(),
                                                        "Notice",
index e36303e..7a89a45 100644 (file)
@@ -313,7 +313,12 @@ public class ViewController {
                boolean bResult = false;
                while(true) {
                        try {
-                               bResult = installManager.install(installablePackages, targetPath, monitor);
+                               if (installablePackages != null) {
+                                       bResult = installManager.install(installablePackages, targetPath, monitor);                                     
+                               } else {
+                                       Log.err("Fail to install because installable packages are null.");
+                                       throw new IMFatalException("Fail to install because installable packages are null.");
+                               }
                                break;
                        } catch (IMNetworkException e) {
                                Log.ExceptionLog(e);
@@ -589,7 +594,8 @@ public class ViewController {
         * @return There are packages to install or remove, return true. if not false.
         */
        public boolean existInstallableOrRemovablePackages() {
-               PackageSet rmPkgs = getRemovablePackageList();
+               PackageSet rmPkgs = new PackageSet();
+               rmPkgs = getRemovablePackageList();
                PackageSet insPkgs = getInstallableOrUpdatableMetaPackages();
                
                if (!rmPkgs.isEmpty() || !insPkgs.isEmpty()) {
@@ -822,31 +828,36 @@ public class ViewController {
        private String downloadInstallManager() {
                Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
                
-               Downloader downloader = new Downloader();
-               
-               String packagePath = pkg.getFileName();
-               String installManagerTempPath = PathUtil.get(PathUtil.getTempDir(), PathUtil.getFileName(packagePath));
-               File tempInstaller = new File(installManagerTempPath);
-               
-               if (tempInstaller.exists()) {
-                       if (!PathUtil.remove(installManagerTempPath)) {
-                               Log.err("Cannot remove installmanager. => " + tempInstaller);
+               if (pkg != null) {
+                       Downloader downloader = new Downloader();
+                       
+                       String packagePath = pkg.getFileName();
+                       String installManagerTempPath = PathUtil.get(PathUtil.getTempDir(), PathUtil.getFileName(packagePath));
+                       File tempInstaller = new File(installManagerTempPath);
+                       
+                       if (tempInstaller.exists()) {
+                               if (!PathUtil.remove(installManagerTempPath)) {
+                                       Log.err("Cannot remove installmanager. => " + tempInstaller);
+                               }
                        }
-               }
-               
-               try {
-                       long size = downloader.download(pkg.getURL(), installManagerTempPath, null);
                        
-                       if (size > 0) {
-                               return installManagerTempPath;
-                       } else {
+                       try {
+                               long size = downloader.download(pkg.getURL(), installManagerTempPath, null);
+                               
+                               if (size > 0) {
+                                       return installManagerTempPath;
+                               } else {
+                                       return null;
+                               }
+                       } catch (IMNetworkConnectException e) {
+                               Log.ExceptionLog(e);
                                return null;
-                       }
-               } catch (IMNetworkConnectException e) {
-                       Log.ExceptionLog(e);
-                       return null;
-               } catch (IMNetworkDownloadException e) {
-                       Log.ExceptionLog(e);
+                       } catch (IMNetworkDownloadException e) {
+                               Log.ExceptionLog(e);
+                               return null;
+                       }                       
+               } else {
+                       Log.err("Cannot download installmanager package.");
                        return null;
                }
        }
@@ -934,7 +945,7 @@ public class ViewController {
                                }
                                
                                String dist = Config.getInstance().getConfigFile().getDistribution();
-                               if (repo != null && !repo.isEmpty()) {
+                               if (dist != null && !dist.isEmpty()) {
                                        commands.add("-distribution");
                                        commands.add(dist);
                                }
@@ -948,8 +959,10 @@ public class ViewController {
                                        }
                                }
                                
-                               Config.getInstance().getConfigFile().setInstallManagerVersion(packageManager.getPackageByName("install-manager").getVersion().toString());
-                               Config.getInstance().getConfigFile().saveConfig(PathUtil.get(tempIMJarFile.getParent(), "installmanager.conf"));
+                               if (packageManager.getPackageByName("install-manager") != null) {
+                                       Config.getInstance().getConfigFile().setInstallManagerVersion(packageManager.getPackageByName("install-manager").getVersion().toString());
+                                       Config.getInstance().getConfigFile().saveConfig(PathUtil.get(tempIMJarFile.getParent(), "installmanager.conf"));
+                               }
                                
                                Log.log("Updatable commands => " + commands);
                                
index ed5d597..9b7b46c 100644 (file)
@@ -42,7 +42,6 @@ import java.net.URL;
 
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
-import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMFatalException;
 import org.tizen.installmanager.core.Options;
 import org.tizen.installmanager.lib.Log;
@@ -154,6 +153,9 @@ public class PathUtil {
                if (path != null) {
                        for (int i = parentDepth; i > 0; i--) {
                                parentPath = PathUtil.getParentDirectory(parentPath);
+                               if (parentPath == null) {
+                                       break;
+                               }
                        }
                }
                
index f56f0d7..e1d7cdc 100644 (file)
@@ -129,9 +129,11 @@ public class ShellUtil {
                        return exitCode;
                } catch (IOException e) {
                        Log.err("Command exec error => " + Arrays.toString(cmd));
+                       Log.ExceptionLog(e);
                        throw new IMShellCommandFail();
                } catch (InterruptedException e) {
                        Log.err("Command exec error => " + Arrays.toString(cmd));
+                       Log.ExceptionLog(e);
                        throw new IMShellCommandFail();
                }
        }