[Title] CLI installation can support to use SDK image and proxy.
authoryongsung1.kim <yongsung1.kim@samsung.com>
Sun, 28 Apr 2013 12:43:08 +0000 (21:43 +0900)
committeryongsung1.kim <yongsung1.kim@samsung.com>
Sun, 28 Apr 2013 12:43:08 +0000 (21:43 +0900)
[Desc.] SDK image must be extracted before image installation by cli.
'-r' option support file protocol, absolute path and relative path.
'-x' option support proxy setting. (ex. proxy host(except
protocol):proxy port)
[Issue] redmine #9020, #9204

Change-Id: I3eac3a92a99094719d99115cd1882969f2761e22

InstallManager_java/src/org/tizen/installmanager/cli/CliInstall.java
InstallManager_java/src/org/tizen/installmanager/cli/CliUninstall.java
InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java

index 7753844..b93b492 100644 (file)
@@ -48,6 +48,7 @@ import org.tizen.installmanager.lib.IFileSystemInformation;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.Platform;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+import org.tizen.installmanager.lib.NetworkProxy.ProxyType;
 import org.tizen.installmanager.lib.exception.IMNetworkException;
 import org.tizen.installmanager.lib.linux.LinuxFileSystemInfo;
 import org.tizen.installmanager.lib.win.WindowsFileSystemInfo;
@@ -68,6 +69,10 @@ public class CliInstall {
 
        private static ViewController controller = null;
        
+       private static ProxyType proxyType = ProxyType.AUTOMATIC;
+       private static String proxyHost = "";
+       private static String proxyPort = "";
+       
        /**
         * Works for command line installation
         * @return If installation successes, return true. otherwise return false.
@@ -75,15 +80,9 @@ public class CliInstall {
         * @throws IMExitException 
         */
        public static boolean installOnConsole(List<String> packageNames) throws IMExitException {
-               if (!validateRepository()) {
-                       return false;
-               }
-               
-               refresh(); // Refresh installation environment.
-               
-               if (!validateDistribution()) {
-                       return false;
-               }
+               System.out.println("****************************************");
+               System.out.println("******** Start SDK installation ********");
+               System.out.println("****************************************");
                
                PackageManager pm = PackageManager.getInstance();
                        
@@ -183,11 +182,18 @@ public class CliInstall {
         * Validate repository url.
         * @return If repository does not work or is not correct, return false. otherwise return true.
         */
-       private static boolean validateRepository() {
+       public static boolean validateRepository(boolean isNetwork) {
                URL serverUrl = null;
                
                try {
-                       serverUrl = new URL(PathUtil.addURLPath(Options.repository, DISTRIBUTION_INFO));                
+                       if (isNetwork) {
+                               serverUrl = new URL(PathUtil.addURLPath(Options.repository, DISTRIBUTION_INFO));                                
+                       } else {
+                               String packageList = PackageManager.getInstance().getPackageListFileName();
+                               String repo = getReformedPath(Options.repository, true);
+                               serverUrl = new URL(PathUtil.addURLPath(repo, packageList));
+                       }
+               
                } catch (MalformedURLException e) {
                        // the URL is not in a valid form
                        ErrorController.setError(ErrorCode.WRONG_URL_FORMAT);
@@ -208,7 +214,7 @@ public class CliInstall {
         * Validate distribution.
         * @return If can find input distribution in the distribution.info, return true. otherwise return false.
         */
-       private static boolean validateDistribution() {
+       public static boolean validateDistribution() {
                List<String> distributionList = DistributionController.getInstance().getDistributionList();
                
                if (distributionList.contains(Options.distribution)) {
@@ -222,18 +228,90 @@ public class CliInstall {
        /**
         * Refresh installation environment.
         */
-       private static void refresh() {
+       public static void refresh() {
                controller = new ViewController();
                controller.init();
                
                // Set config information as input data.
-               Config.getInstance().saveSnapshotSettings(Options.repository, Options.distribution, Options.serverType, Options.snapshotPath);
+               if (Options.isNetwork) {
+                       Config.getInstance().saveSnapshotSettings(Options.repository, Options.distribution, Options.serverType, Options.snapshotPath);
+                       if (Options.proxy != null) {
+                               parseProxy(Options.proxy);
+                               Config.getInstance().saveProxySettings(proxyType, proxyHost, proxyPort);
+                       }
+               } else {
+                       String repo = getReformedPath(Options.repository, false);
+
+                       Config.getInstance().saveSnapshotSettings(repo, Options.distribution, Options.serverType, Options.snapshotPath);                        
+               }
+                       
                
                PackageManager.dispose();
                initInstallManager();
        }
        
        /**
+        * Parsing proxy address.
+        * @param proxy
+        */
+       private static void parseProxy(String proxy) {
+               proxyType = ProxyType.MANUAL;
+               StringBuffer newProxyHost = new StringBuffer();
+               int idx = 0;
+               int length = proxy.length();
+               
+               for (int i = 0; i < length; i++) {
+                       char c = proxy.charAt(i);
+                       if (c != ':') {
+                               newProxyHost.append(c);
+                       } else {
+                               proxyHost = newProxyHost.toString();
+                               idx = i;
+                               break;
+                       }
+               }
+               
+               proxyPort = proxy.substring(idx+ 1, length);
+       }
+       
+       /**
+        * InstallManager use different SDK image path(repository address) 
+        * form when gets packages and saves configuration.
+        * So, SDK image path(repository address) needs to be reformed by usage.
+        * @param repository SDK image path
+        * @param additional If true, repository will be reformed by added string. otherwise removed string.
+        * @return Reformed SDK image path.
+        */
+       private static String getReformedPath(String repository, boolean additional) {
+               String repo = "";
+               if (additional) {
+                       if (repository.startsWith("file")) {
+                               repo = repository;
+                       } else if (repository.startsWith("~")) {
+                               repo = repository.substring(1);
+                               repo = PathUtil.get("file://", System.getProperty("user.home"), repo);
+                       } else if (repository.startsWith("/")) {
+                               repo = PathUtil.get("file://", repository);
+                       } else {
+                               Log.err("Not support url prefix.");
+                       }
+               } else {
+                       if (repository.startsWith("file")) {
+                               repo = repository.substring(7);
+                       } else if (repository.startsWith("~")) {
+                               repo = repository.substring(1);
+                               repo = PathUtil.get(System.getProperty("user.home"), repo);
+                       } else if (repository.startsWith("/")) {
+                               repo = repository;
+                       } else {
+                               Log.err("Not support url prefix.");
+                       }
+               }
+               
+               return repo;
+       }
+       
+       /**
         * init IM's configuation and packages information.
         * @return
         */
index 7897f2f..d758a5c 100644 (file)
@@ -55,6 +55,10 @@ public class CliUninstall {
         * @throws IMExitException 
         */
        public static boolean removeOnConsole(List<String> packageNames) throws IMExitException {
+               System.out.println("****************************************");
+               System.out.println("******* Start SDK uninstallation *******");
+               System.out.println("****************************************");
+               
                ViewController controller = new ViewController();
                controller.init();
                
index b34ff2d..387c6bf 100644 (file)
@@ -34,6 +34,7 @@ import java.util.List;
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMExitException;
 import org.tizen.installmanager.core.Options;
+import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.Registry;
 
@@ -42,15 +43,54 @@ import org.tizen.installmanager.lib.Registry;
  * @author Yongsung Kim <yongsung1.kim@samsung.com>
  */
 public class InstallManagerNoUI {
-       
+
        public static boolean cliInstall(List<String> packageNames) throws IMExitException {
+               if (Options.isNetwork) {
+                       return cliNetworkInstall(packageNames);
+               } else {
+                       return cliImageInstall(packageNames);
+               }
+       }
+       
+       public static boolean cliImageInstall(List<String> packageNames) throws IMExitException {
+               if (Registry.getInstalledPath() != "") {
+                       List<String> all = new ArrayList<String>();
+                       all.add("all");
+                       if (cliUninstall(all)) {
+                               Log.log("Success to remove installed SDK because of SDK image installation.");
+                       } else {
+                               Log.err("Fail to remove all installed SDK because of SDK image installation.");
+                       }
+               }
+               
+               CliInstall.refresh(); // Refresh installation environment.
+               
+               if (!CliInstall.validateRepository(false)) {
+                       return false;
+               }
+               
+               boolean result = false;
+               
+               if (CliInstall.installOnConsole(packageNames)) {
+                       result = true;
+                       Log.log("Success to install SDK as cli.");
+               } else {
+                       result = false;
+                       Log.err("Fail to install SDK as cli.");
+               }
+               return result;
+       }
+       
+       public static boolean cliNetworkInstall(List<String> packageNames) throws IMExitException {
                if (Registry.getInstalledPath() != "") {
                        String installRepo = Config.getInstance().getConfigFile().getRepository();
                        String installDist = Config.getInstance().getConfigFile().getDistribution();
                        String remoteRepo = Options.repository;
                        String remoteDist = Options.distribution;
+                       ServerType serverType = Config.getInstance().getConfigFile().getServerType();
                        
-                       if (!installRepo.equalsIgnoreCase(remoteRepo) || !installDist.equalsIgnoreCase(remoteDist)) {
+                       if (!installRepo.equalsIgnoreCase(remoteRepo) || !installDist.equalsIgnoreCase(remoteDist)
+                                       || serverType == ServerType.LOCAL) {
                                List<String> all = new ArrayList<String>();
                                all.add("all");
                                System.out.println("* Repository or distribution are changed. " + 
@@ -61,13 +101,19 @@ public class InstallManagerNoUI {
                                        Log.err("Fail to remove all installed packages before install new packages.");
                                }
                        }                       
-               } 
+               }
                
-               boolean result = false;
+               CliInstall.refresh(); // Refresh installation environment.
                
-               System.out.println("****************************************");
-               System.out.println("******** Start SDK installation ********");
-               System.out.println("****************************************");
+               if (!CliInstall.validateRepository(true)) {
+                       return false;
+               }
+               
+               if (!CliInstall.validateDistribution()) {
+                       return false;
+               }
+               
+               boolean result = false;
                
                if (CliInstall.installOnConsole(packageNames)) {
                        result = true;
@@ -80,20 +126,21 @@ public class InstallManagerNoUI {
        }
        
        public static boolean cliUninstall(List<String> packageNames) throws IMExitException {
-               boolean result = false;
-               
-               System.out.println("****************************************");
-               System.out.println("******* Start SDK uninstallation *******");
-               System.out.println("****************************************");
-               
-               if (CliUninstall.removeOnConsole(packageNames)) {
-                       result = true;
-                       Log.log("Success to uninstall SDK as cli.");
+               if (Registry.getInstalledPath() == "") {
+                       System.out.println("Tizen SDK was not installed.");
+                       return false;
                } else {
-                       result = false;
-                       Log.err("Fail to uninstall SDK as cli.");
+                       boolean result = false;
+
+                       if (CliUninstall.removeOnConsole(packageNames)) {
+                               result = true;
+                               Log.log("Success to uninstall SDK as cli.");
+                       } else {
+                               result = false;
+                               Log.err("Fail to uninstall SDK as cli.");
+                       }
+                       return result;                  
                }
-               return result;
        }
        
        public static void cliShowInstallInformation() {
index 06b07c4..37fd9db 100644 (file)
@@ -36,6 +36,7 @@ import java.util.List;
 
 import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.lib.Log;
+import org.tizen.installmanager.lib.Platform;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
 
 /**
@@ -121,11 +122,14 @@ public class Options {
        public static boolean snapshot = false;
        
        public static String repository = null;
+       public static String imageFilePath = null;
        public static String snapshotPath = null;
        public static ServerType serverType = null;
        public static String distribution = null;
        public static String targetDir = null;
        
+       public static boolean isNetwork = true;
+       
        public static List<String> packages = new ArrayList<String>();
        
        /**
@@ -180,7 +184,6 @@ public class Options {
                        } else if(arg.equals("-install")) {
                                if (iter.hasNext()) {
                                        doInstallNoUI = true;
-                                       serverType = ServerType.SNAPSHOT;
                                        workCliOptions(args);
                                } else {
                                        Log.err("-install option must have some arguments.");
@@ -348,10 +351,26 @@ public class Options {
        }
        
        private static boolean validateArgs() {
-               if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
-                       return true;
+               if (isNetwork) {
+                       if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
+                               return true;
+                       } else {
+                               return false;
+                       }
                } else {
-                       return false;
+                       if (Options.repository != null && !Options.packages.isEmpty()) {
+                               if (Platform.isWindows()) {
+                                       if (Options.repository.startsWith("file")) {
+                                               return true;
+                                       } else {
+                                               return false;
+                                       }
+                               } else {
+                                       return true;
+                               }
+                       } else {
+                               return false;
+                       }                       
                }
        }
                
@@ -369,17 +388,24 @@ public class Options {
                while (argIter.hasNext()) {
                        if (argIter.next().equalsIgnoreCase("-r")) {
                                argIter.remove();
-                               Options.repository = argIter.next();
+                               repository = argIter.next();
+                               if (!repository.startsWith("http")) {
+                                       isNetwork = false;
+                                       serverType = ServerType.LOCAL;
+                               } else {
+                                       serverType = ServerType.SNAPSHOT;
+                                       isNetwork = true;                                       
+                               }
                                argIter.remove();
                        }
                }
-
+               
                // set target directory
                argIter = argArray.iterator();
                while (argIter.hasNext()) {
                        if (argIter.next().equalsIgnoreCase("-l")) {
                                argIter.remove();
-                               Options.targetDir = argIter.next();
+                               targetDir = argIter.next();
                                argIter.remove();
                        }
                }
@@ -389,7 +415,7 @@ public class Options {
                while (argIter.hasNext()) {
                        if (argIter.next().equalsIgnoreCase("-d")) {
                                argIter.remove();
-                               Options.distribution = argIter.next();
+                               distribution = argIter.next();
                                argIter.remove();
                        }
                }
@@ -400,22 +426,33 @@ public class Options {
                        if (argIter.next().equalsIgnoreCase("-p")) {
                                argIter.remove();
                                while (argIter.hasNext()) {
-                                       Options.packages.add(argIter.next());
+                                       packages.add(argIter.next());
                                        argIter.remove();
                                }
                        }
                }
                
-               // set packages
+               // set proxy
                argIter = argArray.iterator();
                while (argIter.hasNext()) {
                        if (argIter.next().equalsIgnoreCase("-x")) {
                                argIter.remove();
                                while (argIter.hasNext()) {
                                        Options.proxy = argIter.next();
+                                       Log.log("Use proxy setting => " + Options.proxy);
                                        argIter.remove();
                                }
                        }
                }
        }
+       
+       private static void exclusiveOptions(String option, Iterator<String> argIter) {
+               while (argIter.hasNext()) {
+                       if (argIter.next().equalsIgnoreCase(option)) {
+                               Log.err("[" + option + "] cannot be used.");
+                               System.out.println("[" + option + "] cannot be used with some options.");
+                               throw new IMFatalException("[" + option + "] cannot be used with some options.");
+                       }
+               }
+       }
 }
index 4ce9198..464b4d8 100644 (file)
@@ -41,6 +41,7 @@ import java.util.Map;
 import java.util.Stack;
 
 import org.tizen.installmanager.core.Config;
+import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.core.DistributionController;
 import org.tizen.installmanager.core.IMExitException;
 import org.tizen.installmanager.core.IMFatalException;
@@ -162,8 +163,9 @@ public abstract class PackageManager {
         */
        public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {
                HashMap<String,List<PropertySection>> r2sMap = null;
+               ServerType serverType = Config.getInstance().getConfigFile().getServerType();
                
-               if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // Using SDK Image
+               if (serverType == ServerType.LOCAL) { // Using SDK Image
                        r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);
                } else {
                        r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);