All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC refactor 00/21] Merging windows-build with master
@ 2013-06-05 17:00 Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 01/21] Fix ShellSession execute Ioana Grigoropol
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- 3rd batch of refactoring & merging windows-build with master
- applies on top of the second batch of 8 patches
- still one more class to refactor(OptionsPage)

Ioana Grigoropol (21):
  Fix ShellSession execute
  Remove shell type from ShellSession constructor
  Use / as separator  instead of OS separator
  Remove unsed methods & inner classes from ShellSession
  Save active connection for Bitbake recipe
  Initialize and store the connection on Recipe Wizard
  Store connection for recipe in Recipe Wizard Page
  Refactor Wizard Page fields to have consistent names
  Refactor populate method name
  Break handlePopulate into remote and local functions
  Use uri instead of string to determine location of recipe & determine
    archive type
  Store metadata location as URI instead of String
  Refactor Recipe Wizard Page to use Remote target Api
  Run all Recipe task in wizard container
  Enable Populate button when src URI changes
  Store reference to OptionsPage in InstallWizard
  Collect Bitbake error lines
  Refactor Bitbake wizard to use RemoteHelper API
  Retrieve console from RemoteHelper instead of recreating it
  Remove LongRunningTask,ICalculatePercentage from InstallWizard
  Create separated class for ConsoleWriter

 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    4 +-
 .../src/org/yocto/bc/bitbake/BBSession.java        |   10 +
 .../src/org/yocto/bc/bitbake/ShellSession.java     |  138 ++---
 .../org/yocto/bc/remote/utils/ConsoleWriter.java   |   36 ++
 .../bc/remote/utils/YoctoRunnableWithProgress.java |  211 ++++++++
 .../src/org/yocto/bc/ui/Activator.java             |    2 +-
 .../bc/ui/editors/bitbake/BitBakeFileEditor.java   |    1 +
 .../bc/ui/wizards/BitbakeRecipeUIElement.java      |   15 +-
 .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java  |   41 +-
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |  528 +++++++++++---------
 .../yocto/bc/ui/wizards/install/InstallWizard.java |  275 +++-------
 .../BBConfigurationInitializeOperation.java        |   23 +-
 12 files changed, 710 insertions(+), 574 deletions(-)
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java

-- 
1.7.9.5



^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC refactor 01/21] Fix ShellSession execute
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 02/21] Remove shell type from ShellSession constructor Ioana Grigoropol
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- use ICommandResponseHandler to write to the console, and in particular CommandResponseHandler implementation
	- discard all Writer usages since they are no longer needed
- use RemoteHelper implementation to source the environment for bitbake
	 - make sure to disable sanity checkes before sourcing in order to avoid unwanted errors
	 - export the number of columns used for the shell, otherwise the lines will be automatically splitted at a default size(80 characters)
	 - before running any command, make sure to source the environment since each command will be ran in a different terminal

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/bc/bitbake/ShellSession.java     |  104 ++++++++------------
 .../src/org/yocto/bc/ui/Activator.java             |    2 +-
 2 files changed, 43 insertions(+), 63 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
index 129d1d9..e8ed384 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
@@ -18,10 +18,14 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.Writer;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.rse.core.model.IHost;
 import org.eclipse.rse.services.files.IHostFile;
 import org.yocto.bc.ui.model.ProjectInfo;
 import org.yocto.remote.utils.ICommandResponseHandler;
 import org.yocto.remote.utils.RemoteHelper;
+import org.yocto.remote.utils.YoctoCommand;
 
 /**
  * A class for Linux shell sessions.
@@ -43,6 +47,10 @@ public class ShellSession {
 	 */
 	public static final String TERMINATOR = "#234o987dsfkcqiuwey18837032843259d";
 	public static final String LT = System.getProperty("line.separator");
+	public static final String exportCmd = "export BB_ENV_EXTRAWHITE=\"DISABLE_SANITY_CHECKS $BB_ENV_EXTRAWHITE\"";
+	public static final String exportColumnsCmd = "export COLUMNS=1000";
+	private static final String BUILD_DIR = "/build/";
+
 	
 	public static String getFilePath(String file) throws IOException {
 		File f = new File(file);
@@ -65,12 +73,9 @@ public class ShellSession {
 	private Process process;
 
 	private OutputStream pos = null;
-	//private File initFile = null;
 	private String shellPath = null;
 	private final String initCmd;
 	private final IHostFile root;
-	private final Writer out;
-	
 	private ProjectInfo projectInfo;
 
 	public ProjectInfo getProjectInfo() {
@@ -81,33 +86,29 @@ public class ShellSession {
 		this.projectInfo = projectInfo;
 	}
 
-	public ShellSession(ProjectInfo pInfo, int shellType, IHostFile root, String initCmd, Writer out) throws IOException {
+	public ShellSession(ProjectInfo pInfo, int shellType, IHostFile root, String initCmd) throws IOException {
 		this.projectInfo = pInfo;
 		this.root = root;
 		this.initCmd  = initCmd;
-		if (out == null) {
-			this.out = new NullWriter();
-		} else {
-			this.out = out;
-		}
 		if (shellType == SHELL_TYPE_SH) {
 			shellPath = "/bin/sh";
 		}
 		shellPath  = "/bin/bash";
-		
-		initializeShell();
+
+		initializeShell(new NullProgressMonitor());
 	}
 
-	private void initializeShell() throws IOException {
-		process = Runtime.getRuntime().exec(shellPath);
-		pos = process.getOutputStream();
-		
-		if (root != null) {
-			out.write(execute("cd " + root.getAbsolutePath()));
-		}
-		
-		if (initCmd != null) {
-			out.write(execute("source " + initCmd));
+	private void initializeShell(IProgressMonitor monitor) throws IOException {
+		try {
+			if (root != null) {
+				IHost connection = projectInfo.getConnection();
+				RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand("source " + initCmd, root.getAbsolutePath(), ""), monitor);
+				RemoteHelper.handleRunCommandRemote(connection,  new YoctoCommand(exportCmd, root.getAbsolutePath(), ""), monitor);
+			} else {
+				throw new Exception("Root file not found!");
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
 		}
 	}
 
@@ -118,51 +119,32 @@ public class ShellSession {
 
 	synchronized 
 	public String execute(String command, boolean hasErrors) throws IOException {
-		String errorMessage = null;
-		interrupt = false;
-		out.write(command);
-		out.write(LT);
-		
-		sendToProcessAndTerminate(command);
-
-		if (process.getErrorStream().available() > 0) {
-			byte[] msg = new byte[process.getErrorStream().available()];
-
-			process.getErrorStream().read(msg, 0, msg.length);
-			out.write(new String(msg));
-			out.write(LT);
-			errorMessage = "Error while executing: " + command + LT + new String(msg);
+		try {
+			if (projectInfo.getConnection() != null) {
+				command = getInitCmd() + command;
+				RemoteHelper.handleRunCommandRemote(projectInfo.getConnection(), new YoctoCommand(command, getBuildDirAbsolutePath(), ""), new NullProgressMonitor());
+				return getBuildDirAbsolutePath();
+			}
+			return null;
+		} catch (Exception e) {
+			e.printStackTrace();
 		}
-		
-		BufferedReader br = new BufferedReader(new InputStreamReader(process
-				.getInputStream()));
-
-		StringBuffer sb = new StringBuffer();
-		String line = null;
+		return null;
+	}
 
-		while (((line = br.readLine()) != null) && !line.endsWith(TERMINATOR) && !interrupt) {
-			sb.append(line);
-			sb.append(LT);
-			out.write(line);
-			out.write(LT);
-		}
-		
-		if (interrupt) {
-			process.destroy();
-			initializeShell();
-			interrupt = false;
-		}
-		
-		if (errorMessage != null) {
-			throw new IOException(errorMessage);
-		}
+	private String getBuildDirAbsolutePath() {
+		return root.getAbsolutePath() + BUILD_DIR;
+	}
 
-		return sb.toString();
+	private String getInitCmd() {
+		return "source " + initCmd + " " + getBuildDirAbsolutePath()
+				+ " > tempsf; rm -rf tempsf;" + exportCmd + ";"
+				+ exportColumnsCmd + ";" + "cd " + getBuildDirAbsolutePath()
+				+ ";";
 	}
 
 synchronized 
 	public void execute(String command, ICommandResponseHandler handler) throws IOException {
-		System.out.println(command);
 		execute(command, TERMINATOR, handler);
 	}
 	
@@ -183,14 +165,12 @@ synchronized
 				byte[] msg = new byte[errIs.available()];
 
 				errIs.read(msg, 0, msg.length);
-				out.write(new String(msg));
 				handler.response(new String(msg), true);
 			} 
 			
 			std = br.readLine();
 			
 			if (std != null && !std.endsWith(terminator)) {
-				out.write(std);
 				handler.response(std, false);
 			} 
 			
@@ -198,7 +178,7 @@ synchronized
 		
 		if (interrupt) {
 			process.destroy();
-			initializeShell();
+			initializeShell(null);
 			interrupt = false;
 		}
 	}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
index ded1e44..dc2e858 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
@@ -191,7 +191,7 @@ public class Activator extends AbstractUIPlugin {
 		
 		if (ss == null) {
 			IHostFile remoteHostFile = RemoteHelper.getRemoteHostFile(projInfo.getConnection(), absolutePath.getPath(), monitor);
-			ss = new ShellSession(projInfo, ShellSession.SHELL_TYPE_BASH, remoteHostFile, ProjectInfoHelper.getInitScriptPath(absolutePath), out);
+			ss = new ShellSession(projInfo, ShellSession.SHELL_TYPE_BASH, remoteHostFile, ProjectInfoHelper.getInitScriptPath(absolutePath));
 		}
 		
 		return ss;
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 02/21] Remove shell type from ShellSession constructor
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 01/21] Fix ShellSession execute Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 03/21] Use / as separator instead of OS separator Ioana Grigoropol
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- ShellSession is only used with shellType SHELL_BASH and thus the need to keep an extra argument is not needed
- When running commands using RemoteHelper, a shell is created per command. Its type is determined by using the IShellServiceSubSystem implementation from the target.

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/bc/bitbake/ShellSession.java     |   14 +-------------
 .../src/org/yocto/bc/ui/Activator.java             |    2 +-
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
index e8ed384..bc962f7 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
@@ -33,14 +33,6 @@ import org.yocto.remote.utils.YoctoCommand;
  *
  */
 public class ShellSession {
-	/**
-	 * Bash shell
-	 */
-	public static final int SHELL_TYPE_BASH = 1;
-	/**
-	 * sh shell
-	 */
-	public static final int SHELL_TYPE_SH = 2;
 	private volatile boolean interrupt = false;
 	/**
 	 * String used to isolate command execution
@@ -86,14 +78,10 @@ public class ShellSession {
 		this.projectInfo = projectInfo;
 	}
 
-	public ShellSession(ProjectInfo pInfo, int shellType, IHostFile root, String initCmd) throws IOException {
+	public ShellSession(ProjectInfo pInfo, IHostFile root, String initCmd) throws IOException {
 		this.projectInfo = pInfo;
 		this.root = root;
 		this.initCmd  = initCmd;
-		if (shellType == SHELL_TYPE_SH) {
-			shellPath = "/bin/sh";
-		}
-		shellPath  = "/bin/bash";
 
 		initializeShell(new NullProgressMonitor());
 	}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
index dc2e858..c11b674 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java
@@ -191,7 +191,7 @@ public class Activator extends AbstractUIPlugin {
 		
 		if (ss == null) {
 			IHostFile remoteHostFile = RemoteHelper.getRemoteHostFile(projInfo.getConnection(), absolutePath.getPath(), monitor);
-			ss = new ShellSession(projInfo, ShellSession.SHELL_TYPE_BASH, remoteHostFile, ProjectInfoHelper.getInitScriptPath(absolutePath));
+			ss = new ShellSession(projInfo, remoteHostFile, ProjectInfoHelper.getInitScriptPath(absolutePath));
 		}
 		
 		return ss;
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 03/21] Use / as separator instead of OS separator
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 01/21] Fix ShellSession execute Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 02/21] Remove shell type from ShellSession constructor Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 04/21] Remove unsed methods & inner classes from ShellSession Ioana Grigoropol
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- when running remote commands it is not indicated to use the OS separator since the host and the target could be different
- instead use the remote target separator(/) since this will always be a Linux based machine

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/bc/bitbake/ShellSession.java     |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
index bc962f7..4e8dd47 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
@@ -53,11 +53,11 @@ public class ShellSession {
 		
 		StringBuffer sb = new StringBuffer();
 		
-		String elems[] = file.split(File.separator);
+		String elems[] = file.split("//");
 		
 		for (int i = 0; i < elems.length - 1; ++i) {
 			sb.append(elems[i]);
-			sb.append(File.separator);
+			sb.append("//");
 		}
 		
 		return sb.toString();
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 04/21] Remove unsed methods & inner classes from ShellSession
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (2 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 03/21] Use / as separator instead of OS separator Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 05/21] Save active connection for Bitbake recipe Ioana Grigoropol
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/bc/bitbake/ShellSession.java     |   20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
index 4e8dd47..8760503 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java
@@ -130,11 +130,6 @@ public class ShellSession {
 				+ exportColumnsCmd + ";" + "cd " + getBuildDirAbsolutePath()
 				+ ";";
 	}
-
-synchronized 
-	public void execute(String command, ICommandResponseHandler handler) throws IOException {
-		execute(command, TERMINATOR, handler);
-	}
 	
 	synchronized 
 	public void execute(String command, String terminator, ICommandResponseHandler handler) throws IOException {
@@ -207,21 +202,6 @@ synchronized
 		interrupt = true;
 	}
 	
-	private class NullWriter extends Writer {
-
-		@Override
-		public void close() throws IOException {			
-		}
-
-		@Override
-		public void flush() throws IOException {			
-		}
-
-		@Override
-		public void write(char[] cbuf, int off, int len) throws IOException {			
-		}
-		
-	}
 	public void printError(String errorLines) {
 		RemoteHelper.getCommandHandler(projectInfo.getConnection()).response(errorLines, true);
 	}
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 05/21] Save active connection for Bitbake recipe
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (3 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 04/21] Remove unsed methods & inner classes from ShellSession Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 06/21] Initialize and store the connection on Recipe Wizard Ioana Grigoropol
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- retrieve active connection from project info and save it on the Bitbake editor

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../bc/ui/editors/bitbake/BitBakeFileEditor.java   |    1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
index 1e42d29..44fd0c1 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
@@ -68,6 +68,7 @@ public class BitBakeFileEditor extends AbstractDecoratedTextEditor {
 			
 			try {
 				ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI());
+				((BitBakeDocumentProvider)getDocumentProvider()).setActiveConnection(projInfo.getConnection());
 				viewerConfiguration.setBBSession(Activator.getBBSession(projInfo, new NullProgressMonitor()));
 			} catch (IOException e) {
 				e.printStackTrace();
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 06/21] Initialize and store the connection on Recipe Wizard
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (4 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 05/21] Save active connection for Bitbake recipe Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 07/21] Store connection for recipe in Recipe Wizard Page Ioana Grigoropol
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- retrieve the connection for the project destination of the recipe (using the Activator map)
- store it in the Wizard & use it for running remote commands

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java  |   37 ++++++++++++++------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
index 14b268b..c08651a 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -33,6 +34,7 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.rse.core.model.IHost;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
@@ -42,10 +44,15 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.ide.IDE;
 
 import org.yocto.bc.bitbake.BBLanguageHelper;
+import org.yocto.bc.ui.Activator;
+import org.yocto.bc.ui.model.ProjectInfo;
+import org.yocto.remote.utils.RemoteHelper;
+import org.yocto.remote.utils.YoctoCommand;
 
 public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
 	private NewBitBakeFileRecipeWizardPage page;
 	private ISelection selection;
+	private IHost connection;
 
 	public NewBitBakeFileRecipeWizard() {
 		super();
@@ -106,6 +113,24 @@ public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
 	 */
 	public void init(IWorkbench workbench, IStructuredSelection selection) {
 		this.selection = selection;
+		if (selection instanceof IStructuredSelection) {
+			Object element = selection.getFirstElement();
+
+			if (element instanceof IResource) {
+				IProject p = ((IResource)element).getProject();
+				try {
+					ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI());
+					this.connection = projInfo.getConnection();
+				} catch (CoreException e) {
+					e.printStackTrace();
+				} catch (InvocationTargetException e) {
+					e.printStackTrace();
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+
+			}
+		}
 	}
 
 	/**
@@ -178,17 +203,7 @@ public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
 			public void run(IProgressMonitor monitor) throws InvocationTargetException {
 				try {
 					doFinish(element, monitor);
-					File temp_dir = new File(element.getMetaDir() + "/temp");
-					if (temp_dir.exists()) {
-						File working_dir = new File(element.getMetaDir());
-					
-						String rm_cmd = "rm -rf temp";
-						final Process process = Runtime.getRuntime().exec(rm_cmd, null, working_dir);
-						int returnCode = process.waitFor();
-						if (returnCode != 0) {
-							throw new Exception("Failed to clean up the temp dir");
-						}
-					}
+					RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand("rm -rf " + element.getMetaDir() + "/temp", "", ""), monitor);
 				} catch (Exception e) {
 					throw new InvocationTargetException(e);
 				} finally {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 07/21] Store connection for recipe in Recipe Wizard Page
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (5 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 06/21] Initialize and store the connection on Recipe Wizard Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 08/21] Refactor Wizard Page fields to have consistent names Ioana Grigoropol
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java  |    2 +-
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |    5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
index c08651a..a4a648e 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
@@ -61,7 +61,7 @@ public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
 
 	@Override
 	public void addPages() {
-		page = new NewBitBakeFileRecipeWizardPage(selection);
+		page = new NewBitBakeFileRecipeWizardPage(selection, connection);
 		addPage(page);
 	}
 
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index 61878b9..36ffd4fa 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -21,6 +21,7 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.rse.core.model.IHost;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -72,12 +73,14 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private ISelection selection;
 	private String metaDirLoc;
 	private ArrayList inheritance;
+	private final IHost connection;
 	
-	public NewBitBakeFileRecipeWizardPage(ISelection selection) {
+	public NewBitBakeFileRecipeWizardPage(ISelection selection, IHost connection) {
 		super("wizardPage");
 		setTitle("BitBake Recipe");
 		setDescription("Create a new BitBake recipe.");
 		this.selection = selection;
+		this.connection = connection;
 		element = new BitbakeRecipeUIElement();
 		inheritance = new ArrayList();
 	}
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 08/21] Refactor Wizard Page fields to have consistent names
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (6 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 07/21] Store connection for recipe in Recipe Wizard Page Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 09/21] Refactor populate method name Ioana Grigoropol
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   25 +++++++++++---------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index 36ffd4fa..4504144 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -65,9 +65,11 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private Text homepageText;
 	private Text authorText;
 	private Text sectionText;
-	private Text srcuriText;
+	private Text txtSrcURI;
 	private Text md5sumText;
 	private Text sha256sumText;
+	private Button btnPopulate;
+
 	private BitbakeRecipeUIElement element;
 	
 	private ISelection selection;
@@ -126,18 +128,19 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		label = new Label(container, SWT.NULL);
 		label.setText("SRC_&URI:");
 
-		srcuriText = new Text(container, SWT.BORDER | SWT.SINGLE);
+		txtSrcURI = new Text(container, SWT.BORDER | SWT.SINGLE);
 		gd = new GridData(GridData.FILL_HORIZONTAL);
-		srcuriText.setLayoutData(gd);
-		srcuriText.addModifyListener(new ModifyListener() {
+		txtSrcURI.setLayoutData(gd);
+		txtSrcURI.addModifyListener(new ModifyListener() {
 			public void modifyText(ModifyEvent e) {
 				dialogChanged();
 			}
 		});
 
-		Button buttonP = new Button(container, SWT.PUSH);
-		buttonP.setText("Populate...");
-		buttonP.addSelectionListener(new SelectionAdapter() {
+		btnPopulate = new Button(container, SWT.PUSH);
+		btnPopulate.setText("Populate...");
+		btnPopulate.setEnabled(false);
+		btnPopulate.addSelectionListener(new SelectionAdapter() {
 			@Override
 			public void widgetSelected(SelectionEvent e) {
 				handlePopulate();
@@ -222,7 +225,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 			return;
 		}
 
-		if (srcuriText.getText().length() == 0) {
+		if (txtSrcURI.getText().length() == 0) {
 			updateStatus("SRC_URI can't be empty");
 		}
 		
@@ -240,7 +243,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		element.setMd5sum(md5sumText.getText());
 		element.setSection(sectionText.getText());
 		element.setSha256sum(sha256sumText.getText());
-		element.setSrcuri(srcuriText.getText());
+		element.setSrcuri(txtSrcURI.getText());
 		element.setInheritance(inheritance);
 		element.setMetaDir(metaDirLoc);
 		
@@ -258,7 +261,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	}
 	
 	private void handlePopulate() {
-		String src_uri = srcuriText.getText();
+		String src_uri = txtSrcURI.getText();
 		if ((src_uri.startsWith("http://") || src_uri.startsWith("ftp://")) 
 			&& (src_uri.endsWith("tar.gz") || src_uri.endsWith("tar.bz2"))) {
 		
@@ -519,7 +522,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	    }
 	    int idx = src_uri.lastIndexOf("-");
 	    String new_src_uri = src_uri.substring(0, idx)+"-${PV}.tar.gz";
-	    srcuriText.setText(new_src_uri);
+	    txtSrcURI.setText(new_src_uri);
 	}
 	
 	private void initialize() {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 09/21] Refactor populate method name
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (7 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 08/21] Refactor Wizard Page fields to have consistent names Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 10/21] Break handlePopulate into remote and local functions Ioana Grigoropol
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- add more suggestive name

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java  |    2 +-
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
index a4a648e..24033b8 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
@@ -197,7 +197,7 @@ public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
 
 	@Override
 	public boolean performFinish() {
-		final BitbakeRecipeUIElement element = page.getUIElement();
+		final BitbakeRecipeUIElement element = page.populateUIElement();
 		
 		IRunnableWithProgress op = new IRunnableWithProgress() {
 			public void run(IProgressMonitor monitor) throws InvocationTargetException {
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index 4504144..4ee6b9c 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -232,7 +232,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		updateStatus(null);
 	}
 
-	public BitbakeRecipeUIElement getUIElement() {
+	public BitbakeRecipeUIElement populateUIElement() {
 		element.setAuthor(authorText.getText());
 		element.setChecksum(checksumText.getText());
 		element.setContainer(containerText.getText());
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 10/21] Break handlePopulate into remote and local functions
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (8 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 09/21] Refactor populate method name Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 11/21] Use uri instead of string to determine location of recipe & determine archive type Ioana Grigoropol
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   31 ++++++++++++--------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index 4ee6b9c..9db0608 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -264,28 +264,33 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		String src_uri = txtSrcURI.getText();
 		if ((src_uri.startsWith("http://") || src_uri.startsWith("ftp://")) 
 			&& (src_uri.endsWith("tar.gz") || src_uri.endsWith("tar.bz2"))) {
-		
-			HashMap<String, String> mirror_map = createMirrorLookupTable();
-		
-			populateRecipeName(src_uri);
-			populateSrcuriChecksum(src_uri);
-			String extractDir = extractPackage(src_uri);
-			populateLicensefileChecksum(extractDir);
-			updateSrcuri(mirror_map, src_uri);
-			populateInheritance(extractDir);
+			handleRemotePopulate(src_uri);
 		} else if (src_uri.startsWith("file://")) {
 			String path_str = src_uri.substring(7);
 			File package_dir = new File(path_str);
 			if (package_dir.isDirectory()) {
-				String package_name = path_str.substring(path_str.lastIndexOf("/")+1);
-				fileText.setText(package_name+".bb");
-				populateLicensefileChecksum(path_str);
-				populateInheritance(path_str);
+				handleLocalPopulate(path_str);
 			}
 		}
 		
 	}
+
+	private void handleRemotePopulate(String src_uri) {
+		HashMap<String, String> mirror_map = createMirrorLookupTable();
+		populateRecipeName(src_uri);
+		populateSrcuriChecksum(src_uri);
+		String extractDir = extractPackage(src_uri);
+		populateLicensefileChecksum(extractDir);
+		updateSrcuri(mirror_map, src_uri);
+		populateInheritance(extractDir);
+	}
 	
+	private void handleLocalPopulate(String path_str) {
+		String package_name = path_str.substring(path_str.lastIndexOf("/")+1);
+		fileText.setText(package_name+".bb");
+		populateLicensefileChecksum(path_str);
+		populateInheritance(path_str);
+	}
 	private String extractPackage(String src_uri) {
 		try {
 			File working_dir = new File(metaDirLoc+"/temp");
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 11/21] Use uri instead of string to determine location of recipe & determine archive type
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (9 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 10/21] Break handlePopulate into remote and local functions Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 12/21] Store metadata location as URI instead of String Ioana Grigoropol
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- create URI from text location of the recipe and determine the location of the recipe by using the scheme(ftp, http, file)
- extract achive type from URI

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   59 ++++++++++++++++----
 1 file changed, 49 insertions(+), 10 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index 9db0608..c9b39be 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -54,6 +54,8 @@ import java.io.InputStream;
 import java.io.FilenameFilter;
 import java.security.MessageDigest;
 import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private Text containerText;
@@ -76,6 +78,17 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private String metaDirLoc;
 	private ArrayList inheritance;
 	private final IHost connection;
+
+	private String srcFileNameExt;
+	private String srcFileName;
+
+	public static final String TEMP_FOLDER_NAME = "temp";
+	public static final String TAR_BZ2_EXT = ".tar.bz2";
+	public static final String TAR_GZ_EXT = ".tar.gz";
+	public static final String HTTP = "http";
+	public static final String FTP ="ftp";
+	public static final String BB_RECIPE_EXT =".bb";
+	private static final String COPYING_FILE = "COPYING";
 	
 	public NewBitBakeFileRecipeWizardPage(ISelection selection, IHost connection) {
 		super("wizardPage");
@@ -261,20 +274,46 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	}
 	
 	private void handlePopulate() {
-		String src_uri = txtSrcURI.getText();
-		if ((src_uri.startsWith("http://") || src_uri.startsWith("ftp://")) 
-			&& (src_uri.endsWith("tar.gz") || src_uri.endsWith("tar.bz2"))) {
-			handleRemotePopulate(src_uri);
-		} else if (src_uri.startsWith("file://")) {
-			String path_str = src_uri.substring(7);
-			File package_dir = new File(path_str);
-			if (package_dir.isDirectory()) {
-				handleLocalPopulate(path_str);
+		try {
+			String src_uri = txtSrcURI.getText();
+			URI srcURI = new URI(txtSrcURI.getText().trim());
+			String scheme = srcURI.getScheme();
+			this.srcFileNameExt = getSrcFileName(true);
+			this.srcFileName = getSrcFileName(false);
+			if ((scheme.equals(HTTP) || scheme.equals(FTP))
+					&& (srcFileNameExt.endsWith(TAR_GZ_EXT) || srcFileNameExt.endsWith(TAR_BZ2_EXT))) {
+				handleRemotePopulate(src_uri);
+			} else {
+				String packageName = srcFileName.replace("-", "_");
+				fileText.setText(packageName + BB_RECIPE_EXT);
+
+				handleLocalPopulate(src_uri);
 			}
+		} catch (URISyntaxException e) {
+			e.printStackTrace();
 		}
-		
 	}
 
+	private String getSrcFileName(boolean withExt){
+		URI srcURI;
+		try {
+			srcURI = new URI(txtSrcURI.getText().trim());
+			String path = srcURI.getPath();
+			String fileName = path.substring(path.lastIndexOf("/") + 1);
+			if (withExt)
+				return fileName;
+			else {
+				if (fileName.endsWith(TAR_BZ2_EXT)) {
+					return fileName.substring(0, fileName.indexOf(TAR_BZ2_EXT));
+				} else if(fileName.endsWith(TAR_GZ_EXT)){
+					return fileName.substring(0, fileName.indexOf(TAR_GZ_EXT));
+				}
+			}
+		} catch (URISyntaxException e) {
+			e.printStackTrace();
+		}
+		return "";
+	}
 	private void handleRemotePopulate(String src_uri) {
 		HashMap<String, String> mirror_map = createMirrorLookupTable();
 		populateRecipeName(src_uri);
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 12/21] Store metadata location as URI instead of String
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (10 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 11/21] Use uri instead of string to determine location of recipe & determine archive type Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 13/21] Refactor Recipe Wizard Page to use Remote target Api Ioana Grigoropol
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- use URI to store meta-data location
- initialize metadata location with projectLocation/meta

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../bc/ui/wizards/BitbakeRecipeUIElement.java      |   15 +++++++++++----
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   19 +++++++++++++++++--
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
index 9699117..8bbc113 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
@@ -12,6 +12,9 @@ package org.yocto.bc.ui.wizards;
 
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.widgets.Text;
+
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 
 public class BitbakeRecipeUIElement {
@@ -27,7 +30,7 @@ public class BitbakeRecipeUIElement {
 	private String srcuri;
 	private String md5sum;
 	private String sha256sum;
-	private String metaDir;
+	private URI metaDir;
 	private ArrayList inheritance;
 
 	public BitbakeRecipeUIElement()
@@ -44,7 +47,11 @@ public class BitbakeRecipeUIElement {
 		this.md5sum = "";
 		this.sha256sum = "";
 		this.inheritance = new ArrayList();
-		this.metaDir = "";
+		try {
+			this.metaDir = new URI("");
+		} catch (URISyntaxException e) {
+			e.printStackTrace();
+		}
 	}
 
 	public String getContainer() {
@@ -135,11 +142,11 @@ public class BitbakeRecipeUIElement {
 		this.inheritance = value;
 	}
 	
-	public String getMetaDir() {
+	public URI getMetaDir() {
 		return metaDir;
 	}
 	
-	public void setMetaDir(String value) {
+	public void setMetaDir(URI value) {
 		metaDir = value;
 	}
 }
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index c9b39be..e9dc53f 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -15,6 +15,7 @@ import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.viewers.ISelection;
@@ -36,6 +37,9 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import org.yocto.bc.ui.Activator;
+import org.yocto.bc.ui.model.ProjectInfo;
+import org.yocto.remote.utils.RemoteHelper;
 
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -53,6 +57,7 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.FilenameFilter;
 import java.security.MessageDigest;
+import java.lang.reflect.InvocationTargetException;
 import java.math.BigInteger;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -75,7 +80,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private BitbakeRecipeUIElement element;
 	
 	private ISelection selection;
-	private String metaDirLoc;
+	private URI metaDirLoc;
 	private ArrayList inheritance;
 	private final IHost connection;
 
@@ -213,7 +218,17 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		}
 		
 		IProject project = container.getProject();
-		metaDirLoc = project.getLocation().toString() + "/meta";
+		ProjectInfo projInfo = null;
+		try {
+			projInfo = Activator.getProjInfo(project.getLocationURI());
+		} catch (InvocationTargetException e) {
+			e.printStackTrace();
+		} catch (CoreException e) {
+			e.printStackTrace();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		metaDirLoc = RemoteHelper.createNewURI(projInfo.getOriginalURI(), "meta");
 	
 		if (fileName.length() == 0) {
 			updateStatus("File name must be specified");
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 13/21] Refactor Recipe Wizard Page to use Remote target Api
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (11 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 12/21] Store metadata location as URI instead of String Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 14/21] Run all Recipe task in wizard container Ioana Grigoropol
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- refactored all steps taken when creating a new recipe to use RemoteHelper API and run commands on a abstract way regardless of the location of the target
- each step that needs to run a command remote will appear as a new YoctoCommand
- all commands are ran using RemoteHelper utility(handleRunCommandRemote) and passing a YoctoCommand
	- handleRunCommandRemote is a wrapper over the RSE Api that is able to run a command on a remote target in a separate shell
	- in addition to this, it also processes the output of the command and adds it to a ProcessStreamBuffer
	- each YoctoCommand contains:
		- the underlying command to be ran
		- the directory in which it should be ran
		- the ProcessStreamBuffer of this command
			- each process stream buffer contains two buffers:
				- error lines buffer
				- output lines buffer
	- all output/error processing of the command is done in separate threads and ensures that the command is finished before processing the output
	- [upstream issue] when dealing with remote targets, all the output and error lines will be found in the error lines
		- the underlying implementation has only one buffer and the errors are the first processed
		- [particular case] checksums are retrieved by running a Pattern against the output lines (local target) or error lines(remote target)

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |  419 +++++++++-----------
 1 file changed, 192 insertions(+), 227 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index e9dc53f..db8724d 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -11,18 +11,24 @@
  *******************************************************************************/
 package org.yocto.bc.ui.wizards;
 
+import java.util.List;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.services.files.IHostFile;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -39,7 +45,9 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
 import org.yocto.bc.ui.Activator;
 import org.yocto.bc.ui.model.ProjectInfo;
+import org.yocto.remote.utils.ProcessStreamBuffer;
 import org.yocto.remote.utils.RemoteHelper;
+import org.yocto.remote.utils.YoctoCommand;
 
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -47,6 +55,7 @@ import java.util.Set;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.regex.Pattern;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
@@ -84,6 +93,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	private ArrayList inheritance;
 	private final IHost connection;
 
+	private String tempFolderPath;
 	private String srcFileNameExt;
 	private String srcFileName;
 
@@ -94,7 +104,28 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	public static final String FTP ="ftp";
 	public static final String BB_RECIPE_EXT =".bb";
 	private static final String COPYING_FILE = "COPYING";
-	
+
+	private static final String CMAKE_LIST = "cmakelists.txt";
+	private static final String CMAKE = "cmake";
+	private static final String SETUP_SCRIPT = "setup.py";
+	private static final String DISUTILS = "disutils";
+	private static final String CONFIGURE_IN = "configure.in";
+	private static final String CONFIGURE_AC = "configure.ac";
+	private static final String AUTOTOOLS = "autotools";
+
+	private static final String md5Pattern = "^[0-9a-f]{32}$";
+	protected static final String sha256Pattern = "^[0-9a-f]{64}$";
+
+	private static final String MIRRORS_FILE = "mirrors.bbclass";
+	private static final String CLASSES_FOLDER = "classes";
+
+	private HashMap<String, String> mirrorTable;
+	private URI extractDir;
+
+	protected ProcessStreamBuffer md5Buffer;
+	protected ProcessStreamBuffer sha256Buffer;
+	protected ProcessStreamBuffer md5CopyingBuffer;
+
 	public NewBitBakeFileRecipeWizardPage(ISelection selection, IHost connection) {
 		super("wizardPage");
 		setTitle("BitBake Recipe");
@@ -290,19 +321,19 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	
 	private void handlePopulate() {
 		try {
-			String src_uri = txtSrcURI.getText();
+			IProgressMonitor monitor = new NullProgressMonitor();
 			URI srcURI = new URI(txtSrcURI.getText().trim());
 			String scheme = srcURI.getScheme();
 			this.srcFileNameExt = getSrcFileName(true);
 			this.srcFileName = getSrcFileName(false);
 			if ((scheme.equals(HTTP) || scheme.equals(FTP))
 					&& (srcFileNameExt.endsWith(TAR_GZ_EXT) || srcFileNameExt.endsWith(TAR_BZ2_EXT))) {
-				handleRemotePopulate(src_uri);
+				handleRemotePopulate(srcURI, monitor);
 			} else {
 				String packageName = srcFileName.replace("-", "_");
 				fileText.setText(packageName + BB_RECIPE_EXT);
 
-				handleLocalPopulate(src_uri);
+				handleLocalPopulate(srcURI, monitor);
 			}
 		} catch (URISyntaxException e) {
 			e.printStackTrace();
@@ -329,259 +360,193 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		}
 		return "";
 	}
-	private void handleRemotePopulate(String src_uri) {
-		HashMap<String, String> mirror_map = createMirrorLookupTable();
-		populateRecipeName(src_uri);
-		populateSrcuriChecksum(src_uri);
-		String extractDir = extractPackage(src_uri);
-		populateLicensefileChecksum(extractDir);
-		updateSrcuri(mirror_map, src_uri);
-		populateInheritance(extractDir);
-	}
-	
-	private void handleLocalPopulate(String path_str) {
-		String package_name = path_str.substring(path_str.lastIndexOf("/")+1);
-		fileText.setText(package_name+".bb");
-		populateLicensefileChecksum(path_str);
-		populateInheritance(path_str);
-	}
-	private String extractPackage(String src_uri) {
+	private void handleRemotePopulate(URI srcURI, IProgressMonitor monitor) {
+		populateRecipeName();
+
 		try {
-			File working_dir = new File(metaDirLoc+"/temp");
-			int idx = src_uri.lastIndexOf("/");
-			String tar_file = src_uri.substring(idx+1);
-			int tar_file_surfix_idx = tar_file.lastIndexOf(".tar");
-			String tar_file_surfix = tar_file.substring(tar_file_surfix_idx);
-			String tar_file_path = metaDirLoc+"/temp/"+tar_file;
-			
-			String tar_cmd = "";
-			int tar_idx = 0;
-			if (tar_file_surfix.matches(".tar.gz")) {
-				tar_cmd = "tar -zxvf "+ tar_file_path;
-				tar_idx = tar_file_path.lastIndexOf(".tar.gz");
-			} else if (tar_file_surfix.matches(".tar.bz2")) {
-				tar_idx = tar_file_path.lastIndexOf(".tar.bz2");
-				tar_cmd = "tar -xvf " + tar_file_path;
-			}
-			final Process process = Runtime.getRuntime().exec(tar_cmd, null, working_dir);
-			int returnCode = process.waitFor();
-			if (returnCode == 0) {
-				return tar_file_path.substring(0, tar_idx);
-			}
+			String metaDirLocPath = metaDirLoc.getPath();
+			monitor.subTask("Cleaning environment");
+			YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, "");
+			RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5));
+
+			YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, "");
+			RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5));
+
+			updateTempFolderPath();
+			monitor.worked(10);
+
+			monitor.subTask("Downloading package sources");
+
+			updateTempFolderPath();
+
+			YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, "");
+			RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40));
+
+			monitor.worked(50);
+
+			monitor.subTask("Compute package checksums");
+			String md5Cmd = "md5sum " + srcFileNameExt;
+			YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, "");
+
+			RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10));
+			md5Buffer =  md5YCmd.getProcessBuffer();
+
+			monitor.worked(60);
+
+			String sha256Cmd = "sha256sum " + srcFileNameExt;
+			YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, "");
+			RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10));
+			sha256Buffer = sha256YCmd.getProcessBuffer();
+
+			monitor.worked(70);
+
+			monitor.subTask("Extracting package");
+			extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0));
+			monitor.worked(80);
+
+			YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10));
+			md5CopyingBuffer = 	licenseChecksumCmd.getProcessBuffer();
+
+			monitor.subTask("Creating mirror lookup table");
+			mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10));
+
+			monitor.worked(90);
+			monitor.done();
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		return null;
+
+		updateSrcUri(mirrorTable, srcURI);
+		populateInheritance(extractDir, monitor);
+
+		String md5Val = md5Buffer.getOutputLineContaining(srcFileNameExt, md5Pattern);
+		md5sumText.setText(Pattern.matches(md5Pattern,  md5Val) ? md5Val : "");
+		String sha256Val = sha256Buffer.getOutputLineContaining(srcFileNameExt, sha256Pattern);
+		sha256sumText.setText(Pattern.matches(sha256Pattern,  sha256Val) ? sha256Val : "");
+		String checkSumVal =  md5CopyingBuffer.getOutputLineContaining(COPYING_FILE, md5Pattern);
+		checksumText.setText(RemoteHelper.createNewURI(extractDir, COPYING_FILE).toString() + ";md5=" + (Pattern.matches(md5Pattern,  checkSumVal) ? checkSumVal : ""));
 	}
 	
-	private void populateInheritance(String extractDir) {
-		File extract_dir = new File(extractDir);
-		
-		File[] files = extract_dir.listFiles();
-		for (File file : files) {
-			if (file.isDirectory()) 
-				continue;
-			else {	
-				if (file.getName().equalsIgnoreCase("cmakelists.txt"))
-					inheritance.add("cmake");
-				else if (file.getName().equalsIgnoreCase("setup.py"))
-					inheritance.add("disutils");
-				else {
-					String pattern = "configure.[ac|.in]";
-					if (file.getName().equalsIgnoreCase("configure.ac") || file.getName().equalsIgnoreCase("configure.in"))
-						inheritance.add("autotools");
-					else
-						continue;
-				}
-			}
-		}	
+	private void updateTempFolderPath(){
+		this.tempFolderPath = getMetaFolderPath() + TEMP_FOLDER_NAME + "/";
 	}
-	
-	private void populateLicensefileChecksum(String extractDir) {
-		String licenseFileChecksum_str = null;
-		String licenseFilePath = null;
-		
-		try {
-			File extract_dir = new File(extractDir);
-				
-			FilenameFilter copyFilter = new FilenameFilter() {
-				public boolean accept(File dir, String name) {
-					if (name.startsWith("COPYING")) {
-						return true;
-					} else {
-						return false;
-					}
-				}
-			};
 
-			File copyFile = null;
-			File[] files = extract_dir.listFiles(copyFilter);
-			for (File file : files) {
-				if (file.isDirectory()) 
-					continue;
-				else {	
-					copyFile = file;
-					licenseFilePath = file.getCanonicalPath();
-					break;
-				}
+	private String getMetaFolderPath(){
+		String sep = metaDirLoc.getPath().endsWith("/")? "" : "/";
+		return metaDirLoc.getPath() + sep;
+	}
+
+	private void handleLocalPopulate(URI srcURI, IProgressMonitor monitor) {
+		populateLicenseFileChecksum(srcURI, monitor);
+		populateInheritance(srcURI, monitor);
+	}
+
+	private URI extractPackage(URI srcURI, IProgressMonitor monitor) {
+		try {
+			String path = srcFileNameExt;
+			String tarCmd = "tar ";
+			if (path.endsWith(TAR_BZ2_EXT)) {
+				tarCmd += "-zxvf ";
+			} else if(path.endsWith(TAR_GZ_EXT)){
+				tarCmd += "-xvf ";
 			}
 
-			MessageDigest digest_md5 = MessageDigest.getInstance("MD5");			
-			InputStream is = new FileInputStream(copyFile);				
-			byte[] buffer = new byte[8192];
-			int read = 0;
-			
-			while( (read = is.read(buffer)) > 0) {
-				digest_md5.update(buffer, 0, read);
-			}		
-			byte[] md5sum = digest_md5.digest();
-			BigInteger bigInt_md5 = new BigInteger(1, md5sum);
-			licenseFileChecksum_str = bigInt_md5.toString(16);
-			is.close();
+			RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand(tarCmd + path, tempFolderPath, ""), monitor);
+
+			return RemoteHelper.createNewURI(metaDirLoc, TEMP_FOLDER_NAME + "/" + srcFileName);
+
 		} catch (Exception e) {
-			throw new RuntimeException("Unable to process file for MD5 calculation", e);
-		}
-		
-		if (licenseFileChecksum_str != null) {
-			int idx = licenseFilePath.lastIndexOf("/");
-			String license_file_name = licenseFilePath.substring(idx+1);
-			checksumText.setText("file://"+license_file_name+";md5="+licenseFileChecksum_str);					
+			e.printStackTrace();
 		}
+		return null;
 	}
 	
-	private void populateSrcuriChecksum(String src_uri) {
-		String md5sum_str = null;
-		String sha256sum_str = null;
-		
-		try {
-			File working_dir = new File(metaDirLoc+"/temp");
-			working_dir.mkdir();
-			String download_cmd = "wget " + src_uri;
-			final Process process = Runtime.getRuntime().exec(download_cmd, null, working_dir);
-			int returnCode = process.waitFor();
-			if (returnCode == 0) {
-				int idx = src_uri.lastIndexOf("/");
-				String tar_file = src_uri.substring(idx+1);
-				String tar_file_path = metaDirLoc+"/temp/"+tar_file;
-				MessageDigest digest_md5 = MessageDigest.getInstance("MD5");
-				MessageDigest digest_sha256 = MessageDigest.getInstance("SHA-256");
-				File f = new File(tar_file_path);
-				InputStream is = new FileInputStream(f);				
-				byte[] buffer = new byte[8192];
-				int read = 0;
-				try {
-					while( (read = is.read(buffer)) > 0) {
-						digest_md5.update(buffer, 0, read);
-						digest_sha256.update(buffer, 0, read);
-					}		
-					byte[] md5sum = digest_md5.digest();
-					byte[] sha256sum = digest_sha256.digest();
-					BigInteger bigInt_md5 = new BigInteger(1, md5sum);
-					BigInteger bigInt_sha256 = new BigInteger(1, sha256sum);
-					md5sum_str = bigInt_md5.toString(16);
-					sha256sum_str = bigInt_sha256.toString(16);
-				}
-				catch(IOException e) {
-					throw new RuntimeException("Unable to process file for MD5", e);
-				}
-				finally {
-					try {
-						is.close();
-					}
-					catch(IOException e) {
-						throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
-					}
-				}
-				if (md5sum_str != null)
-					md5sumText.setText(md5sum_str);
-				if (sha256sum_str != null)
-					sha256sumText.setText(sha256sum_str);
+	private void populateInheritance(URI extractDir, IProgressMonitor monitor) {
+		IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, metaDirLoc.getPath(), "", IFileService.FILE_TYPE_FILES, monitor);
+		if (hostFiles == null)
+			return;
+
+		for (IHostFile file: hostFiles) {
+			String fileName = file.getName();
+			if (fileName.equalsIgnoreCase(CMAKE_LIST)){
+				inheritance.add(CMAKE);
+			} else if (fileName.equalsIgnoreCase(SETUP_SCRIPT)) {
+				inheritance.add(DISUTILS);
+			} else if (fileName.equalsIgnoreCase(CONFIGURE_AC) || file.getName().equalsIgnoreCase(CONFIGURE_IN)) {
+				inheritance.add(AUTOTOOLS);
 			}
-		} catch (Exception e) {
-			e.printStackTrace();
 		}
 	}
 	
-	private HashMap<String, String> createMirrorLookupTable() {
-		HashMap<String, String> mirror_map = new HashMap<String, String>();
-		File mirror_file = new File(metaDirLoc+"/classes/mirrors.bbclass");
+	private YoctoCommand populateLicenseFileChecksum(URI extractDir, IProgressMonitor monitor) {
+		if (extractDir == null)
+			throw new RuntimeException("Something went wrong during source extraction!");
 
 		try {
-			if (mirror_file.exists()) {
-				BufferedReader input = new BufferedReader(new FileReader(mirror_file));
-		
-				try
-				{
-					String line = null;
-					String delims = "[\\t]+";
-					
-					while ((line = input.readLine()) != null)
-					{	
-						String[] tokens = line.split(delims);
-						if (tokens.length < 2)
-							continue;
-						String ending_str = " \\n \\";
-						int idx = tokens[1].lastIndexOf(ending_str);
-						String key = tokens[1].substring(0, idx);
-						mirror_map.put(key, tokens[0]);
-					}
-				}
-				finally {
-					input.close();
-				}
-			}
+			YoctoCommand catCmd = new YoctoCommand("md5sum " + COPYING_FILE, extractDir.getPath(), "");
+			RemoteHelper.handleRunCommandRemote(connection, catCmd, monitor);
+			return catCmd;
+		} catch (Exception e) {
+			throw new RuntimeException("Unable to process file for MD5 calculation", e);
 		}
-		catch (IOException e)
-		{
-			e.printStackTrace();
 
+	}
+
+	private HashMap<String, String> createMirrorLookupTable(IProgressMonitor monitor) throws Exception {
+		HashMap<String, String> mirrorMap = new HashMap<String, String>();
+
+		YoctoCommand cmd = new YoctoCommand("cat " + MIRRORS_FILE, getMetaFolderPath() + CLASSES_FOLDER, "");
+		RemoteHelper.handleRunCommandRemote(connection, cmd, monitor);
+
+		if (!cmd.getProcessBuffer().hasErrors()){
+			String delims = "[\\t]+";
+			List<String> outputLines = cmd.getProcessBuffer().getOutputLines();
+			for (String outLine : outputLines) {
+				String[] tokens = outLine.split(delims);
+				if (tokens.length < 2)
+					continue;
+				String endingStr = " \\n \\";
+				int idx = tokens[1].lastIndexOf(endingStr);
+				String key = tokens[1].substring(0, idx);
+				mirrorMap.put(key, tokens[0]);
+			}
 		}
-		return mirror_map;
+		return mirrorMap;
 	}
 	
-	private void populateRecipeName(String src_uri) {
-		String file_name = fileText.getText();
-		if (!file_name.isEmpty()) 
+	private void populateRecipeName() {
+		String fileName = fileText.getText();
+		if (!fileName.isEmpty())
 			return;
-		String delims = "[/]+";
-		String recipe_file = null;
-		
-		String[] tokens = src_uri.split(delims);
-		if (tokens.length > 0) {
-			String tar_file = tokens[tokens.length - 1];
-			int surfix_idx = 0;
-			if (tar_file.endsWith(".tar.gz"))
-				surfix_idx = tar_file.lastIndexOf(".tar.gz");
-			else
-				surfix_idx = tar_file.lastIndexOf(".tar.bz2");
-			int sept_idx = tar_file.lastIndexOf("-");
-			recipe_file = tar_file.substring(0, sept_idx)+"_"+tar_file.substring(sept_idx+1, surfix_idx)+".bb";
-		}
-		if (recipe_file != null)
-			fileText.setText(recipe_file);
+
+		String recipeFile = srcFileName.replace("-", "_");
+		recipeFile += BB_RECIPE_EXT;
+		if (recipeFile != null)
+			fileText.setText(recipeFile);
 	}
 	
-	private void updateSrcuri(HashMap<String, String> mirrorsMap, String src_uri) {
+	private void updateSrcUri(HashMap<String, String> mirrorsMap, URI srcUri) {
 		Set<String> mirrors = mirrorsMap.keySet();
-		Iterator iter = mirrors.iterator();
+		Iterator<String> iter = mirrors.iterator();
 		String mirror_key = null;
-		
-	    while (iter.hasNext()) {
-	    	String value = (String)iter.next();
-	    	if (src_uri.startsWith(value)) {
-	    		mirror_key = value;
-	    		break;
-	    	}	
-	    }
-	    
-	    if (mirror_key != null) {
-	    	String replace_string = (String)mirrorsMap.get(mirror_key);
-	    	if (replace_string != null)
-	    		src_uri = replace_string+src_uri.substring(mirror_key.length());
-	    }
-	    int idx = src_uri.lastIndexOf("-");
-	    String new_src_uri = src_uri.substring(0, idx)+"-${PV}.tar.gz";
-	    txtSrcURI.setText(new_src_uri);
+		String srcURL = srcUri.toString();
+
+		while (iter.hasNext()) {
+			String value = iter.next();
+			if (srcURL.startsWith(value)) {
+				mirror_key = value;
+				break;
+			}
+		}
+
+		if (mirror_key != null) {
+			String replace_string = mirrorsMap.get(mirror_key);
+			if (replace_string != null)
+				srcURL = replace_string + srcURL.substring(mirror_key.length());
+		}
+		int idx = srcURL.lastIndexOf("-");
+		String new_src_uri = srcURL.substring(0, idx)+"-${PV}" + TAR_GZ_EXT;
+		txtSrcURI.setText(new_src_uri);
 	}
 	
 	private void initialize() {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 14/21] Run all Recipe task in wizard container
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (12 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 13/21] Refactor Recipe Wizard Page to use Remote target Api Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 15/21] Enable Populate button when src URI changes Ioana Grigoropol
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- if we run the remote commands without using the Wizard container, the monitor will never get updated properly and the messages will not appear
	- in order to fix this, we use a IRunnableWithProgress to perform all tasks

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   88 +++++++++++---------
 1 file changed, 50 insertions(+), 38 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index db8724d..dc29498 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.window.Window;
@@ -337,6 +338,10 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 			}
 		} catch (URISyntaxException e) {
 			e.printStackTrace();
+		} catch (InvocationTargetException e) {
+			e.printStackTrace();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
 		}
 	}
 
@@ -360,62 +365,69 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		}
 		return "";
 	}
-	private void handleRemotePopulate(URI srcURI, IProgressMonitor monitor) {
+	private void handleRemotePopulate(final URI srcURI, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
 		populateRecipeName();
 
-		try {
-			String metaDirLocPath = metaDirLoc.getPath();
-			monitor.subTask("Cleaning environment");
-			YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, "");
-			RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5));
+		this.getContainer().run(true, true, new IRunnableWithProgress() {
 
-			YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, "");
-			RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5));
+			@Override
+			public void run(IProgressMonitor monitor) throws InvocationTargetException,
+					InterruptedException {
+				monitor.beginTask("Populating recipe fields ... ", 100);
+				try {
+					String metaDirLocPath = metaDirLoc.getPath();
+					monitor.subTask("Cleaning environment");
+					YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, "");
+					RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5));
 
-			updateTempFolderPath();
-			monitor.worked(10);
+					YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, "");
+					RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5));
 
-			monitor.subTask("Downloading package sources");
+					updateTempFolderPath();
+					monitor.worked(10);
 
-			updateTempFolderPath();
+					monitor.subTask("Downloading package sources");
 
-			YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, "");
-			RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40));
+					updateTempFolderPath();
 
-			monitor.worked(50);
+					YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, "");
+					RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40));
 
-			monitor.subTask("Compute package checksums");
-			String md5Cmd = "md5sum " + srcFileNameExt;
-			YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, "");
+					monitor.worked(50);
 
-			RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10));
-			md5Buffer =  md5YCmd.getProcessBuffer();
+					monitor.subTask("Compute package checksums");
+					String md5Cmd = "md5sum " + srcFileNameExt;
+					YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, "");
 
-			monitor.worked(60);
+					RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10));
+					md5Buffer =  md5YCmd.getProcessBuffer();
 
-			String sha256Cmd = "sha256sum " + srcFileNameExt;
-			YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, "");
-			RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10));
-			sha256Buffer = sha256YCmd.getProcessBuffer();
+					monitor.worked(60);
 
-			monitor.worked(70);
+					String sha256Cmd = "sha256sum " + srcFileNameExt;
+					YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, "");
+					RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10));
+					sha256Buffer = sha256YCmd.getProcessBuffer();
 
-			monitor.subTask("Extracting package");
-			extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0));
-			monitor.worked(80);
+					monitor.worked(70);
 
-			YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10));
-			md5CopyingBuffer = 	licenseChecksumCmd.getProcessBuffer();
+					monitor.subTask("Extracting package");
+					extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0));
+					monitor.worked(80);
 
-			monitor.subTask("Creating mirror lookup table");
-			mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10));
+					YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10));
+					md5CopyingBuffer = 	licenseChecksumCmd.getProcessBuffer();
 
-			monitor.worked(90);
-			monitor.done();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
+					monitor.subTask("Creating mirror lookup table");
+					mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10));
 
+					monitor.worked(90);
+					monitor.done();
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		});
 		updateSrcUri(mirrorTable, srcURI);
 		populateInheritance(extractDir, monitor);
 
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 15/21] Enable Populate button when src URI changes
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (13 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 14/21] Run all Recipe task in wizard container Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 16/21] Store reference to OptionsPage in InstallWizard Ioana Grigoropol
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../ui/wizards/NewBitBakeFileRecipeWizardPage.java |   38 +++++++++++---------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
index dc29498..2d66fed 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -183,6 +183,12 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 		txtSrcURI.setLayoutData(gd);
 		txtSrcURI.addModifyListener(new ModifyListener() {
 			public void modifyText(ModifyEvent e) {
+				if (txtSrcURI.getText().trim().isEmpty()) {
+					if (btnPopulate != null)
+						btnPopulate.setEnabled(false);
+				} else if (btnPopulate != null){
+					btnPopulate.setEnabled(true);
+				}
 				dialogChanged();
 			}
 		});
@@ -367,7 +373,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 	}
 	private void handleRemotePopulate(final URI srcURI, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
 		populateRecipeName();
-
+		
 		this.getContainer().run(true, true, new IRunnableWithProgress() {
 
 			@Override
@@ -379,48 +385,48 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage {
 					monitor.subTask("Cleaning environment");
 					YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, "");
 					RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5));
-
+		
 					YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, "");
 					RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5));
-
+		
 					updateTempFolderPath();
 					monitor.worked(10);
-
+		
 					monitor.subTask("Downloading package sources");
-
+		
 					updateTempFolderPath();
-
+		
 					YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, "");
 					RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40));
-
+		
 					monitor.worked(50);
-
+		
 					monitor.subTask("Compute package checksums");
 					String md5Cmd = "md5sum " + srcFileNameExt;
 					YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, "");
-
+		
 					RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10));
 					md5Buffer =  md5YCmd.getProcessBuffer();
-
+		
 					monitor.worked(60);
-
+		
 					String sha256Cmd = "sha256sum " + srcFileNameExt;
 					YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, "");
 					RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10));
 					sha256Buffer = sha256YCmd.getProcessBuffer();
-
+		
 					monitor.worked(70);
-
+		
 					monitor.subTask("Extracting package");
 					extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0));
 					monitor.worked(80);
-
+		
 					YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10));
 					md5CopyingBuffer = 	licenseChecksumCmd.getProcessBuffer();
-
+		
 					monitor.subTask("Creating mirror lookup table");
 					mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10));
-
+		
 					monitor.worked(90);
 					monitor.done();
 				} catch (Exception e) {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 16/21] Store reference to OptionsPage in InstallWizard
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (14 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 15/21] Enable Populate button when src URI changes Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 17/21] Collect Bitbake error lines Ioana Grigoropol
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../yocto/bc/ui/wizards/install/InstallWizard.java |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
index f9174e2..6e60126 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -65,6 +65,7 @@ public class InstallWizard extends FiniteStateWizard implements
 
 	private Map model;
 	private MessageConsole myConsole;
+	private OptionsPage optionsPage;
 
 	public InstallWizard() {
 		this.model = new Hashtable();
@@ -121,7 +122,8 @@ public class InstallWizard extends FiniteStateWizard implements
 	 */
 	@Override
 	public void addPages() {
-		addPage(new OptionsPage(model));
+		optionsPage = new OptionsPage(model);
+		addPage(optionsPage);
 	}
 
 	@Override
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 17/21] Collect Bitbake error lines
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (15 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 16/21] Store reference to OptionsPage in InstallWizard Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 18/21] Refactor Bitbake wizard to use RemoteHelper API Ioana Grigoropol
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/bc/bitbake/BBSession.java        |   10 +++++++++
 .../BBConfigurationInitializeOperation.java        |   23 ++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java
index 714b3ab..5a44710 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java
@@ -467,6 +467,7 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 		Stack blockStack = new Stack();
 
 		while ((line = reader.readLine()) != null) {
+			errorLines += line;
 			String trimmed = line.trim();
 			if (trimmed.length() == 0 || line.startsWith("#")) {
 				// weed out the blank and comment lines
@@ -769,4 +770,13 @@ public class BBSession implements IBBSessionListener, IModelElement, Map {
 	public ProjectInfo getProjectInfo() {
 		return pinfo;
 	}
+
+	public boolean hasErrorOccured() {
+		return errorOccured;
+	}
+
+	public String getErrorLines() {
+		return errorLines;
+	}
+
 }
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
index 20c001a..d761667 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
@@ -20,17 +20,22 @@ import org.yocto.bc.bitbake.BBSession;
 import org.yocto.bc.bitbake.ProjectInfoHelper;
 import org.yocto.bc.ui.Activator;
 import org.yocto.bc.ui.model.ProjectInfo;
+import org.yocto.remote.utils.RemoteHelper;
 
 public class BBConfigurationInitializeOperation implements IRunnableWithProgress {
 
 	private final ProjectInfo pinfo;
 	private final Writer writer;
+	private boolean errorOccured = false;
+	private String errorMessage = "";
 
 	public BBConfigurationInitializeOperation(ProjectInfo pinfo) {
 		this.pinfo = pinfo;
 		writer = null;
 	}
-
+	public boolean hasErrorOccured() {
+		return errorOccured;
+	}
 	public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) {
 		this.pinfo = pinfo;
 		this.writer = writer;
@@ -39,11 +44,25 @@ public class BBConfigurationInitializeOperation implements IRunnableWithProgress
 	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
 		BBSession session;
 		try {
+			System.out.println("Initialize bitbake session ...");
+			monitor.beginTask("Initialize bitbake session ...", RemoteHelper.TOTALWORKLOAD);
 			session = Activator.getBBSession(pinfo, writer, monitor);
 			session.initialize();
-
+			monitor.worked(90);
+			monitor.done();
+			errorOccured = session.hasErrorOccured();
+			errorMessage = session.getErrorLines();
+			if (!errorOccured) {
+				System.out.println("Bitbake session initialized successfully.");
+				errorMessage = "";
+			} else
+				System.out.println("An error occured and Bitbake session was not initialized.");
 		} catch (Exception e) {
 			throw new InvocationTargetException(e);
 		}
 	}
+
+	public String getErrorMessage() {
+		return errorMessage;
+	}
 }
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 18/21] Refactor Bitbake wizard to use RemoteHelper API
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (16 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 17/21] Collect Bitbake error lines Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 19/21] Retrieve console from RemoteHelper instead of recreating it Ioana Grigoropol
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Bitbake command wizard improvements:
- retrive the console mapped to this particular connection from the RemoteHelper
- retrive the stored remote connection & services from the model
- retrive the connection from the map stored in RemoteHelper
- retrive the command response handler mapped in the RemoteHelper for this connection
- use newly added YoctoRunnableWithProgress for running the time consuming action(git clone) instead of the inner class
	- this is a customized IRunnableWithProgress that can be ran in a Wizard container and update the progress of the underlying monitor
	- this particular implementation is customized for running a git clone command
	- in order to parse the output of the git clone command, it also contains a calculator that
		tries to match each line with a given pattern and retrieves the percentage for updating the monitor
	- the run method of this class will make a call to the wrapper YoctoThread that runs the actual command
	  in a separate thread in order not to block the interface
		- this thread will delegate the output processing to a YoctoRunnableOutputProcessor
		- this particular type of OutputProcessor takes care of parsing the error lines it receives
			and reporting the progress to the monitor
Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    4 +-
 .../bc/remote/utils/YoctoRunnableWithProgress.java |  211 ++++++++++++++++++++
 .../yocto/bc/ui/wizards/install/InstallWizard.java |   90 +++++----
 3 files changed, 266 insertions(+), 39 deletions(-)
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java

diff --git a/plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF b/plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF
index 7cecce8..84946ad 100644
--- a/plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF
@@ -19,6 +19,8 @@ Require-Bundle: org.eclipse.ui,
 Eclipse-LazyStart: true
 Bundle-ClassPath: .
 Import-Package: org.eclipse.ptp.remote.core,
+ org.eclipse.ptp.remote.core.exception,
  org.eclipse.rse.core.model,
  org.eclipse.rse.services.clientserver.messages,
- org.eclipse.rse.services.files
+ org.eclipse.rse.services.files,
+ org.eclipse.rse.services.shells
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java
new file mode 100644
index 0000000..706a2d2
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java
@@ -0,0 +1,211 @@
+package org.yocto.bc.remote.utils;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.ptp.remote.core.IRemoteConnection;
+import org.eclipse.ptp.remote.core.IRemoteServices;
+import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
+import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.services.shells.IHostShell;
+import org.eclipse.swt.widgets.Display;
+import org.yocto.remote.utils.CommandResponseHandler;
+import org.yocto.remote.utils.OutputProcessor;
+import org.yocto.remote.utils.RemoteHelper;
+import org.yocto.remote.utils.YoctoCommand;
+
+public class YoctoRunnableWithProgress implements IRunnableWithProgress {
+
+	private String taskName;
+	private IRemoteConnection remoteConnection;
+	private IRemoteServices remoteServices;
+	private IProgressMonitor monitor;
+	private final ICalculatePercentage calculator;
+	private int reportedWorkload;
+
+	private final YoctoCommand command;
+
+	public YoctoRunnableWithProgress(YoctoCommand command) throws IOException {
+		this.command = command;
+		this.calculator = new GitCalculatePercentage();
+	}
+
+	private interface ICalculatePercentage {
+		public float calWorkloadDone(String info) throws IllegalArgumentException;
+	}
+
+	private class GitCalculatePercentage implements ICalculatePercentage {
+		final Pattern pattern = Pattern.compile("^Receiving objects:\\s*(\\d+)%.*");
+		@Override
+		public float calWorkloadDone(String info) throws IllegalArgumentException {
+			Matcher m = pattern.matcher(info.trim());
+			if(m.matches()) {
+				return new Float(m.group(1)) / 100;
+			}else {
+				throw new IllegalArgumentException();
+			}
+		}
+	}
+
+	@Override
+	public void run(IProgressMonitor monitor) throws InvocationTargetException,
+			InterruptedException {
+		try {
+			this.monitor = monitor;
+			this.monitor.beginTask(taskName, RemoteHelper.TOTALWORKLOAD);
+
+			if (!remoteConnection.isOpen()) {
+				try {
+					remoteConnection.open(monitor);
+				} catch (RemoteConnectionException e1) {
+					e1.printStackTrace();
+				}
+			}
+
+			if (!remoteServices.isInitialized()) {
+				remoteServices.initialize();
+			}
+
+			try {
+				IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
+				YoctoThread th = new YoctoThread(connection, command);
+				th.run();
+			} catch (Exception e) {
+				e.printStackTrace();
+			} finally {
+				monitor.done();
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+	class YoctoRunnableOutputProcessor extends OutputProcessor{
+
+		public YoctoRunnableOutputProcessor(IProgressMonitor monitor,
+				IHostShell hostShell, CommandResponseHandler cmdHandler,
+				String task) {
+			super(monitor, hostShell, cmdHandler, task);
+		}
+		@Override
+		protected boolean isErrChStop(char ch) {
+			return (ch == '\n' || ch == '\r');
+		}
+
+		@Override
+		protected boolean isOutChStop(char ch) {
+			return (ch == '\n');
+		}
+
+		@Override
+		protected void processOutputBufferLine(char ch, String str) {
+			processBuffer.addOutputLine(str);
+		}
+
+		@Override
+		protected void processErrorBufferLine(char ch, String str) {
+			processBuffer.addOutputLine(str);
+			if (ch == '\r')
+				reportProgress(str);
+		}
+
+	}
+
+	class YoctoThread implements Runnable{
+		private final IHost connection;
+		private final YoctoCommand command;
+		private final CommandResponseHandler cmdHandler;
+		private IHostShell hostShell;
+
+		YoctoThread(IHost connection, YoctoCommand command){
+			this.connection = connection;
+			this.cmdHandler = RemoteHelper.getCommandHandler(connection);
+			this.command = command;
+		}
+
+		@Override
+		public void run() {
+			try {
+				hostShell = RemoteHelper.runCommandRemote(this.connection, command, monitor);
+				command.setProcessBuffer(new YoctoRunnableOutputProcessor(monitor, hostShell, cmdHandler, taskName).processOutput());
+			} catch (CoreException e) {
+				e.printStackTrace();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	private void updateMonitor(final int work){
+
+		Display.getDefault().asyncExec(new Runnable() {
+
+			@Override
+			public void run() {
+				if (monitor != null) {
+					monitor.worked(work);
+				}
+			}
+
+		});
+	}
+
+	private void doneMonitor(){
+		Display.getDefault().asyncExec(new Runnable() {
+			@Override
+			public void run() {
+				monitor.done();
+			}
+		});
+	}
+
+	public void reportProgress(String info) {
+		if(calculator == null) {
+			updateMonitor(1);
+		} else {
+			float percentage;
+			try {
+				percentage = calculator.calWorkloadDone(info);
+			} catch (IllegalArgumentException e) {
+				System.out.println(info);
+				//can't get percentage
+				return;
+			}
+			int delta = (int) (RemoteHelper.TOTALWORKLOAD * percentage - reportedWorkload);
+			if( delta > 0 ) {
+				updateMonitor(delta);
+				reportedWorkload += delta;
+			}
+
+			if (reportedWorkload == RemoteHelper.TOTALWORKLOAD)
+				doneMonitor();
+		}
+	}
+
+	public IRemoteConnection getRemoteConnection() {
+		return remoteConnection;
+	}
+
+	public void setRemoteConnection(IRemoteConnection remoteConnection) {
+		this.remoteConnection = remoteConnection;
+	}
+
+	public String getTaskName() {
+		return taskName;
+	}
+
+	public void setTaskName(String taskName) {
+		this.taskName = taskName;
+	}
+
+	public IRemoteServices getRemoteServices() {
+		return remoteServices;
+	}
+
+	public void setRemoteServices(IRemoteServices remoteServices) {
+		this.remoteServices = remoteServices;
+	}
+}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
index 6e60126..a253f05 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -17,7 +17,11 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardContainer;
 import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ptp.remote.core.IRemoteConnection;
+import org.eclipse.ptp.remote.core.IRemoteServices;
+import org.eclipse.rse.core.model.IHost;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
@@ -30,12 +34,16 @@ import org.eclipse.ui.console.IConsoleManager;
 import org.eclipse.ui.console.IConsoleView;
 import org.eclipse.ui.console.MessageConsole;
 import org.eclipse.ui.console.MessageConsoleStream;
+import org.yocto.bc.remote.utils.YoctoRunnableWithProgress;
 import org.yocto.bc.ui.Activator;
 import org.yocto.bc.ui.model.ProjectInfo;
 import org.yocto.bc.ui.wizards.FiniteStateWizard;
 import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
 import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
+import org.yocto.remote.utils.CommandResponseHandler;
 import org.yocto.remote.utils.ICommandResponseHandler;
+import org.yocto.remote.utils.RemoteHelper;
+import org.yocto.remote.utils.YoctoCommand;
 
 /**
  * A wizard for installing a fresh copy of an OE system.
@@ -56,6 +64,9 @@ public class InstallWizard extends FiniteStateWizard implements
 	protected static final String INSTALL_DIRECTORY = "Install Directory";
 	protected static final String INIT_SCRIPT = "Init Script";
 
+	protected static final String SELECTED_CONNECTION = "SEL_CONNECTION";
+	protected static final String SELECTED_REMOTE_SERVICE = "SEL_REMOTE_SERVICE";
+
 	protected static final String PROJECT_NAME = "Project Name";
 	protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
 	protected static final String DEFAULT_INSTALL_DIR = "~/yocto";
@@ -133,65 +144,68 @@ public class InstallWizard extends FiniteStateWizard implements
 
 	@Override
 	public boolean performFinish() {
-		BCCommandResponseHandler cmdOut = new BCCommandResponseHandler(
-				myConsole);
-		
 		WizardPage page = (WizardPage) getPage("Options");
 		page.setPageComplete(true);
-		Map options = (Map) model;
-		String install_dir = "";
-		if (options.containsKey(INSTALL_DIRECTORY)) {
-			install_dir = (String) options.get(INSTALL_DIRECTORY);
-		}
+		Map<String, Object> options = model;
 
 		try {
 			URI uri = new URI("");
 			if (options.containsKey(INSTALL_DIRECTORY)) {
 				uri = (URI) options.get(INSTALL_DIRECTORY);
 			}
+			IRemoteConnection remoteConnection = ((IRemoteConnection)model.get(InstallWizard.SELECTED_CONNECTION));
+			IRemoteServices remoteServices = ((IRemoteServices)model.get(InstallWizard.SELECTED_REMOTE_SERVICE));
+			IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
+			CommandResponseHandler cmdHandler = new CommandResponseHandler(RemoteHelper.getConsole(connection));
+			IWizardContainer container = this.getContainer();
 			if (((Boolean)options.get(GIT_CLONE)).booleanValue()) {
-				String []git_clone_cmd = {"git", "clone", "--progress", "git://git.pokylinux.org/poky.git", install_dir};
-				final Pattern pattern = Pattern.compile("^Receiving objects:\\s*(\\d+)%.*");
-
-				this.getContainer().run(true,true,
-						new LongtimeRunningTask("Checking out Yocto git repository",
-							git_clone_cmd, null, null,
-							cmdOut,
-							new ICalculatePercentage() {
-								public float calWorkloadDone(String info) throws IllegalArgumentException {
-									Matcher m=pattern.matcher(info.trim());
-									if(m.matches()) {
-										return new Float(m.group(1)) / 100;
-									}else {
-										throw new IllegalArgumentException();
-									}
-								}
-							}
-						)
-				);
-			}
+				String cmd = "/usr/bin/git clone --progress";
+				String args = "git://git.yoctoproject.org/poky.git " + uri.getPath();
+				String taskName = "Checking out Yocto git repository";
 
-			if (!cmdOut.hasError()) {
+				YoctoRunnableWithProgress adapter = new YoctoRunnableWithProgress(new YoctoCommand(cmd, "", args));
 
-				String initPath = install_dir + "/"
-						+ (String) options.get(INIT_SCRIPT);
+				adapter.setRemoteConnection(remoteConnection);
+				adapter.setRemoteServices(remoteServices);
+				adapter.setTaskName(taskName);
+				try {
+					container.run(true, true, adapter);
+				} catch (InvocationTargetException e) {
+					e.printStackTrace();
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+			if (!cmdHandler.hasError()) {
+				String initPath = "";
+				if (uri.getPath() != null) {
+					 initPath = uri.getPath() + "/" + (String) options.get(INIT_SCRIPT);
+				} else {
+					initPath = uri.getFragment() + "/" + (String) options.get(INIT_SCRIPT);
+				}
 				String prjName = (String) options.get(PROJECT_NAME);
 				ProjectInfo pinfo = new ProjectInfo();
 				pinfo.setInitScriptPath(initPath);
 				pinfo.setLocationURI(uri);
 				pinfo.setName(prjName);
-			
-				ConsoleWriter cw = new ConsoleWriter();
-				this.getContainer().run(false, false,
-						new BBConfigurationInitializeOperation(pinfo, cw));
-				
+				pinfo.setConnection(connection);
+				pinfo.setRemoteServices(remoteServices);
+
+				final ConsoleWriter cw = new ConsoleWriter();
+				BBConfigurationInitializeOperation configInitOp = new BBConfigurationInitializeOperation(pinfo, null);
+				container.run(false, false, configInitOp);
+				myConsole = RemoteHelper.getConsole(connection);
 				myConsole.newMessageStream().println(cw.getContents());
 
+				if (configInitOp.hasErrorOccured()) {
+					optionsPage.setErrorMessage(configInitOp.getErrorMessage());
+					return false;
+				}
+
 				model.put(InstallWizard.KEY_PINFO, pinfo);
 				Activator.putProjInfo(pinfo.getOEFSURI(), pinfo);
 
-				this.getContainer().run(false, false,
-						new CreateBBCProjectOperation(pinfo));
+				container.run(false, false, new CreateBBCProjectOperation(pinfo));
 				return true;
 			}
 		} catch (Exception e) {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 19/21] Retrieve console from RemoteHelper instead of recreating it
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (17 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 18/21] Refactor Bitbake wizard to use RemoteHelper API Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 20/21] Remove LongRunningTask, ICalculatePercentage from InstallWizard Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 21/21] Create separated class for ConsoleWriter Ioana Grigoropol
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../yocto/bc/ui/wizards/install/InstallWizard.java |   25 +-------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
index a253f05..8294219 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -85,32 +85,9 @@ public class InstallWizard extends FiniteStateWizard implements
 		
 		setWindowTitle("Yocto Project BitBake Commander");
 		setNeedsProgressMonitor(true);
-		
-		myConsole = findConsole("Yocto Project Console");
-		IWorkbench wb = PlatformUI.getWorkbench();
-		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
-		IWorkbenchPage page = win.getActivePage();
-		String id = IConsoleConstants.ID_CONSOLE_VIEW;
-		try {
-			IConsoleView view = (IConsoleView) page.showView(id);
-			view.display(myConsole);
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
 	}
 
-	private MessageConsole findConsole(String name) {
-		ConsolePlugin plugin = ConsolePlugin.getDefault();
-		IConsoleManager conMan = plugin.getConsoleManager();
-		IConsole[] existing = conMan.getConsoles();
-		for (int i = 0; i < existing.length; i++)
-			if (name.equals(existing[i].getName()))
-				return (MessageConsole) existing[i];
-		// no console found, so create a new one
-		MessageConsole myConsole = new MessageConsole(name, null);
-		conMan.addConsoles(new IConsole[] { myConsole });
-		return myConsole;
-	}
+
 
 	public InstallWizard(IStructuredSelection selection) {
 		model = new Hashtable();
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 20/21] Remove LongRunningTask, ICalculatePercentage from InstallWizard
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (18 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 19/21] Retrieve console from RemoteHelper instead of recreating it Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  2013-06-05 17:00 ` [RFC refactor 21/21] Create separated class for ConsoleWriter Ioana Grigoropol
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

- remove inner classes & interfaces and use RemoteHelper implementation

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../yocto/bc/ui/wizards/install/InstallWizard.java |  155 --------------------
 1 file changed, 155 deletions(-)

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
index 8294219..42a3bef 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -197,161 +197,6 @@ public class InstallWizard extends FiniteStateWizard implements
 	public void init(IWorkbench workbench, IStructuredSelection selection) {
 	}
 
-	private interface ICalculatePercentage {
-		public float calWorkloadDone(String info) throws IllegalArgumentException;
-	}
-
-	private class LongtimeRunningTask implements IRunnableWithProgress {
-		private String []cmdArray;
-		private String []envp;
-		private File dir;
-		private ICommandResponseHandler handler;
-		private Process p;
-		private String taskName;
-		static public final int TOTALWORKLOAD=100;
-		private int reported_workload;
-		ICalculatePercentage cal;
-
-		public LongtimeRunningTask(String taskName, 
-				String []cmdArray, String []envp, File dir, 
-				ICommandResponseHandler handler,
-				ICalculatePercentage calculator) {
-			this.taskName=taskName;
-			this.cmdArray=cmdArray;
-			this.envp=envp;
-			this.dir=dir;
-			this.handler=handler;
-			this.p=null;
-			this.cal=calculator;
-		}
-
-		private void reportProgress(IProgressMonitor monitor,String info) {
-			if(cal == null) {
-				monitor.worked(1);
-			}else {
-				float percentage;
-				try {
-					percentage=cal.calWorkloadDone(info);
-				} catch (IllegalArgumentException e) {
-					//can't get percentage
-					return;
-				}
-				int delta=(int) (TOTALWORKLOAD * percentage - reported_workload);
-				if( delta > 0 ) {
-					monitor.worked(delta);
-					reported_workload += delta;
-				}
-			}
-		}
-
-		synchronized public void run(IProgressMonitor monitor) 
-				throws InvocationTargetException, InterruptedException {
-
-			boolean cancel=false;
-			reported_workload=0;
-
-			try {
-				monitor.beginTask(taskName, TOTALWORKLOAD);
-
-				p=Runtime.getRuntime().exec(cmdArray,envp,dir);
-				BufferedReader inbr = new BufferedReader(new InputStreamReader(p.getInputStream()));
-				BufferedReader errbr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
-				String info;
-				while (!cancel) {
-					if(monitor.isCanceled()) 
-					{
-						cancel=true;
-						throw new InterruptedException("User Cancelled");
-					}
-
-					info=null;
-					//reading stderr
-					while (errbr.ready()) {
-						info=errbr.readLine();
-						//some application using stderr to print out information
-						handler.response(info, false);
-					}
-					//reading stdout
-					while (inbr.ready()) {
-						info=inbr.readLine();
-						handler.response(info, false);
-					}
-
-					//report progress
-					if(info!=null)
-						reportProgress(monitor,info);
-
-					//check if exit
-					try {
-						int exitValue=p.exitValue();
-						if (exitValue != 0) {
-							handler.response(
-									taskName + " failed with the return value " + new Integer(exitValue).toString(), 
-									true);
-						}
-						break;
-					}catch (IllegalThreadStateException e) {
-					}
-
-					Thread.sleep(500);
-				}
-			} catch (IOException e) {
-				throw new InvocationTargetException(e);
-			} finally {
-				monitor.done();
-				if (p != null ) {
-					p.destroy();
-				}
-			}
-		}
-	}
-
-	private class BCCommandResponseHandler implements ICommandResponseHandler {
-		private MessageConsoleStream myConsoleStream;
-		private Boolean errorOccured = false;
-
-		public BCCommandResponseHandler(MessageConsole console) {
-			try {
-				this.myConsoleStream = console.newMessageStream();
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-
-		public void printDialog(String msg) {
-			try {
-				myConsoleStream.println(msg);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-
-		public Boolean hasError() {
-			return errorOccured;
-		}
-
-		public void response(String line, boolean isError) {
-			try {
-				if (isError) {
-					myConsoleStream.println(line);
-					errorOccured = true;
-				} else {
-					myConsoleStream.println(line);
-				}
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-
-		public void printCmd(String cmd) {
-			try {
-				myConsoleStream.println(cmd);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
 	private class ConsoleWriter extends Writer {
 
 		private StringBuffer sb;
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC refactor 21/21] Create separated class for ConsoleWriter
  2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
                   ` (19 preceding siblings ...)
  2013-06-05 17:00 ` [RFC refactor 20/21] Remove LongRunningTask, ICalculatePercentage from InstallWizard Ioana Grigoropol
@ 2013-06-05 17:00 ` Ioana Grigoropol
  20 siblings, 0 replies; 22+ messages in thread
From: Ioana Grigoropol @ 2013-06-05 17:00 UTC (permalink / raw)
  To: yocto

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org/yocto/bc/remote/utils/ConsoleWriter.java   |   36 ++++++++++++++++++++
 .../yocto/bc/ui/wizards/install/InstallWizard.java |    1 +
 2 files changed, 37 insertions(+)
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java

diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java
new file mode 100644
index 0000000..3bb364b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java
@@ -0,0 +1,36 @@
+package org.yocto.bc.remote.utils;
+
+import java.io.IOException;
+import java.io.Writer;
+
+public class ConsoleWriter extends Writer {
+
+	private StringBuffer sb;
+
+	public ConsoleWriter() {
+		sb = new StringBuffer();
+	}
+
+	@Override
+	public void close() throws IOException {
+	}
+
+	public String getContents() {
+		return sb.toString();
+	}
+
+	@Override
+	public void flush() throws IOException {
+	}
+
+	@Override
+	public void write(char[] cbuf, int off, int len) throws IOException {
+		sb.append(cbuf);
+	}
+
+	@Override
+	public void write(String str) throws IOException {
+		sb.append(str);
+	}
+
+}
\ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
index 42a3bef..f4bc99b 100644
--- a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -44,6 +44,7 @@ import org.yocto.remote.utils.CommandResponseHandler;
 import org.yocto.remote.utils.ICommandResponseHandler;
 import org.yocto.remote.utils.RemoteHelper;
 import org.yocto.remote.utils.YoctoCommand;
+import org.yocto.bc.remote.utils.ConsoleWriter;
 
 /**
  * A wizard for installing a fresh copy of an OE system.
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2013-06-05 17:22 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-05 17:00 [RFC refactor 00/21] Merging windows-build with master Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 01/21] Fix ShellSession execute Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 02/21] Remove shell type from ShellSession constructor Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 03/21] Use / as separator instead of OS separator Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 04/21] Remove unsed methods & inner classes from ShellSession Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 05/21] Save active connection for Bitbake recipe Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 06/21] Initialize and store the connection on Recipe Wizard Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 07/21] Store connection for recipe in Recipe Wizard Page Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 08/21] Refactor Wizard Page fields to have consistent names Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 09/21] Refactor populate method name Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 10/21] Break handlePopulate into remote and local functions Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 11/21] Use uri instead of string to determine location of recipe & determine archive type Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 12/21] Store metadata location as URI instead of String Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 13/21] Refactor Recipe Wizard Page to use Remote target Api Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 14/21] Run all Recipe task in wizard container Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 15/21] Enable Populate button when src URI changes Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 16/21] Store reference to OptionsPage in InstallWizard Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 17/21] Collect Bitbake error lines Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 18/21] Refactor Bitbake wizard to use RemoteHelper API Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 19/21] Retrieve console from RemoteHelper instead of recreating it Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 20/21] Remove LongRunningTask, ICalculatePercentage from InstallWizard Ioana Grigoropol
2013-06-05 17:00 ` [RFC refactor 21/21] Create separated class for ConsoleWriter Ioana Grigoropol

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.