[INST] Installmanager can support repository history.(max 5) 73/19773/1
authoryongsung1.kim <yongsung1.kim@samsung.com>
Mon, 31 Mar 2014 07:54:48 +0000 (16:54 +0900)
committeryongsung1.kim <yongsung1.kim@samsung.com>
Thu, 17 Apr 2014 10:55:40 +0000 (19:55 +0900)
Conflicts:

InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java

Change-Id: I332d385112e6f13643f4219c9360f8f46d389a17
Signed-off-by: yongsung1.kim <yongsung1.kim@samsung.com>
InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java
InstallManager_java/src/org/tizen/installmanager/lib/Registry.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/ChangeServerDialog.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java

index af88e58..26f17cd 100644 (file)
@@ -109,7 +109,8 @@ public class InstallManager {
         * Load config file\r
         */\r
        public void initConfig() {\r
-               if (mConfig != null) {\r
+               if (mConfig != null) {
+                       Registry.saveRepoInfo(mConfig.getConfigFile().getRepository());\r
                        if (Config.isSupportMultiSDK()) {\r
                                if (!Registry.getInstalledPath().isEmpty()) {\r
                                        mConfig.setTargetDir(Registry.getInstalledPath());\r
@@ -119,7 +120,7 @@ public class InstallManager {
                        }\r
                } else {\r
                        mConfig = Config.getInstance();\r
-\r
+                       Registry.saveRepoInfo(mConfig.getConfigFile().getRepository());\r
                        if (Options.doReplaceRepository) {\r
                                Log.log("Replace repository => " + Options.repository);\r
                                mConfig.getConfigFile().setRepository(Options.repository);\r
index 245dc8c..648ffcc 100644 (file)
@@ -156,7 +156,8 @@ public class ErrorController {
                SNAPSHOT_PATH_IS_NULL("Snapshot path missing."),\r
                FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."),\r
                \r
-               //Using add extra repository dialog\r
+               //Using add extra repository dialog
+               INVALID_REPOSITORY_FOR_HISTORY("Invalid repository for history."),\r
                SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."),\r
                NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."),\r
                HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."),\r
index b0bd66c..1b966f9 100644 (file)
@@ -37,6 +37,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMFatalException;
@@ -55,12 +56,15 @@ public class Registry {
        //installed path.
        public static final String REGISTRY_FILE_NAME = "tizensdkpath";
        public static final String MULTI_SDK_FILE_NAME = "multisdkpath";
+       public static final String REPO_HISTORY_FILE_NAME = "repo.history";
        public static final String REGISTRY_FILE_PATH = PathUtil.get(
                        Config.INSTALL_MANAGER_CONFIG, REGISTRY_FILE_NAME);
        private static final String OLD_REGISTRY_FILE_PATH = PathUtil.get(
                        Config.getConfigHome(), REGISTRY_FILE_NAME);
        public static final String MULTI_SDK_FILE_PATH = PathUtil.get(
                        Config.INSTALL_MANAGER_CONFIG, MULTI_SDK_FILE_NAME);
+       public static final String REPO_HISTORY_FILE_PATH = PathUtil.get(
+                       Config.INSTALL_MANAGER_CONFIG, REPO_HISTORY_FILE_NAME);
        private static final String INSTALLED_PATH_KEY = "TIZEN_SDK_INSTALLED_PATH";
        private static final String SDK_DATA_PATH_KEY = "TIZEN_SDK_DATA_PATH";
 
@@ -77,6 +81,8 @@ public class Registry {
        public static String sdkDataPath = "";
 //     public static String sdkDataPath = getSDKinfoBySDKPath(Config.getInstance().getTargetDir());
        private static ArrayList<String> sdkPathList = getSDKPath();
+       private static ArrayList<String> repoHistory = getRepoHistory();
+       private final static int REPO_HISTORY_COUNT = 5;
 
        /**
         * Exports target path to the registry file.
@@ -337,6 +343,15 @@ public class Registry {
                return sdkPath;
        }
        
+       public static ArrayList<String> getRepoHistory() {
+               File repoHistoryFile = new File(REPO_HISTORY_FILE_PATH);
+               ArrayList<String> repoHistory = new ArrayList<String>();
+               if (repoHistoryFile.exists()) {
+                       repoHistory = getPathFromRegistryFile(REPO_HISTORY_FILE_PATH);
+               }
+               return repoHistory;
+       }
+       
        private static ArrayList<String> getPathFromRegistryFile(String filePath) {
                ArrayList<String> sdkPaths = new ArrayList<String>();
                InputStream is = null;
@@ -449,7 +464,6 @@ public class Registry {
                        if (bw != null) {
                                try {
                                        bw.close();
-
                                } catch (IOException e) {
                                        Log.ExceptionLog(e);
                                }
@@ -510,6 +524,69 @@ public class Registry {
                }
        }
        
+       public static void saveRepoInfo(String repository) {
+               if (repository == null || repository.isEmpty()) {
+                       Log.err("Repository is invalid for registering : " + repository);
+                       throw new IMFatalException(ErrorCode.INVALID_REPOSITORY_FOR_HISTORY);
+               }
+               
+               File repoHistoryFile = new File(REPO_HISTORY_FILE_PATH);
+               if (!repoHistoryFile.exists() || Options.doInstallNoUI || Options.doRemoveNoUI) {
+                       try {
+                               repoHistoryFile = PathUtil.makeNewFile(REPO_HISTORY_FILE_PATH);
+                       } catch (IOException e) {
+                               Log.ExceptionLog(e);
+                               return;
+                       }                       
+               } else {
+                       if (repoHistory.contains(repository)) {
+                               return;
+                       }
+               }
+               
+               if (repoHistoryFile == null) {
+                       return;
+               }
+               
+               removeOldHistory();
+               
+               BufferedWriter bw = null;
+               try {
+                       FileWriter fw = new FileWriter(repoHistoryFile);
+                       bw = new BufferedWriter(fw);
+                       if (!repoHistory.isEmpty()) {
+                               for (String repo : repoHistory) {
+                                       if (!repo.equalsIgnoreCase("")) {
+                                               bw.write(repo);
+                                               bw.newLine();
+                                       }
+                               }
+                       }
+                       bw.write(repository);
+                       bw.newLine();
+                       bw.flush();                             
+               } catch (IOException e) {
+                       Log.err("Cannot register to file. " + repoHistoryFile.getAbsolutePath());
+                       throw new IMFatalException(ErrorCode.CANNOT_REGISTER_TARGET_DIR);
+               } finally {
+                       if (bw != null) {
+                               try {
+                                       bw.close();
+                                       repoHistory.add(repository);
+                                       Log.log("Package server address history. => " + repoHistory);
+                               } catch (IOException e) {
+                                       Log.ExceptionLog(e);
+                               }
+                       }
+               }
+       }
+       
+       private static void removeOldHistory() {
+               while (repoHistory.size() >= REPO_HISTORY_COUNT) {
+                       repoHistory.remove(0);                  
+               }
+       }
+       
        /**
         * Get installed version.
         * @return
index 9d9565e..c42947c 100644 (file)
@@ -1,17 +1,45 @@
+/*
+ *  InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Donghee Yang <donghee.yang@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Yongsung kim <yongsung1.kim@samsung.com>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
 package org.tizen.installmanager.ui.dialog;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.lib.Downloader;
 import org.tizen.installmanager.lib.ErrorController;
@@ -20,10 +48,11 @@ import org.tizen.installmanager.util.PathUtil;
 public class ChangeServerDialog extends Dialog {
        private static final String STRING_TITLE = "Change Server";
        private Label titleLabel = null;
-       private Text serverText = null;
+       private Combo serverCombo = null;
        private Label errLabel = null;
        
        private String serverUrl = "";
+       private ArrayList<String> serverUrls = new ArrayList<String>();
        
        public ChangeServerDialog(Shell parentShell) {
                super(parentShell);
@@ -50,7 +79,7 @@ public class ChangeServerDialog extends Dialog {
                
                setTitle();
                setTitleLabel(container);
-               setServerUrlText(container);
+               setServerUrlComboBox(container);
                setErrLabel(container);
 
                return container;
@@ -58,9 +87,10 @@ public class ChangeServerDialog extends Dialog {
        
        @Override
        protected void okPressed() {
-               String changeServerUrl = serverText.getText();
+               String changeServerUrl = serverCombo.getText();
                
-               if (serverUrl.equals(changeServerUrl)) {
+               if (serverUrls.contains(changeServerUrl)) {
+                       serverUrl = changeServerUrl;
                        this.close();
                } else {                        
                        if (isExactFormat(changeServerUrl)) {
@@ -84,16 +114,20 @@ public class ChangeServerDialog extends Dialog {
                titleLabel.setBounds(10, 10, 200, 23);
        }
        
-       private void setServerUrlText(Composite composite) {
-               serverText = new Text(composite, SWT.BORDER);
-               serverText.setBounds(10, 33, 360, 23);
-               serverText.setEnabled(true);
+       private void setServerUrlComboBox(Composite composite) {
+               serverCombo = new Combo(composite, SWT.NONE);
+               serverCombo.setBounds(10, 33, 360, 23);
+               serverCombo.setEnabled(true);
                
-               if (serverUrl.isEmpty()) {
-                       serverText.setText("http://");
+               if (serverUrls.isEmpty()) {
+                       serverCombo.setText("http://");
                } else {
-                       serverText.setText(serverUrl);
-                       serverText.selectAll();
+                       serverCombo.setText(serverUrl);
+                       for (String url : serverUrls) {
+                               if (url != null) {
+                                       serverCombo.add(url);                                   
+                               }
+                       }
                }
        }
        
@@ -143,6 +177,10 @@ public class ChangeServerDialog extends Dialog {
                serverUrl = url; 
        }
        
+       public void setCurrentServer(ArrayList<String> urls) {
+               serverUrls = urls; 
+       }
+       
        public String getServerUrl() {
                return serverUrl;
        }
index 02e913b..cc71b9f 100644 (file)
@@ -30,6 +30,7 @@ package org.tizen.installmanager.ui.dialog;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -46,7 +47,6 @@ import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Button;
@@ -60,15 +60,18 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.DistributionController;
 import org.tizen.installmanager.core.InstallManager;
+import org.tizen.installmanager.core.InstallManagerConstants;
 import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.core.IMFatalException;
 import org.tizen.installmanager.core.SnapshotLog;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
 import org.tizen.installmanager.lib.Platform;
+import org.tizen.installmanager.lib.Registry;
 import org.tizen.installmanager.pkg.lib.PackageManager;
 import org.tizen.installmanager.pkg.model.Snapshot;
 import org.tizen.installmanager.pkg.model.SnapshotList;
@@ -87,6 +90,7 @@ public class ConfigurationDialog extends Dialog {
        private String snapshotPath = "";
        private String currentDistribution = "";
        private String repository = "";
+       ArrayList<String> repos = new ArrayList<String>();
        private ServerType serverType = ServerType.SNAPSHOT;
        
        private SnapshotLogDialog snapshotDialog = null;
@@ -103,7 +107,6 @@ public class ConfigurationDialog extends Dialog {
 
        private Table snapshotTable;
 
-       private Label localErrLabel;
        private Label textPackageServerUrl;
        private Label textLocalServerUrl;
        private File imageFile;
@@ -111,6 +114,14 @@ public class ConfigurationDialog extends Dialog {
        private DistributionController controller =  null;
        private boolean noErr = true; // flag check to verify pkg list file path.
        
+       //patch support
+       private Button buttonPatch = null;
+       private Label labelPatch = null;
+       private Button buttonPatchSelection = null;
+       
+       private static final int IMAGE_FILE = 0;
+       private static final int PATCH_FILE = 1;
+       
        //snapshot table column
        public static final int TABLE_STATUS = 0;
        public static final int TABLE_NAME = 1;
@@ -154,7 +165,11 @@ public class ConfigurationDialog extends Dialog {
                setLocalButton(container);
                setFileDialog(container);
                setLocalLabel(container);
-               setLocalErrorlabel(container);
+               
+//             setSeparator_02(container);
+//             setPatchButton(container);
+//             setPatchDialog(container);
+//             setPatchLabel(container);
                
                return container;
        }
@@ -234,6 +249,14 @@ public class ConfigurationDialog extends Dialog {
                this.repository = serverUrl;
        }
        
+       public void setRepositories(ArrayList<String> serverUrls) {
+               if (serverUrls == null || serverUrls.isEmpty()) {
+                       return;
+               }
+               
+               this.repos = serverUrls;
+       }
+       
        /**
         * Change package server type by install type(normal, snapshot, local).
         * @param isConfDialog User push 'OK' button in configuration dialog is true, otherwise is false.
@@ -342,7 +365,6 @@ public class ConfigurationDialog extends Dialog {
                                buttonSelectImage.setEnabled(false);
                                textLocalServerUrl.setEnabled(false);
                                textLocalServerUrl.setText("");
-                               localErrLabel.setText("");
                                setOkEnable(false);
                        }
                });
@@ -380,12 +402,16 @@ public class ConfigurationDialog extends Dialog {
                        public void widgetSelected(SelectionEvent e) {
                                ChangeServerDialog changeServerDialog = new ChangeServerDialog(composite.getShell());
                                changeServerDialog.setCurrentServer(repository);
+                               changeServerDialog.setCurrentServer(Registry.getRepoHistory());
                                int ret = changeServerDialog.open();
                                if (ret == 0) {
                                        String changeServerUrl = changeServerDialog.getServerUrl();
                                        if (!repository.equals(changeServerUrl)) {
                                                setPackageServerEnv(changeServerUrl);
                                        }
+                                       if (!Registry.getRepoHistory().contains(changeServerUrl)) {
+                                               Registry.saveRepoInfo(changeServerUrl);
+                                       }
                                } else {
                                        Log.log("Change server dialog is canceled.");                                   
                                }
@@ -559,7 +585,6 @@ public class ConfigurationDialog extends Dialog {
                                buttonLocal.setSelection(false);
                                textLocalServerUrl.setEnabled(false);
                                textLocalServerUrl.setText("");
-                               localErrLabel.setText("");
                                buttonSelectImage.setEnabled(false);
                                
                                setOkEnable(true);
@@ -736,7 +761,6 @@ public class ConfigurationDialog extends Dialog {
                        public void widgetSelected(SelectionEvent e) {
                                textLocalServerUrl.setEnabled(true);
                                buttonSelectImage.setEnabled(true);
-                               localErrLabel.setEnabled(true);
                                
                                distributionCombo.setEnabled(false);
                                buttonChangeServer.setEnabled(false);
@@ -776,10 +800,9 @@ public class ConfigurationDialog extends Dialog {
                                        Log.log("SDK image File selection => " + strDir);
                                        if (strDir.endsWith(SDK_IMAGE_ZIP_EXTENSION)) {
                                                imageFile = new File(strDir);
-                                               if (validation(strDir)) {
+                                               if (validation(strDir, IMAGE_FILE)) {
                                                        Log.log("Package list file found in SDK image => " + strDir);
                                                        textLocalServerUrl.setText(strDir);
-                                                       localErrLabel.setText("");
                                                        UNZIP_RESULT unzipResult = unzipSDKImageFile(imageFile);
                                                        if (checkUnzip(unzipResult)) {
                                                                setOkEnable(true);                                                              
@@ -828,7 +851,7 @@ public class ConfigurationDialog extends Dialog {
        }
        
        @SuppressWarnings("unused")
-       private boolean validation(String strDir) {
+       private boolean validation(String strDir, int fileStyle) {
                ZipFile zipFile = null;
                ZipEntry entry = null;
                
@@ -841,10 +864,24 @@ public class ConfigurationDialog extends Dialog {
                }
 
                if (zipFile != null) {
-                       String packageList = PackageManager.getInstance().getPackageListFileName();
-                       Log.log("This platform must have package list file as '" + packageList + "'");
-                       
-                       entry = zipFile.getEntry(packageList);
+                       if (fileStyle == IMAGE_FILE) {
+                               String packageList = PackageManager.getInstance().getPackageListFileName();
+                               Log.log("This platform must have package list file as '" + packageList + "'");
+                               
+                               entry = zipFile.getEntry(packageList);
+                       } else if (fileStyle == PATCH_FILE) {
+                               String scriptFile = InstallManagerConstants.SDK_PATCH_SCRIPT;
+                               Log.log("Patch must have execute script file as '" + scriptFile + "'");
+                               
+                               entry = zipFile.getEntry(scriptFile);
+                       } else {
+                               try {
+                                       zipFile.close();
+                               } catch (IOException e) {
+                                       Log.ExceptionLog(e);
+                               }
+                               return false;
+                       }
                        
                        try {
                                zipFile.close();
@@ -857,12 +894,6 @@ public class ConfigurationDialog extends Dialog {
                        return false;
                }
        }
-       
-       private void setLocalErrorlabel(Composite composite) {
-               localErrLabel = new Label(composite, SWT.WRAP);
-               localErrLabel.setBounds(20, 343, 475, 45);
-               localErrLabel.setForeground(new Color(null, 255, 0, 0));
-       }
 
        /**
         * Show file path dialog when file dialog button is pushed.
@@ -881,6 +912,78 @@ public class ConfigurationDialog extends Dialog {
 
                return strDir;
        }
+       
+       private void setSeparator_02(Composite composite) {
+               Label sep = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+               sep.setBounds(10, 348, 560, 1);
+       }
+       
+       private void setPatchButton(Composite composite) {
+               buttonPatch = new Button(composite, SWT.RADIO);
+               buttonPatch.setSelection(false);
+               buttonPatch.setBounds(10, 358, 350, 18);
+               buttonPatch.setText("SDK patch");
+
+               buttonPatch.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               textLocalServerUrl.setEnabled(true);
+                               buttonPatchSelection.setEnabled(true);
+                               
+                               distributionCombo.setEnabled(false);
+                               buttonChangeServer.setEnabled(false);
+                               buttonSnapshotFilter.setEnabled(false);
+                               buttonSelectImage.setEnabled(false);
+                               setOkEnable(false);
+                               
+                               snapshotPath = "";
+                       }
+               });
+       }
+       
+       private void setPatchDialog(Composite composite) {
+               buttonPatchSelection = new Button(composite, SWT.NONE);
+               buttonPatchSelection.setEnabled(false);
+               buttonPatchSelection.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               String strDir = showSettingPatchpathDlg();
+                               if (strDir != null) {
+                                       Log.log("Success to open SDK patch selection file dialog.");
+                                       Log.log("SDK patch file selection => " + strDir);
+                                       if (strDir.endsWith(SDK_IMAGE_ZIP_EXTENSION)) {
+                                               
+                                       }
+                               }
+                       }
+               });
+
+               buttonPatchSelection.setImage(PathUtil.getImageFromResource("/res/icons/icon_directory_open.png"));
+               if (!Platform.isMacOS()) {
+                       buttonPatchSelection.setBounds(520, 381, 35, 29);
+               } else {
+                       buttonPatchSelection.setBounds(525, 380, 40, 31);
+               }
+       }
+       
+       private void setPatchLabel(Composite composite) {
+               labelPatch = new Label(composite, SWT.BORDER);
+               labelPatch.setBounds(10, 386, 500, 20);
+               labelPatch.setEnabled(false);
+       }
+       
+       private String showSettingPatchpathDlg() {
+               FileDialog dlg = new FileDialog(Display.getCurrent().getShells()[0]);
+               dlg.setText("Select the SDK patch file.");
+               String strDir = null;
+               try {
+                       strDir = dlg.open();                    
+               } catch (SWTException e) {
+                       Log.ExceptionLog(e);
+               }
+
+               return strDir;
+       }
 
        /**
         * Unzip SDK ImageFile.