From: donghee yang Date: Mon, 19 Nov 2012 17:09:34 +0000 (+0900) Subject: [Title] Supported "Cancel" when import/export/generate rootstrap X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f3b06f979d491b377ef03d04f13df868b2d9aeb;p=sdk%2Fide%2Fnativeplatform-eplugin.git [Title] Supported "Cancel" when import/export/generate rootstrap --- diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RootstrapManager.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RootstrapManager.java index e1457f7..1a479c4 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RootstrapManager.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RootstrapManager.java @@ -1,10 +1,8 @@ package org.tizen.nativeplatform.rootstrap; -import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; @@ -24,6 +22,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.tizen.common.core.application.InstallPathConfig; import org.tizen.nativecommon.build.SmartBuildInterface; @@ -31,8 +30,8 @@ import org.tizen.nativecommon.build.exception.SBIException; import org.tizen.nativecommon.build.model.Rootstrap; import org.tizen.nativecommon.build.model.SBIModel; import org.tizen.nativecommon.build.model.Target; -import org.tizen.nativeplatform.password.SudoPasswdManager; import org.tizen.nativeplatform.preferences.PreferencesManager; +import org.tizen.nativeplatform.util.CommandLauncher; import org.tizen.nativeplatform.views.model.PlatformRootstrap; import org.w3c.dom.Attr; import org.w3c.dom.Document; @@ -112,7 +111,11 @@ public class RootstrapManager { if ( rootstrap != null ) { rootstraps.remove( rootstrap ); removeSBIPluginXML( rootstrap ); - removeBaseFileSystem( rootstrap.getId() ); + try { + removeBaseFileSystem( rootstrap.getId() , rootstrap.getArch()); + } catch (InterruptedException e) { + // do nothing + } RootstrapManager.notifyChangedRootstrap(); return true; } @@ -123,8 +126,8 @@ public class RootstrapManager { public static boolean exportRootstrap( - PlatformRootstrap rootstrap, - String exportFilePath) { + PlatformRootstrap rootstrap, String exportFilePath, + IProgressMonitor monitor) throws InterruptedException { // make temp directory String tempDirPath = makeTempDirectory(); @@ -133,8 +136,8 @@ public class RootstrapManager { // zip file-system String basePath = rootstrap.getPath().removeLastSegments(1).toOSString(); String rootstrapID = rootstrap.getId(); - if( !commandWithSudo( String.format("cd %s;sudo -S tar cvzf %s/rootstrap.tar.gz %s", - basePath, tempDirPath, rootstrapID), "Platform Internal" ) ) { + if( !CommandLauncher.executeSudo( String.format("sudo -S tar cvzf %s/rootstrap.tar.gz %s", + tempDirPath, rootstrapID), basePath, "Platform Internal", monitor ) ) { return false; } @@ -142,13 +145,13 @@ public class RootstrapManager { String pluginFileName = rootstrap.getId() + ".xml"; String pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()) .append(pluginFileName).toOSString(); - if ( !commandWithSudo( String.format("cp %s %s/", pluginPath, tempDirPath ), null) ) { + if ( !CommandLauncher.executeSudo( String.format("cp %s %s/", pluginPath, tempDirPath )) ) { return false; } // zip them together - if ( !commandWithSudo( String.format("cd %s;tar cvf %s rootstrap.tar.gz %s", - tempDirPath, exportFilePath, pluginFileName), "Platform Internal" ) ) { + if ( !CommandLauncher.executeSudo( String.format("tar cvf %s rootstrap.tar.gz %s", + exportFilePath, pluginFileName), tempDirPath, "Platform Internal", monitor ) ) { return false; } @@ -156,12 +159,14 @@ public class RootstrapManager { } finally { // remove temporary directory - commandWithSudo( String.format("sudo -S rm -rf %s",tempDirPath), null ); + CommandLauncher.executeSudo( String.format("sudo -S rm -rf %s",tempDirPath) ); } } - public static PlatformRootstrap importRootstrap( String importFilePath) throws Exception { + public static PlatformRootstrap importRootstrap( String importFilePath, + IProgressMonitor monitor) throws InterruptedException { + PlatformRootstrap result = null; String pluginPath = null; String rootstrapPath = null; @@ -171,9 +176,9 @@ public class RootstrapManager { try { // extract "tar" archive - if( !commandWithSudo( String.format("cd %s;tar xvf %s", - tempDirPath, importFilePath), "Platform Internal" ) ) { - throw new Exception("Extracting rootsrap failed!"); + if( !CommandLauncher.executeSudo( String.format("tar xvf %s", + importFilePath), tempDirPath, "Platform Internal", monitor ) ) { + throw new InterruptedException("Extracting rootsrap failed!"); } // find rootstrap id @@ -191,7 +196,7 @@ public class RootstrapManager { } ); if ( xmlFiles.length == 0 ) { - throw new Exception("There is no SBI plugin file(*.xml)"); + throw new InterruptedException("There is no SBI plugin file(*.xml)"); } String pluginFilePath = xmlFiles[0].getPath().toString(); String pluginFileName = new File(pluginFilePath).getName(); @@ -199,13 +204,13 @@ public class RootstrapManager { // check already exist? if( RootstrapManager.getRootstrap(pluginId) != null ) { - throw new Exception("There already exists the rootrap with same id!"); + throw new InterruptedException("There already exists the rootrap with same id!"); } // copy xml pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()) .append(pluginFileName).toOSString(); - commandWithSudo( String.format("cp %s %s", pluginFilePath, pluginPath), null); + CommandLauncher.executeSudo( String.format("cp %s %s", pluginFilePath, pluginPath), null); // extracting file system String basePath = SmartBuildInterface.getInstance().getBaseRootstrapPath()+"/platform"; @@ -214,33 +219,37 @@ public class RootstrapManager { if ( !(baseDirDir.exists()) ) { baseDirDir.mkdir(); } - if ( !commandWithSudo( String.format("cd %s;sudo -S tar xvf %s/rootstrap.tar.gz", - basePath, tempDirPath), "Platform Internal" ) ) { - throw new Exception("Extracting rootsrap failed!"); + if ( !CommandLauncher.executeSudo( String.format("sudo -S tar xvf %s/rootstrap.tar.gz", + tempDirPath), basePath, "Platform Internal", monitor ) ) { + throw new InterruptedException("Extracting rootsrap failed!"); } SBIModel.reinitialize(); result = createRootstrapFromSBIPlugin( pluginId ); if ( result == null ) { - throw new Exception("Loading SBI plugin failed!"); + throw new InterruptedException("Loading SBI plugin failed!"); } return result; } catch (Exception e) { if ( pluginPath != null ) { - commandWithSudo( String.format("rm -rf %s", pluginPath), null ); - SBIModel.reinitialize(); + CommandLauncher.executeSudo( String.format("rm -rf %s", pluginPath), null ); + try { + SBIModel.reinitialize(); + } catch (SBIException e1) { + throw new InterruptedException(e1.getMessage()); + } } if ( rootstrapPath != null ) { - commandWithSudo( String.format("sudo -S rm -rf %s", rootstrapPath), null ); + CommandLauncher.executeSudo( String.format("sudo -S rm -rf %s", rootstrapPath), null ); } - throw e; + throw new InterruptedException(e.getMessage()); } finally { // remove temporary directory - commandWithSudo( String.format("sudo -S rm -rf %s",tempDirPath), null ); + CommandLauncher.executeSudo( String.format("sudo -S rm -rf %s",tempDirPath), null ); } } @@ -379,16 +388,16 @@ public class RootstrapManager { public static PlatformRootstrap generate(String name, String arch, - ArrayList reposURLs, boolean immediateGen) { + ArrayList reposURLs, boolean immediateGen, + IProgressMonitor monitor) throws InterruptedException { boolean initialized = false; String id = name; if ( immediateGen ) { - if ( generateBaseFileSystem(id, arch, reposURLs) ) { + if ( generateBaseFileSystem(id, arch, reposURLs, monitor) ) { initialized = true; } else { - removeBaseFileSystem(id); return null; } } @@ -400,7 +409,7 @@ public class RootstrapManager { } else { if ( immediateGen ) { - removeBaseFileSystem(id); + removeBaseFileSystem(id, arch); } return null; } @@ -409,52 +418,78 @@ public class RootstrapManager { private static boolean generateBaseFileSystem(String id, String arch, - ArrayList reposURLs) { + ArrayList reposURLs, IProgressMonitor monitor) throws InterruptedException { - // remove temp directory if exist - if ( !commandWithSudo(String.format("sudo -S rm -rf %s", id), null) ) { - // this is for checking sudo password error - return false; - } - - // use rogen - String rogen = InstallPathConfig.getSDKPath()+"/tools/rogen/bin/rogen.rb"; - String baseArch = getBaseArchitecture(arch); - String urlData = ""; - for( String url: reposURLs ) { - urlData += (urlData.isEmpty() ? url : "," + url ); - } - - String command; - if ( PreferencesManager.isProxyUsed() ) { - String protocol = PreferencesManager.getProxyProtocol(); - String host = PreferencesManager.getProxyHost(); - int port = PreferencesManager.getProxyPort(); - String envSetup = String.format("%s_proxy=%s://%s:%d", protocol, protocol, host, port); - command = String.format( "%s %s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform", - envSetup, rogen, id, baseArch, urlData ); - } - else { - command = String.format( "%s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform", - rogen, id, baseArch, urlData ); + String tempDirPath = null; + try { + // make temp directory + tempDirPath = makeTempDirectory(); + + // use rogen + String rogen = InstallPathConfig.getSDKPath()+"/tools/rogen/bin/rogen.rb"; + String baseArch = getBaseArchitecture(arch); + String urlData = ""; + for( String url: reposURLs ) { + urlData += (urlData.isEmpty() ? url : "," + url ); + } + + String command; + if ( PreferencesManager.isProxyUsed() ) { + String protocol = PreferencesManager.getProxyProtocol(); + String host = PreferencesManager.getProxyHost(); + int port = PreferencesManager.getProxyPort(); + String envSetup = String.format("%s_proxy=%s://%s:%d", protocol, protocol, host, port); + command = String.format( "%s %s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform", + envSetup, rogen, id, baseArch, urlData ); + } + else { + command = String.format( "%s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform", + rogen, id, baseArch, urlData ); + } + + if ( !CommandLauncher.executeSudo( command, tempDirPath, "Platform Internal", monitor) ) { + return false; + } + + // copy + String rootstrapBasePath = new File(getRootstrapPath(id)).getParent(); + CommandLauncher.executeSudo(String.format("sudo -S mkdir -p %s", rootstrapBasePath), tempDirPath); + CommandLauncher.executeSudo(String.format("sudo -S mv %/%s %s/", tempDirPath, id, rootstrapBasePath), tempDirPath); } - - if ( !commandWithSudo( command, "Platform Internal") ) { - return false; + finally { + if ( new File(tempDirPath).exists() ) { + // check sub-directory + String checkDir = String.format("%s/%s/local/scratch.%s.0/proc", tempDirPath, id, arch ); + if ( new File(checkDir).exists() ) { + CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir)); + } + checkDir = String.format("%s/%s/local/scratch.%s.0/dev/pts", tempDirPath, id, arch ); + if ( new File(checkDir).exists() ) { + CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir)); + } + + // remove + CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath)); + } } - - // copy - String rootstrapBasePath = new File(getRootstrapPath(id)).getParent(); - commandWithSudo(String.format("sudo -S mkdir -p %s", rootstrapBasePath), null); - commandWithSudo(String.format("sudo -S mv %s %s/", id, rootstrapBasePath), null); - + return true; } - private static void removeBaseFileSystem( String id ) { + private static void removeBaseFileSystem( String id, String arch ) throws InterruptedException { String path = getRootstrapPath( id ); - commandWithSudo( String.format("sudo -S rm -rf %s", path), null ); + // check sub-directory + String checkDir = String.format("%s/local/scratch.%s.0/proc", path, arch ); + if ( new File(checkDir).exists() ) { + CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir)); + } + checkDir = String.format("%s/local/scratch.%s.0/dev/pts", path, arch ); + if ( new File(checkDir).exists() ) { + CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir)); + } + + CommandLauncher.executeSudo( String.format("sudo -S rm -rf %s", path), null ); } @@ -468,62 +503,6 @@ public class RootstrapManager { } - private static boolean commandWithSudo( String command, String consoleName ) { - String passwd = SudoPasswdManager.getSudoPassword(); - try { - // create expect script file - File expectScript = new File("/tmp/run_sudo.exp"); - expectScript.createNewFile(); - BufferedWriter bw = new BufferedWriter(new FileWriter(expectScript)); - bw.write("#!/usr/bin/expect --");bw.newLine(); - bw.write(String.format("spawn sh -c \"%s;echo \\$? > /tmp/exit-status\"",command));bw.newLine(); - bw.write("while (1) {");bw.newLine(); - bw.write(" expect {");bw.newLine(); - bw.write(" \"password for\" {");bw.newLine(); - bw.write(String.format("send \"%s\\r\"", passwd));bw.newLine(); - bw.write(" }");bw.newLine(); - bw.write(" eof {");bw.newLine(); - bw.write(" return");bw.newLine(); - bw.write(" }");bw.newLine(); - bw.write(" }");bw.newLine(); - bw.write("}");bw.newLine(); - bw.close(); - expectScript.setExecutable(true); - - File shellScript = new File("/tmp/run_sudo.sh"); - shellScript.createNewFile(); - bw = new BufferedWriter(new FileWriter(shellScript)); - bw.write("#!/bin/sh -ee");bw.newLine(); - bw.write("/tmp/run_sudo.exp");bw.newLine(); - bw.write("EXIT_CODE=`cat /tmp/exit-status`");bw.newLine(); - bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");bw.newLine(); - bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");bw.newLine(); - bw.write(" exit 1");bw.newLine(); - bw.write("fi");bw.newLine(); - bw.close(); - shellScript.setExecutable(true); - - // execute script - String scriptCommand = shellScript.getPath(); - if (consoleName != null && !consoleName.isEmpty() ) { - SmartBuildInterface.getInstance().commandConsole(scriptCommand, "/tmp", consoleName); - } - else { - SmartBuildInterface.getInstance().command(scriptCommand, "/tmp"); - } - } - catch (IOException e) { - e.printStackTrace(); - return false; - } catch (SBIException e) { - e.printStackTrace(); - return false; - } - - return true; - } - - public static boolean generateSBIPluginXML( String id, String name, String arch, ArrayList reposURLs) { diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncher.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncher.java new file mode 100644 index 0000000..634f56e --- /dev/null +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncher.java @@ -0,0 +1,237 @@ +package org.tizen.nativeplatform.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Field; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.tizen.common.ui.view.console.ConsoleManager; +import org.tizen.common.util.HostUtil; +import org.tizen.nativeplatform.password.SudoPasswdManager; + +public class CommandLauncher { + public static boolean executeSudo(String command ) throws InterruptedException { + return executeSudo( command, null, null, null ); + } + + + public static boolean executeSudo(String command, String workingDir ) throws InterruptedException { + return executeSudo( command, workingDir, null, null ); + } + + + public static boolean executeSudo(String command, String workingDir, + String consoleViewName, IProgressMonitor monitor ) throws InterruptedException { + + // generate script + String scriptCmd = genSudoExecuteScript(command); + if ( scriptCmd == null ) { + throw new InterruptedException("Generating execution script failed!"); + } + + // start process + Process proc = createProcess( scriptCmd, workingDir ); + + // create monitor process + ProcessMonitorThread monitorThread = null; + if ( monitor != null ) { + monitorThread = new ProcessMonitorThread(proc, monitor); + monitorThread.start(); + } + + // handle console + if( consoleViewName != null ) { + ConsoleManager cm = new ConsoleManager( consoleViewName, true ); + cm.clear(); + BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream())); + String line = null; + try { + while((line=input.readLine())!=null){ + cm.println(line); + } + } catch (IOException e) { + // do nothing + } + } + proc.waitFor(); + if ( monitor != null ) { + monitorThread.join(); + if ( monitor.isCanceled() ) { + throw new InterruptedException("Command execution is canceled!"); + } + } + + // abnormal termination + if (proc.exitValue() != 0) { + return false; + } + else { + return true; + } + } + + + public static Process createProcess(String command, String workingDir ) throws InterruptedException { + // start process + String[] fullCommand = HostUtil.getCommand(command); + ProcessBuilder pb = new ProcessBuilder(); + pb.redirectErrorStream(true); + pb.command(fullCommand); + if(workingDir != null) { + pb.directory(new File(workingDir)); + } + Process proc; + try { + proc = pb.start(); + } catch (IOException e) { + throw new InterruptedException("Creating process failed!"); + } + + return proc; + } + + + // return generate script and return script path + private static String genSudoExecuteScript(String command) { + String passwd = SudoPasswdManager.getSudoPassword(); + File shellScript = null; + + try { + // create expect script file + File expectScript = new File("/tmp/run_sudo.exp"); + expectScript.createNewFile(); + BufferedWriter bw = new BufferedWriter(new FileWriter(expectScript)); + bw.write("#!/usr/bin/expect --");bw.newLine(); + bw.write(String.format("spawn sh -c \"%s;echo \\$? > /tmp/exit-status\"",command));bw.newLine(); + bw.write("while (1) {");bw.newLine(); + bw.write(" expect {");bw.newLine(); + bw.write(" \"password for\" {");bw.newLine(); + bw.write(String.format("send \"%s\\r\"", passwd));bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write(" eof {");bw.newLine(); + bw.write(" return");bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write("}");bw.newLine(); + bw.close(); + expectScript.setExecutable(true); + + shellScript = new File("/tmp/run_sudo.sh"); + shellScript.createNewFile(); + bw = new BufferedWriter(new FileWriter(shellScript)); + bw.write("#!/bin/sh -ee");bw.newLine(); + bw.write("/tmp/run_sudo.exp");bw.newLine(); + bw.write("EXIT_CODE=`cat /tmp/exit-status`");bw.newLine(); + bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");bw.newLine(); + bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");bw.newLine(); + bw.write(" exit 1");bw.newLine(); + bw.write("fi");bw.newLine(); + bw.close(); + shellScript.setExecutable(true); + } + catch (IOException e ) { + return null; + } + + // execute script + return shellScript.getPath(); + } + + + // return generate script and return script path + private static String genSudoKillProcessScript(Process process) { + String passwd = SudoPasswdManager.getSudoPassword(); + File shellScript = null; + + try { + // get process id + Field f = process.getClass().getDeclaredField("pid"); + f.setAccessible(true); + String pid = f.get(process).toString(); + + // create killtree script file + File killScript = new File("/tmp/killtree.sh"); + killScript.createNewFile(); + BufferedWriter bw = new BufferedWriter(new FileWriter(killScript)); + bw.write("#!/bin/sh");bw.newLine(); + bw.write("killtree() {");bw.newLine(); + bw.write(" local _pid=$1");bw.newLine(); + bw.write(" sudo kill -STOP ${_pid}");bw.newLine(); + bw.write(" for _child in $(ps -o pid --no-headers --ppid ${_pid}); do");bw.newLine(); + bw.write(" killtree ${_child}");bw.newLine(); + bw.write(" done");bw.newLine(); + bw.write(" sudo kill -KILL ${_pid}");bw.newLine(); + bw.write("}");bw.newLine(); + bw.write("killtree $1");bw.newLine(); + bw.close(); + killScript.setExecutable(true); + + // create expect script file + File expectScript = new File("/tmp/run_sudo2.exp"); + expectScript.createNewFile(); + bw = new BufferedWriter(new FileWriter(expectScript)); + bw.write("#!/usr/bin/expect --");bw.newLine(); + bw.write(String.format("spawn sh -c \"/tmp/killtree.sh %s\"",pid ));bw.newLine(); + bw.write("while (1) {");bw.newLine(); + bw.write(" expect {");bw.newLine(); + bw.write(" \"password for\" {");bw.newLine(); + bw.write(String.format("send \"%s\\r\"", passwd));bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write(" eof {");bw.newLine(); + bw.write(" return");bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write(" }");bw.newLine(); + bw.write("}");bw.newLine(); + bw.close(); + expectScript.setExecutable(true); + + shellScript = new File("/tmp/run_sudo2.sh"); + shellScript.createNewFile(); + bw = new BufferedWriter(new FileWriter(shellScript)); + bw.write("#!/bin/sh -ee");bw.newLine(); + bw.write("/tmp/run_sudo2.exp");bw.newLine(); + bw.close(); + shellScript.setExecutable(true); + + return shellScript.getPath(); + } + catch (Exception e ) { + return null; + } + } + + + static class ProcessMonitorThread extends Thread { + private Process process; + private IProgressMonitor monitor; + public ProcessMonitorThread(Process process, IProgressMonitor monitor) { + this.process = process; + this.monitor = monitor; + } + + + public void run() { + boolean sendSignal = false; + while( true ) { + try { + Thread.sleep(1000); // wait 1 sec + if ( !sendSignal && monitor.isCanceled() ) { + String killCmd = genSudoKillProcessScript( process ); + Process killProcess = createProcess( killCmd, null ); + killProcess.waitFor(); + sendSignal = true; + } + process.exitValue(); + break; + } + catch(Exception e) { + continue; + } + } + } + } +} diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapUIMessages.properties b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapUIMessages.properties index 13f42aa..de617d1 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapUIMessages.properties +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapUIMessages.properties @@ -30,7 +30,7 @@ GenRootDlg.Button.GenImmedate = Generate Immediately GenRootDlg.Progress.Msg.Generating = Generating rootstrap... GenRootDlg.Progress.Msg.Searching = Seaching repositories -GenRootDlg.Error.Fail.Generate = Failed to generate rootstrap +GenRootDlg.Error.Fail.Generate = Failed to generate rootstrap! GenRootDlg.Error.Empty.Snapshot = Snapshot URL is empty GenRootDlg.Error.Empty.Rootstrap = Rootstrap is empty GenRootDlg.Error.Snapshot.Failed = Getting snapshot information failed!\n @@ -51,6 +51,8 @@ Action.Msg.Info.ImportOK = Importing rootstrap is successful! Action.Msg.Error.ImportFailed = Importing rootstrap failed! Action.Msg.Progress.Initializing.PkgMgr = Initializing Package Manager... Action.Msg.Error.InitFailed.PkgMgr = Initializing Package Manager failed! +Action.Msg.Progress.Removing = Removing rootstrap... +Action.Msg.Error.RemoveFailed = Removing rootstrap failed! FileDlg.Title.Export = Export rootstrap FileDlg.Title.Import = Import rootstrap \ No newline at end of file diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapView.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapView.java index b555b20..85dba8d 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapView.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapView.java @@ -474,21 +474,22 @@ public class RootstrapView extends ViewPart { // generate rootstrap here ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { - dialog.run(true, false, new IRunnableWithProgress() { + dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Generating"), -1); generatedRootstrap = null; - generatedRootstrap = RootstrapManager.generate(rootstrapName, arch, repositoryURLs, immediateGen); + generatedRootstrap = RootstrapManager.generate(rootstrapName, arch, repositoryURLs, immediateGen, monitor); if ( generatedRootstrap == null ) { throw new InterruptedException(); } } }); } catch (Exception e1) { - e1.printStackTrace(); - DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Gen.Rootstrap.Failed") ); + DialogUtil.openErrorDialog(String.format("%s\n * %s", + resources.getString("GenRootDlg.Error.Gen.Rootstrap.Failed"), + e1.getMessage())); return; } @@ -511,7 +512,7 @@ public class RootstrapView extends ViewPart { // generate rootstrap here ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { - dialog.run(true, false, new IRunnableWithProgress() { + dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { @@ -519,7 +520,7 @@ public class RootstrapView extends ViewPart { monitor.beginTask(resources.getString("Action.Msg.Progress.Importing"), -1); generatedRootstrap = null; try { - generatedRootstrap = RootstrapManager.importRootstrap( selectedFilePath ); + generatedRootstrap = RootstrapManager.importRootstrap( selectedFilePath, monitor ); } catch (Exception e) { throw new InterruptedException(e.getMessage()); } @@ -615,9 +616,9 @@ public class RootstrapView extends ViewPart { } }); } catch (Exception e1) { - DialogUtil.openErrorDialog( - String.format("%s\n * %s", resources.getString("Action.Msg.Error.InitFailed.PkgMgr"), - e1.getMessage() ) ); + DialogUtil.openErrorDialog( String.format("%s\n * %s", + resources.getString("Action.Msg.Error.InitFailed.PkgMgr"), + e1.getMessage() ) ); return; } @@ -644,7 +645,7 @@ public class RootstrapView extends ViewPart { { Table table = tableViewer.getTable(); TableItem[] item = table.getSelection(); - PlatformRootstrap selected = (PlatformRootstrap)item[0].getData(); + final PlatformRootstrap selected = (PlatformRootstrap)item[0].getData(); // default rootstrap cannot be removed! PlatformRootstrap defaultRootstrap = RootstrapManager.getDefaultRootstrap( selected.getArch() ); @@ -655,7 +656,17 @@ public class RootstrapView extends ViewPart { IWorkspace works = ResourcesPlugin.getWorkspace(); IProject[] projs = works.getRoot().getProjects(); - for (final IProject proj : projs) { + for (IProject proj : projs) { + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(proj); + if ( info == null ) continue; + IConfiguration config = info.getDefaultConfiguration(); + if ( config == null ) continue; + IManagedProject managedProject = config.getManagedProject(); + String projectArtifactType = managedProject.getProjectType() != null ? + managedProject.getProjectType().getBuildArtefactType().getId() : null; + if ( managedProject == null || + projectArtifactType != PlatformConfigurationManager.TIZEN_PLATFORM_ARTIFACT_TYPE) continue; + setActiveRootstrap( proj, defaultRootstrap ); } @@ -703,11 +714,13 @@ public class RootstrapView extends ViewPart { // generate rootstrap here ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { - dialog.run(true, false, new IRunnableWithProgress() { + dialog.run(true, true, new IRunnableWithProgress() { @Override - public void run(IProgressMonitor monitor) { + public void run(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + monitor.beginTask(resources.getString("Action.Msg.Progress.Exporting"), -1); - boolean result = RootstrapManager.exportRootstrap( selectedRootstrap, selectedFilePath ); + boolean result = RootstrapManager.exportRootstrap( selectedRootstrap, selectedFilePath, monitor ); if ( result ) { DialogUtil.openMessageDialog(shell,resources.getString("Action.Msg.Info.ExportOK")); } @@ -717,8 +730,9 @@ public class RootstrapView extends ViewPart { } }); } catch (Exception e1) { - e1.printStackTrace(); - DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Gen.Rootstrap.Failed") ); + DialogUtil.openErrorDialog( String.format("%s\n * %s", + resources.getString("Action.Msg.Error.ExportFailed"), + e1.getMessage() ) ); return; } }