- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.core;\r
- \r
- import java.io.File;\r
- import java.io.FilenameFilter;\r
- import java.io.IOException;\r
- import java.io.UnsupportedEncodingException;\r
- import java.net.URL;\r
- import java.net.URLEncoder;\r
- import java.security.MessageDigest;\r
- import java.util.ArrayList;\r
- import java.util.Collection;\r
- import java.util.LinkedList;\r
- \r
- import org.tizen.installmanager.lib.Checksum;\r
- import org.tizen.installmanager.lib.Downloader;\r
- import org.tizen.installmanager.lib.ErrorController;\r
- import org.tizen.installmanager.lib.ErrorController.InfoCode;\r
- import org.tizen.installmanager.lib.IIMProgressMonitor;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.Registry;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.lib.exception.IMNetworkException;\r
- import org.tizen.installmanager.lib.win.WindowsProgramController;\r
- import org.tizen.installmanager.pkg.lib.PackageManager;\r
- import org.tizen.installmanager.pkg.model.Package;\r
- import org.tizen.installmanager.pkg.model.PackageSet;\r
- import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
- import org.tizen.installmanager.util.IMShellCommandFail;\r
- import org.tizen.installmanager.util.PathUtil;\r
- import org.tizen.installmanager.util.ShellUtil;\r
- \r
- /**\r
- * This class contains the main business logic of Install Manager. Use singleton\r
- * instance.\r
- * \r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- */\r
- public class InstallManager {\r
- \r
- private static final InstallManager mInstallManager = new InstallManager();\r
- \r
- private Config mConfig = null;\r
- private static Downloader mDownloader = new Downloader();\r
- private PackageManager packageManager;\r
- \r
- // windows path\r
- private static String WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.vbs";\r
- private static String WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.vbs";\r
- private static String WINDOWS_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.vbs";\r
- private static String WINDOWS_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.vbs";\r
- \r
- // linux script\r
- private static String LINUX_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.sh";\r
- private static String LINUX_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.sh";\r
- private static String LINUX_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.sh";\r
- private static String LINUX_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.sh";\r
- private static String LINUX_TSUDO_PATH = "/res/desktop_directory/tsudo.sh";\r
- \r
- private File makeShortCutFile = null;\r
- private File removeShortCutFile = null;\r
- private File tSudoFile = null;\r
- \r
- private static String REMOVE_ALL_PACKAGES = "Remove all packages...";\r
- private static String REMOVE_ALL_SDK_FILES = "Remove all SDK files...";\r
- \r
- private Thread installThread = null;\r
- private LinkedList<Package> installBuffer = new LinkedList<Package>();\r
- \r
- private InstallManager() {\r
- }\r
- \r
- /**\r
- * @return singleton instance of <code>InstallManager</code>\r
- */\r
- public static InstallManager getInstance() {\r
- return mInstallManager;\r
- }\r
- \r
- /**\r
- * Load config file\r
- */\r
- public void initConfig() {\r
- if (mConfig != null) {\r
- if (Config.isSupportMultiSDK()) {\r
- if (!Registry.getInstalledPath().isEmpty()) {\r
- mConfig.setTargetDir(Registry.getInstalledPath());\r
- }\r
- } else {\r
- return;\r
- }\r
- } else {\r
- mConfig = Config.getInstance();\r
- \r
- if (Options.doReplaceRepository) {\r
- Log.log("Replace repository => " + Options.repository);\r
- mConfig.getConfigFile().setRepository(Options.repository);\r
- mConfig.saveConfig();\r
- }\r
- \r
- if (Options.distribution != null && !Options.distribution.isEmpty()) {\r
- mConfig.getConfigFile().setDistribution(Options.distribution);\r
- mConfig.saveConfig();\r
- }\r
- \r
- if (mConfig.getConfigFile() == null) {\r
- Log.log("Loading config file failed");\r
- throw new IMFatalException("Loading configuration file failed");\r
- }\r
- \r
- if (!Registry.getInstalledPath().isEmpty()) {\r
- mConfig.setTargetDir(Registry.getInstalledPath());\r
- }\r
- mConfig.setSdkDatatDir(Registry.getSdkDataPath());\r
- }\r
- }\r
- \r
- /**\r
- * Initialize packages information.\r
- */\r
- public void initPackageList() {\r
- Collection<String> repositoryURLs = mConfig.getSDKPackageServerList();\r
- \r
- initPackageManager(repositoryURLs);\r
- }\r
- \r
- private void initPackageManager(Collection<String> repositoryURLs) {\r
- File installedPackageListFile = null;\r
- if (Registry.targetPath != "") {\r
- installedPackageListFile = new File(PathUtil.get(\r
- PathUtil.get(Registry.targetPath, Config.INFO_DIRECTORY),\r
- Config.INSTALLED_PACKAGE_LIST_FILE_NAME));\r
- } else {\r
- installedPackageListFile = new File(PathUtil.get(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
- Config.INSTALLED_PACKAGE_LIST_FILE_NAME));\r
- }\r
- \r
- try {\r
- if (installedPackageListFile.exists()) {\r
- this.packageManager = PackageManager.getInstance(\r
- installedPackageListFile, repositoryURLs);\r
- } else {\r
- this.packageManager = PackageManager.getInstance(null,\r
- repositoryURLs);\r
- }\r
- } catch (IOException e) {\r
- Log.err("Cannot load package manager =>" + installedPackageListFile\r
- + ", " + repositoryURLs);\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_FILE);\r
- }\r
- }\r
- \r
- /**\r
- * Initialize distribution and snapshot information\r
- */\r
- public boolean initDistribution() {\r
- DistributionController controller = DistributionController\r
- .getInstance(mConfig.getSDKRepositoryList());\r
- \r
- boolean initResult = controller.init();\r
- Log.log("Init Distribution result => " + initResult);\r
- \r
- // First distribution that read from config file is recognized as the\r
- // distribution installed.\r
- String installedDistribution = Config.getInstance().getConfigFile()\r
- .getDistribution();\r
- controller.setInstalledDistribution(installedDistribution);\r
- \r
- return initResult;\r
- }\r
- \r
- /**\r
- * Initialize installmanager. It performs that read config file, make\r
- * temporary files and load package list from repository.\r
- * \r
- * @return <code>true</code> if initialize success to install or uninstall.\r
- */\r
- public void init() {\r
- initConfig();\r
- \r
- cleanPackageDir();\r
- \r
- initDistribution();\r
- if (Config.status == Config.Status.INSTALL) {\r
- checkOldSDK();\r
- }\r
- initPackageList();\r
- initConfigurationFile();\r
- checkNewPackageServer();\r
- }\r
- \r
- /**\r
- * If packageServer has multi SDK packages, set Config.isNewPackageServer\r
- * true. otherwise false. InstallManager can be used old SDK installation.\r
- */\r
- private void checkNewPackageServer() {\r
- if (packageManager\r
- .getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME) == null) {\r
- Config.isNewPackageServer = false;\r
- Log.log("PackageServer has old SDK packages.");\r
- } else {\r
- Config.isNewPackageServer = true;\r
- Log.log("PackageServer has new SDK packages(Multi SDK).");\r
- }\r
- }\r
- \r
- private void initConfigurationFile() {\r
- copyMakeShortCutFile();\r
- copyRemoveShortCutFile();\r
- \r
- // Linux has several kinds such as Ubuntu, Fedora, etc. So, If\r
- // installation needs super user's\r
- // permission, sudo command depends on machine. Therefore,\r
- // Installmanager gives a tsudo command\r
- // which does not need to care of machine post install script for\r
- // package.\r
- if (Platform.isLinux()) {\r
- copyTizenSudoFile();\r
- }\r
- }\r
- \r
- /**\r
- * Delete temporary files related installmanager.\r
- */\r
- public static void deleteTempFile() {\r
- \r
- File tmpDir = new File(PathUtil.getTempFileParent());\r
- File[] tmpFiles = tmpDir.listFiles(new FilenameFilter() {\r
- @Override\r
- public boolean accept(File dir, String name) {\r
- boolean found = false;\r
- String[] prefix = { "makeshortcut", "removeshortcut",\r
- "installmanager.repository", "Packages",\r
- "tizen_installmanager", "checkJavaInstallation",\r
- "install" };\r
- for (String pref : prefix) {\r
- found = name.startsWith(pref);\r
- if (found == true) {\r
- return true;\r
- }\r
- }\r
- return found;\r
- }\r
- });\r
- \r
- if (tmpFiles != null) {\r
- for (File f : tmpFiles) {\r
- if (!f.delete()) {\r
- Log.err("Fail to delete file ==> " + f);\r
- }\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Copy make shortcut file from resource to temp directory.\r
- */\r
- private void copyMakeShortCutFile() {\r
- try {\r
- if (Platform.isLinux()) {\r
- makeShortCutFile = PathUtil.getTempFileFromResource(\r
- LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");\r
- } else if (Platform.isWindows()) {\r
- makeShortCutFile = PathUtil.getTempFileFromResource(\r
- WINDOWS_MAKE_SHORTCUT_PATH, "makeshortcut", ".vbs");\r
- } else if (Platform.isMacOS()) {\r
- makeShortCutFile = PathUtil.getTempFileFromResource(\r
- LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- \r
- if (makeShortCutFile.exists()) {\r
- makeShortCutFile.setExecutable(true);\r
- }\r
- } catch (IOException e) {\r
- Log.err("Installer cannot make 'makeshortcut script' file.");\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
- }\r
- }\r
- \r
- /**\r
- * Copy remove shortcut file from resource to temp directory.\r
- */\r
- private void copyRemoveShortCutFile() {\r
- try {\r
- if (Platform.isLinux()) {\r
- removeShortCutFile = PathUtil.getTempFileFromResource(\r
- LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");\r
- } else if (Platform.isWindows()) {\r
- removeShortCutFile = PathUtil.getTempFileFromResource(\r
- WINDOWS_REMOVE_SHORTCUT_PATH, "removeshortcut", ".vbs");\r
- } else if (Platform.isMacOS()) {\r
- removeShortCutFile = PathUtil.getTempFileFromResource(\r
- LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- removeShortCutFile.setExecutable(true);\r
- } catch (IOException e) {\r
- Log.err("Installer cannot make 'makeshortcut script' file.");\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
- }\r
- }\r
- \r
- /**\r
- * Copy remove shortcut file from resource to temp directory.\r
- */\r
- private void copyTizenSudoFile() {\r
- try {\r
- tSudoFile = PathUtil.getTempFileFromResource(LINUX_TSUDO_PATH,\r
- "tsudo", ".sh");\r
- tSudoFile.setExecutable(true);\r
- } catch (IOException e) {\r
- Log.err("Installer cannot make 'tsudo.sh' file.");\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_TSUDO);\r
- }\r
- }\r
- \r
- /**\r
- * get make shortcut File instance.\r
- * \r
- * @return File instance of makeshortcut script.\r
- */\r
- public File getTSudo() {\r
- return tSudoFile;\r
- }\r
- \r
- /**\r
- * Get temporary file path.(makeshortcut script, Packages list, Installer\r
- * log)\r
- * \r
- * @return temporary file path, if not exist makeshortcut file, return empty\r
- * string.\r
- */\r
- public String getTSudoPath() {\r
- if (getTSudo() == null) {\r
- return "";\r
- } else {\r
- return getTSudo().getAbsolutePath();\r
- }\r
- }\r
- \r
- /**\r
- * get make shortcut File instance.\r
- * \r
- * @return File instance of makeshortcut script.\r
- */\r
- public File getMakeShortCut() {\r
- return makeShortCutFile;\r
- }\r
- \r
- /**\r
- * Get temporary file path.(makeshortcut script, Packages list, Installer\r
- * log)\r
- * \r
- * @return temporary file path, if not exist makeshortcut file, return empty\r
- * string.\r
- */\r
- public String getMakeShortCutPath() {\r
- if (getMakeShortCut() == null) {\r
- return "";\r
- } else {\r
- return getMakeShortCut().getAbsolutePath();\r
- }\r
- }\r
- \r
- /**\r
- * Get temporary file path.(rmoveshortcut script, Packages list, Installer\r
- * log)\r
- * \r
- * @return temporary file path, if not exist removeshortcut file, return\r
- * emptry string.\r
- */\r
- public String getRemoveShortCutPath() {\r
- if (getRemoveShortCut() == null) {\r
- return "";\r
- } else {\r
- return getRemoveShortCut().getAbsolutePath();\r
- }\r
- }\r
- \r
- /**\r
- * Get remove shortcut File instance.\r
- * \r
- * @return File instance of removeshortcut script.\r
- */\r
- public File getRemoveShortCut() {\r
- return removeShortCutFile;\r
- }\r
- \r
- /**\r
- * Get Config instance\r
- * \r
- * @return\r
- */\r
- public Config getConfig() {\r
- return mConfig;\r
- }\r
- \r
- /**\r
- * Get PackageManager instance.\r
- * \r
- * @return\r
- */\r
- public PackageManager getPackageManager() {\r
- return packageManager;\r
- }\r
- \r
- /**\r
- * Check old SDK is installed for compatibility.\r
- */\r
- private void checkOldSDK() {\r
- Log.log("Check old SDK.");\r
- if (Registry.getOldInstalledPath() != "") { // Old SDK is installed.\r
- if (Registry.getInstalledPath() != null\r
- && !Registry.getInstalledPath().isEmpty()) {\r
- // Old SDK is installed but new SDK is also installed, so\r
- // environment does not need to\r
- // set new SDK environment.\r
- Log.log("Old SDK is installed but new SDK is also installed. => "\r
- + Registry.getInstalledPath());\r
- return;\r
- } else {\r
- Log.log("Old SDK is installed. => "\r
- + Registry.getOldInstalledPath());\r
- setCurrentSDKEnvironment(Registry.getOldInstalledPath());\r
- }\r
- } else {\r
- return;\r
- }\r
- }\r
- \r
- /**\r
- * If old SDK is installed and new SDK is not installed, installmanager set\r
- * environment for new SDK running properly.\r
- * \r
- * @param targetPath\r
- * SDK installed path.\r
- */\r
- private void setCurrentSDKEnvironment(String targetPath) {\r
- Log.log("Set new SDK environment from old SDK.");\r
- Registry.sdkDataPath = Config.getConfigHome();\r
- \r
- if (targetPath == null || targetPath.isEmpty()) {\r
- Log.err("Install path is invalid: " + targetPath\r
- + ". This might be a bug of IM");\r
- throw new IMFatalException(ErrorCode.INVALID_INSTALL_PATH);\r
- } else {\r
- Registry.exportInstallPath(targetPath);\r
- Registry.exportMultiInstallPath(targetPath, true);\r
- }\r
- \r
- // Make sdk.info file into target directory for compatibility.\r
- Registry.saveSDKInfo(targetPath);\r
- // Remove tizensdkpath file in 'tizen-sdk-data'.\r
- // Registry.removeOldRegistry();\r
- }\r
- \r
- /**\r
- * @param pkg\r
- * @param filePath\r
- * @return <code>true</code> if the package is already downloaded to the\r
- * file path\r
- */\r
- private boolean existInCacheFolder(Package pkg, String filePath,\r
- IIMProgressMonitor monitor) {\r
- File file = new File(filePath);\r
- \r
- if (!file.exists()) {\r
- return false;\r
- }\r
- \r
- if (monitor != null) {\r
- monitor.workedDownloadProgress("Validate the " + pkg.getPackageName(), 0);\r
- }\r
- \r
- if (Options.doPackageValidation) {\r
- if (Checksum.getSHA256(filePath) != null) {\r
- return checkFileChecksum(pkg, Checksum.getSHA256(filePath));\r
- } else {\r
- return false;\r
- }\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- private boolean checkPackageSize(Package pkg, long size) {\r
- if (pkg.getPackageSize() == size) {\r
- return true;\r
- }\r
- return false;\r
- }\r
- \r
- private boolean checkFileChecksum(Package pkg, MessageDigest mDigest) {\r
- \r
- if (pkg.getSHA256() == null || pkg.getSHA256().isEmpty()) {\r
- return false;\r
- }\r
- \r
- if (mDigest.getAlgorithm().equals(Checksum.SHA_256_TYPE)) {\r
- return (pkg.getSHA256().equalsIgnoreCase(Checksum\r
- .messageDigestToString(mDigest)));\r
- } else {\r
- // TODO there's no checksum field in package.\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Packages Installation management. Download and install packages.\r
- * \r
- * @param packagesToInstall\r
- * @param targetDir\r
- * @param monitor\r
- * @return\r
- * @throws IMExitException\r
- */\r
- public boolean install(PackageSet installablePackages,\r
- final String targetDir, InstallProgressMonitor monitor)\r
- throws IMExitException, IMNetworkException {\r
- Log.log("InstallManager.install() installable packages : "\r
- + installablePackages);\r
- \r
- // performance measurement\r
- Performance.sdkPackageSize = packageManager\r
- .getTotalSizeOfInstallablePackages(installablePackages, true);\r
- \r
- if (installablePackages == null || targetDir == null\r
- || targetDir.isEmpty()) {\r
- Log.err("packaegs => " + installablePackages + ", targetDir => "\r
- + targetDir);\r
- return false;\r
- }\r
- \r
- mConfig.setTargetDir(targetDir);\r
- mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
- \r
- if (monitor != null) {\r
- monitor.workedRefresh();\r
- monitor.beginTask(installablePackages.size(),\r
- getTotalDownloadSize(installablePackages),\r
- getTotalInstallSize(installablePackages));\r
- }\r
- \r
- initializeTargetDir(targetDir);\r
- makeShortcutMenu();\r
- \r
- // make start menu\r
- // if you cannot get installmanager from repository, install from local.\r
- if (!packageManager\r
- .existsPackage(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME)) {\r
- Log.log("Cannot find install-manager from repository.");\r
- \r
- if (!installInstallManagerFromLocal(targetDir)) {\r
- Log.err("Cannot install install-manager from local directory.");\r
- }\r
- }\r
- \r
- // wait if cancel confirm dialog is showing. wait until user press\r
- // button(cancel or not).\r
- // TODO :\r
- if (monitor != null) {\r
- while (monitor.checkCancelAndDisableCancelButton() == false) {\r
- if (monitor.isCanceled()) {\r
- throw new IMInstallCancelException();\r
- }\r
- }\r
- }\r
- \r
- // remove missing packages in repository.\r
- removeMissingPackages(monitor);\r
- \r
- for (Package pkg : installablePackages) {\r
- if (!install(pkg, targetDir, monitor)) {\r
- return false;\r
- }\r
- }\r
- \r
- // download complete.\r
- if (monitor != null) {\r
- monitor.workedDownloadProgress("Download complete", 0);\r
- monitor.downloadDone();\r
- }\r
- \r
- // install thread is running yet.\r
- try {\r
- installThread.join();\r
- } catch (InterruptedException e) {\r
- Log.ExceptionLog(e);\r
- Log.err("");\r
- }\r
- \r
- // install complete\r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Installation complete", 0);\r
- monitor.installDone();\r
- }\r
- \r
- // save config file\r
- mConfig.saveConfig();\r
- \r
- // save sdk version.\r
- saveSDKVersion();\r
- \r
- // Delete installed packages\r
- if (Options.doRemovePackages) {\r
- removePackagesDir();\r
- }\r
- \r
- if (Config.status == Config.Status.INSTALL) {\r
- Registry.exportMultiInstallPath(targetDir, true);\r
- }\r
- \r
- // show reboot message in linux platform.\r
- if (Platform.isLinux() || Platform.isMacOS()) {\r
- ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);\r
- }\r
- \r
- Performance.setInstallationEndTime();\r
- return true;\r
- }\r
- \r
- private long getTotalDownloadSize(PackageSet pkgSet) {\r
- if (pkgSet == null) {\r
- return -1;\r
- }\r
- \r
- long totalSize = 0;\r
- for (Package pkg : pkgSet) {\r
- totalSize += pkg.getPackageSize();\r
- }\r
- \r
- return totalSize;\r
- }\r
- \r
- private long getTotalInstallSize(PackageSet pkgSet) {\r
- if (pkgSet == null) {\r
- return -1;\r
- }\r
- \r
- long totalSize = 0;\r
- for (Package pkg : pkgSet) {\r
- totalSize += pkg.getUncompressedPackageSize();\r
- }\r
- \r
- return totalSize;\r
- }\r
- \r
- private boolean install(final Package pkg, final String targetDir,\r
- final InstallProgressMonitor monitor) throws IMExitException,\r
- IMNetworkException {\r
- Log.log("Install package => " + pkg.getPackageName());\r
- Log.log("Target directory => " + targetDir);\r
- \r
- boolean result = false;\r
- \r
- if (Options.doTest && Performance.getDownloadStartTime() == null) {\r
- Performance.setDownloadStartTime();\r
- }\r
- \r
- // download package from repository.\r
- result = downloadPackage(pkg, monitor);\r
- \r
- if (Options.doTest) {\r
- Performance.setDownloadEndTime();\r
- }\r
- \r
- if (result) {\r
- installBuffer.push(pkg);\r
- \r
- if (Options.doTest\r
- && Performance.getInstallationStartTime() == null) {\r
- Performance.setInstallationStartTime();\r
- }\r
- \r
- if (installThread == null || !installThread.isAlive()) {\r
- installThread = new Thread() {\r
- public void run() {\r
- Package p = null;\r
- while ((p = installBuffer.pollLast()) != null) {\r
- if (!installPackage(p, targetDir, monitor)) {\r
- return;\r
- }\r
- \r
- if (installBuffer.size() <= 0) {\r
- if (monitor != null ) {\r
- monitor.workedInstallProgress("Waiting for download", 0);\r
- monitor.installEnd();\r
- }\r
- }\r
- }\r
- }\r
- };\r
- \r
- installThread.start();\r
- }\r
- \r
- if (Options.doTest) {\r
- Performance.setInstallationEndTime();\r
- }\r
- \r
- if (!ErrorController.checkInstallationSuccess()) {\r
- return false;\r
- }\r
- } else {\r
- Log.log("Installation failed. => " + pkg.getPackageName());\r
- return false;\r
- }\r
- \r
- return result;\r
- }\r
- \r
- public boolean downloadPackages(PackageSet packageSet,\r
- InstallProgressMonitor monitor) throws IMNetworkException {\r
- if (packageSet == null) {\r
- return false;\r
- }\r
- \r
- for (Package pkg : packageSet) {\r
- if (!downloadPackage(pkg, monitor)) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- \r
- private boolean downloadPackage(Package pkg, InstallProgressMonitor monitor)\r
- throws IMNetworkException {\r
- Log.log("Download package => " + pkg);\r
- \r
- // check the parameter\r
- if (pkg == null) {\r
- Log.err("Cannot find package.");\r
- return false;\r
- }\r
- \r
- // check the option.\r
- if (Options.doInstallNoUI) {\r
- System.out.println(pkg.getPackageName() + " is downloading...");\r
- }\r
- \r
- // check the cancel button\r
- if (monitor != null) {\r
- if (monitor.isCanceled()) {\r
- Log.log("download canceled");\r
- throw new IMInstallCancelException();\r
- } else {\r
- monitor.workedDownloadProgress(pkg.getPackageName(), 1);\r
- }\r
- }\r
- \r
- URL downloadFileURL = pkg.getURL();\r
- String downloadTargetPath = getDownloadTargetPath(pkg);\r
- \r
- // check the package in cache folder\r
- if (existInCacheFolder(pkg, downloadTargetPath, monitor)) {\r
- Log.log("Found the package in cache");\r
- \r
- if (monitor != null) {\r
- monitor.workedDownloadSize(pkg.getPackageSize());\r
- }\r
- \r
- return true;\r
- }\r
- \r
- // download package from repository\r
- long size = mDownloader.download(downloadFileURL, downloadTargetPath,\r
- monitor);\r
- \r
- if (size >= 0) {\r
- if (Options.onlyDownload) {\r
- System.out.println("Download success. => " + pkg);\r
- }\r
- Log.log("finish download => " + pkg);\r
- } else { // fail\r
- Log.err("download failed => " + downloadFileURL);\r
- \r
- PathUtil.remove(downloadTargetPath);\r
- \r
- String errMsg = "";\r
- if (monitor.isCanceled()) {\r
- errMsg = ErrorController.getErrorMessage();\r
- } else {\r
- errMsg = "Fail to get '" + pkg.getPackageName() + "'." + "\n("\r
- + ErrorController.getErrorMessage() + ")";\r
- }\r
- throw new IMFatalException(errMsg);\r
- }\r
- \r
- // package validation\r
- if (Options.doPackageValidation) {\r
- Log.log("Validate package");\r
- if (!checkPackageSize(pkg, size)) {\r
- Log.err("The expected size of package => "\r
- + pkg.getPackageSize());\r
- Log.err("Package size error. downloaded size => " + size);\r
- \r
- PathUtil.remove(downloadTargetPath);\r
- \r
- throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);\r
- }\r
- \r
- // TODO :\r
- if (!checkFileChecksum(pkg, mDownloader.getFileChecksum())) {\r
- Log.err("The expected checksum of package => "\r
- + pkg.getSHA256());\r
- Log.err("Package checksum error downloaded checksum => "\r
- + mDownloader.getFileChecksum());\r
- \r
- PathUtil.remove(downloadTargetPath);\r
- \r
- throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);\r
- }\r
- }\r
- \r
- return true;\r
- }\r
- \r
- private boolean installPackage(Package pkg, String targetDir,\r
- InstallProgressMonitor monitor) {\r
- // save target directory\r
- initializeTargetDir(targetDir);\r
- \r
- // remove packages to update.\r
- if (packageManager.isInstalledPackage(pkg) && (packageManager.isReInstall() || packageManager.isUpdatable(pkg))) {\r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Remove the previous version", 0);\r
- }\r
- \r
- removePackage(pkg, null);\r
- }\r
- \r
- // remove conflict packages\r
- PackageSet pkgSet = packageManager.getConflictPackages(pkg);\r
- if (pkgSet.size() > 0) {\r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Remove the conflict packages", 0);\r
- }\r
- removePackages(pkgSet, null);\r
- }\r
- \r
- if (Options.doInstallNoUI) {\r
- System.out.println(pkg.getPackageName() + " is installing...");\r
- }\r
- \r
- Installer installer = new Installer();\r
- boolean bResult = installer.install(pkg, targetDir, monitor);\r
- \r
- if (bResult) {// save installed package list\r
- packageManager.addPackageToInstalledPackages(pkg);\r
- packageManager.saveInstalledList();\r
- } else {\r
- Log.log("Installation failed => " + pkg);\r
- \r
- ErrorController.setError(ErrorCode.INSTALLATION_FAIL);\r
- ErrorController.setInstallationSuccess(false);\r
- }\r
- \r
- return bResult;\r
- }\r
- \r
- public String getDownloadTargetPath(Package pkg) {\r
- String repository = pkg.getBaseURL().toString();\r
- \r
- String encodeRepository = null;\r
- try {\r
- encodeRepository = URLEncoder.encode(repository, "UTF-8");\r
- } catch (UnsupportedEncodingException e) {\r
- Log.ExceptionLog(e);\r
- return encodeRepository;\r
- }\r
- \r
- return PathUtil.get(mConfig.getDownloadDirPath(), encodeRepository,\r
- pkg.getFileName());\r
- }\r
- \r
- private boolean installInstallManagerFromLocal(String sdkPath) {\r
- Log.log("Install install-manager from local. => " + sdkPath);\r
- String targetDir = PathUtil.get(sdkPath,\r
- InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);\r
- \r
- File targetDirFile = new File(targetDir);\r
- \r
- if (!targetDirFile.exists()) {\r
- targetDirFile.mkdirs();\r
- }\r
- \r
- try {\r
- if (Platform.isLinux()) {\r
- installInstallManagerFromLocalInLinux(targetDir);\r
- } else if (Platform.isWindows()) {\r
- installInstallManagerFromLocalInWindows(targetDir);\r
- } else if (Platform.isMacOS()) {\r
- installInstallManagerFromLocalInMac(targetDir);\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- \r
- File toInstallManagerImage = new File(PathUtil.get(\r
- Registry.getInstalledPath(),\r
- InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,\r
- InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_NAME));\r
- PathUtil.writeFileFromInputStream(\r
- PathUtil.getResourceAsStream(InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_PATH),\r
- toInstallManagerImage);\r
- \r
- File toDesktopFile = new File(PathUtil.get(\r
- Registry.getInstalledPath(),\r
- InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,\r
- InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_NAME));\r
- PathUtil.writeFileFromInputStream(\r
- PathUtil.getResourceAsStream(InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_PATH),\r
- toDesktopFile);\r
- \r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- }\r
- \r
- // execute install script\r
- File installScript = getInstallScript();\r
- if (installScript != null && installScript.exists()) {\r
- installScript.setExecutable(true);\r
- \r
- Installer installer = new Installer();\r
- try {\r
- installer.executeScript(installScript);\r
- return true;\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- private void installInstallManagerFromLocalInLinux(String targetDir) {\r
- try {\r
- // copy excutable file to target directory\r
- PathUtil.copy(PathUtil.get(Options.executablePath,\r
- InstallManagerConstants.INSTALLMANAGER_BINARY_NAME),\r
- targetDir);\r
- \r
- // copy library file to target directory\r
- PathUtil.copy(PathUtil.get(PathUtil.getCurrentDir(),\r
- InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME),\r
- targetDir);\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- private void installInstallManagerFromLocalInWindows(String targetDir) {\r
- installInstallManagerFromLocalInLinux(targetDir);\r
- }\r
- \r
- private void installInstallManagerFromLocalInMac(String targetDir) {\r
- String parentDir = PathUtil.getParentDirectory(\r
- PathUtil.getCurrentDir(), 4);\r
- \r
- String imExecutableAppDirPath = PathUtil\r
- .get(parentDir,\r
- InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_DIR_NAME_FOR_MAC);\r
- String command = "cp -rf " + imExecutableAppDirPath + " " + targetDir;\r
- \r
- try {\r
- ShellUtil.execute(command);\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- Log.err(command);\r
- throw new IMFatalException(\r
- ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);\r
- }\r
- \r
- String imExecutableBinaryPath = PathUtil\r
- .get(parentDir,\r
- InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX);\r
- command = "cp -rf " + imExecutableBinaryPath + " " + targetDir;\r
- \r
- try {\r
- ShellUtil.execute(command);\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- return;\r
- }\r
- \r
- String imJarFilePath = PathUtil.get(parentDir,\r
- InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME);\r
- command = "cp -rf " + imJarFilePath + " " + targetDir;\r
- \r
- try {\r
- ShellUtil.execute(command);\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- return;\r
- }\r
- }\r
- \r
- private void removeMissingPackages(IIMProgressMonitor monitor) {\r
- PackageSet missingPackages = packageManager\r
- .getMissingPackagesFromRepository();\r
- Log.log("Remove missing packages => " + missingPackages);\r
- \r
- if (monitor != null) {\r
- monitor.workedDownloadProgress("Remove missing packages", 0);\r
- }\r
- \r
- for (Package pkg : missingPackages) {\r
- if (!removePackage(pkg, monitor)) {\r
- Log.err("Cannot remove missing package");\r
- throw new IMFatalException(\r
- ErrorCode.CANNOT_REMOVE_MISSING_PACKAGE);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Initializes target directory\r
- * \r
- * @param targetDir\r
- * path to SDK target directory\r
- */\r
- public void initializeTargetDir(String targetDir) {\r
- Log.log("Initialize target dir. " + targetDir);\r
- // Make target directory\r
- File targetDirFile = new File(targetDir);\r
- if (!targetDirFile.exists()) {\r
- if (!targetDirFile.mkdirs()) {\r
- Log.err("Fail to create file ==> " + targetDirFile);\r
- }\r
- }\r
- \r
- // Keep target path in system\r
- Registry.exportInstallPath(targetDir);\r
- \r
- // Keep target path for later use\r
- mConfig.setTargetDir(targetDir);\r
- mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
- \r
- // Make .info directory\r
- if (!mConfig.makeInfoDirectory()) {\r
- Log.err(Config.CONFIG_HOME_PATH + " cannot create.");\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_CONFIG_FILE);\r
- }\r
- }\r
- \r
- /**\r
- * Save installed SDK version.\r
- */\r
- public void saveSDKVersion() {\r
- Registry.saveInstallVersion(mConfig.getConfigFile()\r
- .getInstallManagerVersion());\r
- }\r
- \r
- /**\r
- * Make tizen menu and installmanager shortcut.\r
- */\r
- private void makeShortcutMenu() {\r
- Log.log("InstallManager make shortcut menu.");\r
- \r
- // execute install script.\r
- File installScript = getInstallScript();\r
- if (installScript != null) {\r
- installScript.setExecutable(true);\r
- \r
- Installer installer = new Installer();\r
- try {\r
- installer.executeScript(installScript);\r
- } catch (IMShellCommandFail e) {\r
- // TODO\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Get install script from resource according to each platform.\r
- * \r
- * @return\r
- */\r
- private File getInstallScript() {\r
- try {\r
- if (Platform.isLinux()) {\r
- return PathUtil.getTempFileFromResource(\r
- LINUX_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",\r
- ".sh");\r
- } else if (Platform.isWindows()) {\r
- return PathUtil.getTempFileFromResource(\r
- WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",\r
- ".vbs");\r
- } else if (Platform.isMacOS()) {\r
- return null;\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- } catch (IOException e) {\r
- Log.err("Cannot execute InstallManager's install script.");\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
- }\r
- }\r
- \r
- private void removeInstallManager() {\r
- Log.log("InstallManager.removeInstallManager");\r
- \r
- String installManagerDirectory = PathUtil.get(\r
- Registry.getInstalledPath(),\r
- InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);\r
- PathUtil.remove(installManagerDirectory);\r
- \r
- if (Registry.getInstalledPath().isEmpty()) {\r
- return;\r
- }\r
- }\r
- \r
- private void removeShortcutMenu() {\r
- File removeScript = getRemoveScript();\r
- \r
- if (removeScript == null) {\r
- return;\r
- }\r
- \r
- removeScript.setExecutable(true);\r
- \r
- Installer installer = new Installer();\r
- try {\r
- installer.executeScript(removeScript);\r
- } catch (IMShellCommandFail e) {\r
- Log.err("Cannot execute InstallManager's remove script.");\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- private File getRemoveScript() {\r
- try {\r
- if (Platform.isLinux()) {\r
- return PathUtil\r
- .getTempFileFromResource(\r
- LINUX_INSTALL_MANAGER_REMOVE_SCRIPT,\r
- "im_remove", ".sh");\r
- } else if (Platform.isWindows()) {\r
- return PathUtil.getTempFileFromResource(\r
- WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT, "im_remove",\r
- ".vbs");\r
- } else if (Platform.isMacOS()) {\r
- return null;\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- } catch (IOException e) {\r
- // TODO Auto-generated catch block\r
- Log.err("Cannot get InstallManager's remove script.");\r
- Log.ExceptionLog(e);\r
- return null;\r
- }\r
- }\r
- \r
- /*\r
- * private void copyInstallManagerToTargetDirectoryForMac() {\r
- * Log.log("Copy InstallManager to target in MAC platform");\r
- * \r
- * //get '.app' directory String fromPath =\r
- * PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 3); if (fromPath ==\r
- * null) { Log.err("Cannot get parent directory => " +\r
- * PathUtil.getCurrentDir()); return; }\r
- * \r
- * File fromFile = new File(fromPath);\r
- * \r
- * if (Registry.getInstalledPath() == null ||\r
- * Registry.getInstalledPath().equals("")) {\r
- * Log.err("Cannot find target dir"); return; }\r
- * \r
- * File toFile = getInstalledAppPath(); if (!toFile.exists()) { if\r
- * (!toFile.mkdirs()) { Log.err("Fail to create file ==> " + toFile); } }\r
- * \r
- * if (fromFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {\r
- * return; }\r
- * \r
- * try { PathUtil.copy(fromFile, toFile); } catch (IOException e) {\r
- * Log.ExceptionLog(e); return; }\r
- * \r
- * // copy InstallManager script to {target dir}/install-manager/ File\r
- * installManagerScript = new File(PathUtil.get(Registry.getInstalledPath(),\r
- * Config.INSTALL_MANAGER_DIRECTORY, Config.INSTALL_MANAGER_APP_JAVA,\r
- * Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER )); File targetDir = new\r
- * File(PathUtil.get(Registry.getInstalledPath(),\r
- * Config.INSTALL_MANAGER_DIRECTORY));\r
- * \r
- * try { PathUtil.copy(installManagerScript, targetDir); } catch\r
- * (IOException e) { Log.ExceptionLog(e); return; }\r
- * \r
- * //remove binary directory in target directory String removableBinaryPath\r
- * = PathUtil.get(toFile.getAbsolutePath() , "Contents" , "Resources" ,\r
- * "Java" , "binary");\r
- * \r
- * PathUtil.remove(removableBinaryPath); }\r
- * \r
- * private File getInstalledAppPath() { String appPath =\r
- * Registry.getInstalledPath() + File.separator +\r
- * Config.INSTALL_MANAGER_DIRECTORY + File.separator +\r
- * Config.INSTALL_MANAGER_APP;\r
- * \r
- * return new File(appPath); }\r
- */\r
- \r
- /**\r
- * Remove trash packages which are used during installation using SDK image.\r
- */\r
- private void cleanPackageDir() {\r
- // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY\r
- if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,\r
- Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME,\r
- Config.INSTALL_MANAGER_IMAGE_DOWNLOAD_DIRECTORY_NAME))) {\r
- Log.log("Success to remove trash SDK image package binaries.");\r
- } else {\r
- Log.err("Fail to remove trash SDK image package binaries.");\r
- }\r
- }\r
- \r
- public void removePackagesDir() {\r
- // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY\r
- if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,\r
- Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME))) {\r
- Log.log("Success to remove downloaded package binaries.");\r
- } else {\r
- Log.err("Fail to remove downloaded package binaries.");\r
- }\r
- }\r
- \r
- /**\r
- * Package uninstallation management\r
- * \r
- * @param pkg\r
- * @param monitor\r
- * @return\r
- */\r
- public boolean removePackage(Package pkg, IIMProgressMonitor monitor) {\r
- Log.log("InstallManager package remove start => " + pkg);\r
- \r
- if (pkg == null) {\r
- return false;\r
- }\r
- \r
- if (monitor != null) {\r
- monitor.workedTitle(pkg.getPackageName());\r
- }\r
- \r
- if (Options.doRemoveNoUI || Options.doInstallNoUI) {\r
- System.out.println(pkg.getPackageName() + " is uninstalling...");\r
- }\r
- \r
- boolean bResult = false;\r
- if (packageManager.isInstalledPackage(pkg)) {\r
- Installer installer = new Installer();\r
- \r
- bResult = installer.uninstall(pkg, monitor);\r
- } else {\r
- bResult = true;\r
- }\r
- \r
- // Remove packages in installed package list without result.\r
- // We don't know that failed packages are working well.\r
- packageManager.exceptPackageFromInstalledPackages(pkg);\r
- packageManager.saveInstalledList();\r
- \r
- Log.log(pkg + " remove end => " + bResult);\r
- return bResult;\r
- }\r
- \r
- /**\r
- * Packages uninstallation management\r
- * \r
- * @param pkg\r
- * @param monitor\r
- * @return\r
- */\r
- public boolean removePackages(PackageSet metasToRemove,\r
- IIMProgressMonitor monitor) {\r
- Log.log("InstallManager Packages remove Start => " + metasToRemove);\r
- \r
- if (metasToRemove == null) {\r
- return false;\r
- }\r
- \r
- PackageSet pkgsToRemove = packageManager\r
- .getToRemovePackagesInRemove(metasToRemove);\r
- \r
- Log.log("Remove packages: " + pkgsToRemove);\r
- \r
- if (monitor != null) {\r
- monitor.beginTask("Uninstalling...", pkgsToRemove.size() + 1);\r
- }\r
- \r
- int i = 0;\r
- for (Package pkg : pkgsToRemove) {\r
- if (monitor != null) {\r
- monitor.workedDownloadProgress(pkg.getPackageName(), 1);\r
- monitor.worked(++i);\r
- }\r
- \r
- if (removePackage(pkg, monitor)) {\r
- continue;\r
- } else {\r
- Log.log("Remove fail but make progress=> " + pkg);\r
- }\r
- }\r
- \r
- // if you remove all packages, delete targetDirectory and config File.\r
- if (!packageManager.existInstalledMetaPackages()) {\r
- Log.log("Installed meta packages do not exist");\r
- if (monitor != null) {\r
- monitor.workedDownloadProgress("Remove target directory...", 0);\r
- monitor.worked(pkgsToRemove.size());\r
- }\r
- \r
- if (packageManager.existInstalledPackages()) {\r
- Log.log("Installed meta packages do not exist, but some packages exist.");\r
- removeAll(monitor);\r
- } else {\r
- // not exist to remove\r
- removeSDK(monitor);\r
- }\r
- }\r
- \r
- Log.log("InstallManager packages remove success. return => " + true);\r
- return true;\r
- }\r
- \r
- /**\r
- * Remove all of packages.\r
- * \r
- * @param monitor\r
- */\r
- public void removeAll(IIMProgressMonitor monitor) {\r
- Log.log("InstallManager.removeAll()");\r
- \r
- removeAllPackages(monitor);\r
- removeSDK(monitor);\r
- }\r
- \r
- private void removeAllPackages(IIMProgressMonitor monitor) {\r
- Log.log("Remove all packages.");\r
- \r
- PackageSet removablePackages = packageManager.getInstalledPackages();\r
- \r
- for (Package pkg : removablePackages) {\r
- if (!removePackage(pkg, monitor)) {\r
- Log.err("InstallManager.removeAll remove fail => " + pkg);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Remove All of TizenSDK files.\r
- */\r
- public void removeSDK(IIMProgressMonitor monitor) {\r
- Log.log("InstallManager removeSDK start");\r
- \r
- if (monitor != null) {\r
- monitor.workedTitle(REMOVE_ALL_SDK_FILES);\r
- }\r
- \r
- removeInstallManager();\r
- removeShortcutMenu();\r
- removeChangeLog();\r
- removeInfoDirectory();\r
- checkTargetDirAndRemove();\r
- // Registry.removeRegistry();\r
- if (Config.isSupportMultiSDK()) {\r
- Registry.removeMultiSDKInfo(Config.getSelectedSDKPath());\r
- } else {\r
- Registry.removeMultiSDKInfo(Registry.getInstalledPath());\r
- }\r
- \r
- // do not remove config home because it has log files\r
- Log.log("InstallManager removeSDK end");\r
- }\r
- \r
- private void checkTargetDirAndRemove() {\r
- File targetDir = new File(Registry.getInstalledPath());\r
- if (canRemoveTargetDir(targetDir)) {\r
- removeTargetDirectory();\r
- } else {\r
- Log.err("Cannot delete target directory => "\r
- + targetDir.getAbsolutePath());\r
- }\r
- }\r
- \r
- /**\r
- * Check status that target directory can remove or not.\r
- * \r
- * @param targetDir\r
- * @return\r
- */\r
- private boolean canRemoveTargetDir(File targetDir) {\r
- if (targetDir.exists()) {\r
- File[] fileList = targetDir.listFiles();\r
- if ((fileList == null || fileList.length <= 0)\r
- || (fileList.length == 1 && fileList[0].getName().equals(\r
- Config.OLD_INSTALL_MANAGER_DIRECTORY))) {\r
- return true;\r
- } else {\r
- ArrayList<String> fileNames = new ArrayList<String>();\r
- for (File file : fileList) {\r
- fileNames.add(file.getName());\r
- }\r
- Log.err("The SDK directory is not empty => " + fileNames);\r
- return false;\r
- }\r
- } else {\r
- Log.err("The SDK direcotry is already removed");\r
- return false;\r
- }\r
- }\r
- \r
- private void removeChangeLog() {\r
- File releaseNoteFile = new File(\r
- PathUtil.getFromInstalledPath(Config.RELEASE_NOTE));\r
- \r
- if (releaseNoteFile.exists()) {\r
- PathUtil.remove(releaseNoteFile);\r
- }\r
- }\r
- \r
- private void removeInfoDirectory() {\r
- // remove info directory in $HOME/tizen-sdk-data\r
- File infoDirFile = new File(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));\r
- if (infoDirFile.exists()) {\r
- PathUtil.remove(infoDirFile);\r
- }\r
- \r
- // remove info directory in target directory\r
- File targetInfoFile = new File(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));\r
- \r
- if (targetInfoFile.exists()) {\r
- PathUtil.remove(targetInfoFile);\r
- }\r
- }\r
- \r
- /**\r
- * Remove target directory.\r
- */\r
- public void removeTargetDirectory() {\r
- Log.log("InstallManager remove target directory start");\r
- \r
- if (Platform.CURRENT_PLATFORM == Platform.LINUX_32\r
- || Platform.CURRENT_PLATFORM == Platform.LINUX_64\r
- || Platform.CURRENT_PLATFORM == Platform.MACOS_64) {\r
- PathUtil.remove(Registry.getInstalledPath());\r
- } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32\r
- || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {\r
- if (!WindowsProgramController.removeRunningDir(Registry\r
- .getInstalledPath())) {\r
- Log.err("Cannot remove target directory");\r
- }\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- \r
- Log.log("InstallManager remove target directory end");\r
- }\r
- \r
- /**\r
- * Singleton and global downloader shared and used by every components in IM\r
- * \r
- * @return singleton downloader object\r
- */\r
- public static Downloader getDownloader() {\r
- return InstallManager.mDownloader;\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.core;
+
+ import java.io.File;
+ import java.io.FilenameFilter;
+ import java.io.IOException;
++import java.io.UnsupportedEncodingException;
+ import java.net.URL;
++import java.net.URLEncoder;
+ import java.security.MessageDigest;
+ import java.util.ArrayList;
+ import java.util.Collection;
++import java.util.LinkedList;
+
+ import org.tizen.installmanager.lib.Checksum;
+ import org.tizen.installmanager.lib.Downloader;
+ import org.tizen.installmanager.lib.ErrorController;
+ import org.tizen.installmanager.lib.ErrorController.InfoCode;
+ import org.tizen.installmanager.lib.IIMProgressMonitor;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.lib.Platform;
+ import org.tizen.installmanager.lib.Registry;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.lib.exception.IMNetworkException;
+ import org.tizen.installmanager.lib.win.WindowsProgramController;
+ import org.tizen.installmanager.pkg.lib.PackageManager;
+ import org.tizen.installmanager.pkg.model.Package;
+ import org.tizen.installmanager.pkg.model.PackageSet;
+ import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
+ import org.tizen.installmanager.util.IMShellCommandFail;
+ import org.tizen.installmanager.util.PathUtil;
+ import org.tizen.installmanager.util.ShellUtil;
+
+ /**
+ * This class contains the main business logic of Install Manager. Use singleton
+ * instance.
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ */
+ public class InstallManager {
+
+ private static final InstallManager mInstallManager = new InstallManager();
+
+ private Config mConfig = null;
+ private static Downloader mDownloader = new Downloader();
+ private PackageManager packageManager;
+
+ // windows path
+ private static String WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.vbs";
+ private static String WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.vbs";
+ private static String WINDOWS_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.vbs";
+ private static String WINDOWS_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.vbs";
+
+ // linux script
+ private static String LINUX_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.sh";
+ private static String LINUX_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.sh";
+ private static String LINUX_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.sh";
+ private static String LINUX_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.sh";
+ private static String LINUX_TSUDO_PATH = "/res/desktop_directory/tsudo.sh";
+
+ private File makeShortCutFile = null;
+ private File removeShortCutFile = null;
+ private File tSudoFile = null;
+
+ private static String REMOVE_ALL_PACKAGES = "Remove all packages...";
+ private static String REMOVE_ALL_SDK_FILES = "Remove all SDK files...";
++
++ private Thread installThread = null;
++ private LinkedList<Package> installBuffer = new LinkedList<Package>();
++
+ private InstallManager() {
+ }
+
+ /**
+ * @return singleton instance of <code>InstallManager</code>
+ */
+ public static InstallManager getInstance() {
+ return mInstallManager;
+ }
+
+ /**
+ * Load config file
+ */
+ public void initConfig() {
+ if (mConfig != null) {
+ Registry.saveRepoInfo(mConfig.getConfigFile().getRepository());
+ if (Config.isSupportMultiSDK()) {
+ if (!Registry.getInstalledPath().isEmpty()) {
+ mConfig.setTargetDir(Registry.getInstalledPath());
+ }
+ } else {
+ return;
+ }
+ } else {
+ mConfig = Config.getInstance();
+ Registry.saveRepoInfo(mConfig.getConfigFile().getRepository());
+ if (Options.doReplaceRepository) {
+ Log.log("Replace repository => " + Options.repository);
+ mConfig.getConfigFile().setRepository(Options.repository);
+ mConfig.saveConfig();
+ }
+
+ if (Options.distribution != null && !Options.distribution.isEmpty()) {
+ mConfig.getConfigFile().setDistribution(Options.distribution);
+ mConfig.saveConfig();
+ }
+
+ if (mConfig.getConfigFile() == null) {
+ Log.log("Loading config file failed");
+ throw new IMFatalException("Loading configuration file failed");
+ }
-
++
+ if (!Registry.getInstalledPath().isEmpty()) {
+ mConfig.setTargetDir(Registry.getInstalledPath());
+ }
+ mConfig.setSdkDatatDir(Registry.getSdkDataPath());
+ }
+ }
-
++
+ /**
+ * Initialize packages information.
+ */
+ public void initPackageList() {
+ Collection<String> repositoryURLs = mConfig.getSDKPackageServerList();
+
+ initPackageManager(repositoryURLs);
+ }
+
+ private void initPackageManager(Collection<String> repositoryURLs) {
+ File installedPackageListFile = null;
+ if (!Registry.targetPath.equalsIgnoreCase("")) {
+ installedPackageListFile = new File(PathUtil.get(
+ PathUtil.get(Registry.targetPath, Config.INFO_DIRECTORY),
+ Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
+ } else {
+ installedPackageListFile = new File(PathUtil.get(
+ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
+ Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
+ }
+
+ try {
+ if (installedPackageListFile.exists()) {
- this.packageManager = PackageManager.getInstance(installedPackageListFile, repositoryURLs);
++ this.packageManager = PackageManager.getInstance(
++ installedPackageListFile, repositoryURLs);
+ } else {
- this.packageManager = PackageManager.getInstance(null, repositoryURLs);
++ this.packageManager = PackageManager.getInstance(null,
++ repositoryURLs);
+ }
+ } catch (IOException e) {
+ Log.err("Cannot load package manager =>" + installedPackageListFile
+ + ", " + repositoryURLs);
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_FILE);
+ }
+ }
-
++
+ /**
+ * Initialize distribution and snapshot information
+ */
+ public boolean initDistribution() {
- DistributionController controller =
- DistributionController.getInstance(mConfig.getSDKRepositoryList());
-
++ DistributionController controller = DistributionController
++ .getInstance(mConfig.getSDKRepositoryList());
++
+ boolean initResult = controller.init();
+ Log.log("Init Distribution result => " + initResult);
-
- //First distribution that read from config file is recognized as the distribution installed.
- String installedDistribution = Config.getInstance().getConfigFile().getDistribution();
++
++ // First distribution that read from config file is recognized as the
++ // distribution installed.
++ String installedDistribution = Config.getInstance().getConfigFile()
++ .getDistribution();
+ controller.setInstalledDistribution(installedDistribution);
+
+ return initResult;
+ }
-
-
++
+ /**
+ * Initialize installmanager. It performs that read config file, make
+ * temporary files and load package list from repository.
+ *
+ * @return <code>true</code> if initialize success to install or uninstall.
+ */
+ public void init() {
+ initConfig();
-
++
+ cleanPackageDir();
-
++
+ initDistribution();
+ if (Config.status == Config.Status.INSTALL) {
- checkOldSDK();
++ checkOldSDK();
+ }
+ initPackageList();
+ initConfigurationFile();
+ checkNewPackageServer();
+ }
-
++
+ /**
- * If packageServer has multi SDK packages, set Config.isNewPackageServer true. otherwise false.
- * InstallManager can be used old SDK installation.
++ * If packageServer has multi SDK packages, set Config.isNewPackageServer
++ * true. otherwise false. InstallManager can be used old SDK installation.
+ */
+ private void checkNewPackageServer() {
- if (packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME) == null) {
++ if (packageManager
++ .getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME) == null) {
+ Config.isNewPackageServer = false;
+ Log.log("PackageServer has old SDK packages.");
+ } else {
+ Config.isNewPackageServer = true;
+ Log.log("PackageServer has new SDK packages(Multi SDK).");
+ }
+ }
-
++
+ private void initConfigurationFile() {
+ copyMakeShortCutFile();
+ copyRemoveShortCutFile();
-
- // Linux has several kinds such as Ubuntu, Fedora, etc. So, If installation needs super user's
- // permission, sudo command depends on machine. Therefore, Installmanager gives a tsudo command
- // which does not need to care of machine post install script for package.
++
++ // Linux has several kinds such as Ubuntu, Fedora, etc. So, If
++ // installation needs super user's
++ // permission, sudo command depends on machine. Therefore,
++ // Installmanager gives a tsudo command
++ // which does not need to care of machine post install script for
++ // package.
+ if (Platform.isLinux()) {
+ copyTizenSudoFile();
+ }
+ }
-
++
+ /**
+ * Delete temporary files related installmanager.
+ */
+ public static void deleteTempFile() {
+
+ File tmpDir = new File(PathUtil.getTempFileParent());
+ File[] tmpFiles = tmpDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ boolean found = false;
+ String[] prefix = { "makeshortcut", "removeshortcut",
+ "installmanager.repository", "Packages",
+ "tizen_installmanager", "checkJavaInstallation",
+ "install" };
+ for (String pref : prefix) {
+ found = name.startsWith(pref);
+ if (found == true) {
+ return true;
+ }
+ }
+ return found;
+ }
+ });
-
++
+ if (tmpFiles != null) {
+ for (File f : tmpFiles) {
+ if (!f.delete()) {
+ Log.err("Fail to delete file ==> " + f);
+ }
+ }
+ }
+ }
+
+ /**
+ * Copy make shortcut file from resource to temp directory.
+ */
+ private void copyMakeShortCutFile() {
+ try {
+ if (Platform.isLinux()) {
+ makeShortCutFile = PathUtil.getTempFileFromResource(
+ LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");
+ } else if (Platform.isWindows()) {
+ makeShortCutFile = PathUtil.getTempFileFromResource(
+ WINDOWS_MAKE_SHORTCUT_PATH, "makeshortcut", ".vbs");
+ } else if (Platform.isMacOS()) {
+ makeShortCutFile = PathUtil.getTempFileFromResource(
+ LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
-
++
+ if (makeShortCutFile.exists()) {
+ makeShortCutFile.setExecutable(true);
+ }
+ } catch (IOException e) {
+ Log.err("Installer cannot make 'makeshortcut script' file.");
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
+ }
+ }
+
+ /**
+ * Copy remove shortcut file from resource to temp directory.
+ */
+ private void copyRemoveShortCutFile() {
+ try {
+ if (Platform.isLinux()) {
+ removeShortCutFile = PathUtil.getTempFileFromResource(
+ LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");
+ } else if (Platform.isWindows()) {
+ removeShortCutFile = PathUtil.getTempFileFromResource(
+ WINDOWS_REMOVE_SHORTCUT_PATH, "removeshortcut", ".vbs");
+ } else if (Platform.isMacOS()) {
+ removeShortCutFile = PathUtil.getTempFileFromResource(
+ LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ removeShortCutFile.setExecutable(true);
+ } catch (IOException e) {
+ Log.err("Installer cannot make 'makeshortcut script' file.");
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
+ }
+ }
-
++
+ /**
+ * Copy remove shortcut file from resource to temp directory.
+ */
+ private void copyTizenSudoFile() {
+ try {
- tSudoFile = PathUtil.getTempFileFromResource(LINUX_TSUDO_PATH, "tsudo", ".sh");
++ tSudoFile = PathUtil.getTempFileFromResource(LINUX_TSUDO_PATH,
++ "tsudo", ".sh");
+ tSudoFile.setExecutable(true);
+ } catch (IOException e) {
+ Log.err("Installer cannot make 'tsudo.sh' file.");
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_TSUDO);
+ }
+ }
-
++
+ /**
+ * get make shortcut File instance.
+ *
+ * @return File instance of makeshortcut script.
+ */
+ public File getTSudo() {
+ return tSudoFile;
+ }
+
+ /**
+ * Get temporary file path.(makeshortcut script, Packages list, Installer
+ * log)
+ *
+ * @return temporary file path, if not exist makeshortcut file, return empty
+ * string.
+ */
+ public String getTSudoPath() {
+ if (getTSudo() == null) {
+ return "";
+ } else {
+ return getTSudo().getAbsolutePath();
+ }
+ }
+
+ /**
+ * get make shortcut File instance.
+ *
+ * @return File instance of makeshortcut script.
+ */
+ public File getMakeShortCut() {
+ return makeShortCutFile;
+ }
+
+ /**
+ * Get temporary file path.(makeshortcut script, Packages list, Installer
+ * log)
+ *
+ * @return temporary file path, if not exist makeshortcut file, return empty
+ * string.
+ */
+ public String getMakeShortCutPath() {
+ if (getMakeShortCut() == null) {
+ return "";
+ } else {
+ return getMakeShortCut().getAbsolutePath();
+ }
+ }
+
+ /**
+ * Get temporary file path.(rmoveshortcut script, Packages list, Installer
+ * log)
+ *
+ * @return temporary file path, if not exist removeshortcut file, return
+ * emptry string.
+ */
+ public String getRemoveShortCutPath() {
+ if (getRemoveShortCut() == null) {
+ return "";
+ } else {
+ return getRemoveShortCut().getAbsolutePath();
+ }
+ }
+
+ /**
+ * Get remove shortcut File instance.
+ *
+ * @return File instance of removeshortcut script.
+ */
+ public File getRemoveShortCut() {
+ return removeShortCutFile;
+ }
+
+ /**
+ * Get Config instance
+ *
+ * @return
+ */
+ public Config getConfig() {
+ return mConfig;
+ }
+
+ /**
+ * Get PackageManager instance.
+ *
+ * @return
+ */
+ public PackageManager getPackageManager() {
+ return packageManager;
+ }
-
++
+ /**
+ * Check old SDK is installed for compatibility.
+ */
+ private void checkOldSDK() {
+ Log.log("Check old SDK.");
- if (!Registry.getOldInstalledPath().equals("")) { // Old SDK is installed.
++ if (Registry.getOldInstalledPath() != "") { // 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.
- Log.log("Old SDK is installed but new SDK is also installed. => " + Registry.getInstalledPath());
++ Log.log("Old SDK is installed but new SDK is also installed. => "
++ + Registry.getInstalledPath());
+ return;
+ } else {
- Log.log("Old SDK is installed. => " + Registry.getOldInstalledPath());
++ Log.log("Old SDK is installed. => "
++ + Registry.getOldInstalledPath());
+ setCurrentSDKEnvironment(Registry.getOldInstalledPath());
- }
++ }
+ } else {
+ return;
+ }
+ }
-
++
+ /**
- * If old SDK is installed and new SDK is not installed, installmanager set environment for new SDK running properly.
- * @param targetPath SDK installed path.
++ * If old SDK is installed and new SDK is not installed, installmanager set
++ * environment for new SDK running properly.
++ *
++ * @param targetPath
++ * SDK installed path.
+ */
+ private void setCurrentSDKEnvironment(String targetPath) {
+ Log.log("Set new SDK environment from old SDK.");
+ Registry.sdkDataPath = Config.getConfigHome();
-
++
+ if (targetPath == null || targetPath.isEmpty()) {
+ Log.err("Install path is invalid: " + targetPath
+ + ". This might be a bug of IM");
+ throw new IMFatalException(ErrorCode.INVALID_INSTALL_PATH);
+ } else {
+ Registry.exportInstallPath(targetPath);
- Registry.exportMultiInstallPath(targetPath, true);
++ Registry.exportMultiInstallPath(targetPath, true);
+ }
-
++
+ // Make sdk.info file into target directory for compatibility.
+ Registry.saveSDKInfo(targetPath);
+ // Remove tizensdkpath file in 'tizen-sdk-data'.
-// Registry.removeOldRegistry();
++ // Registry.removeOldRegistry();
+ }
+
+ /**
- * Download packages
- *
- * @param packagesToDownload
- * Set of packages to download
- * @param monitor
- * @return <code>true</code> if download success.
- * @throws IMExitException
++ * @param pkg
++ * @param filePath
++ * @return <code>true</code> if the package is already downloaded to the
++ * file path
+ */
- public boolean downloadPackages(PackageSet downloadPkgSet,
- InstallProgressMonitor monitor) throws IMExitException, IMNetworkException{
- Log.log("InstallManager download start => " + downloadPkgSet);
++ private boolean existInCacheFolder(Package pkg, String filePath,
++ IIMProgressMonitor monitor) {
++ File file = new File(filePath);
+
- long totalSize = 0;
- for (Package pkg : downloadPkgSet) {
- totalSize += pkg.getPackageSize();
++ if (!file.exists()) {
++ return false;
+ }
+
+ if (monitor != null) {
- monitor.workedRefresh();
- int total = (int) (totalSize / 1024);
- monitor.beginTask("", total);
++ monitor.workedDownloadProgress("Validate the " + pkg.getPackageName(), 0);
+ }
+
- for (Package pkg : downloadPkgSet) {
-
- if (monitor != null) {
- monitor.workedDownload(pkg.getPackageName());
++ if (Options.doPackageValidation) {
++ if (Checksum.getSHA256(filePath) != null) {
++ return checkFileChecksum(pkg, Checksum.getSHA256(filePath));
+ } else {
- if (Options.doInstallNoUI) {
- System.out.println(pkg.getPackageName() + " is downloading...");
- }
++ return false;
+ }
++ } else {
++ return true;
++ }
++ }
+
- if (monitor != null && monitor.isCanceled()) {
- Log.log("download canceled");
- throw new IMInstallCancelException();
- }
++ private boolean checkPackageSize(Package pkg, long size) {
++ if (pkg.getPackageSize() == size) {
++ return true;
++ }
++ return false;
++ }
+
- String fileName = pkg.getFileName();
- boolean downloadResult = downloadPackage(pkg, PathUtil.addURLPath(mConfig.getDownloadPkgPath(), fileName), monitor);
++ private boolean checkFileChecksum(Package pkg, MessageDigest mDigest) {
+
- if (!downloadResult) {
- Log.err("InstallManager download fail => " + pkg);
- return false;
- }
++ if (pkg.getSHA256() == null || pkg.getSHA256().isEmpty()) {
++ return false;
+ }
+
- if (monitor != null) {
- monitor.workedProgressbar(100);
++ if (mDigest.getAlgorithm().equals(Checksum.SHA_256_TYPE)) {
++ return (pkg.getSHA256().equalsIgnoreCase(Checksum
++ .messageDigestToString(mDigest)));
++ } else {
++ // TODO there's no checksum field in package.
++ return false;
+ }
-
- return true;
+ }
+
+ /**
- * Download package.
++ * Packages Installation management. Download and install packages.
+ *
- * @param packageToDownload
- * @param fileDownloadTargetPath
++ * @param packagesToInstall
++ * @param targetDir
+ * @param monitor
- * @return <code>true</code> if success
++ * @return
++ * @throws IMExitException
+ */
- public boolean downloadPackage(Package packageToDownload,
- String fileDownloadTargetPath, IIMProgressMonitor monitor) throws IMNetworkException{
- Log.log("Download package '" + packageToDownload + "'");
-
- if (packageToDownload == null || fileDownloadTargetPath == null
- || fileDownloadTargetPath.isEmpty()) {
- Log.err("InstallManager.downloadPackage(): Invalid package: "
- + packageToDownload + ": This might be a bug of IM");
- throw new IMFatalException(
- ErrorCode.PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL);
++ public boolean install(PackageSet installablePackages,
++ final String targetDir, InstallProgressMonitor monitor)
++ throws IMExitException, IMNetworkException {
++ Log.log("InstallManager.install() installable packages : "
++ + installablePackages);
++
++ // performance measurement
++ Performance.sdkPackageSize = packageManager
++ .getTotalSizeOfInstallablePackages(installablePackages, true);
++
++ if (installablePackages == null || targetDir == null
++ || targetDir.isEmpty()) {
++ Log.err("packaegs => " + installablePackages + ", targetDir => "
++ + targetDir);
++ return false;
+ }
++
++ mConfig.setTargetDir(targetDir);
++ mConfig.setSdkDatatDir(Registry.sdkDataPath);
+
- // Check cache foler
- if (existInCacheFolder(packageToDownload, fileDownloadTargetPath, monitor)) {
- if (monitor != null) {
- if (monitor.isCanceled()) {
- throw new IMFatalException(ErrorCode.CANCEL);
- } else {
- monitor.workedChecksum(packageToDownload.getPackageSize());
- }
- }
- Log.log("Found in cache");
-
- return true;
++ if (monitor != null) {
++ monitor.workedRefresh();
++ monitor.beginTask(installablePackages.size(),
++ getTotalDownloadSize(installablePackages),
++ getTotalInstallSize(installablePackages));
+ }
++
++ initializeTargetDir(targetDir);
++ makeShortcutMenu();
+
+ // TODO : refactoring.
+ long size = 0;
- if (Options.onlyDownload || Options.downloadPackage) {
++ if (Options.onlyDownload) {
+ System.out.print("Downloading package => " + packageToDownload + " .......");
+ }
+ Log.log("start download package: " + packageToDownload);
+ URL packageUrl = packageToDownload.getURL();
+
+ if (monitor != null) {
+ monitor.workedDownload(packageToDownload.getPackageName());
+ }
+ size = mDownloader.download(packageUrl, fileDownloadTargetPath,
+ monitor);
+
+ if (size >= 0) {
- if (Options.onlyDownload || Options.downloadPackage) {
++ if (Options.onlyDownload) {
+ System.out.println(" done.");
+ }
+ Log.log("finish download");
+ } else {
+ Log.err("download failed => " + packageToDownload.getURL());
+
+ PathUtil.remove(fileDownloadTargetPath);
+
+ String errMsg = "";
-
- if (monitor != null) {
- if (monitor.isCanceled()) {
- errMsg = ErrorController.getErrorMessage();
- } else {
- errMsg = "Fail to get '" +
- packageToDownload.getPackageName() + "'." +
- "\n(" + ErrorController.getErrorMessage() + ")";
- }
- throw new IMFatalException(errMsg);
++ if (monitor.isCanceled()) {
++ errMsg = ErrorController.getErrorMessage();
+ } else {
- Log.err("monitor is null.");
++ errMsg = "Fail to get '" +
++ packageToDownload.getPackageName() + "'." +
++ "\n(" + ErrorController.getErrorMessage() + ")";
+ }
++ throw new IMFatalException(errMsg);
+ }
+
- if (Options.doPackageValidation) {
- Log.log("Validate package");
- if (!checkPackageSize(packageToDownload, size)) {
- Log.err("The expected size of package => " + packageToDownload.getPackageSize());
- Log.err("Package size error. downloaded size => " + size);
-
- PathUtil.remove(fileDownloadTargetPath);
-
- throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);
- }
++ // download complete.
++ if (monitor != null) {
++ monitor.workedDownloadProgress("Download complete", 0);
++ monitor.downloadDone();
++ }
+
- // TODO :
- if (!checkFileChecksum(packageToDownload,
- mDownloader.getFileChecksum())) {
- Log.err("The expected checksum of package => " + packageToDownload.getSHA256());
- Log.err("Package checksum error downloaded checksum => "
- + mDownloader.getFileChecksum());
-
- PathUtil.remove(fileDownloadTargetPath);
-
- throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);
- }
++ // install thread is running yet.
++ try {
++ installThread.join();
++ } catch (InterruptedException e) {
++ Log.ExceptionLog(e);
++ Log.err("");
+ }
+
- return true;
- }
++ // install complete
++ if (monitor != null) {
++ monitor.workedInstallProgress("Installation complete", 0);
++ monitor.installDone();
++ }
+
- /**
- * @param pkg
- * @param filePath
- * @return <code>true</code> if the package is already downloaded to the
- * file path
- */
- private boolean existInCacheFolder(Package pkg, String filePath, IIMProgressMonitor monitor) {
- File file = new File(filePath);
++ // save config file
++ mConfig.saveConfig();
+
- if (!file.exists()) {
- return false;
++ // save sdk version.
++ saveSDKVersion();
++
++ // Delete installed packages
++ if (Options.doRemovePackages) {
++ removePackagesDir();
+ }
-
- if (monitor != null) {
- monitor.workedChecksum(pkg.getPackageName());
++
++ if (Config.status == Config.Status.INSTALL) {
++ Registry.exportMultiInstallPath(targetDir, true);
+ }
+
- if (Options.doPackageValidation) {
- if (Checksum.getSHA256(filePath) != null) {
- return checkFileChecksum(pkg, Checksum.getSHA256(filePath));
- } else {
- return false;
- }
- } else {
- return true;
++ // show reboot message in linux platform.
++ if (Platform.isLinux() || Platform.isMacOS()) {
++ ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);
+ }
++
++ Performance.setInstallationEndTime();
++ return true;
+ }
+
- private boolean checkPackageSize(Package pkg, long size) {
- if (pkg.getPackageSize() == size) {
- return true;
++ private long getTotalDownloadSize(PackageSet pkgSet) {
++ if (pkgSet == null) {
++ return -1;
+ }
- return false;
- }
+
- private boolean checkFileChecksum(Package pkg, MessageDigest mDigest) {
++ long totalSize = 0;
++ for (Package pkg : pkgSet) {
++ totalSize += pkg.getPackageSize();
++ }
+
- if (pkg.getSHA256() == null || pkg.getSHA256().isEmpty()) {
- return false;
++ return totalSize;
++ }
++
++ private long getTotalInstallSize(PackageSet pkgSet) {
++ if (pkgSet == null) {
++ return -1;
+ }
+
- if (mDigest.getAlgorithm().equals(Checksum.SHA_256_TYPE)) {
- return (pkg.getSHA256().equalsIgnoreCase(Checksum
- .messageDigestToString(mDigest)));
- } else {
- // TODO there's no checksum field in package.
- return false;
++ long totalSize = 0;
++ for (Package pkg : pkgSet) {
++ totalSize += pkg.getUncompressedPackageSize();
+ }
++
++ return totalSize;
+ }
+
- /**
- * Package installation management
- *
- * @param pkg
- * package to install.
- * @param targetDir
- * target directory to install.
- * @param monitor
- * @return
- */
- public boolean install(Package pkg, String targetDir,
- IIMProgressMonitor monitor) {
- Log.log("Install package '" + pkg + "'");
++ private boolean install(final Package pkg, final String targetDir,
++ final InstallProgressMonitor monitor) throws IMExitException,
++ IMNetworkException {
++ Log.log("Install package => " + pkg.getPackageName());
++ Log.log("Target directory => " + targetDir);
+
- if (monitor != null) {
- monitor.workedProcess(pkg.getPackageName());
- } else {
- if (Options.doInstallNoUI) {
- System.out.println(pkg.getPackageName() + " is installing...");
- }
++ boolean result = false;
++
++ if (Options.doTest && Performance.getDownloadStartTime() == null) {
++ Performance.setDownloadStartTime();
+ }
+
- Installer installer = new Installer();
- boolean bResult = installer.install(pkg, targetDir, monitor);
++ // download package from repository.
++ result = downloadPackage(pkg, monitor);
+
- if (bResult) {
- // save installed package list
- packageManager.addPackageToInstalledPackages(pkg);
- packageManager.saveInstalledList(PathUtil.get(
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
- Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
++ if (Options.doTest) {
++ Performance.setDownloadEndTime();
++ }
++
++ if (result) {
++ installBuffer.push(pkg);
++
++ if (Options.doTest
++ && Performance.getInstallationStartTime() == null) {
++ Performance.setInstallationStartTime();
++ }
++
++ if (installThread == null || !installThread.isAlive()) {
++ installThread = new Thread() {
++ public void run() {
++ Package p = null;
++ while ((p = installBuffer.pollLast()) != null) {
++ if (!installPackage(p, targetDir, monitor)) {
++ return;
++ }
++
++ if (installBuffer.size() <= 0) {
++ if (monitor != null ) {
++ monitor.workedInstallProgress("Waiting for download", 0);
++ monitor.installEnd();
++ }
++ }
++ }
++ }
++ };
++
++ installThread.start();
++ }
++
++ if (Options.doTest) {
++ Performance.setInstallationEndTime();
++ }
++
++ if (!ErrorController.checkInstallationSuccess()) {
++ return false;
++ }
+ } else {
- Log.err("InstallManager.install() install fail => " + pkg);
++ Log.log("Installation failed. => " + pkg.getPackageName());
+ return false;
+ }
- return bResult;
++
++ return result;
+ }
+
+ /**
+ * Packages Installation management.
+ * Download and install packages.
+ *
+ * @param packagesToInstall
+ * @param targetDir
+ * @param monitor
+ * @return
+ * @throws IMExitException
+ */
+ public boolean install(PackageSet installablePackages, final String targetDir,
+ InstallProgressMonitor monitor) throws IMExitException, IMNetworkException{
+ Log.log("InstallManager.install() installable packages : " + installablePackages);
+
+ //performance measurement
+ Performance.sdkPackageSize = packageManager.getTotalSizeOfInstallablePackages(installablePackages, true);
+
+ if (installablePackages == null || targetDir == null || targetDir.isEmpty()) {
+ Log.err("packaegs => " + installablePackages + ", targetDir => "
+ + targetDir);
+ return false;
+ }
+
+ mConfig.setTargetDir(targetDir);
+ mConfig.setSdkDatatDir(Registry.sdkDataPath);
+
- // Temporary code for installing intel haxm package for the first time.
- initializeTargetDir(targetDir);
-
- if (!Performance.existDownloadStartTime()) {
- Performance.setDownloadStartTime();
- }
-
- // Temporary code for installing intel haxm package for the first time.
- PackageSet preDownloadPkgs = new PackageSet();
-
- for (Package pkg : installablePackages) {
- if (!pkg.getPackageName().equalsIgnoreCase("intelhaxm")) {
- continue;
- } else {
- preDownloadPkgs.add(pkg);
- if (downloadPackages(preDownloadPkgs, monitor)) {
- Log.log("Success to download intelhaxm package from repository specially!!!!!!.");
- } else {
- Log.err("Fail to download intelhaxm package from repository.");
- if (!Options.doResumeDownloading) {
- removePackagesDir();
- }
- return false;
- }
- }
- }
-
- //Temporary code for installing intel haxm package for the first time.
- if (monitor != null) {
- monitor.beginTask("Installing", installablePackages.size());
- }
-
- int i = 0;
-
- // Temporary code for installing intel haxm package for the first time.
- for (Package pkg : preDownloadPkgs) {
- if (!pkg.getPackageName().equalsIgnoreCase("intelhaxm")) {
- continue;
- } else {
- if (monitor != null) {
- monitor.workedProcess(pkg.getPackageName());
- monitor.worked(++i);
- }
-
- if (!install(pkg, targetDir, monitor)) {
- Log.log("Installation fail => " + pkg);
-
- if (!Options.doResumeDownloading) {
- removePackagesDir();
- }
-
- throw new IMFatalException(ErrorCode.INSTALLATION_FAIL);
- }
- }
- }
-
- installablePackages.remove(packageManager.getPackageByName("intelhaxm"));
++ Performance.setDownloadStartTime();
+
+ // download packages from repository
+ if (downloadPackages(installablePackages, monitor)) {
+ Log.log("Success to download packages from repository.");
+ } else {
+ Log.err("Fail to download packages from repository.");
+ if (!Options.doResumeDownloading) {
+ removePackagesDir();
+ }
+
+ return false;
+ }
-
- // wait if cancel confirm dialog is showing. wait until user press
- // button(cancel or not).
++
++ // check the cancel button
+ if (monitor != null) {
- while (monitor.checkCancelAndDisableCancelButton() == false) {
- if (monitor.isCanceled()) {
- throw new IMInstallCancelException();
- }
++ if (monitor.isCanceled()) {
++ Log.log("download canceled");
++ throw new IMInstallCancelException();
++ } else {
++ monitor.workedDownloadProgress(pkg.getPackageName(), 1);
+ }
+ }
-
- Performance.setDownloadEndTime();
++
++ URL downloadFileURL = pkg.getURL();
++ String downloadTargetPath = getDownloadTargetPath(pkg);
+
+ Performance.setInstallationStartTime();
+ // save target directory
-// initializeTargetDir(targetDir);
++ initializeTargetDir(targetDir);
+
+ //if distribution is changed, remove all packages and install.
+ if (packageManager.isReInstallable()) {
+ removeAllPackages(monitor);
+ } else {
+ // remove missing packages
+ if (!packageManager.isRepoPackagesEmpty()) {
+ // Remove missing packages only network installation.
+ if (Config.fromWhere == Config.ConfDialog.SNAPSHOT) {
+ removeMissingPackages(monitor);
+ }
+ }
+
- // remove conflict packages
- if (!removeConflictPackages(installablePackages, monitor)) {
- Log.err("Cannot remove conflict package");
- throw new IMFatalException(
- ErrorCode.CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES);
++ // download package from repository
++ long size = mDownloader.download(downloadFileURL, downloadTargetPath,
++ monitor);
++
++ if (size >= 0) {
++ if (Options.onlyDownload) {
++ System.out.println("Download success. => " + pkg);
+ }
++ Log.log("finish download => " + pkg);
++ } else { // fail
++ Log.err("download failed => " + downloadFileURL);
+
- boolean result = false;
- //If Options.snapshot is true, remove installed packages that differernt version from installable packages.
- if (Options.snapshot) {
- result = removeDifferentVersionPackages(installablePackages, monitor);
++ PathUtil.remove(downloadTargetPath);
++
++ String errMsg = "";
++ if (monitor.isCanceled()) {
++ errMsg = ErrorController.getErrorMessage();
+ } else {
- result = removeUpdatablePackages(installablePackages, monitor);
- }
-
- if (!result) {
- Log.err("Cannot remove updatable package");
- throw new IMFatalException(
- ErrorCode.CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES);
++ errMsg = "Fail to get '" + pkg.getPackageName() + "'." + "\n("
++ + ErrorController.getErrorMessage() + ")";
+ }
++ throw new IMFatalException(errMsg);
+ }
+
- //start installation
- if (monitor != null) {
- monitor.beginTask("Installing", installablePackages.size() + 1);
- }
++ // package validation
++ if (Options.doPackageValidation) {
++ Log.log("Validate package");
++ if (!checkPackageSize(pkg, size)) {
++ Log.err("The expected size of package => "
++ + pkg.getPackageSize());
++ Log.err("Package size error. downloaded size => " + size);
+
- // make start menu
- makeShortcutMenu();
-
- // if you cannot get installmanager from repository, install from local.
- if (!packageManager.existsPackage(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME)) {
- Log.log("Cannot find install-manager from repository.");
- if (!installInstallManagerFromLocal(targetDir)) {
- Log.err("Cannot install install-manager from local directory.");
++ PathUtil.remove(downloadTargetPath);
++
++ throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);
++ }
++
++ // TODO :
++ if (!checkFileChecksum(pkg, mDownloader.getFileChecksum())) {
++ Log.err("The expected checksum of package => "
++ + pkg.getSHA256());
++ Log.err("Package checksum error downloaded checksum => "
++ + mDownloader.getFileChecksum());
++
++ PathUtil.remove(downloadTargetPath);
++
++ throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);
+ }
+ }
+
++ int i = 0;
+ for (Package pkg : installablePackages) {
+ if (monitor != null) {
+ monitor.workedProcess(pkg.getPackageName());
+ monitor.worked(++i);
+ }
+
- if (!install(pkg, targetDir, monitor)) {
- Log.log("Installation fail => " + pkg);
-
- if (!Options.doResumeDownloading) {
- removePackagesDir();
- }
-
- throw new IMFatalException(ErrorCode.INSTALLATION_FAIL);
++ private boolean installPackage(Package pkg, String targetDir,
++ InstallProgressMonitor monitor) {
++ // save target directory
++ initializeTargetDir(targetDir);
++
++ // remove packages to update.
++ if (packageManager.isInstalledPackage(pkg) && (packageManager.isReInstall() || packageManager.isUpdatable(pkg))) {
++ if (monitor != null) {
++ monitor.workedInstallProgress("Remove the previous version", 0);
+ }
++
++ removePackage(pkg, null);
+ }
+
- // remove temp directory
- String tempDir = targetDir + File.separator + Config.TEMP_DIRECTORY;
- PathUtil.remove(tempDir);
-
- // save config file
- mConfig.saveConfig();
-
- // save sdk version.
- saveSDKVersion();
-
- // Delete installed packages
- if (Options.doRemovePackages) {
- removePackagesDir();
++ // remove conflict packages
++ PackageSet pkgSet = packageManager.getConflictPackages(pkg);
++ if (pkgSet.size() > 0) {
++ if (monitor != null) {
++ monitor.workedInstallProgress("Remove the conflict packages", 0);
++ }
++ removePackages(pkgSet, null);
+ }
+
- // move InstallManager to target directory
- if (monitor != null) {
- monitor.workedSubTitle("Move to target directory...");
++ if (Options.doInstallNoUI) {
++ System.out.println(pkg.getPackageName() + " is installing...");
+ }
-
- if (Config.status == Config.Status.INSTALL) {
- Registry.exportMultiInstallPath(targetDir, true);
++
++ Installer installer = new Installer();
++ boolean bResult = installer.install(pkg, targetDir, monitor);
++
++ if (bResult) {// save installed package list
++ packageManager.addPackageToInstalledPackages(pkg);
++ packageManager.saveInstalledList();
++ } else {
++ Log.log("Installation failed => " + pkg);
++
++ ErrorController.setError(ErrorCode.INSTALLATION_FAIL);
++ ErrorController.setInstallationSuccess(false);
+ }
-
- //show reboot message in linux platform.
- if (Platform.isLinux() || Platform.isMacOS()) {
- ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);
++
++ return bResult;
++ }
++
++ public String getDownloadTargetPath(Package pkg) {
++ String repository = pkg.getBaseURL().toString();
++
++ String encodeRepository = null;
++ try {
++ encodeRepository = URLEncoder.encode(repository, "UTF-8");
++ } catch (UnsupportedEncodingException e) {
++ Log.ExceptionLog(e);
++ return encodeRepository;
+ }
-
- Performance.setInstallationEndTime();
-
- return true;
++
++ return PathUtil.get(mConfig.getDownloadDirPath(), encodeRepository,
++ pkg.getFileName());
+ }
-
++
+ private boolean installInstallManagerFromLocal(String sdkPath) {
+ Log.log("Install install-manager from local. => " + sdkPath);
- String targetDir = PathUtil.get(sdkPath, InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
-
++ String targetDir = PathUtil.get(sdkPath,
++ InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
++
+ File targetDirFile = new File(targetDir);
-
++
+ if (!targetDirFile.exists()) {
+ targetDirFile.mkdirs();
+ }
-
++
+ try {
+ if (Platform.isLinux()) {
- installInstallManagerFromLocalInLinux(targetDir);
++ installInstallManagerFromLocalInLinux(targetDir);
+ } else if (Platform.isWindows()) {
+ installInstallManagerFromLocalInWindows(targetDir);
+ } else if (Platform.isMacOS()) {
+ installInstallManagerFromLocalInMac(targetDir);
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
-
- File toInstallManagerImage = new File(PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME, InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_NAME));
- PathUtil.writeFileFromInputStream(PathUtil.getResourceAsStream(InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_PATH), toInstallManagerImage);
-
- File toDesktopFile = new File(PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME, InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_NAME));
- PathUtil.writeFileFromInputStream(PathUtil.getResourceAsStream(InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_PATH), toDesktopFile);
++
++ File toInstallManagerImage = new File(PathUtil.get(
++ Registry.getInstalledPath(),
++ InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,
++ InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_NAME));
++ PathUtil.writeFileFromInputStream(
++ PathUtil.getResourceAsStream(InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_PATH),
++ toInstallManagerImage);
++
++ File toDesktopFile = new File(PathUtil.get(
++ Registry.getInstalledPath(),
++ InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,
++ InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_NAME));
++ PathUtil.writeFileFromInputStream(
++ PathUtil.getResourceAsStream(InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_PATH),
++ toDesktopFile);
+
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ return false;
+ }
-
- //execute install script
++
++ // execute install script
+ File installScript = getInstallScript();
+ if (installScript != null && installScript.exists()) {
+ installScript.setExecutable(true);
-
++
+ Installer installer = new Installer();
+ try {
+ installer.executeScript(installScript);
+ return true;
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ return false;
+ }
-
++
+ private void installInstallManagerFromLocalInLinux(String targetDir) {
+ try {
- //copy excutable file to target directory
- PathUtil.copy(PathUtil.get(Options.executablePath, InstallManagerConstants.INSTALLMANAGER_BINARY_NAME), targetDir);
-
- //copy library file to target directory
- PathUtil.copy(PathUtil.get(PathUtil.getCurrentDir(), InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME), targetDir);
++ // copy excutable file to target directory
++ PathUtil.copy(PathUtil.get(Options.executablePath,
++ InstallManagerConstants.INSTALLMANAGER_BINARY_NAME),
++ targetDir);
++
++ // copy library file to target directory
++ PathUtil.copy(PathUtil.get(PathUtil.getCurrentDir(),
++ InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME),
++ targetDir);
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
-
++
+ private void installInstallManagerFromLocalInWindows(String targetDir) {
+ installInstallManagerFromLocalInLinux(targetDir);
+ }
+
+ private void installInstallManagerFromLocalInMac(String targetDir) {
- String parentDir = PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 4);
-
- String imExecutableAppDirPath = PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_DIR_NAME_FOR_MAC);
++ String parentDir = PathUtil.getParentDirectory(
++ PathUtil.getCurrentDir(), 4);
++
++ String imExecutableAppDirPath = PathUtil
++ .get(parentDir,
++ InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_DIR_NAME_FOR_MAC);
+ String command = "cp -rf " + imExecutableAppDirPath + " " + targetDir;
-
++
+ try {
+ ShellUtil.execute(command);
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ Log.err(command);
- throw new IMFatalException(ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
++ throw new IMFatalException(
++ ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
+ }
-
- String imExecutableBinaryPath = PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX);
++
++ String imExecutableBinaryPath = PathUtil
++ .get(parentDir,
++ InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX);
+ command = "cp -rf " + imExecutableBinaryPath + " " + targetDir;
-
++
+ try {
+ ShellUtil.execute(command);
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ return;
+ }
-
- String imJarFilePath = PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME);
++
++ String imJarFilePath = PathUtil.get(parentDir,
++ InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME);
+ command = "cp -rf " + imJarFilePath + " " + targetDir;
-
++
+ try {
+ ShellUtil.execute(command);
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ return;
+ }
+ }
-
++
+ private void removeMissingPackages(IIMProgressMonitor monitor) {
+ PackageSet missingPackages = packageManager
+ .getMissingPackagesFromRepository();
+ Log.log("Remove missing packages => " + missingPackages);
+
+ if (monitor != null) {
- monitor.workedTitle("Remove Missing Packages");
++ monitor.workedDownloadProgress("Remove missing packages", 0);
+ }
+
+ for (Package pkg : missingPackages) {
+ if (!removePackage(pkg, monitor)) {
+ Log.err("Cannot remove missing package");
+ throw new IMFatalException(
+ ErrorCode.CANNOT_REMOVE_MISSING_PACKAGE);
+ }
+ }
+ }
+
- private boolean removeConflictPackages(PackageSet installableMetaPkgs,
- IIMProgressMonitor monitor) {
- PackageSet conflictPackages = packageManager
- .getConflictPackagesInUpdate(installableMetaPkgs);
- Log.log("Remove conflict packages => " + conflictPackages);
-
- if (conflictPackages.isEmpty()) {
- return true;
- }
-
- if (monitor != null) {
- monitor.workedTitle("Remove Conflict Packages");
- }
-
- return remove(conflictPackages);
- }
-
- private boolean removeDifferentVersionPackages(PackageSet installablePackages,
- IIMProgressMonitor monitor) {
- PackageSet updatablePackages = packageManager
- .getdifferentVersionFromInstalledPackages(installablePackages);
-
- if (updatablePackages.isEmpty()) {
- return true;
- }
-
- Log.log("Remove packages in snapshot => " + updatablePackages);
-
- if (monitor != null) {
- monitor.workedTitle("Remove updatable Packages...");
- }
-
- return remove(updatablePackages);
- }
- private boolean removeUpdatablePackages(PackageSet installablePackages,
- IIMProgressMonitor monitor) {
- PackageSet updatablePackages = packageManager
- .getUpdatablePackagesInUpdate(installablePackages);
-
- if (updatablePackages.isEmpty()) {
- return true;
- }
-
- Log.log("Remove updatable packages => " + updatablePackages);
-
- if (monitor != null) {
- monitor.workedTitle("Remove updatable Packages");
- }
-
- return remove(updatablePackages);
- }
-
- private boolean remove(PackageSet packages) {
- for (Package pkg : packages) {
-
- if (removePackage(pkg, null)) {
- continue;
- } else {
- Log.err("Cannot remove package => " + pkg);
- return false;
- }
- }
-
- return true;
- }
-
+ /**
+ * Initializes target directory
+ *
+ * @param targetDir
+ * path to SDK target directory
+ */
+ public void initializeTargetDir(String targetDir) {
+ Log.log("Initialize target dir. " + targetDir);
+ // Make target directory
+ File targetDirFile = new File(targetDir);
+ if (!targetDirFile.exists()) {
+ if (!targetDirFile.mkdirs()) {
+ Log.err("Fail to create file ==> " + targetDirFile);
+ }
+ }
+
+ // Keep target path in system
+ Registry.exportInstallPath(targetDir);
+
+ // Keep target path for later use
+ mConfig.setTargetDir(targetDir);
+ mConfig.setSdkDatatDir(Registry.sdkDataPath);
+
+ // Make .info directory
+ if (!mConfig.makeInfoDirectory()) {
+ Log.err(Config.CONFIG_HOME_PATH + " cannot create.");
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_CONFIG_FILE);
+ }
+ }
-
++
+ /**
+ * Save installed SDK version.
+ */
+ public void saveSDKVersion() {
- Registry.saveInstallVersion(mConfig.getConfigFile().getInstallManagerVersion());
++ Registry.saveInstallVersion(mConfig.getConfigFile()
++ .getInstallManagerVersion());
+ }
+
+ /**
+ * Make tizen menu and installmanager shortcut.
+ */
+ private void makeShortcutMenu() {
+ Log.log("InstallManager make shortcut menu.");
+
+ // execute install script.
+ File installScript = getInstallScript();
+ if (installScript != null) {
+ installScript.setExecutable(true);
+
+ Installer installer = new Installer();
+ try {
+ installer.executeScript(installScript);
+ } catch (IMShellCommandFail e) {
+ // TODO
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+
+ /**
+ * Get install script from resource according to each platform.
+ *
+ * @return
+ */
+ private File getInstallScript() {
+ try {
+ if (Platform.isLinux()) {
+ return PathUtil.getTempFileFromResource(
- LINUX_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install", ".sh");
++ LINUX_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",
++ ".sh");
+ } else if (Platform.isWindows()) {
+ return PathUtil.getTempFileFromResource(
+ WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",
+ ".vbs");
+ } else if (Platform.isMacOS()) {
+ return null;
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ } catch (IOException e) {
+ Log.err("Cannot execute InstallManager's install script.");
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
+ }
+ }
+
+ private void removeInstallManager() {
+ Log.log("InstallManager.removeInstallManager");
+
- String installManagerDirectory = PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
++ String installManagerDirectory = PathUtil.get(
++ Registry.getInstalledPath(),
++ InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
+ PathUtil.remove(installManagerDirectory);
+
+ if (Registry.getInstalledPath().isEmpty()) {
+ return;
+ }
+ }
+
+ private void removeShortcutMenu() {
+ File removeScript = getRemoveScript();
+
+ if (removeScript == null) {
+ return;
+ }
+
+ removeScript.setExecutable(true);
+
+ Installer installer = new Installer();
+ try {
+ installer.executeScript(removeScript);
+ } catch (IMShellCommandFail e) {
+ Log.err("Cannot execute InstallManager's remove script.");
+ Log.ExceptionLog(e);
+ }
+ }
+
+ private File getRemoveScript() {
+ try {
+ if (Platform.isLinux()) {
- return PathUtil.getTempFileFromResource(
- LINUX_INSTALL_MANAGER_REMOVE_SCRIPT, "im_remove", ".sh");
- } else if (Platform.isWindows()) {
+ return PathUtil
+ .getTempFileFromResource(
- WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT,
- "im_remove", ".vbs");
++ LINUX_INSTALL_MANAGER_REMOVE_SCRIPT,
++ "im_remove", ".sh");
++ } else if (Platform.isWindows()) {
++ return PathUtil.getTempFileFromResource(
++ WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT, "im_remove",
++ ".vbs");
+ } else if (Platform.isMacOS()) {
+ return null;
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ Log.err("Cannot get InstallManager's remove script.");
+ Log.ExceptionLog(e);
+ return null;
+ }
+ }
+
-
+ /*
- private void copyInstallManagerToTargetDirectoryForMac() {
- Log.log("Copy InstallManager to target in MAC platform");
-
- //get '.app' directory
- String fromPath = PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 3);
- if (fromPath == null) {
- Log.err("Cannot get parent directory => " + PathUtil.getCurrentDir());
- return;
- }
-
- File fromFile = new File(fromPath);
-
- if (Registry.getInstalledPath() == null
- || Registry.getInstalledPath().equals("")) {
- Log.err("Cannot find target dir");
- return;
- }
-
- File toFile = getInstalledAppPath();
- if (!toFile.exists()) {
- if (!toFile.mkdirs()) {
- Log.err("Fail to create file ==> " + toFile);
- }
- }
-
- if (fromFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {
- return;
- }
-
- try {
- PathUtil.copy(fromFile, toFile);
- } catch (IOException e) {
- Log.ExceptionLog(e);
- return;
- }
-
- // copy InstallManager script to {target dir}/install-manager/
- File installManagerScript = new File(PathUtil.get(Registry.getInstalledPath(),
- Config.INSTALL_MANAGER_DIRECTORY,
- Config.INSTALL_MANAGER_APP_JAVA,
- Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER ));
- File targetDir = new File(PathUtil.get(Registry.getInstalledPath(),
- Config.INSTALL_MANAGER_DIRECTORY));
-
- try {
- PathUtil.copy(installManagerScript, targetDir);
- } catch (IOException e) {
- Log.ExceptionLog(e);
- return;
- }
-
- //remove binary directory in target directory
- String removableBinaryPath = PathUtil.get(toFile.getAbsolutePath()
- , "Contents"
- , "Resources"
- , "Java"
- , "binary");
-
- PathUtil.remove(removableBinaryPath);
- }
-
- private File getInstalledAppPath() {
- String appPath = Registry.getInstalledPath() + File.separator
- + Config.INSTALL_MANAGER_DIRECTORY + File.separator
- + Config.INSTALL_MANAGER_APP;
-
- return new File(appPath);
- } */
++ * private void copyInstallManagerToTargetDirectoryForMac() {
++ * Log.log("Copy InstallManager to target in MAC platform");
++ *
++ * //get '.app' directory String fromPath =
++ * PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 3); if (fromPath ==
++ * null) { Log.err("Cannot get parent directory => " +
++ * PathUtil.getCurrentDir()); return; }
++ *
++ * File fromFile = new File(fromPath);
++ *
++ * if (Registry.getInstalledPath() == null ||
++ * Registry.getInstalledPath().equals("")) {
++ * Log.err("Cannot find target dir"); return; }
++ *
++ * File toFile = getInstalledAppPath(); if (!toFile.exists()) { if
++ * (!toFile.mkdirs()) { Log.err("Fail to create file ==> " + toFile); } }
++ *
++ * if (fromFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {
++ * return; }
++ *
++ * try { PathUtil.copy(fromFile, toFile); } catch (IOException e) {
++ * Log.ExceptionLog(e); return; }
++ *
++ * // copy InstallManager script to {target dir}/install-manager/ File
++ * installManagerScript = new File(PathUtil.get(Registry.getInstalledPath(),
++ * Config.INSTALL_MANAGER_DIRECTORY, Config.INSTALL_MANAGER_APP_JAVA,
++ * Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER )); File targetDir = new
++ * File(PathUtil.get(Registry.getInstalledPath(),
++ * Config.INSTALL_MANAGER_DIRECTORY));
++ *
++ * try { PathUtil.copy(installManagerScript, targetDir); } catch
++ * (IOException e) { Log.ExceptionLog(e); return; }
++ *
++ * //remove binary directory in target directory String removableBinaryPath
++ * = PathUtil.get(toFile.getAbsolutePath() , "Contents" , "Resources" ,
++ * "Java" , "binary");
++ *
++ * PathUtil.remove(removableBinaryPath); }
++ *
++ * private File getInstalledAppPath() { String appPath =
++ * Registry.getInstalledPath() + File.separator +
++ * Config.INSTALL_MANAGER_DIRECTORY + File.separator +
++ * Config.INSTALL_MANAGER_APP;
++ *
++ * return new File(appPath); }
++ */
+
+ /**
+ * Remove trash packages which are used during installation using SDK image.
+ */
+ private void cleanPackageDir() {
+ // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY
- if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,
++ if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,
+ Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME,
+ Config.INSTALL_MANAGER_IMAGE_DOWNLOAD_DIRECTORY_NAME))) {
+ Log.log("Success to remove trash SDK image package binaries.");
+ } else {
+ Log.err("Fail to remove trash SDK image package binaries.");
+ }
+ }
-
++
+ public void removePackagesDir() {
+ // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY
+ if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,
+ Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME))) {
+ Log.log("Success to remove downloaded package binaries.");
+ } else {
+ Log.err("Fail to remove downloaded package binaries.");
+ }
+ }
+
+ /**
+ * Package uninstallation management
+ *
+ * @param pkg
+ * @param monitor
+ * @return
+ */
+ public boolean removePackage(Package pkg, IIMProgressMonitor monitor) {
+ Log.log("InstallManager package remove start => " + pkg);
-
++
+ if (pkg == null) {
+ return false;
+ }
-
++
+ if (monitor != null) {
+ monitor.workedTitle(pkg.getPackageName());
+ }
-
++
+ if (Options.doRemoveNoUI || Options.doInstallNoUI) {
+ System.out.println(pkg.getPackageName() + " is uninstalling...");
+ }
+
- Installer installer = new Installer();
-
- boolean bResult = installer.uninstall(pkg, monitor);
++ boolean bResult = false;
++ if (packageManager.isInstalledPackage(pkg)) {
++ Installer installer = new Installer();
+
++ bResult = installer.uninstall(pkg, monitor);
++ } else {
++ bResult = true;
++ }
++
+ // Remove packages in installed package list without result.
+ // We don't know that failed packages are working well.
+ packageManager.exceptPackageFromInstalledPackages(pkg);
- packageManager.saveInstalledList(PathUtil.get(
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
- Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
++ packageManager.saveInstalledList();
+
+ Log.log(pkg + " remove end => " + bResult);
+ return bResult;
+ }
+
+ /**
+ * Packages uninstallation management
+ *
+ * @param pkg
+ * @param monitor
+ * @return
+ */
+ public boolean removePackages(PackageSet metasToRemove,
+ IIMProgressMonitor monitor) {
+ Log.log("InstallManager Packages remove Start => " + metasToRemove);
+
+ if (metasToRemove == null) {
+ return false;
+ }
+
- PackageSet pkgsToRemove = packageManager.getToRemovePackagesInRemove(metasToRemove);
-
++ PackageSet pkgsToRemove = packageManager
++ .getToRemovePackagesInRemove(metasToRemove);
++
+ Log.log("Remove packages: " + pkgsToRemove);
+
+ if (monitor != null) {
+ monitor.beginTask("Uninstalling...", pkgsToRemove.size() + 1);
+ }
+
+ int i = 0;
+ for (Package pkg : pkgsToRemove) {
+ if (monitor != null) {
- monitor.workedProcess(pkg.getPackageName());
++ monitor.workedDownloadProgress(pkg.getPackageName(), 1);
+ monitor.worked(++i);
+ }
+
+ if (removePackage(pkg, monitor)) {
+ continue;
+ } else {
+ Log.log("Remove fail but make progress=> " + pkg);
+ }
+ }
+
+ // if you remove all packages, delete targetDirectory and config File.
+ if (!packageManager.existInstalledMetaPackages()) {
+ Log.log("Installed meta packages do not exist");
+ if (monitor != null) {
- monitor.workedSubTitle("Remove target directory...");
++ monitor.workedDownloadProgress("Remove target directory...", 0);
+ monitor.worked(pkgsToRemove.size());
+ }
+
+ if (packageManager.existInstalledPackages()) {
+ Log.log("Installed meta packages do not exist, but some packages exist.");
+ removeAll(monitor);
+ } else {
+ // not exist to remove
+ removeSDK(monitor);
+ }
+ }
+
+ Log.log("InstallManager packages remove success. return => " + true);
+ return true;
+ }
-
++
+ /**
+ * Remove all of packages.
+ *
+ * @param monitor
+ */
+ public void removeAll(IIMProgressMonitor monitor) {
+ Log.log("InstallManager.removeAll()");
+
+ removeAllPackages(monitor);
+ removeSDK(monitor);
+ }
-
++
+ private void removeAllPackages(IIMProgressMonitor monitor) {
+ Log.log("Remove all packages.");
-
- if (monitor != null) {
- monitor.workedTitle(REMOVE_ALL_PACKAGES);
- }
-
++
+ PackageSet removablePackages = packageManager.getInstalledPackages();
+
+ for (Package pkg : removablePackages) {
+ if (!removePackage(pkg, monitor)) {
+ Log.err("InstallManager.removeAll remove fail => " + pkg);
+ }
+ }
+ }
+
+ /**
+ * Remove All of TizenSDK files.
+ */
+ public void removeSDK(IIMProgressMonitor monitor) {
+ Log.log("InstallManager removeSDK start");
-
++
+ if (monitor != null) {
+ monitor.workedTitle(REMOVE_ALL_SDK_FILES);
+ }
+
+ removeInstallManager();
+ removeShortcutMenu();
+ removeChangeLog();
+ removeInfoDirectory();
+ checkTargetDirAndRemove();
-// Registry.removeRegistry();
++ // Registry.removeRegistry();
+ if (Config.isSupportMultiSDK()) {
- Registry.removeMultiSDKInfo(Config.getSelectedSDKPath());
++ Registry.removeMultiSDKInfo(Config.getSelectedSDKPath());
+ } else {
+ Registry.removeMultiSDKInfo(Registry.getInstalledPath());
+ }
+
-
+ // do not remove config home because it has log files
+ Log.log("InstallManager removeSDK end");
+ }
+
+ private void checkTargetDirAndRemove() {
+ File targetDir = new File(Registry.getInstalledPath());
+ if (canRemoveTargetDir(targetDir)) {
+ removeTargetDirectory();
+ } else {
+ Log.err("Cannot delete target directory => "
+ + targetDir.getAbsolutePath());
+ }
+ }
+
+ /**
+ * Check status that target directory can remove or not.
+ *
+ * @param targetDir
+ * @return
+ */
+ private boolean canRemoveTargetDir(File targetDir) {
+ if (targetDir.exists()) {
+ File[] fileList = targetDir.listFiles();
+ if ((fileList == null || fileList.length <= 0)
+ || (fileList.length == 1 && fileList[0].getName().equals(
+ Config.OLD_INSTALL_MANAGER_DIRECTORY))) {
+ return true;
+ } else {
+ ArrayList<String> fileNames = new ArrayList<String>();
+ for (File file : fileList) {
+ fileNames.add(file.getName());
+ }
+ Log.err("The SDK directory is not empty => " + fileNames);
+ return false;
+ }
+ } else {
+ Log.err("The SDK direcotry is already removed");
+ return false;
+ }
+ }
+
+ private void removeChangeLog() {
+ File releaseNoteFile = new File(
+ PathUtil.getFromInstalledPath(Config.RELEASE_NOTE));
+
+ if (releaseNoteFile.exists()) {
+ PathUtil.remove(releaseNoteFile);
+ }
+ }
+
+ private void removeInfoDirectory() {
+ // remove info directory in $HOME/tizen-sdk-data
+ File infoDirFile = new File(
+ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));
+ if (infoDirFile.exists()) {
+ PathUtil.remove(infoDirFile);
+ }
+
+ // remove info directory in target directory
+ File targetInfoFile = new File(
+ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));
+
+ if (targetInfoFile.exists()) {
+ PathUtil.remove(targetInfoFile);
+ }
+ }
+
+ /**
+ * Remove target directory.
+ */
+ public void removeTargetDirectory() {
+ Log.log("InstallManager remove target directory start");
+
+ if (Platform.CURRENT_PLATFORM == Platform.LINUX_32
+ || Platform.CURRENT_PLATFORM == Platform.LINUX_64
+ || Platform.CURRENT_PLATFORM == Platform.MACOS_64) {
+ PathUtil.remove(Registry.getInstalledPath());
+ } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32
+ || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {
+ if (!WindowsProgramController.removeRunningDir(Registry
+ .getInstalledPath())) {
+ Log.err("Cannot remove target directory");
+ }
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+
+ Log.log("InstallManager remove target directory end");
+ }
+
+ /**
+ * Singleton and global downloader shared and used by every components in IM
+ *
+ * @return singleton downloader object
+ */
+ public static Downloader getDownloader() {
+ return InstallManager.mDownloader;
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.core;\r
- \r
- import java.io.BufferedReader;\r
- import java.io.File;\r
- import java.io.FileInputStream;\r
- import java.io.FileNotFoundException;\r
- import java.io.FileReader;\r
- import java.io.IOException;\r
- import java.io.InputStream;\r
- import java.io.InputStreamReader;\r
- import java.util.HashMap;\r
- import java.util.LinkedList;\r
- import java.util.List;\r
- import java.util.Map;\r
- import java.util.Stack;\r
- \r
- import org.tizen.installmanager.lib.ErrorController;\r
- import org.tizen.installmanager.lib.ErrorController.InfoCode;\r
- import org.tizen.installmanager.lib.IIMProgressMonitor;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.LoggerShellParser;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.Registry;\r
- import org.tizen.installmanager.lib.SDKPackageFormat;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.pkg.model.Package;\r
- import org.tizen.installmanager.util.IMShellCommandFail;\r
- import org.tizen.installmanager.util.PathUtil;\r
- import org.tizen.installmanager.util.ShellUtil;\r
- \r
- /**\r
- * This class manages lowlevel install/uninstall operations\r
- * \r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- */\r
- public class Installer {\r
- /**\r
- * Install a package to target directory.\r
- * \r
- * @param pack\r
- * Package to be installed.\r
- * @param targetDir\r
- * Target directory to install.\r
- * @param monitor\r
- * If you want to express in UI, implement IIMProgressMonitor and\r
- * set this parametor. if not, set <code>null</code>.\r
- * @return <code>true</code>, if installation is success.\r
- */\r
- public boolean install(Package pack, String targetDir,\r
- IIMProgressMonitor monitor) {\r
- Log.log("**** installer install start => " + pack + ", target => " + targetDir);\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress(pack.getPackageName(), 1);\r
- }\r
- \r
- // unzip in temp dir\r
- String tempDir = PathUtil.get(targetDir, Config.TEMP_DIRECTORY);\r
- \r
- // Clear temp dir before unzip package.\r
- File tmpDir = new File(tempDir);\r
- \r
- if (tmpDir.exists()) {\r
- if (!tmpDir.delete()) {\r
- Log.err("Fail to delete " + tmpDir);\r
- }\r
- }\r
- \r
- long unZipSize = unZipPackage(pack, tempDir, monitor);\r
- \r
- if (unZipSize <= 0) {\r
- Log.err("Unzip failed. => " + pack);\r
- PathUtil.remove(tempDir);\r
- throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
- }\r
- if (!checkUnzipSize(pack, unZipSize)) {\r
- Log.err("Unzip size error. => " + pack);\r
- PathUtil.remove(tempDir);\r
- throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
- }\r
- \r
- if (!moveToTargetDirectoryFromTempDirectory(tempDir, targetDir)) {\r
- PathUtil.remove(tempDir);\r
- Log.err("Moving temp to target failed. Remove temp and cancel installing.");\r
- throw new IMFatalException(\r
- ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);\r
- }\r
- \r
- List<File> missingFiles = findMissingFiles(pack, monitor);\r
- if (missingFiles.size() > 0) {\r
- Log.err("Some files are not moved properly: " + missingFiles);\r
- throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);\r
- } else {\r
- Log.log("All files moved properly.");\r
- }\r
- \r
- if (!executeInstallScript(pack, monitor, tempDir)) {\r
- Log.err("Fail to execute install script.");\r
- PathUtil.remove(tempDir);\r
- throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)\r
- + " (" + pack + " package)");\r
- }\r
- \r
- if (!moveRemoveScript(tempDir, pack)) {\r
- PathUtil.remove(tempDir);\r
- return false;\r
- }\r
- \r
- PathUtil.remove(tempDir);\r
- return true;\r
- }\r
- \r
- private boolean moveRemoveScript(String tempDir, Package pack) {\r
- // move removeScript file to special Directory\r
- File removeScriptFrom = new File(tempDir + File.separator\r
- + pack.getRemoveScript());\r
- \r
- if ((pack.getRemoveScript() != null)\r
- && !(pack.getRemoveScript().equals(""))\r
- && (removeScriptFrom.exists())) {\r
- File removeScriptTo = new File(getRemoveScriptLocalPath(pack));\r
- if (!createRemoveScriptDir(removeScriptTo)) {\r
- Log.err("Cannot create remove script directory in Info directory => "\r
- + pack.getPackageName());\r
- return false;\r
- } else {\r
- if (removeScriptTo.exists()) {\r
- if (!removeScriptTo.delete()) {\r
- Log.err("Fail to delete file ==> " + removeScriptTo);\r
- }\r
- }\r
- if (!PathUtil.moveFile(removeScriptFrom, removeScriptTo)) {\r
- Log.err("Cannot move removeScript to targetDir => "\r
- + pack.getPackageName());\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
- \r
- // private boolean moveInstallScript(String tempDir, Package pack) {\r
- // // move removeScript file to special Directory\r
- // File installScriptFrom = new File(tempDir + File.separator\r
- // + pack.getInstallScript());\r
- //\r
- // if ((pack.getInstallScript() != null)\r
- // && !(pack.getInstallScript().equals(""))\r
- // && (installScriptFrom.exists())) {\r
- // File installScriptTo = new File(getInstallScriptLocalPath(pack));\r
- // if (!createInstallScriptDir(installScriptTo)) {\r
- // Log.err("Cannot create install script directory in Info directory => "\r
- // + pack.getPackageName());\r
- // return false;\r
- // } else {\r
- // if (installScriptTo.exists()) {\r
- // if (!installScriptTo.delete()) {\r
- // Log.err("Fail to delete file ==> " + installScriptTo);\r
- // }\r
- // }\r
- // if (!PathUtil.moveFile(installScriptFrom, installScriptTo)) {\r
- // Log.err("Cannot move install Script to targetDir => "\r
- // + pack.getPackageName());\r
- // return false;\r
- // }\r
- // }\r
- // }\r
- // return true;\r
- // }\r
- \r
- /**\r
- * @param pack\r
- * @return list of files which are not moved normally\r
- */\r
- private List<File> findMissingFiles(Package pack, IIMProgressMonitor monitor) {\r
- LinkedList<File> missingFiles = new LinkedList<File>();\r
- \r
- if (pack == null) {\r
- return missingFiles;\r
- }\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Verify that the file exists", 0);\r
- }\r
- \r
- File listFile = new File(getInstalledFileListPath(pack));\r
- InputStream is = null;\r
- BufferedReader in = null;\r
- try {\r
- is = new FileInputStream(listFile);\r
- in = new BufferedReader(new InputStreamReader(is, "UTF-8"));\r
- String line;\r
- while ((line = in.readLine()) != null) {\r
- File tmp = new File(PathUtil.getFromInstalledPath(line));\r
- if (!tmp.exists()) {\r
- if (Platform.isWindows()) {\r
- missingFiles.add(tmp);\r
- } else if (Platform.isLinux() || Platform.isMacOS()) {\r
- // check if it is broken link\r
- try {\r
- int exitCode = ShellUtil.execute("ls " + tmp, null);\r
- if (exitCode == 0) {\r
- Log.log("broken link " + tmp\r
- + " but no problem");\r
- } else {\r
- Log.err(tmp + " not exist.");\r
- missingFiles.add(tmp);\r
- }\r
- } catch (IMShellCommandFail e) {\r
- Log.err("Failed to check file exists");\r
- Log.ExceptionLog(e);\r
- }\r
- } else {\r
- throw new IMFatalException(\r
- ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- }\r
- }\r
- } catch (IOException e) {\r
- Log.err("Installer.findMissingFiles() Cannot check file list: "\r
- + listFile.getAbsolutePath());\r
- throw new IMFatalException(\r
- ErrorCode.CANNOT_CHECK_INSTLLED_FILE_LIST);\r
- } finally {\r
- if (in != null) {\r
- try {\r
- in.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- if (is != null) {\r
- try {\r
- is.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- return missingFiles;\r
- }\r
- \r
- /**\r
- * Set script running process' environment variables.\r
- * \r
- * @return Environment variables map\r
- */\r
- private Map<String, String> setEnvironmentVariable() {\r
- HashMap<String, String> env = new HashMap<String, String>();\r
- \r
- env.put("INSTALLED_PATH", Registry.getInstalledPath());\r
- env.put("SDK_DATA_PATH", Registry.sdkDataPath);\r
- env.put("USER_DATA_PATH", Registry.sdkDataPath);\r
- env.put("MAKESHORTCUT_PATH", InstallManager.getInstance().getMakeShortCutPath());\r
- env.put("REMOVE_SHORTCUT", InstallManager.getInstance().getRemoveShortCutPath());\r
- env.put("TSUDO", InstallManager.getInstance().getTSudoPath());\r
- \r
- if (Options.doInstallNoUI || Options.doRemoveNoUI){\r
- env.put("INSTALLMANAGER_UI", "CLI");\r
- } else {\r
- env.put("INSTALLMANAGER_UI", "GUI");\r
- }\r
- \r
- if (Options.interactive) {\r
- env.put("INTERACTIVE", "true");\r
- } else {\r
- env.put("INTERACTIVE", "false");\r
- env.put("SUPASS", Options.suPass);\r
- }\r
- \r
- return env;\r
- }\r
- \r
- private long unZipPackage(Package pkg, String tempDir,\r
- IIMProgressMonitor monitor) {\r
- String filePath = InstallManager.getInstance().getDownloadTargetPath(pkg);\r
- \r
- File pkgFile = new File(filePath);\r
- if (!pkgFile.exists()) {\r
- Log.err(filePath + " doesn't exist");\r
- throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_LOCAL);\r
- }\r
- \r
- SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();\r
- \r
- // Each packages are saved installed list to file\r
- String installedFileListPath = getInstalledFileListPath(pkg);\r
- \r
- format.setFileOutput(installedFileListPath);\r
- \r
- return format.unZip(filePath, tempDir, monitor);\r
- }\r
- \r
- private String getRemoveScriptLocalPath(Package pkg) {\r
- return PathUtil.get(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
- pkg.getPackageName(), pkg.getRemoveScript());\r
- }\r
- \r
- private String getInstalledFileListPath(Package pkg) {\r
- return PathUtil.get(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
- pkg.getPackageName(), (pkg.getPackageName() + ".list"));\r
- }\r
- \r
- private boolean moveToTargetDirectoryFromTempDirectory(String tempDir,\r
- String targetDir) {\r
- Log.log("Move temp to target");\r
- File fromFile = new File(tempDir + File.separator\r
- + Config.DATA_DIRECTORY);\r
- if (!fromFile.exists()) {\r
- Log.err("Data directory is not exist in package.");\r
- return true;\r
- }\r
- File toFile = new File(targetDir);\r
- \r
- File[] fromList = fromFile.listFiles();\r
- \r
- if (fromList == null) {\r
- return false;\r
- }\r
- \r
- for (int i = 0; i < fromList.length; i++) {\r
- boolean ret = false;\r
- if (Platform.isLinux()) {\r
- ret = PathUtil.copyHardLink(fromList[i], toFile);\r
- } else if (Platform.isWindows()) {\r
- ret = PathUtil.move(fromList[i],\r
- new File(toFile, fromList[i].getName()));\r
- } else if (Platform.isMacOS()) {\r
- ret = PathUtil.copyHardLink(fromList[i], toFile);\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- if (!ret) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- \r
- /**\r
- * Uninstalls the given package\r
- * \r
- * @param pkg\r
- * package to be uninstalled\r
- * @param monitor\r
- * @return true if success. false if fatal error. delete failure is checked\r
- * and sets error status in ErrorController but still returns true.\r
- * if file to be deleted doesn't exist, it's not considered error.\r
- */\r
- public boolean uninstall(Package pkg, IIMProgressMonitor monitor) {\r
- Log.log("Installer uninstall start");\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Remove the " + pkg.getPackageName(), 1);\r
- }\r
- \r
- int resultRemoveScript = executeRemoveScript(pkg, monitor);\r
- \r
- if (resultRemoveScript == 0) {\r
- Log.log("Execute remove script success.");\r
- } else if (resultRemoveScript == 1) {\r
- Log.err("Execute remove script fail.");\r
- } else if (resultRemoveScript == 2) {\r
- Log.log("This package does not need a remove script.");\r
- }\r
- \r
- File installedFileList = new File(getInstalledFileListPath(pkg));\r
- \r
- if (!installedFileList.exists()) {\r
- ErrorController.setError(ErrorCode.CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST);\r
- return false;\r
- }\r
- \r
- BufferedReader reader = null;\r
- try {\r
- reader = new BufferedReader(new FileReader(installedFileList));\r
- \r
- String line = null;\r
- Stack<File> dirStack = new Stack<File>();\r
- while ((line = reader.readLine()) != null) {\r
- File deleteFile = new File(PathUtil.getFromInstalledPath(line));\r
- \r
- if (deleteFile.isDirectory()) {\r
- File[] listFiles = deleteFile.listFiles();\r
- \r
- if (listFiles == null || listFiles.length <= 0) {\r
- deleteIfExists(deleteFile);\r
- } else {\r
- dirStack.push(deleteFile);\r
- }\r
- } else {\r
- deleteIfExists(deleteFile);\r
- }\r
- }\r
- \r
- while (!dirStack.isEmpty()) {\r
- File deleteDir = dirStack.pop();\r
- File[] listFiles = deleteDir.listFiles();\r
- \r
- if (listFiles == null || listFiles.length <= 0) {\r
- deleteIfExists(deleteDir);\r
- }\r
- }\r
- \r
- } catch (FileNotFoundException e) {\r
- Log.err("File not found => " + installedFileList.getAbsolutePath());\r
- return false;\r
- } catch (IOException e) {\r
- Log.err("IO Exception => " + installedFileList.getAbsolutePath());\r
- return false;\r
- } catch (Throwable e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- } finally {\r
- try {\r
- if (reader != null) {\r
- reader.close();\r
- deleteIfExists(installedFileList);\r
- }\r
- } catch (IOException ioe) {\r
- Log.err("Close fileoutput fail.");\r
- }\r
- }\r
- \r
- return true;\r
- }\r
- \r
- /**\r
- * Delete the <code>file</code>\r
- * \r
- * @param file\r
- */\r
- private void deleteIfExists(File file) {\r
- if (!file.delete()) {\r
- Log.err("Delete fail -> " + file.getAbsolutePath());\r
- }\r
- }\r
- \r
- private boolean checkUnzipSize(Package pack, long size) {\r
- // TODO : impl. not supported\r
- return true;\r
- }\r
- \r
- private boolean createRemoveScriptDir(File removeScript) {\r
- File parentDir = removeScript.getParentFile();\r
- \r
- if (!parentDir.exists()) {\r
- return parentDir.mkdirs();\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- private boolean executeInstallScript(Package pack,\r
- IIMProgressMonitor monitor, String tempDir) {\r
- if (pack.getInstallScript() != null\r
- && !pack.getInstallScript().equals("")) {\r
- String command = PathUtil.get(tempDir, pack.getInstallScript());\r
- File scriptFile = new File(command);\r
- \r
- if (scriptFile.exists()) {\r
- Log.log("Execute " + pack.getPackageName() + " install script");\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Execute the " + pack.getPackageName() + " install script", 0);\r
- }\r
- try {\r
- return executeScript(scriptFile);\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)\r
- + " (" + pack + " package)");\r
- }\r
- } else {\r
- Log.log(pack.getPackageName() + " does not have install script");\r
- }\r
- }\r
- return true;\r
- }\r
- \r
- private int executeRemoveScript(Package pkg, IIMProgressMonitor monitor) {\r
- Log.log("executeRemoveScript => " + pkg.getRemoveScript());\r
- \r
- // execute remove script\r
- String script = PathUtil.get(getRemoveScriptLocalPath(pkg));\r
- File scriptFile = new File(script);\r
- \r
- if (scriptFile.exists()) {\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Excute the " + pkg.getPackageName() + " remove script", 0);\r
- }\r
- \r
- try {\r
- if (executeScript(scriptFile)) {\r
- return 0; // succeed to execute remove script.\r
- } else {\r
- return 1; // fail to execute remove script.\r
- }\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorController.getMessage(ErrorCode.REMOVE_SCRIPT_FATAL_ERROR)\r
- + " (" + pkg + " package)");\r
- }\r
- }\r
- return 2; // package does not need remove script.\r
- }\r
- \r
- /**\r
- * Executes the file with default environment variables\r
- * \r
- * @param scriptFile\r
- * @return <code>true</code> if success\r
- * @throws IMShellCommandFail\r
- */\r
- public boolean executeScript(File scriptFile) throws IMShellCommandFail {\r
- scriptFile.setExecutable(true);\r
- Map<String, String> env = setEnvironmentVariable();\r
- \r
- String command = ShellUtil.addInterpreter(scriptFile.getAbsolutePath());\r
- \r
- String current = PathUtil.getCurrentDir();\r
- Log.log("Current working directory. => " + current);\r
- int exitCode = ShellUtil.execute(command, env, new File(current),\r
- new LoggerShellParser());\r
- \r
- // check exit code\r
- if (exitCode == 0) {\r
- return true;\r
- } else if (exitCode == 1 || exitCode == 2) {\r
- Log.err("Exit code => " + Integer.toString(exitCode));\r
- return false;\r
- } else if (exitCode == 99) {\r
- ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);\r
- Log.log("Set restart message.");\r
- return true;\r
- } else {\r
- Log.err("Installer.executeScript() install script error => "\r
- + scriptFile.getAbsolutePath());\r
- Log.err("Exit code => " + Integer.toString(exitCode));\r
- throw new IMFatalException(ErrorController.getMessage(ErrorCode.SCRIPT_FATAL_ERROR)\r
- + " (" + scriptFile.getParentFile().getName() + " package)");\r
- }\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.core;
+
+ import java.io.BufferedReader;
+ import java.io.File;
+ import java.io.FileInputStream;
+ import java.io.FileNotFoundException;
+ import java.io.FileReader;
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.InputStreamReader;
+ import java.util.HashMap;
+ import java.util.LinkedList;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Stack;
+
+ import org.tizen.installmanager.lib.ErrorController;
+ import org.tizen.installmanager.lib.ErrorController.InfoCode;
+ import org.tizen.installmanager.lib.IIMProgressMonitor;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.lib.LoggerShellParser;
+ import org.tizen.installmanager.lib.Platform;
+ import org.tizen.installmanager.lib.Registry;
+ import org.tizen.installmanager.lib.SDKPackageFormat;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.pkg.model.Package;
+ import org.tizen.installmanager.util.IMShellCommandFail;
+ import org.tizen.installmanager.util.PathUtil;
+ import org.tizen.installmanager.util.ShellUtil;
+
+ /**
+ * This class manages lowlevel install/uninstall operations
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ */
+ public class Installer {
+ /**
+ * Install a package to target directory.
+ *
+ * @param pack
+ * Package to be installed.
+ * @param targetDir
+ * Target directory to install.
+ * @param monitor
+ * If you want to express in UI, implement IIMProgressMonitor and
+ * set this parametor. if not, set <code>null</code>.
+ * @return <code>true</code>, if installation is success.
+ */
+ public boolean install(Package pack, String targetDir,
+ IIMProgressMonitor monitor) {
+ Log.log("**** installer install start => " + pack + ", target => " + targetDir);
+
++ if (monitor != null) {
++ monitor.workedInstallProgress(pack.getPackageName(), 1);
++ }
++
+ // unzip in temp dir
+ String tempDir = PathUtil.get(targetDir, Config.TEMP_DIRECTORY);
+
+ // Clear temp dir before unzip package.
+ File tmpDir = new File(tempDir);
+
+ if (tmpDir.exists()) {
+ if (!tmpDir.delete()) {
+ Log.err("Fail to delete " + tmpDir);
+ }
+ }
+
+ long unZipSize = unZipPackage(pack, tempDir, monitor);
+
+ if (unZipSize <= 0) {
+ Log.err("Unzip failed. => " + pack);
+ PathUtil.remove(tempDir);
+ throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
+ }
+ if (!checkUnzipSize(pack, unZipSize)) {
+ Log.err("Unzip size error. => " + pack);
+ PathUtil.remove(tempDir);
+ throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
+ }
+
+ if (!moveToTargetDirectoryFromTempDirectory(tempDir, targetDir)) {
+ PathUtil.remove(tempDir);
+ Log.err("Moving temp to target failed. Remove temp and cancel installing.");
+ throw new IMFatalException(
+ ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
+ }
+
- List<File> missingFiles = findMissingFiles(pack);
++ List<File> missingFiles = findMissingFiles(pack, monitor);
+ if (missingFiles.size() > 0) {
+ Log.err("Some files are not moved properly: " + missingFiles);
-// throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);
++ throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);
+ } else {
+ Log.log("All files moved properly.");
+ }
+
+ if (!executeInstallScript(pack, monitor, tempDir)) {
+ Log.err("Fail to execute install script.");
++ PathUtil.remove(tempDir);
+ throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)
+ + " (" + pack + " package)");
+ }
+
+ if (!moveRemoveScript(tempDir, pack)) {
++ PathUtil.remove(tempDir);
+ return false;
+ }
+
-// if (!moveInstallScript(tempDir, pack)) {
-// return false;
-// }
-
+ PathUtil.remove(tempDir);
+ return true;
+ }
+
+ private boolean moveRemoveScript(String tempDir, Package pack) {
+ // move removeScript file to special Directory
+ File removeScriptFrom = new File(tempDir + File.separator
+ + pack.getRemoveScript());
+
+ if ((pack.getRemoveScript() != null)
+ && !(pack.getRemoveScript().equals(""))
+ && (removeScriptFrom.exists())) {
+ File removeScriptTo = new File(getRemoveScriptLocalPath(pack));
+ if (!createRemoveScriptDir(removeScriptTo)) {
+ Log.err("Cannot create remove script directory in Info directory => "
+ + pack.getPackageName());
+ return false;
+ } else {
+ if (removeScriptTo.exists()) {
+ if (!removeScriptTo.delete()) {
+ Log.err("Fail to delete file ==> " + removeScriptTo);
+ }
+ }
+ if (!PathUtil.moveFile(removeScriptFrom, removeScriptTo)) {
+ Log.err("Cannot move removeScript to targetDir => "
+ + pack.getPackageName());
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // private boolean moveInstallScript(String tempDir, Package pack) {
+ // // move removeScript file to special Directory
+ // File installScriptFrom = new File(tempDir + File.separator
+ // + pack.getInstallScript());
+ //
+ // if ((pack.getInstallScript() != null)
+ // && !(pack.getInstallScript().equals(""))
+ // && (installScriptFrom.exists())) {
+ // File installScriptTo = new File(getInstallScriptLocalPath(pack));
+ // if (!createInstallScriptDir(installScriptTo)) {
+ // Log.err("Cannot create install script directory in Info directory => "
+ // + pack.getPackageName());
+ // return false;
+ // } else {
+ // if (installScriptTo.exists()) {
+ // if (!installScriptTo.delete()) {
+ // Log.err("Fail to delete file ==> " + installScriptTo);
+ // }
+ // }
+ // if (!PathUtil.moveFile(installScriptFrom, installScriptTo)) {
+ // Log.err("Cannot move install Script to targetDir => "
+ // + pack.getPackageName());
+ // return false;
+ // }
+ // }
+ // }
+ // return true;
+ // }
+
+ /**
+ * @param pack
+ * @return list of files which are not moved normally
+ */
- private List<File> findMissingFiles(Package pack) {
++ private List<File> findMissingFiles(Package pack, IIMProgressMonitor monitor) {
+ LinkedList<File> missingFiles = new LinkedList<File>();
++
++ if (pack == null) {
++ return missingFiles;
++ }
++
++ if (monitor != null) {
++ monitor.workedInstallProgress("Verify that the file exists", 0);
++ }
++
+ File listFile = new File(getInstalledFileListPath(pack));
+ InputStream is = null;
+ BufferedReader in = null;
+ try {
+ is = new FileInputStream(listFile);
+ in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ String line;
+ while ((line = in.readLine()) != null) {
+ File tmp = new File(PathUtil.getFromInstalledPath(line));
+ if (!tmp.exists()) {
+ if (Platform.isWindows()) {
+ missingFiles.add(tmp);
+ } else if (Platform.isLinux() || Platform.isMacOS()) {
+ // check if it is broken link
+ try {
+ int exitCode = ShellUtil.execute("ls " + tmp, null);
+ if (exitCode == 0) {
+ Log.log("broken link " + tmp
+ + " but no problem");
+ } else {
+ Log.err(tmp + " not exist.");
+ missingFiles.add(tmp);
+ }
+ } catch (IMShellCommandFail e) {
+ Log.err("Failed to check file exists");
+ Log.ExceptionLog(e);
+ }
+ } else {
+ throw new IMFatalException(
+ ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ }
+ }
+ } catch (IOException e) {
+ Log.err("Installer.findMissingFiles() Cannot check file list: "
+ + listFile.getAbsolutePath());
+ throw new IMFatalException(
+ ErrorCode.CANNOT_CHECK_INSTLLED_FILE_LIST);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+ return missingFiles;
+ }
+
+ /**
+ * Set script running process' environment variables.
+ *
+ * @return Environment variables map
+ */
+ public Map<String, String> setEnvironmentVariable() {
+ HashMap<String, String> env = new HashMap<String, String>();
+
+ env.put("INSTALLED_PATH", Registry.getInstalledPath());
+ env.put("SDK_DATA_PATH", Registry.sdkDataPath);
+ env.put("USER_DATA_PATH", Registry.sdkDataPath);
+ env.put("MAKESHORTCUT_PATH", InstallManager.getInstance().getMakeShortCutPath());
+ env.put("REMOVE_SHORTCUT", InstallManager.getInstance().getRemoveShortCutPath());
+ env.put("TSUDO", InstallManager.getInstance().getTSudoPath());
+
+ if (Options.doInstallNoUI || Options.doRemoveNoUI){
+ env.put("INSTALLMANAGER_UI", "CLI");
+ } else {
+ env.put("INSTALLMANAGER_UI", "GUI");
+ }
+
+ if (Options.interactive) {
+ env.put("INTERACTIVE", "true");
+ } else {
+ env.put("INTERACTIVE", "false");
+ env.put("SUPASS", Options.suPass);
+ }
+
+ return env;
+ }
+
+ private long unZipPackage(Package pkg, String tempDir,
+ IIMProgressMonitor monitor) {
- String filePath = PathUtil.get(Config.getInstance().getDownloadPkgPath(), pkg.getFileName());
-
++ String filePath = InstallManager.getInstance().getDownloadTargetPath(pkg);
++
+ File pkgFile = new File(filePath);
+ if (!pkgFile.exists()) {
+ Log.err(filePath + " doesn't exist");
+ throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_LOCAL);
+ }
+
+ SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();
+
+ // Each packages are saved installed list to file
+ String installedFileListPath = getInstalledFileListPath(pkg);
+
+ format.setFileOutput(installedFileListPath);
+
+ return format.unZip(filePath, tempDir, monitor);
+ }
+
+ private String getRemoveScriptLocalPath(Package pkg) {
+ return PathUtil.get(
+ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
+ pkg.getPackageName(), pkg.getRemoveScript());
+ }
+
+ private String getInstalledFileListPath(Package pkg) {
+ return PathUtil.get(
+ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
+ pkg.getPackageName(), (pkg.getPackageName() + ".list"));
+ }
+
+ private boolean moveToTargetDirectoryFromTempDirectory(String tempDir,
+ String targetDir) {
+ Log.log("Move temp to target");
+ File fromFile = new File(tempDir + File.separator
+ + Config.DATA_DIRECTORY);
+ if (!fromFile.exists()) {
+ Log.err("Data directory is not exist in package.");
+ return true;
+ }
+ File toFile = new File(targetDir);
+
+ File[] fromList = fromFile.listFiles();
+
+ if (fromList == null) {
+ return false;
+ }
+
+ for (int i = 0; i < fromList.length; i++) {
+ boolean ret = false;
+ if (Platform.isLinux()) {
+ ret = PathUtil.copyHardLink(fromList[i], toFile, false);
+ } else if (Platform.isWindows()) {
+ ret = PathUtil.move(fromList[i],
+ new File(toFile, fromList[i].getName()));
+ } else if (Platform.isMacOS()) {
+ ret = PathUtil.copyHardLink(fromList[i], toFile, false);
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ if (!ret) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Uninstalls the given package
+ *
+ * @param pkg
+ * package to be uninstalled
+ * @param monitor
+ * @return true if success. false if fatal error. delete failure is checked
+ * and sets error status in ErrorController but still returns true.
+ * if file to be deleted doesn't exist, it's not considered error.
+ */
+ public boolean uninstall(Package pkg, IIMProgressMonitor monitor) {
+ Log.log("Installer uninstall start");
++
++ if (monitor != null) {
++ monitor.workedInstallProgress("Remove the " + pkg.getPackageName(), 1);
++ }
++
+ int resultRemoveScript = executeRemoveScript(pkg, monitor);
+
+ if (resultRemoveScript == 0) {
+ Log.log("Execute remove script success.");
+ } else if (resultRemoveScript == 1) {
+ Log.err("Execute remove script fail.");
+ } else if (resultRemoveScript == 2) {
+ Log.log("This package does not need a remove script.");
+ }
+
+ File installedFileList = new File(getInstalledFileListPath(pkg));
+
+ if (!installedFileList.exists()) {
+ ErrorController.setError(ErrorCode.CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST);
+ return false;
+ }
+
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(installedFileList));
+
+ String line = null;
+ Stack<File> dirStack = new Stack<File>();
+ while ((line = reader.readLine()) != null) {
+ File deleteFile = new File(PathUtil.getFromInstalledPath(line));
+
+ if (deleteFile.isDirectory()) {
+ File[] listFiles = deleteFile.listFiles();
+
+ if (listFiles == null || listFiles.length <= 0) {
+ deleteIfExists(deleteFile);
+ } else {
+ dirStack.push(deleteFile);
+ }
+ } else {
+ deleteIfExists(deleteFile);
+ }
+ }
+
+ while (!dirStack.isEmpty()) {
+ File deleteDir = dirStack.pop();
+ File[] listFiles = deleteDir.listFiles();
+
+ if (listFiles == null || listFiles.length <= 0) {
+ deleteIfExists(deleteDir);
+ }
+ }
+
+ } catch (FileNotFoundException e) {
+ Log.err("File not found => " + installedFileList.getAbsolutePath());
+ return false;
+ } catch (IOException e) {
+ Log.err("IO Exception => " + installedFileList.getAbsolutePath());
+ return false;
+ } catch (Throwable e) {
+ Log.ExceptionLog(e);
+ return false;
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ deleteIfExists(installedFileList);
+ }
+ } catch (IOException ioe) {
+ Log.err("Close fileoutput fail.");
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Delete the <code>file</code>
+ *
+ * @param file
+ */
+ private void deleteIfExists(File file) {
+ if (!file.delete()) {
+ Log.err("Delete fail -> " + file.getAbsolutePath());
+ }
+ }
+
+ private boolean checkUnzipSize(Package pack, long size) {
+ // TODO : impl. not supported
+ return true;
+ }
+
+ private boolean createRemoveScriptDir(File removeScript) {
+ File parentDir = removeScript.getParentFile();
+
+ if (!parentDir.exists()) {
+ return parentDir.mkdirs();
+ } else {
+ return true;
+ }
+ }
+
+ private boolean executeInstallScript(Package pack,
+ IIMProgressMonitor monitor, String tempDir) {
+ if (pack.getInstallScript() != null
+ && !pack.getInstallScript().equals("")) {
+ String command = PathUtil.get(tempDir, pack.getInstallScript());
+ File scriptFile = new File(command);
+
+ if (scriptFile.exists()) {
- Log.log("Execute install script");
++ Log.log("Execute " + pack.getPackageName() + " install script");
+
+ if (monitor != null) {
- monitor.workedSubTitle(scriptFile.getName());
++ monitor.workedInstallProgress("Execute the " + pack.getPackageName() + " install script", 0);
+ }
+ try {
+ return executeScript(scriptFile);
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)
+ + " (" + pack + " package)");
+ }
+ } else {
+ Log.log(pack.getPackageName() + " does not have install script");
+ }
+ }
+ return true;
+ }
+
+ private int executeRemoveScript(Package pkg, IIMProgressMonitor monitor) {
+ Log.log("executeRemoveScript => " + pkg.getRemoveScript());
+
+ // execute remove script
+ String script = PathUtil.get(getRemoveScriptLocalPath(pkg));
+ File scriptFile = new File(script);
+
+ if (scriptFile.exists()) {
+
+ if (monitor != null) {
- monitor.workedSubTitle(scriptFile.getName());
++ monitor.workedInstallProgress("Excute the " + pkg.getPackageName() + " remove script", 0);
+ }
+
+ try {
+ if (executeScript(scriptFile)) {
+ return 0; // succeed to execute remove script.
+ } else {
+ return 1; // fail to execute remove script.
+ }
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorController.getMessage(ErrorCode.REMOVE_SCRIPT_FATAL_ERROR)
+ + " (" + pkg + " package)");
+ }
+ }
+ return 2; // package does not need remove script.
+ }
+
+ /**
+ * Executes the file with default environment variables
+ *
+ * @param scriptFile
+ * @return <code>true</code> if success
+ * @throws IMShellCommandFail
+ */
+ public boolean executeScript(File scriptFile) throws IMShellCommandFail {
+ scriptFile.setExecutable(true);
+ Map<String, String> env = setEnvironmentVariable();
+
+ String command = ShellUtil.addInterpreter(scriptFile.getAbsolutePath());
+
+ String current = PathUtil.getCurrentDir();
+ Log.log("Current working directory. => " + current);
+ int exitCode = ShellUtil.execute(command, env, new File(current),
+ new LoggerShellParser());
+
+ // check exit code
+ if (exitCode == 0) {
+ return true;
+ } else if (exitCode == 1 || exitCode == 2) {
+ Log.err("Exit code => " + Integer.toString(exitCode));
+ return false;
+ } else if (exitCode == 99) {
+ ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);
+ Log.log("Set restart message.");
+ return true;
+ } else {
+ Log.err("Installer.executeScript() install script error => "
+ + scriptFile.getAbsolutePath());
+ Log.err("Exit code => " + Integer.toString(exitCode));
+ throw new IMFatalException(ErrorController.getMessage(ErrorCode.SCRIPT_FATAL_ERROR)
+ + " (" + scriptFile.getParentFile().getName() + " package)");
+ }
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */ \r
- \r
- package org.tizen.installmanager.core;\r
- \r
- import java.util.ArrayList;\r
- import java.util.Arrays;\r
- import java.util.Iterator;\r
- import java.util.List;\r
- \r
- import org.tizen.installmanager.core.Config.ServerType;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- \r
- /**\r
- * This class represents options from command line arguments.\r
- * @author Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- *\r
- */\r
- public class Options {\r
- /**\r
- * Do sanity checks including file size and checksum \r
- */\r
- public static boolean doPackageValidation = true;\r
- \r
- /**\r
- * Do download package file.\r
- */\r
- public static boolean onlyDownload = false;\r
- \r
- /**\r
- * Do resume downloading.\r
- */\r
- public static boolean doResumeDownloading = true;\r
- \r
- /**\r
- * Use system proxy\r
- */\r
- public static boolean useAutoProxy = true;\r
- \r
- /**\r
- * Do remove temporary installmanager that exist in /tmp/tizensdk\r
- */\r
- public static boolean doRemoveTempTizenSDK = true;\r
- \r
- /**\r
- * Conf file provided by user\r
- */\r
- public static String userConfPath = null;\r
- \r
- /**\r
- * update installmanager.\r
- * If <code>doUpdateInstallManager</code> is false, do not update installmanager binary.\r
- */\r
- public static boolean doUpdateInstallManager = true;\r
- /**\r
- * Do replace repository. \r
- * If <code>doRepository</code> is true, change repository address to <code>repo</code> variable. \r
- */\r
- public static boolean doReplaceRepository = false;\r
- \r
- /**\r
- * Do remove packages after installation\r
- */\r
- public static boolean doRemovePackages = true;\r
- \r
- /**\r
- * Do remove old sdk.\r
- * If installer cannot update sdk, <code>doRemoveOldSDK</code> is true.\r
- */\r
- public static boolean doRemoveOldSDK = false;\r
- /**\r
- * Just check installer is available for update.\r
- */\r
- public static boolean checkPackageUpdate = false;\r
- \r
- /**\r
- * Prints dependency graph of packages\r
- */\r
- public static boolean printDepGraph = false;\r
- \r
- /**\r
- * start installmanager test\r
- */ \r
- public static boolean doTest = false;\r
- \r
- /**\r
- * Use Snapshot file.\r
- */\r
- public static boolean snapshot = false;\r
- \r
- /**\r
- * Do auto install or uninstall without GUI\r
- */\r
- public static boolean doInstallNoUI = false;\r
- public static boolean doRemoveNoUI = false;\r
- public static boolean doUpdateNoUI = false;\r
- public static boolean doShowDistListNoUI = false;\r
- public static boolean doShowPackageListNoUI = false;\r
- public static boolean doShowSDKInstallStatus = false;\r
- public static boolean doShowHelp = false;\r
- \r
- public static String repository = null;\r
- public static String imageFilePath = null;\r
- public static String snapshotPath = null;\r
- public static ServerType serverType = null;\r
- public static String distribution = null;\r
- public static String targetDir = null;\r
- public static String sdkDataPath = null;\r
- \r
- public static boolean isNetwork = true;\r
- \r
- public static List<String> packages = new ArrayList<String>();\r
- public static List<String> skipPackages = new ArrayList<String>();\r
- \r
- public static boolean isAgreeLicense = false;\r
- \r
- /**\r
- * Use only download for making SDK image.\r
- */\r
- public static String boundary = "public"; // all, public, partner\r
- public static String platForm = null;\r
- public static int platFormBit = 0;\r
- \r
- /**\r
- * See all snapshots\r
- */\r
- public static boolean allSnapshots = false;\r
- \r
- /**\r
- * Support Partner SDK\r
- */\r
- public static boolean partnerSdk = false;\r
- public static String purposeOfInstalling = "public";\r
- \r
- /**\r
- * Display InstallManager Version\r
- */\r
- public static boolean showVersion = false;\r
- \r
- /**\r
- * User-provided proxy server\r
- */\r
- public static String proxy = null;\r
- \r
- /**\r
- * Logging all system information\r
- */\r
- public static boolean propertyLogging = false;\r
- \r
- /**\r
- * Non-interactive(continuous installation).\r
- */\r
- public static boolean interactive = true;\r
- public static String suPass = ""; \r
- \r
- public static String[] args;\r
- \r
- public static String executablePath = null;\r
- \r
- /**\r
- * Parses command line arguments and sets corresponding options. \r
- * @param args command line arguments\r
- */\r
- public static void loadCmdArgs(String[] args) {\r
- Options.args = args;\r
- Iterator<String> iter = Arrays.asList(args).iterator();\r
- \r
- while (iter.hasNext()) {\r
- String arg = iter.next();\r
- Log.log(arg+" option is specified");\r
- \r
- if (arg.equals("-noPackageValidation")) {\r
- doPackageValidation = false;\r
- } else if (arg.equals("-path")) {\r
- if (iter.hasNext()) {\r
- executablePath = iter.next();\r
- Log.log("executable path : " + executablePath);\r
- }\r
- } else if (arg.equals(OptionConstant.OPTION_TEST)) {\r
- doTest = true;\r
- } else if (arg.equals("-install")) {\r
- if (iter.hasNext()) {\r
- doInstallNoUI = true;\r
- workCliOptions(args);\r
- } else {\r
- Log.err("-install option must have some arguments.");\r
- System.out.println("-install option must have some arguements" +\r
- " such as specific meta packages");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- \r
- if (!validateArgs()) {\r
- Log.err("repository : " + repository + ", distribution : "\r
- + distribution + ", packages : " + packages);\r
- System.out.println("-install option must have some arguements"\r
- + " you can see usage using '-help'");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- break;\r
- } else if (arg.equals("-remove")) {\r
- if (iter.hasNext()) {\r
- doRemoveNoUI = true;\r
- workCliOptions(args);\r
- } else {\r
- Log.err("-remove option must have some arguments.");\r
- System.out.println("-remove option must have some arguements" +\r
- " such as specific meta packages or 'all'");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- break;\r
- } else if (arg.equalsIgnoreCase("-repoinfo")) {\r
- if (iter.hasNext()) {\r
- doShowDistListNoUI = true;\r
- serverType = ServerType.SNAPSHOT;\r
- workCliOptions(args);\r
- } else {\r
- Log.err("-info option must have some arguments.");\r
- System.out.println("-remove option must have some arguements" +\r
- " such as repository address.");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- break;\r
- } else if (arg.equalsIgnoreCase("-packageinfo")) {\r
- if (iter.hasNext()) {\r
- doShowPackageListNoUI = true;\r
- serverType = ServerType.SNAPSHOT;\r
- workCliOptions(args);\r
- } else {\r
- Log.err("-packages option must have some arguments.");\r
- System.out.println("-remove option must have some arguements" +\r
- " such as repository address and distribution.");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- break;\r
- } else if (arg.equalsIgnoreCase("-status")) {\r
- doShowSDKInstallStatus = true;\r
- break;\r
- } else if (arg.equalsIgnoreCase("-help")) {\r
- doShowHelp = true;\r
- break;\r
- } else if (arg.equals("-noRemovePackages")) {\r
- doRemovePackages = false;\r
- } else if (arg.equals("-skipUpdate")) {\r
- doUpdateInstallManager = false;\r
- } else if (arg.equals("-checkPackageUpdate")) {\r
- checkPackageUpdate = true;\r
- } else if (arg.equals("-printDepGraph")) {\r
- printDepGraph = true;\r
- } else if (arg.equals("-proxy")) {\r
- if(iter.hasNext()) {\r
- proxy = iter.next();\r
- Log.log("User-provided proxy: "+proxy);\r
- } else {\r
- Log.err("-proxy requires proxy description");\r
- throw new IMFatalException(ErrorCode.PROXY_NOT_PROVIDED);\r
- }\r
- } else if (arg.equals("-snapShot")) {\r
- if(iter.hasNext()) {\r
- snapshot = true;\r
- snapshotPath = iter.next();\r
- Log.log("User-provided repository: " + repository);\r
- } else {\r
- Log.err("-snapShot requires repository description");\r
- throw new IMFatalException(ErrorCode.USESNAPSHOT_REPOSITORY_NOT_PROVIDED);\r
- }\r
- } else if (arg.equals("-allSnapshots")) {\r
- allSnapshots = true;\r
- Log.log("Using '-allSnapshots' option, all snapshots are displaying.");\r
- } else if (arg.equals("-onlyDownload")) {\r
- if(iter.hasNext()) {\r
- onlyDownload = true;\r
- boundary = iter.next();\r
- platForm = iter.next().toLowerCase();\r
- platFormBit = Integer.parseInt(iter.next());\r
- Log.log("Only download boundary : "+ boundary);\r
- } else {\r
- Log.err("-onlyDownload requires packageList description");\r
- throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);\r
- }\r
- onlyDownload = true;\r
- } else if (arg.equals("-noResumeDownloading")) {\r
- doResumeDownloading = false;\r
- Log.log("Using '-noResumeDownloading' option, do not resume downloading");\r
- } else if (arg.equals("-noUseAutoProxy")) {\r
- useAutoProxy = false;\r
- Log.log("Using '-noUseAutoProxy' option, do not use system proxy.");\r
- } else if (arg.equals("-version")) {\r
- showVersion = true;\r
- Log.log("Using '-version' option, display InstallManager version on console.");\r
- } else if (arg.equals("-noRemoveTempTizenSDK")) {\r
- doRemoveTempTizenSDK = false;\r
- } else if (arg.equals("-repository")) {\r
- if(iter.hasNext()) {\r
- doReplaceRepository = true;\r
- repository = iter.next();\r
- Log.log("replace repository : "+repository);\r
- } else {\r
- Log.err("-replaceRepository requires repository description");\r
- throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);\r
- }\r
- } else if (arg.equals(OptionConstant.OPTION_DISTRIBUTION)) {\r
- if(iter.hasNext()) {\r
- distribution = iter.next();\r
- Log.log("replace distribution : "+distribution);\r
- } else {\r
- Log.err("-distribution requires distribution description");\r
- throw new IMFatalException(OptionConstant.MSG_DISTRIBUTION_NOT_PROVIDED);\r
- }\r
- } else if (arg.equals("-removeOldSDK")) {\r
- doRemoveOldSDK = true;\r
- } else if (arg.equals("-property")) {\r
- propertyLogging = true;\r
- } else if (arg.equals("-skip")) {\r
- if (iter.hasNext()) {\r
- String skipPackageName = iter.next(); \r
- skipPackages.add(skipPackageName);\r
- Log.log("Skip package => " + skipPackageName);\r
- } else {\r
- Log.err("-skip requires package name");\r
- throw new IMFatalException("-skip requires package name");\r
- }\r
- } else {\r
- Log.err("InstallManager do not support '" + arg + "' option");\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Get options.\r
- * @return\r
- */\r
- public static String getArgsStr() {\r
- String argsStr = "";\r
- for(String arg : args) {\r
- argsStr = argsStr + " " + arg;\r
- }\r
- return argsStr;\r
- }\r
- \r
- private static boolean validateArgs() {\r
- if (isNetwork) {\r
- if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- } else {\r
- if (Options.repository != null && !Options.packages.isEmpty()) {\r
- if (Platform.isWindows()) {\r
- if (Options.repository.startsWith("file")) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- } else {\r
- return true;\r
- }\r
- } else if (Options.imageFilePath == null) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- }\r
- \r
- private static void workCliOptions(String[] args) {\r
- ArrayList<String> argArray = new ArrayList<String>();\r
- \r
- for (String t : args) {\r
- if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove")) {\r
- argArray.add(t); \r
- }\r
- }\r
- \r
- Iterator<String> argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-path")) {\r
- argIter.remove();\r
- argIter.next();\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set repository\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-r")) {\r
- argIter.remove();\r
- repository = argIter.next();\r
- if (!repository.startsWith("http")) {\r
- isNetwork = false;\r
- serverType = ServerType.LOCAL;\r
- exclusiveOptions("-d", argArray);\r
- } else {\r
- serverType = ServerType.SNAPSHOT;\r
- isNetwork = true; \r
- }\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set SDK image path\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-f")) {\r
- argIter.remove();\r
- imageFilePath = argIter.next();\r
- isNetwork = false;\r
- serverType = ServerType.LOCAL;\r
- argIter.remove();\r
- exclusiveOptions("-d", argArray);\r
- }\r
- }\r
- \r
- // set target directory\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-l")) {\r
- argIter.remove();\r
- targetDir = argIter.next();\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set license agreement\r
- if (doInstallNoUI) {\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-accept_license")) {\r
- argIter.remove();\r
- isAgreeLicense = true;\r
- }\r
- } \r
- }\r
- \r
- // set sdk data directory\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-w")) {\r
- argIter.remove();\r
- sdkDataPath = argIter.next();\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set distribution\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-d")) {\r
- argIter.remove();\r
- distribution = argIter.next();\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set packages\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-p")) {\r
- argIter.remove();\r
- while (argIter.hasNext()) {\r
- String pkg = argIter.next();\r
- if (!pkg.startsWith("-")) {\r
- packages.add(pkg);\r
- argIter.remove();\r
- } else {\r
- break; \r
- }\r
- }\r
- }\r
- }\r
- \r
- // set skip packages\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-skip")) {\r
- argIter.remove();\r
- while (argIter.hasNext()) {\r
- String pkg = argIter.next();\r
- if (!pkg.startsWith("-")) {\r
- skipPackages.add(pkg);\r
- argIter.remove();\r
- } else {\r
- break; \r
- }\r
- }\r
- }\r
- }\r
- \r
- // set proxy\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-x")) {\r
- argIter.remove();\r
- Options.proxy = argIter.next();\r
- Log.log("Use proxy setting => " + Options.proxy);\r
- argIter.remove();\r
- }\r
- }\r
- \r
- // set test\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-test")) {\r
- argIter.remove();\r
- Options.doTest = true;\r
- Log.log("Set to test working performance.");\r
- }\r
- }\r
- \r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-ni")) {\r
- argIter.remove();\r
- if (argIter.hasNext()) { // -ni option must have -passwd option.\r
- if (Platform.isLinux()) {\r
- argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase("-passwd")) {\r
- argIter.remove();\r
- if (argIter.hasNext()) {\r
- suPass = argIter.next();\r
- interactive = false;\r
- argIter.remove();\r
- } else { // -passwd option must have value.\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- }\r
- }\r
- if (suPass == "") {\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- } else if (Platform.isWindows()) {\r
- interactive = true;\r
- } else if (Platform.isMacOS()) {\r
- interactive = true;\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- } else {\r
- throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
- }\r
- }\r
- }\r
- }\r
- \r
- private static void exclusiveOptions(String option, ArrayList<String> argArray) {\r
- Iterator<String> argIter = argArray.iterator();\r
- while (argIter.hasNext()) {\r
- if (argIter.next().equalsIgnoreCase(option)) {\r
- Log.err("[" + option + "] cannot be used.");\r
- System.out.println("[" + option + "] cannot be used with some options.");\r
- throw new IMFatalException("[" + option + "] cannot be used with some options.");\r
- }\r
- }\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.core;
+
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Iterator;
+ 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;
+ import org.tizen.installmanager.lib.Registry;
+
+ /**
+ * This class represents options from command line arguments.
+ * @author Wooyoung Cho <wooyoung1.cho@samsung.com>
+ *
+ */
+ public class Options {
+ /**
+ * Do sanity checks including file size and checksum
+ */
+ public static boolean doPackageValidation = true;
+
+ /**
+ * Do download package file.
+ */
+ public static boolean onlyDownload = false;
+
+ /**
+ * Do resume downloading.
+ */
+ public static boolean doResumeDownloading = true;
+
+ /**
+ * Use system proxy
+ */
+ public static boolean useAutoProxy = true;
+
+ /**
+ * Do remove temporary installmanager that exist in /tmp/tizensdk
+ */
+ public static boolean doRemoveTempTizenSDK = true;
+
+ /**
+ * Conf file provided by user
+ */
+ public static String userConfPath = null;
+
+ /**
+ * update installmanager.
+ * If <code>doUpdateInstallManager</code> is false, do not update installmanager binary.
+ */
+ public static boolean doUpdateInstallManager = true;
+ /**
+ * Do replace repository.
+ * If <code>doRepository</code> is true, change repository address to <code>repo</code> variable.
+ */
+ public static boolean doReplaceRepository = false;
+
+ /**
+ * Do remove packages after installation
+ */
+ public static boolean doRemovePackages = true;
+
+ /**
+ * Do remove old sdk.
+ * If installer cannot update sdk, <code>doRemoveOldSDK</code> is true.
+ */
+ public static boolean doRemoveOldSDK = false;
+ /**
+ * Just check installer is available for update.
+ */
+ public static boolean checkPackageUpdate = false;
+
+ /**
+ * Prints dependency graph of packages
+ */
+ public static boolean printDepGraph = false;
+
+ /**
+ * start installmanager test
+ */
+ public static boolean doTest = false;
+
+ /**
+ * Use Snapshot file.
+ */
+ public static boolean snapshot = false;
+
+ /**
+ * Download specific package
+ */
+ public static boolean downloadPackage = false;
+
+ /**
+ * Do auto install or uninstall without GUI
+ */
+ public static boolean doInstallNoUI = false;
+ public static boolean doRemoveNoUI = false;
+ public static boolean doUpdateNoUI = false;
+ public static boolean doShowDistListNoUI = false;
+ public static boolean doShowPackageListNoUI = false;
+ public static boolean doShowSDKInstallStatus = false;
+ public static boolean doShowHelp = 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 String sdkDataPath = null;
+
+ public static boolean isNetwork = true;
+
+ public static List<String> packages = new ArrayList<String>();
+ public static List<String> skipPackages = new ArrayList<String>();
+
+ public static boolean isAgreeLicense = false;
+
+ /**
+ * Use only download for making SDK image.
+ */
+ public static String boundary = "public"; // all, public, partner
+ public static String platForm = null;
+ public static int platFormBit = 0;
+
+ /**
+ * See all snapshots
+ */
+ public static boolean allSnapshots = false;
+
+ /**
+ * Support Partner SDK
+ */
+ public static boolean partnerSdk = false;
+ public static String purposeOfInstalling = "public";
+
+ /**
+ * Display InstallManager Version
+ */
+ public static boolean showVersion = false;
+
+ /**
+ * User-provided proxy server
+ */
+ public static String proxy = null;
+
+ /**
+ * Logging all system information
+ */
+ public static boolean propertyLogging = false;
+
+ /**
+ * Non-interactive(continuous installation).
+ */
+ public static boolean interactive = true;
+ public static String suPass = "";
+
+ public static String[] args;
+
+ public static String executablePath = null;
+
+ /**
+ * SDK patch
+ */
+ public static boolean doSDKPatch = false;
+ public static String SDKPatchPath = null;
+
+ /**
+ * Parses command line arguments and sets corresponding options.
+ * @param args command line arguments
+ */
+ public static void loadCmdArgs(String[] args) {
+ Options.args = args;
+ Iterator<String> iter = Arrays.asList(args).iterator();
+
+ while (iter.hasNext()) {
+ String arg = iter.next();
+
+ if (arg.equals("-noPackageValidation")) {
+ doPackageValidation = false;
+ } else if (arg.equals("-path")) {
+ if (iter.hasNext()) {
+ executablePath = iter.next();
+ Log.log("executable path : " + executablePath);
+ }
+ } else if (arg.equals(OptionConstant.OPTION_TEST)) {
+ doTest = true;
+ } else if (arg.equals("-install")) {
+ if (iter.hasNext()) {
+ doInstallNoUI = true;
+ workCliOptions(args);
+ } else {
+ Log.err("-install option must have some arguments.");
+ System.out.println("-install option must have some arguements" +
+ " such as specific meta packages");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+
+ if (!validateArgs()) {
+ Log.err("repository : " + repository + ", distribution : "
+ + distribution + ", packages : " + packages);
+ System.out.println("-install option must have some arguements"
+ + " you can see usage using '-help'");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ break;
+ } else if (arg.equals("-remove")) {
+ if (iter.hasNext()) {
+ doRemoveNoUI = true;
+ workCliOptions(args);
+ } else {
+ Log.err("-remove option must have some arguments.");
+ System.out.println("-remove option must have some arguements" +
+ " such as specific meta packages or 'all'");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ break;
+ } else if (arg.equals("-download")) {
+ if (iter.hasNext()) {
+ downloadPackage = true;
+ workCliOptions(args);
+ } else {
+ Log.err("-download option must have some arguments.");
+ System.out.println("-install option must have some arguements" +
+ " such as any packages");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ break;
+ } else if (arg.equalsIgnoreCase("-patch")) {
+ if (!canSDKPatch()) {
+ Log.err("Cannot find installed SDK. The SDK must be installed before patching.");
+ System.out.println("Cannot find installed SDK. The SDK must be installed before patching.");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ } else {
+ if (iter.hasNext()) {
+ doSDKPatch = true;
+ workCliOptions(args);
+ }
+
+ if (SDKPatchPath == null) {
+ Log.err("Cannot find SDK patch file path.");
+ System.out.println("Cannot find SDK patch file path. Please check your '-f' options.");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ }
+ break;
+ } else if (arg.equalsIgnoreCase("-repoinfo")) {
+ if (iter.hasNext()) {
+ doShowDistListNoUI = true;
+ serverType = ServerType.SNAPSHOT;
+ workCliOptions(args);
+ } else {
+ Log.err("-info option must have some arguments.");
+ System.out.println("-remove option must have some arguements" +
+ " such as repository address.");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ break;
+ } else if (arg.equalsIgnoreCase("-packageinfo")) {
+ if (iter.hasNext()) {
+ doShowPackageListNoUI = true;
+ serverType = ServerType.SNAPSHOT;
+ workCliOptions(args);
+ } else {
+ Log.err("-packages option must have some arguments.");
+ System.out.println("-remove option must have some arguements" +
+ " such as repository address and distribution.");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ break;
+ } else if (arg.equalsIgnoreCase("-status")) {
+ doShowSDKInstallStatus = true;
+ break;
+ } else if (arg.equalsIgnoreCase("-help")) {
+ doShowHelp = true;
+ break;
+ } else if (arg.equals("-noRemovePackages")) {
+ doRemovePackages = false;
+ } else if (arg.equals("-skipUpdate")) {
+ doUpdateInstallManager = false;
+ } else if (arg.equals("-checkPackageUpdate")) {
+ checkPackageUpdate = true;
+ } else if (arg.equals("-printDepGraph")) {
+ printDepGraph = true;
+ } else if (arg.equals("-proxy")) {
+ if(iter.hasNext()) {
+ proxy = iter.next();
+ Log.log("User-provided proxy: "+proxy);
+ } else {
+ Log.err("-proxy requires proxy description");
+ throw new IMFatalException(ErrorCode.PROXY_NOT_PROVIDED);
+ }
+ } else if (arg.equals("-snapShot")) {
+ if(iter.hasNext()) {
+ snapshot = true;
+ snapshotPath = iter.next();
+ Log.log("User-provided snapshot path: " + snapshotPath);
+ } else {
+ Log.err("-snapShot requires repository description");
+ throw new IMFatalException(ErrorCode.USESNAPSHOT_REPOSITORY_NOT_PROVIDED);
+ }
+ } else if (arg.equals("-allSnapshots")) {
+ allSnapshots = true;
+ Log.log("Using '-allSnapshots' option, all snapshots are displaying.");
+ } else if (arg.equals("-onlyDownload")) {
+ if(iter.hasNext()) {
+ onlyDownload = true;
+ boundary = iter.next();
+ platForm = iter.next().toLowerCase();
+ platFormBit = Integer.parseInt(iter.next());
+ Log.log("Only download boundary : "+ boundary);
+ } else {
+ Log.err("-onlyDownload requires packageList description");
+ throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);
+ }
+ onlyDownload = true;
+ } else if (arg.equals("-noResumeDownloading")) {
+ doResumeDownloading = false;
+ Log.log("Using '-noResumeDownloading' option, do not resume downloading");
+ } else if (arg.equals("-noUseAutoProxy")) {
+ useAutoProxy = false;
+ Log.log("Using '-noUseAutoProxy' option, do not use system proxy.");
+ } else if (arg.equals("-version")) {
+ showVersion = true;
+ Log.log("Using '-version' option, display InstallManager version on console.");
+ } else if (arg.equals("-noRemoveTempTizenSDK")) {
+ doRemoveTempTizenSDK = false;
+ } else if (arg.equals("-repository")) {
+ if(iter.hasNext()) {
+ doReplaceRepository = true;
+ repository = iter.next();
+ Log.log("replace repository : "+repository);
+ } else {
+ Log.err("-replaceRepository requires repository description");
+ throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);
+ }
+ } else if (arg.equals(OptionConstant.OPTION_DISTRIBUTION)) {
+ if(iter.hasNext()) {
+ distribution = iter.next();
+ Log.log("replace distribution : "+distribution);
+ } else {
+ Log.err("-distribution requires distribution description");
+ throw new IMFatalException(OptionConstant.MSG_DISTRIBUTION_NOT_PROVIDED);
+ }
+ } else if (arg.equals("-removeOldSDK")) {
+ doRemoveOldSDK = true;
+ } else if (arg.equals("-property")) {
+ propertyLogging = true;
++ } else if (arg.equals("-skip")) {
++ if (iter.hasNext()) {
++ String skipPackageName = iter.next();
++ skipPackages.add(skipPackageName);
++ Log.log("Skip package => " + skipPackageName);
++ } else {
++ Log.err("-skip requires package name");
++ throw new IMFatalException("-skip requires package name");
++ }
+ } else {
+ Log.err("InstallManager do not support '" + arg + "' option");
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ }
+
+ String option = "";
+ for (int i = 0; i < args.length; i++) {
+ option = option.concat(args[i] + " ");
+ }
+ Log.log("Option : " + option);
+ }
+
+ /**
+ * Get options.
+ * @return
+ */
+ public static String getArgsStr() {
+ String argsStr = "";
+ for(String arg : args) {
+ argsStr = argsStr + " " + arg;
+ }
+ return argsStr;
+ }
+
+ private static boolean validateArgs() {
+ if (isNetwork) {
+ if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ if (Options.repository != null && !Options.packages.isEmpty()) {
+ if (Platform.isWindows()) {
+ if (Options.repository.startsWith("file")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return true;
+ }
+ } else if (Options.imageFilePath == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ private static void workCliOptions(String[] args) {
+ ArrayList<String> argArray = new ArrayList<String>();
+
+ for (String t : args) {
+ if (!t.equalsIgnoreCase("-install")
+ && !t.equalsIgnoreCase("-remove")
+ && !t.equalsIgnoreCase("-download")
+ && !t.equalsIgnoreCase("-patch")) {
+ argArray.add(t);
+ }
+ }
+
+ Iterator<String> argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-path")) {
+ argIter.remove();
+ argIter.next();
+ argIter.remove();
+ }
+ }
+
+ // set repository
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-r")) {
+ argIter.remove();
+ repository = argIter.next();
+ if (!repository.startsWith("http")) {
+ isNetwork = false;
+ serverType = ServerType.LOCAL;
+ exclusiveOptions("-d", argArray);
+ } else {
+ serverType = ServerType.SNAPSHOT;
+ isNetwork = true;
+ }
+ argIter.remove();
+ }
+ }
+
+ // set SDK image path
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-f")) {
+ if (doInstallNoUI) {
+ argIter.remove();
+ imageFilePath = argIter.next();
+ isNetwork = false;
+ serverType = ServerType.LOCAL;
+ argIter.remove();
+ exclusiveOptions("-d", argArray);
+ } else if (doSDKPatch) {
+ SDKPatchPath = argIter.next();
+ argIter.remove();
+ }
+ }
+ }
+
+ // set target directory
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-l")) {
+ argIter.remove();
+ targetDir = argIter.next();
+ argIter.remove();
+ }
+ }
+
+ // set license agreement
+ if (doInstallNoUI) {
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-accept_license")) {
+ argIter.remove();
+ isAgreeLicense = true;
+ }
+ }
+ }
+
+ // set sdk data directory
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-w")) {
+ argIter.remove();
+ sdkDataPath = argIter.next();
+ argIter.remove();
+ }
+ }
+
+ // set distribution
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-d")) {
+ argIter.remove();
+ distribution = argIter.next();
+ argIter.remove();
+ }
+ }
+
+ // set packages
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-p")) {
+ argIter.remove();
+ while (argIter.hasNext()) {
+ String pkg = argIter.next();
+ if (!pkg.startsWith("-")) {
+ packages.add(pkg);
+ argIter.remove();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ // set skip packages
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-skip")) {
+ argIter.remove();
+ while (argIter.hasNext()) {
+ String pkg = argIter.next();
+ if (!pkg.startsWith("-")) {
+ skipPackages.add(pkg);
+ argIter.remove();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ // set proxy
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-x")) {
+ argIter.remove();
+ Options.proxy = argIter.next();
+ Log.log("Use proxy setting => " + Options.proxy);
+ argIter.remove();
+ }
+ }
+
+ // set test
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-test")) {
+ argIter.remove();
+ Options.doTest = true;
+ Log.log("Set to test working performance.");
+ }
+ }
+
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-ni")) {
+ argIter.remove();
+ if (argIter.hasNext()) { // -ni option must have -passwd option.
+ if (Platform.isLinux()) {
+ argIter = argArray.iterator();
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase("-passwd")) {
+ argIter.remove();
+ if (argIter.hasNext()) {
+ suPass = argIter.next();
+ interactive = false;
+ argIter.remove();
+ } else { // -passwd option must have value.
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ }
+ }
+ if (suPass.equals("")) {
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ } else if (Platform.isWindows()) {
+ interactive = true;
+ } else if (Platform.isMacOS()) {
+ interactive = true;
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+ } else {
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);
+ }
+ }
+ }
+ }
+
+ private static void exclusiveOptions(String option, ArrayList<String> argArray) {
+ Iterator<String> argIter = argArray.iterator();
+ 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.");
+ }
+ }
+ }
+
+ private static boolean canSDKPatch() {
+ if (Registry.isInstalled()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
- package org.tizen.installmanager.core;\r
- \r
- import java.io.BufferedWriter;\r
- import java.io.File;\r
- import java.io.FileWriter;\r
- import java.io.IOException;\r
- import java.text.SimpleDateFormat;\r
- import java.util.Date;\r
- \r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.util.PathUtil;\r
- \r
- public class Performance {\r
- public static final String INSTALL_TEST_FILE_NAME = "installtime";\r
- public static final String REMOVE_TEST_FILE_NAME = "removetime";\r
- \r
- //total time\r
- private static Date imStartTime = null;\r
- private static Date imEndTime = null;\r
- \r
- //initialize time\r
- private static Date initializeStartTime = null;\r
- private static Date initializeEndTime = null;\r
- \r
- //download time\r
- private static Date downloadStartTime = null;\r
- private static Date downloadEndTime = null;\r
- \r
- \r
- //installation time\r
- private static Date installationStartTime = null;\r
- private static Date installationEndTime = null;\r
- \r
- //removal time\r
- private static Date removalStartTime = null;\r
- private static Date removalEndTime = null;\r
- \r
- //information\r
- public static long sdkPackageSize = 0; \r
- \r
- \r
- public static void setIMStartTime() {\r
- imStartTime = new Date();\r
- }\r
- \r
- public static void setIMEndTime() {\r
- imEndTime = new Date();\r
- }\r
- \r
- public static void setInitializeStartTime() {\r
- initializeStartTime = new Date();\r
- }\r
- \r
- public static void setInitializeEndTime() {\r
- initializeEndTime = new Date();\r
- }\r
- \r
- public static void setDownloadStartTime() {\r
- downloadStartTime = new Date();\r
- }\r
- \r
- public static Date getDownloadStartTime() {\r
- return downloadStartTime;\r
- }\r
- \r
- public static void setDownloadEndTime() {\r
- downloadEndTime = new Date();\r
- }\r
- \r
- public static void setInstallationStartTime() {\r
- installationStartTime = new Date();\r
- }\r
- \r
- public static Date getInstallationStartTime() {\r
- return installationStartTime;\r
- }\r
- \r
- public static void setInstallationEndTime() {\r
- installationEndTime = new Date();\r
- }\r
- \r
- public static void setRemovalStartTime() {\r
- removalStartTime = new Date();\r
- }\r
- \r
- public static void setRemovalEndTime() {\r
- removalEndTime = new Date();\r
- }\r
- \r
- public static void printToLogFile() {\r
- Log.log("The installmanager start time : " + imStartTime);\r
- Log.log("The installmanager end time : " + imEndTime);\r
- Log.log("The installation start time : " + installationStartTime);\r
- Log.log("The installation end time : " + installationEndTime);\r
- \r
- long progressSecond = getInstallationTime()/1000;\r
- \r
- if (progressSecond >= 0) {\r
- Log.log("The progress time of the installation : About " + progressSecond/60 + " minutes"\r
- +"(" + progressSecond + " seconds)");\r
- } else {\r
- Log.log("The progress time of the installation : Installation fail");\r
- }\r
- }\r
- \r
- public static void printTestResult() {\r
- //get file name of test result\r
- SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
- String testFileName = formatter.format(imStartTime) + ".txt";\r
- \r
- String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
- File testResultFile = new File(testResultFilePath);\r
- \r
- if (!testResultFile.getParentFile().exists()) {\r
- testResultFile.getParentFile().mkdirs();\r
- }\r
- \r
- BufferedWriter out = null;\r
- try {\r
- out = new BufferedWriter(new FileWriter(testResultFile));\r
- \r
- out.write("*** InstallManager performance test ***");\r
- out.newLine();\r
- out.write("Sdk package size\t: " + sdkPackageSize);\r
- out.newLine();\r
- out.write("The initialization time\t: " + getInitializeTime() + "sec");\r
- out.write("(" + getKBPerSecond(sdkPackageSize, getInitializeTime())+ "kb/s)");\r
- out.newLine();\r
- out.write("The download time\t: " + getDownloadTime() + "sec");\r
- out.write("(" + getKBPerSecond(sdkPackageSize, getDownloadTime())+ "kb/s)");\r
- out.newLine();\r
- out.write("The installation time\t: " + getInstallationTime() + "sec");\r
- out.write("(" + getKBPerSecond(sdkPackageSize, getInstallationTime())+ "kb/s)");\r
- out.newLine();\r
- out.write("The total installation time\t: " + getTotalInstallationTime() + "sec");\r
- out.write("(" + getKBPerSecond(sdkPackageSize, getTotalInstallationTime())+ "kb/s)");\r
- out.newLine();\r
- out.write("The removal time\t: " + getRemovalTime() + "sec");\r
- out.write("(" + getKBPerSecond(sdkPackageSize, getRemovalTime())+ "b/s)");\r
- out.newLine();\r
- out.write("The install-manager start time\t: " + imStartTime);\r
- out.newLine();\r
- out.write("The install-manager end time\t: " + imEndTime);\r
- out.newLine();\r
- out.newLine();\r
- \r
- long progressSecond = getTotalTime();\r
- \r
- if (progressSecond >= 0) {\r
- out.write("* Total time to install : About " + progressSecond/60 + " minutes"\r
- +"(" + progressSecond + " seconds)");\r
- out.newLine();\r
- } else {\r
- out.write("* Total time to install : Installation fail");\r
- out.newLine();\r
- }\r
- \r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- } finally {\r
- if (out != null) {\r
- try {\r
- out.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- }\r
- \r
- public static void printTestResultXmlFormat() {\r
- if (installationStartTime != null) {\r
- printInstallTestResultXmlFormat();\r
- } else {\r
- printRemoveTestResultXmlFormat();\r
- }\r
- }\r
- \r
- public static void printInstallTestResultXmlFormat() {\r
- //get file name of test result\r
- SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
- String testFileName = INSTALL_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";\r
- \r
- String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
- File testResultFile = new File(testResultFilePath);\r
- \r
- if (!testResultFile.getParentFile().exists()) {\r
- testResultFile.getParentFile().mkdirs();\r
- }\r
- \r
- BufferedWriter out = null;\r
- try {\r
- out = new BufferedWriter(new FileWriter(testResultFile));\r
- out.write(getTestSuiteXml("InstallManager performance test", 3, getTotalTime()));\r
- out.newLine();\r
- out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));\r
- out.newLine();\r
- out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));\r
- out.newLine();\r
- out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));\r
- out.newLine();\r
- out.write(getTestCaseXml("TotalInstallationTest", "Total installation time", getTotalInstallationTime()));\r
- out.write("</testsuite>");\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- } finally {\r
- if (out != null) {\r
- try {\r
- out.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- }\r
- \r
- public static void printRemoveTestResultXmlFormat() {\r
- //get file name of test result\r
- SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
- String testFileName = REMOVE_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";\r
- \r
- String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
- File testResultFile = new File(testResultFilePath);\r
- \r
- if (!testResultFile.getParentFile().exists()) {\r
- testResultFile.getParentFile().mkdirs();\r
- }\r
- \r
- BufferedWriter out = null;\r
- try {\r
- out = new BufferedWriter(new FileWriter(testResultFile));\r
- out.write(getTestSuiteXml("InstallManager performance test", 1, getTotalTime()));\r
- out.newLine();\r
- out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));\r
- out.newLine();\r
- out.write("</testsuite>");\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- } finally {\r
- if (out != null) {\r
- try {\r
- out.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- }\r
- \r
- private static String getTestSuiteXml(String testName, int testNum, long time) {\r
- return "<testsuite errors=\"\" failures=\"\" name=\"" + testName + "\" skips=\"\" tests=\"" + testNum +"\" time=\""+ time +"\">";\r
- }\r
- \r
- private static String getTestCaseXml(String testClass, String testName, long time) {\r
- return "<testcase classname=\"" + testClass + "\" name=\"" + testName + "\" time=\"" + time +"\"/>";\r
- }\r
- \r
- private static long getInitializeTime() {\r
- if (initializeStartTime == null || initializeEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (initializeEndTime.getTime() - initializeStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getDownloadTime() {\r
- if (downloadStartTime == null || downloadEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (downloadEndTime.getTime() - downloadStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getTotalTime() {\r
- if (imStartTime == null || imEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (imEndTime.getTime() - imStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getInstallationTime() {\r
- if (installationStartTime == null || installationEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (installationEndTime.getTime() - installationStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getTotalInstallationTime() {\r
- if (downloadStartTime == null || installationEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (installationEndTime.getTime() - downloadStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getRemovalTime() {\r
- if (removalStartTime == null || removalEndTime == null) {\r
- return 0;\r
- }\r
- \r
- long interval = (removalEndTime.getTime() - removalStartTime.getTime())/1000;\r
- return interval;\r
- }\r
- \r
- private static long getKBPerSecond(long size, long seconds) {\r
- if (seconds == 0) {\r
- return 0;\r
- } else {\r
- return (size/1024/seconds);\r
- }\r
- }\r
- }\r
+ package org.tizen.installmanager.core;
+
+ import java.io.BufferedWriter;
+ import java.io.File;
+ import java.io.FileWriter;
+ import java.io.IOException;
+ import java.text.SimpleDateFormat;
+ import java.util.Date;
+
+ import org.tizen.installmanager.lib.ErrorController;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.util.PathUtil;
+
+ public class Performance {
+ public static final String INSTALL_TEST_FILE_NAME = "installtime";
+ public static final String REMOVE_TEST_FILE_NAME = "removetime";
+
+ //total time
+ private static Date imStartTime = null;
+ private static Date imEndTime = null;
+
+ //initialize time
+ private static Date initializeStartTime = null;
+ private static Date initializeEndTime = null;
+
+ //download time
+ private static Date downloadStartTime = null;
+ private static Date downloadEndTime = null;
+
+
+ //installation time
+ private static Date installationStartTime = null;
+ private static Date installationEndTime = null;
+
+ //removal time
+ private static Date removalStartTime = null;
+ private static Date removalEndTime = null;
+
+ //information
+ public static long sdkPackageSize = 0;
+
+
+ public static void setIMStartTime() {
+ imStartTime = new Date();
+ }
+
+ public static void setIMEndTime() {
+ imEndTime = new Date();
+ }
+
+ public static void setInitializeStartTime() {
+ initializeStartTime = new Date();
+ }
+
+ public static void setInitializeEndTime() {
+ initializeEndTime = new Date();
+ }
+
+ public static void setDownloadStartTime() {
+ downloadStartTime = new Date();
+ }
+
- public static boolean existDownloadStartTime() {
- if (downloadStartTime != null) {
- return true;
- } else {
- return false;
- }
- }
+ public static void setDownloadEndTime() {
+ downloadEndTime = new Date();
+ }
+
+ public static void setInstallationStartTime() {
+ installationStartTime = new Date();
+ }
+
++ public static Date getInstallationStartTime() {
++ return installationStartTime;
++ }
++
+ public static void setInstallationEndTime() {
+ installationEndTime = new Date();
+ }
+
+ public static void setRemovalStartTime() {
+ removalStartTime = new Date();
+ }
+
+ public static void setRemovalEndTime() {
+ removalEndTime = new Date();
+ }
+
+ public static void printToLogFile() {
+ Log.log("The installmanager start time : " + imStartTime);
+ Log.log("The installmanager end time : " + imEndTime);
+ Log.log("The installation start time : " + installationStartTime);
+ Log.log("The installation end time : " + installationEndTime);
+
+ long progressSecond = getInstallationTime()/1000;
+
+ if (progressSecond >= 0) {
+ Log.log("The progress time of the installation : About " + progressSecond/60 + " minutes"
+ +"(" + progressSecond + " seconds)");
+ } else {
+ Log.log("The progress time of the installation : Installation fail");
+ }
+ }
+
+ public static void printTestResult() {
+ //get file name of test result
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+ String testFileName = formatter.format(imStartTime) + "_result" + ".txt";
+
+ String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath()
+ , "result", testFileName);
+ File testResultFile = new File(testResultFilePath);
+
+ if (!testResultFile.getParentFile().exists()) {
+ testResultFile.getParentFile().mkdirs();
+ }
+
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(testResultFile));
+
+ out.write("*** InstallManager performance test ***");
+ out.newLine();
+ out.write("Sdk package size\t: " + sdkPackageSize);
+ out.newLine();
+ out.write("The initialization time\t: " + getInitializeTime() + "sec");
- out.write("(" + getBitPerSecond(sdkPackageSize / 8, getInitializeTime())+ "byte/sec)");
++ out.write("(" + getBitPerSecond(sdkPackageSize, getInitializeTime())+ "b/s)");
+ out.newLine();
+ out.write("The download time\t: " + getDownloadTime() + "sec");
- out.write("(" + getBitPerSecond(sdkPackageSize / 8, getDownloadTime())+ "byte/sec)");
++ out.write("(" + getBitPerSecond(sdkPackageSize, getDownloadTime())+ "b/s)");
+ out.newLine();
+ out.write("The installation time\t: " + getInstallationTime() + "sec");
- out.write("(" + getBitPerSecond(sdkPackageSize / 8, getInstallationTime())+ "byte/sec)");
++ out.write("(" + getBitPerSecond(sdkPackageSize, getInstallationTime())+ "b/s)");
+ out.newLine();
+ out.write("The removal time\t: " + getRemovalTime() + "sec");
- out.write("(" + getBitPerSecond(sdkPackageSize / 8, getRemovalTime())+ "byte/sec)");
++ out.write("(" + getBitPerSecond(sdkPackageSize, getRemovalTime())+ "b/s)");
+ out.newLine();
+ out.write("The install-manager start time\t: " + imStartTime);
+ out.newLine();
+ out.write("The install-manager end time\t: " + imEndTime);
+ out.newLine();
+ out.newLine();
+
+ long progressSecond = getTotalTime();
+
+ if (progressSecond >= 0) {
+ out.write("* Total time to install : About " + progressSecond/60 + " minutes"
+ +"(" + progressSecond + " seconds)");
+ out.newLine();
+ } else {
+ out.write("* Total time to install : Installation fail");
+ out.newLine();
+ }
+
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+ }
+
- public static void printTestResultXmlFormat(boolean isForAutomation) {
++ public static void printTestResultXmlFormat() {
+ //get file name of test result
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+ String testFileName = formatter.format(imStartTime) + ".xml";
+
- String testResultFilePath = "";
-
- if (isForAutomation) {
- testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath()
- , "result", testFileName);
- } else {
- testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
- }
-
++ String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
+ File testResultFile = new File(testResultFilePath);
+
+ if (!testResultFile.getParentFile().exists()) {
+ testResultFile.getParentFile().mkdirs();
+ }
+
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(testResultFile));
+ out.write(getTestSuiteXml("InstallManager performance test", 4, getTotalTime()));
+ out.newLine();
+ out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));
+ out.newLine();
+ out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));
+ out.newLine();
+ out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));
+ out.newLine();
+ out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));
+ out.newLine();
+ out.write("</testsuite>");
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+ }
+
- public static void printTestResultXmlFormat2(boolean isForAutomation) {
++ public static void printTestResultXmlFormat2() {
+ if (installationStartTime != null) {
+ printInstallTestResultXmlFormat(isForAutomation);
+ } else {
+ printRemoveTestResultXmlFormat(isForAutomation);
+ }
+ }
+
+ public static void printInstallTestResultXmlFormat(boolean isForAutomation) {
+ //get file name of test result
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+ String testFileName = INSTALL_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";
+
+ String testResultFilePath = "";
+ if (isForAutomation) {
+ testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath()
+ , "result", testFileName);
+ } else {
+ testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
+ }
+
+ File testResultFile = new File(testResultFilePath);
+
+ if (!testResultFile.getParentFile().exists()) {
+ testResultFile.getParentFile().mkdirs();
+ }
+
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(testResultFile));
+ out.write(getTestSuiteXml("InstallManager performance test", 3, getTotalTime()));
+ out.newLine();
+ out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));
+ out.newLine();
+ out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));
+ out.newLine();
+ out.write(getTestCaseXml("DownloadRetry", "Download retry count", ErrorController.getNetworkRetryCount()));
+ out.newLine();
+ out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));
+ out.newLine();
++ out.write(getTestCaseXml("TotalInstallationTest", "Total installation time", getTotalInstallationTime()));
+ out.write("</testsuite>");
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+ }
+
+ public static void printRemoveTestResultXmlFormat(boolean isForAutomation) {
+ //get file name of test result
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+ String testFileName = REMOVE_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";
+
+ String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
+ if (isForAutomation) {
+ testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath()
+ , "result", testFileName);
+ } else {
+ testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
+ }
+
+ File testResultFile = new File(testResultFilePath);
+
+ if (!testResultFile.getParentFile().exists()) {
+ testResultFile.getParentFile().mkdirs();
+ }
+
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(testResultFile));
+ out.write(getTestSuiteXml("InstallManager performance test", 1, getTotalTime()));
+ out.newLine();
+ out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));
+ out.newLine();
+ out.write("</testsuite>");
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ }
+ }
+
+ private static String getTestSuiteXml(String testName, int testNum, long time) {
+ return "<testsuite errors=\"\" failures=\"\" name=\"" + testName + "\" skips=\"\" tests=\"" + testNum +"\" time=\""+ time +"\">";
+ }
+
+ private static String getTestCaseXml(String testClass, String testName, long time) {
+ return "<testcase classname=\"" + testClass + "\" name=\"" + testName + "\" time=\"" + time +"\"/>";
+ }
+
+ private static long getInitializeTime() {
+ if (initializeStartTime == null || initializeEndTime == null) {
+ return 0;
+ }
+
+ long interval = (initializeEndTime.getTime() - initializeStartTime.getTime())/1000;
+ return interval;
+ }
+
+ private static long getDownloadTime() {
+ if (downloadStartTime == null || downloadEndTime == null) {
+ return 0;
+ }
+
+ long interval = (downloadEndTime.getTime() - downloadStartTime.getTime())/1000;
+ return interval;
+ }
+
+ private static long getTotalTime() {
+ if (imStartTime == null || imEndTime == null) {
+ return 0;
+ }
+
+ long interval = (imEndTime.getTime() - imStartTime.getTime())/1000;
+ return interval;
+ }
+
+ private static long getInstallationTime() {
+ if (installationStartTime == null || installationEndTime == null) {
+ return 0;
+ }
+
+ long interval = (installationEndTime.getTime() - installationStartTime.getTime())/1000;
+ return interval;
+ }
+
++ private static long getTotalInstallationTime() {
++ if (downloadStartTime == null || installationEndTime == null) {
++ return 0;
++ }
++
++ long interval = (installationEndTime.getTime() - downloadStartTime.getTime())/1000;
++ return interval;
++ }
++
+ private static long getRemovalTime() {
+ if (removalStartTime == null || removalEndTime == null) {
+ return 0;
+ }
+
+ long interval = (removalEndTime.getTime() - removalStartTime.getTime())/1000;
+ return interval;
+ }
+
- private static long getBitPerSecond(long size, long seconds) {
++ private static long getKBPerSecond(long size, long seconds) {
+ if (seconds == 0) {
+ return 0;
+ } else {
- return size/seconds;
++ return (size/1024/seconds);
+ }
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.lib;\r
- \r
- import java.io.File;\r
- import java.io.FileNotFoundException;\r
- import java.io.IOException;\r
- import java.io.InputStream;\r
- import java.io.RandomAccessFile;\r
- import java.net.Authenticator;\r
- import java.net.ConnectException;\r
- import java.net.HttpURLConnection;\r
- import java.net.InetAddress;\r
- import java.net.InetSocketAddress;\r
- import java.net.MalformedURLException;\r
- import java.net.NoRouteToHostException;\r
- import java.net.Proxy;\r
- import java.net.SocketAddress;\r
- import java.net.SocketException;\r
- import java.net.SocketTimeoutException;\r
- import java.net.URL;\r
- import java.net.URLConnection;\r
- import java.net.UnknownHostException;\r
- import java.security.MessageDigest;\r
- import java.security.NoSuchAlgorithmException;\r
- import java.util.List;\r
- import java.util.NoSuchElementException;\r
- \r
- import javax.net.ssl.SSLHandshakeException;\r
- \r
- import org.eclipse.swt.widgets.Display;\r
- import org.eclipse.swt.widgets.Shell;\r
- import org.tizen.installmanager.core.Config;\r
- import org.tizen.installmanager.core.IMFatalException;\r
- import org.tizen.installmanager.core.InstallManager;\r
- import org.tizen.installmanager.core.Options;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.lib.NetworkProxy.ProxyType;\r
- import org.tizen.installmanager.lib.exception.IMNetworkConnectException;\r
- import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;\r
- import org.tizen.installmanager.ui.dialog.LoginDlg;\r
- import org.tizen.installmanager.util.PathUtil;\r
- import org.tizen.installmanager.util.ResourceHandler;\r
- \r
- /**\r
- * Manages downloading from url.\r
- * \r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- * \r
- */\r
- public class Downloader {\r
- private static final String PROTOCOL_SEPARATOR = "://";\r
- private static final String USER_PASSWORD_SEPARATOR = ":";\r
- private static final String ID_SEPARATOR = "@";\r
- \r
- private static final int BUF_SIZE = 65536;\r
- \r
- public static final long ERROR = -1;\r
- \r
- private MessageDigest mDigest;\r
- private URLConnection mConnection = null;\r
- private static final int CONNECT_TIMEOUT = 15000; // connection timeout: 10 sec\r
- private static final int READ_TIMEOUT = 20000; // read timeout: 20 sec\r
- private static final int CONNECT_THREAD_JOIN_TIMEOUT = 11000; // // connection\r
- // thread timeout: 11\r
- // sec\r
- private static final int CONNECT_RETRY = 3;\r
- private static final int FIRST_TRY = 0;\r
- \r
- private String mUser = "";\r
- private String mPassword = "";\r
- \r
- private int responseCode = -1;\r
- private String responseMessage = "";\r
- private long fileSize = 0;\r
- long rangeSize = 0;\r
- \r
- //Http response code\r
- public static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; \r
- \r
- \r
- // proxy authentication\r
- private static String proxyUser = "";\r
- private static String proxyPassword = "";\r
- \r
- public Downloader() {\r
- try {\r
- mDigest = MessageDigest.getInstance("SHA-256");\r
- } catch (NoSuchAlgorithmException e) {\r
- Log.err("Downloader No algorithm for SHA-256");\r
- throw new IMFatalException("No algorithm for SHA-256");\r
- }\r
- }\r
- \r
- /**\r
- * Downloads the url to the local path\r
- * \r
- * @param sUrl\r
- * url to download\r
- * @param localPath\r
- * local path to save the file from the url\r
- * @param monitor\r
- * @return download size in bytes if success. -1 if fail.\r
- */\r
- public long download(URL sUrl, String localPath, IIMProgressMonitor monitor) \r
- throws IMNetworkConnectException, IMNetworkDownloadException{\r
- Log.log("Downloading: " + sUrl + " -> " + localPath);\r
- \r
- if (localPath == null || localPath.equals("")) {\r
- return ERROR;\r
- } \r
- \r
- if ((sUrl == null || sUrl.toExternalForm().equals(""))) {\r
- return ERROR;\r
- } \r
- \r
- File localFile = new File(localPath);\r
- setRangeSize(localFile);\r
- \r
- if (!connect(sUrl) || mConnection == null) {\r
- Log.err("Network connection error.\n" + sUrl);\r
- \r
- if (ErrorController.getErrorCode() == ErrorCode.HTTP_ERROR_MESSAGE_416) {\r
- Log.err("Requested range not satisfiable.");\r
- PathUtil.remove(localPath);\r
- }\r
- \r
- return ERROR;\r
- } \r
- \r
- long downloadSize = downloadFile(localPath, monitor);\r
- \r
- return downloadSize;\r
- }\r
- \r
- private void setRangeSize(File localFile) { \r
- //set range size.\r
- if (localFile.exists()) {\r
- rangeSize = localFile.length();\r
- } else {\r
- rangeSize = 0;\r
- }\r
- }\r
- \r
- private long downloadFile(String localPath, IIMProgressMonitor monitor) throws IMNetworkDownloadException{\r
- Log.log("File download start => " + localPath);\r
- \r
- File destFile = new File(localPath);\r
- if (!destFile.isAbsolute()) {\r
- return ERROR;\r
- }\r
- \r
- File parentDir = destFile.getParentFile();\r
- if (!parentDir.exists()) {\r
- if (!parentDir.mkdirs()) {\r
- Log.err("Fail to create directory ==> " + parentDir);\r
- }\r
- }\r
- \r
- RandomAccessFile output = null;\r
- if (isDownloadFileExist(destFile)){\r
- return destFile.length();\r
- } else {\r
- output = getOutputFile(destFile);\r
- }\r
- \r
- InputStream input = getFileInputStream();\r
- if (input == null) {\r
- return ERROR;\r
- }\r
- \r
- byte[] buf = new byte[BUF_SIZE];\r
- long totalWriteSize = rangeSize;\r
- long writeSizePerSecond = 0;\r
- long totalFileSize = getDownloadFileSize() +rangeSize;\r
- \r
- long beginMS = System.currentTimeMillis();\r
- \r
- makeDigest(localPath);\r
- \r
- try {\r
- \r
- if (monitor != null) {\r
- monitor.workedDownloadSize(rangeSize);\r
- }\r
- \r
- while (totalWriteSize < totalFileSize) {\r
- if (input.available() > 0) {\r
- int inputReadSize = input.read(buf);\r
- \r
- output.write(buf, 0, inputReadSize);\r
- \r
- totalWriteSize += inputReadSize;\r
- writeSizePerSecond += inputReadSize;\r
- \r
- if (mDigest != null) {\r
- mDigest.update(buf, 0, inputReadSize);\r
- }\r
- \r
- long endMS = System.currentTimeMillis();\r
- if (endMS > (beginMS + 100)) {\r
- if (monitor != null) {\r
- if (monitor.isCanceled()) {\r
- ErrorController.setError(ErrorCode.CANCEL);\r
- return ERROR;\r
- }\r
- monitor.workedDownloadSize(writeSizePerSecond);\r
- }\r
- \r
- writeSizePerSecond = 0;\r
- beginMS = endMS;\r
- }\r
- }\r
- \r
- long endMS = System.currentTimeMillis();\r
- if (endMS > (beginMS + READ_TIMEOUT)) {\r
- Log.err("Can not be read during 20 seconds.");\r
- ErrorController\r
- .setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- \r
- throw new IMNetworkDownloadException(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- }\r
- }\r
- \r
- if (writeSizePerSecond > 0 && monitor != null) {\r
- monitor.workedDownloadSize(writeSizePerSecond);\r
- }\r
- } catch (SocketTimeoutException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);\r
- throw new IMNetworkDownloadException(ErrorCode.SERVER_CONNECTION_TIME_OUT);\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.UNKNOWN_ERROR);\r
- throw new IMNetworkDownloadException(ErrorCode.UNKOWN_ERROR);\r
- } finally {\r
- try {\r
- if (input != null) {\r
- input.close();\r
- }\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- \r
- try {\r
- if (output != null) {\r
- output.close();\r
- }\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- if (totalWriteSize != this.fileSize) {\r
- Log.err("File size error occurs during the download");\r
- Log.err("Expected file size => " + fileSize);\r
- Log.err("Downloaded file size => " + totalWriteSize);\r
- \r
- throw new IMNetworkDownloadException(ErrorCode.NETWORK_DOWNLOADED_FILE_INCORRECTLY);\r
- }\r
- \r
- Log.log("Downloaded size: " + totalWriteSize);\r
- return totalWriteSize;\r
- }\r
- \r
- private InputStream getFileInputStream() {\r
- try {\r
- return mConnection.getInputStream();\r
- } catch (FileNotFoundException e) {\r
- Log.ExceptionLog(e);\r
- String url = mConnection.getURL().toString();\r
- int index = url.lastIndexOf("/");\r
- String errUrl = url.substring(0, index);\r
- String errorMsg = ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY\r
- .getErrorMessage() + "\n(URL = " + errUrl + ")";\r
- ErrorController.setErrorMessage(errorMsg);\r
- return null;\r
- } catch (SocketTimeoutException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);\r
- return null;\r
- } catch (NoRouteToHostException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.NO_ROUTE_TO_HOST);\r
- Log.err(ErrorController.getErrorMessage());\r
- return null;\r
- } catch (SocketException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- Log.err(ErrorController.getErrorMessage());\r
- return null;\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- if (e.getClass().toString().indexOf("FtpLoginException") >= 0) {\r
- ErrorController.setError(ErrorCode.NOT_LOGGED_IN);\r
- Log.err(ErrorController.getErrorMessage());\r
- return null;\r
- }\r
- \r
- ErrorController.setError(ErrorCode.CANNOT_DOWNLOAD_FILE);\r
- Log.err(ErrorController.getErrorMessage());\r
- return null;\r
- } catch (Throwable e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setErrorMessage(e.getMessage());\r
- return null;\r
- }\r
- }\r
- \r
- /**\r
- * file output.\r
- * @param outputFilePath\r
- * @return \r
- */\r
- private RandomAccessFile getOutputFile(File outputFile) {\r
- //Create new file to download or resume downloading.\r
- if (!outputFile.exists()) {\r
- try {\r
- outputFile.createNewFile();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.CANNOT_CREATE_DOWNLOAD_FILE);\r
- return null;\r
- }\r
- }\r
- \r
- RandomAccessFile raFile = null;\r
- try {\r
- raFile = new RandomAccessFile(outputFile, "rw");\r
- } catch (FileNotFoundException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setErrorMessage(e.getMessage());\r
- return null;\r
- }\r
- \r
- try {\r
- if (rangeSize > 0) {\r
- raFile.seek(rangeSize);\r
- }\r
- } catch (IOException e) {\r
- ErrorController.setErrorMessage(e.getMessage());\r
- Log.ExceptionLog(e);\r
- ResourceHandler.closeObjectSilently(raFile);\r
- }\r
- \r
- return raFile;\r
- }\r
- \r
- private void makeDigest(String filePath) {\r
- if (mDigest != null) {\r
- mDigest.reset();\r
- } else {\r
- try {\r
- mDigest = MessageDigest.getInstance("SHA-256");\r
- } catch (NoSuchAlgorithmException e) {\r
- Log.ExceptionLog(e);\r
- return;\r
- }\r
- }\r
- \r
- if (rangeSize > 0) {\r
- mDigest = Checksum.getSHA256(filePath);\r
- }\r
- }\r
- \r
- private boolean isDownloadFileExist(File localFile) {\r
- if (!localFile.exists()) {\r
- return false;\r
- } else {\r
- if (localFile.length() == getDownloadFileSize()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Set user name.\r
- * \r
- * @param user\r
- */\r
- public void setUser(String user) {\r
- mUser = user;\r
- }\r
- \r
- /**\r
- * Set password\r
- * \r
- * @param password\r
- */\r
- public void setPassword(String password) {\r
- mPassword = password;\r
- }\r
- \r
- /**\r
- * Get MessageDigest instance from downloading file.\r
- * \r
- * @return\r
- */\r
- public MessageDigest getFileChecksum() {\r
- return mDigest;\r
- }\r
- \r
- /**\r
- * Connect to aUrl and ready to download.\r
- * \r
- * @param aUrl\r
- * @return <code>true</code> if connect success.\r
- */\r
- public boolean connect(URL aUrl) {\r
- Log.log("Connect to " + aUrl);\r
- \r
- if (isAvailableURL(aUrl)) {\r
- boolean bRet = false;\r
- \r
- URL url = getURLWithAuthentication(aUrl);\r
- \r
- for (int i = 0; i < CONNECT_RETRY; i++) {\r
- bRet = connectWithConfiguration(url);\r
- \r
- if (bRet == false\r
- && getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH) {\r
- LoginDlg loginDialog = new LoginDlg(new Shell(\r
- Display.getCurrent()));\r
- \r
- if (i == FIRST_TRY) {\r
- loginDialog.setWarningMessage(getResponseMessage());\r
- } else {\r
- loginDialog\r
- .setWarningMessage(ErrorCode.PROXY_AUTHENTICATION_IS_WRONG\r
- .getErrorMessage());\r
- }\r
- int dRet = loginDialog.open();\r
- \r
- if (dRet == 0) {\r
- setProxyAuthentication(loginDialog.getID(),\r
- loginDialog.getPassword());\r
- } else {\r
- break;\r
- }\r
- } else {\r
- break;\r
- }\r
- }\r
- \r
- return bRet;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- private boolean connectWithConfiguration(URL url) {\r
- boolean bRet = false;\r
- \r
- String proxyType = Config.getInstance().getConfigFile().getProxyType();\r
- if (proxyType == "") { // InstallManager uses a system proxy as default.\r
- proxyType = ProxyType.AUTOMATIC.toString();\r
- }\r
- \r
- if (proxyType.equalsIgnoreCase(ProxyType.DIRECT.toString())) {\r
- bRet = connectWithDirectProxy(url);\r
- } else if (proxyType.equalsIgnoreCase(ProxyType.AUTOMATIC.toString())) {\r
- if (Options.useAutoProxy) {\r
- bRet = connectWithAutoProxy(url);\r
- } else {\r
- Config.getInstance().getConfigFile().setProxyType(ProxyType.DIRECT.toString());\r
- bRet = connectWithDirectProxy(url);\r
- }\r
- } else if (proxyType.equalsIgnoreCase(ProxyType.MANUAL.toString())) {\r
- bRet = connectWithManualProxy(url);\r
- } else {\r
- bRet = connectWithDirectProxy(url);\r
- }\r
- \r
- return bRet;\r
- }\r
- \r
- private URL getURLWithAuthentication(URL url) {\r
- try {\r
- if (!mUser.isEmpty() && !mPassword.equals("")) {\r
- String fullUrl = url.getProtocol() + PROTOCOL_SEPARATOR + mUser\r
- + USER_PASSWORD_SEPARATOR + mPassword + ID_SEPARATOR\r
- + url.getHost() + url.getPath();\r
- \r
- return new URL(fullUrl);\r
- } else {\r
- return url;\r
- }\r
- \r
- } catch (MalformedURLException e) {\r
- Log.ExceptionLog(e);\r
- return url;\r
- } catch (Throwable e) {\r
- Log.ExceptionLog(e);\r
- return url;\r
- }\r
- }\r
- \r
- public boolean connectWithDirectProxy(URL url) {\r
- boolean bRet = false;\r
- \r
- String protocol = url.getProtocol();\r
- if (protocol.startsWith("file")) {\r
- Log.log("Connect to local path.");\r
- bRet = connectToURL(url, Proxy.NO_PROXY);\r
- \r
- } else {\r
- Proxy directProxy = NetworkProxy.getHttpDirectProxy(url);\r
- bRet = connectToURL(url, directProxy);\r
- }\r
- \r
- return bRet;\r
- }\r
- \r
- public boolean connectWithAutoProxy(URL url) {\r
- boolean bRet = false;\r
- if (NetworkProxy.useProxy) {\r
- bRet = connectWithProxy(url);\r
- \r
- if (!bRet) {\r
- bRet = connectWithDirectProxy(url);\r
- \r
- if (bRet) {\r
- NetworkProxy.useProxy = false;\r
- }\r
- }\r
- } else {\r
- bRet = connectWithDirectProxy(url);\r
- \r
- if (!bRet) {\r
- bRet = connectWithProxy(url);\r
- \r
- if (bRet) {\r
- NetworkProxy.useProxy = true;\r
- }\r
- }\r
- }\r
- \r
- return bRet;\r
- }\r
- \r
- public boolean connectWithManualProxy(URL url) {\r
- Log.log("Connect to url with manual proxy. => " + url);\r
- saveProxyAuthentication();\r
- \r
- String protocol = url.getProtocol();\r
- Config conf = InstallManager.getInstance().getConfig();\r
- \r
- boolean bRet = false;\r
- if (protocol.startsWith("file")) {\r
- Log.log("Connect to local path.");\r
- bRet = connectToURL(url, Proxy.NO_PROXY);\r
- \r
- } else {\r
- if (!conf.hasProxy()) {\r
- ErrorController.setInstallationSuccess(false);\r
- throw new IMFatalException(ErrorCode.PROXY_CANNOT_FIND_SETTING);\r
- } else {\r
- Log.log("Connect to repository with config proxy.");\r
- bRet = connectToURL(url, getConfigProxy());\r
- }\r
- }\r
- return bRet;\r
- }\r
- \r
- /**\r
- * Check url available.\r
- * \r
- * @param url\r
- * @return\r
- */\r
- public static boolean isAvailableURL(URL url) {\r
- if (url.getProtocol().equalsIgnoreCase("file")) {\r
- return true;\r
- }\r
- SocketAddress socketAddress = null;\r
- try {\r
- int port = url.getPort();\r
- if (port < 0) {\r
- port = url.getDefaultPort();\r
- }\r
- socketAddress = getSocketAddress(url.getHost(), port);\r
- \r
- } catch (IMFatalException e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- }\r
- \r
- if (socketAddress == null) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- public static boolean isAvailableURL(String host, int port) {\r
- SocketAddress socketAddress = null;\r
- try {\r
- socketAddress = getSocketAddress(host, port);\r
- \r
- } catch (IMFatalException e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- }\r
- \r
- if (socketAddress == null) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- private boolean connectWithProxy(URL url) {\r
- saveProxyAuthentication();\r
- \r
- String protocol = url.getProtocol();\r
- Config conf = InstallManager.getInstance().getConfig();\r
- \r
- boolean bRet = false;\r
- if (protocol.startsWith("file")) {\r
- Log.log("Connect to local path.");\r
- bRet = connectToURL(url, Proxy.NO_PROXY);\r
- \r
- } else if (Options.proxy != null) {\r
- Log.log("Connect to repository with '-proxy' option.");\r
- bRet = connectToURL(url, getOptionalProxy());\r
- \r
- } else if (conf.hasProxy()) {\r
- Log.log("Connect to repository with config proxy.");\r
- bRet = connectToURL(url, getConfigProxy());\r
- \r
- } else { // system proxy\r
- Log.log("Connect to repository with system proxy.");\r
- List<Proxy> proxyList = NetworkProxy.getSystemProxyList(url);\r
- \r
- for (Proxy proxy : proxyList) {\r
- if (proxy == Proxy.NO_PROXY) {\r
- proxy = NetworkProxy.getHttpDirectProxy(url);\r
- }\r
- \r
- if (bRet = connectToURL(url, proxy)) {\r
- break;\r
- }\r
- }\r
- }\r
- \r
- return bRet;\r
- }\r
- \r
- private boolean connectToURL(final URL url, final Proxy proxy) {\r
- \r
- ConnectionThread connectionThread = new ConnectionThread(url, proxy);\r
- \r
- connectionThread.setDaemon(true);\r
- connectionThread.start();\r
- \r
- try {\r
- connectionThread.join(CONNECT_THREAD_JOIN_TIMEOUT);\r
- } catch (InterruptedException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- \r
- if (!connectionThread.getConnectionResult()) {\r
- return false;\r
- }\r
- \r
- if (connectionThread.isAlive()) {\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- Log.err("Cannot connect to server (URL => " + url\r
- + "). Connection thread still alive.");\r
- Log.err("proxy => " + proxy);\r
- return false;\r
- }\r
- \r
- if (!checkConnectionStatus(mConnection)) {\r
- return false;\r
- }\r
- \r
- fileSize = mConnection.getContentLength();\r
- if (fileSize < 0) {\r
- Log.err("Cannot connect to repository(url=>" + url + ", proxy=>"\r
- + proxy);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- private boolean checkConnectionStatus(URLConnection connection) {\r
- if (connection == null) {\r
- return false;\r
- } else {\r
- String protocol = connection.getURL().getProtocol();\r
- if (protocol.equalsIgnoreCase("http")) {\r
- return checkHttpConnectionStatus(connection);\r
- } else if (protocol.equalsIgnoreCase("ftp")) {\r
- return true;\r
- } else {\r
- return true;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Get reponse code from connection.\r
- * \r
- * @return\r
- */\r
- public int getResponseCode() {\r
- return responseCode;\r
- }\r
- \r
- /**\r
- * Get reponse message from connection.\r
- * \r
- * @return\r
- */\r
- public String getResponseMessage() {\r
- return responseMessage;\r
- }\r
- \r
- private boolean checkHttpConnectionStatus(URLConnection connection) {\r
- HttpURLConnection httpCon = (HttpURLConnection) connection;\r
- \r
- try {\r
- responseCode = httpCon.getResponseCode();\r
- responseMessage = httpCon.getResponseMessage();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- return false;\r
- }\r
- \r
- Log.log(Integer.toString(responseCode));\r
- Log.log(responseMessage);\r
- \r
- switch (responseCode) {\r
- case HttpURLConnection.HTTP_OK:\r
- return true;\r
- case HttpURLConnection.HTTP_PARTIAL :\r
- return true;\r
- case HttpURLConnection.HTTP_NOT_FOUND:\r
- ErrorController.setError(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);\r
- break;\r
- case HttpURLConnection.HTTP_UNAUTHORIZED:\r
- ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_401);\r
- break;\r
- case HttpURLConnection.HTTP_FORBIDDEN:\r
- ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_403);\r
- break;\r
- case HttpURLConnection.HTTP_PROXY_AUTH:\r
- ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_407);\r
- break;\r
- case Downloader.HTTP_REQUESTED_RANGE_NOT_SATISFIABLE :\r
- ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_416);\r
- break;\r
- case -1:\r
- Log.err("Http response code returns -1(null). It looks a Linux bug.");\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- break;\r
- default:\r
- String errMsg = "Server connection failed." + "\nError message : "\r
- + responseMessage + "(Code number="\r
- + Integer.toString(responseCode) + ")";\r
- ErrorController.setErrorMessage(errMsg);\r
- break;\r
- }\r
- \r
- return false;\r
- }\r
- \r
- private Proxy getOptionalProxy() {\r
- Config conf = InstallManager.getInstance().getConfig();\r
- \r
- String[] arr = Options.proxy.split(":");\r
- try {\r
- Log.log("Use user-provided proxy: " + Options.proxy);\r
- \r
- SocketAddress addr = getSocketAddress(arr[0], arr[1]);\r
- \r
- // save proxy server and port\r
- conf.getConfigFile().setProxyServer(arr[0]);\r
- conf.getConfigFile().setProxyPort(arr[1]);\r
- \r
- return new Proxy(Proxy.Type.HTTP, addr);\r
- } catch (IllegalArgumentException e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorCode.PROXY_SERVER_IS_WRONG);\r
- } catch (ArrayIndexOutOfBoundsException e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorCode.PROXY_SERVER_IS_WRONG);\r
- } catch (IMFatalException e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(e.getMessage() + "\n(proxy: " + arr[0]\r
- + ":" + arr[1] + ").");\r
- }\r
- }\r
- \r
- private Proxy getConfigProxy() {\r
- Config conf = InstallManager.getInstance().getConfig();\r
- \r
- Log.log("Use proxy specified in .conf file: "\r
- + conf.getConfigFile().getProxyHost() + ":"\r
- + conf.getConfigFile().getProxyPort());\r
- \r
- SocketAddress addr = null;\r
- try {\r
- addr = getSocketAddress(conf.getConfigFile().getProxyHost(), conf\r
- .getConfigFile().getProxyPort());\r
- } catch (IMFatalException e) {\r
- throw new IMFatalException(e.getMessage() + "\n(proxy:"\r
- + conf.getConfigFile().getProxyHost() + ":"\r
- + conf.getConfigFile().getProxyPort() + ").");\r
- }\r
- \r
- return new Proxy(Proxy.Type.HTTP, addr);\r
- }\r
- \r
- private SocketAddress getSocketAddress(String address, String port)\r
- throws IMFatalException {\r
- try {\r
- return getSocketAddress(address, Integer.parseInt(port));\r
- } catch (NumberFormatException e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorCode.URL_PORT_IS_WRONG);\r
- }\r
- }\r
- \r
- public static SocketAddress getSocketAddress(String address, int port)\r
- throws IMFatalException {\r
- SocketAddress addr = null;\r
- try {\r
- addr = new InetSocketAddress(InetAddress.getByName(address), port);\r
- } catch (UnknownHostException e) {\r
- Log.ExceptionLog(e);\r
- \r
- String errMsg = ErrorCode.UNKNOWN_HOST_EXCEPTION.getErrorMessage() +\r
- "(" + address + ")";\r
- throw new IMFatalException(errMsg);\r
- \r
- } catch (IllegalArgumentException e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(ErrorCode.URL_PORT_IS_WRONG);\r
- \r
- } catch (SecurityException e) {\r
- Log.ExceptionLog(e);\r
- \r
- ErrorController.setErrorMessage(e.getMessage());\r
- throw new IMFatalException(ErrorCode.URL_SECURITY_EXCEPTION);\r
- }\r
- \r
- return addr;\r
- }\r
- \r
- public void saveProxyAuthentication() {\r
- if (!proxyUser.isEmpty() && !proxyPassword.isEmpty()) {\r
- Authenticator.setDefault(new ProxyAuthenticator(proxyUser,\r
- proxyPassword));\r
- } else {\r
- return;\r
- }\r
- }\r
- \r
- public void setProxyAuthentication(String user, String password) {\r
- proxyUser = user;\r
- proxyPassword = password;\r
- }\r
- \r
- /**\r
- * Get file size to download.\r
- * \r
- * @return\r
- */\r
- public long getDownloadFileSize() {\r
- if (fileSize <= 0) {\r
- return mConnection.getContentLength();\r
- } else {\r
- return fileSize;\r
- }\r
- }\r
- \r
- class ConnectionThread extends Thread {\r
- URL url = null;\r
- Proxy proxy = null;\r
- \r
- boolean connectionResult = false;\r
- \r
- public ConnectionThread(URL url, Proxy proxy) {\r
- this.url = url;\r
- this.proxy = proxy;\r
- }\r
- \r
- public void run() {\r
- try {\r
- if (url != null) {\r
- mConnection = url.openConnection(proxy);\r
- }\r
- \r
- // set connetion timeout\r
- if (mConnection != null) {\r
- mConnection.setConnectTimeout(CONNECT_TIMEOUT);\r
- mConnection.setReadTimeout(READ_TIMEOUT);\r
- \r
- if (rangeSize > 0) {\r
- setRangeRequest();\r
- } \r
- mConnection.connect();\r
- } else {\r
- return;\r
- }\r
- \r
- connectionResult = true;\r
- } catch (ConnectException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- \r
- } catch (NoRouteToHostException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- \r
- } catch (SocketTimeoutException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);\r
- \r
- } catch (SocketException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);\r
- \r
- } catch (FileNotFoundException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController\r
- .setError(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);\r
- \r
- } catch (SSLHandshakeException e) {\r
- Log.ExceptionLog(e);\r
- ErrorController.setError(ErrorCode.NOT_SUPPORT_HTTPS_PROTOCOL);\r
- \r
- } catch (NoSuchElementException e) {\r
- Log.ExceptionLog(e);\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- } catch (Throwable e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- private void setRangeRequest() {\r
- Log.log("request range size of file " + rangeSize);\r
- \r
- if (mConnection != null) {\r
- mConnection.setRequestProperty("Range", "bytes=" + String.valueOf(rangeSize) + '-');\r
- } else {\r
- return;\r
- }\r
- }\r
- \r
- public boolean getConnectionResult() {\r
- return connectionResult;\r
- }\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.lib;
+
+ import java.io.File;
+ import java.io.FileNotFoundException;
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.RandomAccessFile;
+ import java.net.Authenticator;
+ import java.net.ConnectException;
+ import java.net.HttpURLConnection;
+ import java.net.InetAddress;
+ import java.net.InetSocketAddress;
+ import java.net.MalformedURLException;
+ import java.net.NoRouteToHostException;
+ import java.net.Proxy;
+ import java.net.SocketAddress;
+ import java.net.SocketException;
+ import java.net.SocketTimeoutException;
+ import java.net.URL;
+ import java.net.URLConnection;
+ import java.net.UnknownHostException;
+ import java.security.MessageDigest;
+ import java.security.NoSuchAlgorithmException;
+ import java.util.List;
+ import java.util.NoSuchElementException;
+
+ import javax.net.ssl.SSLHandshakeException;
+
+ import org.eclipse.swt.widgets.Display;
+ import org.eclipse.swt.widgets.Shell;
+ import org.tizen.installmanager.core.Config;
+ import org.tizen.installmanager.core.IMFatalException;
+ import org.tizen.installmanager.core.InstallManager;
+ import org.tizen.installmanager.core.Options;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.lib.NetworkProxy.ProxyType;
+ import org.tizen.installmanager.lib.exception.IMNetworkConnectException;
+ import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;
+ import org.tizen.installmanager.ui.dialog.LoginDlg;
+ import org.tizen.installmanager.util.PathUtil;
+ import org.tizen.installmanager.util.ResourceHandler;
+
+ /**
+ * Manages downloading from url.
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ *
+ */
+ public class Downloader {
+ private static final String PROTOCOL_SEPARATOR = "://";
+ private static final String USER_PASSWORD_SEPARATOR = ":";
+ private static final String ID_SEPARATOR = "@";
+
+ private static final int BUF_SIZE = 65536;
+
+ public static final long ERROR = -1;
+
+ private MessageDigest mDigest;
+ private URLConnection mConnection = null;
+ private static final int CONNECT_TIMEOUT = 15000; // connection timeout: 10 sec
+ private static final int READ_TIMEOUT = 20000; // read timeout: 20 sec
+ private static final int CONNECT_TIMEOUT_TEST = 30000; // connection timeout: 10 sec
+ private static final int READ_TIMEOUT_TEST = 60000; // read timeout: 20 sec
+ private static final int CONNECT_THREAD_JOIN_TIMEOUT = 11000; // // connection
+ // thread timeout: 11
+ // sec
+ private static final int CONNECT_RETRY = 3;
+ private static final int FIRST_TRY = 0;
+
+ private String mUser = "";
+ private String mPassword = "";
+
+ private int responseCode = -1;
+ private String responseMessage = "";
+ private long fileSize = 0;
+ long rangeSize = 0;
+
+ //Http response code
+ public static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
+
+
+ // proxy authentication
+ private static String proxyUser = "";
+ private static String proxyPassword = "";
+
+ public Downloader() {
+ try {
+ mDigest = MessageDigest.getInstance("SHA-256");
+ } catch (NoSuchAlgorithmException e) {
+ Log.err("Downloader No algorithm for SHA-256");
+ throw new IMFatalException("No algorithm for SHA-256");
+ }
+ }
+
+ /**
+ * Downloads the url to the local path
+ *
+ * @param sUrl
+ * url to download
+ * @param localPath
+ * local path to save the file from the url
+ * @param monitor
+ * @return download size in bytes if success. -1 if fail.
+ */
+ public long download(URL sUrl, String localPath, IIMProgressMonitor monitor)
+ throws IMNetworkConnectException, IMNetworkDownloadException{
+ Log.log("Downloading: " + sUrl + " -> " + localPath);
+
+ if (localPath == null || localPath.equals("")) {
+ return ERROR;
+ }
+
+ if ((sUrl == null || sUrl.toExternalForm().equals(""))) {
+ return ERROR;
+ }
+
+ File localFile = new File(localPath);
+ setRangeSize(localFile);
+
+ if (!connect(sUrl) || mConnection == null) {
+ Log.err("Network connection error.\n" + sUrl);
+
+ if (ErrorController.getErrorCode() == ErrorCode.HTTP_ERROR_MESSAGE_416) {
+ Log.err("Requested range not satisfiable.");
+ PathUtil.remove(localPath);
+ }
+
+ return ERROR;
+ }
+
+ long downloadSize = downloadFile(localPath, monitor);
+
+ return downloadSize;
+ }
+
+ private void setRangeSize(File localFile) {
+ //set range size.
+ if (localFile.exists()) {
+ rangeSize = localFile.length();
+ } else {
+ rangeSize = 0;
+ }
+ }
+
+ private long downloadFile(String localPath, IIMProgressMonitor monitor) throws IMNetworkDownloadException{
+ Log.log("File download start => " + localPath);
+
+ File destFile = new File(localPath);
+ if (!destFile.isAbsolute()) {
+ return ERROR;
+ }
+
+ File parentDir = destFile.getParentFile();
+ if (!parentDir.exists()) {
+ if (!parentDir.mkdirs()) {
+ Log.err("Fail to create directory ==> " + parentDir);
+ }
+ }
+
+ RandomAccessFile output = null;
+ if (isDownloadFileExist(destFile)){
+ return destFile.length();
+ } else {
+ output = getOutputFile(destFile);
+ }
+
+ InputStream input = getFileInputStream();
+ if (input == null) {
+ return ERROR;
+ }
+
+ byte[] buf = new byte[BUF_SIZE];
+ long totalWriteSize = rangeSize;
+ long writeSizePerSecond = 0;
+ long totalFileSize = getDownloadFileSize() +rangeSize;
+
+ long beginMS = System.currentTimeMillis();
+
+ makeDigest(localPath);
+
+ try {
+
+ if (monitor != null) {
- monitor.workedDownload(rangeSize);
++ monitor.workedDownloadSize(rangeSize);
+ }
+
+ while (totalWriteSize < totalFileSize) {
+ if (input.available() > 0) {
+ int inputReadSize = input.read(buf);
+
+ output.write(buf, 0, inputReadSize);
+
+ totalWriteSize += inputReadSize;
+ writeSizePerSecond += inputReadSize;
+
+ if (mDigest != null) {
+ mDigest.update(buf, 0, inputReadSize);
+ }
+
+ long endMS = System.currentTimeMillis();
+ if (endMS > (beginMS + 100)) {
+ if (monitor != null) {
+ if (monitor.isCanceled()) {
+ ErrorController.setError(ErrorCode.CANCEL);
+ return ERROR;
+ }
- monitor.workedDownload(writeSizePerSecond);
++ monitor.workedDownloadSize(writeSizePerSecond);
+ }
+
+ writeSizePerSecond = 0;
+ beginMS = endMS;
+ }
+ }
+
+ long endMS = System.currentTimeMillis();
+ long timeOutOffset = 0;
+
+ if (Options.doTest) {
+ timeOutOffset = READ_TIMEOUT_TEST;
+ } else {
+ timeOutOffset = READ_TIMEOUT;
+ }
+
+ if (endMS > (beginMS + timeOutOffset)) {
+ Log.err("Can not be read during 20 seconds(test case : 60 seconds).");
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+
+ throw new IMNetworkDownloadException(ErrorCode.INTERNET_CONNECTION_ERROR);
+ } else {
+ // normal operation. to do nothing.
+ }
+ }
++
++ if (writeSizePerSecond > 0 && monitor != null) {
++ monitor.workedDownloadSize(writeSizePerSecond);
++ }
+ } catch (SocketTimeoutException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);
+ throw new IMNetworkDownloadException(ErrorCode.SERVER_CONNECTION_TIME_OUT);
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.UNKNOWN_ERROR);
+ throw new IMNetworkDownloadException(ErrorCode.UNKOWN_ERROR);
+ } finally {
+ try {
+ if (input != null) {
+ input.close();
+ }
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+
+ try {
+ if (output != null) {
+ output.close();
+ }
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+
+ if (totalWriteSize != this.fileSize) {
+ Log.err("File size error occurs during the download");
+ Log.err("Expected file size => " + fileSize);
+ Log.err("Downloaded file size => " + totalWriteSize);
+
+ throw new IMNetworkDownloadException(ErrorCode.NETWORK_DOWNLOADED_FILE_INCORRECTLY);
+ }
+
+ Log.log("Downloaded size: " + totalWriteSize);
+ return totalWriteSize;
+ }
+
+ private InputStream getFileInputStream() {
+ try {
+ return mConnection.getInputStream();
+ } catch (FileNotFoundException e) {
+ Log.ExceptionLog(e);
+ String url = mConnection.getURL().toString();
+ int index = url.lastIndexOf("/");
+ String errUrl = url.substring(0, index);
+ String errorMsg = ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY
+ .getErrorMessage() + "\n(URL = " + errUrl + ")";
+ ErrorController.setErrorMessage(errorMsg);
+ return null;
+ } catch (SocketTimeoutException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);
+ return null;
+ } catch (NoRouteToHostException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.NO_ROUTE_TO_HOST);
+ Log.err(ErrorController.getErrorMessage());
+ return null;
+ } catch (SocketException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+ Log.err(ErrorController.getErrorMessage());
+ return null;
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ if (e.getClass().toString().indexOf("FtpLoginException") >= 0) {
+ ErrorController.setError(ErrorCode.NOT_LOGGED_IN);
+ Log.err(ErrorController.getErrorMessage());
+ return null;
+ }
+
+ ErrorController.setError(ErrorCode.CANNOT_DOWNLOAD_FILE);
+ Log.err(ErrorController.getErrorMessage());
+ return null;
+ } catch (Throwable e) {
+ Log.ExceptionLog(e);
+ ErrorController.setErrorMessage(e.getMessage());
+ return null;
+ }
+ }
+
+ /**
+ * file output.
+ * @param outputFilePath
+ * @return
+ */
+ private RandomAccessFile getOutputFile(File outputFile) {
+ //Create new file to download or resume downloading.
+ if (!outputFile.exists()) {
+ try {
+ outputFile.createNewFile();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.CANNOT_CREATE_DOWNLOAD_FILE);
+ return null;
+ }
+ }
+
+ RandomAccessFile raFile = null;
+ try {
+ raFile = new RandomAccessFile(outputFile, "rw");
+ } catch (FileNotFoundException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setErrorMessage(e.getMessage());
+ return null;
+ }
+
+ try {
+ if (rangeSize > 0) {
+ raFile.seek(rangeSize);
+ }
+ } catch (IOException e) {
+ ErrorController.setErrorMessage(e.getMessage());
+ Log.ExceptionLog(e);
+ ResourceHandler.closeObjectSilently(raFile);
+ }
+
+ return raFile;
+ }
+
+ private void makeDigest(String filePath) {
+ if (mDigest != null) {
+ mDigest.reset();
+ } else {
+ try {
+ mDigest = MessageDigest.getInstance("SHA-256");
+ } catch (NoSuchAlgorithmException e) {
+ Log.ExceptionLog(e);
+ return;
+ }
+ }
+
+ if (rangeSize > 0) {
+ mDigest = Checksum.getSHA256(filePath);
+ }
+ }
+
+ private boolean isDownloadFileExist(File localFile) {
+ if (!localFile.exists()) {
+ return false;
+ } else {
+ if (localFile.length() == getDownloadFileSize()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Set user name.
+ *
+ * @param user
+ */
+ public void setUser(String user) {
+ mUser = user;
+ }
+
+ /**
+ * Set password
+ *
+ * @param password
+ */
+ public void setPassword(String password) {
+ mPassword = password;
+ }
+
+ /**
+ * Get MessageDigest instance from downloading file.
+ *
+ * @return
+ */
+ public MessageDigest getFileChecksum() {
+ return mDigest;
+ }
+
+ /**
+ * Connect to aUrl and ready to download.
+ *
+ * @param aUrl
+ * @return <code>true</code> if connect success.
+ */
+ public boolean connect(URL aUrl) {
+ Log.log("Connect to " + aUrl);
+
+ if (isAvailableURL(aUrl)) {
+ boolean bRet = false;
+
+ URL url = getURLWithAuthentication(aUrl);
+
+ for (int i = 0; i < CONNECT_RETRY; i++) {
+ bRet = connectWithConfiguration(url);
+
+ if (bRet == false
+ && getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH) {
+ LoginDlg loginDialog = new LoginDlg(new Shell(
+ Display.getCurrent()));
+
+ if (i == FIRST_TRY) {
+ loginDialog.setWarningMessage(getResponseMessage());
+ } else {
+ loginDialog
+ .setWarningMessage(ErrorCode.PROXY_AUTHENTICATION_IS_WRONG
+ .getErrorMessage());
+ }
+ int dRet = loginDialog.open();
+
+ if (dRet == 0) {
+ setProxyAuthentication(loginDialog.getID(),
+ loginDialog.getPassword());
+ } else {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ return bRet;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean connectWithConfiguration(URL url) {
+ boolean bRet = false;
+
+ String proxyType = Config.getInstance().getConfigFile().getProxyType();
+ if (proxyType.equals("")) { // InstallManager uses a system proxy as default.
+ proxyType = ProxyType.AUTOMATIC.toString();
+ }
+
+ if (proxyType.equalsIgnoreCase(ProxyType.DIRECT.toString())) {
+ bRet = connectWithDirectProxy(url);
+ } else if (proxyType.equalsIgnoreCase(ProxyType.AUTOMATIC.toString())) {
+ if (Options.useAutoProxy) {
+ bRet = connectWithAutoProxy(url);
+ } else {
+ Config.getInstance().getConfigFile().setProxyType(ProxyType.DIRECT.toString());
+ bRet = connectWithDirectProxy(url);
+ }
+ } else if (proxyType.equalsIgnoreCase(ProxyType.MANUAL.toString())) {
+ bRet = connectWithManualProxy(url);
+ } else {
+ bRet = connectWithDirectProxy(url);
+ }
+
+ return bRet;
+ }
+
+ private URL getURLWithAuthentication(URL url) {
+ try {
+ if (!mUser.isEmpty() && !mPassword.equals("")) {
+ String fullUrl = url.getProtocol() + PROTOCOL_SEPARATOR + mUser
+ + USER_PASSWORD_SEPARATOR + mPassword + ID_SEPARATOR
+ + url.getHost() + url.getPath();
+
+ return new URL(fullUrl);
+ } else {
+ return url;
+ }
+
+ } catch (MalformedURLException e) {
+ Log.ExceptionLog(e);
+ return url;
+ } catch (Throwable e) {
+ Log.ExceptionLog(e);
+ return url;
+ }
+ }
+
+ public boolean connectWithDirectProxy(URL url) {
+ boolean bRet = false;
+
+ String protocol = url.getProtocol();
+ if (protocol.startsWith("file")) {
+ Log.log("Connect to local path.");
+ bRet = connectToURL(url, Proxy.NO_PROXY);
+
+ } else {
+ Proxy directProxy = NetworkProxy.getHttpDirectProxy(url);
+ bRet = connectToURL(url, directProxy);
+ }
+
+ return bRet;
+ }
+
+ public boolean connectWithAutoProxy(URL url) {
+ boolean bRet = false;
+ if (NetworkProxy.useProxy) {
+ bRet = connectWithProxy(url);
+
+ if (!bRet) {
+ bRet = connectWithDirectProxy(url);
+
+ if (bRet) {
+ NetworkProxy.useProxy = false;
+ }
+ }
+ } else {
+ bRet = connectWithDirectProxy(url);
+
+ if (!bRet) {
+ bRet = connectWithProxy(url);
+
+ if (bRet) {
+ NetworkProxy.useProxy = true;
+ }
+ }
+ }
+
+ return bRet;
+ }
+
+ public boolean connectWithManualProxy(URL url) {
+ Log.log("Connect to url with manual proxy. => " + url);
+ saveProxyAuthentication();
+
+ String protocol = url.getProtocol();
+ Config conf = InstallManager.getInstance().getConfig();
+
+ boolean bRet = false;
+ if (protocol.startsWith("file")) {
+ Log.log("Connect to local path.");
+ bRet = connectToURL(url, Proxy.NO_PROXY);
+
+ } else {
+ if (!conf.hasProxy()) {
+ ErrorController.setInstallationSuccess(false);
+ throw new IMFatalException(ErrorCode.PROXY_CANNOT_FIND_SETTING);
+ } else {
+ Log.log("Connect to repository with config proxy.");
+ bRet = connectToURL(url, getConfigProxy());
+ }
+ }
+ return bRet;
+ }
+
+ /**
+ * Check url available.
+ *
+ * @param url
+ * @return
+ */
+ public static boolean isAvailableURL(URL url) {
+ if (url.getProtocol().equalsIgnoreCase("file")) {
+ return true;
+ }
+ SocketAddress socketAddress = null;
+ try {
+ int port = url.getPort();
+ if (port < 0) {
+ port = url.getDefaultPort();
+ }
+ socketAddress = getSocketAddress(url.getHost(), port);
+
+ } catch (IMFatalException e) {
+ Log.ExceptionLog(e);
+ return false;
+ }
+
+ if (socketAddress == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public static boolean isAvailableURL(String host, int port) {
+ SocketAddress socketAddress = null;
+ try {
+ socketAddress = getSocketAddress(host, port);
+
+ } catch (IMFatalException e) {
+ Log.ExceptionLog(e);
+ return false;
+ }
+
+ if (socketAddress == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ private boolean connectWithProxy(URL url) {
+ saveProxyAuthentication();
+
+ String protocol = url.getProtocol();
+ Config conf = InstallManager.getInstance().getConfig();
+
+ boolean bRet = false;
+ if (protocol.startsWith("file")) {
+ Log.log("Connect to local path.");
+ bRet = connectToURL(url, Proxy.NO_PROXY);
+
+ } else if (Options.proxy != null) {
+ Log.log("Connect to repository with '-proxy' option.");
+ bRet = connectToURL(url, getOptionalProxy());
+
+ } else if (conf.hasProxy()) {
+ Log.log("Connect to repository with config proxy.");
+ bRet = connectToURL(url, getConfigProxy());
+
+ } else { // system proxy
+ Log.log("Connect to repository with system proxy.");
+ List<Proxy> proxyList = NetworkProxy.getSystemProxyList(url);
+
+ for (Proxy proxy : proxyList) {
++ if (proxy == Proxy.NO_PROXY) {
++ proxy = NetworkProxy.getHttpDirectProxy(url);
++ }
++
+ if (bRet = connectToURL(url, proxy)) {
+ break;
+ }
+ }
+ }
+
+ return bRet;
+ }
+
+ private boolean connectToURL(final URL url, final Proxy proxy) {
+
+ ConnectionThread connectionThread = new ConnectionThread(url, proxy);
+
+ connectionThread.setDaemon(true);
+ connectionThread.start();
+
+ try {
+ connectionThread.join(CONNECT_THREAD_JOIN_TIMEOUT);
+ } catch (InterruptedException e) {
+ Log.ExceptionLog(e);
+ }
+
+ if (!connectionThread.getConnectionResult()) {
+ return false;
+ }
+
+ if (connectionThread.isAlive()) {
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+ Log.err("Cannot connect to server (URL => " + url
+ + "). Connection thread still alive.");
+ Log.err("proxy => " + proxy);
+ return false;
+ }
+
+ if (!checkConnectionStatus(mConnection)) {
+ return false;
+ }
+
+ fileSize = mConnection.getContentLength();
+ if (fileSize < 0) {
+ Log.err("Cannot connect to repository(url=>" + url + ", proxy=>"
+ + proxy);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ private boolean checkConnectionStatus(URLConnection connection) {
+ if (connection == null) {
+ return false;
+ } else {
+ String protocol = connection.getURL().getProtocol();
+ if (protocol.equalsIgnoreCase("http")) {
+ return checkHttpConnectionStatus(connection);
+ } else if (protocol.equalsIgnoreCase("ftp")) {
+ return true;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ /**
+ * Get reponse code from connection.
+ *
+ * @return
+ */
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ /**
+ * Get reponse message from connection.
+ *
+ * @return
+ */
+ public String getResponseMessage() {
+ return responseMessage;
+ }
+
+ private boolean checkHttpConnectionStatus(URLConnection connection) {
+ HttpURLConnection httpCon = (HttpURLConnection) connection;
+
+ try {
+ responseCode = httpCon.getResponseCode();
+ responseMessage = httpCon.getResponseMessage();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+ return false;
+ }
+
+ Log.log(Integer.toString(responseCode));
+ Log.log(responseMessage);
+
+ switch (responseCode) {
+ case HttpURLConnection.HTTP_OK:
+ return true;
+ case HttpURLConnection.HTTP_PARTIAL :
+ return true;
+ case HttpURLConnection.HTTP_NOT_FOUND:
+ ErrorController.setError(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);
+ break;
+ case HttpURLConnection.HTTP_UNAUTHORIZED:
+ ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_401);
+ break;
+ case HttpURLConnection.HTTP_FORBIDDEN:
+ ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_403);
+ break;
+ case HttpURLConnection.HTTP_PROXY_AUTH:
+ ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_407);
+ break;
+ case Downloader.HTTP_REQUESTED_RANGE_NOT_SATISFIABLE :
+ ErrorController.setError(ErrorCode.HTTP_ERROR_MESSAGE_416);
+ break;
+ case -1:
+ Log.err("Http response code returns -1(null). It looks a Linux bug.");
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+ break;
+ default:
+ String errMsg = "Server connection failed." + "\nError message : "
+ + responseMessage + "(Code number="
+ + Integer.toString(responseCode) + ")";
+ ErrorController.setErrorMessage(errMsg);
+ break;
+ }
+
+ return false;
+ }
+
+ private Proxy getOptionalProxy() {
+ Config conf = InstallManager.getInstance().getConfig();
+
+ String[] arr = Options.proxy.split(":");
+ try {
+ Log.log("Use user-provided proxy: " + Options.proxy);
+
+ SocketAddress addr = getSocketAddress(arr[0], arr[1]);
+
+ // save proxy server and port
+ conf.getConfigFile().setProxyServer(arr[0]);
+ conf.getConfigFile().setProxyPort(arr[1]);
+
+ return new Proxy(Proxy.Type.HTTP, addr);
+ } catch (IllegalArgumentException e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorCode.PROXY_SERVER_IS_WRONG);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorCode.PROXY_SERVER_IS_WRONG);
+ } catch (IMFatalException e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(e.getMessage() + "\n(proxy: " + arr[0]
+ + ":" + arr[1] + ").");
+ }
+ }
+
+ private Proxy getConfigProxy() {
+ Config conf = InstallManager.getInstance().getConfig();
+
+ Log.log("Use proxy specified in .conf file: "
+ + conf.getConfigFile().getProxyHost() + ":"
+ + conf.getConfigFile().getProxyPort());
+
+ SocketAddress addr = null;
+ try {
+ addr = getSocketAddress(conf.getConfigFile().getProxyHost(), conf
+ .getConfigFile().getProxyPort());
+ } catch (IMFatalException e) {
+ throw new IMFatalException(e.getMessage() + "\n(proxy:"
+ + conf.getConfigFile().getProxyHost() + ":"
+ + conf.getConfigFile().getProxyPort() + ").");
+ }
+
+ return new Proxy(Proxy.Type.HTTP, addr);
+ }
+
+ private SocketAddress getSocketAddress(String address, String port)
+ throws IMFatalException {
+ try {
+ return getSocketAddress(address, Integer.parseInt(port));
+ } catch (NumberFormatException e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorCode.URL_PORT_IS_WRONG);
+ }
+ }
+
+ public static SocketAddress getSocketAddress(String address, int port)
+ throws IMFatalException {
+ SocketAddress addr = null;
+ try {
+ addr = new InetSocketAddress(InetAddress.getByName(address), port);
+ } catch (UnknownHostException e) {
+ Log.ExceptionLog(e);
+
+ String errMsg = ErrorCode.UNKNOWN_HOST_EXCEPTION.getErrorMessage() +
+ "(" + address + ")";
+ throw new IMFatalException(errMsg);
+
+ } catch (IllegalArgumentException e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(ErrorCode.URL_PORT_IS_WRONG);
+
+ } catch (SecurityException e) {
+ Log.ExceptionLog(e);
+
+ ErrorController.setErrorMessage(e.getMessage());
+ throw new IMFatalException(ErrorCode.URL_SECURITY_EXCEPTION);
+ }
+
+ return addr;
+ }
+
+ public void saveProxyAuthentication() {
+ if (!proxyUser.isEmpty() && !proxyPassword.isEmpty()) {
+ Authenticator.setDefault(new ProxyAuthenticator(proxyUser,
+ proxyPassword));
+ } else {
+ return;
+ }
+ }
+
+ public void setProxyAuthentication(String user, String password) {
+ proxyUser = user;
+ proxyPassword = password;
+ }
+
+ /**
+ * Get file size to download.
+ *
+ * @return
+ */
+ public long getDownloadFileSize() {
+ if (fileSize <= 0) {
+ return mConnection.getContentLength();
+ } else {
+ return fileSize;
+ }
+ }
+
+ class ConnectionThread extends Thread {
+ URL url = null;
+ Proxy proxy = null;
+
+ boolean connectionResult = false;
+
+ public ConnectionThread(URL url, Proxy proxy) {
+ this.url = url;
+ this.proxy = proxy;
+ }
+
+ public void run() {
+ try {
+ if (url != null) {
+ mConnection = url.openConnection(proxy);
+ }
+
+ // set connetion timeout
+ if (mConnection != null) {
+ if (Options.doTest) {
+ mConnection.setConnectTimeout(CONNECT_TIMEOUT_TEST);
+ mConnection.setReadTimeout(READ_TIMEOUT_TEST);
+ } else {
+ mConnection.setConnectTimeout(CONNECT_TIMEOUT);
+ mConnection.setReadTimeout(READ_TIMEOUT);
+ }
+ // mConnection.setConnectTimeout(CONNECT_TIMEOUT);
+ // mConnection.setReadTimeout(READ_TIMEOUT);
+
+ if (rangeSize > 0) {
+ setRangeRequest();
+ }
+ mConnection.connect();
+ } else {
+ return;
+ }
+
+ connectionResult = true;
+ } catch (ConnectException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+
+ } catch (NoRouteToHostException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+
+ } catch (SocketTimeoutException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.SERVER_CONNECTION_TIME_OUT);
+
+ } catch (SocketException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.INTERNET_CONNECTION_ERROR);
+
+ } catch (FileNotFoundException e) {
+ Log.ExceptionLog(e);
+ ErrorController
+ .setError(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);
+
+ } catch (SSLHandshakeException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setError(ErrorCode.NOT_SUPPORT_HTTPS_PROTOCOL);
+
+ } catch (NoSuchElementException e) {
+ Log.ExceptionLog(e);
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ } catch (Throwable e) {
+ Log.ExceptionLog(e);
+ }
+ }
+
+ private void setRangeRequest() {
+ Log.log("request range size of file " + rangeSize);
+
+ if (mConnection != null) {
+ mConnection.setRequestProperty("Range", "bytes=" + String.valueOf(rangeSize) + '-');
+ } else {
+ return;
+ }
+ }
+
+ public boolean getConnectionResult() {
+ return connectionResult;
+ }
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.lib;\r
- \r
- import org.tizen.installmanager.core.Config;\r
- \r
- /**\r
- * This class manages error codes and states\r
- *\r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- */\r
- public class ErrorController {\r
- /**\r
- * Define case of error\r
- *\r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- *\r
- */\r
- public enum ErrorCode {\r
- CANNOT_FIND_CONFIG_FILE("The installmanager.conf file not found."),\r
- CANNOT_FIND_FILE_IN_REPOSITROY("Cannot find file in repository."),\r
- CANNOT_CREATE_DOWNLOAD_FILE("Download file cannot be created."),\r
- CANNOT_CHECK_INSTLLED_FILE_LIST("Installed file list cannot be checked."),\r
- CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY("File cannot be moved to the target directory."),\r
- CANNOT_CONNECT_TO_PROXY_SERVER("Proxy server connection fails."),\r
- WRONG_PACKAGE_URL("Package URLs are invalid."),\r
- CANCEL("Download canceled."),\r
- UNKNOWN_ERROR("Unknown error."),\r
- UNKNOWN_PACKAGE_EXTENSION("Package extension not supported."),\r
- INVALID_PACKAGE_VERSION("Invalid package version."),\r
- CANNOT_FIND_PACKAGE_VERSION("Package version not found."),\r
- CANNOT_FIND_INSTALLABLE_OR_REMOVABLE_PACKAGES("Install or uninstall packages not found. Network connection may have failed."),\r
- CANNOT_FIND_FILE_IN_LOCAL("Local file not found."),\r
- CANNOT_SAVE_CONFIG("Configuration file cannot be saved."),\r
- CANNOT_CREATE_SHORTCUT("Shortcut creation is failed."),\r
- CANNOT_CREATE_TSUDO("tsudo creation is failed."),\r
- CANNOT_CREATE_INSTALL_LIST("Install list creation failed."),\r
- CANNOT_CREATE_CONFIG_FILE("Configuration directory or file creation failed."),\r
- CANNOT_FIND_USER_CONFIG_FILE("User configuration file creation failed."),\r
- CANNOT_REGISTER_TARGET_DIR("Target directory registration failed."),\r
- CANNOT_PARSING_TEXT("Configuration file parsing failed."),\r
- CANNOT_SAVE_PROPERTY_FILE("The installmanager.conf or Package file cannot be saved."),\r
- CANNOT_UNPACK_PACKAGE("The package zip file unpackaging failed."),\r
- CANNOT_CREATE_RESOURCE("Resource file creation failed."),\r
- CANNOT_FIND_PACKAGE("Required packages not found. The package server may be invalid."),\r
- CANNOT_REMOVE_PACKAGE("Package removal failed."),\r
- CANNOT_REMOVE_MISSING_PACKAGE("Missing package cannot be removed."),\r
- FIND_MISSING_FILES("Some files are not installed properly."),\r
- CANNOT_ACCESS_FILE("File access failed."),\r
- CANNOT_REMOVE_OLDSDK("Old SDK removal failed."),\r
- COPY_FILE_IS_FAIL("Copying the file to the target directory failed."),\r
- OLD_TIZEN_SDK_EXISTS("Old Tizen SDK is installed. Remove the old SDK and run the Tizen SDK Install Manager again."),\r
- UNSUPPORTED_PLATFORM("Platform not supported."),\r
- REMOVE_SCRIPT_NOT_EXISTS("Removal script not found."),\r
- REMOVE_SCRIPT_FATAL_ERROR("Fatal error occurred while executing remove script."),\r
- INSTALLATION_FAIL("Installation failed."),\r
- INSTALL_CANCELED("Installation canceled."),\r
- INSTALLED_VERSION_IS_HIGH("Installation progress failed due to high installed package version."),\r
- CANNOT_CREATE_FILE("File creation failed."),\r
- THREAD_INTERRUPTED("Thread execution interrupted."),\r
- CIRCULAR_PACKAGE_DEPENDENCY("Circular package dependency detected."),\r
- \r
- //Configuration file error\r
- CONFIG_CANNOT_PARSING_PACKAGE_LIST("Package list cannot be read. Check the repository or proxy server."),\r
- CONFIG_CANNOT_FIND_PACKAGE_LIST_FILE_IN_REPOSITORY("Cannot get the package information. " +\r
- "\nPlease check your repository or SDK image file."),\r
- CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES("Conflict package removal failed."),\r
- CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES("Updatable package removal failed."),\r
- CONFIG_CANNOT_READ_SERVER_TYPE("Server type cannot be read. Check the server type in the installmanager.conf file."),\r
- CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST("Installation file list not found."),\r
- \r
- //Package error\r
- CANNOT_FIND_REPOSITORY("Cannot find repository. Please check your repository."),\r
- PACKAGE_WRONG_SIZE("Package size incorrect."),\r
- PACKAGE_WRONG_CHECKSUM("Package file checksum error."),\r
- PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL("Install or uninstall package not found."),\r
- INSTALL_SCRIPT_NOT_EXISTS("Install script files not found."),\r
- INSTALL_SCRIPT_FATAL_ERROR("Fatal error occurred while executing install script."),\r
- SCRIPT_FATAL_ERROR("Fatal error occurred while executing post script."),\r
- \r
- // Network error\r
- INTERNET_CONNECTION_ERROR("Server connection failed. Check the network status or set InstallManager settings."),\r
- SERVER_CONNECTION_TIME_OUT("Server connection timed out."),\r
- PROXY_NOT_PROVIDED("Proxy setting missing. Use the '-proxy <proxy-address>:<port>' option."),\r
- PROXY_SERVER_IS_WRONG("Proxy server connection failed. Check the proxy server."),\r
- PROXY_CONNECT_ERROR("Proxy server connection failed. Check the proxy server."),\r
- URL_SECURITY_EXCEPTION("Proxy server URL security error."),\r
- UNKNOWN_HOST_EXCEPTION("Fail to resolve host name."),\r
- URL_PORT_IS_WRONG("Incorrect port number."),\r
- NO_ROUTE_TO_HOST("Server not found. Check the URL."),\r
- NOT_LOGGED_IN("Login failed."),\r
- NOT_SUPPORT_HTTPS_PROTOCOL("HTTPS not supported."),\r
- \r
- //Network download error\r
- NETWORK_DOWNLOADED_FILE_INCORRECTLY("The downloaded file is invalid."),\r
- \r
- //proxy\r
- PROXY_CANNOT_FIND_SETTING("Cannot find proxy settings."),\r
- PROXY_AUTHENTICATION_IS_WRONG("Your authentication is wrong, please enter your correct ID and password."),\r
- \r
- //Http Socket error message\r
- HTTP_ERROR_MESSAGE_403("403 Forbidden is returned by http protocol. " +\r
- "The server can be reached, but the server declined to allow access to the page."),\r
- HTTP_ERROR_MESSAGE_401("Server requires authentication."),\r
- HTTP_ERROR_MESSAGE_407("Proxy requires Authentication "),\r
- HTTP_ERROR_MESSAGE_416("Requested range not satisfiable."),\r
- \r
- //option\r
- WRONG_OPTION("Incorrect option. Check it."),\r
- USESNAPSHOT_REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-snapShot <repository>' option."),\r
- REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-repository <repository>' option."),\r
- PACKAGES_NOT_PROVIDED("Repository setting is missing. Use the '-proxy <repository>' option."),\r
- CANNOT_FIND_INSTALLMANAGER_EXECUTABLE_PATH("Cannot find installmanager executable path."),\r
- \r
- //etc\r
- CANNOT_REMOVE_TARGET_DIR("Target directory removal failed."),\r
- INSTALLATION_STOP("Required packages for the META package not installed."),\r
- UNINSTALLATION_FAIL("Uninstallation failed."),\r
- FILE_NOT_FOUND("File not found."),\r
- FILE_DO_NOT_HAVE_PERMISSION("Do not have permission for the file."),\r
- REMOVE_OLD_SDK_OK("Old SDK uninstallation completed. Restart Install Manager."),\r
- INVALID_INSTALL_PATH("Invalid installation path."),\r
- DOWNLOAD_AND_EXIT("Packages downloaded successfully. Exit Install Manager."),\r
- CANNOT_DOWNLOAD_FILE("File download failed."),\r
- CANNOT_FIND_JAVA("\'JAVA\' not found. Check the java installation."),\r
- UNKOWN_ERROR("Unknown error."),\r
- NO_ERROR("Install Manager error. Send the log file to the Tizen SDK team."),\r
- ERROR_TEMP("Information retrieval from the default SDK package server failed.\n In Advanced Configuration, select the package server and distribution."),\r
- \r
- 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
- 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
- WRONG_PACKAGE_SERVER("Package list files not found. Check the package list files on the package server."),\r
- WRONG_PACKAGE_LIST_FORMAT("Mandatory field missing in the package list file."),\r
- WRONG_URL_FORMAT_HTTP("URL must begin with 'http://'."),\r
- WRONG_URL_FORMAT("Incorrect URL format. Enter the URL in the correct format."),\r
- CANNOT_CONNECT_URL_ADDRESS("Connection to the URL failed. Enter the correct URL."),\r
- PACKAGE_NOT_IN_EXTENSION_SERVER("Package file not found on the package server."),\r
- DUPLICATED_EXTENSION_REPOSITORY("Extension repository URL already exists.\nEnter a different extension repository URL."),\r
- DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY("Built-in extension repository URL already exists.\nEnter a different extension repository URL."),\r
- DUPLICATED_EXTENSION_REPOSITORY_NAME("Extension repository name already exists.\nEnter a different extension repository name."),\r
- DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY_NAME("Built-in extension repository name already exists.\nEnter a different extension repository name.");\r
- \r
- private String errorMessage = "";\r
- \r
- ErrorCode(String arg) {\r
- errorMessage = arg;\r
- }\r
- \r
- public String getErrorMessage() {\r
- return errorMessage;\r
- }\r
- \r
- public void setErrorMessage(String msg) {\r
- errorMessage = msg;\r
- }\r
- \r
- public boolean existErrorMessage() {\r
- if (errorMessage.isEmpty()) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- }\r
- \r
- public enum InfoCode {\r
- CANNOT_KILL_PROCESS("Cannot kill the proecss."),\r
- RESTART_THE_COMPUTER("Some Tizen SDK components may not work yet.\nPlease restart your computer before using Tizen SDK.");\r
- \r
- private String infoMessage = "";\r
- \r
- InfoCode(String arg) {\r
- infoMessage = arg;\r
- }\r
- \r
- public String getInfoMessage() {\r
- return infoMessage;\r
- }\r
- }\r
- \r
- static public boolean isInstallManagerUpdatable = false;\r
- \r
- \r
- static private ErrorCode mErrorCode = ErrorCode.NO_ERROR;\r
- static private boolean mInstallationStatus = true;\r
- static private String errorMsg = "";\r
- static private InfoCode infoCode = null;\r
- \r
- private static int exitCode = Config.EXITCODE_NORMAL;\r
- \r
- /**\r
- * Set error code.\r
- * @param errorCode\r
- */\r
- static public void setError(ErrorCode errorCode) {\r
- mInstallationStatus = false;\r
- mErrorCode = errorCode;\r
- }\r
- \r
- /**\r
- * \r
- * @return Latest error message.\r
- */\r
- static public String getErrorMessage() {\r
- if (mErrorCode != null) { \r
- return mErrorCode.getErrorMessage();\r
- } else {\r
- return errorMsg;\r
- }\r
- }\r
- \r
- static public void setErrorMessage(String msg) {\r
- mInstallationStatus = false;\r
- mErrorCode = null; \r
- errorMsg = msg;\r
- }\r
- \r
- /** \r
- * @return Latest error code.\r
- */\r
- static public ErrorCode getErrorCode() {\r
- return mErrorCode;\r
- }\r
- \r
- /**\r
- * Get information message\r
- * @return\r
- */\r
- static public String getInfoMessage() {\r
- return infoCode.getInfoMessage();\r
- }\r
- \r
- /**\r
- * Set information message\r
- * @param msg\r
- */\r
- static public void setInfoCode(InfoCode info) {\r
- infoCode = info;\r
- }\r
- \r
- static public boolean existInfoMessage() {\r
- if (infoCode == null) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * Set status of installation.\r
- * @param status\r
- */\r
- static public void setInstallationSuccess(boolean status) {\r
- Log.log("Set installation success: "+status);\r
- if (status == true) {\r
- mErrorCode = null;\r
- }\r
- mInstallationStatus = status;\r
- }\r
- \r
- /**\r
- * Get status of installation.\r
- * @return\r
- */\r
- static public boolean checkInstallationSuccess() {\r
- return mInstallationStatus;\r
- }\r
- \r
- /**\r
- * Get error message of e\r
- * @param e\r
- * @return\r
- */\r
- public static String getMessage(ErrorCode e) {\r
- return e.getErrorMessage();\r
- }\r
- \r
- /**\r
- * Sets exit code to be used on exit\r
- * @param exitCode\r
- */\r
- public static void setExitCode(int exitCode) {\r
- ErrorController.exitCode = exitCode;\r
- }\r
- \r
- /**\r
- * Gets exit code to be used on exit\r
- */\r
- public static int getExitCode() {\r
- return ErrorController.exitCode;\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.lib;
+
+ import org.tizen.installmanager.core.Config;
+
+ /**
+ * This class manages error codes and states
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ */
+ public class ErrorController {
+ /**
+ * Define case of error
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ *
+ */
+ public enum ErrorCode {
+ CANNOT_FIND_CONFIG_FILE("The installmanager.conf file not found."),
+ CANNOT_FIND_FILE_IN_REPOSITROY("Cannot find file in repository."),
+ CANNOT_CREATE_DOWNLOAD_FILE("Download file cannot be created."),
+ CANNOT_CHECK_INSTLLED_FILE_LIST("Installed file list cannot be checked."),
+ CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY("File cannot be moved to the target directory."),
+ CANNOT_CONNECT_TO_PROXY_SERVER("Proxy server connection fails."),
+ WRONG_PACKAGE_URL("Package URLs are invalid."),
+ CANCEL("Download canceled."),
+ UNKNOWN_ERROR("Unknown error."),
+ UNKNOWN_PACKAGE_EXTENSION("Package extension not supported."),
+ INVALID_PACKAGE_VERSION("Invalid package version."),
+ CANNOT_FIND_PACKAGE_VERSION("Package version not found."),
+ CANNOT_FIND_INSTALLABLE_OR_REMOVABLE_PACKAGES("Install or uninstall packages not found. Network connection may have failed."),
+ CANNOT_FIND_FILE_IN_LOCAL("Local file not found."),
+ CANNOT_SAVE_CONFIG("Configuration file cannot be saved."),
+ CANNOT_CREATE_SHORTCUT("Shortcut creation is failed."),
+ CANNOT_CREATE_TSUDO("tsudo creation is failed."),
+ CANNOT_CREATE_INSTALL_LIST("Install list creation failed."),
+ CANNOT_CREATE_CONFIG_FILE("Configuration directory or file creation failed."),
+ CANNOT_FIND_USER_CONFIG_FILE("User configuration file creation failed."),
+ CANNOT_REGISTER_TARGET_DIR("Target directory registration failed."),
+ CANNOT_PARSING_TEXT("Configuration file parsing failed."),
+ CANNOT_SAVE_PROPERTY_FILE("The installmanager.conf or Package file cannot be saved."),
+ CANNOT_UNPACK_PACKAGE("The package zip file unpackaging failed."),
+ CANNOT_CREATE_RESOURCE("Resource file creation failed."),
+ CANNOT_FIND_PACKAGE("Required packages not found. The package server may be invalid."),
+ CANNOT_REMOVE_PACKAGE("Package removal failed."),
+ CANNOT_REMOVE_MISSING_PACKAGE("Missing package cannot be removed."),
+ FIND_MISSING_FILES("Some files are not installed properly."),
+ CANNOT_ACCESS_FILE("File access failed."),
+ CANNOT_REMOVE_OLDSDK("Old SDK removal failed."),
+ COPY_FILE_IS_FAIL("Copying the file to the target directory failed."),
+ OLD_TIZEN_SDK_EXISTS("Old Tizen SDK is installed. Remove the old SDK and run the Tizen SDK Install Manager again."),
+ UNSUPPORTED_PLATFORM("Platform not supported."),
+ REMOVE_SCRIPT_NOT_EXISTS("Removal script not found."),
+ REMOVE_SCRIPT_FATAL_ERROR("Fatal error occurred while executing remove script."),
+ INSTALLATION_FAIL("Installation failed."),
+ INSTALL_CANCELED("Installation canceled."),
+ INSTALLED_VERSION_IS_HIGH("Installation progress failed due to high installed package version."),
+ CANNOT_CREATE_FILE("File creation failed."),
+ THREAD_INTERRUPTED("Thread execution interrupted."),
+ CIRCULAR_PACKAGE_DEPENDENCY("Circular package dependency detected."),
+
+ //Configuration file error
+ CONFIG_CANNOT_PARSING_PACKAGE_LIST("Package list cannot be read. Check the repository or proxy server."),
+ CONFIG_CANNOT_FIND_PACKAGE_LIST_FILE_IN_REPOSITORY("Cannot get the package information. " +
+ "\nPlease check your repository or SDK image file."),
+ CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES("Conflict package removal failed."),
+ CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES("Updatable package removal failed."),
+ CONFIG_CANNOT_READ_SERVER_TYPE("Server type cannot be read. Check the server type in the installmanager.conf file."),
+ CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST("Installation file list not found."),
+
+ //Package error
+ CANNOT_FIND_REPOSITORY("Cannot find repository. Please check your repository."),
+ PACKAGE_WRONG_SIZE("Package size incorrect."),
+ PACKAGE_WRONG_CHECKSUM("Package file checksum error."),
+ PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL("Install or uninstall package not found."),
+ INSTALL_SCRIPT_NOT_EXISTS("Install script files not found."),
+ INSTALL_SCRIPT_FATAL_ERROR("Fatal error occurred while executing install script."),
+ SCRIPT_FATAL_ERROR("Fatal error occurred while executing post script."),
+
+ // Network error
+ INTERNET_CONNECTION_ERROR("Server connection failed. Check the network status or set InstallManager settings."),
+ SERVER_CONNECTION_TIME_OUT("Server connection timed out."),
+ PROXY_NOT_PROVIDED("Proxy setting missing. Use the '-proxy <proxy-address>:<port>' option."),
+ PROXY_SERVER_IS_WRONG("Proxy server connection failed. Check the proxy server."),
+ PROXY_CONNECT_ERROR("Proxy server connection failed. Check the proxy server."),
+ URL_SECURITY_EXCEPTION("Proxy server URL security error."),
+ UNKNOWN_HOST_EXCEPTION("Fail to resolve host name."),
+ URL_PORT_IS_WRONG("Incorrect port number."),
+ NO_ROUTE_TO_HOST("Server not found. Check the URL."),
+ NOT_LOGGED_IN("Login failed."),
+ NOT_SUPPORT_HTTPS_PROTOCOL("HTTPS not supported."),
+
+ //Network download error
+ NETWORK_DOWNLOADED_FILE_INCORRECTLY("The downloaded file is invalid."),
+
+ //proxy
+ PROXY_CANNOT_FIND_SETTING("Cannot find proxy settings."),
+ PROXY_AUTHENTICATION_IS_WRONG("Your authentication is wrong, please enter your correct ID and password."),
+
+ //Http Socket error message
+ HTTP_ERROR_MESSAGE_403("403 Forbidden is returned by http protocol. " +
+ "The server can be reached, but the server declined to allow access to the page."),
+ HTTP_ERROR_MESSAGE_401("Server requires authentication."),
+ HTTP_ERROR_MESSAGE_407("Proxy requires Authentication "),
+ HTTP_ERROR_MESSAGE_416("Requested range not satisfiable."),
+
+ //option
+ WRONG_OPTION("Incorrect option. Check it."),
+ USESNAPSHOT_REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-snapShot <repository>' option."),
+ REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-repository <repository>' option."),
+ PACKAGES_NOT_PROVIDED("Repository setting is missing. Use the '-proxy <repository>' option."),
+ CANNOT_FIND_INSTALLMANAGER_EXECUTABLE_PATH("Cannot find installmanager executable path."),
+
+ //etc
+ CANNOT_REMOVE_TARGET_DIR("Target directory removal failed."),
+ INSTALLATION_STOP("Required packages for the META package not installed."),
+ UNINSTALLATION_FAIL("Uninstallation failed."),
+ FILE_NOT_FOUND("File not found."),
+ FILE_DO_NOT_HAVE_PERMISSION("Do not have permission for the file."),
+ REMOVE_OLD_SDK_OK("Old SDK uninstallation completed. Restart Install Manager."),
+ INVALID_INSTALL_PATH("Invalid installation path."),
+ DOWNLOAD_AND_EXIT("Packages downloaded successfully. Exit Install Manager."),
+ CANNOT_DOWNLOAD_FILE("File download failed."),
+ CANNOT_FIND_JAVA("\'JAVA\' not found. Check the java installation."),
+ UNKOWN_ERROR("Unknown error."),
+ NO_ERROR("Install Manager error. Send the log file to the Tizen SDK team."),
+ ERROR_TEMP("Information retrieval from the default SDK package server failed.\n In Advanced Configuration, select the package server and distribution."),
+
+ SNAPSHOT_PATH_IS_NULL("Snapshot path missing."),
+ FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."),
+
+ //Using add extra repository dialog
+ INVALID_REPOSITORY_FOR_HISTORY("Invalid repository for history."),
+ SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."),
+ NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."),
+ HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."),
+ WRONG_PACKAGE_SERVER("Package list files not found. Check the package list files on the package server."),
+ WRONG_PACKAGE_LIST_FORMAT("Mandatory field missing in the package list file."),
+ WRONG_URL_FORMAT_HTTP("URL must begin with 'http://'."),
+ WRONG_URL_FORMAT("Incorrect URL format. Enter the URL in the correct format."),
+ CANNOT_CONNECT_URL_ADDRESS("Connection to the URL failed. Enter the correct URL."),
+ PACKAGE_NOT_IN_EXTENSION_SERVER("Package file not found on the package server."),
+ DUPLICATED_EXTENSION_REPOSITORY("Extension repository URL already exists.\nEnter a different extension repository URL."),
+ DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY("Built-in extension repository URL already exists.\nEnter a different extension repository URL."),
+ DUPLICATED_EXTENSION_REPOSITORY_NAME("Extension repository name already exists.\nEnter a different extension repository name."),
+ DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY_NAME("Built-in extension repository name already exists.\nEnter a different extension repository name.");
+
+ private String errorMessage = "";
+
+ ErrorCode(String arg) {
+ errorMessage = arg;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String msg) {
+ errorMessage = msg;
+ }
+
+ public boolean existErrorMessage() {
+ if (errorMessage.isEmpty()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ }
+
+ public enum InfoCode {
+ CANNOT_KILL_PROCESS("Cannot kill the proecss."),
+ RESTART_THE_COMPUTER("Some Tizen SDK components may not work yet.\nPlease restart your computer before using Tizen SDK.");
+
+ private String infoMessage = "";
+
+ InfoCode(String arg) {
+ infoMessage = arg;
+ }
+
+ public String getInfoMessage() {
+ return infoMessage;
+ }
+ }
+
+ static public boolean isInstallManagerUpdatable = false;
+
+
+ static private ErrorCode mErrorCode = ErrorCode.NO_ERROR;
+ static private boolean mInstallationStatus = true;
+ static private String errorMsg = "";
+ static private InfoCode infoCode = null;
+
+ private static int exitCode = Config.EXITCODE_NORMAL;
+
+ private static int retryCount = 0;
+
+ /**
+ * Set error code.
+ * @param errorCode
+ */
+ static public void setError(ErrorCode errorCode) {
++ mInstallationStatus = false;
+ mErrorCode = errorCode;
+ }
+
+ /**
+ *
+ * @return Latest error message.
+ */
+ static public String getErrorMessage() {
+ if (mErrorCode != null) {
+ return mErrorCode.getErrorMessage();
+ } else {
+ return errorMsg;
+ }
+ }
+
+ static public void setErrorMessage(String msg) {
++ mInstallationStatus = false;
+ mErrorCode = null;
+ errorMsg = msg;
+ }
+
+ /**
+ * @return Latest error code.
+ */
+ static public ErrorCode getErrorCode() {
+ return mErrorCode;
+ }
+
+ /**
+ * Get information message
+ * @return
+ */
+ static public String getInfoMessage() {
+ return infoCode.getInfoMessage();
+ }
+
+ /**
+ * Set information message
+ * @param msg
+ */
+ static public void setInfoCode(InfoCode info) {
+ infoCode = info;
+ }
+
+ static public boolean existInfoMessage() {
+ if (infoCode == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Set status of installation.
+ * @param status
+ */
+ static public void setInstallationSuccess(boolean status) {
+ Log.log("Set installation success: "+status);
+ if (status == true) {
+ mErrorCode = null;
+ }
+ mInstallationStatus = status;
+ }
+
+ /**
+ * Get status of installation.
+ * @return
+ */
+ static public boolean checkInstallationSuccess() {
+ return mInstallationStatus;
+ }
+
+ /**
+ * Get error message of e
+ * @param e
+ * @return
+ */
+ public static String getMessage(ErrorCode e) {
+ return e.getErrorMessage();
+ }
+
+ /**
+ * Sets exit code to be used on exit
+ * @param exitCode
+ */
+ public static void setExitCode(int exitCode) {
+ ErrorController.exitCode = exitCode;
+ }
+
+ /**
+ * Gets exit code to be used on exit
+ */
+ public static int getExitCode() {
+ return ErrorController.exitCode;
+ }
+
+ public static void setNetworkRetryCount(int cnt) {
+ retryCount = cnt;
+ }
+
+ public static int getNetworkRetryCount() {
+ return retryCount;
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */ \r
- \r
- package org.tizen.installmanager.pkg.lib;\r
- \r
- import java.io.File;\r
- import java.io.IOException;\r
- import java.net.MalformedURLException;\r
- import java.net.URL;\r
- import java.util.ArrayList;\r
- import java.util.Collection;\r
- import java.util.HashMap;\r
- import java.util.LinkedList;\r
- import java.util.List;\r
- import java.util.Map;\r
- import java.util.Stack;\r
- \r
- import org.tizen.installmanager.core.Config;\r
- import org.tizen.installmanager.core.Config.ServerType;\r
- import org.tizen.installmanager.core.DistributionController;\r
- import org.tizen.installmanager.core.IMExitException;\r
- import org.tizen.installmanager.core.IMFatalException;\r
- import org.tizen.installmanager.core.InstallManager;\r
- import org.tizen.installmanager.core.Options;\r
- import org.tizen.installmanager.core.SDKExtensionInfo;\r
- import org.tizen.installmanager.lib.Downloader;\r
- import org.tizen.installmanager.lib.ErrorController;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Registry;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.exception.IMNetworkConnectException;\r
- import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;\r
- import org.tizen.installmanager.pkg.lib.darwin.DarwinPackageManager;\r
- import org.tizen.installmanager.pkg.lib.linux.LinuxPackageManager;\r
- import org.tizen.installmanager.pkg.lib.win.WindowsPackageManager;\r
- import org.tizen.installmanager.pkg.model.IMPackageNotFound;\r
- import org.tizen.installmanager.pkg.model.Package;\r
- import org.tizen.installmanager.pkg.model.PackageSet;\r
- import org.tizen.installmanager.pkg.model.Properties;\r
- import org.tizen.installmanager.pkg.model.Property;\r
- import org.tizen.installmanager.pkg.model.PropertySection;\r
- import org.tizen.installmanager.pkg.model.Snapshot;\r
- import org.tizen.installmanager.pkg.model.Version;\r
- import org.tizen.installmanager.util.PathUtil;\r
- \r
- \r
- /**\r
- * Package Manager\r
- * <p>\r
- * This class provides various methods for managing packages.\r
- * Most of the methods handle packages symbolically. Namely, they are identified by its package name not the object if not specially mentioned.\r
- * <p>\r
- * Some methods are carefully designed to preserve the order of packages because the order of packages is important sometimes. \r
- * See the details in the documentation of each methods.\r
- * \r
- * @author Shihyun Kim <shihyun.kim@samsung.com>\r
- *\r
- */\r
- public abstract class PackageManager {\r
- /**\r
- * Packages that are already installed in the system.\r
- */\r
- private PackageSet installedPackages;\r
- /**\r
- * packages that are available in the repositories(package servers).\r
- */\r
- private PackageSet repoPackages;\r
- /**\r
- * packages that combines <code>installedPackages</code> and <code>repoPackages</code>. \r
- * This includes only the latest package from the several versions of a package.\r
- * This is used as the universe set(base set) of packages available.\r
- */\r
- private PackageSet recentPackages;\r
- \r
- /**\r
- * Packages from extension package server.111\r
- */\r
- private PackageSet extensionPackages = new PackageSet();\r
- \r
- private static PackageManager pm = null;\r
- \r
- //repository that installed.\r
- private static String installedRepository = null;\r
- private String currentRepository = null;\r
- \r
- public boolean isInstallInstallManager = false;\r
- \r
- public enum State {\r
- INSTALL,\r
- UNINSTALL;\r
- }\r
- \r
- /**\r
- * It is a position where can installmanager get the package list file \r
- */\r
- private enum Style {\r
- NETWORK,\r
- IMAGE,\r
- EXTRA;\r
- }\r
- \r
- //abstract method\r
- /**\r
- * Get package list file name.\r
- * @return\r
- */\r
- abstract public String getPackageListFileName();\r
- \r
- /**\r
- * Creates and initializes Package Manager instance.\r
- * This combines installed packages and packages from the repositories.\r
- * \r
- * @param installed a file in which installed packages are specified. This can be <code>null</code> if no packages are installed.\r
- * @param repoPackagesUrls a collection of URLs of repositories(package servers). This cannot be <code>null</code>.\r
- * @throws IOException if temporary file cannot created\r
- */\r
- protected PackageManager(File installed, Collection<String> repoPackagesUrls) throws IOException {\r
- setInstalledPackageList(installed);\r
- loadRepositoryPackageList(repoPackagesUrls);\r
- getRecentPackages();\r
- \r
- if (repoPackagesUrls.size() > 0) {\r
- setRepository(repoPackagesUrls.iterator().next());\r
- }\r
- }\r
- \r
- private void setRepository(String repository) {\r
- if (installedRepository == null) {\r
- installedRepository = repository;\r
- }\r
- \r
- currentRepository = repository;\r
- return;\r
- }\r
- \r
- /**\r
- * set repository url to each package.(reposistory url plus package name is complete url.)\r
- * @param repoPackagesUrls\r
- * @throws IOException\r
- */\r
- public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {\r
- HashMap<String,List<PropertySection>> r2sMap = null;\r
- ServerType serverType = Config.getInstance().getConfigFile().getServerType();\r
- \r
- if (serverType == ServerType.LOCAL) { // Using SDK Image\r
- r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);\r
- } else {\r
- r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK); \r
- }\r
- setRepoPackages(r2sMap);\r
- \r
- //Add EXTRAS for extention packages\r
- addExtraMetaPackage();\r
- }\r
- \r
- /**\r
- * set repository url to each package.(reposistory url plus package name is complete url.)\r
- * @param repoPackagesUrls Packgae server list.\r
- * @throws IOException\r
- */\r
- public void loadExtensionPackages() throws IOException {\r
- HashMap<String,List<PropertySection>> repoToSectionsMap = \r
- getRepositoryAndPackageList(SDKExtensionInfo.getInstance().getExtensionRepositories().keySet(),\r
- Style.EXTRA);\r
- \r
- //Update extension packages.\r
- if (repoToSectionsMap != null/*adall && !repoToSectionsMap.isEmpty()*/) {\r
- setExtensionPackages(repoToSectionsMap);\r
- setExtensionPackagesToRecentPackages();\r
- } else {\r
- return;\r
- }\r
- }\r
- \r
- private HashMap<String,List<PropertySection>> getRepositoryAndPackageList\r
- (Collection<String> repoPackagesUrls, Style style) throws IOException {\r
- PropertyParser parser = new PropertyParser();\r
- HashMap<String,List<PropertySection>> r2sMap = new HashMap<String,List<PropertySection>>();\r
- \r
- if(repoPackagesUrls != null) {\r
- for(String repo : repoPackagesUrls) { \r
- URL packageListURL = getPackageListPath(repo, style);\r
- File packageListFile = null;\r
- \r
- if (style != Style.EXTRA) { // Snapshot, Image case\r
- packageListFile = downloadPackageListFile(packageListURL);\r
- if(packageListFile != null) {\r
- r2sMap.put(repo, parser.readFromFile(packageListFile));\r
- }\r
- } else { // Extra extension case\r
- // Get package list file from cache.\r
- URL extraPackageListURL = getPackageListPath(SDKExtensionInfo.getInstance().getExtraPackageListPath(repo), style);\r
- packageListFile = downloadPackageListFile(extraPackageListURL);\r
- if (packageListFile != null) { // If cache does not exist, install manager get it from remote repository.\r
- r2sMap.put(repo, parser.readFromFile(packageListFile));\r
- } else {\r
- // InstallManager can get package list file from remote repository.\r
- packageListFile = downloadPackageListFile(packageListURL);\r
- if (packageListFile != null) {\r
- r2sMap.put(repo, parser.readFromFile(packageListFile));\r
- }\r
- }\r
- }\r
- }\r
- } else {\r
- Log.log("Cannot find repository. This is local installer.");\r
- }\r
- \r
- return r2sMap;\r
- }\r
- \r
- private File downloadPackageListFile(URL packageListURL) throws IOException {\r
- if (packageListURL == null) {\r
- return null;\r
- }\r
- Downloader dl = InstallManager.getDownloader();\r
- File tmp = null;\r
- \r
- if (Options.onlyDownload) {\r
- tmp = new File(PathUtil.getFromCurrDir(getPackageListFileName()));\r
- } else {\r
- tmp = File.createTempFile("Packages", ".list");\r
- tmp.deleteOnExit();\r
- }\r
- \r
- long size = 0;\r
- try {\r
- size = dl.download(packageListURL, tmp.getAbsolutePath(), null);\r
- } catch (IMNetworkConnectException e) {\r
- Log.ExceptionLog(e);\r
- return null;\r
- } catch (IMNetworkDownloadException e) {\r
- Log.ExceptionLog(e);\r
- return null;\r
- }\r
- \r
- if (size > 0) {\r
- return tmp;\r
- } else {\r
- return null;\r
- }\r
- }\r
- \r
- private void setExtensionPackages(HashMap<String,List<PropertySection>> repoToSectionsMap) {\r
- extensionPackages = new PackageSet();\r
- boolean result = setPackages(extensionPackages, repoToSectionsMap, true);\r
- if (!result) {\r
- Log.err("Cannot set extension packages.");\r
- }\r
- }\r
- \r
- private void addExtraMetaPackage() {\r
- if (repoPackages == null) {\r
- repoPackages = new PackageSet();\r
- } else {\r
- if (repoPackages.hasPackageByName("EXTRAS")) {\r
- return;\r
- }\r
- }\r
- \r
- Properties props = new Properties();\r
- \r
- props.add(new Property(Package.FIELD_PACKAGE, "EXTRAS"));\r
- props.add(new Property(Package.FIELD_LABEL, "Extras"));\r
- props.add(new Property(Package.FIELD_ATTRIBUTE, "root"));\r
- props.add(new Property(Package.FIELD_PACKAGE_SIZE, "0"));\r
- props.add(new Property(Package.FIELD_UNCOMPRESSED_SIZE, "0"));\r
- \r
- Package extraPackage = new Package(props);\r
- repoPackages.add(extraPackage);\r
- }\r
- \r
- /**\r
- * Get packages from extension package server.\r
- * @return set of packages\r
- */\r
- public PackageSet getExtensionPackages() {\r
- return extensionPackages;\r
- }\r
- \r
- public PackageSet getInstalledExtensionPackages() {\r
- PackageSet extensionPackages = new PackageSet();\r
- PackageSet pkgs = this.getInstalledPackages();\r
- \r
- \r
- for (Package pkg : pkgs) {\r
- if (pkg.isExtensionPackage()) {\r
- extensionPackages.add(pkg);\r
- }\r
- }\r
- \r
- return extensionPackages;\r
- }\r
- \r
- /**\r
- * Set installed packages.\r
- * @param installedPackageListPath\r
- */\r
- public void setInstalledPackageList(File installedPackageListPath) {\r
- List<PropertySection> sectionsInstalled = null;\r
- PropertyParser parser = new PropertyParser();\r
- \r
- if(installedPackageListPath != null) {\r
- sectionsInstalled = parser.readFromFile(installedPackageListPath);\r
- } else {\r
- sectionsInstalled= new LinkedList<PropertySection>();\r
- }\r
- \r
- if (sectionsInstalled != null) {\r
- setInstalledPackageList(sectionsInstalled); \r
- }\r
- }\r
- \r
- /**\r
- * Set installed packages\r
- * @param sections\r
- */\r
- private void setInstalledPackageList(List<PropertySection> sections) {\r
- installedPackages = new PackageSet();\r
- \r
- for(PropertySection sect : sections) {\r
- installedPackages.add(new Package(sect.getProperties()));\r
- }\r
- }\r
- \r
- public void installedPackagesFree() {\r
- installedPackages = null;\r
- }\r
- \r
- /**\r
- * Get package list file path from url.\r
- * @param url\r
- * @return Full url path\r
- */\r
- private URL getPackageListPath(String url, Style style) {\r
- if (url == null || url.isEmpty()) {\r
- return null;\r
- } else {\r
- String packageListURL = "";\r
- \r
- if (style == Style.NETWORK) {\r
- String snapshotPath = Config.getInstance().getSnapshotPath();\r
- \r
- if (snapshotPath == null || snapshotPath.isEmpty() || snapshotPath.equalsIgnoreCase("null")) {\r
- String distribution = Config.getInstance().getConfigFile().getDistribution();\r
- \r
- Snapshot latestSnapshot = DistributionController.getInstance().getLatestSnapshot(distribution);\r
- if (latestSnapshot == null) {\r
- return null;\r
- } else {\r
- snapshotPath = DistributionController.getInstance().getLatestSnapshot(distribution).getPath();\r
- }\r
- }\r
- \r
- packageListURL = PathUtil.addURLPath(url,\r
- snapshotPath, \r
- getPackageListFileName());\r
- } else {\r
- packageListURL = PathUtil.addURLPath(url, getPackageListFileName());\r
- }\r
- \r
- try {\r
- return new URL(packageListURL);\r
- } catch (MalformedURLException e) {\r
- Log.ExceptionLog(e);\r
- return null;\r
- }\r
- }\r
- }\r
- \r
- \r
- \r
- /**\r
- * @return installed packages\r
- */\r
- public PackageSet getInstalledPackages() {\r
- return (PackageSet) installedPackages.clone();\r
- }\r
- \r
- /**\r
- * Set packages of repository\r
- * @param sections\r
- */\r
- protected void setRepoPackages( Map<String,List<PropertySection>> repoToSectionsMap) {\r
- repoPackages = new PackageSet();\r
- boolean result = setPackages(repoPackages, repoToSectionsMap, false);\r
- if (!result) {\r
- Log.err("Cannot find repository. Please check your repository.");\r
- ErrorController.setError(ErrorCode.CANNOT_FIND_REPOSITORY);\r
- }\r
- }\r
- \r
- /**\r
- * Set packages to <code>destPackages</code>\r
- * @param destPackages It is set of packages.\r
- * @param repoToSectionsMap It is added to <code>destPackages</code>\r
- */\r
- private boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {\r
- if (destPackages == null) {\r
- destPackages = new PackageSet();\r
- }\r
- \r
- if (repoToSectionsMap == null || repoToSectionsMap.isEmpty()) {\r
- return false;\r
- }\r
- \r
- for(String repoBaseUrl : repoToSectionsMap.keySet()) {\r
- for(PropertySection sect : repoToSectionsMap.get(repoBaseUrl)) {\r
- Package pkg = new Package(sect.getProperties(), repoBaseUrl);\r
- Log.log("Check valid package version. => " + pkg);\r
- pkg.getVersion(); // Vaild version check.\r
- if (isExtensionPackage) {\r
- if (pkg.getAttribute().equalsIgnoreCase("extra")) {\r
- pkg.setExtensionServer(repoBaseUrl);\r
- destPackages.add(pkg);\r
- }\r
- } else {\r
- destPackages.add(pkg);\r
- \r
- }\r
- }\r
- }\r
- return true;\r
- }\r
- \r
- /**\r
- * @return packages of repository\r
- */\r
- public PackageSet getRepoPackages() {\r
- return repoPackages;\r
- }\r
- \r
- /**\r
- * Set repository packages.\r
- * @param packageSet\r
- */\r
- public void setRepoPackages(PackageSet packageSet) {\r
- repoPackages = packageSet;\r
- }\r
- \r
- /**\r
- * @return root meta packages of repository\r
- */\r
- public PackageSet getRootMetaPackagesOfRepository() {\r
- PackageSet clone = (PackageSet) repoPackages.clone();\r
- \r
- // Repository packages should not have extension packages.\r
- for (Package pkg : repoPackages) {\r
- if (pkg.isExtensionPackage()) {\r
- clone.remove(pkg);\r
- }\r
- }\r
- \r
- repoPackages = clone;\r
- \r
- return rootMeta(repoPackages);\r
- }\r
- \r
- /**\r
- * Get install meta packages from repository.\r
- * @return\r
- */\r
- public PackageSet getInstallMetaPackagesOfRepository() {\r
- return installMeta(repoPackages);\r
- }\r
- \r
- /**\r
- * Get root meta package from extension package server()\r
- */\r
- public PackageSet getRootMetaPackagesOfExtensionServer() {\r
- return rootMeta(extensionPackages);\r
- }\r
- \r
- /**\r
- * @return recent packages. This includes the latest packages among all packages from currently \r
- * installed packages and packages of repository if a package has several versions.\r
- */\r
- public PackageSet getRecentPackages() {\r
- if(recentPackages == null) {\r
- recentPackages = new PackageSet();\r
- for(Package ip : installedPackages) {\r
- if(repoPackages != null && repoPackages.contains(ip)) {\r
- Package rp = repoPackages.getPackage(ip);\r
- Log.log("Repo packages : " + repoPackages);\r
- if(ip.getVersion().compareTo(rp.getVersion()) > 0) {\r
- recentPackages.add(ip);\r
- } else {\r
- recentPackages.add(rp);\r
- }\r
- } else if (extensionPackages != null && extensionPackages.contains(ip)) {\r
- Package ep = extensionPackages.getPackage(ip);\r
- if(ip.getVersion().compareTo(ep.getVersion()) > 0) {\r
- recentPackages.add(ip);\r
- } else {\r
- recentPackages.add(ep);\r
- }\r
- } else {\r
- recentPackages.add(ip);\r
- }\r
- }\r
- \r
- if (repoPackages != null) {\r
- for(Package rp : repoPackages) {\r
- if(!recentPackages.contains(rp)) {\r
- recentPackages.add(rp);\r
- }\r
- }\r
- }\r
- }\r
- return recentPackages;\r
- }\r
- \r
- private void setExtensionPackagesToRecentPackages() {\r
- if (recentPackages == null) {\r
- recentPackages = new PackageSet();\r
- }\r
- \r
- for(Package ip : installedPackages) {\r
- if (extensionPackages != null && extensionPackages.contains(ip)) {\r
- Package ep = extensionPackages.getPackage(ip);\r
- if(ip.getVersion().compareTo(ep.getVersion()) > 0) {\r
- recentPackages.add(ip);\r
- } else {\r
- recentPackages.add(ep);\r
- }\r
- } else {\r
- recentPackages.add(ip);\r
- }\r
- }\r
- }\r
- \r
- \r
- \r
- // Methods for update process\r
- /**\r
- * except package from installed package list. \r
- * @param pkg\r
- * @return\r
- */\r
- public boolean exceptPackageFromInstalledPackages(Package pkg) {\r
- return installedPackages.remove(pkg);\r
- }\r
- \r
- /**\r
- * Add package to installed package list.\r
- * @param pkg\r
- * @return\r
- */\r
- public boolean addPackageToInstalledPackages(Package pkg) {\r
- installedPackages.remove(pkg);\r
- return installedPackages.add(pkg);\r
- }\r
- \r
- /**\r
- * @return updatable packages among installed packages\r
- */\r
- public PackageSet getUpdatableInstalledPackages() {\r
- PackageSet updatables = new PackageSet();\r
- for(Package ip : installedPackages) {\r
- if(repoPackages.contains(ip)) {\r
- Package rp = repoPackages.getPackage(ip);\r
- if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
- updatables.add(ip);\r
- }\r
- }\r
- }\r
- return updatables;\r
- }\r
- \r
- /**\r
- * if pkg is updatable, return true. else return false.\r
- * @param pkg\r
- * @return\r
- */\r
- public boolean isUpdatable(Package pkg) {\r
- if (pkg == null) {\r
- return false;\r
- }\r
- \r
- PackageSet updatables = getUpdatableInstalledPackages();\r
- if (updatables.contains(pkg)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public boolean isInstalledPackage(Package pkg) {\r
- if (pkg == null) {\r
- return false;\r
- }\r
- \r
- if (installedPackages.contains(pkg)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * If package set of repository is empty, return true;\r
- * @return\r
- */\r
- public boolean isRepoPackagesEmpty() {\r
- if (repoPackages == null || repoPackages.isEmpty()) {\r
- return true;\r
- } else if (repoPackages.size() == 1) {\r
- if (repoPackages.getPackageByName("EXTRAS") != null) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * If pkg is installed, return true. else return false\r
- * @param pkg\r
- * @return\r
- */\r
- public boolean isInstalledVersion(Package pkg) {\r
- Package installedPackage = installedPackages.getPackage(pkg);\r
- if (installedPackage == null) {\r
- return false;\r
- } else {\r
- Version installedVersion = installedPackage.getVersion();\r
- if (installedVersion.compareTo(pkg.getVersion()) == 0) {\r
- return true;\r
- } else {\r
- return false;\r
- } \r
- }\r
- }\r
- \r
- public PackageSet getRecentMetaPackages() {\r
- PackageSet recentPackages = union(repoPackages, installedPackages);\r
- return rootMeta(recentPackages);\r
- }\r
- \r
- /**\r
- * @return meta packages among installed packages\r
- */\r
- public PackageSet getInstalledMetaPackages() {\r
- return meta(installedPackages);\r
- }\r
- \r
- public List<String> getInstalledMetaNames() {\r
- ArrayList<String> installedMetaNames = new ArrayList<String>();\r
- \r
- for (Package meta : getInstalledMetaPackages()) {\r
- installedMetaNames.add(meta.getPackageName());\r
- }\r
- \r
- return installedMetaNames;\r
- }\r
- \r
- public List<String> getInstalledPkgNames() {\r
- ArrayList<String> installedPkgNames = new ArrayList<String>();\r
- \r
- for (Package pkg : getInstalledPackages()) {\r
- installedPkgNames.add(pkg.getPackageName());\r
- }\r
- \r
- return installedPkgNames;\r
- }\r
- \r
- /**\r
- * @return meta packages among all recent packages\r
- */\r
- public PackageSet getAllMetaPackages() {\r
- PackageSet allMeta = new PackageSet();\r
- \r
- PackageSet recentMeta = meta(recentPackages);\r
- PackageSet extensionMeta = meta(extensionPackages);\r
- \r
- allMeta.addAll(recentMeta);\r
- allMeta.addAll(extensionMeta);\r
- \r
- return allMeta;\r
- }\r
- \r
- public PackageSet getLeafMetaPackages() {\r
- PackageSet allMetas = meta(recentPackages);\r
- \r
- PackageSet leafMetas = new PackageSet();\r
- for (Package meta : allMetas) {\r
- //if (depends size <= 0) is leaf\r
- if (meta.getDependentPackageNames().size() <= 0) {\r
- leafMetas.add(meta);\r
- } else {\r
- if (!isChildrenAllMeta(meta)) {\r
- leafMetas.add(meta);\r
- }\r
- }\r
- }\r
- \r
- return leafMetas;\r
- }\r
- \r
- public PackageSet getInstalledLeafMetaPackages() {\r
- PackageSet allMetas = meta(installedPackages);\r
- \r
- PackageSet leafMetas = new PackageSet();\r
- for (Package meta : allMetas) {\r
- //if (depends size <= 0) is leaf\r
- if (meta.getDependentPackageNames().size() <= 0) {\r
- leafMetas.add(meta);\r
- } else {\r
- if (!isChildrenAllMeta(meta)) {\r
- leafMetas.add(meta);\r
- }\r
- }\r
- }\r
- \r
- return leafMetas;\r
- }\r
- \r
- private boolean hasMetaPackagesInChildren(Package pkg) {\r
- PackageSet dependPackages = getDependsPackages(pkg);\r
- \r
- if (dependPackages == null) {\r
- return true;\r
- } else {\r
- for (Package dPackage : dependPackages) {\r
- if (dPackage.isMeta()) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- }\r
- private boolean isChildrenAllMeta(Package pkg) { \r
- PackageSet dependPackages = getDependsPackages(pkg);\r
- \r
- if (dependPackages == null) {\r
- return true;\r
- } else {\r
- for (Package dPackage : dependPackages) {\r
- if (!dPackage.isMeta()) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- }\r
- \r
- private PackageSet getDependsPackages(Package pkg) {\r
- PackageSet dependPackages = new PackageSet();\r
- if (pkg == null) {\r
- return dependPackages;\r
- }\r
- \r
- Collection<String> depends = pkg.getDependentPackageNames();\r
- \r
- try {\r
- dependPackages = recentPackages.getPackagesByNames(depends);\r
- } catch (IMPackageNotFound e) {\r
- Log.ExceptionLog(e);\r
- }\r
- return dependPackages;\r
- }\r
- \r
- /**\r
- * @return partner meta packages among all meta packages.\r
- */\r
- public PackageSet getPartnerMetaPackages() {\r
- PackageSet allMetas = meta(recentPackages);\r
- \r
- PackageSet partnerMeta = new PackageSet();\r
- for (Package meta : allMetas) {\r
- if (meta.isPartnerMeta()) {\r
- partnerMeta.add(meta);\r
- }\r
- }\r
- \r
- return partnerMeta;\r
- }\r
- \r
- /**\r
- * @return public meta packages among all meta packages.\r
- */\r
- public PackageSet getPublicMetaPackages() {\r
- PackageSet allMetas = meta(recentPackages);\r
- \r
- PackageSet publicMeta = new PackageSet();\r
- for (Package meta : allMetas) {\r
- if (meta.isPublicMeta()) {\r
- publicMeta.add(meta);\r
- }\r
- }\r
- \r
- return publicMeta;\r
- }\r
- \r
- /**\r
- * Get dependency packages of installable package.\r
- * @param pkgs installable packages.\r
- * @return\r
- */\r
- public PackageSet getDependsPackagesFromRepository(PackageSet pkgs) {\r
- return dep(pkgs, State.INSTALL);\r
- }\r
- \r
- /**\r
- * @return meta packages that have no updates considering its dependents\r
- */\r
- public PackageSet getNotUpdatableMetaPackages() {\r
- PackageSet noup = new PackageSet();\r
- for(Package m : getAllMetaPackages()) {\r
- if(!isMetaUpdatable(m)) {\r
- noup.add(m);\r
- }\r
- }\r
- return noup;\r
- }\r
- \r
- public PackageSet getNotInstallableAndNotUpdatablePackages() {\r
- PackageSet notPkg = new PackageSet();\r
- \r
- for (Package m :getAllMetaPackages()) {\r
- if (isMetaRemovable(m) && !isMetaUpdatable(m)) {\r
- notPkg.add(m);\r
- }\r
- }\r
- \r
- return notPkg;\r
- }\r
- \r
- /**\r
- * @return meta packages thar are updatable among installed packages\r
- */\r
- public PackageSet getUpdatableMetaPackages() {\r
- PackageSet allMetas = getAllMetaPackages();\r
- PackageSet notUpdatableMetas = getNotUpdatableMetaPackages(); \r
- return diff(allMetas, notUpdatableMetas);\r
- }\r
- \r
- public PackageSet getUpdatableInstalledMetaPackages() {\r
- PackageSet installedMeta = getInstalledMetaPackages();\r
- PackageSet updatableMeta = getUpdatableMetaPackages();\r
- return intersect(installedMeta, updatableMeta);\r
- }\r
- \r
- /**\r
- * @param selectedMetas\r
- * @return packages that will be installed after update/install resulted from the selected meta packages\r
- */ \r
- public PackageSet getResultPackagesAfterUpdate(PackageSet selectedMetas) {\r
- PackageSet deps = dep(selectedMetas, State.INSTALL);\r
- PackageSet conflicts = conflictPackages(selectedMetas);\r
- PackageSet remainedFromConflicts = diff(installedPackages, conflicts);\r
- return union(deps, remainedFromConflicts);\r
- }\r
- \r
- /**\r
- * Get updatable packages in update process except new packages.\r
- * @param packageSet\r
- * @return\r
- */\r
- public PackageSet getUpdatablePackagesInUpdate(PackageSet packageSet) {\r
- PackageSet result = dep(packageSet, State.INSTALL);\r
- PackageSet up = getUpdatableInstalledPackages();\r
- return intersect(result, up);\r
- }\r
- \r
- /**\r
- * Get removable packages in snapshot process except new packages.\r
- * @param selectedMetas\r
- * @return\r
- */\r
- public PackageSet getRemovablePackagesInSnapshot(PackageSet selectedMetas) {\r
- PackageSet result = dep(selectedMetas, State.UNINSTALL);\r
- PackageSet pkgSet = getdifferentVersionFromInstalledPackages(result);\r
- \r
- return pkgSet;\r
- }\r
- \r
- /**\r
- * check version between sourcePackages and installedPackages, and return different version packages.\r
- * @param pkgs \r
- * @return Different version packages among installed packages\r
- */\r
- public PackageSet getdifferentVersionFromInstalledPackages(PackageSet pkgs) {\r
- PackageSet depPkgs = dep(pkgs, State.INSTALL);\r
- PackageSet otherVersionPackages = new PackageSet();\r
- for(Package ip : installedPackages) {\r
- if(depPkgs.contains(ip)) {\r
- Package rp = depPkgs.getPackage(ip);\r
- if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
- otherVersionPackages.add(ip);\r
- }\r
- }\r
- }\r
- \r
- return otherVersionPackages;\r
- }\r
- \r
- /**\r
- * @param selectedMetas\r
- * @return packages to newly install in update process by the selected meta packages\r
- */\r
- public PackageSet getInstallablePackages(PackageSet selectedMetas) {\r
- PackageSet installablePackages = null;\r
- if (isReInstall()) {\r
- installablePackages = dep(selectedMetas, State.INSTALL);\r
- } else if (Config.isSupportMultiSDK()) {\r
- if (Config.status == Config.Status.INSTALL) {\r
- installablePackages = dep(selectedMetas, State.INSTALL); \r
- } else if (Config.status == Config.Status.UPDATE) {\r
- PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
- installablePackages = diffPackageWithVersion(result, installedPackages);\r
- }\r
- } else {\r
- PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
- installablePackages = diffPackageWithVersion(result, installedPackages);\r
- }\r
- \r
- return installablePackages;\r
- }\r
- \r
- /**\r
- * @param selectedMetas\r
- * @return packages to update in update process by the selected meta packages\r
- */\r
- public PackageSet getToUpdatePackagesInUpdate(PackageSet selectedMetas) {\r
- PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
- PackageSet up = getUpdatableInstalledPackages();\r
- return intersect(result, up);\r
- }\r
- \r
- \r
- /**\r
- * Get conflict packages that installed.\r
- * @param packageSet\r
- * @return packages to remove in update process by conflicts with the selected meta packages \r
- */\r
- public PackageSet getConflictPackagesInUpdate(PackageSet packageSet) { \r
- return intersect(installedPackages, getConflictPackages(packageSet));\r
- }\r
- \r
- /**\r
- * Get conflict packages that contain reverse depends packages. \r
- * @param packageSet\r
- * @return\r
- */\r
- public PackageSet getConflictPackages(PackageSet packageSet) {\r
- PackageSet conflicts = conflictPackages(packageSet);\r
- \r
- conflicts.addAll(reverseDep(conflicts));\r
- return intersect(getConflictMetaPackages(), conflicts);\r
- }\r
- \r
- /**\r
- * Get conflict packages that contain reverse depends packages. \r
- * @param packageSet\r
- * @return\r
- */\r
- public PackageSet getConflictPackages(Package pkg) {\r
- PackageSet conflicts = conflictPackages(pkg);\r
- \r
- conflicts.addAll(reverseDep(conflicts));\r
- return intersect(getConflictMetaPackages(), conflicts);\r
- }\r
- \r
- private PackageSet getConflictMetaPackages() { \r
- PackageSet leafMetas = new PackageSet();\r
- for (Package meta : recentPackages) {\r
- //if (depends size <= 0) is leaf\r
- if (meta.getDependentPackageNames().size() <= 0) {\r
- leafMetas.add(meta);\r
- } else {\r
- if (!hasMetaPackagesInChildren(meta)) {\r
- leafMetas.add(meta);\r
- }\r
- }\r
- }\r
- \r
- return leafMetas;\r
- }\r
- \r
- // Methods for remove process\r
- \r
- /**\r
- * @return packages that can be removed\r
- */\r
- public PackageSet getRemovableMetaPackages() {\r
- return getInstalledMetaPackages();\r
- }\r
- \r
- public PackageSet getInstallableMetaPackagesInSnapshot() {\r
- PackageSet repoMetas = meta(repoPackages);\r
- \r
- PackageSet installableMeta = new PackageSet();\r
- for (Package metaPackage : repoMetas) {\r
- if (isMetaInstallable(metaPackage)) {\r
- installableMeta.add(metaPackage);\r
- }\r
- }\r
- \r
- return installableMeta;\r
- }\r
- \r
- /**\r
- * Get remove packages by selected metas.\r
- * @param selectedMetas\r
- * @return packages to remove in remove process\r
- */\r
- public PackageSet getToRemovePackagesInRemove(PackageSet selectedMetas) {\r
- if (Options.doRemoveNoUI) {\r
- // When installmanager removes specific packages, it should consider package dependency.\r
- // For example, 'sdb' package depends on 'tizen-web-cli' and 'tizen-native-cli'.\r
- // In this case, when installmanager removes 'tizen-web-cli' package, 'sdb' package should\r
- // not be removed because of 'tizen-native-cli'.\r
- \r
- // Get candidate packages to remove. \r
- PackageSet depMetas = getDependMetas(selectedMetas, State.UNINSTALL);\r
- PackageSet dep = dep(depMetas, State.UNINSTALL);\r
- PackageSet mayRemove = intersect(installedPackages, dep);\r
- \r
- // Get packages to remain.\r
- PackageSet remainMetas = diff(getInstalledLeafMetaPackages(), depMetas);\r
- PackageSet remainPackages = dep(remainMetas, State.UNINSTALL);\r
- \r
- // Get packages to remove.\r
- PackageSet toRemove = diff(mayRemove, remainPackages);\r
- return reverseSet(toRemove); \r
- } else {\r
- // InstallManager removes whole SDK.\r
- PackageSet dep = dep(selectedMetas, State.UNINSTALL);\r
- return reverseSet(dep);\r
- }\r
- }\r
- \r
- /**\r
- * @param selectedMetas\r
- * @return packages that will be remained after remove resulted from the selected meta packages\r
- */\r
- public PackageSet getResultPackagesAfterRemove(PackageSet selectedMetas) {\r
- return diff(getInstalledMetaPackages(), selectedMetas);\r
- }\r
- \r
- // set handling methods\r
- \r
- /**\r
- * @param pset\r
- * @return meta packages in the package set\r
- */\r
- private PackageSet meta(PackageSet pset) {\r
- PackageSet metas = new PackageSet();\r
- \r
- if (pset == null) {\r
- return metas;\r
- }\r
- \r
- for(Package p : pset) {\r
- if(p.isMeta()) {\r
- metas.add(p);\r
- }\r
- }\r
- return metas;\r
- }\r
- \r
- /**\r
- * @param pset\r
- * @return meta packages in the package set\r
- */\r
- private PackageSet rootMeta(PackageSet pset) {\r
- PackageSet metas = new PackageSet();\r
- for(Package p : pset) {\r
- if (!Options.doTest) {\r
- if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta()) {\r
- metas.add(p);\r
- }\r
- } else {\r
- if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta() || p.isTestMeta()) {\r
- metas.add(p);\r
- }\r
- }\r
- }\r
- return metas;\r
- }\r
- \r
- /**\r
- * @param pset\r
- * @return meta packages in the package set\r
- */\r
- private PackageSet installMeta(PackageSet pset) {\r
- PackageSet metas = new PackageSet();\r
- for(Package p : pset) {\r
- if(p.isInstallMeta()) {\r
- metas.add(p);\r
- }\r
- }\r
- return metas;\r
- }\r
- \r
- /**\r
- * Get dependency package list from p.\r
- * @param p a package\r
- * @return all the packages that the given package depends on directly or indirectly\r
- */\r
- private PackageSet dep(Package p, State state) {\r
- // depth first traverse on dependency graph\r
- PackageSet dep = new PackageSet();\r
- Stack<Package> pkgStack = new Stack<Package>();\r
- pkgStack.push(p);\r
- while(!pkgStack.isEmpty()) {\r
- Package pkg = pkgStack.pop();\r
- \r
- if(!dep.contains(pkg)) {\r
- dep.add(pkg);\r
- PackageSet depPackageSet = new PackageSet();\r
- try {\r
- if (state == State.INSTALL) {\r
- if (repoPackages.contains(pkg)) {\r
- depPackageSet = repoPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
- } else if (extensionPackages.contains(pkg)) {\r
- depPackageSet = extensionPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
- }\r
- } else if (state == State.UNINSTALL){\r
- depPackageSet = installedPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
- } else {\r
- Log.err("State class have two state(INSTALL/UNINSTALL) ");\r
- throw new IMFatalException(ErrorCode.UNKOWN_ERROR); \r
- }\r
- } catch (IMPackageNotFound e) {\r
- Log.err("Finding dependents: "+p+": Package does not exist: " + e.getPackageName()+ " or "+ pkg.getDependentPackageNames());\r
- throw new IMFatalException(ErrorCode.CANNOT_FIND_PACKAGE);\r
- }\r
- \r
- for(Package depPkg : depPackageSet) {\r
- if(p.equals(depPkg)) {\r
- Log.err("Circular dependency found: "+p);\r
- throw new IMFatalException(ErrorCode.CIRCULAR_PACKAGE_DEPENDENCY);\r
- }\r
- pkgStack.push(depPkg);\r
- }\r
- } else {\r
- // already visited.\r
- addDependsSet(dep, pkg);\r
- }\r
- }\r
- \r
- return reverseSet(dep);\r
- }\r
- \r
- private PackageSet reverseDep(PackageSet packages) {\r
- PackageSet reversePackages = new PackageSet();\r
- \r
- for (Package pkg : packages) {\r
- reversePackages.addAll(reverseDep(pkg));\r
- }\r
- \r
- return reversePackages;\r
- }\r
- \r
- /**\r
- * Need reverse depends when remove.\r
- * @param p\r
- * @return\r
- */\r
- private PackageSet reverseDep(Package p) {\r
- // depth first traverse on dependency graph\r
- PackageSet reverseDep = new PackageSet();\r
- Stack<Package> pkgStack = new Stack<Package>();\r
- pkgStack.push(p);\r
- while(!pkgStack.isEmpty()) {\r
- Package pkg = pkgStack.pop();\r
- \r
- if(!reverseDep.contains(pkg)) {\r
- reverseDep.add(pkg);\r
- \r
- for (Package recentPkg : recentPackages) {\r
- Collection<String> dependsList = recentPkg.getDependentPackageNames();\r
- for (String pkgName : dependsList) {\r
- if (pkgName.equals(pkg.getPackageName())) {\r
- pkgStack.push(recentPkg);\r
- break;\r
- }\r
- }\r
- \r
- }\r
- } else {\r
- // already visited\r
- addDependsSet(reverseDep, pkg);\r
- }\r
- }\r
- \r
- return reverseDep;\r
- }\r
- \r
- /**\r
- * Remove saved package and save package at the end of set.\r
- * @param dependsSet\r
- * @param pkg\r
- */\r
- private void addDependsSet(PackageSet dependsSet, Package pkg) {\r
- if (dependsSet.contains(pkg)) {\r
- dependsSet.remove(pkg);\r
- }\r
- \r
- dependsSet.add(pkg);\r
- }\r
- \r
- /**\r
- * reverse package list.\r
- * @param pkgSet\r
- * @return\r
- */\r
- public PackageSet reverseSet(PackageSet pkgSet) {\r
- if (pkgSet == null) {\r
- return null;\r
- }\r
- \r
- Stack<Package> stack = new Stack<Package>();\r
- for (Package pkg : pkgSet) {\r
- stack.push(pkg);\r
- }\r
- \r
- PackageSet reverseSet = new PackageSet();\r
- \r
- while(!stack.isEmpty()) {\r
- reverseSet.add(stack.pop());\r
- }\r
- \r
- return reverseSet;\r
- }\r
- \r
- /**\r
- * @param pset package set\r
- * @return all the packages that the given packages depends on directly or indirectly\r
- */\r
- private PackageSet dep(PackageSet pset, State state) {\r
- PackageSet dep = new PackageSet();\r
- for(Package p : pset) {\r
- dep.addAll(dep(p, state));\r
- }\r
- return dep;\r
- }\r
- \r
- /**\r
- * Get conflict package list from p.\r
- * @param p\r
- * @return packages that conflict with the given package directly or indirectly\r
- */\r
- public PackageSet conflictPackages(Package p) {\r
- PackageSet conflicts = new PackageSet();\r
- PackageSet dep = dep(p, State.INSTALL);\r
- for(Package pkg : dep) {\r
- Collection<String> conflictPackageNames = pkg.getConflictPackageNames();\r
- for(String conflictPackageName : conflictPackageNames) {\r
- if(installedPackages.hasPackageByName(conflictPackageName)) {\r
- Package conflictPackage = installedPackages.getPackageByName(conflictPackageName);\r
- conflicts.addAll(reverseDep(conflictPackage));\r
- } else if (repoPackages.hasPackageByName(conflictPackageName)) {\r
- Package conflictPackage = repoPackages.getPackageByName(conflictPackageName);\r
- conflicts.addAll(reverseDep(conflictPackage));\r
- }\r
- }\r
- }\r
- return conflicts;\r
- }\r
- \r
- /**\r
- * Get conflict package list.\r
- * @param pset\r
- * @return packages that conflict with the given packages directly or indirectly \r
- */\r
- public PackageSet conflictPackages(PackageSet pset) {\r
- PackageSet conflicts = new PackageSet();\r
- for(Package p : pset) {\r
- conflicts.addAll(conflictPackages(p));\r
- }\r
- return conflicts;\r
- }\r
- \r
- /**\r
- * Adds packages of pset2 to packages of pset1.\r
- * @param pset1\r
- * @param pset2\r
- * @return new package set has the union of pset1 and pset2.\r
- */\r
- private PackageSet union(PackageSet pset1, PackageSet pset2) {\r
- PackageSet union = (PackageSet) pset1.clone();\r
- union.addAll(pset2);\r
- return union;\r
- }\r
- \r
- /**\r
- * Removes packages of pset2 from packages of pset1.\r
- * @param pset1\r
- * @param pset2\r
- * @return new package set that represents (pset1 - pset2). \r
- */\r
- public PackageSet diff(PackageSet pset1, PackageSet pset2) {\r
- PackageSet diff = new PackageSet();\r
- for(Package p : pset1) {\r
- if(!pset2.contains(p)) {\r
- diff.add(p);\r
- }\r
- }\r
- return diff;\r
- }\r
- \r
- private PackageSet diffPackageWithVersion(PackageSet pset1, PackageSet pset2) {\r
- PackageSet diff = new PackageSet();\r
- for(Package p : pset1) {\r
- Package pkg = pset2.getPackage(p);\r
- \r
- if (pkg == null) {\r
- diff.add(p);\r
- } else {\r
- if (Version.compareTo(p.getVersion(), pkg.getVersion()) != 0) {\r
- diff.add(p);\r
- }\r
- }\r
- }\r
- return diff;\r
- }\r
- \r
- /**\r
- * \r
- * @param pset1\r
- * @param pset2\r
- * @return new set of intersection of pset1 and pset2. It has the order of pset1.\r
- */\r
- private PackageSet intersect(PackageSet pset1, PackageSet pset2) {\r
- PackageSet pset = new PackageSet();\r
- for(Package p : pset1) {\r
- if(pset2.contains(p)) {\r
- pset.add(p);\r
- }\r
- }\r
- return pset;\r
- }\r
- \r
- private PackageSet getDependMetas(PackageSet packageSet, State state) {\r
- PackageSet depMetas = new PackageSet();\r
- PackageSet depPkgs = dep(packageSet, state);\r
- for (Package p : depPkgs) {\r
- if (p.isMeta()) {\r
- depMetas.add(p);\r
- }\r
- }\r
- \r
- return depMetas;\r
- }\r
- \r
- /**\r
- * @param m meta package to be checked updatable\r
- * @return <code>true</code> if the meta package is updatable. \r
- * ie. the meta package is installed and one of its dependents is already installed and is updatable.\r
- */\r
- public boolean isMetaUpdatable(Package m) { \r
- // if one of the meta package's dependents is installed and updatable, the meta package is updatable.\r
- PackageSet dep = dep(m, State.INSTALL);\r
- \r
- for(Package p : dep) {\r
- \r
- if(installedPackages.contains(p)) {\r
- Package ip = installedPackages.getPackage(p);\r
- if (ip == null) {\r
- continue;\r
- }\r
- \r
- Package rp = null;\r
- if (repoPackages != null && repoPackages.hasPackage(p)) {\r
- rp = repoPackages.getPackage(p);\r
- } else if (extensionPackages != null && extensionPackages.hasPackage(p)) {\r
- rp = extensionPackages.getPackage(p);\r
- }\r
- \r
- // checks p is updatable\r
- if(rp != null && rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
- return true;\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- \r
- \r
- /**\r
- * @param m meta package to be checked removable\r
- * @return <code>true</code> if the meta package is removable \r
- * ie. the meta package is installed and one of its dependents is already installed and is removable.\r
- */\r
- private boolean isMetaRemovable(Package m) {\r
- // if the meta package is not installed, it's never updatable\r
- if(installedPackages.contains(m)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * check new installation or upgrade or downgrade.\r
- * @param meta meta package to be checked installable.\r
- * @return <code>true</code> if the meta package is updatable. \r
- * ie. the meta package is installed and one of its dependents is already installed and is updatable.\r
- */\r
- private boolean isMetaInstallable(Package meta) { \r
- // if one of the meta package's dependents is installed and updatable, the meta package is updatable.\r
- PackageSet dep = dep(meta, State.INSTALL);\r
- \r
- for(Package p : dep) {\r
- //Do not check meta package. It is only used by install-type or category.\r
- if (p.isMeta()) {\r
- continue;\r
- }\r
- \r
- if(installedPackages.contains(p)) {\r
- Package ip = installedPackages.getPackage(p);\r
- if (ip == null) {\r
- continue;\r
- }\r
- \r
- Package rp = repoPackages.getPackage(p); // rp always exists if ip exists\r
- \r
- // checks p is updatable\r
- if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
- return true;\r
- }\r
- } else {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- // utility methods\r
- /**\r
- * Get installed package.\r
- * @param pkg\r
- * @return If not exist package in installed package list, return empty string.\r
- */\r
- public Package getInstalledPackageByName(String pkgName) {\r
- Package retPkg = installedPackages.getPackageByName(pkgName);\r
- \r
- return retPkg;\r
- }\r
- \r
- /**\r
- * Get installed packages by package name.\r
- * @param pkgName name of packages\r
- * @return If not exist package in installed package list, return empty string.\r
- */\r
- public PackageSet getInstalledPackagesByName(List<String> pkgNames) {\r
- PackageSet installedPackages = new PackageSet();\r
- for (String pkg : pkgNames) {\r
- Package retPkg = getInstalledPackageByName(pkg);\r
- \r
- if (retPkg != null) {\r
- installedPackages.add(retPkg);\r
- }\r
- }\r
- \r
- return installedPackages;\r
- }\r
- \r
- /**\r
- * Get Package instance from package name.\r
- * @param pkgName\r
- * @return\r
- */\r
- public Package getPackageByName(String pkgName) {\r
- PackageSet packageList = repoPackages;\r
- packageList.addAll(extensionPackages);\r
- \r
- if (packageList.hasPackageByName(pkgName)) {\r
- return packageList.getPackageByName(pkgName);\r
- } else {\r
- return null;\r
- }\r
- }\r
- \r
- public boolean existsPackage(String packageName) {\r
- if (getPackageByName(packageName) != null) {\r
- return true;\r
- } else if (getInstalledPackageByName(packageName) != null) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public void removePackageFromPackageManager(String pkgName) {\r
- PackageSet clone = (PackageSet) repoPackages.clone();\r
- Package pkg = clone.getPackageByName(pkgName);\r
- \r
- if (clone.hasPackage(pkg)) {\r
- clone.remove(pkg);\r
- }\r
- \r
- repoPackages = clone;\r
- }\r
- /**\r
- * @param packageNames\r
- * @return packages collected by the given package names\r
- */\r
- public PackageSet getPackagesByNames(Collection<String> packageNames) {\r
- PackageSet pset = new PackageSet();\r
- for(String name : packageNames) {\r
- if(repoPackages.hasPackageByName(name)) {\r
- Package pkg = repoPackages.getPackageByName(name);\r
- pset.add(pkg);\r
- } else if (extensionPackages.hasPackageByName(name)) {\r
- Package pkg = extensionPackages.getPackageByName(name);\r
- pset.add(pkg);\r
- } else {\r
- throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);\r
- }\r
- }\r
- return pset;\r
- }\r
- \r
- public PackageSet getMandatoryPackages() {\r
- PackageSet pSet = new PackageSet();\r
- \r
- for (Package pkg : repoPackages) {\r
- if (pkg.isMandatory()) {\r
- pSet.add(pkg);\r
- }\r
- }\r
- \r
- return pSet;\r
- }\r
- \r
- public PackageSet getUpdatableMandatoryPackages() {\r
- PackageSet pSet = new PackageSet();\r
- \r
- for (Package mPkg : getMandatoryPackages()) {\r
- if (!installedPackages.contains(mPkg)) {\r
- pSet.add(mPkg);\r
- } else if(isUpdatable(mPkg)) {\r
- pSet.add(mPkg);\r
- } else {\r
- continue;\r
- }\r
- }\r
- \r
- return pSet;\r
- }\r
- \r
- /**\r
- * Check installed meta packages\r
- * @return if installed package exists, return true. if not return false.\r
- */\r
- public boolean existInstalledMetaPackages() {\r
- if (getInstalledMetaPackages().size() <= 0) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * Check installable meta packages\r
- * @return if installable meta package exists, return true. if not return false.\r
- */\r
- public boolean existInstallableMetaPackages() {\r
- if (getInstalledMetaPackages().size() <= 0) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * Check installed packages.\r
- * @return if installed package exists, return true. if not return false.\r
- */\r
- public boolean existInstalledPackages() {\r
- if (installedPackages.size() <= 0) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * Check installable or updatable packages.\r
- * @return if installable package exists, return true. if not return false.\r
- */\r
- public boolean existInstallablePackages() {\r
- for(Package p : repoPackages) {\r
- if(installedPackages.contains(p)) {\r
- Package ip = installedPackages.getPackage(p);\r
- if (ip == null) {\r
- continue;\r
- }\r
- \r
- Package rp = recentPackages.getPackage(p); // rp always exists if ip exists\r
- // checks p is updatable\r
- if(rp.getVersion().compareTo(ip.getVersion()) > 0) {\r
- return true;\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- /**\r
- * get total size to remove. \r
- * @param pkg\r
- * @return\r
- */\r
- public long getTotalSizeOfRemovablePackages(Package pkg) {\r
- PackageSet pkgs = new PackageSet();\r
- \r
- pkgs.add(pkg);\r
- PackageSet depPkgSet = getToRemovePackagesInRemove(pkgs);\r
- \r
- return getTotalSize(depPkgSet, true);\r
- }\r
- \r
- /**\r
- * get total size to install. \r
- * @param pkg\r
- * @param isUncompressed Uncompressed is true, not false.\r
- * @return\r
- */\r
- public long getTotalSizeOfInstallablePackages(PackageSet pkgs, boolean isUncompressed) {\r
- PackageSet depPkgSet = getInstallablePackages(pkgs);\r
- \r
- return getTotalSize(depPkgSet, isUncompressed);\r
- }\r
- \r
- /**\r
- * get total size to remove. \r
- * @param pkg\r
- * @return\r
- */\r
- public long getTotalSizeOfRemovablePackages(PackageSet pkgs) {\r
- PackageSet depPkgSet = getRemovablePackagesInSnapshot(pkgs);\r
- \r
- return getTotalSize(depPkgSet, true);\r
- }\r
- \r
- /**\r
- * Get uncompressed packages size or compressed(zipped) packages size.\r
- * @param pkgs Packages set which can be calculated total size.\r
- * @param isUncompressed Uncompressed is true, not false.\r
- * @return\r
- */\r
- private long getTotalSize(PackageSet pkgs, boolean isUncompressed) {\r
- long totalSize = 0;\r
- for (Package depPkg : pkgs) {\r
- if (isUncompressed) {\r
- totalSize += depPkg.getUncompressedPackageSize(); \r
- } else {\r
- totalSize += depPkg.getPackageSize(); \r
- }\r
- }\r
- \r
- return totalSize;\r
- }\r
- \r
- /**\r
- * @return <code>true</code> if installed and repository packages are empty.\r
- */\r
- public boolean isEmpty() {\r
- \r
- if (installedPackages.size() <= 0 && repoPackages.size() <= 0) {\r
- return true;\r
- }\r
- \r
- return false;\r
- }\r
- \r
- /**\r
- * Get Installable packages.\r
- * @return packages that can be newly installable.\r
- */\r
- public PackageSet getInstallableMetaPackages() {\r
- return diff(getAllMetaPackages(), getInstalledMetaPackages());\r
- }\r
- \r
- /**\r
- * @return packages that can be newly installable or updatable. \r
- */\r
- public PackageSet getInstallableOrUpdatableMetaPackages() {\r
- PackageSet installableMetaPackages = new PackageSet();\r
- PackageSet allMetaPackages = getAllMetaPackages();\r
- \r
- for (Package metaPackage : allMetaPackages) {\r
- if (isMetaInstallable(metaPackage)) {\r
- installableMetaPackages.add(metaPackage);\r
- }\r
- }\r
- \r
- return installableMetaPackages;\r
- }\r
- \r
- \r
- /**\r
- * Check missing packages from repository's package list. \r
- * @return packages that is missing in repository's package list.\r
- */\r
- public PackageSet getMissingPackagesFromRepository() {\r
- PackageSet missingPackages = new PackageSet();\r
- \r
- if (!repoPackages.isEmpty()) {\r
- missingPackages = diff(installedPackages, repoPackages);\r
- missingPackages = diff(missingPackages, extensionPackages);\r
- }\r
- \r
- return missingPackages;\r
- }\r
- \r
- /**\r
- * save packages to installedpackage.list\r
- * @param filePath\r
- */\r
- public void saveInstalledList() {\r
- String filePath = PathUtil.get(\r
- PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
- Config.INSTALLED_PACKAGE_LIST_FILE_NAME);\r
- \r
- PropertyParser parser = new PropertyParser();\r
- List<PropertySection> pSections = saveProperySectionsFromPackages(installedPackages);\r
- parser.writeToFile(pSections, filePath);\r
- }\r
- \r
- /**\r
- * save information of packages.\r
- * @param packages \r
- * @return\r
- */\r
- public List<PropertySection> saveProperySectionsFromPackages(PackageSet packages) {\r
- List<PropertySection> pSections = new ArrayList<PropertySection>();\r
- PropertySection pSection = null;\r
- Properties properties = null;\r
- \r
- for (Package pkg : packages) {\r
- properties = (Properties)pkg.getProperties();\r
- pSection = new PropertySection();\r
- pSection.setProperties(properties);\r
- pSections.add(pSection);\r
- }\r
- \r
- return pSections;\r
- }\r
- \r
- /**\r
- * Check the repository change.\r
- * @return\r
- */\r
- public boolean isRepositoryChanged() { \r
- if (installedRepository == null || !currentRepository.equalsIgnoreCase(installedRepository)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Check to need re-installation.\r
- * If there has been a change distribution or repository or SDK image, force to re-install.\r
- * @return If it needs to re-install, return true. otherwise return false.\r
- */\r
- public boolean isReInstall() {\r
- if (isInstallInstallManager) {\r
- return false;\r
- } else if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {\r
- return true;\r
- } else if (isRepositoryChanged()) {\r
- return true;\r
- } else {\r
- if (DistributionController.getInstance().isDistributionChanged()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- }\r
- \r
- public boolean isConflict(PackageSet pkgsToInstall, Package pkg) {\r
- return false;\r
- }\r
- \r
- /**\r
- * Prints dependency graph of packages in dot format to stdout.\r
- * @throws IMExitException \r
- */\r
- public void printDepGraph() {\r
- StringBuffer buf = new StringBuffer();\r
- \r
- buf.append("digraph G {\n");\r
- \r
- for(Package p : recentPackages) {\r
- PackageSet dep = dep(p, State.INSTALL);\r
- \r
- for(Package d : dep) {\r
- if(!d.equals(p)) {\r
- buf.append("\""+p+"\" -> \"" + d + "\";\n");\r
- }\r
- }\r
- }\r
- \r
- buf.append("}\n");\r
- System.out.println(buf);\r
- }\r
- \r
- public static void dispose() {\r
- if (pm != null) {\r
- pm = null;\r
- }\r
- }\r
- \r
- /**\r
- * Get PackageManager singleton instance.\r
- * @param installed\r
- * @param repoPackagesUrls\r
- * @return\r
- * @throws IOException\r
- */\r
- public static PackageManager getInstance(File installed, Collection<String> repoPackagesUrls) throws IOException {\r
- if (Options.platForm == null) {\r
- if (Config.isSupportMultiSDK) {\r
- if (Registry.targetPath != "") {\r
- pm = null;\r
- if (Platform.isLinux()) {\r
- pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isWindows()) {\r
- pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isMacOS()) {\r
- pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
- } else {\r
- return null;\r
- } \r
- } else {\r
- if (pm == null) {\r
- if (Platform.isLinux()) {\r
- pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isWindows()) {\r
- pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isMacOS()) {\r
- pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
- } else {\r
- return null;\r
- }\r
- } \r
- }\r
- } else {\r
- if (pm == null) {\r
- if (Platform.isLinux()) {\r
- pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isWindows()) {\r
- pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
- } else if (Platform.isMacOS()) {\r
- pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
- } else {\r
- return null;\r
- }\r
- } \r
- }\r
- } else {\r
- if (pm == null) {\r
- if (Options.platForm.equalsIgnoreCase("ubuntu")) {\r
- pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
- } else if (Options.platForm.equalsIgnoreCase("windows")) {\r
- pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
- } else if (Options.platForm.equalsIgnoreCase("macos")) {\r
- pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
- } else {\r
- return null;\r
- }\r
- }\r
- }\r
- return pm;\r
- }\r
- \r
- public static PackageManager getInstance() {\r
- return pm;\r
- }\r
- \r
- public SDKExtensionInfo getSdkExtensionInfo() {\r
- return SDKExtensionInfo.getInstance();\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.pkg.lib;
+
+ import java.io.File;
+ import java.io.IOException;
+ import java.net.MalformedURLException;
+ import java.net.URL;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.HashMap;
+ import java.util.LinkedList;
+ import java.util.List;
+ 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;
+ import org.tizen.installmanager.core.InstallManager;
+ import org.tizen.installmanager.core.Options;
+ import org.tizen.installmanager.core.SDKExtensionInfo;
+ import org.tizen.installmanager.lib.Downloader;
+ import org.tizen.installmanager.lib.ErrorController;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.lib.Registry;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.lib.Platform;
+ import org.tizen.installmanager.lib.exception.IMNetworkConnectException;
+ import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;
+ import org.tizen.installmanager.pkg.lib.darwin.DarwinPackageManager;
+ import org.tizen.installmanager.pkg.lib.linux.LinuxPackageManager;
+ import org.tizen.installmanager.pkg.lib.win.WindowsPackageManager;
+ import org.tizen.installmanager.pkg.model.IMPackageNotFound;
+ import org.tizen.installmanager.pkg.model.Package;
+ import org.tizen.installmanager.pkg.model.PackageSet;
+ import org.tizen.installmanager.pkg.model.Properties;
+ import org.tizen.installmanager.pkg.model.Property;
+ import org.tizen.installmanager.pkg.model.PropertySection;
+ import org.tizen.installmanager.pkg.model.Snapshot;
+ import org.tizen.installmanager.pkg.model.Version;
+ import org.tizen.installmanager.util.PathUtil;
+
+
+ /**
+ * Package Manager
+ * <p>
+ * This class provides various methods for managing packages.
+ * Most of the methods handle packages symbolically. Namely, they are identified by its package name not the object if not specially mentioned.
+ * <p>
+ * Some methods are carefully designed to preserve the order of packages because the order of packages is important sometimes.
+ * See the details in the documentation of each methods.
+ *
+ * @author Shihyun Kim <shihyun.kim@samsung.com>
+ *
+ */
+ public abstract class PackageManager {
+ /**
+ * Packages that are already installed in the system.
+ */
+ private PackageSet installedPackages;
+ /**
+ * packages that are available in the repositories(package servers).
+ */
+ private PackageSet repoPackages;
+ /**
+ * packages that combines <code>installedPackages</code> and <code>repoPackages</code>.
+ * This includes only the latest package from the several versions of a package.
+ * This is used as the universe set(base set) of packages available.
+ */
+ private PackageSet recentPackages;
+
+ /**
+ * Packages from extension package server.111
+ */
+ private PackageSet extensionPackages = new PackageSet();
+
+ private static PackageManager pm = null;
+
+ //repository that installed.
+ private static String installedRepository = null;
+ private String currentRepository = null;
+
+ public boolean isInstallInstallManager = false;
+
+ public enum State {
+ INSTALL,
+ 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.
+ * @return
+ */
+ abstract public String getPackageListFileName();
+
+ /**
+ * Creates and initializes Package Manager instance.
+ * This combines installed packages and packages from the repositories.
+ *
+ * @param installed a file in which installed packages are specified. This can be <code>null</code> if no packages are installed.
+ * @param repoPackagesUrls a collection of URLs of repositories(package servers). This cannot be <code>null</code>.
+ * @throws IOException if temporary file cannot created
+ */
+ protected PackageManager(File installed, Collection<String> repoPackagesUrls) throws IOException {
+ setInstalledPackageList(installed);
+ loadRepositoryPackageList(repoPackagesUrls);
+ getRecentPackages();
+
+ if (repoPackagesUrls.size() > 0) {
+ setRepository(repoPackagesUrls.iterator().next());
+ }
+ }
+
+ private void setRepository(String repository) {
+ if (installedRepository == null) {
+ installedRepository = repository;
+ }
+
+ currentRepository = repository;
+ return;
+ }
+
+ /**
+ * set repository url to each package.(reposistory url plus package name is complete url.)
+ * @param repoPackagesUrls
+ * @throws IOException
+ */
+ public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {
+ HashMap<String,List<PropertySection>> r2sMap = null;
+ ServerType serverType = Config.getInstance().getConfigFile().getServerType();
+
+ if (serverType == ServerType.LOCAL) { // Using SDK Image
+ r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);
+ } else {
+ r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);
+ }
+ setRepoPackages(r2sMap);
+
+ //Add EXTRAS for extention packages
+ addExtraMetaPackage();
+ }
+
+ /**
+ * set repository url to each package.(reposistory url plus package name is complete url.)
+ * @param repoPackagesUrls Packgae server list.
+ * @throws IOException
+ */
+ public void loadExtensionPackages() throws IOException {
+ HashMap<String,List<PropertySection>> repoToSectionsMap =
+ getRepositoryAndPackageList(SDKExtensionInfo.getInstance().getExtensionRepositories().keySet(),
+ Style.EXTRA);
+
+ //Update extension packages.
+ if (repoToSectionsMap != null/*adall && !repoToSectionsMap.isEmpty()*/) {
+ setExtensionPackages(repoToSectionsMap);
+ setExtensionPackagesToRecentPackages();
+ } else {
+ return;
+ }
+ }
+
+ private HashMap<String,List<PropertySection>> getRepositoryAndPackageList
+ (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, style);
+ File packageListFile = null;
+
+ if (style != Style.EXTRA) { // Snapshot, Image case
+ packageListFile = downloadPackageListFile(packageListURL);
+ 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 {
+ // InstallManager can get package list file from remote repository.
+ packageListFile = downloadPackageListFile(packageListURL);
+ if (packageListFile != null) {
+ r2sMap.put(repo, parser.readFromFile(packageListFile));
+ }
+ }
+ }
+ }
+ } else {
+ Log.log("Cannot find repository. This is local installer.");
+ }
+
+ return r2sMap;
+ }
+
+ private File downloadPackageListFile(URL packageListURL) throws IOException {
+ if (packageListURL == null) {
+ return null;
+ }
+ Downloader dl = InstallManager.getDownloader();
+ File tmp = null;
+
+ if (Options.onlyDownload) {
+ tmp = new File(PathUtil.getFromCurrDir(getPackageListFileName()));
+ } else {
+ tmp = File.createTempFile("Packages", ".list");
+ tmp.deleteOnExit();
+ }
+
+ long size = 0;
+ try {
+ size = dl.download(packageListURL, tmp.getAbsolutePath(), null);
+ } catch (IMNetworkConnectException e) {
+ Log.ExceptionLog(e);
+ return null;
+ } catch (IMNetworkDownloadException e) {
+ Log.ExceptionLog(e);
+ return null;
+ }
+
+ if (size > 0) {
+ return tmp;
+ } else {
+ return null;
+ }
+ }
+
+ private void setExtensionPackages(HashMap<String,List<PropertySection>> repoToSectionsMap) {
+ extensionPackages = new PackageSet();
+ boolean result = setPackages(extensionPackages, repoToSectionsMap, true);
+ if (!result) {
+ Log.err("Cannot set extension packages.");
+ }
+ }
+
+ private void addExtraMetaPackage() {
+ if (repoPackages == null) {
+ repoPackages = new PackageSet();
+ } else {
+ if (repoPackages.hasPackageByName("EXTRAS")) {
+ return;
+ }
+ }
+
+ Properties props = new Properties();
+
+ props.add(new Property(Package.FIELD_PACKAGE, "EXTRAS"));
+ props.add(new Property(Package.FIELD_LABEL, "Extras"));
+ props.add(new Property(Package.FIELD_ATTRIBUTE, "root"));
+ props.add(new Property(Package.FIELD_PACKAGE_SIZE, "0"));
+ props.add(new Property(Package.FIELD_UNCOMPRESSED_SIZE, "0"));
+
+ Package extraPackage = new Package(props);
+ repoPackages.add(extraPackage);
+ }
+
+ /**
+ * Get packages from extension package server.
+ * @return set of packages
+ */
+ public PackageSet getExtensionPackages() {
+ return extensionPackages;
+ }
+
+ public PackageSet getInstalledExtensionPackages() {
+ PackageSet extensionPackages = new PackageSet();
+ PackageSet pkgs = this.getInstalledPackages();
+
+
+ for (Package pkg : pkgs) {
+ if (pkg.isExtensionPackage()) {
+ extensionPackages.add(pkg);
+ }
+ }
+
+ return extensionPackages;
+ }
+
+ /**
+ * Set installed packages.
+ * @param installedPackageListPath
+ */
+ public void setInstalledPackageList(File installedPackageListPath) {
+ List<PropertySection> sectionsInstalled = null;
+ PropertyParser parser = new PropertyParser();
+
+ if(installedPackageListPath != null) {
+ sectionsInstalled = parser.readFromFile(installedPackageListPath);
+ } else {
+ sectionsInstalled= new LinkedList<PropertySection>();
+ }
+
+ if (sectionsInstalled != null) {
+ setInstalledPackageList(sectionsInstalled);
+ }
+ }
+
+ /**
+ * Set installed packages
+ * @param sections
+ */
+ private void setInstalledPackageList(List<PropertySection> sections) {
+ installedPackages = new PackageSet();
+
+ for(PropertySection sect : sections) {
+ installedPackages.add(new Package(sect.getProperties()));
+ }
+ }
+
+ public void installedPackagesFree() {
+ installedPackages = null;
+ }
+
+ /**
+ * Get package list file path from url.
+ * @param url
+ * @return Full url path
+ */
+ private URL getPackageListPath(String url, Style style) {
+ if (url == null || url.isEmpty()) {
+ return null;
+ } else {
+ String packageListURL = "";
+
+ if (style == Style.NETWORK) {
+ String snapshotPath = Config.getInstance().getSnapshotPath();
+
+ if (snapshotPath == null || snapshotPath.isEmpty() || snapshotPath.equalsIgnoreCase("null")) {
+ String distribution = Config.getInstance().getConfigFile().getDistribution();
+
+ Snapshot latestSnapshot = DistributionController.getInstance().getLatestSnapshot(distribution);
+ if (latestSnapshot == null) {
+ return null;
+ } else {
+ snapshotPath = latestSnapshot.getPath();
+ }
+ }
+
+ if (snapshotPath != null) {
+ packageListURL = PathUtil.addURLPath(url,
+ snapshotPath,
+ getPackageListFileName());
+ }
+ } else {
+ packageListURL = PathUtil.addURLPath(url, getPackageListFileName());
+ }
+
+ try {
+ return new URL(packageListURL);
+ } catch (MalformedURLException e) {
+ Log.ExceptionLog(e);
+ return null;
+ }
+ }
+ }
+
+
+
+ /**
+ * @return installed packages
+ */
+ public PackageSet getInstalledPackages() {
+ return (PackageSet) installedPackages.clone();
+ }
+
+ /**
+ * Set packages of repository
+ * @param sections
+ */
+ protected void setRepoPackages( Map<String,List<PropertySection>> repoToSectionsMap) {
+ repoPackages = new PackageSet();
+ boolean result = setPackages(repoPackages, repoToSectionsMap, false);
+ if (!result) {
+ Log.err("Cannot find repository. Please check your repository.");
+ ErrorController.setError(ErrorCode.CANNOT_FIND_REPOSITORY);
+ }
+ }
+
+ /**
+ * Set packages to <code>destPackages</code>
+ * @param destPackages It is set of packages.
+ * @param repoToSectionsMap It is added to <code>destPackages</code>
+ */
+ public boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {
+ if (destPackages == null) {
+ destPackages = new PackageSet();
+ }
+
+ if (repoToSectionsMap == null || repoToSectionsMap.isEmpty()) {
+ return false;
+ }
+
+ for(String repoBaseUrl : repoToSectionsMap.keySet()) {
+ for(PropertySection sect : repoToSectionsMap.get(repoBaseUrl)) {
+ Package pkg = new Package(sect.getProperties(), repoBaseUrl);
+ Log.log("Check valid package version. => " + pkg);
+ pkg.getVersion(); // Vaild version check.
+ if (isExtensionPackage) {
+ if (pkg.getAttribute().equalsIgnoreCase("extra")) {
+ pkg.setExtensionServer(repoBaseUrl);
+ destPackages.add(pkg);
+ }
+ } else {
+ destPackages.add(pkg);
+
+ }
+ }
+ }
-
+ return true;
+ }
+
+ /**
+ * @return packages of repository
+ */
+ public PackageSet getRepoPackages() {
+ return repoPackages;
+ }
+
+ /**
+ * Set repository packages.
+ * @param packageSet
+ */
+ public void setRepoPackages(PackageSet packageSet) {
+ repoPackages = packageSet;
+ }
+
+ /**
+ * @return root meta packages of repository
+ */
+ public PackageSet getRootMetaPackagesOfRepository() {
+ PackageSet clone = (PackageSet) repoPackages.clone();
+
+ // Repository packages should not have extension packages.
+ for (Package pkg : repoPackages) {
+ if (pkg.isExtensionPackage()) {
+ clone.remove(pkg);
+ }
+ }
+
+ repoPackages = clone;
+
+ return rootMeta(repoPackages);
+ }
+
+ /**
+ * Get install meta packages from repository.
+ * @return
+ */
+ public PackageSet getInstallMetaPackagesOfRepository() {
+ return installMeta(repoPackages);
+ }
+
+ /**
+ * Get root meta package from extension package server()
+ */
+ public PackageSet getRootMetaPackagesOfExtensionServer() {
+ return rootMeta(extensionPackages);
+ }
+
+ /**
+ * @return recent packages. This includes the latest packages among all packages from currently
+ * installed packages and packages of repository if a package has several versions.
+ */
+ public PackageSet getRecentPackages() {
+ Log.log("Repo packages : " + repoPackages);
+ if(recentPackages == null) {
+ recentPackages = new PackageSet();
+ for(Package ip : installedPackages) {
+ if(repoPackages != null && repoPackages.contains(ip)) {
+ Package rp = repoPackages.getPackage(ip);
+ if(ip.getVersion().compareTo(rp.getVersion()) > 0) {
+ recentPackages.add(ip);
+ } else {
+ recentPackages.add(rp);
+ }
+ } else if (extensionPackages != null && extensionPackages.contains(ip)) {
+ Package ep = extensionPackages.getPackage(ip);
+ if(ip.getVersion().compareTo(ep.getVersion()) > 0) {
+ recentPackages.add(ip);
+ } else {
+ recentPackages.add(ep);
+ }
+ } else {
+ recentPackages.add(ip);
+ }
+ }
+
+ if (repoPackages != null) {
+ for(Package rp : repoPackages) {
+ if(!recentPackages.contains(rp)) {
+ recentPackages.add(rp);
+ }
+ }
+ }
+ }
+ return recentPackages;
+ }
+
+ private void setExtensionPackagesToRecentPackages() {
+ if (recentPackages == null) {
+ recentPackages = new PackageSet();
+ }
+
+ for(Package ip : installedPackages) {
+ if (extensionPackages != null && extensionPackages.contains(ip)) {
+ Package ep = extensionPackages.getPackage(ip);
+ if(ip.getVersion().compareTo(ep.getVersion()) > 0) {
+ recentPackages.add(ip);
+ } else {
+ recentPackages.add(ep);
+ }
+ } else {
+ recentPackages.add(ip);
+ }
+ }
+ }
+
+
+
+ // Methods for update process
+ /**
+ * except package from installed package list.
+ * @param pkg
+ * @return
+ */
+ public boolean exceptPackageFromInstalledPackages(Package pkg) {
+ return installedPackages.remove(pkg);
+ }
+
+ /**
+ * Add package to installed package list.
+ * @param pkg
+ * @return
+ */
+ public boolean addPackageToInstalledPackages(Package pkg) {
+ installedPackages.remove(pkg);
+ return installedPackages.add(pkg);
+ }
+
+ /**
+ * @return updatable packages among installed packages
+ */
+ public PackageSet getUpdatableInstalledPackages() {
+ PackageSet updatables = new PackageSet();
+ for(Package ip : installedPackages) {
+ if(repoPackages.contains(ip)) {
+ Package rp = repoPackages.getPackage(ip);
+ if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
+ updatables.add(ip);
+ }
+ }
+ }
+ return updatables;
+ }
+
+ /**
+ * if pkg is updatable, return true. else return false.
+ * @param pkg
+ * @return
+ */
+ public boolean isUpdatable(Package pkg) {
+ if (pkg == null) {
+ return false;
+ }
+
+ PackageSet updatables = getUpdatableInstalledPackages();
+ if (updatables.contains(pkg)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
++ public boolean isInstalledPackage(Package pkg) {
++ if (pkg == null) {
++ return false;
++ }
++
++ if (installedPackages.contains(pkg)) {
++ return true;
++ } else {
++ return false;
++ }
++ }
++
+ /**
+ * If package set of repository is empty, return true;
+ * @return
+ */
+ public boolean isRepoPackagesEmpty() {
+ if (repoPackages == null || repoPackages.isEmpty()) {
+ return true;
+ } else if (repoPackages.size() == 1) {
+ if (repoPackages.getPackageByName("EXTRAS") != null) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * If pkg is installed, return true. else return false
+ * @param pkg
+ * @return
+ */
+ public boolean isInstalledVersion(Package pkg) {
+ Package installedPackage = installedPackages.getPackage(pkg);
+ if (installedPackage == null) {
+ return false;
+ } else {
+ Version installedVersion = installedPackage.getVersion();
+ if (installedVersion.compareTo(pkg.getVersion()) == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public PackageSet getRecentMetaPackages() {
+ PackageSet recentPackages = union(repoPackages, installedPackages);
+ return rootMeta(recentPackages);
+ }
+
+ /**
+ * @return meta packages among installed packages
+ */
+ public PackageSet getInstalledMetaPackages() {
+ return meta(installedPackages);
+ }
+
+ public List<String> getInstalledMetaNames() {
+ ArrayList<String> installedMetaNames = new ArrayList<String>();
+
+ for (Package meta : getInstalledMetaPackages()) {
+ installedMetaNames.add(meta.getPackageName());
+ }
+
+ return installedMetaNames;
+ }
+
+ public List<String> getInstalledPkgNames() {
+ ArrayList<String> installedPkgNames = new ArrayList<String>();
+
+ for (Package pkg : getInstalledPackages()) {
+ installedPkgNames.add(pkg.getPackageName());
+ }
+
+ return installedPkgNames;
+ }
+
+ /**
+ * @return meta packages among all recent packages
+ */
+ public PackageSet getAllMetaPackages() {
+ PackageSet allMeta = new PackageSet();
+
+ PackageSet recentMeta = meta(recentPackages);
+ PackageSet extensionMeta = meta(extensionPackages);
+
+ allMeta.addAll(recentMeta);
+ allMeta.addAll(extensionMeta);
+
+ return allMeta;
+ }
+
+ public PackageSet getLeafMetaPackages() {
+ PackageSet allMetas = meta(recentPackages);
+
+ PackageSet leafMetas = new PackageSet();
+ for (Package meta : allMetas) {
+ //if (depends size <= 0) is leaf
+ if (meta.getDependentPackageNames().size() <= 0) {
+ leafMetas.add(meta);
+ } else {
+ if (!isChildrenAllMeta(meta)) {
+ leafMetas.add(meta);
+ }
+ }
+ }
+
+ return leafMetas;
+ }
+
+ public PackageSet getInstalledLeafMetaPackages() {
+ PackageSet allMetas = meta(installedPackages);
+
+ PackageSet leafMetas = new PackageSet();
+ for (Package meta : allMetas) {
+ //if (depends size <= 0) is leaf
+ if (meta.getDependentPackageNames().size() <= 0) {
+ leafMetas.add(meta);
+ } else {
+ if (!isChildrenAllMeta(meta)) {
+ leafMetas.add(meta);
+ }
+ }
+ }
+
+ return leafMetas;
+ }
+
+ private boolean hasMetaPackagesInChildren(Package pkg) {
+ PackageSet dependPackages = getDependsPackages(pkg);
+
+ if (dependPackages == null) {
+ return true;
+ } else {
+ for (Package dPackage : dependPackages) {
+ if (dPackage.isMeta()) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ private boolean isChildrenAllMeta(Package pkg) {
+ PackageSet dependPackages = getDependsPackages(pkg);
+
+ if (dependPackages == null) {
+ return true;
+ } else {
+ for (Package dPackage : dependPackages) {
+ if (!dPackage.isMeta()) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ private PackageSet getDependsPackages(Package pkg) {
+ PackageSet dependPackages = new PackageSet();
+ if (pkg == null) {
+ return dependPackages;
+ }
+
+ Collection<String> depends = pkg.getDependentPackageNames();
+
+ try {
+ dependPackages = recentPackages.getPackagesByNames(depends);
+ } catch (IMPackageNotFound e) {
+ Log.ExceptionLog(e);
+ }
+ return dependPackages;
+ }
+
+ /**
+ * @return partner meta packages among all meta packages.
+ */
+ public PackageSet getPartnerMetaPackages() {
+ PackageSet allMetas = meta(recentPackages);
+
+ PackageSet partnerMeta = new PackageSet();
+ for (Package meta : allMetas) {
+ if (meta.isPartnerMeta()) {
+ partnerMeta.add(meta);
+ }
+ }
+
+ return partnerMeta;
+ }
+
+ /**
+ * @return public meta packages among all meta packages.
+ */
+ public PackageSet getPublicMetaPackages() {
+ PackageSet allMetas = meta(recentPackages);
+
+ PackageSet publicMeta = new PackageSet();
+ for (Package meta : allMetas) {
+ if (meta.isPublicMeta()) {
+ publicMeta.add(meta);
+ }
+ }
+
+ return publicMeta;
+ }
+
+ /**
+ * Get dependency packages of installable package.
+ * @param pkgs installable packages.
+ * @return
+ */
+ public PackageSet getDependsPackagesFromRepository(PackageSet pkgs) {
+ return dep(pkgs, State.INSTALL);
+ }
+
+ /**
+ * @return meta packages that have no updates considering its dependents
+ */
+ public PackageSet getNotUpdatableMetaPackages() {
+ PackageSet noup = new PackageSet();
+ for(Package m : getAllMetaPackages()) {
+ if(!isMetaUpdatable(m)) {
+ noup.add(m);
+ }
+ }
+ return noup;
+ }
+
+ public PackageSet getNotInstallableAndNotUpdatablePackages() {
+ PackageSet notPkg = new PackageSet();
+
+ for (Package m :getAllMetaPackages()) {
+ if (isMetaRemovable(m) && !isMetaUpdatable(m)) {
+ notPkg.add(m);
+ }
+ }
+
+ return notPkg;
+ }
+
+ /**
+ * @return meta packages thar are updatable among installed packages
+ */
+ public PackageSet getUpdatableMetaPackages() {
+ PackageSet allMetas = getAllMetaPackages();
+ PackageSet notUpdatableMetas = getNotUpdatableMetaPackages();
+ return diff(allMetas, notUpdatableMetas);
+ }
+
+ public PackageSet getUpdatableInstalledMetaPackages() {
+ PackageSet installedMeta = getInstalledMetaPackages();
+ PackageSet updatableMeta = getUpdatableMetaPackages();
+ return intersect(installedMeta, updatableMeta);
+ }
+
+ /**
+ * @param selectedMetas
+ * @return packages that will be installed after update/install resulted from the selected meta packages
+ */
+ public PackageSet getResultPackagesAfterUpdate(PackageSet selectedMetas) {
+ PackageSet deps = dep(selectedMetas, State.INSTALL);
+ PackageSet conflicts = conflictPackages(selectedMetas);
+ PackageSet remainedFromConflicts = diff(installedPackages, conflicts);
+ return union(deps, remainedFromConflicts);
+ }
+
+ /**
+ * Get updatable packages in update process except new packages.
+ * @param packageSet
+ * @return
+ */
+ public PackageSet getUpdatablePackagesInUpdate(PackageSet packageSet) {
+ PackageSet result = dep(packageSet, State.INSTALL);
+ PackageSet up = getUpdatableInstalledPackages();
+ return intersect(result, up);
+ }
+
+ /**
+ * Get removable packages in snapshot process except new packages.
+ * @param selectedMetas
+ * @return
+ */
+ public PackageSet getRemovablePackagesInSnapshot(PackageSet selectedMetas) {
+ PackageSet result = dep(selectedMetas, State.UNINSTALL);
+ PackageSet pkgSet = getdifferentVersionFromInstalledPackages(result);
+
+ return pkgSet;
+ }
+
+ /**
+ * check version between sourcePackages and installedPackages, and return different version packages.
+ * @param pkgs
+ * @return Different version packages among installed packages
+ */
+ public PackageSet getdifferentVersionFromInstalledPackages(PackageSet pkgs) {
+ PackageSet depPkgs = dep(pkgs, State.INSTALL);
+ PackageSet otherVersionPackages = new PackageSet();
+ for(Package ip : installedPackages) {
+ if(depPkgs.contains(ip)) {
+ Package rp = depPkgs.getPackage(ip);
+ if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
+ otherVersionPackages.add(ip);
+ }
+ }
+ }
+
+ return otherVersionPackages;
+ }
+
+ /**
+ * @param selectedMetas
+ * @return packages to newly install in update process by the selected meta packages
+ */
+ public PackageSet getInstallablePackages(PackageSet selectedMetas) {
+ PackageSet installablePackages = null;
- if (isReInstallable()) {
++ if (isReInstall()) {
+ installablePackages = dep(selectedMetas, State.INSTALL);
+ } else if (Config.isSupportMultiSDK()) {
+ if (Config.status == Config.Status.INSTALL) {
+ installablePackages = dep(selectedMetas, State.INSTALL);
+ } else if (Config.status == Config.Status.UPDATE) {
+ PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
+ installablePackages = diffPackageWithVersion(result, installedPackages);
+ }
+ } else {
+ PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
+ installablePackages = diffPackageWithVersion(result, installedPackages);
+ }
+
+ return installablePackages;
+ }
+
+ /**
+ * @param selectedMetas
+ * @return packages to update in update process by the selected meta packages
+ */
+ public PackageSet getToUpdatePackagesInUpdate(PackageSet selectedMetas) {
+ PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
+ PackageSet up = getUpdatableInstalledPackages();
+ return intersect(result, up);
+ }
+
+
+ /**
+ * Get conflict packages that installed.
+ * @param packageSet
+ * @return packages to remove in update process by conflicts with the selected meta packages
+ */
+ public PackageSet getConflictPackagesInUpdate(PackageSet packageSet) {
+ return intersect(installedPackages, getConflictPackages(packageSet));
+ }
+
+ /**
+ * Get conflict packages that contain reverse depends packages.
+ * @param packageSet
+ * @return
+ */
+ public PackageSet getConflictPackages(PackageSet packageSet) {
+ PackageSet conflicts = conflictPackages(packageSet);
+
+ conflicts.addAll(reverseDep(conflicts));
+ return intersect(getConflictMetaPackages(), conflicts);
+ }
+
+ /**
+ * Get conflict packages that contain reverse depends packages.
+ * @param packageSet
+ * @return
+ */
+ public PackageSet getConflictPackages(Package pkg) {
+ PackageSet conflicts = conflictPackages(pkg);
+
+ conflicts.addAll(reverseDep(conflicts));
+ return intersect(getConflictMetaPackages(), conflicts);
+ }
+
+ private PackageSet getConflictMetaPackages() {
+ PackageSet leafMetas = new PackageSet();
+ for (Package meta : recentPackages) {
+ //if (depends size <= 0) is leaf
+ if (meta.getDependentPackageNames().size() <= 0) {
+ leafMetas.add(meta);
+ } else {
+ if (!hasMetaPackagesInChildren(meta)) {
+ leafMetas.add(meta);
+ }
+ }
+ }
+
+ return leafMetas;
+ }
+
+ // Methods for remove process
+
+ /**
+ * @return packages that can be removed
+ */
+ public PackageSet getRemovableMetaPackages() {
+ return getInstalledMetaPackages();
+ }
+
+ public PackageSet getInstallableMetaPackagesInSnapshot() {
+ PackageSet repoMetas = meta(repoPackages);
+
+ PackageSet installableMeta = new PackageSet();
+ for (Package metaPackage : repoMetas) {
+ if (isMetaInstallable(metaPackage)) {
+ installableMeta.add(metaPackage);
+ }
+ }
+
+ return installableMeta;
+ }
+
+ /**
+ * Get remove packages by selected metas.
+ * @param selectedMetas
+ * @return packages to remove in remove process
+ */
+ public PackageSet getToRemovePackagesInRemove(PackageSet selectedMetas) {
+ if (Options.doRemoveNoUI) {
+ // When installmanager removes specific packages, it should consider package dependency.
+ // For example, 'sdb' package depends on 'tizen-web-cli' and 'tizen-native-cli'.
+ // In this case, when installmanager removes 'tizen-web-cli' package, 'sdb' package should
+ // not be removed because of 'tizen-native-cli'.
+
+ // Get candidate packages to remove.
+ PackageSet depMetas = getDependMetas(selectedMetas, State.UNINSTALL);
+ PackageSet dep = dep(depMetas, State.UNINSTALL);
+ PackageSet mayRemove = intersect(installedPackages, dep);
+
+ // Get packages to remain.
+ PackageSet remainMetas = diff(getInstalledLeafMetaPackages(), depMetas);
+ PackageSet remainPackages = dep(remainMetas, State.UNINSTALL);
+
+ // Get packages to remove.
+ PackageSet toRemove = diff(mayRemove, remainPackages);
+ return reverseSet(toRemove);
+ } else {
+ // InstallManager removes whole SDK.
+ PackageSet dep = dep(selectedMetas, State.UNINSTALL);
+ return reverseSet(dep);
+ }
+ }
+
+ /**
+ * @param selectedMetas
+ * @return packages that will be remained after remove resulted from the selected meta packages
+ */
+ public PackageSet getResultPackagesAfterRemove(PackageSet selectedMetas) {
+ return diff(getInstalledMetaPackages(), selectedMetas);
+ }
+
+ // set handling methods
+
+ /**
+ * @param pset
+ * @return meta packages in the package set
+ */
+ private PackageSet meta(PackageSet pset) {
+ PackageSet metas = new PackageSet();
+
+ if (pset == null) {
+ return metas;
+ }
+
+ for(Package p : pset) {
+ if(p.isMeta()) {
+ metas.add(p);
+ }
+ }
+ return metas;
+ }
+
+ /**
+ * @param pset
+ * @return meta packages in the package set
+ */
+ private PackageSet rootMeta(PackageSet pset) {
+ PackageSet metas = new PackageSet();
+ for(Package p : pset) {
+ if (!Options.doTest) {
+ if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta()) {
+ metas.add(p);
+ }
+ } else {
+ if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta() || p.isTestMeta()) {
+ metas.add(p);
+ }
+ }
+ }
+ return metas;
+ }
+
+ /**
+ * @param pset
+ * @return meta packages in the package set
+ */
+ private PackageSet installMeta(PackageSet pset) {
+ PackageSet metas = new PackageSet();
+ for(Package p : pset) {
+ if(p.isInstallMeta()) {
+ metas.add(p);
+ }
+ }
+ return metas;
+ }
+
+ /**
+ * Get dependency package list from p.
+ * @param p a package
+ * @return all the packages that the given package depends on directly or indirectly
+ */
+ private PackageSet dep(Package p, State state) {
+ // depth first traverse on dependency graph
+ PackageSet dep = new PackageSet();
+ Stack<Package> pkgStack = new Stack<Package>();
+ pkgStack.push(p);
+ while(!pkgStack.isEmpty()) {
+ Package pkg = pkgStack.pop();
+
+ if(!dep.contains(pkg)) {
+ dep.add(pkg);
+ PackageSet depPackageSet = new PackageSet();
+ try {
+ if (state == State.INSTALL) {
+ if (repoPackages.contains(pkg)) {
+ depPackageSet = repoPackages.getPackagesByNames(pkg.getDependentPackageNames());
+ } else if (extensionPackages.contains(pkg)) {
+ depPackageSet = extensionPackages.getPackagesByNames(pkg.getDependentPackageNames());
+ }
+ } else if (state == State.UNINSTALL){
+ depPackageSet = installedPackages.getPackagesByNames(pkg.getDependentPackageNames());
+ } else {
+ Log.err("State class have two state(INSTALL/UNINSTALL) ");
+ throw new IMFatalException(ErrorCode.UNKOWN_ERROR);
+ }
+ } catch (IMPackageNotFound e) {
+ Log.err("Finding dependents: "+p+": Package does not exist: " + e.getPackageName()+ " or "+ pkg.getDependentPackageNames());
+ throw new IMFatalException(ErrorCode.CANNOT_FIND_PACKAGE);
+ }
+
+ for(Package depPkg : depPackageSet) {
+ if(p.equals(depPkg)) {
+ Log.err("Circular dependency found: "+p);
+ throw new IMFatalException(ErrorCode.CIRCULAR_PACKAGE_DEPENDENCY);
+ }
+ pkgStack.push(depPkg);
+ }
+ } else {
+ // already visited.
+ addDependsSet(dep, pkg);
+ }
+ }
+
+ return reverseSet(dep);
+ }
+
+ private PackageSet reverseDep(PackageSet packages) {
+ PackageSet reversePackages = new PackageSet();
+
+ for (Package pkg : packages) {
+ reversePackages.addAll(reverseDep(pkg));
+ }
+
+ return reversePackages;
+ }
+
+ /**
+ * Need reverse depends when remove.
+ * @param p
+ * @return
+ */
+ private PackageSet reverseDep(Package p) {
+ // depth first traverse on dependency graph
+ PackageSet reverseDep = new PackageSet();
+ Stack<Package> pkgStack = new Stack<Package>();
+ pkgStack.push(p);
+ while(!pkgStack.isEmpty()) {
+ Package pkg = pkgStack.pop();
+
+ if(!reverseDep.contains(pkg)) {
+ reverseDep.add(pkg);
+
+ for (Package recentPkg : recentPackages) {
+ Collection<String> dependsList = recentPkg.getDependentPackageNames();
+ for (String pkgName : dependsList) {
+ if (pkgName.equals(pkg.getPackageName())) {
+ pkgStack.push(recentPkg);
+ break;
+ }
+ }
+
+ }
+ } else {
+ // already visited
+ addDependsSet(reverseDep, pkg);
+ }
+ }
+
+ return reverseDep;
+ }
+
+ /**
+ * Remove saved package and save package at the end of set.
+ * @param dependsSet
+ * @param pkg
+ */
+ private void addDependsSet(PackageSet dependsSet, Package pkg) {
+ if (dependsSet.contains(pkg)) {
+ dependsSet.remove(pkg);
+ }
+
+ dependsSet.add(pkg);
+ }
+
+ /**
+ * reverse package list.
+ * @param pkgSet
+ * @return
+ */
+ public PackageSet reverseSet(PackageSet pkgSet) {
+ if (pkgSet == null) {
+ return null;
+ }
+
+ Stack<Package> stack = new Stack<Package>();
+ for (Package pkg : pkgSet) {
+ stack.push(pkg);
+ }
+
+ PackageSet reverseSet = new PackageSet();
+
+ while(!stack.isEmpty()) {
+ reverseSet.add(stack.pop());
+ }
+
+ return reverseSet;
+ }
+
+ /**
+ * @param pset package set
+ * @return all the packages that the given packages depends on directly or indirectly
+ */
+ private PackageSet dep(PackageSet pset, State state) {
+ PackageSet dep = new PackageSet();
+ for(Package p : pset) {
+ dep.addAll(dep(p, state));
+ }
+ return dep;
+ }
+
+ /**
+ * Get conflict package list from p.
+ * @param p
+ * @return packages that conflict with the given package directly or indirectly
+ */
+ public PackageSet conflictPackages(Package p) {
+ PackageSet conflicts = new PackageSet();
+ PackageSet dep = dep(p, State.INSTALL);
+ for(Package pkg : dep) {
+ Collection<String> conflictPackageNames = pkg.getConflictPackageNames();
+ for(String conflictPackageName : conflictPackageNames) {
+ if(installedPackages.hasPackageByName(conflictPackageName)) {
+ Package conflictPackage = installedPackages.getPackageByName(conflictPackageName);
+ conflicts.addAll(reverseDep(conflictPackage));
+ } else if (repoPackages.hasPackageByName(conflictPackageName)) {
+ Package conflictPackage = repoPackages.getPackageByName(conflictPackageName);
+ conflicts.addAll(reverseDep(conflictPackage));
+ }
+ }
+ }
+ return conflicts;
+ }
+
+ /**
+ * Get conflict package list.
+ * @param pset
+ * @return packages that conflict with the given packages directly or indirectly
+ */
+ public PackageSet conflictPackages(PackageSet pset) {
+ PackageSet conflicts = new PackageSet();
+ for(Package p : pset) {
+ conflicts.addAll(conflictPackages(p));
+ }
+ return conflicts;
+ }
+
+ /**
+ * Adds packages of pset2 to packages of pset1.
+ * @param pset1
+ * @param pset2
+ * @return new package set has the union of pset1 and pset2.
+ */
+ private PackageSet union(PackageSet pset1, PackageSet pset2) {
+ PackageSet union = (PackageSet) pset1.clone();
+ union.addAll(pset2);
+ return union;
+ }
+
+ /**
+ * Removes packages of pset2 from packages of pset1.
+ * @param pset1
+ * @param pset2
+ * @return new package set that represents (pset1 - pset2).
+ */
+ public PackageSet diff(PackageSet pset1, PackageSet pset2) {
+ PackageSet diff = new PackageSet();
+ for(Package p : pset1) {
+ if(!pset2.contains(p)) {
+ diff.add(p);
+ }
+ }
+ return diff;
+ }
+
+ private PackageSet diffPackageWithVersion(PackageSet pset1, PackageSet pset2) {
+ PackageSet diff = new PackageSet();
+ for(Package p : pset1) {
+ Package pkg = pset2.getPackage(p);
+
+ if (pkg == null) {
+ diff.add(p);
+ } else {
+ if (Version.compareTo(p.getVersion(), pkg.getVersion()) != 0) {
+ diff.add(p);
+ }
+ }
+ }
+ return diff;
+ }
+
+ /**
+ *
+ * @param pset1
+ * @param pset2
+ * @return new set of intersection of pset1 and pset2. It has the order of pset1.
+ */
+ private PackageSet intersect(PackageSet pset1, PackageSet pset2) {
+ PackageSet pset = new PackageSet();
+ for(Package p : pset1) {
+ if(pset2.contains(p)) {
+ pset.add(p);
+ }
+ }
+ return pset;
+ }
+
+ private PackageSet getDependMetas(PackageSet packageSet, State state) {
+ PackageSet depMetas = new PackageSet();
+ PackageSet depPkgs = dep(packageSet, state);
+ for (Package p : depPkgs) {
+ if (p.isMeta()) {
+ depMetas.add(p);
+ }
+ }
+
+ return depMetas;
+ }
+
+ /**
+ * @param m meta package to be checked updatable
+ * @return <code>true</code> if the meta package is updatable.
+ * ie. the meta package is installed and one of its dependents is already installed and is updatable.
+ */
+ public boolean isMetaUpdatable(Package m) {
+ // if one of the meta package's dependents is installed and updatable, the meta package is updatable.
+ PackageSet dep = dep(m, State.INSTALL);
+
+ for(Package p : dep) {
+
+ if(installedPackages.contains(p)) {
+ Package ip = installedPackages.getPackage(p);
+ if (ip == null) {
+ continue;
+ }
+
+ Package rp = null;
+ if (repoPackages != null && repoPackages.hasPackage(p)) {
+ rp = repoPackages.getPackage(p);
+ } else if (extensionPackages != null && extensionPackages.hasPackage(p)) {
+ rp = extensionPackages.getPackage(p);
+ }
+
+ // checks p is updatable
+ if(rp != null && rp.getVersion().compareTo(ip.getVersion()) != 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ /**
+ * @param m meta package to be checked removable
+ * @return <code>true</code> if the meta package is removable
+ * ie. the meta package is installed and one of its dependents is already installed and is removable.
+ */
+ private boolean isMetaRemovable(Package m) {
+ // if the meta package is not installed, it's never updatable
+ if(installedPackages.contains(m)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * check new installation or upgrade or downgrade.
+ * @param meta meta package to be checked installable.
+ * @return <code>true</code> if the meta package is updatable.
+ * ie. the meta package is installed and one of its dependents is already installed and is updatable.
+ */
+ private boolean isMetaInstallable(Package meta) {
+ // if one of the meta package's dependents is installed and updatable, the meta package is updatable.
+ PackageSet dep = dep(meta, State.INSTALL);
+
+ for(Package p : dep) {
+ //Do not check meta package. It is only used by install-type or category.
+ if (p.isMeta()) {
+ continue;
+ }
+
+ if(installedPackages.contains(p)) {
+ Package ip = installedPackages.getPackage(p);
+ if (ip == null) {
+ continue;
+ }
+
+ Package rp = repoPackages.getPackage(p); // rp always exists if ip exists
+
+ // checks p is updatable
+ if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // utility methods
+ /**
+ * Get installed package.
+ * @param pkg
+ * @return If not exist package in installed package list, return empty string.
+ */
+ public Package getInstalledPackageByName(String pkgName) {
+ Package retPkg = installedPackages.getPackageByName(pkgName);
+
+ return retPkg;
+ }
+
+ /**
+ * Get installed packages by package name.
+ * @param pkgName name of packages
+ * @return If not exist package in installed package list, return empty string.
+ */
+ public PackageSet getInstalledPackagesByName(List<String> pkgNames) {
+ PackageSet installedPackages = new PackageSet();
+ for (String pkg : pkgNames) {
+ Package retPkg = getInstalledPackageByName(pkg);
+
+ if (retPkg != null) {
+ installedPackages.add(retPkg);
+ }
+ }
+
+ return installedPackages;
+ }
+
+ /**
+ * Get Package instance from package name.
+ * @param pkgName
+ * @return
+ */
+ public Package getPackageByName(String pkgName) {
+ PackageSet packageList = repoPackages;
+ packageList.addAll(extensionPackages);
+
+ if (packageList.hasPackageByName(pkgName)) {
+ return packageList.getPackageByName(pkgName);
+ } else {
+ return null;
+ }
+ }
+
+ public boolean existsPackage(String packageName) {
+ if (getPackageByName(packageName) != null) {
+ return true;
+ } else if (getInstalledPackageByName(packageName) != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void removePackageFromPackageManager(String pkgName) {
+ PackageSet clone = (PackageSet) repoPackages.clone();
+ Package pkg = clone.getPackageByName(pkgName);
+
+ if (clone.hasPackage(pkg)) {
+ clone.remove(pkg);
+ }
+
+ repoPackages = clone;
+ }
+ /**
+ * @param packageNames
+ * @return packages collected by the given package names
+ */
+ public PackageSet getPackagesByNames(Collection<String> packageNames) {
+ PackageSet pset = new PackageSet();
+ for(String name : packageNames) {
+ if(repoPackages.hasPackageByName(name)) {
+ Package pkg = repoPackages.getPackageByName(name);
+ pset.add(pkg);
+ } else if (extensionPackages.hasPackageByName(name)) {
+ Package pkg = extensionPackages.getPackageByName(name);
+ pset.add(pkg);
+ } else {
+ throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);
+ }
+ }
+ return pset;
+ }
+
+ public PackageSet getMandatoryPackages() {
+ PackageSet pSet = new PackageSet();
+
+ for (Package pkg : repoPackages) {
+ if (pkg.isMandatory()) {
+ pSet.add(pkg);
+ }
+ }
+
+ return pSet;
+ }
+
+ public PackageSet getUpdatableMandatoryPackages() {
+ PackageSet pSet = new PackageSet();
+
+ for (Package mPkg : getMandatoryPackages()) {
+ if (!installedPackages.contains(mPkg)) {
+ pSet.add(mPkg);
+ } else if(isUpdatable(mPkg)) {
+ pSet.add(mPkg);
+ } else {
+ continue;
+ }
+ }
+
+ return pSet;
+ }
+
+ /**
+ * Check installed meta packages
+ * @return if installed package exists, return true. if not return false.
+ */
+ public boolean existInstalledMetaPackages() {
+ if (getInstalledMetaPackages().size() <= 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Check installable meta packages
+ * @return if installable meta package exists, return true. if not return false.
+ */
+ public boolean existInstallableMetaPackages() {
+ if (getInstalledMetaPackages().size() <= 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Check installed packages.
+ * @return if installed package exists, return true. if not return false.
+ */
+ public boolean existInstalledPackages() {
+ if (installedPackages.size() <= 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Check installable or updatable packages.
+ * @return if installable package exists, return true. if not return false.
+ */
+ public boolean existInstallablePackages() {
+ for(Package p : repoPackages) {
+ if(installedPackages.contains(p)) {
+ Package ip = installedPackages.getPackage(p);
+ if (ip == null) {
+ continue;
+ }
+
+ Package rp = recentPackages.getPackage(p); // rp always exists if ip exists
+ // checks p is updatable
+ if(rp.getVersion().compareTo(ip.getVersion()) > 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * get total size to remove.
+ * @param pkg
+ * @return
+ */
+ public long getTotalSizeOfRemovablePackages(Package pkg) {
+ PackageSet pkgs = new PackageSet();
+
+ pkgs.add(pkg);
+ PackageSet depPkgSet = getToRemovePackagesInRemove(pkgs);
+
+ return getTotalSize(depPkgSet, true);
+ }
+
+ /**
+ * get total size to install.
+ * @param pkg
+ * @param isUncompressed Uncompressed is true, not false.
+ * @return
+ */
+ public long getTotalSizeOfInstallablePackages(PackageSet pkgs, boolean isUncompressed) {
+ PackageSet depPkgSet = getInstallablePackages(pkgs);
+
+ return getTotalSize(depPkgSet, isUncompressed);
+ }
+
+ /**
+ * get total size to remove.
+ * @param pkg
+ * @return
+ */
+ public long getTotalSizeOfRemovablePackages(PackageSet pkgs) {
+ PackageSet depPkgSet = getRemovablePackagesInSnapshot(pkgs);
+
+ return getTotalSize(depPkgSet, true);
+ }
+
+ /**
+ * Get uncompressed packages size or compressed(zipped) packages size.
+ * @param pkgs Packages set which can be calculated total size.
+ * @param isUncompressed Uncompressed is true, not false.
+ * @return
+ */
+ private long getTotalSize(PackageSet pkgs, boolean isUncompressed) {
+ long totalSize = 0;
+ 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;
+ }
+
+ /**
+ * @return <code>true</code> if installed and repository packages are empty.
+ */
+ public boolean isEmpty() {
+
+ if (installedPackages.size() <= 0 && repoPackages.size() <= 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get Installable packages.
+ * @return packages that can be newly installable.
+ */
+ public PackageSet getInstallableMetaPackages() {
+ return diff(getAllMetaPackages(), getInstalledMetaPackages());
+ }
+
+ /**
+ * @return packages that can be newly installable or updatable.
+ */
+ public PackageSet getInstallableOrUpdatableMetaPackages() {
+ PackageSet installableMetaPackages = new PackageSet();
+ PackageSet allMetaPackages = getAllMetaPackages();
+
+ for (Package metaPackage : allMetaPackages) {
+ if (isMetaInstallable(metaPackage)) {
+ installableMetaPackages.add(metaPackage);
+ }
+ }
+
+ return installableMetaPackages;
+ }
+
+
+ /**
+ * Check missing packages from repository's package list.
+ * @return packages that is missing in repository's package list.
+ */
+ public PackageSet getMissingPackagesFromRepository() {
+ PackageSet missingPackages = new PackageSet();
+
+ if (!repoPackages.isEmpty()) {
+ missingPackages = diff(installedPackages, repoPackages);
+ missingPackages = diff(missingPackages, extensionPackages);
+ }
+
+ return missingPackages;
+ }
+
+ /**
+ * save packages to installedpackage.list
+ * @param filePath
+ */
- public void saveInstalledList(String filePath) {
- if (filePath == null) {
- return;
- }
++ public void saveInstalledList() {
++ String filePath = PathUtil.get(
++ PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
++ Config.INSTALLED_PACKAGE_LIST_FILE_NAME);
++
+ PropertyParser parser = new PropertyParser();
+ List<PropertySection> pSections = saveProperySectionsFromPackages(installedPackages);
+ parser.writeToFile(pSections, filePath);
+ }
+
+ /**
+ * save information of packages.
+ * @param packages
+ * @return
+ */
+ public List<PropertySection> saveProperySectionsFromPackages(PackageSet packages) {
+ List<PropertySection> pSections = new ArrayList<PropertySection>();
+ PropertySection pSection = null;
+ Properties properties = null;
+
+ for (Package pkg : packages) {
+ properties = (Properties)pkg.getProperties();
+ pSection = new PropertySection();
+ pSection.setProperties(properties);
+ pSections.add(pSection);
+ }
+
+ return pSections;
+ }
+
+ public PropertySection saveProperySectionsFromPackages(Package pkg) {
+ PropertySection pSection = null;
+ Properties properties = null;
+
+ properties = (Properties)pkg.getProperties();
+ pSection = new PropertySection();
+ pSection.setProperties(properties);
+
+ return pSection;
+ }
+
+ /**
+ * Check the repository change.
+ * @return
+ */
+ public boolean isRepositoryChanged() {
+ if (installedRepository == null || !currentRepository.equalsIgnoreCase(installedRepository)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check to need re-installation.
+ * If there has been a change distribution or repository or SDK image, force to re-install.
+ * @return If it needs to re-install, return true. otherwise return false.
+ */
- public boolean isReInstallable() {
++ public boolean isReInstall() {
+ if (isInstallInstallManager) {
+ return false;
+ } else if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {
+ return true;
+ } else if (isRepositoryChanged()) {
+ return true;
+ } else {
+ if (DistributionController.getInstance().isDistributionChanged()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
++ public boolean isConflict(PackageSet pkgsToInstall, Package pkg) {
++ return false;
++ }
++
+ /**
+ * Prints dependency graph of packages in dot format to stdout.
+ * @throws IMExitException
+ */
+ public void printDepGraph() {
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("digraph G {\n");
+
+ for(Package p : recentPackages) {
+ PackageSet dep = dep(p, State.INSTALL);
+
+ for(Package d : dep) {
+ if(!d.equals(p)) {
+ buf.append("\""+p+"\" -> \"" + d + "\";\n");
+ }
+ }
+ }
+
+ buf.append("}\n");
+ System.out.println(buf);
+ }
+
+ public static void dispose() {
+ if (pm != null) {
+ pm = null;
+ }
+ }
+
+ /**
+ * Get PackageManager singleton instance.
+ * @param installed
+ * @param repoPackagesUrls
+ * @return
+ * @throws IOException
+ */
+ public static PackageManager getInstance(File installed, Collection<String> repoPackagesUrls) throws IOException {
+ if (Options.platForm == null) {
+ if (Config.isSupportMultiSDK) {
+ if (!Registry.targetPath.equals("")) {
+ pm = null;
+ if (Platform.isLinux()) {
+ pm = new LinuxPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isWindows()) {
+ pm = new WindowsPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isMacOS()) {
+ pm = new DarwinPackageManager(installed, repoPackagesUrls);
+ } else {
+ return null;
+ }
+ } else {
+ if (pm == null) {
+ if (Platform.isLinux()) {
+ pm = new LinuxPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isWindows()) {
+ pm = new WindowsPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isMacOS()) {
+ pm = new DarwinPackageManager(installed, repoPackagesUrls);
+ } else {
+ return null;
+ }
+ }
+ }
+ } else {
+ if (pm == null) {
+ if (Platform.isLinux()) {
+ pm = new LinuxPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isWindows()) {
+ pm = new WindowsPackageManager(installed, repoPackagesUrls);
+ } else if (Platform.isMacOS()) {
+ pm = new DarwinPackageManager(installed, repoPackagesUrls);
+ } else {
+ return null;
+ }
+ }
+ }
+ } else {
+ if (pm == null) {
+ if (Options.platForm.equalsIgnoreCase("ubuntu")) {
+ pm = new LinuxPackageManager(installed, repoPackagesUrls);
+ } else if (Options.platForm.equalsIgnoreCase("windows")) {
+ pm = new WindowsPackageManager(installed, repoPackagesUrls);
+ } else if (Options.platForm.equalsIgnoreCase("macos")) {
+ pm = new DarwinPackageManager(installed, repoPackagesUrls);
+ } else {
+ return null;
+ }
+ }
+ }
+ return pm;
+ }
+
+ public static PackageManager getInstance() {
+ return pm;
+ }
+
+ public SDKExtensionInfo getSdkExtensionInfo() {
+ return SDKExtensionInfo.getInstance();
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */ \r
- \r
- package org.tizen.installmanager.pkg.model;\r
- \r
- import java.net.MalformedURLException;\r
- import java.net.URL;\r
- import java.util.Collection;\r
- import java.util.HashSet;\r
- import java.util.List;\r
- \r
- import org.tizen.installmanager.core.IMFatalException;\r
- import org.tizen.installmanager.core.Options;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.util.PathUtil;\r
- \r
- /**\r
- * This class describes a package.\r
- * \r
- * @author Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- *\r
- */\r
- public class Package {\r
- \r
- // fields of package control\r
- // mandatory\r
- public static final String FIELD_PACKAGE = "Package";\r
- public static final String FIELD_VERSION = "Version";\r
- public static final String FIELD_LABEL = "Label";\r
- public static final String FIELD_MAINTAINER = "Maintainer";\r
- public static final String FIELD_DESCRIPTION = "Description";\r
- \r
- // etc\r
- public static final String FIELD_DEPENDS = "Install-dependency"; // list of packages that this package depends on\r
- public static final String FIELD_CONFLICTS = "Conflicts";\r
- public static final String FIELD_PACKAGE_SIZE = "Size"; // size of zipped package\r
- public static final String FIELD_UNCOMPRESSED_SIZE = "Uncompressed-size"; // uncompressed size of package\r
- \r
- // fields of installed control\r
- public static final String FIELD_ATTRIBUTE = "Attribute";\r
- \r
- // fields of repository control\r
- public static final String FIELD_SHA256 = "SHA256";\r
- public static final String FIELD_FILE_PATH = "Path"; // path from the base url\r
- \r
- // fields of ordering for UI\r
- public static final String FIELD_ORDER = "C-Order";\r
- \r
- // field of Partner SDK\r
- public static final String FIELD_PARTNER = "C-Partner";\r
- \r
- // fields of script\r
- public static final String INSTALL_SCRIPT_LINUX = "install.sh";\r
- public static final String REMOVE_SCRIPT_LINUX = "remove.sh";\r
- public static final String INSTALL_SCRIPT_WINDOWS = "Install.bat";\r
- public static final String REMOVE_SCRIPT_WINDOWS = "Remove.bat";\r
- \r
- // fields of ui control\r
- public static final String FIELD_DEFAULT_CHECK = "Default";\r
- \r
- //field of extension server. this field is used by installed list.\r
- public static final String FIELD_EXTENSION_SERVER = "Extension-server"; \r
- \r
- // attribute value\r
- private static final String ATTRIBUTE_ROOT_META = "root";\r
- private static final String ATTRIBUTE_EXTRA_META = "extra";\r
- private static final String ATTRIBUTE_INSTALL_META = "install";\r
- private static final String ATTRIBUTE_TEST_META = "test";\r
- private static final String ATTRIBUTE_MANDATORY = "mandatory";\r
- private static final String ATTRIBUTE_PARTNER = "partner";\r
- private static final String ATTRIBUTE_PUBLIC = "public";\r
- \r
- //dependency information\r
- private static final String START_OF_OS_DEPENDENCY = "[";\r
- \r
- private List<Property> mProperties;\r
- private URL baseURL = null; \r
- private URL url; // url to the package zip file\r
- \r
- private static final int LOWEST_ORDER = 100;\r
- \r
- public Package(List<Property> properties) {\r
- this.mProperties = properties;\r
- }\r
- \r
- /**\r
- * Make url of package.\r
- * @param properties package\r
- * @param repoBaseUrl url before snapshot path.\r
- */\r
- public Package(Properties properties, String repoBaseUrl) {\r
- this(properties);\r
- \r
- try {\r
- this.baseURL = new URL(repoBaseUrl);\r
- this.url = new URL(PathUtil.addURLPath(repoBaseUrl, getValue(FIELD_FILE_PATH)));\r
- } catch (MalformedURLException e) {\r
- Log.err("Invalid package url: "+repoBaseUrl + "/" + getValue(FIELD_FILE_PATH));\r
- throw new IMFatalException(ErrorCode.WRONG_PACKAGE_URL);\r
- }\r
- }\r
- \r
- public void setProperties(List<Property> properties) {\r
- mProperties = properties;\r
- }\r
- \r
- /**\r
- * @return version of this package. If package does not have version, set version to 0.0.0\r
- */\r
- public Version getVersion() {\r
- String version = getValue(FIELD_VERSION);\r
- if (version == null || version.isEmpty()) {\r
- List<Property> props = this.getProperties();\r
- for (Property p : props) {\r
- if (p.getName().equalsIgnoreCase(Package.FIELD_VERSION)) {\r
- p.setValue("0.0.0");\r
- }\r
- }\r
- }\r
- return new Version(getValue(FIELD_VERSION)); \r
- }\r
- \r
- /**\r
- * @return package name of this package\r
- */\r
- public String getPackageName() {\r
- return getValue(FIELD_PACKAGE);\r
- }\r
- \r
- /**\r
- * @return name of package.\r
- */\r
- public String getLabel() {\r
- return getValue(FIELD_LABEL);\r
- }\r
- \r
- /**\r
- * @return the size of zipped package file \r
- */\r
- public Long getPackageSize() {\r
- long result = 0;\r
- try {\r
- result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE));\r
- } catch(NumberFormatException e) {\r
- Log.err(toString() + " size does not exist.");\r
- Log.ExceptionLog(e);\r
- }\r
- \r
- return result;\r
- }\r
- \r
- /**\r
- * @return the real size of package file \r
- */\r
- public Long getUncompressedPackageSize() {\r
- long result = 0;\r
- try {\r
- result = Long.parseLong(getValue(FIELD_UNCOMPRESSED_SIZE));\r
- } catch(NumberFormatException e) {\r
- // All packages do not have 'Uncompressed-size' filed.\r
- // In this case, InstallManager use 'Size' field.\r
- result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE)); \r
- }\r
- \r
- return result;\r
- }\r
- \r
- /**\r
- * @return Path of this package File from repository. \r
- */\r
- public String getFileName() {\r
- return getValue(FIELD_FILE_PATH);\r
- }\r
- \r
- /**\r
- * @return Description of this package.\r
- */\r
- public String getDescription() {\r
- return getValue(FIELD_DESCRIPTION);\r
- }\r
- \r
- /**\r
- * @return SHA256 digest of this package file.\r
- */\r
- public String getSHA256() {\r
- return getValue(FIELD_SHA256);\r
- }\r
- \r
- /**\r
- * @return URL to the package file in repository.\r
- */\r
- public URL getURL() {\r
- return url;\r
- }\r
- \r
- public URL getBaseURL() {\r
- return baseURL;\r
- }\r
- \r
- public String getPartner() {\r
- return getValue(FIELD_PARTNER);\r
- }\r
- \r
- /**\r
- * @return Extension server of this package.\r
- */\r
- public String getExtensionServer() {\r
- return getValue(FIELD_EXTENSION_SERVER);\r
- }\r
- \r
- /**\r
- * Set extension server to package information.\r
- * @param extensionServer extension server of this packge\r
- */\r
- public void setExtensionServer(String extensionServer) {\r
- Property property = getProperty(FIELD_EXTENSION_SERVER);\r
- \r
- if (property != null) {\r
- property.setValue(extensionServer);\r
- } else {\r
- property = new Property();\r
- property.setName(FIELD_EXTENSION_SERVER);\r
- property.setValue(extensionServer);\r
- \r
- mProperties.add(property);\r
- }\r
- }\r
- /**\r
- * Get package order for InstallManager displaying package tree.\r
- * @return package order\r
- */\r
- public int getOrder() {\r
- String order = getValue(FIELD_ORDER);\r
- if (order.equals("")) {\r
- return LOWEST_ORDER;\r
- } else {\r
- int nOrder = 0;\r
- try {\r
- nOrder = Integer.parseInt(order);\r
- } catch (NumberFormatException e) {\r
- Log.err("C-Order field value is not a integer format.");\r
- return 100;\r
- }\r
- return nOrder; \r
- }\r
- }\r
- \r
- /**\r
- * @return Remove Script name of this package.\r
- */\r
- public String getRemoveScript() {\r
- if (Platform.CURRENT_PLATFORM == Platform.LINUX_32\r
- || Platform.CURRENT_PLATFORM == Platform.LINUX_64\r
- || Platform.CURRENT_PLATFORM == Platform.MACOS_64\r
- || Platform.CURRENT_PLATFORM == Platform.MACOS_32) {\r
- return REMOVE_SCRIPT_LINUX;\r
- } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32\r
- || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {\r
- return REMOVE_SCRIPT_WINDOWS;\r
- } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) {\r
- return "";\r
- }\r
- return null;\r
- }\r
- \r
- /**\r
- * @return Install script name of this package.\r
- */\r
- public String getInstallScript() {\r
- if (Platform.isUbuntu() || Platform.isMacOS()) {\r
- return INSTALL_SCRIPT_LINUX;\r
- } else if (Platform.isWindows()) {\r
- return INSTALL_SCRIPT_WINDOWS;\r
- }\r
- \r
- return null;\r
- }\r
- \r
- /**\r
- * @return List of Property instance.\r
- */\r
- public List<Property> getProperties() {\r
- return mProperties;\r
- }\r
- \r
- /**\r
- * Get Property instance from key.\r
- * \r
- * @param key\r
- * @return\r
- */\r
- private Property getProperty(String key) {\r
- if (mProperties != null && key != null) {\r
- for (int i = 0; i < mProperties.size(); i++) {\r
- if (key.compareTo(mProperties.get(i).getName()) == 0) {\r
- return mProperties.get(i);\r
- }\r
- }\r
- }\r
- return null;\r
- }\r
- \r
- /**\r
- * @param propertyName\r
- * @return string value of the property name. empty string if there's no such property name\r
- */\r
- private String getValue(String propertyName) {\r
- for(Property prop : mProperties) {\r
- if(prop.getName().equals(propertyName)) {\r
- return prop.getValue();\r
- }\r
- }\r
- return "";\r
- }\r
- \r
- /**\r
- * @return Attribute value.\r
- */\r
- public String getAttribute() {\r
- return getValue(FIELD_ATTRIBUTE);\r
- }\r
- \r
- /**\r
- * @return <code>true</code> if this package is a meta package.\r
- */\r
- public boolean isMeta() {\r
- // onlyDownload option, in this case, do not need separate public meta package \r
- // to partner meta package because installmanager should download all meta packages.\r
- if (Options.onlyDownload) {\r
- if (isRootMeta() || isInstallMeta() || isExtraMeta() ||\r
- isPublicMeta() || isPartnerMeta() || isMandatory()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- if (Options.doTest) { // include test packages for SDK testing\r
- if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta() || isTestMeta()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- } else { // except test packages for normal SDK.\r
- if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta()) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * @return <code>true</code> if this package is a root meta package.\r
- */\r
- public boolean isRootMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_ROOT_META)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * @return <code>true</code> if this package is a extra meta package.\r
- */\r
- public boolean isExtraMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_EXTRA_META)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Check to belong to partner sdk given package\r
- * @return <code>true</code> if this package is a partner package.\r
- */\r
- public boolean isPartnerMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PARTNER)) {\r
- return true;\r
- } else {\r
- return false;\r
- } \r
- }\r
- \r
- /**\r
- * Check to belong to partner sdk given package\r
- * @return <code>true</code> if this package is a partner package.\r
- */\r
- public boolean isPublicMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PUBLIC)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- } \r
- \r
- /**\r
- * @return <code>true</code> if this meta package is a install meta package.\r
- */\r
- public boolean isInstallMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_INSTALL_META)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * @return <code>true</code> if this meta package is a install meta package.\r
- */\r
- public boolean isTestMeta() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_TEST_META)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * @return <code>true</code>, if this package is a mandatory package. This package must install.\r
- */\r
- public boolean isMandatory() {\r
- String attributeValue = getAttribute().trim();\r
- \r
- if (attributeValue.equalsIgnoreCase(ATTRIBUTE_MANDATORY)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public boolean isExtensionPackage() {\r
- String extensionServer = getExtensionServer();\r
- \r
- if (extensionServer == null || extensionServer.isEmpty()) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * @return package names that this package directly depends on\r
- */\r
- public Collection<String> getDependentPackageNames() {\r
- HashSet<String> depends = new HashSet<String>();\r
- String dependsStr = getValue(FIELD_DEPENDS);\r
- String deps[] = dependsStr.split(",");\r
- for(int i = 0; i < deps.length; i++) {\r
- String dep = removeOSInformationOfDepends(deps[i]);\r
- \r
- if(!dep.isEmpty()) {\r
- depends.add(dep);\r
- }\r
- }\r
- return depends;\r
- }\r
- \r
- private String removeOSInformationOfDepends(String info) { \r
- //Log.log("Package.removeOSInformation (info => " + info + ")");\r
- \r
- if (info.contains(START_OF_OS_DEPENDENCY)) {\r
- int index = info.indexOf(START_OF_OS_DEPENDENCY);\r
- String pkgInfo = info.substring(0, index).trim();\r
- \r
- return pkgInfo;\r
- } else {\r
- return info.trim();\r
- }\r
- }\r
- \r
- /**\r
- * @return package names that this package directly conflicts to\r
- */\r
- public Collection<String> getConflictPackageNames() {\r
- HashSet<String> conflicts = new HashSet<String>();\r
- String conflictsStr = getValue(FIELD_CONFLICTS);\r
- String confs[] = conflictsStr.split(",");\r
- for(int i = 0; i < confs.length; i++) {\r
- conflicts.add(confs[i].trim());\r
- }\r
- return conflicts;\r
- }\r
- \r
- public String toString() {\r
- return getPackageName();\r
- }\r
- \r
- /**\r
- * Checks equality symbolically only using their package names.\r
- * @return <code>true</code> if they have the same package name.\r
- */\r
- public boolean equals(Object obj) {\r
- if (obj instanceof Package) {\r
- Package pkg2 = (Package)obj;\r
- return this.getPackageName().equals(pkg2.getPackageName());\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public int hashCode() {\r
- return getPackageName().hashCode();\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.pkg.model;
+
+ import java.net.MalformedURLException;
+ import java.net.URL;
+ import java.util.Collection;
+ import java.util.HashSet;
+ import java.util.List;
+
-import org.tizen.installmanager.core.Config;
+ import org.tizen.installmanager.core.IMFatalException;
+ import org.tizen.installmanager.core.Options;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.lib.Platform;
++import org.tizen.installmanager.util.PathUtil;
+
+ /**
+ * This class describes a package.
+ *
+ * @author Wooyoung Cho <wooyoung1.cho@samsung.com>
+ *
+ */
+ public class Package {
+
+ // fields of package control
+ // mandatory
+ public static final String FIELD_PACKAGE = "Package";
+ public static final String FIELD_VERSION = "Version";
+ public static final String FIELD_LABEL = "Label";
+ public static final String FIELD_MAINTAINER = "Maintainer";
+ public static final String FIELD_DESCRIPTION = "Description";
+
+ // etc
+ public static final String FIELD_DEPENDS = "Install-dependency"; // list of packages that this package depends on
+ public static final String FIELD_CONFLICTS = "Conflicts";
+ public static final String FIELD_PACKAGE_SIZE = "Size"; // size of zipped package
+ public static final String FIELD_UNCOMPRESSED_SIZE = "Uncompressed-size"; // uncompressed size of package
+
+ // fields of installed control
+ public static final String FIELD_ATTRIBUTE = "Attribute";
+
+ // fields of repository control
+ public static final String FIELD_SHA256 = "SHA256";
+ public static final String FIELD_FILE_PATH = "Path"; // path from the base url
+
+ // fields of ordering for UI
+ public static final String FIELD_ORDER = "C-Order";
+
+ // field of Partner SDK
+ public static final String FIELD_PARTNER = "C-Partner";
+
+ // fields of script
+ public static final String INSTALL_SCRIPT_LINUX = "install.sh";
+ public static final String REMOVE_SCRIPT_LINUX = "remove.sh";
+ public static final String INSTALL_SCRIPT_WINDOWS = "Install.bat";
+ public static final String REMOVE_SCRIPT_WINDOWS = "Remove.bat";
+
+ // fields of ui control
+ public static final String FIELD_DEFAULT_CHECK = "Default";
+
+ //field of extension server. this field is used by installed list.
+ public static final String FIELD_EXTENSION_SERVER = "Extension-server";
+
+ // attribute value
+ private static final String ATTRIBUTE_ROOT_META = "root";
+ private static final String ATTRIBUTE_EXTRA_META = "extra";
+ private static final String ATTRIBUTE_INSTALL_META = "install";
+ private static final String ATTRIBUTE_TEST_META = "test";
+ private static final String ATTRIBUTE_MANDATORY = "mandatory";
+ private static final String ATTRIBUTE_PARTNER = "partner";
+ private static final String ATTRIBUTE_PUBLIC = "public";
+
+ //dependency information
+ private static final String START_OF_OS_DEPENDENCY = "[";
+
+ private List<Property> mProperties;
++ private URL baseURL = null;
+ private URL url; // url to the package zip file
+
+ private static final int LOWEST_ORDER = 100;
+
+ public Package(List<Property> properties) {
+ this.mProperties = properties;
+ }
+
+ /**
+ * Make url of package.
+ * @param properties package
+ * @param repoBaseUrl url before snapshot path.
+ */
+ public Package(Properties properties, String repoBaseUrl) {
+ this(properties);
++
+ try {
- 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));
-// }
++ 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);
+ }
+ }
+
+ public void setProperties(List<Property> properties) {
+ mProperties = properties;
+ }
+
+ /**
+ * @return version of this package. If package does not have version, set version to 0.0.0
+ */
+ public Version getVersion() {
+ String version = getValue(FIELD_VERSION);
+ if (version == null || version.isEmpty()) {
+ List<Property> props = this.getProperties();
+ for (Property p : props) {
+ if (p.getName().equalsIgnoreCase(Package.FIELD_VERSION)) {
+ p.setValue("0.0.0");
+ }
+ }
+ }
+ return new Version(getValue(FIELD_VERSION));
+ }
+
+ /**
+ * @return package name of this package
+ */
+ public String getPackageName() {
+ return getValue(FIELD_PACKAGE);
+ }
+
+ /**
+ * @return name of package.
+ */
+ public String getLabel() {
+ return getValue(FIELD_LABEL);
+ }
+
+ /**
+ * @return the size of zipped package file
+ */
+ public Long getPackageSize() {
+ long result = 0;
+ try {
+ result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE));
+ } catch(NumberFormatException e) {
+ Log.err(toString() + " size does not exist.");
+ Log.ExceptionLog(e);
+ }
+
+ return result;
+ }
+
+ /**
+ * @return the real size of package file
+ */
+ public Long getUncompressedPackageSize() {
+ long result = 0;
+ try {
+ result = Long.parseLong(getValue(FIELD_UNCOMPRESSED_SIZE));
+ } catch(NumberFormatException e) {
+ // All packages do not have 'Uncompressed-size' filed.
+ // In this case, InstallManager use 'Size' field.
+ result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE));
+ }
+
+ return result;
+ }
+
+ /**
+ * @return Path of this package File from repository.
+ */
+ public String getFileName() {
+ return getValue(FIELD_FILE_PATH);
+ }
+
+ /**
+ * @return Description of this package.
+ */
+ public String getDescription() {
+ return getValue(FIELD_DESCRIPTION);
+ }
+
+ /**
+ * @return SHA256 digest of this package file.
+ */
+ public String getSHA256() {
+ return getValue(FIELD_SHA256);
+ }
+
+ /**
+ * @return URL to the package file in repository.
+ */
+ public URL getURL() {
+ return url;
+ }
+
++ public URL getBaseURL() {
++ return baseURL;
++ }
++
+ public String getPartner() {
+ return getValue(FIELD_PARTNER);
+ }
+
+ /**
+ * @return Extension server of this package.
+ */
+ public String getExtensionServer() {
+ return getValue(FIELD_EXTENSION_SERVER);
+ }
+
+ /**
+ * Set extension server to package information.
+ * @param extensionServer extension server of this packge
+ */
+ public void setExtensionServer(String extensionServer) {
+ Property property = getProperty(FIELD_EXTENSION_SERVER);
+
+ if (property != null) {
+ property.setValue(extensionServer);
+ } else {
+ property = new Property();
+ property.setName(FIELD_EXTENSION_SERVER);
+ property.setValue(extensionServer);
+
+ mProperties.add(property);
+ }
+ }
+ /**
+ * Get package order for InstallManager displaying package tree.
+ * @return package order
+ */
+ public int getOrder() {
+ String order = getValue(FIELD_ORDER);
+ if (order.equals("")) {
+ return LOWEST_ORDER;
+ } else {
+ int nOrder = 0;
+ try {
+ nOrder = Integer.parseInt(order);
+ } catch (NumberFormatException e) {
+ Log.err("C-Order field value is not a integer format.");
+ return 100;
+ }
+ return nOrder;
+ }
+ }
+
+ /**
+ * @return Remove Script name of this package.
+ */
+ public String getRemoveScript() {
+ if (Platform.CURRENT_PLATFORM == Platform.LINUX_32
+ || Platform.CURRENT_PLATFORM == Platform.LINUX_64
+ || Platform.CURRENT_PLATFORM == Platform.MACOS_64
+ || Platform.CURRENT_PLATFORM == Platform.MACOS_32) {
+ return REMOVE_SCRIPT_LINUX;
+ } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32
+ || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {
+ return REMOVE_SCRIPT_WINDOWS;
+ } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) {
+ return "";
+ }
+ return null;
+ }
+
+ /**
+ * @return Install script name of this package.
+ */
+ public String getInstallScript() {
+ if (Platform.isUbuntu() || Platform.isMacOS()) {
+ return INSTALL_SCRIPT_LINUX;
+ } else if (Platform.isWindows()) {
+ return INSTALL_SCRIPT_WINDOWS;
+ }
+
+ return null;
+ }
+
+ /**
+ * @return List of Property instance.
+ */
+ public List<Property> getProperties() {
+ return mProperties;
+ }
+
+ /**
+ * Get Property instance from key.
+ *
+ * @param key
+ * @return
+ */
+ private Property getProperty(String key) {
+ if (mProperties != null && key != null) {
+ for (int i = 0; i < mProperties.size(); i++) {
+ if (key.compareTo(mProperties.get(i).getName()) == 0) {
+ return mProperties.get(i);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param propertyName
+ * @return string value of the property name. empty string if there's no such property name
+ */
+ private String getValue(String propertyName) {
+ for(Property prop : mProperties) {
+ if(prop.getName().equals(propertyName)) {
+ return prop.getValue();
+ }
+ }
+ return "";
+ }
+
+ /**
+ * @return Attribute value.
+ */
+ public String getAttribute() {
+ return getValue(FIELD_ATTRIBUTE);
+ }
+
+ /**
+ * @return <code>true</code> if this package is a meta package.
+ */
+ public boolean isMeta() {
+ // onlyDownload option, in this case, do not need separate public meta package
+ // to partner meta package because installmanager should download all meta packages.
+ if (Options.onlyDownload) {
+ if (isRootMeta() || isInstallMeta() || isExtraMeta() ||
+ isPublicMeta() || isPartnerMeta() || isMandatory()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ if (Options.doTest) { // include test packages for SDK testing
+ if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta() || isTestMeta()) {
+ return true;
+ } else {
+ return false;
+ }
+ } else { // except test packages for normal SDK.
+ if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * @return <code>true</code> if this package is a root meta package.
+ */
+ public boolean isRootMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_ROOT_META)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return <code>true</code> if this package is a extra meta package.
+ */
+ public boolean isExtraMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_EXTRA_META)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check to belong to partner sdk given package
+ * @return <code>true</code> if this package is a partner package.
+ */
+ public boolean isPartnerMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PARTNER)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check to belong to partner sdk given package
+ * @return <code>true</code> if this package is a partner package.
+ */
+ public boolean isPublicMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PUBLIC)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return <code>true</code> if this meta package is a install meta package.
+ */
+ public boolean isInstallMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_INSTALL_META)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return <code>true</code> if this meta package is a install meta package.
+ */
+ public boolean isTestMeta() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_TEST_META)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return <code>true</code>, if this package is a mandatory package. This package must install.
+ */
+ public boolean isMandatory() {
+ String attributeValue = getAttribute().trim();
+
+ if (attributeValue.equalsIgnoreCase(ATTRIBUTE_MANDATORY)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isExtensionPackage() {
+ String extensionServer = getExtensionServer();
+
+ if (extensionServer == null || extensionServer.isEmpty()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * @return package names that this package directly depends on
+ */
+ public Collection<String> getDependentPackageNames() {
+ HashSet<String> depends = new HashSet<String>();
+ String dependsStr = getValue(FIELD_DEPENDS);
+ String deps[] = dependsStr.split(",");
+ for(int i = 0; i < deps.length; i++) {
+ String dep = removeOSInformationOfDepends(deps[i]);
+
+ if(!dep.isEmpty()) {
+ depends.add(dep);
+ }
+ }
+ return depends;
+ }
+
+ private String removeOSInformationOfDepends(String info) {
+ //Log.log("Package.removeOSInformation (info => " + info + ")");
+
+ if (info.contains(START_OF_OS_DEPENDENCY)) {
+ int index = info.indexOf(START_OF_OS_DEPENDENCY);
+ String pkgInfo = info.substring(0, index).trim();
+
+ return pkgInfo;
+ } else {
+ return info.trim();
+ }
+ }
+
+ /**
+ * @return package names that this package directly conflicts to
+ */
+ public Collection<String> getConflictPackageNames() {
+ HashSet<String> conflicts = new HashSet<String>();
+ String conflictsStr = getValue(FIELD_CONFLICTS);
+ String confs[] = conflictsStr.split(",");
+ for(int i = 0; i < confs.length; i++) {
+ conflicts.add(confs[i].trim());
+ }
+ return conflicts;
+ }
+
+ public String toString() {
+ return getPackageName();
+ }
+
+ /**
+ * Checks equality symbolically only using their package names.
+ * @return <code>true</code> if they have the same package name.
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof Package) {
+ Package pkg2 = (Package)obj;
+ return this.getPackageName().equals(pkg2.getPackageName());
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return getPackageName().hashCode();
+ }
+ }
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.ui;\r
- \r
- import java.io.IOException;\r
- import java.util.ArrayList;\r
- import java.util.Arrays;\r
- import java.util.Enumeration;\r
- import java.util.Iterator;\r
- import java.util.List;\r
- import java.util.Map;\r
- import java.util.Map.Entry;\r
- import java.util.Properties;\r
- import java.util.Set;\r
- \r
- import org.eclipse.jface.window.ApplicationWindow;\r
- import org.eclipse.swt.SWT;\r
- import org.eclipse.swt.custom.StackLayout;\r
- import org.eclipse.swt.events.PaintEvent;\r
- import org.eclipse.swt.events.PaintListener;\r
- import org.eclipse.swt.events.SelectionAdapter;\r
- import org.eclipse.swt.events.SelectionEvent;\r
- import org.eclipse.swt.graphics.Color;\r
- import org.eclipse.swt.graphics.Image;\r
- import org.eclipse.swt.graphics.Point;\r
- import org.eclipse.swt.graphics.RGB;\r
- import org.eclipse.swt.layout.RowData;\r
- import org.eclipse.swt.layout.RowLayout;\r
- import org.eclipse.swt.widgets.Button;\r
- import org.eclipse.swt.widgets.Composite;\r
- import org.eclipse.swt.widgets.Control;\r
- import org.eclipse.swt.widgets.Display;\r
- import org.eclipse.swt.widgets.Event;\r
- import org.eclipse.swt.widgets.Label;\r
- import org.eclipse.swt.widgets.Layout;\r
- import org.eclipse.swt.widgets.Listener;\r
- import org.eclipse.swt.widgets.Shell;\r
- import org.tizen.installmanager.cli.InstallManagerNoUI;\r
- import org.tizen.installmanager.core.Config;\r
- import org.tizen.installmanager.core.IMExitException;\r
- import org.tizen.installmanager.core.IMFatalException;\r
- import org.tizen.installmanager.core.InstallManager;\r
- import org.tizen.installmanager.core.Options;\r
- import org.tizen.installmanager.core.Performance;\r
- import org.tizen.installmanager.lib.ErrorController;\r
- import org.tizen.installmanager.lib.IMError;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.ProgramController;\r
- import org.tizen.installmanager.lib.Registry;\r
- import org.tizen.installmanager.lib.exception.IMNetworkException;\r
- import org.tizen.installmanager.lib.mac.CocoaUtil;\r
- import org.tizen.installmanager.pkg.lib.PackageManager;\r
- import org.tizen.installmanager.pkg.model.ConfigFile;\r
- import org.tizen.installmanager.pkg.model.PackageSet;\r
- import org.tizen.installmanager.ui.dialog.AddExtraRepositoryDialog;\r
- import org.tizen.installmanager.ui.dialog.IndeterminateProgressDialog;\r
- import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
- import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
- import org.tizen.installmanager.ui.dialog.ProxySettingsDialog;\r
- import org.tizen.installmanager.ui.model.Item;\r
- import org.tizen.installmanager.ui.page.CompletePage;\r
- import org.tizen.installmanager.ui.page.InstallPage;\r
- import org.tizen.installmanager.ui.page.InstallableListPage;\r
- import org.tizen.installmanager.ui.page.InstallingPage;\r
- import org.tizen.installmanager.ui.page.LicensePage;\r
- import org.tizen.installmanager.ui.page.SetInstallDirectoryPage;\r
- import org.tizen.installmanager.ui.page.UninstallableListPage;\r
- import org.tizen.installmanager.ui.page.UninstallingPage;\r
- import org.tizen.installmanager.ui.page.UpdatableListPage;\r
- import org.tizen.installmanager.ui.page.ViewController;\r
- import org.tizen.installmanager.ui.page.WelcomePage;\r
- import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
- import org.tizen.installmanager.ui.page.WelcomePage.INSTALLMANAGER_ACTION;\r
- import org.tizen.installmanager.util.PathUtil;\r
- import org.tizen.installmanager.pkg.model.Package;\r
- \r
- \r
- /**\r
- * This class is main class for install manager.\r
- * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
- */\r
- public class InstallManagerWindow extends ApplicationWindow {\r
- private static final RGB RGB_BACKGROUND = new RGB(242, 242, 242);\r
- \r
- private static final Point POINT_MAIN_WINDOW = new Point(628, 478);\r
- private static Image IMAGE_WINDOW_ICON;\r
- private static Color COLOR_BACKGROUND;\r
- \r
- private static InstallManagerWindow window;\r
- \r
- // private StackLayout sl_composite = new StackLayout();\r
- public StackLayout sl_composite = new StackLayout();\r
- private static Button btnClose;\r
- private static Button btnBack;\r
- private static Button btnNext;\r
- \r
- private Composite pageComposite; // Page area\r
- private WelcomePage compositeWelcomePage;\r
- private LicensePage compositeLicensePage;\r
- private InstallableListPage compositeInstallableListPage;\r
- private UninstallableListPage compositeUninstallableListPage;\r
- private InstallingPage compositeInstallingPage;\r
- private UninstallingPage compositeUninstallingPage;\r
- private CompletePage compositeCompletePage;\r
- private SetInstallDirectoryPage compositeSetInstallDirectoryPage;\r
- public UpdatableListPage compositeUpdatableListPage;\r
- \r
- protected static ViewController controller;\r
- private SelectionAdapter cancelBtnSelectionAdapter = null;\r
- private SelectionAdapter closeBtnSelectionAdapter = null;\r
- \r
- /**\r
- * Create the application window.\r
- */\r
- public InstallManagerWindow() {\r
- super(null);\r
- setShellStyle(SWT.SHELL_TRIM);\r
- setShellStyle(SWT.BORDER | SWT.TITLE);\r
- }\r
- \r
- /**\r
- * Get installmanager window background color.\r
- * @return background color\r
- */\r
- public static Color getBackgroundColor() {\r
- if (COLOR_BACKGROUND == null) {\r
- COLOR_BACKGROUND = new Color(null, RGB_BACKGROUND);\r
- }\r
- return COLOR_BACKGROUND;\r
- }\r
- \r
- private static Image getWindowIconImage() {\r
- if (IMAGE_WINDOW_ICON == null) {\r
- IMAGE_WINDOW_ICON = PathUtil.getImageFromResource("/res/icons/SDK_icon.png");\r
- }\r
- return IMAGE_WINDOW_ICON;\r
- }\r
- \r
- private void init() throws IMExitException{\r
- Log.log("Window init start");\r
- \r
- //make waiting dialog.\r
- final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();\r
- \r
- final Shell shell = progressbar.getParent();\r
- shell.getDisplay().asyncExec(new Runnable(){\r
- public void run() { \r
- //initialize installmanager\r
- progressbar.updateName("Connecting to package server.\nIt may take a minute...");\r
- \r
- shell.getDisplay().asyncExec(new Runnable() {\r
- public void run() {\r
- initInstallManager();\r
- }\r
- \r
- });\r
- \r
- //init end\r
- progressbar.finish();\r
- }\r
- });\r
- \r
- if (!shell.isDisposed()) {\r
- progressbar.open();\r
- }\r
- \r
- Log.log("Window init end");\r
- }\r
- \r
- private void updateInstallManager(Shell shell) {\r
- if (controller.canInstallManagerUpdate()) {\r
- String msg = "There is a new installer on the server. \nNew install-manager will be started. \nIt may take a minute...";\r
- MessageBoxDlg.showDlg(shell, "InstallManager", msg, DialogType.NOTIFY, false);\r
- \r
- controller.updateInstallManager();\r
- }\r
- }\r
- \r
- /**\r
- * init IM's configuation and packages information.\r
- * @return\r
- */\r
- public boolean initInstallManager() {\r
- ErrorController.setInstallationSuccess(true);\r
- \r
- controller = new ViewController();\r
- \r
- if (controller.init()) {\r
- if (Config.isSupportMultiSDK()) {\r
- Log.log("Multi SDK installation.");\r
- } else {\r
- Log.log("Single SDK installation.");\r
- }\r
- return true;\r
- } else {\r
- Log.err("InstallManager init fail.");\r
- ErrorController.setInstallationSuccess(false);\r
- \r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Create contents of the application window.\r
- * \r
- * @param parent\r
- */\r
- @Override\r
- protected Control createContents(Composite parent) {\r
- \r
- parent.setSize(630, 490);\r
- IMError.setComposite(parent);\r
- Composite container = new Composite(parent, SWT.NONE);\r
- \r
- // Set layout attributes.\r
- RowLayout rl_container = new RowLayout(SWT.VERTICAL);\r
- rl_container.spacing = 0;\r
- rl_container.marginTop = 0;\r
- rl_container.marginRight = 0;\r
- rl_container.marginLeft = 0;\r
- rl_container.marginBottom = 0;\r
- container.setLayout(rl_container);\r
- \r
- // Set page composite size. (image, label, etc.)\r
- pageComposite = new Composite(container, SWT.NONE);\r
- pageComposite.setLayoutData(new RowData(628, 405));\r
- pageComposite.setLayout(sl_composite);\r
- \r
- Composite composite_buttonArea = new Composite(container, SWT.NONE);\r
- composite_buttonArea.setLayoutData(new RowData(628, 52));\r
- composite_buttonArea.setBackground(getBackgroundColor());\r
- \r
- setButtonClose(composite_buttonArea);\r
- setButtonNext(composite_buttonArea);\r
- setButtonBack(composite_buttonArea);\r
- \r
- compositeWelcomePage = new WelcomePage(pageComposite, SWT.NONE);\r
- compositeLicensePage = new LicensePage(pageComposite, SWT.NONE);\r
- compositeCompletePage = new CompletePage(pageComposite, SWT.NONE);\r
- compositeInstallingPage = new InstallingPage(pageComposite, SWT.NONE);\r
- compositeInstallableListPage = new InstallableListPage(pageComposite, SWT.NONE);\r
- compositeUninstallingPage = new UninstallingPage(pageComposite, SWT.NONE);\r
- compositeUninstallableListPage = new UninstallableListPage(pageComposite, SWT.NONE);\r
- compositeSetInstallDirectoryPage = new SetInstallDirectoryPage(pageComposite, SWT.NONE);\r
- compositeUpdatableListPage = new UpdatableListPage(pageComposite, SWT.NONE);\r
- \r
- // registLicensePageListener();\r
- // registCompletePageListener();\r
- \r
- initWelcomePage();\r
- \r
- return container;\r
- }\r
- \r
- private void setButtonClose(Composite composite) {\r
- btnClose = new Button(composite, SWT.NONE);\r
- btnClose.setText("Cancel");\r
- cancelBtnSelectionAdapter = new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- int result = MessageBoxDlg.NO;\r
- if (sl_composite.topControl == compositeInstallingPage) {\r
- InstallProgressMonitor mon = compositeInstallingPage.getInstallProgressMonitor();\r
- mon.setCancelRequested(true);\r
- result = MessageBoxDlg.showDlg(\r
- e.display.getActiveShell(),\r
- "Tizen SDK Install Manager",\r
- "Are you sure you want to quit Install Manager?\n\nIf you click \"Yes\", the installation is stopped.",\r
- DialogType.WARNING, false);\r
- if (result == MessageBoxDlg.YES) {\r
- mon.setCanceled(true);\r
- } else {\r
- mon.setCancelRequested(false);\r
- }\r
- return;\r
- } else if (sl_composite.topControl == compositeUninstallingPage) {\r
- result = MessageBoxDlg.showDlg(\r
- e.display.getActiveShell(),\r
- "Tizen SDK Install Manager",\r
- "Are you sure to quit Install Manager?\n\nIf you click \"Yes\", the uninstallation is stopped.",\r
- DialogType.WARNING, false);\r
- } else if (sl_composite.topControl == compositeCompletePage) {\r
- controller.showChangeLog();\r
- \r
- if (!Options.doResumeDownloading) {\r
- controller.cleanUpTargetDirectory();\r
- }\r
- \r
- result = MessageBoxDlg.YES;\r
- } else {\r
- result = MessageBoxDlg.showDlg(e.display.getActiveShell(),\r
- "Tizen SDK Install Manager",\r
- "Are you sure to quit Install Manager?",\r
- DialogType.WARNING, false);\r
- }\r
- \r
- if (result == MessageBoxDlg.YES) {\r
- e.display.close();\r
- }\r
- }\r
- };\r
- \r
- closeBtnSelectionAdapter = new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent arg0) {\r
- arg0.display.close();\r
- }\r
- };\r
- \r
- btnClose.addSelectionListener(cancelBtnSelectionAdapter);\r
- btnClose.setBounds(531, 10, 78, 29);\r
- }\r
- \r
- private void setButtonNext(Composite composite) {\r
- btnNext = new Button(composite, SWT.NONE);\r
- btnNext.setText("Next");\r
- btnNext.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (sl_composite.topControl == compositeWelcomePage) {\r
- updateInstallManager(e.display.getActiveShell());\r
- btnNext.setVisible(false);\r
- if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.INSTALL) {\r
- if (!checkVaildPkgVersion()) {\r
- return;\r
- }\r
- \r
- if (!controller.isNewInstallation()) {// Update case\r
- Config.status = Config.Status.UPDATE;\r
- compositeUpdatableListPage.loadPage(controller);\r
- btnBack.setVisible(true);\r
- btnNext.setVisible(true);\r
- showComposite(compositeUpdatableListPage);\r
- if (controller.existRemovablePackage()) {\r
- btnNext.setText("Install");\r
- }\r
- btnBack.setVisible(true);\r
- } else {\r
- boolean hasItem = compositeInstallableListPage.loadPage(controller);\r
- if (hasItem) {\r
- Config.status = Config.Status.INSTALL;\r
- showComposite(compositeInstallableListPage);\r
- btnNext.setVisible(true);\r
- btnNext.setEnabled(hasItem);\r
- btnBack.setVisible(hasItem);\r
- if (controller.existRemovablePackage()) {\r
- btnNext.setText("Install");\r
- }\r
- } else {\r
- Log.err("Installable packages do not exist. This is error.");\r
- //TODO\r
- }\r
- }\r
- } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UPDATE) {\r
- // btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());\r
- btnNext.setEnabled(true);\r
- PackageManager.dispose();\r
- initInstallManager();\r
- compositeUpdatableListPage.loadPage(controller);\r
- btnBack.setVisible(true);\r
- showComposite(compositeUpdatableListPage);\r
- if (controller.existRemovablePackage()) {\r
- btnNext.setText("Install");\r
- }\r
- btnBack.setVisible(true);\r
- } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UNINSTALL) {\r
- showComposite(compositeUninstallableListPage);\r
- btnNext.setVisible(true);\r
- btnBack.setVisible(true);\r
- btnNext.setText("Uninstall");\r
- compositeUninstallableListPage.loadPage(controller);\r
- // int resultDialog = MessageBoxDlg.NO;\r
- // resultDialog = MessageBoxDlg.showDlg(\r
- // e.display.getActiveShell(),\r
- // "Tizen SDK Install Manager",\r
- // "Are you sure you want to remove the Tizen SDK?\n\nIf you click \"Yes\", the Tizen SDK is uninstalled.",\r
- // DialogType.WARNING, false);\r
- // if (resultDialog == MessageBoxDlg.YES) {\r
- // showComposite(compositeUninstallingPage);\r
- // btnBack.setVisible(false);\r
- // btnNext.setVisible(false);\r
- // btnClose.setEnabled(false);\r
- // \r
- // if (Config.isSupportMultiSDK()) {\r
- // PackageManager.dispose();\r
- // initInstallManager(); \r
- // }\r
- //\r
- // List<Item> items = compositeUninstallablePage.getItems();\r
- // boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,\r
- // controller,\r
- // window);\r
- // if (!result) {\r
- // showComposite(compositeWelcomePage);\r
- // btnBack.setVisible(true);\r
- // btnNext.setVisible(true);\r
- // btnClose.setEnabled(true);\r
- // }\r
- // } else {\r
- // return;\r
- // }\r
- }\r
- } else if (sl_composite.topControl == compositeInstallableListPage) {\r
- // btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());\r
- btnNext.setEnabled(true);\r
- if (Config.isSupportMultiSDK()) {\r
- compositeLicensePage.loadPage(compositeInstallableListPage.getSelectedItems());\r
- showComposite(compositeLicensePage);\r
- btnBack.setVisible(true);\r
- } else {\r
- if (!controller.isNewInstallation()) {// Update case\r
- compositeUpdatableListPage.loadPage(controller);\r
- btnBack.setVisible(true);\r
- showComposite(compositeUpdatableListPage);\r
- if (controller.existRemovablePackage()) {\r
- btnNext.setText("Install");\r
- }\r
- btnBack.setVisible(true);\r
- } else {\r
- //License page button status setting.\r
- compositeLicensePage.loadPage(compositeInstallableListPage.getSelectedItems());\r
- showComposite(compositeLicensePage);\r
- btnNext.setText("I agree");\r
- btnNext.setEnabled(true);\r
- btnNext.setFocus();\r
- btnBack.setVisible(true);\r
- }\r
- }\r
- } else if (sl_composite.topControl == compositeLicensePage) {\r
- List<Item> items = compositeInstallableListPage.getItems();\r
- if (getSelectedPackageNames(items).size() <= 0) {\r
- return;\r
- }\r
- if (Config.isSupportMultiSDK()) {\r
- showComposite(compositeSetInstallDirectoryPage);\r
- compositeSetInstallDirectoryPage.loadPage(\r
- controller, compositeInstallableListPage.getCheckedPackageSize(false));\r
- // btnNext.setText("Install");\r
- } else {\r
- if (controller.existRemovablePackage()) { // update case\r
- btnBack.setVisible(false);\r
- btnNext.setVisible(false);\r
- showComposite(compositeInstallingPage);\r
- boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),\r
- controller,\r
- Registry.getInstalledPath(),\r
- window, true);\r
- if (!result) {\r
- showComposite(compositeInstallableListPage);\r
- btnBack.setVisible(true);\r
- btnNext.setVisible(true);\r
- btnClose.setEnabled(true);\r
- }\r
- } else {\r
- showComposite(compositeSetInstallDirectoryPage);\r
- compositeSetInstallDirectoryPage.loadPage(\r
- controller, compositeInstallableListPage.getCheckedPackageSize(false));\r
- btnNext.setText("Install");\r
- // btnNext.setVisible(false);\r
- // btnBack.setBounds(447, 10, 78, 29);\r
- }\r
- }\r
- } else if (sl_composite.topControl == compositeUpdatableListPage) {\r
- List<Item> items = compositeUpdatableListPage.getItems();\r
- if (getSelectedPackageNames(items).size() <= 0) {\r
- return;\r
- }\r
- \r
- btnBack.setVisible(false);\r
- btnNext.setVisible(false);\r
- showComposite(compositeInstallingPage);\r
- boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items), controller, Registry.getInstalledPath(), window, true);\r
- \r
- if (!result) {\r
- showComposite(compositeUpdatableListPage);\r
- btnBack.setVisible(true);\r
- btnNext.setVisible(true);\r
- btnClose.setEnabled(true);\r
- }\r
- } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {\r
- boolean installable = compositeSetInstallDirectoryPage.isInstallablePath();\r
- \r
- Config.USER_CONFIG_HOME_PATH = compositeSetInstallDirectoryPage.getSDKWorkSpacePath();\r
- Registry.sdkDataPath = controller.getSDKWorkSpacePath();\r
- Registry.targetPath = controller.getInstallPath();\r
- Registry.saveSDKInfo(Registry.targetPath);\r
- \r
- InstallManager.getInstance().initPackageList();\r
- \r
- if (!installable) {\r
- MessageBoxDlg.showDlg(\r
- Display.getCurrent().getShells()[0],\r
- "Error",\r
- "Not enough disk space for the installation. Select a different installation path.",\r
- DialogType.ERROR, false);\r
- return;\r
- }\r
- \r
- if (!compositeSetInstallDirectoryPage.isWorkSpaceDuplicate()) {\r
- int result = MessageBoxDlg.showDlg(\r
- Display.getCurrent().getShells()[0],\r
- "Warning",\r
- "Tizen SDK data directory is used already. Do you want to continue?",\r
- DialogType.WARNING, false);\r
- if (result == MessageBoxDlg.NO) {\r
- return;\r
- }\r
- }\r
- \r
- btnBack.setVisible(false);\r
- btnNext.setVisible(false);\r
- List<Item> items = compositeInstallableListPage.getItems();\r
- showComposite(compositeInstallingPage);\r
- boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),\r
- controller,\r
- compositeSetInstallDirectoryPage.getInstallPath(),\r
- window, false);\r
- if (!result) {\r
- showComposite(compositeInstallableListPage);\r
- btnBack.setVisible(true);\r
- btnNext.setVisible(true);\r
- btnClose.setEnabled(true);\r
- }\r
- } else if (sl_composite.topControl == compositeUninstallableListPage) {\r
- showComposite(compositeUninstallingPage);\r
- btnBack.setVisible(false);\r
- btnNext.setVisible(false);\r
- btnClose.setEnabled(false);\r
- List<Item> items = compositeUninstallableListPage.getItems();\r
- boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,\r
- controller,\r
- window);\r
- if (!result) {\r
- showComposite(compositeUninstallableListPage);\r
- btnBack.setVisible(true);\r
- btnNext.setVisible(true);\r
- btnClose.setEnabled(true);\r
- }\r
- }\r
- }\r
- });\r
- btnNext.setBounds(447, 10, 78, 29);\r
- }\r
- \r
- private void setButtonBack(Composite composite) {\r
- btnBack = new Button(composite, SWT.NONE); \r
- btnBack.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (sl_composite.topControl == compositeInstallableListPage\r
- || sl_composite.topControl == compositeUpdatableListPage) {\r
- compositeInstallableListPage.getItems().clear();\r
- showComposite(compositeWelcomePage);\r
- // if (controller.existRemovablePackage()) {\r
- // btnBack.setVisible(false);\r
- // showComposite(compositeWelcomePage);\r
- // } else {\r
- // showComposite(compositeLicensePage);\r
- // }\r
- btnNext.setVisible(false);\r
- btnBack.setVisible(false);\r
- } else if (sl_composite.topControl == compositeLicensePage) {\r
- btnNext.setEnabled(true);\r
- btnBack.setVisible(false);\r
- btnNext.setFocus();\r
- if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.INSTALL) {\r
- showComposite(compositeInstallableListPage);\r
- btnNext.setText("Next");\r
- btnBack.setVisible(true);\r
- } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UPDATE) {\r
- showComposite(compositeUpdatableListPage);\r
- btnNext.setText("Next");\r
- btnBack.setVisible(true);\r
- }\r
- } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {\r
- showComposite(compositeLicensePage);\r
- btnNext.setText("I agree");\r
- btnNext.setEnabled(true);\r
- } else if (sl_composite.topControl == compositeUninstallableListPage) {\r
- showComposite(compositeWelcomePage);\r
- btnNext.setVisible(false);\r
- btnBack.setVisible(false);\r
- }\r
- }\r
- });\r
- btnBack.setBounds(363, 10, 78, 29);\r
- btnBack.setText("Back");\r
- btnBack.setVisible(false);\r
- }\r
- \r
- private void initWelcomePage() {\r
- compositeWelcomePage.setViewController(controller);\r
- \r
- if (ErrorController.checkInstallationSuccess()) {\r
- // compositeWelcomePage.setTitle(WelcomePage.STRING_TITLE);\r
- // compositeWelcomePage.setSubTitleBounds(20, 190, 600, 40);\r
- // compositeWelcomePage.setSubTitle(WelcomePage.STRING_SUBTITLE1);\r
- // \r
- // compositeWelcomePage.setVisibleRadioButton(true);\r
- // btnNext.setEnabled(true);\r
- btnNext.setVisible(false);\r
- btnClose.setText("Cancel");\r
- \r
- btnClose.removeSelectionListener(closeBtnSelectionAdapter);\r
- btnClose.removeSelectionListener(cancelBtnSelectionAdapter);\r
- btnClose.addSelectionListener(cancelBtnSelectionAdapter);\r
- \r
- compositeWelcomePage.setButtonStatus();\r
- } else {\r
- compositeWelcomePage.setVisibleRadioButton(false);\r
- btnNext.setVisible(false);\r
- \r
- compositeWelcomePage.setTitle("Cannot start Tizen SDK Install Manager.");\r
- \r
- String errMsg = ErrorController.getErrorMessage();\r
- String repository = Config.getInstance().getConfigFile().getRepository();\r
- \r
- if (repository != null && !repository.isEmpty()) {\r
- errMsg = errMsg + "\n(" + repository + ")";\r
- }\r
- compositeWelcomePage.setSubTitleBounds(20, 190, 600, 100);\r
- compositeWelcomePage.setErrorSubTitle(errMsg);\r
- \r
- btnClose.setText("Close");\r
- \r
- btnClose.removeSelectionListener(closeBtnSelectionAdapter);\r
- btnClose.removeSelectionListener(cancelBtnSelectionAdapter);\r
- btnClose.addSelectionListener(closeBtnSelectionAdapter);\r
- }\r
- btnNext.setFocus();\r
- sl_composite.topControl = compositeWelcomePage;\r
- }\r
- \r
- /**\r
- * Refresh InstallManager. \r
- * Refresh packages and configuration information.\r
- */\r
- public void refresh() {\r
- final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();\r
- final Shell shell = progressbar.getParent();\r
- shell.getDisplay().asyncExec(new Runnable(){\r
- public void run() {\r
- progressbar.updateName("Initializing...");\r
- \r
- shell.getDisplay().syncExec(new Runnable() {\r
- public void run() {\r
- PackageManager.dispose();\r
- initInstallManager();\r
- initWelcomePage();\r
- }\r
- });\r
- \r
- //init end\r
- progressbar.finish();\r
- }\r
- });\r
- \r
- if (!shell.isDisposed()) {\r
- progressbar.open();\r
- }\r
- \r
- Log.log("Window refresh end");\r
- }\r
- \r
- /**\r
- * Checks if there's updatable meta package.\r
- * Then print "updatable" to stdout.\r
- */\r
- private static void checkMetaPackageUpdate() {\r
- if (PackageManager.getInstance().getUpdatableMetaPackages().size() != 0) {\r
- System.out.println("updatable");\r
- }\r
- }\r
- \r
- /**\r
- * There is no UI, just download packages.\r
- * @throws IMExitException\r
- */\r
- private static void onlyDownloadPackages() throws IMExitException {\r
- ViewController controller = new ViewController();\r
- controller.init();\r
- \r
- InstallManager installManager = InstallManager.getInstance();\r
- PackageManager packageManager = installManager.getPackageManager();\r
- \r
- // Get all meta packages list by boundary.(eg. public, partner, all....) \r
- PackageSet filteredMeta = filterPackageSet();\r
- PackageSet downloadablePkgs = packageManager.getDependsPackagesFromRepository(filteredMeta);\r
- \r
- // Download all meta packages. \r
- boolean filteredPackages = false;\r
- try {\r
- filteredPackages = installManager.downloadPackages(\r
- downloadablePkgs, null);\r
- } catch (IMNetworkException e) {\r
- Log.ExceptionLog(e);\r
- return;\r
- }\r
- \r
- if (filteredPackages) {\r
- Log.log("Success to download packages from repository");\r
- } else {\r
- Log.err("Fail to download packages from repository");\r
- return;\r
- }\r
- }\r
- \r
- private static PackageSet filterPackageSet() {\r
- PackageManager pm = PackageManager.getInstance();\r
- \r
- PackageSet downloadPackageList = pm.getLeafMetaPackages();\r
- \r
- String boundary = Options.boundary;\r
- if (boundary.equalsIgnoreCase("public")) {\r
- PackageSet partnerMetaPackages = pm.getPartnerMetaPackages();\r
- \r
- if (!partnerMetaPackages.isEmpty()) {\r
- downloadPackageList.removeAll(partnerMetaPackages);\r
- }\r
- } else if (boundary.equalsIgnoreCase("partner")) {\r
- PackageSet publicMetaPackages = pm.getPublicMetaPackages();\r
- \r
- if (!publicMetaPackages.isEmpty()) {\r
- downloadPackageList.removeAll(publicMetaPackages);\r
- }\r
- }\r
- \r
- return downloadPackageList;\r
- }\r
- \r
- private static void showInstallManagerVersion() {\r
- System.out.println("InstallManager Version : " + \r
- Config.getInstance().getInstallManagerVersion().toString());\r
- }\r
- \r
- /**\r
- * Logging all system information.\r
- */\r
- private static void loggingProperty() {\r
- Log.log("=========== System properties ===========");\r
- Properties sysprops = System.getProperties();\r
- for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements();) {\r
- String key = (String) e.nextElement();\r
- String value = sysprops.getProperty(key);\r
- Log.log(key + " = " + value);\r
- }\r
- \r
- Log.log("=========== Environment variables ===========");\r
- \r
- Map<String, String> env = System.getenv();\r
- Set<String> set = env.keySet();\r
- Iterator<String> iter = set.iterator();\r
- \r
- while (iter.hasNext()) {\r
- String key = (String) iter.next();\r
- Set<Entry<String, String>> value = env.entrySet();\r
- Log.log(key + " = " + value);\r
- }\r
- Log.log("=============================================");\r
- }\r
- \r
- /**\r
- * Launch the application.\r
- * \r
- * @param args\r
- */\r
- public static void main(String args[]) {\r
- //performance measurement\r
- Performance.setIMStartTime();\r
- \r
- InstallManager.deleteTempFile();\r
- \r
- Log.open();\r
- Log.LogTitle("Installmanager start");\r
- Log.log(Platform.getPlatformInfo());\r
- Log.log(PathUtil.getCurrentDir());\r
- \r
- if (Options.propertyLogging) {\r
- loggingProperty();\r
- }\r
- \r
- try {\r
- Options.loadCmdArgs(args);\r
- } catch (IMFatalException e) {\r
- Log.err("Check your options. => " + Arrays.toString(args));\r
- System.out.println("Check your options. => " + Arrays.toString(args));\r
- return;\r
- }\r
- \r
- try { \r
- if (Options.onlyDownload) {\r
- onlyDownloadPackages();\r
- System.exit(0);\r
- } else if (Options.doInstallNoUI) {\r
- if (InstallManagerNoUI.cliInstall(Options.packages)) {\r
- Log.log("Success to command line install.");\r
- System.out.println("Success to console install.");\r
- } else {\r
- Log.log("Fail to command line install.");\r
- System.out.println("Fail to console install.");\r
- }\r
- \r
- Performance.setIMEndTime();\r
- if (Options.doTest) {\r
- Performance.printTestResultXmlFormat();\r
- // Performance.printTestResultXmlFormat2();\r
- }\r
- \r
- System.exit(0);\r
- } else if (Options.doRemoveNoUI) {\r
- if (InstallManagerNoUI.cliUninstall(Options.packages)) {\r
- Log.log("Success to command line remove.");\r
- System.out.println("Success to remove.");\r
- } else {\r
- Log.log("Fail to command line remove.");\r
- System.out.println("Fail to remove.");\r
- }\r
- \r
- Performance.setIMEndTime();\r
- if (Options.doTest) {\r
- Performance.printTestResultXmlFormat();\r
- // Performance.printTestResultXmlFormat2();\r
- }\r
- \r
- System.exit(0);\r
- } else if (Options.showVersion) {\r
- showInstallManagerVersion();\r
- System.exit(0);\r
- } else if (Options.doShowHelp) {\r
- InstallManagerNoUI.cliShowHelp();\r
- System.exit(0);\r
- }\r
- \r
- if (Platform.isMacOS()) {\r
- System.setProperty("apple.laf.useScreenMenuBar", "true");\r
- System.setProperty(\r
- "com.apple.mrj.application.apple.menu.about.name",\r
- "Emulator Manager");\r
- Display display = Display.getDefault();\r
- display.syncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- new CocoaUtil().removeTopMenuItems();\r
- }\r
- });\r
- }\r
- \r
- window = new InstallManagerWindow();\r
- window.setBlockOnOpen(true);\r
- \r
- window.init();\r
- \r
- Log.log("after init");\r
- if (Options.checkPackageUpdate) {\r
- checkMetaPackageUpdate();\r
- } else if (Options.printDepGraph) {\r
- InstallManager.getInstance().getPackageManager().printDepGraph();\r
- } else if (Options.doShowDistListNoUI) {\r
- InstallManagerNoUI.cliShowRepoInformation();\r
- } else if (Options.doShowPackageListNoUI) {\r
- InstallManagerNoUI.cliShowPackageList();\r
- } else if (Options.doShowSDKInstallStatus) {\r
- InstallManagerNoUI.cliShowInstallInformation();\r
- } else {\r
- window.open();\r
- if (Display.getCurrent() != null\r
- && !Display.getCurrent().isDisposed()) {\r
- Display.getCurrent().dispose();\r
- }\r
- }\r
- } catch (IMExitException e) {\r
- // do not remove sdk temp dir if exit for self update\r
- if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {\r
- Options.doRemoveTempTizenSDK = false;\r
- }\r
- \r
- Log.log("Gracefully exit");\r
- } catch (Throwable e) {\r
- Log.err("Unexpected error occurred");\r
- Log.ExceptionLog(e);\r
- \r
- if (Options.doInstallNoUI || Options.doRemoveNoUI) {\r
- PathUtil.remove(Registry.REGISTRY_FILE_PATH);\r
- PathUtil.remove(Registry.MULTI_SDK_FILE_PATH);\r
- System.out.println("Fatal error occurred.");\r
- System.exit(0);\r
- }\r
- \r
- // show error message\r
- if (window != null) {\r
- window.open();\r
- \r
- if (Display.getCurrent() != null\r
- && !Display.getCurrent().isDisposed()) {\r
- Display.getCurrent().dispose();\r
- }\r
- }\r
- \r
- ErrorController.setExitCode(Config.EXITCODE_UNKNOWN_ERROR);\r
- } finally {\r
- if (Platform.isWindows()) {\r
- ProgramController.createProgramController().removeSDKTempDir();\r
- }\r
- \r
- //performance measurement\r
- Performance.setIMEndTime();\r
- Performance.printToLogFile();\r
- \r
- if (Options.doTest) {\r
- Performance.printTestResultXmlFormat();\r
- // Performance.printTestResultXmlFormat2();\r
- }\r
- \r
- Log.LogTitle("Installmanager finish");\r
- Log.close();\r
- \r
- if (Platform.isMacOS()) {\r
- System.exit(ErrorController.getExitCode());\r
- } else {\r
- if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {\r
- String binary = PathUtil.get(Registry.getInstalledPath(), Config.INSTALL_MANAGER_DIRECTORY, Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER);\r
- try {\r
- Runtime.getRuntime().exec(binary);\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- } else if (ErrorController.getExitCode() != Config.EXITCODE_NORMAL) {\r
- System.exit(ErrorController.getExitCode());\r
- }\r
- }\r
- }\r
- }\r
- \r
- @Override\r
- protected void configureShell(Shell newShell) {\r
- newShell.setBackground(getBackgroundColor());\r
- newShell.setMinimumSize(getInitialSize());\r
- newShell.setSize(getInitialSize());\r
- newShell.setImage(getWindowIconImage());\r
- super.configureShell(newShell);\r
- \r
- newShell.setText("Tizen SDK Install Manager");\r
- }\r
- \r
- @Override\r
- /**\r
- * Install manager window is close.\r
- */\r
- public boolean close() {\r
- return false;\r
- }\r
- \r
- /**\r
- * Return the initial size of the window.\r
- */\r
- @Override\r
- protected Point getInitialSize() {\r
- return POINT_MAIN_WINDOW;\r
- }\r
- \r
- /**\r
- * Show the composite depending on parameter.\r
- * @param composite\r
- */\r
- public void showComposite(Composite composite) {\r
- StackLayout layout;\r
- if (composite.getParent().getLayout() instanceof StackLayout) {\r
- layout = (StackLayout) composite.getParent().getLayout();\r
- layout.topControl = composite;\r
- }\r
- composite.getParent().layout();\r
- }\r
- \r
- // private void registLicensePageListener() {\r
- // compositeLicensePage.getAcceptButton()\r
- // .addSelectionListener(new SelectionAdapter() {\r
- //\r
- // @Override\r
- // public void widgetSelected(SelectionEvent e) {\r
- // btnNext.setEnabled(compositeLicensePage.getAcceptButton()\r
- // .getSelection());\r
- // }\r
- // });\r
- // }\r
- \r
- private void registCompletePageListener() {\r
- compositeCompletePage.addPaintListener(new PaintListener() {\r
- \r
- @Override\r
- public void paintControl(PaintEvent arg0) {\r
- btnClose.setText("Close");\r
- }\r
- });\r
- }\r
- \r
- public void setNameOfCancelButton(String name) {\r
- btnClose.setText("Close");\r
- }\r
- \r
- /**\r
- * Get selected package names on installing\r
- * @param items\r
- * @return list of selected package names.\r
- */\r
- public List<String> getSelectedPackageNames(List<Item> items) {\r
- List<String> list = new ArrayList<String>();\r
- for (int i = 0; i < items.size(); i++) {\r
- items.get(i).getTerminalPackages(list, true);\r
- }\r
- \r
- return list;\r
- }\r
- \r
- /**\r
- * Installed packages do not have package version, installmanager will show warning dialog.\r
- * @return\r
- */\r
- private boolean checkVaildPkgVersion() {\r
- PackageSet installedPkgs = controller.getInstalledPackages();\r
- if (!installedPkgs.isEmpty()) {\r
- for (Package pkg : installedPkgs) {\r
- String vs = pkg.getVersion().toString();\r
- if (vs != "" && vs.equals("0.0.0")) {\r
- Log.err("Package version not found. ==> " + pkg.getPackageName());\r
- int confirm = MessageBoxDlg.showDlg(getShell(), \r
- "WARNING", \r
- "'" + pkg.getPackageName() + "'" + " package version is not found.\n" +\r
- "If you keep installing Tizen SDK, some unexpected may occur.\n" +\r
- "Do you want to continue?", \r
- DialogType.WARNING, false);\r
- if (confirm == MessageBoxDlg.YES) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- }\r
- }\r
- \r
- return true;\r
- }\r
- \r
- /**\r
- * Get install manager window object.\r
- * @return install manager window object.\r
- */\r
- public static InstallManagerWindow getInstallManagerWindow() {\r
- return window;\r
- }\r
- \r
- /**\r
- * Get complete page composite object\r
- * @return complete page composite object\r
- */\r
- public CompletePage getCompletePage() {\r
- return compositeCompletePage;\r
- }\r
- \r
- public LicensePage getLicensePage() {\r
- return compositeLicensePage;\r
- }\r
- \r
- public InstallableListPage getComponentSelectionPage() {\r
- return compositeInstallableListPage;\r
- }\r
- \r
- public WelcomePage getWelcomePage() {\r
- return compositeWelcomePage;\r
- }\r
- \r
- /**\r
- * Get setInstallDirectoryPage composite object\r
- * @return complete page composite object\r
- */\r
- public SetInstallDirectoryPage getSetInstallDirectoryPage() {\r
- return compositeSetInstallDirectoryPage;\r
- }\r
- \r
- public Button getNextButton() {\r
- return btnNext;\r
- }\r
- \r
- /**\r
- * If parameter is true, 'Next' button will be enabled. but false, 'Next' button will be disabled.\r
- * @param enabled\r
- */\r
- public static void setNextBtnEnabled(boolean enabled) {\r
- btnNext.setEnabled(enabled);\r
- }\r
- \r
- /**\r
- * If parameter is true, 'Back' button will be enabled. but false, 'Back' button will be disabled.\r
- * @param enabled\r
- */\r
- public static void setBackBtnEnabled(boolean enabled) {\r
- btnBack.setEnabled(enabled);\r
- }\r
- \r
- /**\r
- * If parameter is true, 'Cancel' button will be enabled. but false, 'Cancel' button will be disabled.\r
- * @param enabled\r
- */\r
- public void setCancelBtnEnabled(boolean enabled) {\r
- btnClose.setEnabled(enabled);\r
- }\r
- \r
- public ViewController getViewController() {\r
- return controller;\r
- }\r
- }\r
- \r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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;
+
+ import java.io.IOException;
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Enumeration;
+ import java.util.Iterator;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Map.Entry;
+ import java.util.Properties;
+ import java.util.Set;
+
+ import org.eclipse.jface.window.ApplicationWindow;
+ import org.eclipse.swt.SWT;
+ import org.eclipse.swt.custom.StackLayout;
+ import org.eclipse.swt.events.PaintEvent;
+ import org.eclipse.swt.events.PaintListener;
+ import org.eclipse.swt.events.SelectionAdapter;
+ import org.eclipse.swt.events.SelectionEvent;
+ import org.eclipse.swt.graphics.Color;
+ import org.eclipse.swt.graphics.Image;
+ import org.eclipse.swt.graphics.Point;
+ import org.eclipse.swt.graphics.RGB;
+ import org.eclipse.swt.layout.RowData;
+ import org.eclipse.swt.layout.RowLayout;
+ import org.eclipse.swt.widgets.Button;
+ import org.eclipse.swt.widgets.Composite;
+ import org.eclipse.swt.widgets.Control;
+ import org.eclipse.swt.widgets.Display;
++import org.eclipse.swt.widgets.Event;
+ import org.eclipse.swt.widgets.Label;
++import org.eclipse.swt.widgets.Layout;
++import org.eclipse.swt.widgets.Listener;
+ import org.eclipse.swt.widgets.Shell;
+ import org.tizen.installmanager.cli.InstallManagerNoUI;
+ import org.tizen.installmanager.core.Config;
+ import org.tizen.installmanager.core.IMExitException;
+ import org.tizen.installmanager.core.IMFatalException;
+ import org.tizen.installmanager.core.InstallManager;
+ import org.tizen.installmanager.core.InstallManagerConstants;
+ import org.tizen.installmanager.core.Options;
+ import org.tizen.installmanager.core.Performance;
+ import org.tizen.installmanager.lib.ErrorController;
+ import org.tizen.installmanager.lib.IMError;
+ import org.tizen.installmanager.lib.Log;
+ import org.tizen.installmanager.lib.Patch;
+ import org.tizen.installmanager.lib.Platform;
+ import org.tizen.installmanager.lib.ProgramController;
+ import org.tizen.installmanager.lib.Registry;
+ import org.tizen.installmanager.lib.exception.IMNetworkException;
+ import org.tizen.installmanager.lib.mac.CocoaUtil;
+ import org.tizen.installmanager.pkg.lib.PackageManager;
+ import org.tizen.installmanager.pkg.model.ConfigFile;
+ import org.tizen.installmanager.pkg.model.PackageSet;
+ import org.tizen.installmanager.ui.dialog.AddExtraRepositoryDialog;
+ import org.tizen.installmanager.ui.dialog.IndeterminateProgressDialog;
+ import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
+ import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
+ import org.tizen.installmanager.ui.dialog.ProxySettingsDialog;
+ import org.tizen.installmanager.ui.model.Item;
+ import org.tizen.installmanager.ui.page.CompletePage;
++import org.tizen.installmanager.ui.page.InstallPage;
+ import org.tizen.installmanager.ui.page.InstallableListPage;
+ import org.tizen.installmanager.ui.page.InstallingPage;
+ import org.tizen.installmanager.ui.page.LicensePage;
+ import org.tizen.installmanager.ui.page.SetInstallDirectoryPage;
+ import org.tizen.installmanager.ui.page.UninstallableListPage;
+ import org.tizen.installmanager.ui.page.UninstallingPage;
+ import org.tizen.installmanager.ui.page.UpdatableListPage;
+ import org.tizen.installmanager.ui.page.ViewController;
+ import org.tizen.installmanager.ui.page.WelcomePage;
+ import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
-import org.tizen.installmanager.ui.page.WelcomePage.RADIO_ACTION;
++import org.tizen.installmanager.ui.page.WelcomePage.INSTALLMANAGER_ACTION;
+ import org.tizen.installmanager.util.PathUtil;
+ import org.tizen.installmanager.pkg.model.Package;
+
+
+ /**
+ * This class is main class for install manager.
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>
+ */
+ public class InstallManagerWindow extends ApplicationWindow {
+ private static final RGB RGB_BACKGROUND = new RGB(242, 242, 242);
+
+ private static final Point POINT_MAIN_WINDOW = new Point(628, 478);
+ private static Image IMAGE_WINDOW_ICON;
+ private static Color COLOR_BACKGROUND;
+
+ private static InstallManagerWindow window;
+
- private StackLayout sl_composite = new StackLayout();
++// private StackLayout sl_composite = new StackLayout();
++ public StackLayout sl_composite = new StackLayout();
+ private static Button btnClose;
+ private static Button btnBack;
+ private static Button btnNext;
- private Button btnSettings;
- private static Button addExtraButton;
+
- private AddExtraRepositoryDialog extraDialog = null;
-
- private Composite pageComposite;
++ private Composite pageComposite; // Page area
+ private WelcomePage compositeWelcomePage;
+ private LicensePage compositeLicensePage;
- private InstallableListPage compositeInstallablePage;
- private UninstallableListPage compositeUninstallablePage;
++ private InstallableListPage compositeInstallableListPage;
++ private UninstallableListPage compositeUninstallableListPage;
+ private InstallingPage compositeInstallingPage;
+ private UninstallingPage compositeUninstallingPage;
+ private CompletePage compositeCompletePage;
+ private SetInstallDirectoryPage compositeSetInstallDirectoryPage;
+ public UpdatableListPage compositeUpdatableListPage;
+
+ protected static ViewController controller;
+ private SelectionAdapter cancelBtnSelectionAdapter = null;
+ private SelectionAdapter closeBtnSelectionAdapter = null;
+
+ /**
+ * Create the application window.
+ */
+ public InstallManagerWindow() {
+ super(null);
+ setShellStyle(SWT.SHELL_TRIM);
+ setShellStyle(SWT.BORDER | SWT.TITLE);
+ }
+
+ /**
+ * Get installmanager window background color.
+ * @return background color
+ */
+ public static Color getBackgroundColor() {
+ if (COLOR_BACKGROUND == null) {
+ COLOR_BACKGROUND = new Color(null, RGB_BACKGROUND);
+ }
+ return COLOR_BACKGROUND;
+ }
+
+ private static Image getWindowIconImage() {
+ if (IMAGE_WINDOW_ICON == null) {
+ IMAGE_WINDOW_ICON = PathUtil.getImageFromResource("/res/icons/SDK_icon.png");
+ }
+ return IMAGE_WINDOW_ICON;
+ }
+
+ private void init() throws IMExitException{
+ Log.log("Window init start");
+
+ //make waiting dialog.
+ final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();
+
+ final Shell shell = progressbar.getParent();
+ shell.getDisplay().asyncExec(new Runnable(){
+ public void run() {
+ //initialize installmanager
+ progressbar.updateName("Connecting to package server.\nIt may take a minute...");
+
+ shell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ initInstallManager();
+ }
+
+ });
+
+ //init end
+ progressbar.finish();
+ }
+ });
+
+ if (!shell.isDisposed()) {
+ progressbar.open();
+ }
+
+ Log.log("Window init end");
+ }
+
+ private void updateInstallManager(Shell shell) {
+ if (controller.canInstallManagerUpdate()) {
+ String msg = "There is a new installer on the server. \nNew install-manager will be started. \nIt may take a minute...";
+ MessageBoxDlg.showDlg(shell, "InstallManager", msg, DialogType.NOTIFY, false);
+
+ controller.updateInstallManager();
+ }
+ }
+
+ /**
+ * init IM's configuation and packages information.
+ * @return
+ */
+ public boolean initInstallManager() {
+ ErrorController.setInstallationSuccess(true);
+
+ controller = new ViewController();
+
+ if (controller.init()) {
+ if (Config.isSupportMultiSDK()) {
+ Log.log("Multi SDK installation.");
+ } else {
+ Log.log("Single SDK installation.");
+ }
+ return true;
+ } else {
+ Log.err("InstallManager init fail.");
+ ErrorController.setInstallationSuccess(false);
+
+ return false;
+ }
+ }
+
+ /**
+ * Create contents of the application window.
+ *
+ * @param parent
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+
++ parent.setSize(630, 490);
+ IMError.setComposite(parent);
+ Composite container = new Composite(parent, SWT.NONE);
- container.setBackground(getBackgroundColor());
++
++ // Set layout attributes.
+ RowLayout rl_container = new RowLayout(SWT.VERTICAL);
+ rl_container.spacing = 0;
+ rl_container.marginTop = 0;
+ rl_container.marginRight = 0;
+ rl_container.marginLeft = 0;
+ rl_container.marginBottom = 0;
+ container.setLayout(rl_container);
+
++ // Set page composite size. (image, label, etc.)
+ pageComposite = new Composite(container, SWT.NONE);
- pageComposite.setLayoutData(new RowData(619, 395));
++ pageComposite.setLayoutData(new RowData(628, 405));
+ pageComposite.setLayout(sl_composite);
- pageComposite.setBackground(InstallManagerWindow.getBackgroundColor());
++
++ Composite composite_buttonArea = new Composite(container, SWT.NONE);
++ composite_buttonArea.setLayoutData(new RowData(628, 52));
++ composite_buttonArea.setBackground(getBackgroundColor());
+
- Composite composite_1 = new Composite(container, SWT.NONE);
- composite_1.setLayoutData(new RowData(619, 38));
- composite_1.setBackground(InstallManagerWindow.getBackgroundColor());
++ setButtonClose(composite_buttonArea);
++ setButtonNext(composite_buttonArea);
++ setButtonBack(composite_buttonArea);
+
- Label label = new Label(composite_1, SWT.SEPARATOR | SWT.HORIZONTAL);
- label.setBounds(0, 0, 620, 2);
++ compositeWelcomePage = new WelcomePage(pageComposite, SWT.NONE);
++ compositeLicensePage = new LicensePage(pageComposite, SWT.NONE);
++ compositeCompletePage = new CompletePage(pageComposite, SWT.NONE);
++ compositeInstallingPage = new InstallingPage(pageComposite, SWT.NONE);
++ compositeInstallableListPage = new InstallableListPage(pageComposite, SWT.NONE);
++ compositeUninstallingPage = new UninstallingPage(pageComposite, SWT.NONE);
++ compositeUninstallableListPage = new UninstallableListPage(pageComposite, SWT.NONE);
++ compositeSetInstallDirectoryPage = new SetInstallDirectoryPage(pageComposite, SWT.NONE);
++ compositeUpdatableListPage = new UpdatableListPage(pageComposite, SWT.NONE);
++
++// registLicensePageListener();
++// registCompletePageListener();
++
++ initWelcomePage();
++
++ return container;
++ }
+
- btnClose = new Button(composite_1, SWT.NONE);
++ private void setButtonClose(Composite composite) {
++ btnClose = new Button(composite, SWT.NONE);
+ btnClose.setText("Cancel");
+ cancelBtnSelectionAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int result = MessageBoxDlg.NO;
+ if (sl_composite.topControl == compositeInstallingPage) {
+ InstallProgressMonitor mon = compositeInstallingPage.getInstallProgressMonitor();
+ mon.setCancelRequested(true);
+ result = MessageBoxDlg.showDlg(
+ e.display.getActiveShell(),
+ "Tizen SDK Install Manager",
+ "Are you sure you want to quit Install Manager?\n\nIf you click \"Yes\", the installation is stopped.",
+ DialogType.WARNING, false);
+ if (result == MessageBoxDlg.YES) {
+ mon.setCanceled(true);
+ } else {
+ mon.setCancelRequested(false);
+ }
+ return;
+ } else if (sl_composite.topControl == compositeUninstallingPage) {
+ result = MessageBoxDlg.showDlg(
+ e.display.getActiveShell(),
+ "Tizen SDK Install Manager",
+ "Are you sure to quit Install Manager?\n\nIf you click \"Yes\", the uninstallation is stopped.",
+ DialogType.WARNING, false);
+ } else if (sl_composite.topControl == compositeCompletePage) {
+ controller.showChangeLog();
+
+ if (!Options.doResumeDownloading) {
+ controller.cleanUpTargetDirectory();
+ }
+
+ result = MessageBoxDlg.YES;
+ } else {
+ result = MessageBoxDlg.showDlg(e.display.getActiveShell(),
+ "Tizen SDK Install Manager",
+ "Are you sure to quit Install Manager?",
+ DialogType.WARNING, false);
+ }
+
+ if (result == MessageBoxDlg.YES) {
+ e.display.close();
+ }
+ }
+ };
+
+ closeBtnSelectionAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ arg0.display.close();
+ }
+ };
+
+ btnClose.addSelectionListener(cancelBtnSelectionAdapter);
+ btnClose.setBounds(531, 10, 78, 29);
-
- btnNext = new Button(composite_1, SWT.NONE);
++ }
++
++ private void setButtonNext(Composite composite) {
++ btnNext = new Button(composite, SWT.NONE);
+ btnNext.setText("Next");
+ btnNext.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (sl_composite.topControl == compositeWelcomePage) {
+ updateInstallManager(e.display.getActiveShell());
- addExtraButton.setVisible(false);
- btnSettings.setVisible(false);
- if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.INSTALL) {
++ btnNext.setVisible(false);
++ if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.INSTALL) {
+ if (!checkVaildPkgVersion()) {
- btnSettings.setVisible(true);
+ return;
+ }
- btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
- if (Config.isSupportMultiSDK()) {
- showComposite(compositeLicensePage);
++
++ if (!controller.isNewInstallation()) {// Update case
++ Config.status = Config.Status.UPDATE;
++ compositeUpdatableListPage.loadPage(controller);
++ btnBack.setVisible(true);
++ btnNext.setVisible(true);
++ showComposite(compositeUpdatableListPage);
++ if (controller.existRemovablePackage()) {
++ btnNext.setText("Install");
++ }
+ btnBack.setVisible(true);
+ } else {
- if (!controller.isNewInstallation()) {// Update case
- compositeUpdatableListPage.loadPage(controller);
- btnBack.setVisible(true);
- addExtraButton.setVisible(true);
-
- btnSettings.setVisible(false);
- showComposite(compositeUpdatableListPage);
++ boolean hasItem = compositeInstallableListPage.loadPage(controller);
++ if (hasItem) {
++ Config.status = Config.Status.INSTALL;
++ showComposite(compositeInstallableListPage);
++ btnNext.setVisible(true);
++ btnNext.setEnabled(hasItem);
++ btnBack.setVisible(hasItem);
+ if (controller.existRemovablePackage()) {
+ btnNext.setText("Install");
+ }
- btnBack.setVisible(true);
+ } else {
- showComposite(compositeLicensePage);
- btnBack.setVisible(true);
++ Log.err("Installable packages do not exist. This is error.");
++ //TODO
+ }
+ }
- } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UPDATE) {
- btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
++ } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UPDATE) {
++// btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
++ btnNext.setEnabled(true);
+ PackageManager.dispose();
+ initInstallManager();
+ compositeUpdatableListPage.loadPage(controller);
+ btnBack.setVisible(true);
- addExtraButton.setVisible(true);
- btnSettings.setVisible(false);
+ showComposite(compositeUpdatableListPage);
+ if (controller.existRemovablePackage()) {
+ btnNext.setText("Install");
+ }
+ btnBack.setVisible(true);
- } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UNINSTALL) {
- int resultDialog = MessageBoxDlg.NO;
- resultDialog = MessageBoxDlg.showDlg(
- e.display.getActiveShell(),
- "Tizen SDK Install Manager",
- "Are you sure you want to remove the Tizen SDK?\n\nIf you click \"Yes\", the Tizen SDK is uninstalled.",
- DialogType.WARNING, false);
- if (resultDialog == MessageBoxDlg.YES) {
- showComposite(compositeUninstallingPage);
- btnBack.setVisible(false);
- btnNext.setVisible(false);
- btnClose.setEnabled(false);
- addExtraButton.setVisible(false);
-
- if (Config.isSupportMultiSDK()) {
- PackageManager.dispose();
- initInstallManager();
- }
-
- List<Item> items = compositeUninstallablePage.getItems();
- boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,
- controller,
- window);
- if (!result) {
- showComposite(compositeWelcomePage);
- btnBack.setVisible(true);
- btnNext.setVisible(true);
- btnClose.setEnabled(true);
++ } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UNINSTALL) {
++ showComposite(compositeUninstallableListPage);
++ btnNext.setVisible(true);
++ btnBack.setVisible(true);
++ btnNext.setText("Uninstall");
++ compositeUninstallableListPage.loadPage(controller);
++// int resultDialog = MessageBoxDlg.NO;
++// resultDialog = MessageBoxDlg.showDlg(
++// e.display.getActiveShell(),
++// "Tizen SDK Install Manager",
++// "Are you sure you want to remove the Tizen SDK?\n\nIf you click \"Yes\", the Tizen SDK is uninstalled.",
++// DialogType.WARNING, false);
++// if (resultDialog == MessageBoxDlg.YES) {
++// showComposite(compositeUninstallingPage);
++// btnBack.setVisible(false);
++// btnNext.setVisible(false);
++// btnClose.setEnabled(false);
++//
++// if (Config.isSupportMultiSDK()) {
++// PackageManager.dispose();
++// initInstallManager();
++// }
++//
++// List<Item> items = compositeUninstallablePage.getItems();
++// boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,
++// controller,
++// window);
++// if (!result) {
++// showComposite(compositeWelcomePage);
++// btnBack.setVisible(true);
++// btnNext.setVisible(true);
++// btnClose.setEnabled(true);
++// }
++// } else {
++// return;
++// }
++ }
++ } else if (sl_composite.topControl == compositeInstallableListPage) {
++// btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
++ btnNext.setEnabled(true);
++ if (Config.isSupportMultiSDK()) {
++ compositeLicensePage.loadPage(compositeInstallableListPage.getSelectedItems());
++ showComposite(compositeLicensePage);
++ btnBack.setVisible(true);
++ } else {
++ if (!controller.isNewInstallation()) {// Update case
++ compositeUpdatableListPage.loadPage(controller);
++ btnBack.setVisible(true);
++ showComposite(compositeUpdatableListPage);
++ if (controller.existRemovablePackage()) {
++ btnNext.setText("Install");
+ }
++ btnBack.setVisible(true);
+ } else {
- btnSettings.setVisible(true);
- return;
++ //License page button status setting.
++ compositeLicensePage.loadPage(compositeInstallableListPage.getSelectedItems());
++ showComposite(compositeLicensePage);
++ btnNext.setText("I agree");
++ btnNext.setEnabled(true);
++ btnNext.setFocus();
++ btnBack.setVisible(true);
+ }
+ }
+ } else if (sl_composite.topControl == compositeLicensePage) {
- boolean hasItem = compositeInstallablePage.loadPage(controller);
- if (hasItem) {
- showComposite(compositeInstallablePage);
- btnNext.setEnabled(hasItem);
- btnBack.setVisible(hasItem);
- addExtraButton.setVisible(true);
- if (controller.existRemovablePackage()) {
- btnNext.setText("Install");
- }
- } else {
- Log.err("Installable packages do not exist. This is error.");
- //TODO
- }
- } else if (sl_composite.topControl == compositeInstallablePage) {
- List<Item> items = compositeInstallablePage.getItems();
++ List<Item> items = compositeInstallableListPage.getItems();
+ if (getSelectedPackageNames(items).size() <= 0) {
+ return;
+ }
+ if (Config.isSupportMultiSDK()) {
+ showComposite(compositeSetInstallDirectoryPage);
+ compositeSetInstallDirectoryPage.loadPage(
- controller, compositeInstallablePage.getCheckedPackageSize(false));
- btnNext.setText("Install");
- addExtraButton.setVisible(false);
++ controller, compositeInstallableListPage.getCheckedPackageSize(false));
++// btnNext.setText("Install");
+ } else {
- if (controller.existRemovablePackage()) {
++ if (controller.existRemovablePackage()) { // update case
+ btnBack.setVisible(false);
+ btnNext.setVisible(false);
+ showComposite(compositeInstallingPage);
- addExtraButton.setVisible(false);
+ boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),
+ controller,
+ Registry.getInstalledPath(),
+ window, true);
+ if (!result) {
- showComposite(compositeInstallablePage);
++ showComposite(compositeInstallableListPage);
+ btnBack.setVisible(true);
+ btnNext.setVisible(true);
+ btnClose.setEnabled(true);
- addExtraButton.setVisible(true);
+ }
+ } else {
+ showComposite(compositeSetInstallDirectoryPage);
+ compositeSetInstallDirectoryPage.loadPage(
- controller, compositeInstallablePage.getCheckedPackageSize(false));
++ controller, compositeInstallableListPage.getCheckedPackageSize(false));
+ btnNext.setText("Install");
- addExtraButton.setVisible(false);
++// btnNext.setVisible(false);
++// btnBack.setBounds(447, 10, 78, 29);
+ }
+ }
+ } else if (sl_composite.topControl == compositeUpdatableListPage) {
+ List<Item> items = compositeUpdatableListPage.getItems();
+ if (getSelectedPackageNames(items).size() <= 0) {
+ return;
+ }
+
+ btnBack.setVisible(false);
+ btnNext.setVisible(false);
- addExtraButton.setVisible(false);
+ showComposite(compositeInstallingPage);
+ boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items), controller, Registry.getInstalledPath(), window, true);
+
+ if (!result) {
+ showComposite(compositeUpdatableListPage);
+ btnBack.setVisible(true);
+ btnNext.setVisible(true);
+ btnClose.setEnabled(true);
- addExtraButton.setVisible(true);
+ }
+ } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {
+ boolean installable = compositeSetInstallDirectoryPage.isInstallablePath();
+
+ Config.USER_CONFIG_HOME_PATH = compositeSetInstallDirectoryPage.getSDKWorkSpacePath();
+ Registry.sdkDataPath = controller.getSDKWorkSpacePath();
+ Registry.targetPath = controller.getInstallPath();
+ Registry.saveSDKInfo(Registry.targetPath);
+
+ InstallManager.getInstance().initPackageList();
+
+ if (!installable) {
+ MessageBoxDlg.showDlg(
+ Display.getCurrent().getShells()[0],
+ "Error",
+ "Not enough disk space for the installation. Select a different installation path.",
+ DialogType.ERROR, false);
+ return;
+ }
+
- if (Config.isSupportMultiSDK()) {
- if (!compositeSetInstallDirectoryPage.isWorkSpaceDuplicate()) {
- int result = MessageBoxDlg.showDlg(
- Display.getCurrent().getShells()[0],
- "Warning",
- "Tizen SDK data directory is used already. Do you want to continue?",
- DialogType.WARNING, false);
- if (result == MessageBoxDlg.NO) {
- return;
- }
++ if (!compositeSetInstallDirectoryPage.isWorkSpaceDuplicate()) {
++ int result = MessageBoxDlg.showDlg(
++ Display.getCurrent().getShells()[0],
++ "Warning",
++ "Tizen SDK data directory is used already. Do you want to continue?",
++ DialogType.WARNING, false);
++ if (result == MessageBoxDlg.NO) {
++ return;
+ }
+ }
++
+ btnBack.setVisible(false);
+ btnNext.setVisible(false);
- addExtraButton.setVisible(false);
- List<Item> items = compositeInstallablePage.getItems();
++ List<Item> items = compositeInstallableListPage.getItems();
+ showComposite(compositeInstallingPage);
+ boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),
+ controller,
+ compositeSetInstallDirectoryPage.getInstallPath(),
+ window, false);
+ if (!result) {
- showComposite(compositeInstallablePage);
++ showComposite(compositeInstallableListPage);
+ btnBack.setVisible(true);
+ btnNext.setVisible(true);
+ btnClose.setEnabled(true);
+ }
- } else if (sl_composite.topControl == compositeUninstallablePage) {
++ } else if (sl_composite.topControl == compositeUninstallableListPage) {
+ showComposite(compositeUninstallingPage);
+ btnBack.setVisible(false);
+ btnNext.setVisible(false);
+ btnClose.setEnabled(false);
- addExtraButton.setVisible(false);
- List<Item> items = compositeUninstallablePage.getItems();
++ List<Item> items = compositeUninstallableListPage.getItems();
+ boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,
+ controller,
+ window);
+ if (!result) {
- showComposite(compositeUninstallablePage);
++ showComposite(compositeUninstallableListPage);
+ btnBack.setVisible(true);
+ btnNext.setVisible(true);
+ btnClose.setEnabled(true);
+ }
+ }
+ }
+ });
+ btnNext.setBounds(447, 10, 78, 29);
-
- btnBack = new Button(composite_1, SWT.NONE);
++ }
++
++ private void setButtonBack(Composite composite) {
++ btnBack = new Button(composite, SWT.NONE);
+ btnBack.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
- if (sl_composite.topControl == compositeLicensePage) {
++ if (sl_composite.topControl == compositeInstallableListPage
++ || sl_composite.topControl == compositeUpdatableListPage) {
++ compositeInstallableListPage.getItems().clear();
++ showComposite(compositeWelcomePage);
++// if (controller.existRemovablePackage()) {
++// btnBack.setVisible(false);
++// showComposite(compositeWelcomePage);
++// } else {
++// showComposite(compositeLicensePage);
++// }
++ btnNext.setVisible(false);
++ btnBack.setVisible(false);
++ } else if (sl_composite.topControl == compositeLicensePage) {
+ btnNext.setEnabled(true);
+ btnBack.setVisible(false);
+ btnNext.setFocus();
- btnSettings.setVisible(true);
- addExtraButton.setVisible(false);
- showComposite(compositeWelcomePage);
- } else if (sl_composite.topControl == compositeInstallablePage || sl_composite.topControl == compositeUpdatableListPage) {
- compositeInstallablePage.getItems().clear();
- addExtraButton.setVisible(false);
- if (controller.existRemovablePackage()) {
- btnBack.setVisible(false);
- btnSettings.setVisible(true);
- showComposite(compositeWelcomePage);
- } else {
- showComposite(compositeLicensePage);
++ if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.INSTALL) {
++ showComposite(compositeInstallableListPage);
++ btnNext.setText("Next");
++ btnBack.setVisible(true);
++ } else if (compositeWelcomePage.getSelectedButton() == INSTALLMANAGER_ACTION.UPDATE) {
++ showComposite(compositeUpdatableListPage);
++ btnNext.setText("Next");
++ btnBack.setVisible(true);
+ }
- btnNext.setEnabled(true);
- btnNext.setText("Next");
+ } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {
- showComposite(compositeInstallablePage);
- addExtraButton.setVisible(true);
- btnNext.setText("Next");
++ showComposite(compositeLicensePage);
++ btnNext.setText("I agree");
+ btnNext.setEnabled(true);
- } else if (sl_composite.topControl == compositeUninstallablePage) {
++ } else if (sl_composite.topControl == compositeUninstallableListPage) {
+ showComposite(compositeWelcomePage);
- addExtraButton.setVisible(false);
- btnNext.setText("Next");
- btnNext.setEnabled(true);
++ btnNext.setVisible(false);
+ btnBack.setVisible(false);
+ }
+ }
+ });
+ btnBack.setBounds(363, 10, 78, 29);
+ btnBack.setText("Back");
+ btnBack.setVisible(false);
-
- createBtnSettings(composite_1);
- setAddRepositoryButton(composite_1);
-
- compositeWelcomePage = new WelcomePage(pageComposite, SWT.NONE);
- compositeLicensePage = new LicensePage(pageComposite, SWT.NONE);
- compositeCompletePage = new CompletePage(pageComposite, SWT.NONE);
- compositeInstallingPage = new InstallingPage(pageComposite, SWT.NONE);
- compositeInstallablePage = new InstallableListPage(pageComposite, SWT.NONE);
- compositeUninstallingPage = new UninstallingPage(pageComposite, SWT.NONE);
- compositeUninstallablePage = new UninstallableListPage(pageComposite, SWT.NONE);
- compositeSetInstallDirectoryPage = new SetInstallDirectoryPage(pageComposite, SWT.NONE);
- compositeUpdatableListPage = new UpdatableListPage(pageComposite, SWT.NONE);
-
- registLicensePageListener();
- registCompletePageListener();
-
- initWelcomePage();
-
- return container;
- }
-
- private void createBtnSettings(Composite composite) {
- btnSettings = new Button(composite, SWT.NONE);
- btnSettings.setText("Proxy settings");
- btnSettings.setBounds(25, 10, 120, 29);
-
- btnSettings.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- ConfigFile configFile = Config.getInstance().getConfigFile();
- ProxySettingsDialog psDialog = new ProxySettingsDialog(getShell());
-
- psDialog.setProxySettings(configFile.getProxyType(),
- configFile.getProxyHost(),
- configFile.getProxyPort());
-
- psDialog.open();
- }
- });
- }
-
- /**
- * Set add Repository button.
- */
- private void setAddRepositoryButton(final Composite composite) {
- if (addExtraButton == null) {
- addExtraButton = new Button(composite ,SWT.NONE);
- }
-
- addExtraButton.setBounds(20, 10, 130, 29);
- addExtraButton.setText("Extra repository");
- addExtraButton.setVisible(false);
-
- addExtraButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- extraDialog = new AddExtraRepositoryDialog(composite.getShell(), controller);
- extraDialog.open();
-
- if (sl_composite.topControl == compositeInstallablePage) {
- compositeInstallablePage.loadPage(controller);
- } else if (sl_composite.topControl == compositeUpdatableListPage) {
- compositeUpdatableListPage.loadPage(controller);
- }
- }
- });
+ }
+
+ private void initWelcomePage() {
+ compositeWelcomePage.setViewController(controller);
+
+ if (ErrorController.checkInstallationSuccess()) {
- compositeWelcomePage.setTitle(WelcomePage.STRING_TITLE);
- compositeWelcomePage.setSubTitleBounds(20, 190, 600, 40);
- compositeWelcomePage.setSubTitle(WelcomePage.STRING_SUBTITLE);
-
- compositeWelcomePage.setVisibleRadioButton(true);
- btnNext.setEnabled(true);
- btnNext.setVisible(true);
++// compositeWelcomePage.setTitle(WelcomePage.STRING_TITLE);
++// compositeWelcomePage.setSubTitleBounds(20, 190, 600, 40);
++// compositeWelcomePage.setSubTitle(WelcomePage.STRING_SUBTITLE1);
++//
++// compositeWelcomePage.setVisibleRadioButton(true);
++// btnNext.setEnabled(true);
++ btnNext.setVisible(false);
+ btnClose.setText("Cancel");
+
+ btnClose.removeSelectionListener(closeBtnSelectionAdapter);
+ btnClose.removeSelectionListener(cancelBtnSelectionAdapter);
+ btnClose.addSelectionListener(cancelBtnSelectionAdapter);
+
+ compositeWelcomePage.setButtonStatus();
+ } else {
+ compositeWelcomePage.setVisibleRadioButton(false);
+ btnNext.setVisible(false);
+
+ compositeWelcomePage.setTitle("Cannot start Tizen SDK Install Manager.");
+
+ String errMsg = ErrorController.getErrorMessage();
+ String repository = Config.getInstance().getConfigFile().getRepository();
+
+ if (repository != null && !repository.isEmpty()) {
+ errMsg = errMsg + "\n(" + repository + ")";
+ }
+ compositeWelcomePage.setSubTitleBounds(20, 190, 600, 100);
+ compositeWelcomePage.setErrorSubTitle(errMsg);
+
+ btnClose.setText("Close");
+
+ btnClose.removeSelectionListener(closeBtnSelectionAdapter);
+ btnClose.removeSelectionListener(cancelBtnSelectionAdapter);
+ btnClose.addSelectionListener(closeBtnSelectionAdapter);
+ }
+ btnNext.setFocus();
+ sl_composite.topControl = compositeWelcomePage;
+ }
+
+ /**
+ * Refresh InstallManager.
+ * Refresh packages and configuration information.
+ */
+ public void refresh() {
+ final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();
+ final Shell shell = progressbar.getParent();
+ shell.getDisplay().asyncExec(new Runnable(){
+ public void run() {
+ progressbar.updateName("Initializing...");
+
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ PackageManager.dispose();
+ initInstallManager();
+ initWelcomePage();
+ }
+ });
+
+ //init end
+ progressbar.finish();
+ }
+ });
+
+ if (!shell.isDisposed()) {
+ progressbar.open();
+ }
+
+ Log.log("Window refresh end");
+ }
+
+ /**
+ * Checks if there's updatable meta package.
+ * Then print "updatable" to stdout.
+ */
+ private static void checkMetaPackageUpdate() {
+ if (PackageManager.getInstance().getUpdatableMetaPackages().size() != 0) {
+ System.out.println("updatable");
+ }
+ }
+
+ /**
+ * There is no UI, just download packages.
+ * @throws IMExitException
+ */
+ private static void onlyDownloadPackages() throws IMExitException {
+ ViewController controller = new ViewController();
+ controller.init();
+
+ InstallManager installManager = InstallManager.getInstance();
+ PackageManager packageManager = installManager.getPackageManager();
+
+ // Get all meta packages list by boundary.(eg. public, partner, all....)
+ PackageSet filteredMeta = filterPackageSet();
+ PackageSet downloadablePkgs = packageManager.getDependsPackagesFromRepository(filteredMeta);
+
+ // Download all meta packages.
+ boolean filteredPackages = false;
+ try {
+ filteredPackages = installManager.downloadPackages(
+ downloadablePkgs, null);
+ } catch (IMNetworkException e) {
+ Log.ExceptionLog(e);
+ return;
+ }
+
+ if (filteredPackages) {
+ Log.log("Success to download packages from repository");
+ } else {
+ Log.err("Fail to download packages from repository");
+ return;
+ }
+ }
+
+ private static PackageSet filterPackageSet() {
+ PackageManager pm = PackageManager.getInstance();
+
+ PackageSet downloadPackageList = pm.getLeafMetaPackages();
+
+ String boundary = Options.boundary;
+ if (boundary.equalsIgnoreCase("public")) {
+ PackageSet partnerMetaPackages = pm.getPartnerMetaPackages();
+
+ if (!partnerMetaPackages.isEmpty()) {
+ downloadPackageList.removeAll(partnerMetaPackages);
+ }
+ } else if (boundary.equalsIgnoreCase("partner")) {
+ PackageSet publicMetaPackages = pm.getPublicMetaPackages();
+
+ if (!publicMetaPackages.isEmpty()) {
+ downloadPackageList.removeAll(publicMetaPackages);
+ }
+ }
+
+ return downloadPackageList;
+ }
+
+ private static void showInstallManagerVersion() {
+ System.out.println("InstallManager Version : " +
+ Config.getInstance().getInstallManagerVersion().toString());
+ }
+
+ /**
+ * Logging all system information.
+ */
+ private static void loggingProperty() {
+ Log.log("=========== System properties ===========");
+ Properties sysprops = System.getProperties();
+ for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String value = sysprops.getProperty(key);
+ Log.log(key + " = " + value);
+ }
+
+ Log.log("=========== Environment variables ===========");
+
+ Map<String, String> env = System.getenv();
+ Set<String> set = env.keySet();
+ Iterator<String> iter = set.iterator();
+
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ Set<Entry<String, String>> value = env.entrySet();
+ Log.log(key + " = " + value);
+ }
+ Log.log("=============================================");
+ }
+
+ /**
+ * Launch the application.
+ *
+ * @param args
+ */
+ public static void main(String args[]) {
+ //performance measurement
+ Performance.setIMStartTime();
+
+ InstallManager.deleteTempFile();
+
+ Log.open();
+ Log.LogTitle("Installmanager start");
+ Log.log(Platform.getPlatformInfo());
+ Log.log(PathUtil.getCurrentDir());
+
+ if (Options.propertyLogging) {
+ loggingProperty();
+ }
+
+ try {
+ Options.loadCmdArgs(args);
+ } catch (IMFatalException e) {
+ Log.err("Check your options. => " + Arrays.toString(args));
+ System.out.println("Check your options. => " + Arrays.toString(args));
+ return;
+ }
+
+ try {
+ if (Options.onlyDownload) {
+ onlyDownloadPackages();
+ System.exit(0);
+ } else if (Options.downloadPackage) {
+ if (InstallManagerNoUI.cliDownload(Options.packages)) {
+ Log.log("Success to download packages. => " + Options.packages);
+ System.out.println("Success to download packages. => " + Options.packages);
+ } else {
+ Log.log("Fail to download packages. => " + Options.packages);
+ System.out.println("Fail to download packages. => " + Options.packages);
+ }
+ System.exit(0);
+ } else if (Options.doInstallNoUI) {
+ if (InstallManagerNoUI.cliInstall(Options.packages)) {
+ Log.log("Success to command line install.");
+ System.out.println("Success to console install.");
+ Performance.setIMEndTime();
+ if (Options.doTest) {
+ Performance.printTestResult();
+ Performance.printTestResultXmlFormat(true);
+ Performance.printTestResultXmlFormat2(true);
+ Performance.printTestResultXmlFormat(false);
+ Performance.printTestResultXmlFormat2(false);
+ }
+ } else {
+ Log.log("Fail to command line install.");
+ System.out.println("Fail to console install.");
+ }
- Performance.printToLogFile();
++
++ Performance.setIMEndTime();
++ if (Options.doTest) {
++ Performance.printTestResultXmlFormat();
++ Performance.printTestResultXmlFormat2();
++ }
++
+ System.exit(0);
+ } else if (Options.doRemoveNoUI) {
+ if (InstallManagerNoUI.cliUninstall(Options.packages)) {
+ Log.log("Success to command line remove.");
+ System.out.println("Success to remove.");
+ Performance.setIMEndTime();
+ if (Options.doTest) {
+ Performance.printTestResult();
+ Performance.printTestResultXmlFormat(true);
+ Performance.printTestResultXmlFormat2(true);
+ Performance.printTestResultXmlFormat(false);
+ Performance.printTestResultXmlFormat2(false);
+ }
+ } else {
+ Log.log("Fail to command line remove.");
+ System.out.println("Fail to remove.");
+ }
- Performance.printToLogFile();
++
++ Performance.setIMEndTime();
++ if (Options.doTest) {
++ Performance.printTestResultXmlFormat();
++ Performance.printTestResultXmlFormat2();
++ }
++
+ System.exit(0);
+ } else if (Options.showVersion) {
+ showInstallManagerVersion();
+ System.exit(0);
+ } else if (Options.doShowHelp) {
+ InstallManagerNoUI.cliShowHelp();
+ System.exit(0);
+ }
+
+ if (Platform.isMacOS()) {
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+ System.setProperty(
+ "com.apple.mrj.application.apple.menu.about.name",
+ "Emulator Manager");
+ Display display = Display.getDefault();
+ display.syncExec(new Runnable() {
+ @Override
+ public void run() {
+ new CocoaUtil().removeTopMenuItems();
+ }
+ });
+ }
+
+ window = new InstallManagerWindow();
+ window.setBlockOnOpen(true);
+
+ window.init();
+
+ Log.log("after init");
+ if (Options.checkPackageUpdate) {
+ checkMetaPackageUpdate();
+ } else if (Options.printDepGraph) {
+ InstallManager.getInstance().getPackageManager().printDepGraph();
+ } else if (Options.doShowDistListNoUI) {
+ InstallManagerNoUI.cliShowRepoInformation();
+ } else if (Options.doShowPackageListNoUI) {
+ InstallManagerNoUI.cliShowPackageList();
+ } else if (Options.doShowSDKInstallStatus) {
+ InstallManagerNoUI.cliShowInstallInformation();
+ } else if (Options.doSDKPatch) {
+ InstallManagerNoUI.cliSDKPatch();
+ System.exit(0);
+ } else {
+ window.open();
+ if (Display.getCurrent() != null
+ && !Display.getCurrent().isDisposed()) {
+ Display.getCurrent().dispose();
+ }
+ }
+ } catch (IMExitException e) {
+ // do not remove sdk temp dir if exit for self update
+ if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {
+ Options.doRemoveTempTizenSDK = false;
+ }
+
+ Log.log("Gracefully exit");
+ } catch (Throwable e) {
+ Log.err("Unexpected error occurred");
+ Log.ExceptionLog(e);
+
+ if (Options.doSDKPatch) {
+ System.out.println("Fail to SDK patch process.");
+ PathUtil.remove(PathUtil.get(
+ Registry.getInstalledPath(), InstallManagerConstants.SDK_PATCH_TEMP_NAME));
+ System.exit(0);
+ }
+
+ if (Options.doInstallNoUI || Options.doRemoveNoUI) {
+ PathUtil.remove(Registry.REGISTRY_FILE_PATH);
+ PathUtil.remove(Registry.MULTI_SDK_FILE_PATH);
+ System.out.println("Fatal error occurred.");
+ System.exit(0);
+ }
+
+ // show error message
+ if (window != null) {
+ window.open();
+
+ if (Display.getCurrent() != null
+ && !Display.getCurrent().isDisposed()) {
+ Display.getCurrent().dispose();
+ }
+ }
+
+ ErrorController.setExitCode(Config.EXITCODE_UNKNOWN_ERROR);
+ } finally {
+ if (Platform.isWindows()) {
+ ProgramController.createProgramController().removeSDKTempDir();
+ }
+
+ //performance measurement
+ Performance.setIMEndTime();
+ Performance.printToLogFile();
+
+ if (Options.doTest) {
- Performance.printTestResultXmlFormat(true);
- Performance.printTestResultXmlFormat2(true);
- Performance.printTestResultXmlFormat(false);
- Performance.printTestResultXmlFormat2(false);
++ Performance.printTestResultXmlFormat();
++ Performance.printTestResultXmlFormat2();
+ }
+
+ Log.LogTitle("Installmanager finish");
+ Log.close();
+
+ if (Platform.isMacOS()) {
+ System.exit(ErrorController.getExitCode());
+ } else {
+ if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {
+ String binary = PathUtil.get(Registry.getInstalledPath(), Config.INSTALL_MANAGER_DIRECTORY, Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER);
+ try {
+ Runtime.getRuntime().exec(binary);
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ } else if (ErrorController.getExitCode() != Config.EXITCODE_NORMAL) {
+ System.exit(ErrorController.getExitCode());
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ newShell.setBackground(getBackgroundColor());
+ newShell.setMinimumSize(getInitialSize());
+ newShell.setSize(getInitialSize());
+ newShell.setImage(getWindowIconImage());
+ super.configureShell(newShell);
+
+ newShell.setText("Tizen SDK Install Manager");
+ }
+
+ @Override
+ /**
+ * Install manager window is close.
+ */
+ public boolean close() {
+ return false;
+ }
+
+ /**
+ * Return the initial size of the window.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return POINT_MAIN_WINDOW;
+ }
+
+ /**
+ * Show the composite depending on parameter.
+ * @param composite
+ */
+ public void showComposite(Composite composite) {
+ StackLayout layout;
+ if (composite.getParent().getLayout() instanceof StackLayout) {
+ layout = (StackLayout) composite.getParent().getLayout();
+ layout.topControl = composite;
+ }
+ composite.getParent().layout();
+ }
+
- private void registLicensePageListener() {
- compositeLicensePage.getAcceptButton()
- .addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- btnNext.setEnabled(compositeLicensePage.getAcceptButton()
- .getSelection());
- }
- });
- }
++// private void registLicensePageListener() {
++// compositeLicensePage.getAcceptButton()
++// .addSelectionListener(new SelectionAdapter() {
++//
++// @Override
++// public void widgetSelected(SelectionEvent e) {
++// btnNext.setEnabled(compositeLicensePage.getAcceptButton()
++// .getSelection());
++// }
++// });
++// }
+
+ private void registCompletePageListener() {
+ compositeCompletePage.addPaintListener(new PaintListener() {
+
+ @Override
+ public void paintControl(PaintEvent arg0) {
+ btnClose.setText("Close");
+ }
+ });
+ }
+
+ public void setNameOfCancelButton(String name) {
+ btnClose.setText("Close");
+ }
+
+ /**
+ * Get selected package names on installing
+ * @param items
+ * @return list of selected package names.
+ */
+ public List<String> getSelectedPackageNames(List<Item> items) {
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < items.size(); i++) {
+ items.get(i).getTerminalPackages(list, true);
+ }
+
+ return list;
+ }
+
+ /**
+ * Installed packages do not have package version, installmanager will show warning dialog.
+ * @return
+ */
+ private boolean checkVaildPkgVersion() {
+ PackageSet installedPkgs = controller.getInstalledPackages();
+ if (!installedPkgs.isEmpty()) {
+ for (Package pkg : installedPkgs) {
+ String vs = pkg.getVersion().toString();
+ if (vs != "" && vs.equals("0.0.0")) {
+ Log.err("Package version not found. ==> " + pkg.getPackageName());
+ int confirm = MessageBoxDlg.showDlg(getShell(),
+ "WARNING",
+ "'" + pkg.getPackageName() + "'" + " package version is not found.\n" +
+ "If you keep installing Tizen SDK, some unexpected may occur.\n" +
+ "Do you want to continue?",
+ DialogType.WARNING, false);
+ if (confirm == MessageBoxDlg.YES) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Get install manager window object.
+ * @return install manager window object.
+ */
+ public static InstallManagerWindow getInstallManagerWindow() {
+ return window;
+ }
+
+ /**
+ * Get complete page composite object
+ * @return complete page composite object
+ */
+ public CompletePage getCompletePage() {
+ return compositeCompletePage;
+ }
+
- public InstallableListPage getInstallableListPage() {
- return compositeInstallablePage;
++ public LicensePage getLicensePage() {
++ return compositeLicensePage;
++ }
++
++ public InstallableListPage getComponentSelectionPage() {
++ return compositeInstallableListPage;
+ }
+
+ public WelcomePage getWelcomePage() {
+ return compositeWelcomePage;
+ }
+
+ /**
+ * Get setInstallDirectoryPage composite object
+ * @return complete page composite object
+ */
+ public SetInstallDirectoryPage getSetInstallDirectoryPage() {
+ return compositeSetInstallDirectoryPage;
+ }
++
++ public Button getNextButton() {
++ return btnNext;
++ }
+
+ /**
+ * If parameter is true, 'Next' button will be enabled. but false, 'Next' button will be disabled.
+ * @param enabled
+ */
+ public static void setNextBtnEnabled(boolean enabled) {
+ btnNext.setEnabled(enabled);
+ }
+
+ /**
+ * If parameter is true, 'Back' button will be enabled. but false, 'Back' button will be disabled.
+ * @param enabled
+ */
+ public static void setBackBtnEnabled(boolean enabled) {
+ btnBack.setEnabled(enabled);
+ }
+
+ /**
+ * If parameter is true, 'Cancel' button will be enabled. but false, 'Cancel' button will be disabled.
+ * @param enabled
+ */
+ public void setCancelBtnEnabled(boolean enabled) {
+ btnClose.setEnabled(enabled);
+ }
+
+ public ViewController getViewController() {
+ return controller;
+ }
+ }
++
- /*\r
- * InstallManager\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
- * Shihyun Kim <shihyun.kim@samsung.com>\r
- * Taeyoung Son <taeyoung2.son@samsung.com>\r
- * Yongsung kim <yongsung1.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
- \r
- package org.tizen.installmanager.ui.page;\r
- \r
- import java.io.File;\r
- import java.io.IOException;\r
- import java.util.ArrayList;\r
- import java.util.Collection;\r
- import java.util.List;\r
- \r
- import org.eclipse.swt.SWT;\r
- import org.tizen.installmanager.core.Config;\r
- import org.tizen.installmanager.core.IMExitException;\r
- import org.tizen.installmanager.core.IMFatalException;\r
- import org.tizen.installmanager.core.InstallManager;\r
- import org.tizen.installmanager.core.InstallManagerConstants;\r
- import org.tizen.installmanager.core.Options;\r
- import org.tizen.installmanager.core.Performance;\r
- import org.tizen.installmanager.core.SDKExtensionInfo;\r
- import org.tizen.installmanager.core.Config.ServerType;\r
- import org.tizen.installmanager.lib.Documents;\r
- import org.tizen.installmanager.lib.Downloader;\r
- import org.tizen.installmanager.lib.ErrorController;\r
- import org.tizen.installmanager.lib.IIMProgressMonitor;\r
- import org.tizen.installmanager.lib.Log;\r
- import org.tizen.installmanager.lib.Platform;\r
- import org.tizen.installmanager.lib.Registry;\r
- import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
- import org.tizen.installmanager.lib.SDKPackageFormat;\r
- import org.tizen.installmanager.lib.exception.IMNetworkConnectException;\r
- import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;\r
- import org.tizen.installmanager.lib.exception.IMNetworkException;\r
- import org.tizen.installmanager.lib.linux.LinuxShellRunningProgramParser;\r
- import org.tizen.installmanager.pkg.lib.PackageManager;\r
- import org.tizen.installmanager.pkg.model.Package;\r
- import org.tizen.installmanager.pkg.model.PackageSet;\r
- import org.tizen.installmanager.pkg.model.ProcessInformation;\r
- import org.tizen.installmanager.pkg.model.Version;\r
- import org.tizen.installmanager.ui.InstallManagerWindow;\r
- import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
- import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
- import org.tizen.installmanager.ui.model.Item;\r
- import org.tizen.installmanager.ui.model.Item.InstallState;\r
- import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
- import org.tizen.installmanager.util.IMShellCommandFail;\r
- import org.tizen.installmanager.util.PathUtil;\r
- import org.tizen.installmanager.util.ShellUtil;\r
- \r
- /**\r
- * This class is a connector between Model and View. Model and View can communicate each other via ViewController. \r
- * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
- */\r
- public class ViewController {\r
- \r
- private InstallManager installManager;\r
- private PackageManager packageManager;\r
- private SDKExtensionInfo sdkExtensionInfo;\r
- \r
- /**\r
- * Initialize objects which need to install.\r
- * @return\r
- * true : Success to Initialize<br>\r
- * false : Fail to Initialize\r
- */\r
- public boolean init() {\r
- Log.log("ViewController init");\r
- \r
- try {\r
- installManager = InstallManager.getInstance();\r
- installManager.init();\r
- packageManager = installManager.getPackageManager();\r
- \r
- if (packageManager == null) {\r
- throw new IMFatalException("Cannot read package information.");\r
- } else {\r
- if (existInstallableOrRemovablePackages()) {\r
- sdkExtensionInfo = packageManager.getSdkExtensionInfo();\r
- \r
- \r
- // InstallManager maintains the newest extension package list always.\r
- sdkExtensionInfo.refreshCache();\r
- \r
- return true;\r
- } else {\r
- ErrorController.setInstallationSuccess(false);\r
- Log.log("existInstallableOrRemovablePackages() is false.");\r
- return false;\r
- }\r
- }\r
- } catch(IMFatalException e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Get meta packages that are available to install or to update.\r
- * @return Meta package set\r
- */\r
- public PackageSet getInstallableOrUpdatableMetaPackages() {\r
- if (packageManager == null) {\r
- Log.err("PackageManage is null.");\r
- return null;\r
- } else {\r
- return packageManager.getInstallableOrUpdatableMetaPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Get meta packages that are available to install.\r
- * @return Meta package set\r
- */\r
- public PackageSet getInstallableMetaPackageList() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getInstallableMetaPackages();\r
- }\r
- }\r
- \r
- public PackageSet getAllMetaPackages() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getAllMetaPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Get meta packages in repository.\r
- * @return Meta package set\r
- */\r
- public PackageSet getRootMetaPackageListOfRepository() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getRootMetaPackagesOfRepository();\r
- }\r
- }\r
- \r
- public PackageSet getTreeMetaPackageListOfRepository() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getRecentMetaPackages();\r
- }\r
- }\r
- \r
- public PackageSet getRootMetaPackageListOfExtension() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getRootMetaPackagesOfExtensionServer();\r
- } \r
- }\r
- \r
- /**\r
- * Get meta packages that are available to update.\r
- * @return Meta package set\r
- */\r
- public PackageSet getUpdatableMetapackageList() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getUpdatableMetaPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Get meta packages that are available to update.\r
- * @return Meta package set\r
- */\r
- public PackageSet getNotUpdatableMetapackageList() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getNotInstallableAndNotUpdatablePackages();\r
- }\r
- }\r
- \r
- /**\r
- * Get meta packages that are available to remove.\r
- * @return Meta package set\r
- */\r
- public PackageSet getRemovableMetaPackageList() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getRemovableMetaPackages();\r
- }\r
- }\r
- \r
- public PackageSet getInstallablePackageListInSnapshot() {\r
- if (packageManager == null) {\r
- return null;\r
- } else {\r
- return packageManager.getInstallableMetaPackagesInSnapshot();\r
- }\r
- }\r
- \r
- /**\r
- * Get packages that are available to remove.\r
- * @return package set\r
- */\r
- public PackageSet getRemovablePackageList() {\r
- if (packageManager == null) {\r
- Log.err("packageManage is null");\r
- return null;\r
- } else {\r
- return packageManager.getInstalledPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Check to exist removable packages.\r
- * @return if installed package exists, return true. if not return false.\r
- */\r
- public boolean existRemovablePackage() {\r
- if (packageManager == null) {\r
- return false;\r
- } else {\r
- return packageManager.existInstalledPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Check to need new installation.\r
- * @return If it needs new installation, return true. otherwise return false.\r
- */\r
- public boolean isNewInstallation() { \r
- // if (packageManager == null) {\r
- // return false;\r
- // }\r
- \r
- if (packageManager.isReInstall()) {\r
- return true;\r
- } else {\r
- return !packageManager.existInstalledPackages();\r
- }\r
- }\r
- \r
- /**\r
- * Check that package server has web or native minimal install type package.\r
- * @return If package server has web or native minimal install type package, return true\r
- * . Others return false.\r
- */\r
- public boolean hasWebNativeMinimal() {\r
- Package webMinimalPkg = packageManager.getPackageByName("WEB-MINIMAL");\r
- Package nativeMinimalPkg = packageManager.getPackageByName("NATIVE-MINIMAL");\r
- if (webMinimalPkg != null && nativeMinimalPkg != null) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Start to install and update.\r
- * @param installList : selected mata packages\r
- * @param targetPath : install path\r
- * @param monitor\r
- * @return If installation is succeeded, return true. if not return false.\r
- * @throws IMExitException \r
- */\r
- public boolean install(Collection<String> installList, String targetPath,\r
- InstallProgressMonitor monitor) throws IMExitException { \r
- Log.log("======== Start Installing ========");\r
- Log.log("Selected package list => " + installList);\r
- Log.log("target path => " + targetPath);\r
- \r
- if (packageManager == null) {\r
- Log.err("Package list does not exist.");\r
- return false;\r
- }\r
- \r
- PackageSet installablePackages = null;\r
- if (installList.size() == 0) {\r
- Log.log("Package install success.");\r
- return true;\r
- } else {\r
- installablePackages = getInstallablePackages(installList);\r
- }\r
- \r
- Registry.setSDKinfoBySDKPath(targetPath);\r
- Registry.saveSDKInfo(targetPath);\r
- \r
- boolean bResult = false;\r
- while(true) {\r
- try {\r
- bResult = installManager.install(installablePackages, targetPath, monitor);\r
- break;\r
- } catch (IMNetworkException e) {\r
- Log.ExceptionLog(e);\r
- showRetryDialog(e.getMessage());\r
- \r
- if (monitor != null) {\r
- monitor.workedRefresh();\r
- }\r
- continue;\r
- } catch (Exception e) {\r
- Log.ExceptionLog(e);\r
- throw new IMFatalException(e.getMessage());\r
- }\r
- }\r
- \r
- if (bResult) {\r
- PathUtil.remove(Config.getInstance().getDownloadDirPath());\r
- }\r
- \r
- return bResult;\r
- }\r
- \r
- public void showRetryDialog(String msg) {\r
- //retry dialog.\r
- String errorMsg = msg + "\nWould you like to retry?";\r
- int ret = MessageBoxDlg.showDlg(\r
- InstallManagerWindow.getInstallManagerWindow().getShell(),\r
- "Warning",\r
- errorMsg,\r
- DialogType.WARNING, false);\r
- \r
- if (ret == SWT.NO) { //cancel\r
- throw new IMFatalException(msg);\r
- }\r
- }\r
- \r
- /**\r
- * Get installable packages.\r
- * @param installList package name list from UI.\r
- * @return set of installable packages.\r
- */\r
- public PackageSet getInstallablePackages(Collection<String> installList) {\r
- //get installable packages\r
- PackageSet selectedMetas = packageManager.getPackagesByNames(installList);\r
- \r
- //add mandatory packages, madatory packages always reinstall.\r
- selectedMetas.addAll(packageManager.getMandatoryPackages());\r
- \r
- return packageManager.getInstallablePackages(selectedMetas);\r
- }\r
- \r
- /**\r
- * Start to uninstall\r
- * @param uninstallList\r
- * @param monitor\r
- * @return If uninstallation is succeed, return true. if not return false.\r
- * @see ViewController#uninstallPackages(PackageSet, IIMProgressMonitor)\r
- */\r
- public boolean uninstall(List<String> uninstallList, IIMProgressMonitor monitor) { \r
- Log.log("ViewController Uninstall Start => " + uninstallList);\r
- \r
- //performance measurement\r
- Performance.setRemovalStartTime();\r
- if (packageManager == null || uninstallList.size() == 0) {\r
- Log.err("ViewController.uninstall() uninstalllist does not exist. => " + uninstallList);\r
- ErrorController.setError(ErrorCode.UNKNOWN_ERROR);\r
- \r
- Performance.setRemovalEndTime();\r
- return false;\r
- }\r
- \r
- if (Options.doRemoveOldSDK || (uninstallList.size() == 1 && uninstallList.get(0).equals(Config.SDK_NAME))) {\r
- uninstallAll(monitor);\r
- \r
- //performance measurement\r
- Performance.setRemovalEndTime();\r
- \r
- return true;\r
- } else {\r
- PackageSet removablePackages = packageManager.getInstalledPackagesByName(uninstallList);\r
- \r
- //performance measurement\r
- Performance.sdkPackageSize = packageManager.getTotalSizeOfRemovablePackages(removablePackages);\r
- \r
- boolean result = uninstallPackages(removablePackages, monitor);\r
- \r
- //performance measurement\r
- Performance.setRemovalEndTime();\r
- return result;\r
- }\r
- }\r
- \r
- /**\r
- * Uninstall removable packages.\r
- * @param removableMetapkgs\r
- * @param monitor\r
- * @return If removable packages can success to uninstall, return true. if not return false.\r
- */\r
- public boolean uninstallPackages(PackageSet removableMetapkgs, IIMProgressMonitor monitor) {\r
- boolean bRet = installManager.removePackages(removableMetapkgs, monitor);\r
- \r
- Log.log("ViewController Uninstall End => " + bRet);\r
- return bRet;\r
- }\r
- \r
- /**\r
- * Remove all packages.\r
- * @param monitor\r
- */\r
- public void uninstallAll(IIMProgressMonitor monitor) {\r
- Log.log("ViewController Unintall All");\r
- installManager.removeAll(monitor);\r
- Registry.removeRegistry();\r
- }\r
- \r
- /**\r
- * Get package version that is installed already.\r
- * @param pkgName is installed packages already.\r
- * @return version\r
- */\r
- public Package getInstalledPackage(String pkgName) {\r
- return packageManager.getInstalledPackageByName(pkgName);\r
- }\r
- \r
- public PackageSet getInstalledPackages() {\r
- return packageManager.getInstalledPackages();\r
- }\r
- \r
- /**\r
- * Get items of tree\r
- * @return\r
- */\r
- public List<Item> getPackageSetOfTree() { \r
- if (packageManager == null) {\r
- return new ArrayList<Item>();\r
- }\r
- \r
- //get all meta packages (installable packages)\r
- //TODO : show all packages. (installable, installed)\r
- PackageSet metaPackageSet = packageManager.getRootMetaPackagesOfRepository(); \r
- \r
- return makeTreeItem(metaPackageSet);\r
- }\r
- \r
- /**\r
- * Make tree item from package set.\r
- * @param pkgSet\r
- * @return\r
- */\r
- public List<Item> makeTreeItem(PackageSet pkgSet) {\r
- List<Item> treeItemList = new ArrayList<Item>();\r
- Item extraItem = null;\r
- \r
- if (pkgSet == null) {\r
- return treeItemList;\r
- }\r
- \r
- for (Package pkg : pkgSet) {\r
- if (!pkg.isMeta() || pkg.isMandatory()) {\r
- continue;\r
- }\r
- \r
- InstallState itemState = getState(pkg);\r
- \r
- if (pkg.getPackageName().equalsIgnoreCase("EXTRAS")) {\r
- extraItem = new Item(pkg, pkg, itemState);\r
- continue;\r
- }\r
- \r
- Item newItem = null;\r
- if (itemState == InstallState.INSTALL) {\r
- newItem = new Item(pkg, pkg, itemState);\r
- } else if (itemState == InstallState.UPDATE) {\r
- Package installedPkg = packageManager.getInstalledMetaPackages().getPackage(pkg);\r
- newItem = new Item(pkg, installedPkg, itemState); \r
- } else if (itemState == InstallState.UNINSTALL) {\r
- newItem = new Item(pkg, pkg, itemState);\r
- } else {\r
- Log.err("Cannot find install state. => " + itemState);\r
- continue;\r
- }\r
- \r
- treeItemList.add(newItem);\r
- }\r
- \r
- if (extraItem != null) {\r
- treeItemList.add(extraItem);\r
- }\r
- \r
- return treeItemList;\r
- }\r
- \r
- public void refreshTreeItemStatus(List<Item> items) {\r
- \r
- }\r
- \r
- private InstallState getState(Package pkg) {\r
- if (PackageManager.getInstance().isReInstall()) {\r
- return InstallState.INSTALL;\r
- } else if (Config.isSupportMultiSDK()) {\r
- if (Config.status == Config.Status.INSTALL) {\r
- return InstallState.INSTALL; \r
- } else if (Config.status == Config.Status.UPDATE) {\r
- if (packageManager.getInstallableMetaPackages().contains(pkg)) {\r
- return InstallState.INSTALL;\r
- } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {\r
- return InstallState.UPDATE;\r
- } else {\r
- return InstallState.UNINSTALL;\r
- }\r
- }\r
- } else {\r
- if (packageManager.getInstallableMetaPackages().contains(pkg)) {\r
- return InstallState.INSTALL;\r
- } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {\r
- return InstallState.UPDATE;\r
- } else {\r
- return InstallState.UNINSTALL;\r
- }\r
- }\r
- \r
- return null;\r
- }\r
- \r
- /**\r
- * Get total size depends on a package list.\r
- * @param pkgList is list.\r
- * @param isUncompressed Uncompressed is true, not false.\r
- * @return size\r
- */\r
- public long getTotalSizeWithDepends(Collection<String> pkgList, boolean isUncompressed) {\r
- PackageSet pkgSet = packageManager.getPackagesByNames(pkgList);\r
- return getTotalSizeWithDepends(pkgSet, isUncompressed);\r
- }\r
- \r
- /**\r
- * Get total size depends on a package format.\r
- * @param pkg is package format.\r
- * @return size\r
- */\r
- public long getRemovablePackagesSize(Package pkg) {\r
- return packageManager.getTotalSizeOfRemovablePackages(pkg);\r
- }\r
- \r
- /**\r
- * Get total size depends on a package set.\r
- * @param pkgs is package set\r
- * @param isUncompressed Uncompressed is true, not false.\r
- * @return size\r
- */\r
- public long getTotalSizeWithDepends(PackageSet pkgs, boolean isUncompressed) {\r
- return packageManager.getTotalSizeOfInstallablePackages(pkgs, isUncompressed);\r
- }\r
- \r
- /**\r
- * Get installed path.\r
- * @return Installed target path\r
- */\r
- public String getInstalledPath() {\r
- return Registry.getInstalledPath();\r
- }\r
- \r
- public String getInstallPath() {\r
- String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getInstallPath();\r
- return path;\r
- }\r
- \r
- public String getSDKWorkSpacePath() {\r
- String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getSDKWorkSpacePath();\r
- return path;\r
- }\r
- \r
- \r
- /**\r
- * Check to exist package which can install or remove.\r
- * @return There are packages to install or remove, return true. if not false.\r
- */\r
- public boolean existInstallableOrRemovablePackages() {\r
- PackageSet rmPkgs = getRemovablePackageList();\r
- PackageSet insPkgs = getInstallableOrUpdatableMetaPackages();\r
- \r
- if (!rmPkgs.isEmpty() || !insPkgs.isEmpty()) {\r
- Log.log("existInstallableOrRemovablePackages() is true.");\r
- return (getRemovablePackageList().size() > 0 || getInstallableOrUpdatableMetaPackages().size() > 0); \r
- } else {\r
- Log.err("Both Removable Package List and Installable or Updatable Meta Packages are null"); \r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Check to exist package which can install or update.\r
- * @return There are packages to install or remove, return true. if not false.\r
- */\r
- public boolean existInstallableOrUpdatablePackages() {\r
- PackageSet ps = getInstallablePackageListInSnapshot();\r
- \r
- if (ps != null) {\r
- if (Options.snapshot || Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {\r
- return (ps.size() > 0);\r
- } else {\r
- return (ps.size() > 0);\r
- }\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * Get Install configure.\r
- * @return configure object.\r
- */\r
- public Config getConfig() {\r
- return installManager.getConfig();\r
- }\r
- \r
- /**\r
- * Get description of package.\r
- * @param pkgName\r
- * @return decription of package.\r
- */\r
- public String getDescription(String pkgName) {\r
- Package pkg = packageManager.getPackageByName(pkgName);\r
- \r
- if (pkg == null) {\r
- return "";\r
- } else {\r
- return pkg.getDescription();\r
- }\r
- }\r
- \r
- /**\r
- * Check to exist files in target directory.\r
- * @param targetDir is installed directory.\r
- * @return If there are files in directory, return true. if not false.\r
- */\r
- public boolean existFilesInTargetDirectory(String targetDir) {\r
- File targetFile = new File(targetDir);\r
- \r
- if (!targetFile.exists()) {\r
- return false;\r
- }\r
- \r
- File[] targetFileList = targetFile.listFiles();\r
- if (targetFileList == null || targetFileList.length <= 0) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- \r
- /**\r
- * Remove file or directory from parameter\r
- * @param targetPath\r
- */\r
- public void removeTargetPath(String targetPath) {\r
- PathUtil.remove(targetPath);\r
- }\r
- \r
- /**\r
- * save information of server.\r
- * @param repository Base-repository of sdk. if repository is null, it do not save repository.\r
- * @param type type of repository. if type is null, it do not save type.\r
- * @param packageServer package server of sdk. if packageServer is null, it do not save packageServer.\r
- * @param packageType set ServerType.snapshot or ServerType.package. if serverType is null, it do not save serverType.\r
- */\r
- public void saveSnapshotSettings(String repository, String distribution, ServerType packageType, String snapshotPath) {\r
- Config.getInstance().saveSnapshotSettings(repository, distribution, packageType, snapshotPath);\r
- }\r
- \r
- public SDKExtensionInfo getSdkExtensionInfo() {\r
- return sdkExtensionInfo;\r
- }\r
- \r
- public void loadSdkExtension() {\r
- sdkExtensionInfo.load();\r
- }\r
- \r
- /**\r
- * Check the environment of ubuntu.\r
- * @return If true, this is unity panel service.\r
- */\r
- public boolean isUnityEnvironment() {\r
- String command = "ps -ax";\r
- \r
- try {\r
- LinuxShellRunningProgramParser parser = new LinuxShellRunningProgramParser();\r
- int ret = ShellUtil.execute(command, parser);\r
- \r
- if (ret != 0 ){\r
- return false;\r
- } else {\r
- for (ProcessInformation pInfo : parser.getProcessInformation()) {\r
- if (pInfo.getCommand().contains("unity-panel-service")) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- return false;\r
- }\r
- }\r
- \r
- public PackageSet getConflictPackages(PackageSet pkgs) {\r
- PackageSet pkgSet = packageManager.getDependsPackagesFromRepository(pkgs); \r
- return packageManager.getConflictPackages(pkgSet);\r
- }\r
- \r
- public PackageSet getCauseOfConflict(PackageSet checkedPackages, Package conflictPackage) {\r
- PackageSet causePackages = new PackageSet();\r
- \r
- for (Package pkg : checkedPackages) {\r
- if (packageManager.conflictPackages(pkg).contains(conflictPackage)) {\r
- causePackages.add(pkg);\r
- }\r
- }\r
- \r
- return causePackages;\r
- }\r
- \r
- public void showChangeLog() {\r
- if (Documents.isChecked()) {\r
- Documents.showChangeLog(); // show the change log(history)\r
- }\r
- }\r
- \r
- public void cleanUpTargetDirectory() {\r
- Log.log("Clean up the target directory => " + Registry.getInstalledPath());\r
- if (packageManager == null || packageManager.getInstalledPackages().isEmpty()) {\r
- String targetPath = Config.getInstance().getTargetDir();\r
- \r
- if (targetPath.isEmpty()) {\r
- return;\r
- } else {\r
- removeTargetPath(targetPath);\r
- }\r
- }\r
- }\r
- \r
- public boolean canInstallManagerUpdate() {\r
- Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
- \r
- if (pkg == null) {\r
- return false;\r
- }\r
- String version = Config.getInstance().getCurrentConfigFile().getInstallManagerVersion();\r
- \r
- Log.log("Current InstallManager version => " + version);\r
- if (version == null || version.isEmpty()) {\r
- return true;\r
- }\r
- \r
- Log.log("Update version => " + pkg.getVersion().toString());\r
- if (Version.compareTo(new Version(version), pkg.getVersion()) < 0) {\r
- Log.log("Update version is higher than current version. So, installmanager will be updated.");\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public boolean isInstalledInstallManager() {\r
- Package installedPackage = packageManager.getInstalledPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
- \r
- if (installedPackage != null) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public boolean updateInstallManager() {\r
- Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
- \r
- if (pkg == null) {\r
- return false;\r
- }\r
- \r
- if (installInstallManagerToTemp()) {\r
- Log.log("## Success to update the InstallManager, and restart now.");\r
- System.out.println("## Success to update the InstallManager, and restart now.");\r
- \r
- runNewInstallManager();\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- public boolean installInstallManagerToTemp() {\r
- String imPackage = downloadInstallManager();\r
- if (imPackage == null) {\r
- return false;\r
- }\r
- \r
- if (extractIMPackage(imPackage)) {\r
- Log.log("Success to extract updatable InstallManager.");\r
- runNewInstallManager();\r
- return true;\r
- } else {\r
- Log.err("Fail to extract updatable InstallManager. Cannot execute it.");\r
- return false;\r
- }\r
- }\r
- \r
- private String downloadInstallManager() {\r
- Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
- \r
- Downloader downloader = new Downloader();\r
- \r
- String packagePath = pkg.getFileName();\r
- String installManagerTempPath = PathUtil.get(PathUtil.getTempDir(), PathUtil.getFileName(packagePath));\r
- File tempInstaller = new File(installManagerTempPath);\r
- \r
- if (tempInstaller.exists()) {\r
- if (!PathUtil.remove(installManagerTempPath)) {\r
- Log.err("Cannot remove installmanager. => " + tempInstaller);\r
- }\r
- }\r
- \r
- try {\r
- long size = downloader.download(pkg.getURL(), installManagerTempPath, null);\r
- \r
- if (size > 0) {\r
- return installManagerTempPath;\r
- } else {\r
- return null;\r
- }\r
- } catch (IMNetworkConnectException e) {\r
- Log.ExceptionLog(e);\r
- return null;\r
- } catch (IMNetworkDownloadException e) {\r
- Log.ExceptionLog(e);\r
- return null;\r
- }\r
- }\r
- \r
- private boolean extractIMPackage(String imPath) {\r
- removeIMBinaryInTemp();\r
- \r
- SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();\r
- long size = format.unZip(imPath, PathUtil.getTempDir(), null);\r
- \r
- if (size > 0) {\r
- return true;\r
- } else {\r
- throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
- }\r
- }\r
- \r
- private void removeIMBinaryInTemp() {\r
- String tempDir = PathUtil.getTempDir();\r
- \r
- File tempDirFile = new File(tempDir);\r
- \r
- for (File childFile : tempDirFile.listFiles()) {\r
- if (isIMBinary(childFile.getName())) {\r
- if (!childFile.delete()) {\r
- Log.err("Cannot delete " + childFile.getAbsolutePath());\r
- }\r
- }\r
- }\r
- }\r
- \r
- private boolean isIMBinary(String fileName) {\r
- if (fileName.equals(InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME)){\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- private void runNewInstallManager() {\r
- File tempIMJarFile = new File(PathUtil.get(\r
- PathUtil.getTempDir(), "data", "install-manager",\r
- InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME));\r
- \r
- if (tempIMJarFile.exists()) {\r
- try {\r
- ArrayList<String> commands = new ArrayList<String>();\r
- \r
- String javaHome = System.getProperty("java.home");\r
- File java = null;\r
- if (Platform.isLinux() || Platform.isMacOS()) {\r
- java = new File(PathUtil.get(javaHome, "bin", "java"));\r
- } else if (Platform.isWindows()) {\r
- java = new File(PathUtil.get(javaHome, "bin", "java.exe"));\r
- }\r
- \r
- String forceBitOption = "-d" + System.getProperty("sun.arch.data.model");\r
- \r
- String jarPath = PathUtil.get(tempIMJarFile.getAbsolutePath());\r
- if (java.exists()) {\r
- commands.add(java.getAbsolutePath());\r
- } else {\r
- commands.add("java");\r
- }\r
- \r
- if (Platform.isMacOS()) {\r
- commands.add("-XstartOnFirstThread");\r
- }\r
- \r
- commands.add(forceBitOption);\r
- commands.add("-jar");\r
- commands.add(jarPath);\r
- \r
- if (Options.executablePath != null) {\r
- commands.add("-path");\r
- commands.add(Options.executablePath);\r
- }\r
- \r
- String repo = Config.getInstance().getConfigFile().getRepository();\r
- if (repo != null & !repo.isEmpty()) {\r
- commands.add("-repository");\r
- commands.add(repo);\r
- }\r
- \r
- String dist = Config.getInstance().getConfigFile().getDistribution();\r
- if (repo != null & !repo.isEmpty()) {\r
- commands.add("-distribution");\r
- commands.add(dist);\r
- }\r
- \r
- String proxyHost = Config.getInstance().getConfigFile().getProxyHost();\r
- int proxyPort = Config.getInstance().getConfigFile().getProxyPort();\r
- if (proxyHost != null & !proxyHost.isEmpty()) {\r
- if (proxyPort > 0) {\r
- commands.add("-proxy");\r
- commands.add(proxyHost + ":" + proxyPort);\r
- }\r
- }\r
- \r
- Config.getInstance().getConfigFile().setInstallManagerVersion(packageManager.getPackageByName("install-manager").getVersion().toString());\r
- Config.getInstance().getConfigFile().saveConfig(PathUtil.get(tempIMJarFile.getParent(), "installmanager.conf"));\r
- \r
- Log.log("Updatable commands => " + commands);\r
- \r
- ProcessBuilder pb = new ProcessBuilder(commands);\r
- pb.directory(tempIMJarFile.getParentFile());\r
- pb.start();\r
- \r
- System.exit(0);\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- return;\r
- }\r
- }\r
- }\r
- }\r
+ /*
+ * InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Taeyoung Son <taeyoung2.son@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.page;
+
+ import java.io.File;
+ import java.io.IOException;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.List;
+
+ import org.eclipse.swt.SWT;
+ import org.tizen.installmanager.core.Config;
+ import org.tizen.installmanager.core.IMExitException;
+ import org.tizen.installmanager.core.IMFatalException;
+ import org.tizen.installmanager.core.InstallManager;
+ import org.tizen.installmanager.core.InstallManagerConstants;
+ import org.tizen.installmanager.core.Options;
+ import org.tizen.installmanager.core.Performance;
+ import org.tizen.installmanager.core.SDKExtensionInfo;
+ import org.tizen.installmanager.core.Config.ServerType;
+ import org.tizen.installmanager.lib.Documents;
+ 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.lib.Platform;
+ import org.tizen.installmanager.lib.Registry;
+ import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+ import org.tizen.installmanager.lib.SDKPackageFormat;
+ import org.tizen.installmanager.lib.exception.IMNetworkConnectException;
+ import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;
+ import org.tizen.installmanager.lib.exception.IMNetworkException;
+ import org.tizen.installmanager.lib.linux.LinuxShellRunningProgramParser;
+ import org.tizen.installmanager.pkg.lib.PackageManager;
+ import org.tizen.installmanager.pkg.model.Package;
+ import org.tizen.installmanager.pkg.model.PackageSet;
+ import org.tizen.installmanager.pkg.model.ProcessInformation;
+ import org.tizen.installmanager.pkg.model.Version;
+ import org.tizen.installmanager.ui.InstallManagerWindow;
+ import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
+ import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
+ import org.tizen.installmanager.ui.model.Item;
+ import org.tizen.installmanager.ui.model.Item.InstallState;
+ import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
+ import org.tizen.installmanager.util.IMShellCommandFail;
+ import org.tizen.installmanager.util.PathUtil;
+ import org.tizen.installmanager.util.ShellUtil;
+
+ /**
+ * This class is a connector between Model and View. Model and View can communicate each other via ViewController.
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>
+ */
+ public class ViewController {
+
+ private InstallManager installManager;
+ private PackageManager packageManager;
+ private SDKExtensionInfo sdkExtensionInfo;
+
+ /**
+ * Initialize objects which need to install.
+ * @return
+ * true : Success to Initialize<br>
+ * false : Fail to Initialize
+ */
+ public boolean init() {
+ Log.log("ViewController init");
+
+ try {
+ installManager = InstallManager.getInstance();
+ installManager.init();
+ packageManager = installManager.getPackageManager();
+
+ if (packageManager == null) {
+ throw new IMFatalException("Cannot read package information.");
+ } else {
+ if (existInstallableOrRemovablePackages()) {
+ sdkExtensionInfo = packageManager.getSdkExtensionInfo();
+
+
+ // InstallManager maintains the newest extension package list always.
+ sdkExtensionInfo.refreshCache();
+
+ return true;
+ } else {
+ ErrorController.setInstallationSuccess(false);
+ Log.log("existInstallableOrRemovablePackages() is false.");
+ return false;
+ }
+ }
+ } catch(IMFatalException e) {
+ Log.ExceptionLog(e);
+ return false;
+ }
+ }
+
+ /**
+ * Get meta packages that are available to install or to update.
+ * @return Meta package set
+ */
+ public PackageSet getInstallableOrUpdatableMetaPackages() {
+ if (packageManager == null) {
+ Log.err("PackageManage is null.");
+ return null;
+ } else {
+ return packageManager.getInstallableOrUpdatableMetaPackages();
+ }
+ }
+
+ /**
+ * Get meta packages that are available to install.
+ * @return Meta package set
+ */
+ public PackageSet getInstallableMetaPackageList() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getInstallableMetaPackages();
+ }
+ }
+
+ public PackageSet getAllMetaPackages() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getAllMetaPackages();
+ }
+ }
+
+ /**
+ * Get meta packages in repository.
+ * @return Meta package set
+ */
+ public PackageSet getRootMetaPackageListOfRepository() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getRootMetaPackagesOfRepository();
+ }
+ }
+
+ public PackageSet getTreeMetaPackageListOfRepository() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getRecentMetaPackages();
+ }
+ }
+
+ public PackageSet getRootMetaPackageListOfExtension() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getRootMetaPackagesOfExtensionServer();
+ }
+ }
+
+ /**
+ * Get meta packages that are available to update.
+ * @return Meta package set
+ */
+ public PackageSet getUpdatableMetapackageList() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getUpdatableMetaPackages();
+ }
+ }
+
+ /**
+ * Get meta packages that are available to update.
+ * @return Meta package set
+ */
+ public PackageSet getNotUpdatableMetapackageList() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getNotInstallableAndNotUpdatablePackages();
+ }
+ }
+
+ /**
+ * Get meta packages that are available to remove.
+ * @return Meta package set
+ */
+ public PackageSet getRemovableMetaPackageList() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getRemovableMetaPackages();
+ }
+ }
+
+ public PackageSet getInstallablePackageListInSnapshot() {
+ if (packageManager == null) {
+ return null;
+ } else {
+ return packageManager.getInstallableMetaPackagesInSnapshot();
+ }
+ }
+
+ /**
+ * Get packages that are available to remove.
+ * @return package set
+ */
+ public PackageSet getRemovablePackageList() {
+ if (packageManager == null) {
+ Log.err("packageManage is null");
+ return null;
+ } else {
+ return packageManager.getInstalledPackages();
+ }
+ }
+
+ /**
+ * Check to exist removable packages.
+ * @return if installed package exists, return true. if not return false.
+ */
+ public boolean existRemovablePackage() {
+ if (packageManager == null) {
+ return false;
+ } else {
+ return packageManager.existInstalledPackages();
+ }
+ }
+
+ /**
+ * Check to need new installation.
+ * @return If it needs new installation, return true. otherwise return false.
+ */
+ public boolean isNewInstallation() {
+ // if (packageManager == null) {
+ // return false;
+ // }
+
- if (packageManager.isReInstallable()) {
++ if (packageManager.isReInstall()) {
+ return true;
+ } else {
+ return !packageManager.existInstalledPackages();
+ }
+ }
+
+ /**
+ * Check that package server has web or native minimal install type package.
+ * @return If package server has web or native minimal install type package, return true
+ * . Others return false.
+ */
+ public boolean hasWebNativeMinimal() {
+ Package webMinimalPkg = packageManager.getPackageByName("WEB-MINIMAL");
+ Package nativeMinimalPkg = packageManager.getPackageByName("NATIVE-MINIMAL");
+ if (webMinimalPkg != null && nativeMinimalPkg != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Start to install and update.
+ * @param installList : selected mata packages
+ * @param targetPath : install path
+ * @param monitor
+ * @return If installation is succeeded, return true. if not return false.
+ * @throws IMExitException
+ */
+ public boolean install(Collection<String> installList, String targetPath,
+ InstallProgressMonitor monitor) throws IMExitException {
+ Log.log("======== Start Installing ========");
+ Log.log("Selected package list => " + installList);
+ Log.log("target path => " + targetPath);
+
+ if (packageManager == null) {
+ Log.err("Package list does not exist.");
+ return false;
+ }
+
+ PackageSet installablePackages = null;
+ if (installList.size() == 0) {
+ Log.log("Package install success.");
+ return true;
+ } else {
+ installablePackages = getInstallablePackages(installList);
+ }
+
+ Registry.setSDKinfoBySDKPath(targetPath);
+ Registry.saveSDKInfo(targetPath);
+
+ boolean bResult = false;
+ while(true) {
+ try {
+ 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);
+ showRetryDialog(e.getMessage());
+
++ if (monitor != null) {
++ monitor.workedRefresh();
++ }
+ continue;
+ } catch (Exception e) {
+ Log.ExceptionLog(e);
+ throw new IMFatalException(e.getMessage());
+ }
+ }
+
+ if (bResult) {
+ PathUtil.remove(Config.getInstance().getDownloadDirPath());
+ }
+
+ return bResult;
+ }
+
+ public void showRetryDialog(String msg) {
+ //retry dialog.
+ String errorMsg = msg + "\nWould you like to retry?";
+ int ret = MessageBoxDlg.showDlg(
+ InstallManagerWindow.getInstallManagerWindow().getShell(),
+ "Warning",
+ errorMsg,
+ DialogType.WARNING, false);
+
+ if (ret == SWT.NO) { //cancel
+ throw new IMFatalException(msg);
+ }
+ }
+
+ /**
+ * Get installable packages.
+ * @param installList package name list from UI.
+ * @return set of installable packages.
+ */
+ public PackageSet getInstallablePackages(Collection<String> installList) {
+ //get installable packages
+ PackageSet selectedMetas = packageManager.getPackagesByNames(installList);
+
+ //add mandatory packages, madatory packages always reinstall.
+ selectedMetas.addAll(packageManager.getMandatoryPackages());
+
+ return packageManager.getInstallablePackages(selectedMetas);
+ }
+
+ /**
+ * Start to uninstall
+ * @param uninstallList
+ * @param monitor
+ * @return If uninstallation is succeed, return true. if not return false.
+ * @see ViewController#uninstallPackages(PackageSet, IIMProgressMonitor)
+ */
+ public boolean uninstall(List<String> uninstallList, IIMProgressMonitor monitor) {
+ Log.log("ViewController Uninstall Start => " + uninstallList);
+
+ //performance measurement
+ Performance.setRemovalStartTime();
+ if (packageManager == null || uninstallList.size() == 0) {
+ Log.err("ViewController.uninstall() uninstalllist does not exist. => " + uninstallList);
+ ErrorController.setError(ErrorCode.UNKNOWN_ERROR);
+
+ Performance.setRemovalEndTime();
+ return false;
+ }
+
+ if (Options.doRemoveOldSDK || (uninstallList.size() == 1 && uninstallList.get(0).equals(Config.SDK_NAME))) {
+ uninstallAll(monitor);
+
+ //performance measurement
+ Performance.setRemovalEndTime();
+
+ return true;
+ } else {
+ PackageSet removablePackages = packageManager.getInstalledPackagesByName(uninstallList);
+
+ //performance measurement
+ Performance.sdkPackageSize = packageManager.getTotalSizeOfRemovablePackages(removablePackages);
+
+ boolean result = uninstallPackages(removablePackages, monitor);
+
+ //performance measurement
+ Performance.setRemovalEndTime();
+ return result;
+ }
+ }
+
+ /**
+ * Uninstall removable packages.
+ * @param removableMetapkgs
+ * @param monitor
+ * @return If removable packages can success to uninstall, return true. if not return false.
+ */
+ public boolean uninstallPackages(PackageSet removableMetapkgs, IIMProgressMonitor monitor) {
+ boolean bRet = installManager.removePackages(removableMetapkgs, monitor);
+
+ Log.log("ViewController Uninstall End => " + bRet);
+ return bRet;
+ }
+
+ /**
+ * Remove all packages.
+ * @param monitor
+ */
+ public void uninstallAll(IIMProgressMonitor monitor) {
+ Log.log("ViewController Unintall All");
+ installManager.removeAll(monitor);
+ Registry.removeRegistry();
+ }
+
+ /**
+ * Get package version that is installed already.
+ * @param pkgName is installed packages already.
+ * @return version
+ */
+ public Package getInstalledPackage(String pkgName) {
+ return packageManager.getInstalledPackageByName(pkgName);
+ }
+
+ public PackageSet getInstalledPackages() {
+ return packageManager.getInstalledPackages();
+ }
+
+ /**
+ * Get items of tree
+ * @return
+ */
+ public List<Item> getPackageSetOfTree() {
+ if (packageManager == null) {
+ return new ArrayList<Item>();
+ }
+
+ //get all meta packages (installable packages)
+ //TODO : show all packages. (installable, installed)
+ PackageSet metaPackageSet = packageManager.getRootMetaPackagesOfRepository();
+
+ return makeTreeItem(metaPackageSet);
+ }
+
+ /**
+ * Make tree item from package set.
+ * @param pkgSet
+ * @return
+ */
+ public List<Item> makeTreeItem(PackageSet pkgSet) {
+ List<Item> treeItemList = new ArrayList<Item>();
+ Item extraItem = null;
+
+ if (pkgSet == null) {
+ return treeItemList;
+ }
+
+ for (Package pkg : pkgSet) {
+ if (!pkg.isMeta() || pkg.isMandatory()) {
+ continue;
+ }
+
+ InstallState itemState = getState(pkg);
+
+ if (pkg.getPackageName().equalsIgnoreCase("EXTRAS")) {
+ extraItem = new Item(pkg, pkg, itemState);
+ continue;
+ }
+
+ Item newItem = null;
+ if (itemState == InstallState.INSTALL) {
+ newItem = new Item(pkg, pkg, itemState);
+ } else if (itemState == InstallState.UPDATE) {
+ Package installedPkg = packageManager.getInstalledMetaPackages().getPackage(pkg);
+ newItem = new Item(pkg, installedPkg, itemState);
+ } else if (itemState == InstallState.UNINSTALL) {
+ newItem = new Item(pkg, pkg, itemState);
+ } else {
+ Log.err("Cannot find install state. => " + itemState);
+ continue;
+ }
+
+ treeItemList.add(newItem);
+ }
+
+ if (extraItem != null) {
+ treeItemList.add(extraItem);
+ }
+
+ return treeItemList;
+ }
+
+ public void refreshTreeItemStatus(List<Item> items) {
+
+ }
+
+ private InstallState getState(Package pkg) {
- if (PackageManager.getInstance().isReInstallable()) {
++ if (PackageManager.getInstance().isReInstall()) {
+ return InstallState.INSTALL;
+ } else if (Config.isSupportMultiSDK()) {
+ if (Config.status == Config.Status.INSTALL) {
+ return InstallState.INSTALL;
+ } else if (Config.status == Config.Status.UPDATE) {
+ if (packageManager.getInstallableMetaPackages().contains(pkg)) {
+ return InstallState.INSTALL;
+ } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {
+ return InstallState.UPDATE;
+ } else {
+ return InstallState.UNINSTALL;
+ }
+ }
+ } else {
+ if (packageManager.getInstallableMetaPackages().contains(pkg)) {
+ return InstallState.INSTALL;
+ } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {
+ return InstallState.UPDATE;
+ } else {
+ return InstallState.UNINSTALL;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get total size depends on a package list.
+ * @param pkgList is list.
+ * @param isUncompressed Uncompressed is true, not false.
+ * @return size
+ */
+ public long getTotalSizeWithDepends(Collection<String> pkgList, boolean isUncompressed) {
+ PackageSet pkgSet = packageManager.getPackagesByNames(pkgList);
+ return getTotalSizeWithDepends(pkgSet, isUncompressed);
+ }
+
+ /**
+ * Get total size depends on a package format.
+ * @param pkg is package format.
+ * @return size
+ */
+ public long getRemovablePackagesSize(Package pkg) {
+ return packageManager.getTotalSizeOfRemovablePackages(pkg);
+ }
+
+ /**
+ * Get total size depends on a package set.
+ * @param pkgs is package set
+ * @param isUncompressed Uncompressed is true, not false.
+ * @return size
+ */
+ public long getTotalSizeWithDepends(PackageSet pkgs, boolean isUncompressed) {
+ return packageManager.getTotalSizeOfInstallablePackages(pkgs, isUncompressed);
+ }
+
+ /**
+ * Get installed path.
+ * @return Installed target path
+ */
+ public String getInstalledPath() {
+ return Registry.getInstalledPath();
+ }
+
+ public String getInstallPath() {
+ String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getInstallPath();
+ return path;
+ }
+
+ public String getSDKWorkSpacePath() {
+ String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getSDKWorkSpacePath();
+ return path;
+ }
+
+
+ /**
+ * Check to exist package which can install or remove.
+ * @return There are packages to install or remove, return true. if not false.
+ */
+ public boolean existInstallableOrRemovablePackages() {
+ PackageSet rmPkgs = new PackageSet();
+ rmPkgs = getRemovablePackageList();
+ PackageSet insPkgs = getInstallableOrUpdatableMetaPackages();
+
+ if (rmPkgs != null && insPkgs != null) {
+ if (!rmPkgs.isEmpty() || !insPkgs.isEmpty()) {
+ Log.log("existInstallableOrRemovablePackages() is true.");
+ return (getRemovablePackageList().size() > 0 || getInstallableOrUpdatableMetaPackages().size() > 0);
+ } else {
+ Log.err("Both Removable Package List and Installable or Updatable Meta Packages are empty");
+ return false;
+ }
+ } else {
+ Log.err("Both Removable Package List and Installable or Updatable Meta Packages are null");
+ return false;
+ }
+ }
+
+ /**
+ * Check to exist package which can install or update.
+ * @return There are packages to install or remove, return true. if not false.
+ */
+ public boolean existInstallableOrUpdatablePackages() {
+ PackageSet ps = getInstallablePackageListInSnapshot();
+
+ if (ps != null) {
+ if (Options.snapshot || Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {
+ return (ps.size() > 0);
+ } else {
+ return (ps.size() > 0);
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Get Install configure.
+ * @return configure object.
+ */
+ public Config getConfig() {
+ return installManager.getConfig();
+ }
+
+ /**
+ * Get description of package.
+ * @param pkgName
+ * @return decription of package.
+ */
+ public String getDescription(String pkgName) {
+ Package pkg = packageManager.getPackageByName(pkgName);
+
+ if (pkg == null) {
+ return "";
+ } else {
+ return pkg.getDescription();
+ }
+ }
+
+ /**
+ * Check to exist files in target directory.
+ * @param targetDir is installed directory.
+ * @return If there are files in directory, return true. if not false.
+ */
+ public boolean existFilesInTargetDirectory(String targetDir) {
+ File targetFile = new File(targetDir);
+
+ if (!targetFile.exists()) {
+ return false;
+ }
+
+ File[] targetFileList = targetFile.listFiles();
+ if (targetFileList == null || targetFileList.length <= 0) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Remove file or directory from parameter
+ * @param targetPath
+ */
+ public void removeTargetPath(String targetPath) {
+ PathUtil.remove(targetPath);
+ }
+
+ /**
+ * save information of server.
+ * @param repository Base-repository of sdk. if repository is null, it do not save repository.
+ * @param type type of repository. if type is null, it do not save type.
+ * @param packageServer package server of sdk. if packageServer is null, it do not save packageServer.
+ * @param packageType set ServerType.snapshot or ServerType.package. if serverType is null, it do not save serverType.
+ */
+ 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();
+ }
+
+ /**
+ * Check the environment of ubuntu.
+ * @return If true, this is unity panel service.
+ */
+ public boolean isUnityEnvironment() {
+ String command = "ps -ax";
+
+ try {
+ LinuxShellRunningProgramParser parser = new LinuxShellRunningProgramParser();
+ int ret = ShellUtil.execute(command, parser);
+
+ if (ret != 0 ){
+ return false;
+ } else {
+ for (ProcessInformation pInfo : parser.getProcessInformation()) {
+ if (pInfo.getCommand().contains("unity-panel-service")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ } catch (IMShellCommandFail e) {
+ Log.ExceptionLog(e);
+ return false;
+ }
+ }
+
+ public PackageSet getConflictPackages(PackageSet pkgs) {
+ PackageSet pkgSet = packageManager.getDependsPackagesFromRepository(pkgs);
+ return packageManager.getConflictPackages(pkgSet);
+ }
+
+ public PackageSet getCauseOfConflict(PackageSet checkedPackages, Package conflictPackage) {
+ PackageSet causePackages = new PackageSet();
+
+ for (Package pkg : checkedPackages) {
+ if (packageManager.conflictPackages(pkg).contains(conflictPackage)) {
+ causePackages.add(pkg);
+ }
+ }
+
+ return causePackages;
+ }
+
+ public void showChangeLog() {
+ if (Documents.isChecked()) {
+ Documents.showChangeLog(); // show the change log(history)
+ }
+ }
+
+ public void cleanUpTargetDirectory() {
+ Log.log("Clean up the target directory => " + Registry.getInstalledPath());
+ if (packageManager == null || packageManager.getInstalledPackages().isEmpty()) {
+ String targetPath = Config.getInstance().getTargetDir();
+
+ if (targetPath.isEmpty()) {
+ return;
+ } else {
+ removeTargetPath(targetPath);
+ }
+ }
+ }
+
+ public boolean canInstallManagerUpdate() {
+ Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
+
+ if (pkg == null) {
+ return false;
+ }
+ String version = Config.getInstance().getCurrentConfigFile().getInstallManagerVersion();
+
+ Log.log("Current InstallManager version => " + version);
+ if (version == null || version.isEmpty()) {
+ return true;
+ }
+
+ Log.log("Update version => " + pkg.getVersion().toString());
+ if (Version.compareTo(new Version(version), pkg.getVersion()) < 0) {
+ Log.log("Update version is higher than current version. So, installmanager will be updated.");
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isInstalledInstallManager() {
+ Package installedPackage = packageManager.getInstalledPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
+
+ if (installedPackage != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean updateInstallManager() {
+ Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
+
+ if (pkg == null) {
+ return false;
+ }
+
+ if (installInstallManagerToTemp()) {
+ Log.log("## Success to update the InstallManager, and restart now.");
+ System.out.println("## Success to update the InstallManager, and restart now.");
+
+ runNewInstallManager();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean installInstallManagerToTemp() {
+ String imPackage = downloadInstallManager();
+ if (imPackage == null) {
+ return false;
+ }
+
+ if (extractIMPackage(imPackage)) {
+ Log.log("Success to extract updatable InstallManager.");
+ runNewInstallManager();
+ return true;
+ } else {
+ Log.err("Fail to extract updatable InstallManager. Cannot execute it.");
+ return false;
+ }
+ }
+
+ private String downloadInstallManager() {
+ Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
+
+ 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 {
+ return null;
+ }
+ } catch (IMNetworkConnectException e) {
+ Log.ExceptionLog(e);
+ return null;
+ } catch (IMNetworkDownloadException e) {
+ Log.ExceptionLog(e);
+ return null;
+ }
+ } else {
+ Log.err("Cannot download installmanager package.");
+ return null;
+ }
+ }
+
+ private boolean extractIMPackage(String imPath) {
+ removeIMBinaryInTemp();
+
+ SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();
+ long size = format.unZip(imPath, PathUtil.getTempDir(), null);
+
+ if (size > 0) {
+ return true;
+ } else {
+ throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
+ }
+ }
+
+ private void removeIMBinaryInTemp() {
+ String tempDir = PathUtil.getTempDir();
+
+ File tempDirFile = new File(tempDir);
+
+ for (File childFile : tempDirFile.listFiles()) {
+ if (isIMBinary(childFile.getName())) {
+ if (!childFile.delete()) {
+ Log.err("Cannot delete " + childFile.getAbsolutePath());
+ }
+ }
+ }
+ }
+
+ private boolean isIMBinary(String fileName) {
+ if (fileName.equals(InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME)){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void runNewInstallManager() {
+ File tempIMJarFile = new File(PathUtil.get(
+ PathUtil.getTempDir(), "data", "install-manager",
+ InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME));
+
+ if (tempIMJarFile.exists()) {
+ try {
+ ArrayList<String> commands = new ArrayList<String>();
+
+ String javaHome = System.getProperty("java.home");
+ File java = null;
+ if (Platform.isLinux() || Platform.isMacOS()) {
+ java = new File(PathUtil.get(javaHome, "bin", "java"));
+ } else if (Platform.isWindows()) {
+ java = new File(PathUtil.get(javaHome, "bin", "java.exe"));
+ } else {
+ throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
+ }
+
+ String forceBitOption = "-d" + System.getProperty("sun.arch.data.model");
+
+ String jarPath = PathUtil.get(tempIMJarFile.getAbsolutePath());
+ if (java.exists()) {
+ commands.add(java.getAbsolutePath());
+ } else {
+ commands.add("java");
+ }
+
+ if (Platform.isMacOS()) {
+ commands.add("-XstartOnFirstThread");
+ }
+
+ commands.add(forceBitOption);
+ commands.add("-jar");
+ commands.add(jarPath);
+
+ if (Options.executablePath != null) {
+ commands.add("-path");
+ commands.add(Options.executablePath);
+ }
+
+ String repo = Config.getInstance().getConfigFile().getRepository();
+ if (repo != null && !repo.isEmpty()) {
+ commands.add("-repository");
+ commands.add(repo);
+ }
+
+ String dist = Config.getInstance().getConfigFile().getDistribution();
+ if (dist != null && !dist.isEmpty()) {
+ commands.add("-distribution");
+ commands.add(dist);
+ }
+
+ String proxyHost = Config.getInstance().getConfigFile().getProxyHost();
+ int proxyPort = Config.getInstance().getConfigFile().getProxyPort();
+ if (proxyHost != null && !proxyHost.isEmpty()) {
+ if (proxyPort > 0) {
+ commands.add("-proxy");
+ commands.add(proxyHost + ":" + proxyPort);
+ }
+ }
+
+ 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);
+
+ ProcessBuilder pb = new ProcessBuilder(commands);
+ pb.directory(tempIMJarFile.getParentFile());
+ pb.start();
+
+ System.exit(0);
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ return;
+ }
+ }
+ }
+ }