diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java | 404 | ||||
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java | 247 |
2 files changed, 651 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java 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 @@ | |||
1 | package org.yocto.bc.ui.wizards.install; | ||
2 | |||
3 | import java.io.BufferedReader; | ||
4 | import java.io.File; | ||
5 | import java.io.FileInputStream; | ||
6 | import java.io.FileDescriptor; | ||
7 | import java.io.InputStream; | ||
8 | import java.io.IOException; | ||
9 | import java.io.InputStreamReader; | ||
10 | import java.io.OutputStream; | ||
11 | import java.io.Writer; | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Hashtable; | ||
14 | import java.util.Map; | ||
15 | import java.util.regex.Matcher; | ||
16 | import java.util.regex.Pattern; | ||
17 | import java.lang.reflect.InvocationTargetException; | ||
18 | import java.net.URL; | ||
19 | |||
20 | import org.eclipse.core.runtime.IProgressMonitor; | ||
21 | import org.eclipse.core.runtime.IStatus; | ||
22 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
23 | import org.eclipse.core.runtime.Path; | ||
24 | import org.eclipse.core.runtime.Status; | ||
25 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
26 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
27 | import org.eclipse.jface.wizard.IWizardPage; | ||
28 | import org.eclipse.jface.wizard.WizardPage; | ||
29 | |||
30 | import org.eclipse.ui.PlatformUI; | ||
31 | import org.eclipse.ui.IWorkbench; | ||
32 | import org.eclipse.ui.IWorkbenchWizard; | ||
33 | import org.eclipse.ui.IWorkbenchPage; | ||
34 | import org.eclipse.ui.IWorkbenchWindow; | ||
35 | import org.eclipse.ui.console.IConsoleConstants; | ||
36 | import org.eclipse.ui.console.MessageConsole; | ||
37 | import org.eclipse.ui.console.MessageConsoleStream; | ||
38 | import org.eclipse.ui.console.ConsolePlugin; | ||
39 | import org.eclipse.ui.console.IConsoleManager; | ||
40 | import org.eclipse.ui.console.IConsole; | ||
41 | import org.eclipse.ui.console.IConsoleView; | ||
42 | import org.eclipse.ui.progress.IProgressService; | ||
43 | |||
44 | import org.yocto.bc.bitbake.ICommandResponseHandler; | ||
45 | import org.yocto.bc.bitbake.ShellSession; | ||
46 | import org.yocto.bc.ui.Activator; | ||
47 | import org.yocto.bc.ui.model.ProjectInfo; | ||
48 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
49 | |||
50 | import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation; | ||
51 | import 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 | */ | ||
63 | public 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 @@ | |||
1 | package org.yocto.bc.ui.wizards.install; | ||
2 | |||
3 | import java.io.IOException; | ||
4 | import java.io.File; | ||
5 | import java.net.URI; | ||
6 | import java.util.ArrayList; | ||
7 | import java.util.Hashtable; | ||
8 | import java.util.Iterator; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | import org.eclipse.core.resources.IProject; | ||
13 | import org.eclipse.core.resources.IProjectDescription; | ||
14 | import org.eclipse.core.resources.IResource; | ||
15 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
16 | import org.eclipse.core.resources.ResourcesPlugin; | ||
17 | import org.eclipse.core.runtime.CoreException; | ||
18 | import org.eclipse.core.runtime.IStatus; | ||
19 | import org.eclipse.swt.SWT; | ||
20 | import org.eclipse.swt.events.SelectionAdapter; | ||
21 | import org.eclipse.swt.events.SelectionEvent; | ||
22 | import org.eclipse.swt.layout.GridData; | ||
23 | import org.eclipse.swt.layout.GridLayout; | ||
24 | import org.eclipse.swt.widgets.Button; | ||
25 | import org.eclipse.swt.widgets.Composite; | ||
26 | import org.eclipse.swt.widgets.Control; | ||
27 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
28 | import org.eclipse.swt.widgets.FileDialog; | ||
29 | import org.eclipse.swt.widgets.Label; | ||
30 | import org.eclipse.swt.widgets.Text; | ||
31 | import org.eclipse.ui.PlatformUI; | ||
32 | |||
33 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
34 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
35 | import 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 | */ | ||
46 | public 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 | } | ||