Merging windows-build with master
cover Merging windows-build with master
- 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
Signature · 1 line
1.7.9.5
RFC 1/21 Fix ShellSession execute
- 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
--- .../src/org/yocto/bc/bitbake/ShellSession.java | 104 ++++++++------------ .../src/org/yocto/bc/ui/Activator.java | 2 +- 2 files changed, 43 insertions(+), 63 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +42 -62
@@ -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; } }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java +1 -1
@@ -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;
Signature · 1 line
1.7.9.5
RFC 2/21 Remove shell type from ShellSession constructor
In reply to Ioana Grigoropol- 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.
--- .../src/org/yocto/bc/bitbake/ShellSession.java | 14 +------------- .../src/org/yocto/bc/ui/Activator.java | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +1 -13
@@ -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()); }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/Activator.java +1 -1
@@ -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;
Signature · 1 line
1.7.9.5
RFC 3/21 Use / as separator instead of OS separator
In reply to Ioana Grigoropol- 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
--- .../src/org/yocto/bc/bitbake/ShellSession.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +2 -2
@@ -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();
Signature · 1 line
1.7.9.5
RFC 4/21 Remove unsed methods & inner classes from ShellSession
In reply to Ioana Grigoropol--- .../src/org/yocto/bc/bitbake/ShellSession.java | 20 -------------------- 1 file changed, 20 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +0 -20
@@ -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); }
Signature · 1 line
1.7.9.5
RFC 5/21 Save active connection for Bitbake recipe
In reply to Ioana Grigoropol- retrieve active connection from project info and save it on the Bitbake editor
--- .../bc/ui/editors/bitbake/BitBakeFileEditor.java | 1 + 1 file changed, 1 insertion(+)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java +1 -0
@@ -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();
Signature · 1 line
1.7.9.5
RFC 6/21 Initialize and store the connection on Recipe Wizard
In reply to Ioana Grigoropol- 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
--- .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java | 37 ++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java +26 -11
@@ -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 {
Signature · 1 line
1.7.9.5
RFC 7/21 Store connection for recipe in Recipe Wizard Page
In reply to Ioana Grigoropol--- .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java | 2 +- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java +1 -1
@@ -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); }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +4 -1
@@ -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(); }
Signature · 1 line
1.7.9.5
RFC 8/21 Refactor Wizard Page fields to have consistent names
In reply to Ioana Grigoropol--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +14 -11
@@ -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() {
Signature · 1 line
1.7.9.5
RFC 9/21 Refactor populate method name
In reply to Ioana Grigoropol- add more suggestive name
--- .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java | 2 +- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java +1 -1
@@ -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 {
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +1 -1
@@ -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());
Signature · 1 line
1.7.9.5
RFC 10/21 Break handlePopulate into remote and local functions
In reply to Ioana Grigoropol--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +18 -13
@@ -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");
Signature · 1 line
1.7.9.5
RFC 11/21 Use uri instead of string to determine location of recipe & determine archive type
In reply to Ioana Grigoropol- 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
--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 59 ++++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +49 -10
@@ -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);
Signature · 1 line
1.7.9.5
RFC 12/21 Store metadata location as URI instead of String
In reply to Ioana Grigoropol- use URI to store meta-data location
- initialize metadata location with projectLocation/meta
--- .../bc/ui/wizards/BitbakeRecipeUIElement.java | 15 +++++++++++---- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java +11 -4
@@ -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; } }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +17 -2
@@ -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");
Signature · 1 line
1.7.9.5
RFC 13/21 Refactor Recipe Wizard Page to use Remote target Api
In reply to Ioana Grigoropol- 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)
--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 419 +++++++++----------- 1 file changed, 192 insertions(+), 227 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +192 -227
@@ -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() {
Signature · 1 line
1.7.9.5
RFC 14/21 Run all Recipe task in wizard container
In reply to Ioana Grigoropol- 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
--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 88 +++++++++++--------- 1 file changed, 50 insertions(+), 38 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +50 -38
@@ -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);
Signature · 1 line
1.7.9.5
RFC 15/21 Enable Populate button when src URI changes
In reply to Ioana Grigoropol--- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 38 +++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +22 -16
@@ -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) {
Signature · 1 line
1.7.9.5
RFC 16/21 Store reference to OptionsPage in InstallWizard
In reply to Ioana Grigoropol--- .../yocto/bc/ui/wizards/install/InstallWizard.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +3 -1
@@ -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
Signature · 1 line
1.7.9.5
RFC 17/21 Collect Bitbake error lines
In reply to Ioana Grigoropol--- .../src/org/yocto/bc/bitbake/BBSession.java | 10 +++++++++ .../BBConfigurationInitializeOperation.java | 23 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/BBSession.java +10 -0
@@ -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; + } + }
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java +21 -2
@@ -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; + } }
Signature · 1 line
1.7.9.5
RFC 18/21 Refactor Bitbake wizard to use RemoteHelper API
In reply to Ioana GrigoropolBitbake 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
--- 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
plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF +3 -1
@@ -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
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java new file +211 -0
211 lines not on this page · raw message
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +52 -38
142 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC 19/21 Retrieve console from RemoteHelper instead of recreating it
In reply to Ioana Grigoropol--- .../yocto/bc/ui/wizards/install/InstallWizard.java | 25 +------------------- 1 file changed, 1 insertion(+), 24 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +1 -24
@@ -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();
Signature · 1 line
1.7.9.5
RFC 20/21 Remove LongRunningTask, ICalculatePercentage from InstallWizard
In reply to Ioana Grigoropol- remove inner classes & interfaces and use RemoteHelper implementation
--- .../yocto/bc/ui/wizards/install/InstallWizard.java | 155 -------------------- 1 file changed, 155 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +0 -155
@@ -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;
Signature · 1 line
1.7.9.5
RFC 21/21 Create separated class for ConsoleWriter
In reply to Ioana Grigoropol--- .../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
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleWriter.java new file +36 -0
@@ -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); + } + +}
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +1 -0
@@ -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.
Signature · 1 line
1.7.9.5