[Desc.] SDK image must be extracted before image installation by cli.
'-r' option support file protocol, absolute path and relative path.
'-x' option support proxy setting. (ex. proxy host(except
protocol):proxy port)
[Issue] redmine #9020, #9204
Change-Id: I3eac3a92a99094719d99115cd1882969f2761e22
import org.tizen.installmanager.lib.Log;
import org.tizen.installmanager.lib.Platform;
import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+import org.tizen.installmanager.lib.NetworkProxy.ProxyType;
import org.tizen.installmanager.lib.exception.IMNetworkException;
import org.tizen.installmanager.lib.linux.LinuxFileSystemInfo;
import org.tizen.installmanager.lib.win.WindowsFileSystemInfo;
private static ViewController controller = null;
+ private static ProxyType proxyType = ProxyType.AUTOMATIC;
+ private static String proxyHost = "";
+ private static String proxyPort = "";
+
/**
* Works for command line installation
* @return If installation successes, return true. otherwise return false.
* @throws IMExitException
*/
public static boolean installOnConsole(List<String> packageNames) throws IMExitException {
- if (!validateRepository()) {
- return false;
- }
-
- refresh(); // Refresh installation environment.
-
- if (!validateDistribution()) {
- return false;
- }
+ System.out.println("****************************************");
+ System.out.println("******** Start SDK installation ********");
+ System.out.println("****************************************");
PackageManager pm = PackageManager.getInstance();
* Validate repository url.
* @return If repository does not work or is not correct, return false. otherwise return true.
*/
- private static boolean validateRepository() {
+ public static boolean validateRepository(boolean isNetwork) {
URL serverUrl = null;
try {
- serverUrl = new URL(PathUtil.addURLPath(Options.repository, DISTRIBUTION_INFO));
+ if (isNetwork) {
+ serverUrl = new URL(PathUtil.addURLPath(Options.repository, DISTRIBUTION_INFO));
+ } else {
+ String packageList = PackageManager.getInstance().getPackageListFileName();
+ String repo = getReformedPath(Options.repository, true);
+ serverUrl = new URL(PathUtil.addURLPath(repo, packageList));
+ }
+
} catch (MalformedURLException e) {
// the URL is not in a valid form
ErrorController.setError(ErrorCode.WRONG_URL_FORMAT);
* Validate distribution.
* @return If can find input distribution in the distribution.info, return true. otherwise return false.
*/
- private static boolean validateDistribution() {
+ public static boolean validateDistribution() {
List<String> distributionList = DistributionController.getInstance().getDistributionList();
if (distributionList.contains(Options.distribution)) {
/**
* Refresh installation environment.
*/
- private static void refresh() {
+ public static void refresh() {
controller = new ViewController();
controller.init();
// Set config information as input data.
- Config.getInstance().saveSnapshotSettings(Options.repository, Options.distribution, Options.serverType, Options.snapshotPath);
+ if (Options.isNetwork) {
+ Config.getInstance().saveSnapshotSettings(Options.repository, Options.distribution, Options.serverType, Options.snapshotPath);
+ if (Options.proxy != null) {
+ parseProxy(Options.proxy);
+ Config.getInstance().saveProxySettings(proxyType, proxyHost, proxyPort);
+ }
+ } else {
+ String repo = getReformedPath(Options.repository, false);
+
+ Config.getInstance().saveSnapshotSettings(repo, Options.distribution, Options.serverType, Options.snapshotPath);
+ }
+
PackageManager.dispose();
initInstallManager();
}
/**
+ * Parsing proxy address.
+ * @param proxy
+ */
+ private static void parseProxy(String proxy) {
+ proxyType = ProxyType.MANUAL;
+ StringBuffer newProxyHost = new StringBuffer();
+ int idx = 0;
+ int length = proxy.length();
+
+ for (int i = 0; i < length; i++) {
+ char c = proxy.charAt(i);
+ if (c != ':') {
+ newProxyHost.append(c);
+ } else {
+ proxyHost = newProxyHost.toString();
+ idx = i;
+ break;
+ }
+ }
+
+ proxyPort = proxy.substring(idx+ 1, length);
+ }
+
+ /**
+ * InstallManager use different SDK image path(repository address)
+ * form when gets packages and saves configuration.
+ * So, SDK image path(repository address) needs to be reformed by usage.
+ * @param repository SDK image path
+ * @param additional If true, repository will be reformed by added string. otherwise removed string.
+ * @return Reformed SDK image path.
+ */
+ private static String getReformedPath(String repository, boolean additional) {
+ String repo = "";
+ if (additional) {
+ if (repository.startsWith("file")) {
+ repo = repository;
+ } else if (repository.startsWith("~")) {
+ repo = repository.substring(1);
+ repo = PathUtil.get("file://", System.getProperty("user.home"), repo);
+ } else if (repository.startsWith("/")) {
+ repo = PathUtil.get("file://", repository);
+ } else {
+ Log.err("Not support url prefix.");
+ }
+ } else {
+ if (repository.startsWith("file")) {
+ repo = repository.substring(7);
+ } else if (repository.startsWith("~")) {
+ repo = repository.substring(1);
+ repo = PathUtil.get(System.getProperty("user.home"), repo);
+ } else if (repository.startsWith("/")) {
+ repo = repository;
+ } else {
+ Log.err("Not support url prefix.");
+ }
+ }
+
+ return repo;
+ }
+
+ /**
* init IM's configuation and packages information.
* @return
*/
* @throws IMExitException
*/
public static boolean removeOnConsole(List<String> packageNames) throws IMExitException {
+ System.out.println("****************************************");
+ System.out.println("******* Start SDK uninstallation *******");
+ System.out.println("****************************************");
+
ViewController controller = new ViewController();
controller.init();
import org.tizen.installmanager.core.Config;
import org.tizen.installmanager.core.IMExitException;
import org.tizen.installmanager.core.Options;
+import org.tizen.installmanager.core.Config.ServerType;
import org.tizen.installmanager.lib.Log;
import org.tizen.installmanager.lib.Registry;
* @author Yongsung Kim <yongsung1.kim@samsung.com>
*/
public class InstallManagerNoUI {
-
+
public static boolean cliInstall(List<String> packageNames) throws IMExitException {
+ if (Options.isNetwork) {
+ return cliNetworkInstall(packageNames);
+ } else {
+ return cliImageInstall(packageNames);
+ }
+ }
+
+ public static boolean cliImageInstall(List<String> packageNames) throws IMExitException {
+ if (Registry.getInstalledPath() != "") {
+ List<String> all = new ArrayList<String>();
+ all.add("all");
+ if (cliUninstall(all)) {
+ Log.log("Success to remove installed SDK because of SDK image installation.");
+ } else {
+ Log.err("Fail to remove all installed SDK because of SDK image installation.");
+ }
+ }
+
+ CliInstall.refresh(); // Refresh installation environment.
+
+ if (!CliInstall.validateRepository(false)) {
+ return false;
+ }
+
+ boolean result = false;
+
+ if (CliInstall.installOnConsole(packageNames)) {
+ result = true;
+ Log.log("Success to install SDK as cli.");
+ } else {
+ result = false;
+ Log.err("Fail to install SDK as cli.");
+ }
+ return result;
+ }
+
+ public static boolean cliNetworkInstall(List<String> packageNames) throws IMExitException {
if (Registry.getInstalledPath() != "") {
String installRepo = Config.getInstance().getConfigFile().getRepository();
String installDist = Config.getInstance().getConfigFile().getDistribution();
String remoteRepo = Options.repository;
String remoteDist = Options.distribution;
+ ServerType serverType = Config.getInstance().getConfigFile().getServerType();
- if (!installRepo.equalsIgnoreCase(remoteRepo) || !installDist.equalsIgnoreCase(remoteDist)) {
+ if (!installRepo.equalsIgnoreCase(remoteRepo) || !installDist.equalsIgnoreCase(remoteDist)
+ || serverType == ServerType.LOCAL) {
List<String> all = new ArrayList<String>();
all.add("all");
System.out.println("* Repository or distribution are changed. " +
Log.err("Fail to remove all installed packages before install new packages.");
}
}
- }
+ }
- boolean result = false;
+ CliInstall.refresh(); // Refresh installation environment.
- System.out.println("****************************************");
- System.out.println("******** Start SDK installation ********");
- System.out.println("****************************************");
+ if (!CliInstall.validateRepository(true)) {
+ return false;
+ }
+
+ if (!CliInstall.validateDistribution()) {
+ return false;
+ }
+
+ boolean result = false;
if (CliInstall.installOnConsole(packageNames)) {
result = true;
}
public static boolean cliUninstall(List<String> packageNames) throws IMExitException {
- boolean result = false;
-
- System.out.println("****************************************");
- System.out.println("******* Start SDK uninstallation *******");
- System.out.println("****************************************");
-
- if (CliUninstall.removeOnConsole(packageNames)) {
- result = true;
- Log.log("Success to uninstall SDK as cli.");
+ if (Registry.getInstalledPath() == "") {
+ System.out.println("Tizen SDK was not installed.");
+ return false;
} else {
- result = false;
- Log.err("Fail to uninstall SDK as cli.");
+ boolean result = false;
+
+ if (CliUninstall.removeOnConsole(packageNames)) {
+ result = true;
+ Log.log("Success to uninstall SDK as cli.");
+ } else {
+ result = false;
+ Log.err("Fail to uninstall SDK as cli.");
+ }
+ return result;
}
- return result;
}
public static void cliShowInstallInformation() {
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;
/**
public static boolean snapshot = false;
public static String repository = null;
+ public static String imageFilePath = null;
public static String snapshotPath = null;
public static ServerType serverType = null;
public static String distribution = null;
public static String targetDir = null;
+ public static boolean isNetwork = true;
+
public static List<String> packages = new ArrayList<String>();
/**
} else if(arg.equals("-install")) {
if (iter.hasNext()) {
doInstallNoUI = true;
- serverType = ServerType.SNAPSHOT;
workCliOptions(args);
} else {
Log.err("-install option must have some arguments.");
}
private static boolean validateArgs() {
- if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
- return true;
+ if (isNetwork) {
+ if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
} else {
- return false;
+ if (Options.repository != null && !Options.packages.isEmpty()) {
+ if (Platform.isWindows()) {
+ if (Options.repository.startsWith("file")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
}
}
while (argIter.hasNext()) {
if (argIter.next().equalsIgnoreCase("-r")) {
argIter.remove();
- Options.repository = argIter.next();
+ repository = argIter.next();
+ if (!repository.startsWith("http")) {
+ isNetwork = false;
+ serverType = ServerType.LOCAL;
+ } else {
+ serverType = ServerType.SNAPSHOT;
+ isNetwork = true;
+ }
argIter.remove();
}
}
-
+
// set target directory
argIter = argArray.iterator();
while (argIter.hasNext()) {
if (argIter.next().equalsIgnoreCase("-l")) {
argIter.remove();
- Options.targetDir = argIter.next();
+ targetDir = argIter.next();
argIter.remove();
}
}
while (argIter.hasNext()) {
if (argIter.next().equalsIgnoreCase("-d")) {
argIter.remove();
- Options.distribution = argIter.next();
+ distribution = argIter.next();
argIter.remove();
}
}
if (argIter.next().equalsIgnoreCase("-p")) {
argIter.remove();
while (argIter.hasNext()) {
- Options.packages.add(argIter.next());
+ packages.add(argIter.next());
argIter.remove();
}
}
}
- // set packages
+ // set proxy
argIter = argArray.iterator();
while (argIter.hasNext()) {
if (argIter.next().equalsIgnoreCase("-x")) {
argIter.remove();
while (argIter.hasNext()) {
Options.proxy = argIter.next();
+ Log.log("Use proxy setting => " + Options.proxy);
argIter.remove();
}
}
}
}
+
+ private static void exclusiveOptions(String option, Iterator<String> argIter) {
+ while (argIter.hasNext()) {
+ if (argIter.next().equalsIgnoreCase(option)) {
+ Log.err("[" + option + "] cannot be used.");
+ System.out.println("[" + option + "] cannot be used with some options.");
+ throw new IMFatalException("[" + option + "] cannot be used with some options.");
+ }
+ }
+ }
}
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;
*/
public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {
HashMap<String,List<PropertySection>> r2sMap = null;
+ ServerType serverType = Config.getInstance().getConfigFile().getServerType();
- if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // Using SDK Image
+ if (serverType == ServerType.LOCAL) { // Using SDK Image
r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);
} else {
r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);