[Title] EXT : Support to cache extra information and remove extra
authoryongsung1.kim <yongsung1.kim@samsung.com>
Mon, 12 Nov 2012 10:19:18 +0000 (19:19 +0900)
committeryongsung1.kim <yongsung1.kim@samsung.com>
Mon, 12 Nov 2012 10:19:18 +0000 (19:19 +0900)
packages.
[Desc.] * InstallManager can support to cache extra information.
* InstallManager can maintain the newest extra package list always.
* User can remove extra packages each repository.

Change-Id: Id790d976b0893da6dbf77adf1012c159cfeaf676

InstallManager_java/src/org/tizen/installmanager/core/SDKExtensionInfo.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/AddExtraDialog.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/AddExtraRepositoryDialog.java
InstallManager_java/src/org/tizen/installmanager/ui/page/InstallableListPage.java
InstallManager_java/src/org/tizen/installmanager/ui/page/UpdatableListPage.java
InstallManager_java/src/org/tizen/installmanager/ui/page/ViewController.java

index 6498119..70dd80c 100644 (file)
@@ -31,15 +31,19 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 
 import org.tizen.installmanager.lib.Downloader;
+import org.tizen.installmanager.lib.ErrorController;
+import org.tizen.installmanager.lib.IIMProgressMonitor;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.pkg.lib.PackageManager;
-import org.tizen.installmanager.pkg.model.ConfigFile;
+import org.tizen.installmanager.pkg.model.Package;
 import org.tizen.installmanager.pkg.model.PackageSet;
+import org.tizen.installmanager.ui.InstallManagerWindow;
 import org.tizen.installmanager.util.PathUtil;
 
 /**
@@ -52,6 +56,7 @@ public class SDKExtensionInfo {
        
        private static SDKExtensionInfo sdkExtensionInfo = null;
        //member variable
+       LinkedHashMap<String, String> extensionRepositories = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> userExtensionRepositories = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> builtInExtensionRepositories = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> cacheRepositories = new LinkedHashMap<String, String>();
@@ -61,13 +66,17 @@ public class SDKExtensionInfo {
        private final String CACHING_FILE_NAME = "CacheInformation.txt";
        private final String CACHING_DIRECTORY_PATH = PathUtil.get(Config.getConfigHome(), CACHING_DIR_NAME); // tizen-sdk-data/extra
        private String CACHING_FULL_PATH = null;
-       private List<String> CACHING_PACKAGE_LIST_PATH = null;
        
-       //member func
        private SDKExtensionInfo() {
-               load();
+
        }
        
+       /**
+        * Add extra repository information from add extra dialog.
+        * @param name Extra repository name.
+        * @param packageRepo Extra repository address.
+        * @return If true, success to add. false, fail to add.
+        */
        public boolean add(String name, String packageRepo) {
                if (name == null || !checkPackageRepo(packageRepo)) {
                        return false;
@@ -81,34 +90,76 @@ public class SDKExtensionInfo {
                
                setCachePath(name);
                save(name, true);
-               downloadExtraPkgList(packageRepo);
+               downloadExtraPkgList(packageRepo, name);
                
                return true;
        }
        
+       /**
+        * Check to be duplicated user extra package address.
+        * @param packageRepo
+        * @return If true, duplicated repository exists, false not.
+        */
        public boolean contains(String packageRepo) {
                return userExtensionRepositories.containsKey(packageRepo);
        }
        
+       /**
+        * Check to be duplicated built-in extra package address.
+        * @param packageRepo
+        * @return If true, duplicated repository exists, false not.
+        */
        public boolean containsBuiltIn(String packageRepo) {
                return builtInExtensionRepositories.containsKey(packageRepo);
        }
        
+       /**
+        * Remove extra repository information from saved user extension repositories.
+        * @param name Extra repository name.
+        * @param packageRepo Extra repository address.
+        */
        public void remove(String name, String packageRepo) {
+               uninstallExtraPackages(packageRepo);
                if (contains(packageRepo)) {
                        userExtensionRepositories.remove(packageRepo);
                }
+               
                save(name, false);
        }
        
        /**
+        * Uninstall extra packages which belong to selected extra repository. 
+        * @param repo Selected extra repository for removing.
+        */
+       private void uninstallExtraPackages(String repo) {
+               boolean result = false;
+
+               PackageSet pkgs = PackageManager.getInstance().getExtensionPackages();
+               
+               List<String> installedExtraList = new ArrayList<String>();
+               for (Package pkg : pkgs) {
+                       if (pkg.getExtensionServer().equalsIgnoreCase(repo)) {
+                               installedExtraList.add(pkg.getPackageName());
+                       }
+               }
+               
+               if (installedExtraList.size() <= 0) {
+                       return;
+               } else {
+                       result = InstallManagerWindow.getInstallManagerWindow().
+                                       getViewController().uninstall(installedExtraList, null);
+               }
+
+               ErrorController.setInstallationSuccess(result);
+       }
+       
+       /**
         * Save extra repository information to config file and cache directory.
         *  otherwise remove extra information form cache. 
         * @param name extra repository name
         * @param isAdd true is saving, false is removing.
         */
        public void save(String name, boolean isAdd) {
-               saveToConfFile();
                if (isAdd) {
                        saveCache();                    
                } else {
@@ -117,17 +168,6 @@ public class SDKExtensionInfo {
        }
        
        /**
-        * Save extesion information(name(key), repository(value)) to config file.
-        */
-       private void saveToConfFile() {
-               ConfigFile confFile = Config.getInstance().getConfigFile();
-               
-               confFile.setExtensionServer(userExtensionRepositories.toString());
-               
-               Config.getInstance().saveConfig();
-       }
-       
-       /**
         * Save extra repository information to cache.
         * @param name Repository name
         * @param packageRepo Repository URL
@@ -158,8 +198,6 @@ public class SDKExtensionInfo {
                File cacheDir = new File(CACHING_FULL_PATH);
                if (!cacheDir.exists()) {
                        cacheDir.mkdirs();                      
-               } else {
-                       //to do nothing(already existing directory).
                }
        }
        
@@ -211,7 +249,7 @@ public class SDKExtensionInfo {
         * @param packageRepo Remote extra repository address.
         * @return Caching package list file path.
         */
-       private String downloadExtraPkgList(String packageRepo) {
+       private String downloadExtraPkgList(String packageRepo, String name) {
                URL serverUrl = null;
                try {
                        serverUrl = new URL(PathUtil.addURLPath(packageRepo, PackageManager.getInstance().getPackageListFileName()));
@@ -221,10 +259,14 @@ public class SDKExtensionInfo {
                }
  
                Downloader dl = InstallManager.getDownloader();
-               String extraPkgListPath = PathUtil.get(CACHING_FULL_PATH,
+               
+               String extraPkgListPath = PathUtil.get(CACHING_DIRECTORY_PATH, name,
                                PackageManager.getInstance().getPackageListFileName());
                
                File extraPkgList = new File(extraPkgListPath);
+               if (extraPkgList.exists()) {
+                       extraPkgList.delete();
+               }
                
                long size = dl.download(serverUrl, extraPkgList.getAbsolutePath(), null);
                
@@ -233,15 +275,20 @@ public class SDKExtensionInfo {
                } else {
                        return null;
                }
-
        }
        
        /**
         * Remove cache information.
         * @param name
         */
-       private void removeCache(String name) {
-               File cacheDir = new File(PathUtil.get(CACHING_DIRECTORY_PATH, name));
+       public void removeCache(String name) {
+               File cacheDir = null;
+               if (name != null) {
+                       cacheDir = new File(PathUtil.get(CACHING_DIRECTORY_PATH, name));
+               } else {
+                       cacheDir = new File(CACHING_DIRECTORY_PATH);
+               }
+
                if (cacheDir.exists()) {
                        if (PathUtil.remove(cacheDir)) {
                                Log.log("Success to extra cache dir. => " + cacheDir);
@@ -250,30 +297,102 @@ public class SDKExtensionInfo {
                        }
                }
                writeExtraRepoToCache();
-               String tmp = PathUtil.readAllTextFromFile(PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME), false);
-               if (tmp.equalsIgnoreCase("{}")) {
-                       // 'CacheInformation.txt' file is empty. so it could be removed.
-                       if (PathUtil.remove(CACHING_DIRECTORY_PATH)) {
-                               Log.log("Success to remove cache file. => " + CACHING_DIRECTORY_PATH);
-                       } else {
-                               Log.err("Fail to remove cache file. => " + CACHING_DIRECTORY_PATH);
-                       }
-               } else {
-                       // 'CacheInformation.txt' file is empty.
+               File cacheInfo = new File(PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME));
+               if (cacheInfo.exists()) {
+                       String tmp = PathUtil.readAllTextFromFile(cacheInfo.getAbsolutePath(), false);
+                       if (tmp.equalsIgnoreCase("{}")) {
+                               // 'CacheInformation.txt' file is empty. so it could be removed.
+                               if (PathUtil.remove(CACHING_DIRECTORY_PATH)) {
+                                       Log.log("Success to remove cache file. => " + CACHING_DIRECTORY_PATH);
+                               } else {
+                                       Log.err("Fail to remove cache file. => " + CACHING_DIRECTORY_PATH);
+                               }
+                       }                       
                }
        }
        
+       /**
+        * Load extension packages from cache.
+        */
        public void load() {
-               String extensionInfo = "";
+               String userExtensionInfo = "";
                String extraCachePath = PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME); // tizen-sdk-data/extra/CacheInformation.txt
                File extraCache = new File(extraCachePath);
                if (extraCache.exists()) { // If cache file exists, installmanager loads extension information from cache.
-                       extensionInfo = PathUtil.readAllTextFromFile(PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME), false);
+                       userExtensionInfo = PathUtil.readAllTextFromFile(extraCachePath, false);        
                }
-               String builtInExtensionInfo = Config.getInstance().getConfigFile().getBuiltInExtensionServer();
                
+               String builtInExtensionInfo = Config.getInstance().getConfigFile().getBuiltInExtensionServer();
                builtInExtensionRepositories = parseLocationInformationToMap(builtInExtensionInfo);
-               userExtensionRepositories = parseLocationInformationToMap(extensionInfo);
+               userExtensionRepositories = parseLocationInformationToMap(userExtensionInfo);
+
+               setExtensionRepositories();
+               
+               PackageManager pm = PackageManager.getInstance();
+               try {
+                       pm.loadExtensionPackages();
+               } catch (IOException e) {
+                       Log.ExceptionLog(e);
+               }
+       }
+       
+       /**
+        * Set absolute path of cache. 
+        */
+       private void setCacheExtensionInfo() {
+               String extensionInfo = PathUtil.readAllTextFromFile(PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME), false);
+               LinkedHashMap<String, String> extensionCache = parseLocationInformationToMap(extensionInfo);
+               File tmp = new File(PathUtil.get(CACHING_DIRECTORY_PATH));
+               for (String key : extensionCache.keySet()) {
+                       String name = extensionCache.get(key);
+                       try {
+                               String cacheKey = PathUtil.get(tmp.toURI().toURL().toString(), name);
+                               cacheRepositories.put(cacheKey, name);
+                       } catch (MalformedURLException e) {
+                               // Thrown to indicate that a malformed URL has occurred.
+                               Log.ExceptionLog(e);
+                       }
+               }
+       }
+
+       /**
+        * Refresh cache from extra server.
+        */
+       public void refreshCache() {
+               final refreshCacheThread refreshThread = new refreshCacheThread(null);
+               refreshThread.start();
+               try {
+                       refreshThread.join();
+               } catch (InterruptedException e) {
+                       Log.ExceptionLog(e);
+               }
+       }
+       
+       class refreshCacheThread extends Thread {
+               public refreshCacheThread(IIMProgressMonitor monitor) {
+                       
+               }
+
+               /**
+                * refreshCacheThread thread run
+                */
+               @Override
+               public void run() {
+                       String userExtensionInfo = "";
+                       String extraCachePath = PathUtil.get(CACHING_DIRECTORY_PATH, CACHING_FILE_NAME); // tizen-sdk-data/extra/CacheInformation.txt
+                       File extraCache = new File(extraCachePath);
+                       if (extraCache.exists()) { // If cache file exists, installmanager loads extension information from cache.
+                               userExtensionInfo = PathUtil.readAllTextFromFile(extraCachePath, false);        
+                       }
+
+                       LinkedHashMap<String, String> remoteRepositories = parseLocationInformationToMap(userExtensionInfo); 
+                       Collection<String> keys = remoteRepositories.keySet();
+                       if (!keys.isEmpty()) {
+                               for (String key : keys) {
+                                       downloadExtraPkgList(key, remoteRepositories.get(key));                 
+                               }
+                       }
+               }
        }
        
        public boolean checkPackageRepo(String packageRepo) {
@@ -308,64 +427,17 @@ public class SDKExtensionInfo {
                return extensionInformation;
        }
        
-       /**
-        * Get extension packages.
-        * @return Extension package set.
-        */
-       public PackageSet getExtensionPackages() {
-               PackageManager pm = PackageManager.getInstance();
-               
-               if (pm == null) {
-                       return PackageSet.EMPTY;
-               } else {
-                       try {
-                               //Get all extension repositories.
-                               LinkedHashMap<String, String> extensionRepositories = new LinkedHashMap<String, String>();
-                               extensionRepositories.putAll(builtInExtensionRepositories);
-                               extensionRepositories.putAll(userExtensionRepositories);
-                               
-                               pm.loadExtensionPackages(extensionRepositories.keySet());
-                               if (pm.getExtensionPackages().isEmpty()) {
-                                       if(getExtensionPkgsFromCache(pm) == null) {
-                                               Log.err("Cannot load extension packages from cache.");
-                                       }
-                               }
-                               return pm.getRootMetaPackagesOfExtensionServer();
-                               
-                       } catch (IOException e) {
-                               Log.ExceptionLog(e);
-                               return PackageSet.EMPTY;
-                       }
-               }
+       private void setExtensionRepositories() {
+               extensionRepositories.clear();
+               extensionRepositories.putAll(userExtensionRepositories);
+               extensionRepositories.putAll(builtInExtensionRepositories);
        }
        
-       /**
-        * Get extension packages from cache. 
-        * @param pm PackageManager object.
-        * @return PackageManager object which has extension packages.
-        */
-       private PackageManager getExtensionPkgsFromCache(PackageManager pm) {
-               Collection<String> keys = userExtensionRepositories.keySet();
-               
-               for (String key : keys) {
-                       CACHING_PACKAGE_LIST_PATH.add(PathUtil.get(CACHING_FULL_PATH, userExtensionRepositories.get(key)
-                                       , PackageManager.getInstance().getPackageListFileName()));
-               }
-               
-               if (CACHING_PACKAGE_LIST_PATH != null) {
-                       LinkedHashMap<String, String> extensionRepositories = new LinkedHashMap<String, String>();
-                       extensionRepositories.putAll(builtInExtensionRepositories);
-                       try {
-                               pm.loadExtensionPackages(CACHING_PACKAGE_LIST_PATH);
-                       } catch (IOException e) {
-                               //Cannot read extension packages from package list cache file.
-                               Log.ExceptionLog(e);
-                       }                       
-               }
-               return pm;
+       public LinkedHashMap<String, String> getExtensionRepositories() {
+               return extensionRepositories;
        }
        
-       public LinkedHashMap<String, String> getExtensionRepositories() {
+       public LinkedHashMap<String, String> getUserExtensionRepositories() {
                return userExtensionRepositories;
        }
        
index c821a20..a9500a7 100644 (file)
@@ -105,6 +105,15 @@ public abstract class PackageManager {
                UNINSTALL;
        }
        
+       /**
+        * It is a position where can installmanager get the package list file 
+        */
+       private enum Style {
+               NETWORK,
+               IMAGE,
+               EXTRA;
+       }
+       
        //abstract method
        /**
         * Get package list file name.
@@ -145,9 +154,9 @@ public abstract class PackageManager {
        public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {
                HashMap<String,List<PropertySection>> r2sMap = null;
                if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // Using SDK Image
-                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, false);
+                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);
                } else {
-                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, true);                   
+                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);                  
                }
 
                setRepoPackages(r2sMap);
@@ -158,41 +167,43 @@ public abstract class PackageManager {
         * @param repoPackagesUrls Packgae server list.
         * @throws IOException
         */
-       public void loadExtensionPackages(Collection<String> repoPackagesUrls) throws IOException {
-               HashMap<String,List<PropertySection>> repoToSectionsMap = getRepositoryAndPackageList(repoPackagesUrls, false);
+       public void loadExtensionPackages() throws IOException {
+               HashMap<String,List<PropertySection>> repoToSectionsMap = 
+                               getRepositoryAndPackageList(SDKExtensionInfo.getInstance().getExtensionRepositories().keySet(),
+                                               Style.EXTRA);
                setExtensionPackages(repoToSectionsMap);
                setExtensionPackagesToRecentPackages();
        }
        
        private HashMap<String,List<PropertySection>> getRepositoryAndPackageList
-               (Collection<String> repoPackagesUrls, boolean isSnapshotServer) throws IOException {
+               (Collection<String> repoPackagesUrls, Style style) throws IOException {
                PropertyParser parser = new PropertyParser();
                HashMap<String,List<PropertySection>> r2sMap = new HashMap<String,List<PropertySection>>();
                
                if(repoPackagesUrls != null) {
                        for(String repo : repoPackagesUrls) {                           
-                               URL packageListURL = getPackageListPath(repo, isSnapshotServer);
+                               URL packageListURL = getPackageListPath(repo, style);
+                               File packageListFile = null;
                                
-                               File packageListFile = downloadPackageListFile(packageListURL);
-                               
-                               if(packageListFile != null) {
-                                       r2sMap.put(repo, parser.readFromFile(packageListFile));
-                               } else {
-                                       packageListURL = getPackageListPath(SDKExtensionInfo.getInstance().getExtraPackageListPath(repo), isSnapshotServer);
+                               if (style != Style.EXTRA) { // Snapshot, Image case
                                        packageListFile = downloadPackageListFile(packageListURL);
-                                       if (packageListFile != null) {
+                                       if(packageListFile != null) {
+                                               r2sMap.put(repo, parser.readFromFile(packageListFile));
+                                       }
+                               } else { // Extra extension case
+                                       // Get package list file from cache.
+                                       URL extraPackageListURL = getPackageListPath(SDKExtensionInfo.getInstance().getExtraPackageListPath(repo), style);
+                                       packageListFile = downloadPackageListFile(extraPackageListURL);
+                                       if (packageListFile != null) { // If cache does not exist, install manager get it from remote repository.
                                                r2sMap.put(repo, parser.readFromFile(packageListFile));
                                        } else {
-                                               Log.err("Ignore invalid repository: "+repo);                                            
+                                               // InstallManager can get package list file from remote repository.
+                                               packageListFile = downloadPackageListFile(packageListURL);
+                                               if (packageListFile != null) {
+                                                       r2sMap.put(repo, parser.readFromFile(packageListFile));
+                                               }
                                        }
                                }
-
-                               
-//                             if(packageListFile != null) {
-//                                     r2sMap.put(repo, parser.readFromFile(packageListFile));
-//                             } else {
-//                                     Log.err("Ignore invalid repository: "+repo);
-//                             }
                        }
                } else {
                        Log.log("Cannot find repository. This is local installer.");
@@ -239,8 +250,10 @@ public abstract class PackageManager {
        
        public PackageSet getInstalledExtensionPackages() {
                PackageSet extensionPackages = new PackageSet();
+               PackageSet pkgs = this.getInstalledPackages();
                
-               for (Package pkg : extensionPackages) {
+               
+               for (Package pkg : pkgs) {
                        if (pkg.isExtensionPackage()) {
                                extensionPackages.add(pkg);
                        }
@@ -283,13 +296,13 @@ public abstract class PackageManager {
         * @param url
         * @return Full url path
         */
-       private URL getPackageListPath(String url, boolean isSnapshotServer) {
+       private URL getPackageListPath(String url, Style style) {
                if (url == null || url.isEmpty()) {
                        return null;
                } else {
                        String packageListURL = "";
 
-                       if (isSnapshotServer) {
+                       if (style == Style.NETWORK) {
                                String snapshotPath = Config.getInstance().getSnapshotPath();
                                
                                if (snapshotPath == null || snapshotPath.isEmpty()) {
@@ -1499,4 +1512,8 @@ public abstract class PackageManager {
        public static PackageManager getInstance() {
                return pm;
        }
+       
+       public SDKExtensionInfo getSdkExtensionInfo() {
+               return SDKExtensionInfo.getInstance();
+       }
 }
index 488b93f..7c39646 100644 (file)
@@ -119,7 +119,7 @@ public class InstallManagerWindow extends ApplicationWindow {
        private SetInstallDirectoryPage compositeSetInstallDirectoryPage;
        public UpdatableListPage compositeUpdatableListPage;
 
-       private static ViewController controller;
+       protected static ViewController controller;
        private SelectionAdapter cancelBtnSelectionAdapter = null;
        private SelectionAdapter closeBtnSelectionAdapter = null;
        protected boolean cancelButtonClicked;
@@ -592,7 +592,7 @@ public class InstallManagerWindow extends ApplicationWindow {
                
                addExtraButton.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
-                               extraDialog = new AddExtraRepositoryDialog(composite.getShell());
+                               extraDialog = new AddExtraRepositoryDialog(composite.getShell(), controller);
                                int ret = extraDialog.open();
                                
                                if (ret != 0) {
index 889848d..b962882 100644 (file)
@@ -42,11 +42,11 @@ 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.SDKExtensionInfo;
 import org.tizen.installmanager.lib.Downloader;
 import org.tizen.installmanager.lib.ErrorController;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
 import org.tizen.installmanager.pkg.lib.PackageManager;
+import org.tizen.installmanager.ui.page.ViewController;
 import org.tizen.installmanager.util.PathUtil;
 
 /**
@@ -56,7 +56,7 @@ import org.tizen.installmanager.util.PathUtil;
  */
 public class AddExtraDialog extends Dialog {
        private String DIALOG_TITLE = "Add Repository";
-       private AddExtraRepositoryDialog rDialog = null;
+       private ViewController controller;
        
        private Text nameText = null;
        private Text repositoryText = null;
@@ -67,9 +67,10 @@ public class AddExtraDialog extends Dialog {
        private String thirdPartyName = "";
        private String thirdPartyRepository = "";
 
-       public AddExtraDialog(Shell parentShell) {
+       public AddExtraDialog(Shell parentShell, ViewController viewController) {
                super(parentShell);
                setShellStyle(SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL);
+               controller = viewController;
        }
        
        /**
@@ -92,7 +93,6 @@ public class AddExtraDialog extends Dialog {
        
        /**
         * Create contents of the dialog.
-        * 
         * @param parent
         */
        @Override
@@ -100,7 +100,6 @@ public class AddExtraDialog extends Dialog {
                Composite container = (Composite) super.createDialogArea(parent);
                container.setLayout(null);
                container.getShell().setImage(PathUtil.getImageFromResource("/res/icons/SDK_icon.png"));
-               rDialog = new AddExtraRepositoryDialog(getParentShell());
                
                setTitle();
                
@@ -226,11 +225,10 @@ public class AddExtraDialog extends Dialog {
        }
        
        private boolean isDuplicatedName() {
-               SDKExtensionInfo extensionInfo = rDialog.getSdkExtensionInfo();
-               if (extensionInfo.contains(thirdPartyName)) {
+               if (controller.getSdkExtensionInfo().contains(thirdPartyName)) {
                        ErrorController.setError(ErrorCode.DUPLICATED_EXTENSION_REPOSITORY_NAME);
                        return false;
-               } else if (extensionInfo.containsBuiltIn(thirdPartyName)) {
+               } else if (controller.getSdkExtensionInfo().containsBuiltIn(thirdPartyName)) {
                        ErrorController.setError(ErrorCode.DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY_NAME);
                        return false;
                } else {
@@ -240,11 +238,11 @@ public class AddExtraDialog extends Dialog {
        
        private boolean isDuplicatedRepository() {
                removeSeperator();
-               SDKExtensionInfo extensionInfo = rDialog.getSdkExtensionInfo();
-               if (extensionInfo.contains(thirdPartyRepository)) {
+
+               if (controller.getSdkExtensionInfo().contains(thirdPartyRepository)) {
                        ErrorController.setError(ErrorCode.DUPLICATED_EXTENSION_REPOSITORY);
                        return false;
-               } else if (extensionInfo.containsBuiltIn(thirdPartyRepository)) {
+               } else if (controller.getSdkExtensionInfo().containsBuiltIn(thirdPartyRepository)) {
                        ErrorController.setError(ErrorCode.DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY);
                        return false;
                } else {
index c04d0f3..0d2e423 100644 (file)
@@ -47,9 +47,9 @@ 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.tizen.installmanager.core.SDKExtensionInfo;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.pkg.model.PackageSet;
+import org.tizen.installmanager.ui.page.ViewController;
 import org.tizen.installmanager.util.PathUtil;
 
 /**
@@ -60,6 +60,8 @@ import org.tizen.installmanager.util.PathUtil;
 public class AddExtraRepositoryDialog extends Dialog {
        private final String STRING_TITLE = "Add Extra Repository";
        
+       private ViewController controller;
+       
        private AddExtraDialog addDialog = null;
        private String thirdPartyName = "";
        private String thirdPartyRepository = "";
@@ -76,11 +78,10 @@ public class AddExtraRepositoryDialog extends Dialog {
        // Set of removable item list.
        private Set<TableItem> removeRepositorySet;
                
-       private SDKExtensionInfo sdkExtensionInfo = SDKExtensionInfo.getInstance();
-       
-       public AddExtraRepositoryDialog(Shell parentShell) {
+       public AddExtraRepositoryDialog(Shell parentShell, ViewController viewController) {
                super(parentShell);
                setShellStyle(SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL);
+               controller = viewController;
        }
        
        /**
@@ -102,12 +103,12 @@ public class AddExtraRepositoryDialog extends Dialog {
                container.setLayout(null);
                container.getShell().setImage(PathUtil.getImageFromResource("/res/icons/SDK_icon.png"));
                
-               sdkExtensionInfo.load();
+               controller.getSdkExtensionInfo().load();
                removeRepositorySet = new HashSet<TableItem>();
                
                setTitle();
                setRepositoryTable(container);
-               addItemToRepositoryTable(sdkExtensionInfo.getExtensionRepositories());
+               addItemToRepositoryTable(controller.getSdkExtensionInfo().getExtensionRepositories());
                
                setSeparator(container);
                
@@ -184,12 +185,13 @@ public class AddExtraRepositoryDialog extends Dialog {
        
        /**
         * Show 3rd party information on table.
-        * @param type
+        * @param isAdd If true, extra repository is added. false is removed.
         */
        private void showRepositoryTable() {
                repositoryTable.removeAll();
                removeRepositorySet.clear();
-               addItemToRepositoryTable(sdkExtensionInfo.getExtensionRepositories());
+               controller.getSdkExtensionInfo().load();                        
+               addItemToRepositoryTable(controller.getSdkExtensionInfo().getExtensionRepositories());
        }
        
        /**
@@ -200,7 +202,7 @@ public class AddExtraRepositoryDialog extends Dialog {
                Set<String> keys = repositoryInfo.keySet();
                for (String key : keys) {
                        TableItem item = new TableItem(repositoryTable, SWT.NONE);
-                       item.setText(TABLE_COLUMN_NAME, repositoryInfo.get(key));
+                       item.setText(TABLE_COLUMN_NAME, controller.getSdkExtensionInfo().getExtensionRepositories().get(key));
                        item.setText(TABLE_COLUMN_REPOSITORY, key);
                }
        }
@@ -225,7 +227,7 @@ public class AddExtraRepositoryDialog extends Dialog {
                addButton.addSelectionListener(new SelectionAdapter() {
                        @Override
                        public void widgetSelected(SelectionEvent e) {
-                               addDialog = new AddExtraDialog(getShell());
+                               addDialog = new AddExtraDialog(getShell(), controller);
                                
                                int ret = addDialog.open();
                                
@@ -267,7 +269,7 @@ public class AddExtraRepositoryDialog extends Dialog {
         * Write 3rd party information of adding to installmanager.conf 
         */
        private void addRepositoryInformation() {
-               sdkExtensionInfo.add(thirdPartyName, thirdPartyRepository);
+               controller.getSdkExtensionInfo().add(thirdPartyName, thirdPartyRepository);
        }
        
        /**
@@ -275,12 +277,12 @@ public class AddExtraRepositoryDialog extends Dialog {
         */
        private void removeRepositoryInformation() {
                for (TableItem removeItem : removeRepositorySet) {
-                       sdkExtensionInfo.remove(removeItem.getText(0), removeItem.getText(1));
+                       controller.getSdkExtensionInfo().remove(removeItem.getText(0), removeItem.getText(1));
                }
        }
        
        public PackageSet getPackagesFromExtraRepository() {
-               return sdkExtensionInfo.getExtensionPackages();
+               return controller.getRootMetaPackageListOfExtension();
        }
        /**
         * Set to enable OK button.
@@ -291,8 +293,4 @@ public class AddExtraRepositoryDialog extends Dialog {
                okButton = getButton(Window.OK);
                okButton.setEnabled(isAvailable);
        }
-       
-       public SDKExtensionInfo getSdkExtensionInfo() {
-               return sdkExtensionInfo;
-       }
 }
index f7a691e..b8f051b 100644 (file)
@@ -39,7 +39,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.tizen.installmanager.core.IMFatalException;
 import org.tizen.installmanager.core.InstallManager;
-import org.tizen.installmanager.core.SDKExtensionInfo;
 import org.tizen.installmanager.lib.ErrorController;
 import org.tizen.installmanager.lib.IMError;
 import org.tizen.installmanager.lib.Log;
@@ -245,9 +244,9 @@ public class InstallableListPage extends PackageListPage {
 
                try {
                        loadPackagesToTreeViewer(viewController.getRootMetaPackageListOfRepository());
-
-                       SDKExtensionInfo sdkExtensionInfo = SDKExtensionInfo.getInstance();
-                       addExtensionPackagesToExtra(sdkExtensionInfo.getExtensionPackages());
+                       viewController.loadSdkExtension();
+                       addExtensionPackagesToExtra(viewController.getRootMetaPackageListOfExtension());
+                       
                } catch (IMFatalException fatalException) {
                        Log.err(ErrorController.getErrorMessage());
                        IMError.fatalError(ErrorController.getErrorMessage());
@@ -325,6 +324,3 @@ public class InstallableListPage extends PackageListPage {
                return retItem;
        }
 }
-
-
-
index 73e7609..ae050c4 100644 (file)
@@ -77,9 +77,8 @@ public class UpdatableListPage extends PackageListPage {
 
                try {
                        loadPackagesToTreeViewer(viewController.getRootMetaPackageListOfRepository());
-                       
-                       SDKExtensionInfo sdkExtensionInfo = SDKExtensionInfo.getInstance();
-                       addExtensionPackagesToExtra(sdkExtensionInfo.getExtensionPackages());
+                       viewController.loadSdkExtension();
+                       addExtensionPackagesToExtra(viewController.getRootMetaPackageListOfExtension());
                        
                } catch (IMFatalException fatalException) {
                        Log.err(ErrorController.getErrorMessage());
index 7d4772e..fd0dce5 100644 (file)
@@ -37,6 +37,7 @@ import org.tizen.installmanager.core.IMExitException;
 import org.tizen.installmanager.core.IMFatalException;
 import org.tizen.installmanager.core.InstallManager;
 import org.tizen.installmanager.core.Options;
+import org.tizen.installmanager.core.SDKExtensionInfo;
 import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.lib.ErrorController;
 import org.tizen.installmanager.lib.IIMProgressMonitor;
@@ -58,6 +59,7 @@ public class ViewController {
 
        private InstallManager installManager;
        private PackageManager packageManager;
+       private SDKExtensionInfo sdkExtensionInfo;
 
        /**
         * Initialize objects which need to install.
@@ -72,6 +74,10 @@ public class ViewController {
                        installManager = InstallManager.getInstance();
                        installManager.init();
                        packageManager = installManager.getPackageManager();
+                       sdkExtensionInfo = packageManager.getSdkExtensionInfo();
+                       
+                       // InstallManager maintains the newest extension package list always.
+                       sdkExtensionInfo.refreshCache();
                        
                        if (packageManager == null) {
                                throw new IMFatalException("Cannot read package information.");
@@ -124,6 +130,14 @@ public class ViewController {
                        return packageManager.getRootMetaPackagesOfRepository();
                }
        }
+       
+       public PackageSet getRootMetaPackageListOfExtension() {
+               if (packageManager == null) {
+                       return null;
+               } else {
+                       return packageManager.getRootMetaPackagesOfExtensionServer();
+               }               
+       }
 
        /**
         * Get meta packages that are available to update.
@@ -263,7 +277,7 @@ public class ViewController {
                        return true;
                } else {
                        PackageSet removablePackages = packageManager.getInstalledPackagesByName(uninstallList);
-       
+
                        return uninstallPackages(removablePackages, monitor);
                }
        }
@@ -436,4 +450,12 @@ public class ViewController {
        public void saveSnapshotSettings(String repository, String distribution, ServerType packageType, String snapshotPath) {
                Config.getInstance().saveSnapshotSettings(repository, distribution,  packageType, snapshotPath);
        }
+       
+       public SDKExtensionInfo getSdkExtensionInfo() {
+               return sdkExtensionInfo;
+       }
+       
+       public void loadSdkExtension() {
+               sdkExtensionInfo.load();
+       }
 }