summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java145
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java56
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java149
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java215
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java543
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java236
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java166
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java404
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java247
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java50
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java102
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java262
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java43
13 files changed, 2618 insertions, 0 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
new file mode 100644
index 0000000..9699117
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java
@@ -0,0 +1,145 @@
1/*******************************************************************************
2 * Copyright (c) 2011 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards;
12
13import org.eclipse.jface.viewers.ISelection;
14import org.eclipse.swt.widgets.Text;
15import java.util.ArrayList;
16
17public class BitbakeRecipeUIElement {
18
19 private String container;
20 private String file;
21 private String description;
22 private String license;
23 private String checksum;
24 private String homepage;
25 private String author;
26 private String section;
27 private String srcuri;
28 private String md5sum;
29 private String sha256sum;
30 private String metaDir;
31 private ArrayList inheritance;
32
33 public BitbakeRecipeUIElement()
34 {
35 this.container = "";
36 this.file = "";
37 this.description = "";
38 this.license = "";
39 this.checksum = "";
40 this.homepage = "";
41 this.author = "";
42 this.section = "";
43 this.srcuri = "";
44 this.md5sum = "";
45 this.sha256sum = "";
46 this.inheritance = new ArrayList();
47 this.metaDir = "";
48 }
49
50 public String getContainer() {
51 return container;
52 }
53 public void setContainer(String value) {
54 this.container = value;
55 }
56 public String getFile() {
57 return file;
58 }
59 public void setFile(String value) {
60 this.file = value;
61 }
62 public String getDescription() {
63 return description;
64 }
65
66 public void setDescription(String value) {
67 this.description = value;
68 }
69
70 public String getLicense() {
71 return license;
72 }
73
74 public void setLicense(String value) {
75 this.license = value;
76 }
77
78 public String getChecksum() {
79 return checksum;
80 }
81 public void setChecksum(String value) {
82 this.checksum = value;
83 }
84
85 public String getHomePage() {
86 return homepage;
87 }
88
89 public void setHomePage(String value) {
90 this.homepage = value;
91 }
92
93 public String getAuthor() {
94 return author;
95 }
96
97 public void setAuthor(String value) {
98 this.author = value;
99 }
100
101 public String getSection() {
102 return section;
103 }
104 public void setSection(String value) {
105 this.section = value;
106 }
107 public String getSrcuri() {
108 return srcuri;
109 }
110 public void setSrcuri(String value) {
111 this.srcuri = value;
112 }
113
114 public String getMd5sum() {
115 return md5sum;
116 }
117
118 public void setMd5sum(String value) {
119 this.md5sum = value;
120 }
121
122 public String getsha256sum() {
123 return sha256sum;
124 }
125
126 public void setSha256sum(String value) {
127 this.sha256sum = value;
128 }
129
130 public ArrayList<String> getInheritance() {
131 return inheritance;
132 }
133
134 public void setInheritance(ArrayList<String> value) {
135 this.inheritance = value;
136 }
137
138 public String getMetaDir() {
139 return metaDir;
140 }
141
142 public void setMetaDir(String value) {
143 metaDir = value;
144 }
145}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java
new file mode 100644
index 0000000..8b47498
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java
@@ -0,0 +1,56 @@
1package org.yocto.bc.ui.wizards;
2import java.util.Map;
3
4import org.eclipse.jface.wizard.Wizard;
5import org.eclipse.swt.widgets.Composite;
6
7
8
9public abstract class FiniteStateWizard extends Wizard {
10 private boolean finishable = false;
11 private boolean canFinish = false;
12
13 public FiniteStateWizard() {
14 }
15
16 public abstract boolean performFinish();
17
18 /**
19 * @return Returns if the wizard is finishable in its current state.
20 */
21 public boolean isFinishable() {
22 return finishable;
23 }
24 /**
25 * @param finishable Change the finish state of the wizard.
26 */
27 public void setFinishable(boolean finishable) {
28 this.finishable = finishable;
29 }
30
31 /* (non-Javadoc)
32 * @see org.eclipse.jface.wizard.IWizard#createPageControls(org.eclipse.swt.widgets.Composite)
33 */
34 public void createPageControls(Composite pageContainer) {
35 super.createPageControls(pageContainer);
36 }
37
38 /*
39 * (non-Javadoc) Method declared on IWizard.
40 */
41 public boolean canFinish() {
42 if (canFinish)
43 return true;
44 return super.canFinish();
45 }
46
47 public void setCanFinish(boolean canFinish) {
48 this.canFinish = canFinish;
49 }
50
51 /**
52 * Retrive the model object from the wizard.
53 * @return
54 */
55 public abstract Map getModel();
56}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
new file mode 100644
index 0000000..a83a389
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
@@ -0,0 +1,149 @@
1package org.yocto.bc.ui.wizards;
2import java.util.Map;
3
4import org.eclipse.jface.viewers.ISelectionChangedListener;
5import org.eclipse.jface.viewers.SelectionChangedEvent;
6import org.eclipse.jface.wizard.WizardPage;
7import org.eclipse.swt.events.ModifyEvent;
8import org.eclipse.swt.events.ModifyListener;
9import org.eclipse.swt.events.SelectionEvent;
10import org.eclipse.swt.events.SelectionListener;
11import org.eclipse.swt.widgets.Composite;
12import org.eclipse.swt.widgets.Event;
13import org.eclipse.swt.widgets.Listener;
14
15public abstract class FiniteStateWizardPage extends WizardPage {
16 protected Map model = null;
17 protected FiniteStateWizard wizard = null;
18 private static boolean previousState = false;
19 /**
20 * @param pageName
21 */
22 protected FiniteStateWizardPage(String name, Map model) {
23 super(name);
24 this.model = model;
25 this.setPageComplete(false);
26 }
27
28 /*
29 * (non-Javadoc)
30 *
31 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
32 */
33 public abstract void createControl(Composite parent);
34
35 protected void setModelWizard() {
36 if (wizard == null) {
37 wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard();
38 }
39 }
40
41 /**
42 * Add page validation logic here. Returning <code>true</code> means that
43 * the page is complete and the user can go to the next page.
44 *
45 * @return
46 */
47 protected abstract boolean validatePage();
48
49 /**
50 * This method should be implemented by ModelWizardPage classes. This method
51 * is called after the <code>validatePage()</code> returns successfully.
52 * Update the model with the contents of the controls on the page.
53 */
54 protected abstract void updateModel();
55
56 /**
57 * Helper method to see if a field has some sort of text in it.
58 * @param value
59 * @return
60 */
61 protected boolean hasContents(String value) {
62 if (value == null || value.length() == 0) {
63 return false;
64 }
65
66 return true;
67 }
68
69 /**
70 * This method is called right before a page is displayed.
71 * This occurs on user action (Next/Back buttons).
72 */
73 public abstract void pageDisplay();
74
75 /**
76 * This method is called on the concrete WizardPage after the user has
77 * gone to the page after.
78 */
79 public abstract void pageCleanup();
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
83 */
84 public void setVisible(boolean arg0) {
85
86 if (!arg0 && previousState) {
87 pageCleanup();
88 } else if (arg0 && !previousState) {
89 pageDisplay();
90 } else if (arg0 && previousState) {
91 pageDisplay();
92 }
93
94 previousState = arg0;
95
96 super.setVisible(arg0);
97 }
98
99 public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener {
100
101 /*
102 * (non-Javadoc)
103 *
104 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
105 */
106 public void widgetSelected(SelectionEvent e) {
107 validate();
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
114 */
115 public void widgetDefaultSelected(SelectionEvent e) {
116 }
117
118 /*
119 * (non-Javadoc)
120 *
121 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
122 */
123 public void modifyText(ModifyEvent e) {
124 validate();
125 }
126
127 public void validate() {
128 if (validatePage()) {
129 updateModel();
130 setPageComplete(true);
131 return;
132 }
133
134 setPageComplete(false);
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
139 */
140 public void handleEvent(Event event) {
141
142 validate();
143 }
144
145 public void selectionChanged(SelectionChangedEvent event) {
146 validate();
147 }
148 }
149}
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
new file mode 100644
index 0000000..14b268b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java
@@ -0,0 +1,215 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards;
13
14import java.io.ByteArrayInputStream;
15import java.io.IOException;
16import java.io.InputStream;
17import java.io.File;
18import java.lang.reflect.InvocationTargetException;
19import java.util.ArrayList;
20
21import org.eclipse.core.resources.IContainer;
22import org.eclipse.core.resources.IFile;
23import org.eclipse.core.resources.IResource;
24import org.eclipse.core.resources.IWorkspaceRoot;
25import org.eclipse.core.resources.ResourcesPlugin;
26import org.eclipse.core.runtime.CoreException;
27import org.eclipse.core.runtime.IProgressMonitor;
28import org.eclipse.core.runtime.IStatus;
29import org.eclipse.core.runtime.Path;
30import org.eclipse.core.runtime.Status;
31import org.eclipse.jface.dialogs.MessageDialog;
32import org.eclipse.jface.operation.IRunnableWithProgress;
33import org.eclipse.jface.viewers.ISelection;
34import org.eclipse.jface.viewers.IStructuredSelection;
35import org.eclipse.jface.wizard.Wizard;
36import org.eclipse.ui.INewWizard;
37import org.eclipse.ui.IWorkbench;
38import org.eclipse.ui.IWorkbenchPage;
39import org.eclipse.ui.IWorkbenchWizard;
40import org.eclipse.ui.PartInitException;
41import org.eclipse.ui.PlatformUI;
42import org.eclipse.ui.ide.IDE;
43
44import org.yocto.bc.bitbake.BBLanguageHelper;
45
46public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard {
47 private NewBitBakeFileRecipeWizardPage page;
48 private ISelection selection;
49
50 public NewBitBakeFileRecipeWizard() {
51 super();
52 setNeedsProgressMonitor(true);
53 }
54
55 @Override
56 public void addPages() {
57 page = new NewBitBakeFileRecipeWizardPage(selection);
58 addPage(page);
59 }
60
61 private void doFinish(BitbakeRecipeUIElement element, IProgressMonitor monitor) throws CoreException {
62 String fileName = element.getFile();
63 monitor.beginTask("Creating " + fileName, 2);
64 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
65 IResource resource = root.findMember(new Path(element.getContainer()));
66 if (!resource.exists() || !(resource instanceof IContainer)) {
67 throwCoreException("Container \"" + element.getContainer() + "\" does not exist.");
68 }
69 IContainer container = (IContainer) resource;
70
71 // If the extension wasn't specified, assume .bb
72 if (!fileName.endsWith(".bb") && !fileName.endsWith(".inc") && !fileName.endsWith(".conf")) {
73 fileName = fileName + ".bb";
74 }
75
76 final IFile file = container.getFile(new Path(fileName));
77 try {
78 InputStream stream = openContentStream(element);
79 if (file.exists()) {
80 file.setContents(stream, true, true, monitor);
81 } else {
82 file.create(stream, true, monitor);
83 }
84 stream.close();
85 } catch (IOException e) {
86 }
87 monitor.worked(1);
88 monitor.setTaskName("Opening file for editing...");
89 getShell().getDisplay().asyncExec(new Runnable() {
90 public void run() {
91 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
92 try {
93 IDE.openEditor(page, file, true);
94 } catch (PartInitException e) {
95 }
96 }
97 });
98 monitor.worked(1);
99 }
100
101 /**
102 * We will accept the selection in the workbench to see if we can initialize
103 * from it.
104 *
105 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
106 */
107 public void init(IWorkbench workbench, IStructuredSelection selection) {
108 this.selection = selection;
109 }
110
111 /**
112 * We will initialize file contents with a sample text.
113 * @param srcuri
114 * @param author
115 * @param homepage
116 * @param license
117 * @param description
118 * @param fileName
119 * @param newPage
120 */
121
122 private InputStream openContentStream(BitbakeRecipeUIElement element) {
123
124 StringBuffer sb = new StringBuffer();
125
126 sb.append("DESCRIPTION = \"" + element.getDescription() + "\"\n");
127
128 if (element.getAuthor().length() > 0) {
129 sb.append("AUTHOR = \"" + element.getAuthor() + "\"\n");
130 }
131
132 if (element.getHomePage().length() > 0) {
133 sb.append("HOMEPAGE = \"" + element.getHomePage() + "\"\n");
134 }
135
136 if (element.getSection().length() > 0) {
137 sb.append("SECTION = \"" + element.getSection() + "\"\n");
138 }
139
140 if (element.getLicense().length() > 0) {
141 sb.append("LICENSE = \"" + element.getLicense() + "\"\n");
142 }
143
144 if (element.getChecksum().length() > 0) {
145 sb.append("LIC_FILES_CHKSUM = \"" + element.getChecksum() + "\"\n");
146 }
147
148 if (element.getSrcuri().length() > 0) {
149 sb.append("SRC_URI = \"" + element.getSrcuri() + "\"\n");
150 }
151
152 if (element.getMd5sum().length() > 0) {
153 sb.append("SRC_URI[md5sum] = \"" + element.getMd5sum() + "\"\n");
154 }
155
156 if (element.getsha256sum().length() > 0) {
157 sb.append("SRC_URI[sha256sum] = \"" + element.getsha256sum() + "\"\n");
158 }
159
160 ArrayList<String> inheritance = element.getInheritance();
161 if (!inheritance.isEmpty()) {
162 Object ia[] = inheritance.toArray();
163 String inheritance_str = "inherit ";
164 for(int i=0; i<ia.length; i++)
165 inheritance_str += ((String) ia[i]) + " ";
166 sb.append(inheritance_str);
167 }
168 sb.append("\n");
169
170 return new ByteArrayInputStream(sb.toString().getBytes());
171 }
172
173 @Override
174 public boolean performFinish() {
175 final BitbakeRecipeUIElement element = page.getUIElement();
176
177 IRunnableWithProgress op = new IRunnableWithProgress() {
178 public void run(IProgressMonitor monitor) throws InvocationTargetException {
179 try {
180 doFinish(element, monitor);
181 File temp_dir = new File(element.getMetaDir() + "/temp");
182 if (temp_dir.exists()) {
183 File working_dir = new File(element.getMetaDir());
184
185 String rm_cmd = "rm -rf temp";
186 final Process process = Runtime.getRuntime().exec(rm_cmd, null, working_dir);
187 int returnCode = process.waitFor();
188 if (returnCode != 0) {
189 throw new Exception("Failed to clean up the temp dir");
190 }
191 }
192 } catch (Exception e) {
193 throw new InvocationTargetException(e);
194 } finally {
195 monitor.done();
196 }
197 }
198 };
199 try {
200 getContainer().run(true, false, op);
201 } catch (InterruptedException e) {
202 return false;
203 } catch (InvocationTargetException e) {
204 Throwable realException = e.getTargetException();
205 MessageDialog.openError(getShell(), "Error", realException.getMessage());
206 return false;
207 }
208 return true;
209 }
210
211 private void throwCoreException(String message) throws CoreException {
212 IStatus status = new Status(IStatus.ERROR, "org.yocto.bc.ui", IStatus.OK, message, null);
213 throw new CoreException(status);
214 }
215} \ No newline at end of file
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
new file mode 100644
index 0000000..61878b9
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java
@@ -0,0 +1,543 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards;
13
14import org.eclipse.core.resources.IContainer;
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IResource;
17import org.eclipse.core.resources.ResourcesPlugin;
18import org.eclipse.core.runtime.Path;
19import org.eclipse.core.runtime.IPath;
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.IStructuredSelection;
22import org.eclipse.jface.window.Window;
23import org.eclipse.jface.wizard.WizardPage;
24import org.eclipse.swt.SWT;
25import org.eclipse.swt.events.ModifyEvent;
26import org.eclipse.swt.events.ModifyListener;
27import org.eclipse.swt.events.SelectionAdapter;
28import org.eclipse.swt.events.SelectionEvent;
29import org.eclipse.swt.layout.GridData;
30import org.eclipse.swt.layout.GridLayout;
31import org.eclipse.swt.widgets.Button;
32import org.eclipse.swt.widgets.Composite;
33import org.eclipse.swt.widgets.DirectoryDialog;
34import org.eclipse.swt.widgets.FileDialog;
35import org.eclipse.swt.widgets.Label;
36import org.eclipse.swt.widgets.Text;
37import org.eclipse.ui.dialogs.ContainerSelectionDialog;
38
39import java.util.HashMap;
40import java.util.Hashtable;
41import java.util.Set;
42import java.util.ArrayList;
43import java.util.Enumeration;
44import java.util.Iterator;
45
46import java.io.BufferedReader;
47import java.io.InputStreamReader;
48import java.io.File;
49import java.io.FileReader;
50import java.io.IOException;
51import java.io.FileInputStream;
52import java.io.InputStream;
53import java.io.FilenameFilter;
54import java.security.MessageDigest;
55import java.math.BigInteger;
56
57public class NewBitBakeFileRecipeWizardPage extends WizardPage {
58 private Text containerText;
59 private Text fileText;
60
61 private Text descriptionText;
62 private Text licenseText;
63 private Text checksumText;
64 private Text homepageText;
65 private Text authorText;
66 private Text sectionText;
67 private Text srcuriText;
68 private Text md5sumText;
69 private Text sha256sumText;
70 private BitbakeRecipeUIElement element;
71
72 private ISelection selection;
73 private String metaDirLoc;
74 private ArrayList inheritance;
75
76 public NewBitBakeFileRecipeWizardPage(ISelection selection) {
77 super("wizardPage");
78 setTitle("BitBake Recipe");
79 setDescription("Create a new BitBake recipe.");
80 this.selection = selection;
81 element = new BitbakeRecipeUIElement();
82 inheritance = new ArrayList();
83 }
84
85 public void createControl(Composite parent) {
86 final Composite container = new Composite(parent, SWT.NULL);
87 GridLayout layout = new GridLayout();
88 container.setLayout(layout);
89 layout.numColumns = 3;
90 layout.verticalSpacing = 9;
91
92 Label label = new Label(container, SWT.NULL);
93 GridData gd = new GridData();
94 gd.horizontalSpan = 3;
95 label.setLayoutData(gd);
96
97 label = new Label(container, SWT.NULL);
98 label.setText("Recipe &Directory:");
99
100 containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
101 gd = new GridData(GridData.FILL_HORIZONTAL);
102 containerText.setLayoutData(gd);
103 containerText.addModifyListener(new ModifyListener() {
104 public void modifyText(ModifyEvent e) {
105 dialogChanged();
106 }
107 });
108
109 Button buttonBrowse = new Button(container, SWT.PUSH);
110 buttonBrowse.setText("Browse...");
111 buttonBrowse.addSelectionListener(new SelectionAdapter() {
112 @Override
113 public void widgetSelected(SelectionEvent e) {
114 handleBrowse(container, containerText);
115 }
116 });
117
118 label = new Label(container, SWT.NULL);
119 gd = new GridData();
120 gd.horizontalSpan = 3;
121 label.setLayoutData(gd);
122
123 label = new Label(container, SWT.NULL);
124 label.setText("SRC_&URI:");
125
126 srcuriText = new Text(container, SWT.BORDER | SWT.SINGLE);
127 gd = new GridData(GridData.FILL_HORIZONTAL);
128 srcuriText.setLayoutData(gd);
129 srcuriText.addModifyListener(new ModifyListener() {
130 public void modifyText(ModifyEvent e) {
131 dialogChanged();
132 }
133 });
134
135 Button buttonP = new Button(container, SWT.PUSH);
136 buttonP.setText("Populate...");
137 buttonP.addSelectionListener(new SelectionAdapter() {
138 @Override
139 public void widgetSelected(SelectionEvent e) {
140 handlePopulate();
141 }
142 });
143
144 createField(container, "&Recipe Name:", (fileText = new Text(container, SWT.BORDER | SWT.SINGLE)));
145 createField(container, "SRC_URI[&md5sum]:", (md5sumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
146 createField(container, "SRC_URI[&sha256sum]:", (sha256sumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
147 createField(container, "License File &Checksum:", (checksumText = new Text(container, SWT.BORDER | SWT.SINGLE)));
148 createField(container, "&Package Description:", (descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE)));
149 createField(container, "&License:", (licenseText = new Text(container, SWT.BORDER | SWT.SINGLE)));
150
151 createField(container, "&Homepage:", (homepageText = new Text(container, SWT.BORDER | SWT.SINGLE)));
152 createField(container, "Package &Author:", (authorText = new Text(container, SWT.BORDER | SWT.SINGLE)));
153 createField(container, "&Section:", (sectionText = new Text(container, SWT.BORDER | SWT.SINGLE)));
154
155 initialize();
156 dialogChanged();
157 setControl(container);
158 }
159
160 private void createField(Composite container, String title, Text control) {
161 Label label = new Label(container, SWT.NONE);
162 label.setText(title);
163 label.moveAbove(control);
164
165 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
166 gd.horizontalSpan = 2;
167 control.setLayoutData(gd);
168 control.addModifyListener(new ModifyListener() {
169
170 public void modifyText(ModifyEvent e) {
171 dialogChanged();
172 }
173
174 });
175 }
176
177 private void dialogChanged() {
178 String containerName = containerText.getText();
179 IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(containerName));
180 String fileName = fileText.getText();
181
182 if (containerName.length() == 0) {
183 updateStatus("Directory must be specified");
184 return;
185 }
186
187 if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
188 updateStatus("File container must exist");
189 return;
190 }
191 if (!container.isAccessible()) {
192 updateStatus("Project must be writable");
193 return;
194 }
195
196 IProject project = container.getProject();
197 metaDirLoc = project.getLocation().toString() + "/meta";
198
199 if (fileName.length() == 0) {
200 updateStatus("File name must be specified");
201 return;
202 }
203 if (fileName.contains(" ")) {
204 updateStatus("File name must be valid with no space in it");
205 return;
206 }
207 if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
208 updateStatus("File name must be valid");
209 return;
210 }
211
212 if (descriptionText.getText().length() == 0) {
213 updateStatus("Recipe must have a description");
214 return;
215 }
216
217 if (licenseText.getText().length() == 0) {
218 updateStatus("Recipe must have a license");
219 return;
220 }
221
222 if (srcuriText.getText().length() == 0) {
223 updateStatus("SRC_URI can't be empty");
224 }
225
226 updateStatus(null);
227 }
228
229 public BitbakeRecipeUIElement getUIElement() {
230 element.setAuthor(authorText.getText());
231 element.setChecksum(checksumText.getText());
232 element.setContainer(containerText.getText());
233 element.setDescription(descriptionText.getText());
234 element.setFile(fileText.getText());
235 element.setHomePage(homepageText.getText());
236 element.setLicense(licenseText.getText());
237 element.setMd5sum(md5sumText.getText());
238 element.setSection(sectionText.getText());
239 element.setSha256sum(sha256sumText.getText());
240 element.setSrcuri(srcuriText.getText());
241 element.setInheritance(inheritance);
242 element.setMetaDir(metaDirLoc);
243
244 return element;
245 }
246
247 private void handleBrowse(final Composite parent, final Text text) {
248 ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select project directory");
249 if (dialog.open() == Window.OK) {
250 Object[] result = dialog.getResult();
251 if (result.length == 1) {
252 text.setText(((Path) result[0]).toString());
253 }
254 }
255 }
256
257 private void handlePopulate() {
258 String src_uri = srcuriText.getText();
259 if ((src_uri.startsWith("http://") || src_uri.startsWith("ftp://"))
260 && (src_uri.endsWith("tar.gz") || src_uri.endsWith("tar.bz2"))) {
261
262 HashMap<String, String> mirror_map = createMirrorLookupTable();
263
264 populateRecipeName(src_uri);
265 populateSrcuriChecksum(src_uri);
266 String extractDir = extractPackage(src_uri);
267 populateLicensefileChecksum(extractDir);
268 updateSrcuri(mirror_map, src_uri);
269 populateInheritance(extractDir);
270 } else if (src_uri.startsWith("file://")) {
271 String path_str = src_uri.substring(7);
272 File package_dir = new File(path_str);
273 if (package_dir.isDirectory()) {
274 String package_name = path_str.substring(path_str.lastIndexOf("/")+1);
275 fileText.setText(package_name+".bb");
276 populateLicensefileChecksum(path_str);
277 populateInheritance(path_str);
278 }
279 }
280
281 }
282
283 private String extractPackage(String src_uri) {
284 try {
285 File working_dir = new File(metaDirLoc+"/temp");
286 int idx = src_uri.lastIndexOf("/");
287 String tar_file = src_uri.substring(idx+1);
288 int tar_file_surfix_idx = tar_file.lastIndexOf(".tar");
289 String tar_file_surfix = tar_file.substring(tar_file_surfix_idx);
290 String tar_file_path = metaDirLoc+"/temp/"+tar_file;
291
292 String tar_cmd = "";
293 int tar_idx = 0;
294 if (tar_file_surfix.matches(".tar.gz")) {
295 tar_cmd = "tar -zxvf "+ tar_file_path;
296 tar_idx = tar_file_path.lastIndexOf(".tar.gz");
297 } else if (tar_file_surfix.matches(".tar.bz2")) {
298 tar_idx = tar_file_path.lastIndexOf(".tar.bz2");
299 tar_cmd = "tar -xvf " + tar_file_path;
300 }
301 final Process process = Runtime.getRuntime().exec(tar_cmd, null, working_dir);
302 int returnCode = process.waitFor();
303 if (returnCode == 0) {
304 return tar_file_path.substring(0, tar_idx);
305 }
306 } catch (Exception e) {
307 e.printStackTrace();
308 }
309 return null;
310 }
311
312 private void populateInheritance(String extractDir) {
313 File extract_dir = new File(extractDir);
314
315 File[] files = extract_dir.listFiles();
316 for (File file : files) {
317 if (file.isDirectory())
318 continue;
319 else {
320 if (file.getName().equalsIgnoreCase("cmakelists.txt"))
321 inheritance.add("cmake");
322 else if (file.getName().equalsIgnoreCase("setup.py"))
323 inheritance.add("disutils");
324 else {
325 String pattern = "configure.[ac|.in]";
326 if (file.getName().equalsIgnoreCase("configure.ac") || file.getName().equalsIgnoreCase("configure.in"))
327 inheritance.add("autotools");
328 else
329 continue;
330 }
331 }
332 }
333 }
334
335 private void populateLicensefileChecksum(String extractDir) {
336 String licenseFileChecksum_str = null;
337 String licenseFilePath = null;
338
339 try {
340 File extract_dir = new File(extractDir);
341
342 FilenameFilter copyFilter = new FilenameFilter() {
343 public boolean accept(File dir, String name) {
344 if (name.startsWith("COPYING")) {
345 return true;
346 } else {
347 return false;
348 }
349 }
350 };
351
352 File copyFile = null;
353 File[] files = extract_dir.listFiles(copyFilter);
354 for (File file : files) {
355 if (file.isDirectory())
356 continue;
357 else {
358 copyFile = file;
359 licenseFilePath = file.getCanonicalPath();
360 break;
361 }
362 }
363
364 MessageDigest digest_md5 = MessageDigest.getInstance("MD5");
365 InputStream is = new FileInputStream(copyFile);
366 byte[] buffer = new byte[8192];
367 int read = 0;
368
369 while( (read = is.read(buffer)) > 0) {
370 digest_md5.update(buffer, 0, read);
371 }
372 byte[] md5sum = digest_md5.digest();
373 BigInteger bigInt_md5 = new BigInteger(1, md5sum);
374 licenseFileChecksum_str = bigInt_md5.toString(16);
375 is.close();
376 } catch (Exception e) {
377 throw new RuntimeException("Unable to process file for MD5 calculation", e);
378 }
379
380 if (licenseFileChecksum_str != null) {
381 int idx = licenseFilePath.lastIndexOf("/");
382 String license_file_name = licenseFilePath.substring(idx+1);
383 checksumText.setText("file://"+license_file_name+";md5="+licenseFileChecksum_str);
384 }
385 }
386
387 private void populateSrcuriChecksum(String src_uri) {
388 String md5sum_str = null;
389 String sha256sum_str = null;
390
391 try {
392 File working_dir = new File(metaDirLoc+"/temp");
393 working_dir.mkdir();
394 String download_cmd = "wget " + src_uri;
395 final Process process = Runtime.getRuntime().exec(download_cmd, null, working_dir);
396 int returnCode = process.waitFor();
397 if (returnCode == 0) {
398 int idx = src_uri.lastIndexOf("/");
399 String tar_file = src_uri.substring(idx+1);
400 String tar_file_path = metaDirLoc+"/temp/"+tar_file;
401 MessageDigest digest_md5 = MessageDigest.getInstance("MD5");
402 MessageDigest digest_sha256 = MessageDigest.getInstance("SHA-256");
403 File f = new File(tar_file_path);
404 InputStream is = new FileInputStream(f);
405 byte[] buffer = new byte[8192];
406 int read = 0;
407 try {
408 while( (read = is.read(buffer)) > 0) {
409 digest_md5.update(buffer, 0, read);
410 digest_sha256.update(buffer, 0, read);
411 }
412 byte[] md5sum = digest_md5.digest();
413 byte[] sha256sum = digest_sha256.digest();
414 BigInteger bigInt_md5 = new BigInteger(1, md5sum);
415 BigInteger bigInt_sha256 = new BigInteger(1, sha256sum);
416 md5sum_str = bigInt_md5.toString(16);
417 sha256sum_str = bigInt_sha256.toString(16);
418 }
419 catch(IOException e) {
420 throw new RuntimeException("Unable to process file for MD5", e);
421 }
422 finally {
423 try {
424 is.close();
425 }
426 catch(IOException e) {
427 throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
428 }
429 }
430 if (md5sum_str != null)
431 md5sumText.setText(md5sum_str);
432 if (sha256sum_str != null)
433 sha256sumText.setText(sha256sum_str);
434 }
435 } catch (Exception e) {
436 e.printStackTrace();
437 }
438 }
439
440 private HashMap<String, String> createMirrorLookupTable() {
441 HashMap<String, String> mirror_map = new HashMap<String, String>();
442 File mirror_file = new File(metaDirLoc+"/classes/mirrors.bbclass");
443
444 try {
445 if (mirror_file.exists()) {
446 BufferedReader input = new BufferedReader(new FileReader(mirror_file));
447
448 try
449 {
450 String line = null;
451 String delims = "[\\t]+";
452
453 while ((line = input.readLine()) != null)
454 {
455 String[] tokens = line.split(delims);
456 if (tokens.length < 2)
457 continue;
458 String ending_str = " \\n \\";
459 int idx = tokens[1].lastIndexOf(ending_str);
460 String key = tokens[1].substring(0, idx);
461 mirror_map.put(key, tokens[0]);
462 }
463 }
464 finally {
465 input.close();
466 }
467 }
468 }
469 catch (IOException e)
470 {
471 e.printStackTrace();
472
473 }
474 return mirror_map;
475 }
476
477 private void populateRecipeName(String src_uri) {
478 String file_name = fileText.getText();
479 if (!file_name.isEmpty())
480 return;
481 String delims = "[/]+";
482 String recipe_file = null;
483
484 String[] tokens = src_uri.split(delims);
485 if (tokens.length > 0) {
486 String tar_file = tokens[tokens.length - 1];
487 int surfix_idx = 0;
488 if (tar_file.endsWith(".tar.gz"))
489 surfix_idx = tar_file.lastIndexOf(".tar.gz");
490 else
491 surfix_idx = tar_file.lastIndexOf(".tar.bz2");
492 int sept_idx = tar_file.lastIndexOf("-");
493 recipe_file = tar_file.substring(0, sept_idx)+"_"+tar_file.substring(sept_idx+1, surfix_idx)+".bb";
494 }
495 if (recipe_file != null)
496 fileText.setText(recipe_file);
497 }
498
499 private void updateSrcuri(HashMap<String, String> mirrorsMap, String src_uri) {
500 Set<String> mirrors = mirrorsMap.keySet();
501 Iterator iter = mirrors.iterator();
502 String mirror_key = null;
503
504 while (iter.hasNext()) {
505 String value = (String)iter.next();
506 if (src_uri.startsWith(value)) {
507 mirror_key = value;
508 break;
509 }
510 }
511
512 if (mirror_key != null) {
513 String replace_string = (String)mirrorsMap.get(mirror_key);
514 if (replace_string != null)
515 src_uri = replace_string+src_uri.substring(mirror_key.length());
516 }
517 int idx = src_uri.lastIndexOf("-");
518 String new_src_uri = src_uri.substring(0, idx)+"-${PV}.tar.gz";
519 srcuriText.setText(new_src_uri);
520 }
521
522 private void initialize() {
523 if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
524 IStructuredSelection ssel = (IStructuredSelection) selection;
525 if (ssel.size() > 1)
526 return;
527 Object obj = ssel.getFirstElement();
528 if (obj instanceof IResource) {
529 IContainer container;
530 if (obj instanceof IContainer)
531 container = (IContainer) obj;
532 else
533 container = ((IResource) obj).getParent();
534 containerText.setText(container.getFullPath().toString());
535 }
536 }
537 }
538
539 private void updateStatus(String message) {
540 setErrorMessage(message);
541 setPageComplete(message == null);
542 }
543} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
new file mode 100644
index 0000000..71ea70c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java
@@ -0,0 +1,236 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.importProject;
12
13import java.io.File;
14import java.util.Map;
15
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.resources.IWorkspaceRoot;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.swt.SWT;
22import org.eclipse.swt.events.SelectionAdapter;
23import org.eclipse.swt.events.SelectionEvent;
24import org.eclipse.swt.layout.GridData;
25import org.eclipse.swt.layout.GridLayout;
26import org.eclipse.swt.widgets.Button;
27import org.eclipse.swt.widgets.Composite;
28import org.eclipse.swt.widgets.DirectoryDialog;
29import org.eclipse.swt.widgets.FileDialog;
30import org.eclipse.swt.widgets.Label;
31import org.eclipse.swt.widgets.Text;
32import org.eclipse.ui.PlatformUI;
33
34import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
35
36/**
37 * Main property page for new project wizard.
38 * @author kgilmer
39 *
40 */
41public class BBCProjectPage extends FiniteStateWizardPage {
42
43 private class FileOpenSelectionAdapter extends SelectionAdapter {
44 @Override
45 public void widgetSelected(SelectionEvent e) {
46 FileDialog fd = new FileDialog(PlatformUI.getWorkbench()
47 .getDisplay().getActiveShell(), SWT.OPEN);
48
49 fd.setText("Open Configuration Script");
50 fd.setFilterPath(txtProjectLocation.getText());
51
52 String selected = fd.open();
53
54 if (selected != null) {
55 txtInit.setText(selected);
56 updateModel();
57 }
58 }
59 }
60 public static final String PAGE_TITLE = "Yocto Project BitBake Commander Project";
61 private Text txtProjectLocation;
62
63 private Text txtInit;
64 private ValidationListener validationListener;
65 private Text txtProjectName;
66
67 public BBCProjectPage(Map model) {
68 super(PAGE_TITLE, model);
69 setTitle("Create new Yocto Project BitBake Commander project");
70 setMessage("Enter information to create a BitBake Commander project.");
71 }
72
73 public void createControl(Composite parent) {
74 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
75 GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
76
77 Composite top = new Composite(parent, SWT.NONE);
78 top.setLayoutData(new GridData(GridData.FILL_BOTH));
79 top.setLayout(new GridLayout());
80
81 Composite projectNameComp = new Composite(top, SWT.NONE);
82 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
83 projectNameComp.setLayoutData(gdProjName);
84 projectNameComp.setLayout(new GridLayout(2, false));
85 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
86 lblProjectName.setText("N&ame:");
87
88 txtProjectName = new Text(projectNameComp, SWT.BORDER);
89 txtProjectName.setLayoutData(gdFillH);
90 txtProjectName.setFocus();
91 validationListener = new ValidationListener();
92
93 txtProjectName.addModifyListener(validationListener);
94
95 Label lblProjectLocation = new Label(projectNameComp, SWT.None);
96 lblProjectLocation.setText("&Location:");
97
98 Composite locComposite = new Composite(projectNameComp, SWT.NONE);
99 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END
100 | GridData.FILL_HORIZONTAL);
101 gd.horizontalIndent = 0;
102 locComposite.setLayoutData(gd);
103 GridLayout gl = new GridLayout(2, false);
104 gl.marginWidth = 0;
105 locComposite.setLayout(gl);
106
107 txtProjectLocation = new Text(locComposite, SWT.BORDER);
108 txtProjectLocation.setLayoutData(gdFillH);
109 txtProjectLocation.addModifyListener(validationListener);
110
111 Button button = new Button(locComposite, SWT.PUSH);
112 button.setText("Browse...");
113 button.addSelectionListener(new SelectionAdapter() {
114 @Override
115 public void widgetSelected(SelectionEvent e) {
116 handleBrowse();
117 }
118 });
119
120 Label lblInit = new Label(projectNameComp, SWT.NONE);
121 lblInit.setText("Init Script:");
122
123 Composite initComposite = new Composite(projectNameComp, SWT.NONE);
124 gd = new GridData(GridData.VERTICAL_ALIGN_END
125 | GridData.FILL_HORIZONTAL);
126 gd.horizontalIndent = 0;
127 initComposite.setLayoutData(gd);
128 gl = new GridLayout(2, false);
129 gl.marginWidth = 0;
130 initComposite.setLayout(gl);
131
132 txtInit = new Text(initComposite, SWT.BORDER);
133 GridData gdi = new GridData(GridData.FILL_HORIZONTAL);
134 txtInit.setLayoutData(gdi);
135 txtInit.addModifyListener(validationListener);
136
137 Button btnLoadInit = new Button(initComposite, SWT.PUSH);
138 btnLoadInit.setLayoutData(gdVU);
139 btnLoadInit.setText("Choose...");
140 btnLoadInit.addSelectionListener(new FileOpenSelectionAdapter());
141
142 if (System.getenv("OEROOT") != null) {
143 txtProjectLocation.setText(System.getenv("OEROOT"));
144 }
145
146 setControl(top);
147 }
148
149 private void handleBrowse() {
150 DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None);
151 String dir = dialog.open();
152 if (dir != null) {
153 txtProjectLocation.setText(dir);
154 }
155 }
156
157 private String getFileSegment(String initScriptPath) {
158 //return the first segment of " " seperated array, or full string if no " " exists
159 return initScriptPath.split(" ")[0];
160 }
161
162 private boolean isValidProjectName(String projectName) {
163 if (projectName.indexOf('$') > -1) {
164 return false;
165 }
166
167 return true;
168 }
169
170
171 @Override
172 public void pageCleanup() {
173 // TODO Auto-generated method stub
174
175 }
176
177 @Override
178 public void pageDisplay() {
179 // TODO Auto-generated method stub
180
181 }
182
183 @Override
184 protected void updateModel() {
185 model.put(ImportYoctoProjectWizard.KEY_NAME, txtProjectName.getText());
186 model.put(ImportYoctoProjectWizard.KEY_LOCATION, txtProjectLocation.getText());
187 model.put(ImportYoctoProjectWizard.KEY_INITPATH, txtInit.getText());
188 }
189
190
191 @Override
192 protected boolean validatePage() {
193 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
194
195 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
196
197 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
198 setErrorMessage("Invalid project name: " + txtProjectName.getText());
199 return false;
200 }
201
202 IProject proj = wsroot.getProject(txtProjectName.getText());
203 if (proj.exists()) {
204 setErrorMessage("A project with the name " + txtProjectName.getText()
205 + " already exists");
206 return false;
207 }
208
209 if (txtProjectLocation.getText().trim().length() == 0) {
210 setErrorMessage("Set directory that contains Poky tree");
211 return false;
212 }
213
214 File f = new File(txtProjectLocation.getText());
215 if (!f.exists() || !f.isDirectory()) {
216 setErrorMessage("Invalid Directory");
217 return false;
218 }
219
220 if (txtInit.getText().length() == 0) {
221 setErrorMessage("Set configuration file before BitBake is launched.");
222 return false;
223 }
224
225 File f2 = new File(getFileSegment(txtInit.getText()));
226 if (!f2.exists() || f2.isDirectory()) {
227 setErrorMessage("The configuration file is invalid.");
228 return false;
229 }
230
231 setErrorMessage(null);
232 setMessage("All the entries are valid, press \"Finish\" to create the new yocto bitbake project,"+
233 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
234 return true;
235 }
236}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java
new file mode 100644
index 0000000..b1fc841
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java
@@ -0,0 +1,166 @@
1/*******************************************************************************
2 * Copyright (c) 2011 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.importProject;
12
13import java.io.IOException;
14import java.io.Writer;
15import java.util.Hashtable;
16import java.util.Map;
17
18import org.eclipse.core.runtime.IStatus;
19import org.eclipse.core.runtime.Status;
20import org.eclipse.jface.viewers.IStructuredSelection;
21import org.eclipse.ui.IImportWizard;
22import org.eclipse.ui.IWorkbench;
23import org.eclipse.ui.IWorkbenchPage;
24import org.eclipse.ui.IWorkbenchWindow;
25import org.eclipse.ui.PlatformUI;
26import org.eclipse.ui.console.ConsolePlugin;
27import org.eclipse.ui.console.IConsole;
28import org.eclipse.ui.console.IConsoleConstants;
29import org.eclipse.ui.console.IConsoleManager;
30import org.eclipse.ui.console.IConsoleView;
31import org.eclipse.ui.console.MessageConsole;
32
33import org.yocto.bc.ui.Activator;
34import org.yocto.bc.ui.model.ProjectInfo;
35import org.yocto.bc.ui.wizards.FiniteStateWizard;
36
37import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
38import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
39
40public class ImportYoctoProjectWizard extends FiniteStateWizard implements IImportWizard {
41 protected final static String KEY_OEROOT = "OEROOT";
42 public static final String KEY_NAME = "NAME";
43 public static final String KEY_LOCATION = "LOCATION";
44 public static final String KEY_INITPATH = "INITPATH";
45 protected static final String KEY_PINFO = "PINFO";
46
47 private Map projectModel;
48 private IWorkbench workbench;
49 private IStructuredSelection selection;
50
51 private MessageConsole myConsole;
52
53 public ImportYoctoProjectWizard() {
54 projectModel = new Hashtable();
55 }
56
57 public Map getModel() {
58 return projectModel;
59 }
60
61 @Override
62 public void addPages() {
63 addPage(new BBCProjectPage(projectModel));
64 //addPage(new ConsolePage(projectModel));
65 }
66
67
68 public boolean performFinish() {
69 ProjectInfo pinfo = new ProjectInfo();
70 pinfo.setInitScriptPath((String) projectModel.get(ImportYoctoProjectWizard.KEY_INITPATH));
71 pinfo.setLocation((String) projectModel.get(ImportYoctoProjectWizard.KEY_LOCATION));
72 pinfo.setName((String) projectModel.get(ImportYoctoProjectWizard.KEY_NAME));
73
74 try {
75 ConsoleWriter cw = new ConsoleWriter();
76 this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw));
77 myConsole.newMessageStream().println(cw.getContents());
78 } catch (Exception e) {
79 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
80 this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage());
81 //valid = false;
82 //setPageComplete(valid);
83 return false;
84 }
85
86 //valid = true;
87 projectModel.put(ImportYoctoProjectWizard.KEY_PINFO, pinfo);
88 //setPageComplete(valid);
89 //ProjectInfo pinfo = (ProjectInfo) projectModel.get(KEY_PINFO);
90 Activator.putProjInfo(pinfo.getRootPath(), pinfo);
91 try {
92 getContainer().run(false, false, new CreateBBCProjectOperation(pinfo));
93 } catch (Exception e) {
94 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
95 this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage());
96 return false;
97 }
98
99 return true;
100 }
101
102 public void init(IWorkbench workbench, IStructuredSelection selection) {
103 this.workbench = workbench;
104 this.selection = selection;
105 this.setNeedsProgressMonitor(true);
106 setWindowTitle("BitBake Commander Project");
107
108 myConsole = findConsole("Yocto Console");
109 IWorkbench wb = PlatformUI.getWorkbench();
110 IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
111 IWorkbenchPage page = win.getActivePage();
112 String id = IConsoleConstants.ID_CONSOLE_VIEW;
113 try {
114 IConsoleView view = (IConsoleView) page.showView(id);
115 view.display(myConsole);
116 } catch (Exception e) {
117 e.printStackTrace();
118 }
119 }
120
121 private MessageConsole findConsole(String name) {
122 ConsolePlugin plugin = ConsolePlugin.getDefault();
123 IConsoleManager conMan = plugin.getConsoleManager();
124 IConsole[] existing = conMan.getConsoles();
125 for (int i = 0; i < existing.length; i++)
126 if (name.equals(existing[i].getName()))
127 return (MessageConsole) existing[i];
128 // no console found, so create a new one
129 MessageConsole myConsole = new MessageConsole(name, null);
130 conMan.addConsoles(new IConsole[] { myConsole });
131 return myConsole;
132 }
133
134 private class ConsoleWriter extends Writer {
135
136 private StringBuffer sb;
137
138 public ConsoleWriter() {
139 sb = new StringBuffer();
140 }
141 @Override
142 public void close() throws IOException {
143 }
144
145 public String getContents() {
146 return sb.toString();
147 }
148
149 @Override
150 public void flush() throws IOException {
151 }
152
153 @Override
154 public void write(char[] cbuf, int off, int len) throws IOException {
155 //txtConsole.getText().concat(new String(cbuf));
156 sb.append(cbuf);
157 }
158
159 @Override
160 public void write(String str) throws IOException {
161 sb.append(str);
162 }
163
164 }
165
166}
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
new file mode 100644
index 0000000..f2cb1da
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -0,0 +1,404 @@
1package org.yocto.bc.ui.wizards.install;
2
3import java.io.BufferedReader;
4import java.io.File;
5import java.io.FileInputStream;
6import java.io.FileDescriptor;
7import java.io.InputStream;
8import java.io.IOException;
9import java.io.InputStreamReader;
10import java.io.OutputStream;
11import java.io.Writer;
12import java.util.ArrayList;
13import java.util.Hashtable;
14import java.util.Map;
15import java.util.regex.Matcher;
16import java.util.regex.Pattern;
17import java.lang.reflect.InvocationTargetException;
18import java.net.URL;
19
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.core.runtime.IStatus;
22import org.eclipse.core.runtime.NullProgressMonitor;
23import org.eclipse.core.runtime.Path;
24import org.eclipse.core.runtime.Status;
25import org.eclipse.jface.operation.IRunnableWithProgress;
26import org.eclipse.jface.viewers.IStructuredSelection;
27import org.eclipse.jface.wizard.IWizardPage;
28import org.eclipse.jface.wizard.WizardPage;
29
30import org.eclipse.ui.PlatformUI;
31import org.eclipse.ui.IWorkbench;
32import org.eclipse.ui.IWorkbenchWizard;
33import org.eclipse.ui.IWorkbenchPage;
34import org.eclipse.ui.IWorkbenchWindow;
35import org.eclipse.ui.console.IConsoleConstants;
36import org.eclipse.ui.console.MessageConsole;
37import org.eclipse.ui.console.MessageConsoleStream;
38import org.eclipse.ui.console.ConsolePlugin;
39import org.eclipse.ui.console.IConsoleManager;
40import org.eclipse.ui.console.IConsole;
41import org.eclipse.ui.console.IConsoleView;
42import org.eclipse.ui.progress.IProgressService;
43
44import org.yocto.bc.bitbake.ICommandResponseHandler;
45import org.yocto.bc.bitbake.ShellSession;
46import org.yocto.bc.ui.Activator;
47import org.yocto.bc.ui.model.ProjectInfo;
48import org.yocto.bc.ui.wizards.FiniteStateWizard;
49
50import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
51import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
52
53/**
54 * A wizard for installing a fresh copy of an OE system.
55 *
56 * @author kgilmer
57 *
58 * A Wizard for creating a fresh Yocto bitbake project and new poky build tree from git
59 *
60 * @modified jzhang
61 *
62 */
63public class InstallWizard extends FiniteStateWizard implements
64 IWorkbenchWizard {
65
66 static final String KEY_PINFO = "KEY_PINFO";
67 protected static final String OPTION_MAP = "OPTION_MAP";
68 protected static final String INSTALL_SCRIPT = "INSTALL_SCRIPT";
69 protected static final String INSTALL_DIRECTORY = "Install Directory";
70 protected static final String INIT_SCRIPT = "Init Script";
71
72 protected static final String PROJECT_NAME = "Project Name";
73 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
74 protected static final String DEFAULT_INSTALL_DIR = "~/yocto";
75
76 protected static final String GIT_CLONE = "Git Clone";
77 public static final String VALIDATION_FILE = DEFAULT_INIT_SCRIPT;
78
79 private Map model;
80 private MessageConsole myConsole;
81
82 public InstallWizard() {
83 this.model = new Hashtable();
84 model.put(INSTALL_DIRECTORY, DEFAULT_INSTALL_DIR);
85 model.put(INIT_SCRIPT, DEFAULT_INIT_SCRIPT);
86
87 setWindowTitle("Yocto Project BitBake Commander");
88 setNeedsProgressMonitor(true);
89
90 myConsole = findConsole("Yocto Project Console");
91 IWorkbench wb = PlatformUI.getWorkbench();
92 IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
93 IWorkbenchPage page = win.getActivePage();
94 String id = IConsoleConstants.ID_CONSOLE_VIEW;
95 try {
96 IConsoleView view = (IConsoleView) page.showView(id);
97 view.display(myConsole);
98 } catch (Exception e) {
99 e.printStackTrace();
100 }
101 }
102
103 private MessageConsole findConsole(String name) {
104 ConsolePlugin plugin = ConsolePlugin.getDefault();
105 IConsoleManager conMan = plugin.getConsoleManager();
106 IConsole[] existing = conMan.getConsoles();
107 for (int i = 0; i < existing.length; i++)
108 if (name.equals(existing[i].getName()))
109 return (MessageConsole) existing[i];
110 // no console found, so create a new one
111 MessageConsole myConsole = new MessageConsole(name, null);
112 conMan.addConsoles(new IConsole[] { myConsole });
113 return myConsole;
114 }
115
116 public InstallWizard(IStructuredSelection selection) {
117 model = new Hashtable();
118 }
119
120 /*
121 * @Override public IWizardPage getNextPage(IWizardPage page) { if (page
122 * instanceof WelcomePage) { if (model.containsKey(WelcomePage.ACTION_USE))
123 * { return bbcProjectPage; } } else if (page instanceof ProgressPage) {
124 * return bitbakePage; }
125 *
126 * if (super.getNextPage(page) != null) { System.out.println("next page: " +
127 * super.getNextPage(page).getClass().getName()); } else {
128 * System.out.println("end page"); }
129 *
130 * return super.getNextPage(page); }
131 *
132 * @Override public boolean canFinish() { System.out.println("can finish: "
133 * + super.canFinish()); return super.canFinish(); }
134 */
135 @Override
136 public void addPages() {
137 addPage(new OptionsPage(model));
138 }
139
140 @Override
141 public Map getModel() {
142 return model;
143 }
144
145 @Override
146 public boolean performFinish() {
147 BCCommandResponseHandler cmdOut = new BCCommandResponseHandler(
148 myConsole);
149
150 WizardPage page = (WizardPage) getPage("Options");
151 page.setPageComplete(true);
152 Map options = (Map) model;
153 String install_dir = "";
154 if (options.containsKey(INSTALL_DIRECTORY)) {
155 install_dir = (String) options.get(INSTALL_DIRECTORY);
156 }
157
158 try {
159 if (((Boolean)options.get(GIT_CLONE)).booleanValue()) {
160 String []git_clone_cmd = {"git", "clone", "--progress", "git://git.pokylinux.org/poky.git", install_dir};
161 final Pattern pattern = Pattern.compile("^Receiving objects:\\s*(\\d+)%.*");
162
163 this.getContainer().run(true,true,
164 new LongtimeRunningTask("Checking out Yocto git repository",
165 git_clone_cmd, null, null,
166 cmdOut,
167 new ICalculatePercentage() {
168 public float calWorkloadDone(String info) throws IllegalArgumentException {
169 Matcher m=pattern.matcher(info.trim());
170 if(m.matches()) {
171 return new Float(m.group(1)) / 100;
172 }else {
173 throw new IllegalArgumentException();
174 }
175 }
176 }
177 )
178 );
179 }
180
181 if (!cmdOut.hasError()) {
182
183 String initPath = install_dir + "/"
184 + (String) options.get(INIT_SCRIPT);
185 String prjName = (String) options.get(PROJECT_NAME);
186 ProjectInfo pinfo = new ProjectInfo();
187 pinfo.setInitScriptPath(initPath);
188 pinfo.setLocation(install_dir);
189 pinfo.setName(prjName);
190
191 ConsoleWriter cw = new ConsoleWriter();
192 this.getContainer().run(false, false,
193 new BBConfigurationInitializeOperation(pinfo, cw));
194
195 myConsole.newMessageStream().println(cw.getContents());
196
197 model.put(InstallWizard.KEY_PINFO, pinfo);
198 Activator.putProjInfo(pinfo.getRootPath(), pinfo);
199
200 this.getContainer().run(false, false,
201 new CreateBBCProjectOperation(pinfo));
202 return true;
203 }
204 } catch (Exception e) {
205 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
206 IStatus.ERROR, e.getMessage(), e));
207 this.getContainer().getCurrentPage().setDescription(
208 "Failed to create project: " + e.getMessage());
209 }
210 return false;
211 }
212
213 public void init(IWorkbench workbench, IStructuredSelection selection) {
214 }
215
216 private interface ICalculatePercentage {
217 public float calWorkloadDone(String info) throws IllegalArgumentException;
218 }
219
220 private class LongtimeRunningTask implements IRunnableWithProgress {
221 private String []cmdArray;
222 private String []envp;
223 private File dir;
224 private ICommandResponseHandler handler;
225 private Process p;
226 private String taskName;
227 static public final int TOTALWORKLOAD=100;
228 private int reported_workload;
229 ICalculatePercentage cal;
230
231 public LongtimeRunningTask(String taskName,
232 String []cmdArray, String []envp, File dir,
233 ICommandResponseHandler handler,
234 ICalculatePercentage calculator) {
235 this.taskName=taskName;
236 this.cmdArray=cmdArray;
237 this.envp=envp;
238 this.dir=dir;
239 this.handler=handler;
240 this.p=null;
241 this.cal=calculator;
242 }
243
244 private void reportProgress(IProgressMonitor monitor,String info) {
245 if(cal == null) {
246 monitor.worked(1);
247 }else {
248 float percentage;
249 try {
250 percentage=cal.calWorkloadDone(info);
251 } catch (IllegalArgumentException e) {
252 //can't get percentage
253 return;
254 }
255 int delta=(int) (TOTALWORKLOAD * percentage - reported_workload);
256 if( delta > 0 ) {
257 monitor.worked(delta);
258 reported_workload += delta;
259 }
260 }
261 }
262
263 synchronized public void run(IProgressMonitor monitor)
264 throws InvocationTargetException, InterruptedException {
265
266 boolean cancel=false;
267 reported_workload=0;
268
269 try {
270 monitor.beginTask(taskName, TOTALWORKLOAD);
271
272 p=Runtime.getRuntime().exec(cmdArray,envp,dir);
273 BufferedReader inbr = new BufferedReader(new InputStreamReader(p.getInputStream()));
274 BufferedReader errbr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
275 String info;
276 while (!cancel) {
277 if(monitor.isCanceled())
278 {
279 cancel=true;
280 throw new InterruptedException("User Cancelled");
281 }
282
283 info=null;
284 //reading stderr
285 while (errbr.ready()) {
286 info=errbr.readLine();
287 //some application using stderr to print out information
288 handler.response(info, false);
289 }
290 //reading stdout
291 while (inbr.ready()) {
292 info=inbr.readLine();
293 handler.response(info, false);
294 }
295
296 //report progress
297 if(info!=null)
298 reportProgress(monitor,info);
299
300 //check if exit
301 try {
302 int exitValue=p.exitValue();
303 if (exitValue != 0) {
304 handler.response(
305 taskName + " failed with the return value " + new Integer(exitValue).toString(),
306 true);
307 }
308 break;
309 }catch (IllegalThreadStateException e) {
310 }
311
312 Thread.sleep(500);
313 }
314 } catch (IOException e) {
315 throw new InvocationTargetException(e);
316 } finally {
317 monitor.done();
318 if (p != null ) {
319 p.destroy();
320 }
321 }
322 }
323 }
324
325 private class BCCommandResponseHandler implements ICommandResponseHandler {
326 private MessageConsoleStream myConsoleStream;
327 private Boolean errorOccured = false;
328
329 public BCCommandResponseHandler(MessageConsole console) {
330 try {
331 this.myConsoleStream = console.newMessageStream();
332 } catch (Exception e) {
333 e.printStackTrace();
334 }
335 }
336
337 public void printDialog(String msg) {
338 try {
339 myConsoleStream.println(msg);
340 } catch (Exception e) {
341 e.printStackTrace();
342 }
343 }
344
345 public Boolean hasError() {
346 return errorOccured;
347 }
348
349 public void response(String line, boolean isError) {
350 try {
351 if (isError) {
352 myConsoleStream.println(line);
353 errorOccured = true;
354 } else {
355 myConsoleStream.println(line);
356 }
357 } catch (Exception e) {
358 e.printStackTrace();
359 }
360 }
361
362 public void printCmd(String cmd) {
363 try {
364 myConsoleStream.println(cmd);
365 } catch (Exception e) {
366 e.printStackTrace();
367 }
368 }
369 }
370
371 private class ConsoleWriter extends Writer {
372
373 private StringBuffer sb;
374
375 public ConsoleWriter() {
376 sb = new StringBuffer();
377 }
378
379 @Override
380 public void close() throws IOException {
381 }
382
383 public String getContents() {
384 return sb.toString();
385 }
386
387 @Override
388 public void flush() throws IOException {
389 }
390
391 @Override
392 public void write(char[] cbuf, int off, int len) throws IOException {
393 // txtConsole.getText().concat(new String(cbuf));
394 sb.append(cbuf);
395 }
396
397 @Override
398 public void write(String str) throws IOException {
399 sb.append(str);
400 }
401
402 }
403
404}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
new file mode 100644
index 0000000..2844fda
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
@@ -0,0 +1,247 @@
1package org.yocto.bc.ui.wizards.install;
2
3import java.io.IOException;
4import java.io.File;
5import java.net.URI;
6import java.util.ArrayList;
7import java.util.Hashtable;
8import java.util.Iterator;
9import java.util.List;
10import java.util.Map;
11
12import org.eclipse.core.resources.IProject;
13import org.eclipse.core.resources.IProjectDescription;
14import org.eclipse.core.resources.IResource;
15import org.eclipse.core.resources.IWorkspaceRoot;
16import org.eclipse.core.resources.ResourcesPlugin;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.core.runtime.IStatus;
19import org.eclipse.swt.SWT;
20import org.eclipse.swt.events.SelectionAdapter;
21import org.eclipse.swt.events.SelectionEvent;
22import org.eclipse.swt.layout.GridData;
23import org.eclipse.swt.layout.GridLayout;
24import org.eclipse.swt.widgets.Button;
25import org.eclipse.swt.widgets.Composite;
26import org.eclipse.swt.widgets.Control;
27import org.eclipse.swt.widgets.DirectoryDialog;
28import org.eclipse.swt.widgets.FileDialog;
29import org.eclipse.swt.widgets.Label;
30import org.eclipse.swt.widgets.Text;
31import org.eclipse.ui.PlatformUI;
32
33import org.yocto.bc.ui.wizards.FiniteStateWizard;
34import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
35import org.yocto.bc.ui.wizards.FiniteStateWizardPage.ValidationListener;
36
37/**
38 * Select which flavor of OE is to be installed.
39 *
40 * @author kgilmer
41 *
42 * Setting up the parameters for creating the new Yocto Bitbake project
43 *
44 * @modified jzhang
45 */
46public class OptionsPage extends FiniteStateWizardPage {
47
48 private Map vars;
49 private Composite c1;
50 private Composite top;
51
52 private List controlList;
53 private boolean controlsCreated = false;
54
55 private Text txtProjectLocation;
56
57 private Text txtInit;
58 private ValidationListener validationListener;
59 private Text txtProjectName;
60 private Button gitButton;
61
62 protected OptionsPage(Map model) {
63 super("Options", model);
64 //setTitle("Create new yocto bitbake project");
65 setMessage("Enter these parameters to create new Yocto Project BitBake commander project");
66 }
67
68 @Override
69 public void createControl(Composite parent) {
70 top = new Composite(parent, SWT.None);
71 top.setLayout(new GridLayout());
72 top.setLayoutData(new GridData(GridData.FILL_BOTH));
73
74 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
75 GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
76
77 Composite projectNameComp = new Composite(top, SWT.NONE);
78 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
79 projectNameComp.setLayoutData(gdProjName);
80 projectNameComp.setLayout(new GridLayout(2, false));
81 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
82 lblProjectName.setText("Project N&ame:");
83
84 txtProjectName = new Text(projectNameComp, SWT.BORDER);
85 txtProjectName.setLayoutData(gdFillH);
86 txtProjectName.setFocus();
87 validationListener = new ValidationListener();
88
89 txtProjectName.addModifyListener(validationListener);
90
91 Label lblProjectLocation = new Label(projectNameComp, SWT.None);
92 lblProjectLocation.setText("&Project Location:");
93
94 Composite locComposite = new Composite(projectNameComp, SWT.NONE);
95 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END
96 | GridData.FILL_HORIZONTAL);
97 gd.horizontalIndent = 0;
98 locComposite.setLayoutData(gd);
99 GridLayout gl = new GridLayout(2, false);
100 gl.marginWidth = 0;
101 locComposite.setLayout(gl);
102
103 txtProjectLocation = new Text(locComposite, SWT.BORDER);
104 txtProjectLocation.setLayoutData(gdFillH);
105 txtProjectLocation.addModifyListener(validationListener);
106
107 Button button = new Button(locComposite, SWT.PUSH);
108 button.setText("Browse...");
109 button.addSelectionListener(new SelectionAdapter() {
110 @Override
111 public void widgetSelected(SelectionEvent e) {
112 handleBrowse();
113 }
114 });
115
116 //Label lblGit = new Label(projectNameComp, SWT.None);
117 //lblGit.setText("Clone from &Git Repository?");
118
119 Composite gitComposite = new Composite(projectNameComp, SWT.NONE);
120 gd = new GridData(GridData.VERTICAL_ALIGN_END
121 | GridData.FILL_HORIZONTAL);
122 gd.horizontalIndent = 0;
123 gitComposite.setLayoutData(gd);
124 gl = new GridLayout(1, false);
125 gl.marginWidth = 0;
126 gitComposite.setLayout(gl);
127
128 gitButton = new Button(gitComposite, SWT.CHECK);
129 gitButton.setText("Clone from Yocto Project &Git Repository");
130 gitButton.setEnabled(true);
131 gitButton.addSelectionListener(validationListener);
132
133 setControl(top);
134 }
135
136 private void handleBrowse() {
137 DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None);
138 String dir = dialog.open();
139 if (dir != null) {
140 txtProjectLocation.setText(dir);
141 }
142 }
143
144 @Override
145 public void pageCleanup() {
146
147 }
148
149 @Override
150 public void pageDisplay() {
151 }
152
153 @Override
154
155 protected void updateModel() {
156 model.put(InstallWizard.INSTALL_DIRECTORY, txtProjectLocation.getText()+File.separator+txtProjectName.getText());
157 model.put(InstallWizard.PROJECT_NAME, txtProjectName.getText());
158 model.put(InstallWizard.GIT_CLONE, new Boolean(gitButton.getSelection()));
159 }
160
161 private boolean isValidProjectName(String projectName) {
162 if (projectName.indexOf('$') > -1) {
163 return false;
164 }
165
166 return true;
167 }
168 @Override
169 protected boolean validatePage() {
170 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
171
172 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
173
174 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
175 setErrorMessage("Invalid project name: " + txtProjectName.getText());
176 return false;
177 }
178
179 IProject proj = wsroot.getProject(txtProjectName.getText());
180 if (proj.exists()) {
181 setErrorMessage("A project with the name " + txtProjectName.getText()
182 + " already exists");
183 return false;
184 }
185
186 String projectLoc = txtProjectLocation.getText();
187 File checkProject_dir = new File(projectLoc);
188 if (!checkProject_dir.isDirectory()) {
189 setErrorMessage("The project location directory " + txtProjectLocation.getText() + " is not valid");
190 return false;
191 }
192
193 String projectPath = projectLoc + File.separator+txtProjectName.getText();
194 File git_dir=new File(projectPath);
195 if(!gitButton.getSelection()) {
196 if(!git_dir.isDirectory() || !git_dir.exists()) {
197 setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " does not exist, please select git clone.");
198 return false;
199 }else if(!new File(projectPath + File.separator + InstallWizard.VALIDATION_FILE).exists()) {
200 setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " seems invalid, please use other directory or project name.");
201 return false;
202 }
203 }else {
204 // git check
205 if(git_dir.exists()) {
206 setErrorMessage("Directory " + txtProjectLocation.getText()+File.separator+txtProjectName.getText() + " exists, please unselect git clone.");
207 return false;
208 }
209 }
210
211 try {
212 URI location = new URI("file://" + txtProjectLocation.getText()+File.separator+txtProjectName.getText());
213
214 IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocationURI(proj, location);
215 if (!status.isOK()) {
216 setErrorMessage(status.getMessage());
217 return false;
218 }
219 } catch (Exception e) {
220 setErrorMessage("Run into error while trying to validate entries!");
221 return false;
222 }
223 setErrorMessage(null);
224 setMessage("All the entries are valid, press \"Finish\" to start the process, "+
225 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
226 return true;
227 }
228
229 private class FileOpenSelectionAdapter extends SelectionAdapter {
230 @Override
231 public void widgetSelected(SelectionEvent e) {
232 FileDialog fd = new FileDialog(PlatformUI.getWorkbench()
233 .getDisplay().getActiveShell(), SWT.OPEN);
234
235 fd.setText("Open Configuration Script");
236 fd.setFilterPath(txtProjectLocation.getText());
237
238 String selected = fd.open();
239
240 if (selected != null) {
241 txtInit.setText(selected);
242 updateModel();
243 }
244 }
245 }
246
247}
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
new file mode 100644
index 0000000..4f15107
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
@@ -0,0 +1,50 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.newproject;
12
13import java.io.Writer;
14import java.lang.reflect.InvocationTargetException;
15
16import org.eclipse.core.runtime.IProgressMonitor;
17import org.eclipse.jface.operation.IRunnableWithProgress;
18
19import org.yocto.bc.bitbake.BBSession;
20import org.yocto.bc.bitbake.ProjectInfoHelper;
21import org.yocto.bc.ui.Activator;
22import org.yocto.bc.ui.model.ProjectInfo;
23
24public class BBConfigurationInitializeOperation implements IRunnableWithProgress {
25
26 private final ProjectInfo pinfo;
27 private final Writer writer;
28
29 public BBConfigurationInitializeOperation(ProjectInfo pinfo) {
30 this.pinfo = pinfo;
31 writer = null;
32 }
33
34 public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) {
35 this.pinfo = pinfo;
36 this.writer = writer;
37 }
38
39 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
40 BBSession session;
41 try {
42 ProjectInfoHelper.store(pinfo.getRootPath(), pinfo);
43 session = Activator.getBBSession(pinfo.getRootPath(), writer);
44 session.initialize();
45
46 } catch (Exception e) {
47 throw new InvocationTargetException(e);
48 }
49 }
50}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java
new file mode 100644
index 0000000..dc0153b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java
@@ -0,0 +1,102 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Ken Gilmer - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.newproject;
12
13import java.io.IOException;
14import java.lang.reflect.InvocationTargetException;
15import java.net.URI;
16import java.net.URISyntaxException;
17import java.util.Arrays;
18import java.util.Vector;
19
20import org.eclipse.core.resources.IProject;
21import org.eclipse.core.resources.IProjectDescription;
22import org.eclipse.core.resources.IWorkspace;
23import org.eclipse.core.resources.IWorkspaceRoot;
24import org.eclipse.core.resources.ResourcesPlugin;
25import org.eclipse.core.runtime.CoreException;
26import org.eclipse.core.runtime.IProgressMonitor;
27import org.eclipse.core.runtime.IStatus;
28import org.eclipse.core.runtime.QualifiedName;
29import org.eclipse.core.runtime.Status;
30import org.eclipse.ui.actions.WorkspaceModifyOperation;
31
32import org.yocto.bc.bitbake.ProjectInfoHelper;
33import org.yocto.bc.ui.Activator;
34import org.yocto.bc.ui.builder.BitbakeCommanderNature;
35import org.yocto.bc.ui.model.ProjectInfo;
36
37
38/**
39 * Creates a bbc project
40 * @author kgilmer
41 *
42 */
43public class CreateBBCProjectOperation extends WorkspaceModifyOperation {
44
45 public static final String OEFS_SCHEME = "OEFS://";
46 public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT");
47 public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException {
48 IProjectDescription desc = proj.getDescription();
49 Vector natureIds = new Vector();
50
51 natureIds.add(nature_id);
52 natureIds.addAll(Arrays.asList(desc.getNatureIds()));
53 desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()]));
54
55 proj.setDescription(desc, monitor);
56 }
57
58 private ProjectInfo projInfo;
59
60 public CreateBBCProjectOperation(ProjectInfo projInfo) {
61 this.projInfo = projInfo;
62 }
63
64 protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException {
65 addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor);
66 }
67
68 private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo2) throws CoreException {
69 IProjectDescription desc = workspace.newProjectDescription(projInfo2.getProjectName());
70
71 try {
72 desc.setLocationURI(new URI(OEFS_SCHEME + projInfo2.getRootPath()));
73 } catch (URISyntaxException e) {
74 throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to load filesystem.", e));
75 }
76
77 return desc;
78 }
79
80 @Override
81 protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
82 IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo);
83
84 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
85
86 IProject proj = wsroot.getProject(projInfo.getProjectName());
87 proj.create(desc, monitor);
88 try {
89 ProjectInfoHelper.store(proj.getLocationURI().getPath(), projInfo);
90 } catch (IOException e) {
91 throw new InvocationTargetException(e);
92 }
93
94 proj.open(monitor);
95
96 addNatures(proj, monitor);
97 }
98
99 public ProjectInfo getProjectInfo() {
100 return projInfo;
101 }
102}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java
new file mode 100644
index 0000000..810a014
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java
@@ -0,0 +1,262 @@
1package org.yocto.bc.ui.wizards.variable;
2
3import java.util.Comparator;
4import java.util.Map;
5
6import org.eclipse.jface.viewers.ILabelProviderListener;
7import org.eclipse.jface.viewers.IStructuredContentProvider;
8import org.eclipse.jface.viewers.ITableLabelProvider;
9import org.eclipse.jface.viewers.TableViewer;
10import org.eclipse.jface.viewers.Viewer;
11import org.eclipse.jface.viewers.ViewerFilter;
12import org.eclipse.jface.viewers.ViewerSorter;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.events.SelectionAdapter;
15import org.eclipse.swt.events.SelectionEvent;
16import org.eclipse.swt.graphics.Image;
17import org.eclipse.swt.layout.GridData;
18import org.eclipse.swt.layout.GridLayout;
19import org.eclipse.swt.widgets.Composite;
20import org.eclipse.swt.widgets.Table;
21import org.eclipse.swt.widgets.TableColumn;
22import org.eclipse.swt.widgets.Text;
23
24import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
25
26/**
27 * The wizard page for the Variable Wizard.
28 * @author kgilmer
29 *
30 */
31public class VariablePage extends FiniteStateWizardPage {
32
33 private Text txtName;
34 private Text txtValue;
35 private TableViewer viewer;
36 private TableColumn c1;
37 private TableColumn c2;
38
39 protected VariablePage(Map model) {
40 super("Yocto Project BitBake Commander", model);
41 setTitle("Yocto Project BitBake Variable Viewer");
42 setDescription("Sort and fitler global BitBake variables by name or value.");
43 }
44
45 @Override
46 public void createControl(Composite parent) {
47 Composite top = new Composite(parent, SWT.None);
48 top.setLayout(new GridLayout(2, true));
49 top.setLayoutData(new GridData(GridData.FILL_BOTH));
50
51 ValidationListener listener = new ValidationListener();
52
53 txtName = new Text(top, SWT.BORDER);
54 txtName.addModifyListener(listener);
55 txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
56
57 txtValue = new Text(top, SWT.BORDER);
58 txtValue.addModifyListener(listener);
59 txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60
61 viewer = new TableViewer(top);
62
63 Table table = viewer.getTable();
64 table.setLinesVisible(true);
65 table.setHeaderVisible(true);
66 GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
67 data.heightHint = 200;
68 data.horizontalSpan = 2;
69 table.setLayoutData(data);
70 c1 = new TableColumn(table, SWT.NONE);
71 c1.setText("Name");
72 c1.setWidth(200);
73 c1.addSelectionListener(new SelectionAdapter() {
74 public void widgetSelected(SelectionEvent event) {
75 ((VariableViewerSorter) viewer.getSorter()).doSort(0);
76 viewer.refresh();
77 }
78 });
79
80 c2 = new TableColumn(table, SWT.NONE);
81 c2.setText("Value");
82 c2.setWidth(200);
83 c2.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent event) {
85 ((VariableViewerSorter) viewer.getSorter()).doSort(1);
86 viewer.refresh();
87 }
88 });
89
90 viewer.setContentProvider(new VariableContentProvider());
91 viewer.setLabelProvider(new VariableLabelProvider());
92 viewer.setSorter(new VariableViewerSorter());
93
94 viewer.setFilters(new ViewerFilter[] {new MapViewerFilter()});
95 setControl(top);
96 }
97
98 @Override
99 public void pageCleanup() {
100
101 }
102
103 @Override
104 public void pageDisplay() {
105 viewer.setInput(model);
106 }
107
108 @Override
109 protected void updateModel() {
110 viewer.refresh();
111 }
112
113 @Override
114 protected boolean validatePage() {
115 return true;
116 }
117
118 /**
119 * A content provider for the variable wizard dialog.
120 * @author kgilmer
121 *
122 */
123 private class VariableContentProvider implements IStructuredContentProvider {
124
125 public Object[] getElements(Object inputElement) {
126 return model.keySet().toArray();
127 }
128
129 public void dispose() {
130
131 }
132
133 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
134
135 }
136 }
137
138 /**
139 * A label provider for variable wizard dialog.
140 * @author kgilmer
141 *
142 */
143 private class VariableLabelProvider implements ITableLabelProvider {
144
145 public Image getColumnImage(Object element, int columnIndex) {
146 return null;
147 }
148
149 public String getColumnText(Object element, int columnIndex) {
150 String val;
151
152 switch (columnIndex) {
153 case 0:
154 val = element.toString();
155 break;
156 case 1:
157 val = (String) model.get(element);
158 break;
159 default:
160 val = "";
161 break;
162 }
163
164 return val;
165 }
166
167 public void addListener(ILabelProviderListener listener) {
168
169 }
170
171 public void dispose() {
172
173 }
174
175 public boolean isLabelProperty(Object element, String property) {
176 return false;
177 }
178
179 public void removeListener(ILabelProviderListener listener) {
180
181 }
182
183 }
184
185 /**
186 *
187 * A tableviewer sorter found on the internet.
188 *
189 */
190 class VariableViewerSorter extends ViewerSorter {
191 private static final int ASCENDING = 0;
192
193 private static final int DESCENDING = 1;
194
195 private int column;
196
197 private int direction;
198
199 public void doSort(int column) {
200 if (column == this.column) {
201 // Same column as last sort; toggle the direction
202 direction = 1 - direction;
203 } else {
204 // New column; do an ascending sort
205 this.column = column;
206 direction = ASCENDING;
207 }
208 }
209
210 public int compare(Viewer viewer, Object e1, Object e2) {
211 int rc = 0;
212 Comparator c = this.getComparator();
213 // Determine which column and do the appropriate sort
214 switch (column) {
215 case 0:
216 rc = c.compare(e1, e2);
217 break;
218 case 1:
219 rc = c.compare(model.get(e1), model.get(e2));
220 break;
221 }
222
223 // If descending order, flip the direction
224 if (direction == DESCENDING)
225 rc = -rc;
226
227 return rc;
228 }
229 }
230
231 /**
232 * A filter for the name/value model.
233 * @author kgilmer
234 *
235 */
236 private class MapViewerFilter extends ViewerFilter {
237
238 public MapViewerFilter() {
239 }
240
241 @Override
242 public boolean select(Viewer viewer, Object parentElement, Object element) {
243 String keyFilter = txtName.getText();
244 String valFilter = txtValue.getText();
245
246 String elem = (String) element;
247 String val = (String) model.get(element);
248
249 if (keyFilter.length() > 0 && elem.indexOf(keyFilter) == -1 ) {
250 return false;
251 }
252
253 if (valFilter.length() > 0 && val.indexOf(valFilter) == -1 ) {
254 return false;
255 }
256
257 return true;
258 }
259
260 }
261
262}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java
new file mode 100644
index 0000000..d1bee1a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java
@@ -0,0 +1,43 @@
1package org.yocto.bc.ui.wizards.variable;
2
3import java.util.Hashtable;
4import java.util.Map;
5
6import org.eclipse.jface.viewers.IStructuredSelection;
7
8import org.yocto.bc.ui.wizards.FiniteStateWizard;
9
10/**
11 * This wizard is used to view, filter, and search for BitBake variables and variable contents.
12 * @author kgilmer
13 *
14 */
15public class VariableWizard extends FiniteStateWizard {
16
17 private Map model;
18
19 public VariableWizard(Map model) {
20 this.model = model;
21 setWindowTitle("Yocto Project BitBake Commander");
22 }
23
24 public VariableWizard(IStructuredSelection selection) {
25 model = new Hashtable();
26 }
27
28 @Override
29 public void addPages() {
30 addPage(new VariablePage(model));
31 }
32
33 @Override
34 public Map getModel() {
35 return model;
36 }
37
38 @Override
39 public boolean performFinish() {
40 return true;
41 }
42
43}