* Shihyun Kim <shihyun.kim@samsung.com>
* Taeyoung Son <taeyoung2.son@samsung.com>
* Yongsung kim <yongsung1.kim@samsung.com>
+* @author Moonkyu Kang <moonkyu82.kang@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* This class works for command line installation.
* @author Yongsung Kim <yongsung1.kim@samsung.com>
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
*/
public class CliInstall {
private static final String DISTRIBUTION_INFO = "distribution.info";
return false;
}
}
+ // kmk -add download package function 2014/06/13
+ public static boolean downloadOnConsole(List<String> packageNames) throws IMExitException {
+ System.out.println("");
+ System.out.println("*******************************************");
+ System.out.println("******** Start package downloading ********");
+ System.out.println("*******************************************");
+
+ PackageManager pm = PackageManager.getInstance();
+
+ String targetDir = getTargetDir();
+
+ if (packageNames.contains("all")) {
+ if (checkAvailableSize(getAllPackages(), targetDir)) {
+ Log.log("Installmanager will download all packages.");
+ return downloadPackages(getAllPackages(), targetDir);
+ }
+ } else if (!validateDownloadPkgs(pm, packageNames)) {
+ return false;
+ }
+
+ PackageSet downloadPkgs = pm.getPackagesByNames(packageNames);
+
+ if (checkAvailableSize(downloadPkgs, targetDir)) {
+ return downloadPackages(downloadPkgs, targetDir);
+ } else {
+ return false;
+ }
+
+ }
+
+ // kmk -add download package function 2014/06/13
+ private static boolean downloadPackages(PackageSet downloadPkgs, String targetDir)
+ throws IMExitException {
+ // download packages from repository
+ for (int i = NETWORK_RETRY_COUNT; i > 0; i--) {
+ try {
+ for (Package pkg : downloadPkgs) {
+ if (!InstallManager.getInstance().downloadPackage(pkg,
+ PathUtil.addURLPath(targetDir, pkg.getFileName()), null)) {
+ Log.err("Fail to download package. ==> " + pkg);
+ return false;
+ }
+ }
+ return true;
+ } catch (IMNetworkException e) {
+ Log.ExceptionLog(e);
+ ErrorController.setNetworkRetryCount(NETWORK_RETRY_COUNT - i + 1);
+ System.out.println("Network error has occured. retry the download => " + (NETWORK_RETRY_COUNT - i + 1));
+ continue;
+ }
+ }
+ return false;
+ }
+ // kmk -add download package function 2014/06/13
+ private static boolean validateDownloadPkgs(PackageManager pm, Collection<String> pkgNames) {
+ ArrayList<String> wrongNames = new ArrayList<String>();
+
+ for (String name : pkgNames) {
+ Package pkg = pm.getPackageByName(name);
+ if (pkg == null) {
+ wrongNames.add(name);
+ }
+ }
+
+ if (wrongNames.isEmpty()) {
+ Log.log("All input packages are valid.");
+ return true;
+ } else {
+ Log.err("Wrong input package name(s) : " + wrongNames);
+ System.out.println("Wrong input package name(s) : " + wrongNames);
+ return false;
+ }
+ }
+
+
/**
* Get installable meta packages which are filtered by installed, updatable and installable.
return result;
}
}
-
-
+ // kmk -add download package function 2014/06/13
+ public static boolean cliDownload(List<String> packageNames) throws IMExitException {
+ CliInstall.refresh(); // Refresh installation environment.
+
+ if (!CliInstall.validateRepository(true)) {
+ return false;
+ }
+
+ boolean result = false;
+
+ if (CliInstall.downloadOnConsole(packageNames)) {
+ result = true;
+ Log.log("Success to download packages as cli.");
+ } else {
+ result = false;
+ Log.err("Fail to download packages as cli.");
+ }
+ return result;
+
+ }
public static void cliShowHelp() {
String executorTxt = "InstallManager.bin(exe, sh)";
public static Downloader getDownloader() {\r
return InstallManager.mDownloader;\r
}\r
+ \r
+ \r
+ // kmk -add download package function 2014/06/13\r
+ /**\r
+ * Download package.\r
+ * \r
+ * @param packageToDownload\r
+ * @param fileDownloadTargetPath\r
+ * @param monitor\r
+ * @return <code>true</code> if success\r
+ */\r
+ public boolean downloadPackage(Package packageToDownload,\r
+ String fileDownloadTargetPath, IIMProgressMonitor monitor) throws IMNetworkException{\r
+ Log.log("Download package '" + packageToDownload + "'");\r
+\r
+ if (packageToDownload == null || fileDownloadTargetPath == null\r
+ || fileDownloadTargetPath.isEmpty()) {\r
+ Log.err("InstallManager.downloadPackage(): Invalid package: "\r
+ + packageToDownload + ": This might be a bug of IM");\r
+ throw new IMFatalException(\r
+ ErrorCode.PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL);\r
+ }\r
+\r
+ // Check cache foler\r
+ if (existInCacheFolder(packageToDownload, fileDownloadTargetPath, monitor)) {\r
+ if (monitor != null) {\r
+ if (monitor.isCanceled()) {\r
+ throw new IMFatalException(ErrorCode.CANCEL);\r
+ } else {\r
+ monitor.workedDownloadSize(packageToDownload.getPackageSize());\r
+ //monitor.workedChecksum();\r
+ }\r
+ }\r
+ Log.log("Found in cache");\r
+\r
+ return true;\r
+ }\r
+\r
+ // TODO : refactoring.\r
+ long size = 0;\r
+ if (Options.onlyDownload || Options.downloadPackage) {\r
+ System.out.print("Downloading package => " + packageToDownload + " .......");\r
+ }\r
+ Log.log("start download package: " + packageToDownload);\r
+ URL packageUrl = packageToDownload.getURL();\r
+ \r
+ if (monitor != null) {\r
+ //monitor.workedDownload(packageToDownload.getPackageName());\r
+ monitor.workedTitle(packageToDownload.getPackageName());\r
+ }\r
+ size = mDownloader.download(packageUrl, fileDownloadTargetPath,\r
+ monitor);\r
+ \r
+ if (size >= 0) {\r
+ if (Options.onlyDownload || Options.downloadPackage) {\r
+ System.out.println(" done.");\r
+ }\r
+ Log.log("finish download");\r
+ } else { \r
+ Log.err("download failed => " + packageToDownload.getURL());\r
+ \r
+ PathUtil.remove(fileDownloadTargetPath);\r
+ \r
+ String errMsg = "";\r
+ \r
+ if (monitor != null) {\r
+ if (monitor.isCanceled()) {\r
+ errMsg = ErrorController.getErrorMessage();\r
+ } else {\r
+ errMsg = "Fail to get '" + \r
+ packageToDownload.getPackageName() + "'." +\r
+ "\n(" + ErrorController.getErrorMessage() + ")";\r
+ }\r
+ throw new IMFatalException(errMsg); \r
+ } else {\r
+ Log.err("monitor is null.");\r
+ }\r
+ }\r
+\r
+ if (Options.doPackageValidation) {\r
+ Log.log("Validate package");\r
+ if (!checkPackageSize(packageToDownload, size)) {\r
+ Log.err("The expected size of package => " + packageToDownload.getPackageSize());\r
+ Log.err("Package size error. downloaded size => " + size);\r
+ \r
+ PathUtil.remove(fileDownloadTargetPath);\r
+ \r
+ throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);\r
+ }\r
+\r
+ // TODO :\r
+ if (!checkFileChecksum(packageToDownload,\r
+ mDownloader.getFileChecksum())) {\r
+ Log.err("The expected checksum of package => " + packageToDownload.getSHA256());\r
+ Log.err("Package checksum error downloaded checksum => "\r
+ + mDownloader.getFileChecksum());\r
+ \r
+ PathUtil.remove(fileDownloadTargetPath);\r
+ \r
+ throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);\r
+ }\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
}\r
\r
// kmk - added options for extra\r
public static boolean doShowExtra = false;\r
- \r
+ \r
// kmk - object for ExtraPackage\r
private static ExtraOptions extraOptions = new ExtraOptions();\r
public static ExtraOptions getExtraOptions() {\r
return extraOptions;\r
}\r
\r
+ // kmk -add download package function 2014/06/13\r
+ /**\r
+ * Download specific package\r
+ */\r
+ public static boolean downloadPackage = false;\r
+ \r
+ \r
\r
/**\r
* Parses command line arguments and sets corresponding options. \r
}else{\r
extraOptions.setMode(EXTRA_MODE.LIST);\r
} \r
+ }else if (arg.equals("-download")) { // kmk -add download package function 2014/06/13\r
+ if (iter.hasNext()) {\r
+ downloadPackage = true;\r
+ workCliOptions(args);\r
+ } else {\r
+ Log.err("-download option must have some arguments.");\r
+ System.out.println("-install option must have some arguements" +\r
+ " such as any packages");\r
+ throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+ }\r
+ break;\r
}else {\r
Log.err("InstallManager do not support '" + arg + "' option");\r
throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
if (Options.onlyDownload) {\r
onlyDownloadPackages();\r
System.exit(0);\r
+ } else if (Options.downloadPackage) {\r
+ if (InstallManagerNoUI.cliDownload(Options.packages)) { // kmk -add download package function 2014/06/13\r
+ Log.log("Success to download packages. => " + Options.packages);\r
+ System.out.println("Success to download packages. => " + Options.packages);\r
+ } else {\r
+ Log.log("Fail to download packages. => " + Options.packages);\r
+ System.out.println("Fail to download packages. => " + Options.packages);\r
+ }\r
+ System.exit(0);\r
} else if (Options.doInstallNoUI) {\r
if (InstallManagerNoUI.cliInstall(Options.packages)) {\r
Log.log("Success to command line install.");\r