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;
public boolean updateInstallManager() {
Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
-
+
if (pkg == 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;
}
}
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);
}
private boolean isIMBinary(String fileName) {
- if (fileName.equals(InstallManagerConstants.INSTALLMANAGER_BINARY_NAME)){
+ if (fileName.equals(InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME)){
return true;
} else {
return false;
}
private void runNewInstallManager() {
- File tempDirFile = new File(PathUtil.get(PathUtil.getTempDir(), "data", "install-manager"));
-
- for (File childFile : tempDirFile.listFiles()) {
- if (isIMBinary(childFile.getName())) {
- try {
- String cmd = ShellUtil.addInterpreter(childFile.getAbsolutePath());
- ProcessBuilder pb = new ProcessBuilder(ShellUtil.stringToken(cmd));
- pb.directory(tempDirFile);
- pb.start();
-
- System.exit(0);
- } catch (IOException e) {
- Log.ExceptionLog(e);
- return;
+ 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"));
+ }
+
+ 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 (repo != null & !repo.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);
+ }
+ }
+
+ 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;
}
}
}