diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards')
11 files changed, 1382 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPAction.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPAction.java new file mode 100644 index 0000000..171f181 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPAction.java | |||
@@ -0,0 +1,32 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * Stores a list of items from the output of a background thread and the error message if something went wrong | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class BSPAction { | ||
9 | private String[] items; | ||
10 | private String message; | ||
11 | |||
12 | BSPAction(String[] items, String message){ | ||
13 | this.setItems(items); | ||
14 | this.setMessage(message); | ||
15 | } | ||
16 | |||
17 | public String[] getItems() { | ||
18 | return items; | ||
19 | } | ||
20 | |||
21 | public void setItems(String[] items) { | ||
22 | this.items = items; | ||
23 | } | ||
24 | |||
25 | public String getMessage() { | ||
26 | return message; | ||
27 | } | ||
28 | |||
29 | public void setMessage(String message) { | ||
30 | this.message = message; | ||
31 | } | ||
32 | } \ No newline at end of file | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPProgressDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPProgressDialog.java new file mode 100644 index 0000000..8d5864c --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPProgressDialog.java | |||
@@ -0,0 +1,47 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | import org.eclipse.core.runtime.IProgressMonitor; | ||
4 | import org.eclipse.jface.dialogs.ProgressMonitorDialog; | ||
5 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
6 | import org.eclipse.swt.widgets.Shell; | ||
7 | |||
8 | /** | ||
9 | * Creates a progress monitor dialog that will run in the background a BSPThread and display a custom message | ||
10 | * @author ioana.grigoropol | ||
11 | * | ||
12 | */ | ||
13 | public class BSPProgressDialog extends ProgressMonitorDialog{ | ||
14 | String displayMessage; | ||
15 | BSPThread getterThread; | ||
16 | Shell shell; | ||
17 | |||
18 | |||
19 | public BSPProgressDialog(Shell parent, BSPThread getterThread, String displayMessage) { | ||
20 | super(parent); | ||
21 | this.shell = parent; | ||
22 | this.getterThread = getterThread; | ||
23 | this.displayMessage = displayMessage; | ||
24 | } | ||
25 | |||
26 | public void run(boolean showProgressDialog){ | ||
27 | try { | ||
28 | if (showProgressDialog) | ||
29 | super.run(true, true, new IRunnableWithProgress(){ | ||
30 | @Override | ||
31 | public void run(IProgressMonitor monitor) { | ||
32 | monitor.beginTask(displayMessage + " ...", 100); | ||
33 | getterThread.run(); | ||
34 | monitor.done(); | ||
35 | } | ||
36 | }); | ||
37 | else | ||
38 | getterThread.run(); | ||
39 | } catch (Exception e) { | ||
40 | getterThread.getBspAction().setMessage(e.getMessage()); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | public BSPAction getBspAction() { | ||
45 | return getterThread.getBspAction(); | ||
46 | } | ||
47 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPThread.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPThread.java new file mode 100644 index 0000000..f6b19ac --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/BSPThread.java | |||
@@ -0,0 +1,92 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | import java.io.BufferedReader; | ||
4 | import java.io.InputStreamReader; | ||
5 | import java.util.ArrayList; | ||
6 | |||
7 | /** | ||
8 | * Receives a command to be run on a separate thread in the background | ||
9 | * It contains an BSPAction object that will collect the output & error | ||
10 | * Output lines are processed and collected into the items of BSPAction | ||
11 | * @author ioana.grigoropol | ||
12 | * | ||
13 | */ | ||
14 | public abstract class BSPThread implements Runnable { | ||
15 | public static final String SUCCESS = "success"; | ||
16 | public static final String ERROR = "error"; | ||
17 | |||
18 | private BSPAction bspAction; | ||
19 | private String command; | ||
20 | |||
21 | /** | ||
22 | * Receives the command to be run in the background | ||
23 | * @param command | ||
24 | */ | ||
25 | public BSPThread(String command) { | ||
26 | this.command = command; | ||
27 | this.bspAction = new BSPAction(null, null); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public void run() { | ||
32 | ArrayList<String> values = new ArrayList<String>(); | ||
33 | |||
34 | try { | ||
35 | ProcessBuilder builder = new ProcessBuilder(new String[] {"bash", "-c", command}); | ||
36 | // redirect error stream to collect both output & error | ||
37 | builder.redirectErrorStream(true); | ||
38 | Process process = builder.start(); | ||
39 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
40 | String line = null; | ||
41 | String errorMessage = ""; | ||
42 | while ( (line = br.readLine()) != null) { | ||
43 | String[] result = processLine(line); | ||
44 | String status = result[0]; | ||
45 | String value = result[1]; | ||
46 | if (status.equals(ERROR) && !value.isEmpty()) { | ||
47 | errorMessage += value; | ||
48 | continue; | ||
49 | } | ||
50 | if (!value.isEmpty()) | ||
51 | values.add(value); | ||
52 | } | ||
53 | int exitVal = process.waitFor(); | ||
54 | |||
55 | // if the background process did not exit with 0 code, we should set the status accordingly | ||
56 | if (exitVal != 0) { | ||
57 | bspAction.setMessage(errorMessage); | ||
58 | bspAction.setItems(null); | ||
59 | } | ||
60 | } catch (Exception e) { | ||
61 | bspAction.setMessage(e.getMessage()); | ||
62 | bspAction.setItems(null); | ||
63 | } | ||
64 | if (!values.isEmpty()) { | ||
65 | bspAction.setMessage(null); | ||
66 | bspAction.setItems(values.toArray(new String[values.size()])); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Each command ran in the background will have a different output and a different way of processing it | ||
72 | * @param line | ||
73 | * @return | ||
74 | */ | ||
75 | protected abstract String[] processLine(String line); | ||
76 | |||
77 | public BSPAction getBspAction() { | ||
78 | return bspAction; | ||
79 | } | ||
80 | |||
81 | public void setBspAction(BSPAction bspAction) { | ||
82 | this.bspAction = bspAction; | ||
83 | } | ||
84 | |||
85 | public String getCommand() { | ||
86 | return command; | ||
87 | } | ||
88 | |||
89 | public void setCommand(String command) { | ||
90 | this.command = command; | ||
91 | } | ||
92 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/ErrorCollectorThread.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/ErrorCollectorThread.java new file mode 100644 index 0000000..d39ac28 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/ErrorCollectorThread.java | |||
@@ -0,0 +1,19 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * BSPThread that ignores the output of the process and returns an error if the process exits with non zero code | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class ErrorCollectorThread extends BSPThread{ | ||
9 | |||
10 | public ErrorCollectorThread(String command) { | ||
11 | super(command); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected String[] processLine(String line) { | ||
16 | return null; | ||
17 | } | ||
18 | |||
19 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelArchGetter.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelArchGetter.java new file mode 100644 index 0000000..833057a --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelArchGetter.java | |||
@@ -0,0 +1,23 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * BSPThread that processes the output of "yocto-bsp list karch" | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class KernelArchGetter extends BSPThread{ | ||
9 | |||
10 | public KernelArchGetter(String command) { | ||
11 | super(command); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected String[] processLine(String line) { | ||
16 | if (line.contains(":")) | ||
17 | return new String[]{SUCCESS, ""}; | ||
18 | line = line.replaceAll("^\\s+", ""); | ||
19 | line = line.replaceAll("\\s+$", ""); | ||
20 | return new String[]{SUCCESS, line}; | ||
21 | } | ||
22 | |||
23 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelBranchesGetter.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelBranchesGetter.java new file mode 100644 index 0000000..4caea2c --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/KernelBranchesGetter.java | |||
@@ -0,0 +1,28 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * BSPThread that processes the output lines from running command "yocto-bsp list" for the selected kernel | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class KernelBranchesGetter extends BSPThread { | ||
9 | |||
10 | public KernelBranchesGetter(String command) { | ||
11 | super(command); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected String[] processLine(String line) { | ||
16 | // [TODO : Ioana]: find a better way to identify error lines | ||
17 | if (!line.startsWith("[")) | ||
18 | return new String[]{ERROR, line + "\n"}; | ||
19 | |||
20 | String[] items = line.split(","); | ||
21 | |||
22 | String value = items[0]; | ||
23 | value = value.replace("[\"", ""); | ||
24 | value = value.replaceAll("\"$", ""); | ||
25 | return new String[]{SUCCESS, value}; | ||
26 | } | ||
27 | |||
28 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/MainPage.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/MainPage.java new file mode 100644 index 0000000..ea6544f --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/MainPage.java | |||
@@ -0,0 +1,498 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2012 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 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.InputStream; | ||
16 | import java.io.InputStreamReader; | ||
17 | |||
18 | import org.eclipse.core.runtime.IStatus; | ||
19 | import org.eclipse.core.runtime.Status; | ||
20 | import org.eclipse.jface.wizard.WizardPage; | ||
21 | import org.eclipse.swt.SWT; | ||
22 | import org.eclipse.swt.events.FocusEvent; | ||
23 | import org.eclipse.swt.events.FocusListener; | ||
24 | import org.eclipse.swt.events.ModifyEvent; | ||
25 | import org.eclipse.swt.events.ModifyListener; | ||
26 | import org.eclipse.swt.events.SelectionAdapter; | ||
27 | import org.eclipse.swt.events.SelectionEvent; | ||
28 | import org.eclipse.swt.layout.GridData; | ||
29 | import org.eclipse.swt.layout.GridLayout; | ||
30 | import org.eclipse.swt.widgets.Button; | ||
31 | import org.eclipse.swt.widgets.Combo; | ||
32 | import org.eclipse.swt.widgets.Composite; | ||
33 | import org.eclipse.swt.widgets.Control; | ||
34 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
35 | import org.eclipse.swt.widgets.Label; | ||
36 | import org.eclipse.swt.widgets.Text; | ||
37 | import org.eclipse.swt.widgets.Widget; | ||
38 | import org.yocto.sdk.remotetools.YoctoBspElement; | ||
39 | |||
40 | /** | ||
41 | * | ||
42 | * Setting up the parameters for creating the new Yocto BSP | ||
43 | * | ||
44 | * @author jzhang | ||
45 | */ | ||
46 | public class MainPage extends WizardPage { | ||
47 | public static final String PAGE_NAME = "Main"; | ||
48 | private static final String KARCH_CMD = "yocto-bsp list karch"; | ||
49 | private static final String QARCH_CMD = "yocto-bsp list qemu property qemuarch"; | ||
50 | private static final String BSP_SCRIPT = "yocto-bsp"; | ||
51 | private static final String PROPERTIES_CMD_PREFIX = "yocto-bsp list "; | ||
52 | private static final String PROPERTIES_CMD_SURFIX = " properties -o "; | ||
53 | private static final String PROPERTIES_FILE = "/tmp/properties.json"; | ||
54 | |||
55 | private Button btnMetadataLoc; | ||
56 | private Text textMetadataLoc; | ||
57 | private Label labelMetadata; | ||
58 | |||
59 | private Button btnBspOutputLoc; | ||
60 | private Text textBspOutputLoc; | ||
61 | private Label labelBspOutput; | ||
62 | |||
63 | private Button btnBuildLoc; | ||
64 | private Text textBuildLoc; | ||
65 | private Label labelBuildLoc; | ||
66 | |||
67 | private boolean buildDirChecked; | ||
68 | private BuildLocationListener buildLocationListener; | ||
69 | |||
70 | private Text textBspName; | ||
71 | private Label labelBspName; | ||
72 | |||
73 | private Combo comboKArch; | ||
74 | private Label labelKArch; | ||
75 | |||
76 | private Combo comboQArch; | ||
77 | private Label labelQArch; | ||
78 | |||
79 | private YoctoBspElement bspElem; | ||
80 | |||
81 | public MainPage(YoctoBspElement element) { | ||
82 | super(PAGE_NAME, "yocto-bsp Main page", null); | ||
83 | |||
84 | setMessage("Enter the required fields(with *) to create new Yocto Project BSP!"); | ||
85 | this.bspElem = element; | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public void createControl(Composite parent) { | ||
90 | setErrorMessage(null); | ||
91 | Composite composite = new Composite(parent, SWT.NONE); | ||
92 | GridLayout layout = new GridLayout(2, false); | ||
93 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
94 | composite.setLayout(layout); | ||
95 | gd.horizontalSpan = 2; | ||
96 | composite.setLayoutData(gd); | ||
97 | |||
98 | labelMetadata = new Label(composite, SWT.NONE); | ||
99 | labelMetadata.setText("Metadata location*: "); | ||
100 | Composite textContainer = new Composite(composite, SWT.NONE); | ||
101 | textContainer.setLayout(new GridLayout(2, false)); | ||
102 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
103 | textMetadataLoc = (Text)addTextControl(textContainer, ""); | ||
104 | textMetadataLoc.setEnabled(false); | ||
105 | textMetadataLoc.addModifyListener(new ModifyListener() { | ||
106 | @Override | ||
107 | public void modifyText(ModifyEvent e) { | ||
108 | controlChanged(e.widget); | ||
109 | } | ||
110 | }); | ||
111 | setBtnMetadataLoc(addFileSelectButton(textContainer, textMetadataLoc)); | ||
112 | |||
113 | labelBuildLoc = new Label(composite, SWT.NONE); | ||
114 | labelBuildLoc.setText("Build location: "); | ||
115 | |||
116 | textContainer = new Composite(composite, SWT.NONE); | ||
117 | textContainer.setLayout(new GridLayout(2, false)); | ||
118 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
119 | |||
120 | textBuildLoc = (Text)addTextControl(textContainer, ""); | ||
121 | buildLocationListener = new BuildLocationListener(""); | ||
122 | textBuildLoc.addFocusListener(buildLocationListener); | ||
123 | |||
124 | setBtnBuilddirLoc(addFileSelectButton(textContainer, textBuildLoc)); | ||
125 | |||
126 | labelBspName = new Label(composite, SWT.NONE); | ||
127 | labelBspName.setText("BSP Name*: "); | ||
128 | |||
129 | textContainer = new Composite(composite, SWT.NONE); | ||
130 | textContainer.setLayout(new GridLayout(2, false)); | ||
131 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
132 | |||
133 | textBspName = (Text)addTextControl(textContainer, ""); | ||
134 | textBspName.addModifyListener(new ModifyListener() { | ||
135 | @Override | ||
136 | public void modifyText(ModifyEvent e) { | ||
137 | controlChanged(e.widget); | ||
138 | } | ||
139 | }); | ||
140 | |||
141 | labelBspOutput = new Label(composite, SWT.NONE); | ||
142 | labelBspOutput.setText("BSP output location: "); | ||
143 | |||
144 | textContainer = new Composite(composite, SWT.NONE); | ||
145 | textContainer.setLayout(new GridLayout(2, false)); | ||
146 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
147 | |||
148 | textBspOutputLoc = (Text)addTextControl(textContainer, ""); | ||
149 | textBspOutputLoc.addModifyListener(new ModifyListener() { | ||
150 | @Override | ||
151 | public void modifyText(ModifyEvent e) { | ||
152 | controlChanged(e.widget); | ||
153 | } | ||
154 | }); | ||
155 | setBtnBspOutLoc(addFileSelectButton(textContainer, textBspOutputLoc)); | ||
156 | |||
157 | labelKArch = new Label(composite, SWT.NONE); | ||
158 | labelKArch.setText("Kernel Architecture*: "); | ||
159 | |||
160 | textContainer = new Composite(composite, SWT.NONE); | ||
161 | textContainer.setLayout(new GridLayout(2, false)); | ||
162 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
163 | |||
164 | comboKArch = new Combo(textContainer, SWT.READ_ONLY); | ||
165 | comboKArch.setLayout(new GridLayout(2, false)); | ||
166 | comboKArch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | ||
167 | comboKArch.setEnabled(false); | ||
168 | comboKArch.addModifyListener(new ModifyListener() { | ||
169 | @Override | ||
170 | public void modifyText(ModifyEvent e) { | ||
171 | controlChanged(e.widget); | ||
172 | } | ||
173 | }); | ||
174 | |||
175 | labelQArch = new Label(composite, SWT.NONE); | ||
176 | labelQArch.setText("Qemu Architecture(* for karch as qemu): "); | ||
177 | labelQArch.setEnabled(false); | ||
178 | |||
179 | textContainer = new Composite(composite, SWT.NONE); | ||
180 | textContainer.setLayout(new GridLayout(2, false)); | ||
181 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
182 | |||
183 | comboQArch = new Combo(textContainer, SWT.READ_ONLY); | ||
184 | comboQArch.setLayout(new GridLayout(2, false)); | ||
185 | comboQArch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | ||
186 | comboQArch.setEnabled(false); | ||
187 | comboQArch.addModifyListener(new ModifyListener() { | ||
188 | @Override | ||
189 | public void modifyText(ModifyEvent e) { | ||
190 | controlChanged(e.widget); | ||
191 | } | ||
192 | }); | ||
193 | |||
194 | setControl(composite); | ||
195 | validatePage(); | ||
196 | } | ||
197 | |||
198 | private Control addTextControl(final Composite parent, String value) { | ||
199 | final Text text; | ||
200 | |||
201 | text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | ||
202 | text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
203 | text.setText(value); | ||
204 | text.setSize(10, 150); | ||
205 | |||
206 | return text; | ||
207 | } | ||
208 | |||
209 | private Button addFileSelectButton(final Composite parent, final Text text) { | ||
210 | Button button = new Button(parent, SWT.PUSH | SWT.LEAD); | ||
211 | button.setText("Browse..."); | ||
212 | button.addSelectionListener(new SelectionAdapter() { | ||
213 | @Override | ||
214 | public void widgetSelected(SelectionEvent event) { | ||
215 | String dirName = new DirectoryDialog(parent.getShell()).open(); | ||
216 | if (dirName != null) { | ||
217 | text.setText(dirName); | ||
218 | } | ||
219 | } | ||
220 | }); | ||
221 | return button; | ||
222 | } | ||
223 | |||
224 | private void controlChanged(Widget widget) { | ||
225 | Status status = new Status(IStatus.OK, "not_used", 0, "", null); | ||
226 | setErrorMessage(null); | ||
227 | String metadataLoc = textMetadataLoc.getText(); | ||
228 | |||
229 | if (widget == textMetadataLoc) { | ||
230 | resetKarchCombo(); | ||
231 | if (metadataLoc.length() == 0) { | ||
232 | status = new Status(IStatus.ERROR, "not_used", 0, "Meta data location can't be empty!", null); | ||
233 | } else { | ||
234 | File meta_data = new File(metadataLoc); | ||
235 | if (!meta_data.exists() || !meta_data.isDirectory()) { | ||
236 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
237 | "Invalid meta data location: Make sure it exists and is a directory!", null); | ||
238 | } else { | ||
239 | File bspScript = new File(metadataLoc + "/scripts/" + BSP_SCRIPT); | ||
240 | if (!bspScript.exists() || !bspScript.canExecute()) | ||
241 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
242 | "Make sure yocto-bsp exists under \"" + metadataLoc + "/scripts\" and is executable!", null); | ||
243 | else { | ||
244 | kernelArchesHandler(); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | } else if (widget == comboKArch) { | ||
249 | String selection = comboKArch.getText(); | ||
250 | if (!bspElem.getKarch().contentEquals(selection)) | ||
251 | bspElem = new YoctoBspElement(); | ||
252 | if (selection.matches("qemu")) { | ||
253 | labelQArch.setEnabled(true); | ||
254 | comboQArch.setEnabled(true); | ||
255 | } else { | ||
256 | labelQArch.setEnabled(false); | ||
257 | comboQArch.setEnabled(false); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | String buildDir = textBuildLoc.getText(); | ||
262 | String outputDir = textBspOutputLoc.getText(); | ||
263 | String bspName = textBspName.getText(); | ||
264 | |||
265 | if (bspName.contains(" ")) { | ||
266 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
267 | "BSP name contains space which is not allowed!", null); | ||
268 | } | ||
269 | |||
270 | if (!outputDir.isEmpty()){ | ||
271 | if (outputDir.matches(buildDir)) { | ||
272 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
273 | "You've set BSP output directory the same as build directory, please leave output directory empty for this scenario!", null); | ||
274 | } else { | ||
275 | File outputDirectory = new File(outputDir); | ||
276 | if (outputDirectory.exists()){ | ||
277 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
278 | "Your BSP output directory points to an exiting directory!", null); | ||
279 | } | ||
280 | } | ||
281 | } else if (buildDir.startsWith(metadataLoc) && !bspName.isEmpty()) { | ||
282 | String bspDirStr = metadataLoc + "/meta-" + bspName; | ||
283 | File bspDir = new File(bspDirStr); | ||
284 | if (bspDir.exists()) { | ||
285 | status = new Status(IStatus.ERROR, "not_used", 0, | ||
286 | "Your BSP with name: " + bspName + " already exist under directory: " + bspDirStr + ", please change your bsp name!", null); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | if (status.getSeverity() == IStatus.ERROR) | ||
291 | setErrorMessage(status.getMessage()); | ||
292 | |||
293 | getWizard().getContainer().updateButtons(); | ||
294 | canFlipToNextPage(); | ||
295 | } | ||
296 | |||
297 | private Status checkBuildDir() { | ||
298 | |||
299 | String metadataLoc = textMetadataLoc.getText(); | ||
300 | String buildLoc = textBuildLoc.getText(); | ||
301 | |||
302 | if (buildLoc.isEmpty()) { | ||
303 | buildLoc = metadataLoc + "/build"; | ||
304 | return createBuildDir(buildLoc); | ||
305 | } else { | ||
306 | File buildLocDir = new File(buildLoc); | ||
307 | if (!buildLocDir.exists()) { | ||
308 | return createBuildDir(buildLoc); | ||
309 | } else if (buildLocDir.isDirectory()) { | ||
310 | return createBuildDir(buildLoc); | ||
311 | } else { | ||
312 | return new Status(IStatus.ERROR, "not_used", 0, "Invalid build location: Make sure the build location is a directory!", null); | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | |||
317 | private Status createBuildDir(String buildLoc) { | ||
318 | String metadataDir = textMetadataLoc.getText(); | ||
319 | |||
320 | // if we do not change the directory to metadata location the script will be looked into the directory indicated by user.dir system property | ||
321 | // system.property usually points to the location from where eclipse was started | ||
322 | String createBuildDirCmd = "cd " + metadataDir + ";source " + metadataDir + "/oe-init-build-env " + buildLoc; | ||
323 | |||
324 | try { | ||
325 | ProcessBuilder builder = new ProcessBuilder(new String[] {"bash", "-c", createBuildDirCmd}); | ||
326 | Process proc = builder.start(); | ||
327 | InputStream errorStream = proc.getErrorStream(); | ||
328 | InputStreamReader isr = new InputStreamReader(errorStream); | ||
329 | BufferedReader br = new BufferedReader(isr); | ||
330 | String line = null; | ||
331 | String status = ""; | ||
332 | while ( (line = br.readLine()) != null) { | ||
333 | status += line; | ||
334 | } | ||
335 | |||
336 | if (proc.waitFor() != 0) | ||
337 | return new Status(IStatus.ERROR, "not_used", 0, status, null);; | ||
338 | return new Status(IStatus.OK, "not_used", 0, "", null); | ||
339 | } catch (Exception e) { | ||
340 | return new Status(IStatus.ERROR, "not_used", 0, e.getMessage(), null); | ||
341 | } | ||
342 | } | ||
343 | |||
344 | public YoctoBspElement getBSPElement() { | ||
345 | return this.bspElem; | ||
346 | } | ||
347 | |||
348 | |||
349 | private void resetKarchCombo() { | ||
350 | comboKArch.deselectAll(); | ||
351 | comboQArch.deselectAll(); | ||
352 | comboKArch.setEnabled(false); | ||
353 | labelQArch.setEnabled(false); | ||
354 | comboQArch.setEnabled(false); | ||
355 | } | ||
356 | |||
357 | private void kernelArchesHandler() { | ||
358 | BSPAction kArchesAction = getKArches(); | ||
359 | if (kArchesAction.getMessage() == null && kArchesAction.getItems().length != 0) { | ||
360 | comboKArch.setItems(kArchesAction.getItems()); | ||
361 | comboKArch.setEnabled(true); | ||
362 | } else if (kArchesAction.getMessage() != null){ | ||
363 | setErrorMessage(kArchesAction.getMessage()); | ||
364 | return; | ||
365 | } | ||
366 | BSPAction qArchesAction = getQArches(); | ||
367 | if (qArchesAction.getMessage() == null && qArchesAction.getItems().length != 0) { | ||
368 | comboQArch.setItems(qArchesAction.getItems()); | ||
369 | } else if (qArchesAction.getMessage() != null) | ||
370 | setErrorMessage(qArchesAction.getMessage()); | ||
371 | |||
372 | } | ||
373 | |||
374 | @Override | ||
375 | public boolean canFlipToNextPage(){ | ||
376 | String err = getErrorMessage(); | ||
377 | if (err != null) | ||
378 | return false; | ||
379 | else if (!validatePage()) | ||
380 | return false; | ||
381 | return true; | ||
382 | } | ||
383 | |||
384 | |||
385 | public boolean validatePage() { | ||
386 | String metadataLoc = textMetadataLoc.getText(); | ||
387 | String bspname = textBspName.getText(); | ||
388 | String karch = comboKArch.getText(); | ||
389 | String qarch = comboQArch.getText(); | ||
390 | if (metadataLoc.isEmpty() || | ||
391 | bspname.isEmpty() || | ||
392 | karch.isEmpty()) { | ||
393 | return false; | ||
394 | } else if (karch.matches("qemu") && qarch.isEmpty()) { | ||
395 | return false; | ||
396 | } | ||
397 | |||
398 | bspElem.setBspName(bspname); | ||
399 | if (!textBspOutputLoc.getText().isEmpty()) | ||
400 | bspElem.setBspOutLoc(textBspOutputLoc.getText()); | ||
401 | else | ||
402 | bspElem.setBspOutLoc(""); | ||
403 | if (!textBuildLoc.getText().isEmpty()) { | ||
404 | checkBuildDir(); | ||
405 | bspElem.setBuildLoc(textBuildLoc.getText()); | ||
406 | } else { | ||
407 | bspElem.setBuildLoc(metadataLoc + "/build"); | ||
408 | if (!buildDirChecked) { | ||
409 | checkBuildDir(); | ||
410 | buildDirChecked = true; | ||
411 | } | ||
412 | } | ||
413 | bspElem.setMetadataLoc(metadataLoc); | ||
414 | bspElem.setKarch(karch); | ||
415 | bspElem.setQarch(qarch); | ||
416 | |||
417 | |||
418 | if (!bspElem.getValidPropertiesFile()) { | ||
419 | boolean validPropertiesFile = true; | ||
420 | BSPAction action = createPropertiesFile(); | ||
421 | if (action.getMessage() != null) { | ||
422 | validPropertiesFile = false; | ||
423 | setErrorMessage(action.getMessage()); | ||
424 | } | ||
425 | bspElem.setValidPropertiesFile(validPropertiesFile); | ||
426 | } | ||
427 | return true; | ||
428 | } | ||
429 | |||
430 | private BSPAction createPropertiesFile() { | ||
431 | String createPropertiesCmd = bspElem.getMetadataLoc() + "/scripts/" + | ||
432 | PROPERTIES_CMD_PREFIX + bspElem.getKarch() + | ||
433 | PROPERTIES_CMD_SURFIX + PROPERTIES_FILE; | ||
434 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new ErrorCollectorThread(createPropertiesCmd), "Creating properties file "); | ||
435 | progressDialog.run(false); | ||
436 | return progressDialog.getBspAction(); | ||
437 | } | ||
438 | |||
439 | private BSPAction getKArches() { | ||
440 | String getKArchCmd = textMetadataLoc.getText() + "/scripts/" + KARCH_CMD; | ||
441 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new KernelArchGetter(getKArchCmd), "Loading kernel architectures "); | ||
442 | progressDialog.run(false); | ||
443 | return progressDialog.getBspAction(); | ||
444 | } | ||
445 | |||
446 | private BSPAction getQArches() { | ||
447 | String getQArchCmd = textMetadataLoc.getText() + "/scripts/" + QARCH_CMD; | ||
448 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new QemuArchGetter(getQArchCmd), "Loading Qemu architectures "); | ||
449 | progressDialog.run(false); | ||
450 | return progressDialog.getBspAction(); | ||
451 | } | ||
452 | |||
453 | public Button getBtnMetadataLoc() { | ||
454 | return btnMetadataLoc; | ||
455 | } | ||
456 | |||
457 | public void setBtnMetadataLoc(Button btnMetadataLoc) { | ||
458 | this.btnMetadataLoc = btnMetadataLoc; | ||
459 | } | ||
460 | |||
461 | public Button getBtnBspOutLoc() { | ||
462 | return btnBspOutputLoc; | ||
463 | } | ||
464 | |||
465 | public void setBtnBspOutLoc(Button btnBspOutLoc) { | ||
466 | this.btnBspOutputLoc = btnBspOutLoc; | ||
467 | } | ||
468 | |||
469 | public Button getBtnBuilddirLoc() { | ||
470 | return btnBuildLoc; | ||
471 | } | ||
472 | |||
473 | public void setBtnBuilddirLoc(Button btnBuilddirLoc) { | ||
474 | this.btnBuildLoc = btnBuilddirLoc; | ||
475 | } | ||
476 | |||
477 | class BuildLocationListener implements FocusListener{ | ||
478 | String value; | ||
479 | boolean changed; | ||
480 | |||
481 | BuildLocationListener(String value){ | ||
482 | this.value = value; | ||
483 | } | ||
484 | @Override | ||
485 | public void focusGained(FocusEvent e) { | ||
486 | value = ((Text)e.getSource()).getText(); | ||
487 | } | ||
488 | |||
489 | @Override | ||
490 | public void focusLost(FocusEvent e) { | ||
491 | if(!((Text)e.getSource()).getText().equals(value)) { | ||
492 | checkBuildDir(); | ||
493 | buildDirChecked = true; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | } | ||
498 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/OutputCollectorThread.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/OutputCollectorThread.java new file mode 100644 index 0000000..df5fba5 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/OutputCollectorThread.java | |||
@@ -0,0 +1,19 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * BSPThread that returns all the output lines of the process execution | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class OutputCollectorThread extends BSPThread{ | ||
9 | |||
10 | public OutputCollectorThread(String command) { | ||
11 | super(command); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected String[] processLine(String line) { | ||
16 | return new String[]{SUCCESS, line}; | ||
17 | } | ||
18 | |||
19 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java new file mode 100644 index 0000000..18149e7 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java | |||
@@ -0,0 +1,498 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2012 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 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
12 | |||
13 | import java.util.ArrayList; | ||
14 | import java.util.Collections; | ||
15 | import java.util.Enumeration; | ||
16 | import java.util.HashSet; | ||
17 | import java.util.Hashtable; | ||
18 | import java.util.Iterator; | ||
19 | |||
20 | import org.eclipse.jface.dialogs.MessageDialog; | ||
21 | import org.eclipse.jface.wizard.WizardPage; | ||
22 | import org.eclipse.swt.SWT; | ||
23 | import org.eclipse.swt.custom.ScrolledComposite; | ||
24 | import org.eclipse.swt.events.SelectionEvent; | ||
25 | import org.eclipse.swt.events.SelectionListener; | ||
26 | import org.eclipse.swt.layout.GridData; | ||
27 | import org.eclipse.swt.layout.GridLayout; | ||
28 | import org.eclipse.swt.widgets.Button; | ||
29 | import org.eclipse.swt.widgets.Combo; | ||
30 | import org.eclipse.swt.widgets.Composite; | ||
31 | import org.eclipse.swt.widgets.Control; | ||
32 | import org.eclipse.swt.widgets.Group; | ||
33 | import org.eclipse.swt.widgets.Label; | ||
34 | import org.eclipse.swt.widgets.Text; | ||
35 | import org.eclipse.swt.widgets.Widget; | ||
36 | import org.yocto.sdk.remotetools.YoctoBspElement; | ||
37 | import org.yocto.sdk.remotetools.YoctoBspPropertyElement; | ||
38 | import org.yocto.sdk.remotetools.YoctoJSONHelper; | ||
39 | /** | ||
40 | * | ||
41 | * Setting up the parameters for creating the new Yocto BSP | ||
42 | * | ||
43 | * @author jzhang | ||
44 | */ | ||
45 | public class PropertiesPage extends WizardPage { | ||
46 | private static final String PAGE_NAME = "Properties"; | ||
47 | private static final String VALUES_CMD_PREFIX = "yocto-bsp list "; | ||
48 | private static final String VALUES_CMD_SURFIX = " property "; | ||
49 | private static final String KERNEL_CHOICE = "kernel_choice"; | ||
50 | private static final String DEFAULT_KERNEL = "use_default_kernel"; | ||
51 | private static final String SMP_NAME = "smp"; | ||
52 | private static final String EXISTING_KBRANCH_NAME = "existing_kbranch"; | ||
53 | private static final String NEED_NEW_KBRANCH_NAME = "need_new_kbranch"; | ||
54 | private static final String NEW_KBRANCH_NAME = "new_kbranch"; | ||
55 | private static final String QARCH_NAME = "qemuarch"; | ||
56 | |||
57 | private static final String KERNEL_CHOICES = "choices"; | ||
58 | private static final String KERNEL_BRANCHES = "branches"; | ||
59 | |||
60 | private Hashtable<YoctoBspPropertyElement, Control> propertyControlMap; | ||
61 | HashSet<YoctoBspPropertyElement> properties; | ||
62 | |||
63 | private ScrolledComposite composite; | ||
64 | private Composite controlContainer = null; | ||
65 | |||
66 | private YoctoBspElement bspElem = null; | ||
67 | private boolean kArchChanged = false; | ||
68 | |||
69 | private Combo kernelCombo; | ||
70 | private Combo branchesCombo; | ||
71 | |||
72 | private Button newBranchButton; | ||
73 | private Button existingBranchButton; | ||
74 | |||
75 | private Button smpButton; | ||
76 | |||
77 | private Group kGroup = null; | ||
78 | private Group kbGroup = null; | ||
79 | // private Group otherSettingsGroup = null; | ||
80 | private Group propertyGroup = null; | ||
81 | |||
82 | public PropertiesPage(YoctoBspElement element) { | ||
83 | super(PAGE_NAME, "yocto-bsp Properties page", null); | ||
84 | this.bspElem = element; | ||
85 | } | ||
86 | |||
87 | public void onEnterPage(YoctoBspElement element) { | ||
88 | if (!element.getValidPropertiesFile()) { | ||
89 | setErrorMessage("There's no valid properties file created, please choose \"Back\" to reselect kernel architecture!"); | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | if (this.bspElem == null || this.bspElem.getKarch().isEmpty() || !this.bspElem.getKarch().contentEquals(element.getKarch())) { | ||
94 | kArchChanged = true; | ||
95 | } else | ||
96 | kArchChanged = false; | ||
97 | |||
98 | this.bspElem = element; | ||
99 | try { | ||
100 | if (kArchChanged) { | ||
101 | updateKernelValues(KERNEL_CHOICES, KERNEL_CHOICE); | ||
102 | |||
103 | if (propertyGroup != null) { | ||
104 | for (Control cntrl : propertyGroup.getChildren()) { | ||
105 | cntrl.dispose(); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | properties = YoctoJSONHelper.getProperties(); | ||
110 | |||
111 | if (!properties.isEmpty()) { | ||
112 | |||
113 | if (!element.getQarch().isEmpty()) { | ||
114 | YoctoBspPropertyElement qarch_elem = new YoctoBspPropertyElement(); | ||
115 | qarch_elem.setName(QARCH_NAME); | ||
116 | qarch_elem.setValue(element.getQarch()); | ||
117 | properties.add(qarch_elem); | ||
118 | } | ||
119 | |||
120 | propertyControlMap = new Hashtable<YoctoBspPropertyElement, Control>(); | ||
121 | |||
122 | ArrayList<YoctoBspPropertyElement> propertiesList = new ArrayList<YoctoBspPropertyElement>(properties); | ||
123 | Collections.sort(propertiesList, Collections.reverseOrder()); | ||
124 | |||
125 | Iterator<YoctoBspPropertyElement> it = propertiesList.iterator(); | ||
126 | Composite comp = new Composite(propertyGroup, SWT.FILL); | ||
127 | GridLayout layout = new GridLayout(2, false); | ||
128 | GridData data = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1); | ||
129 | comp.setLayoutData(data); | ||
130 | comp.setLayout(layout); | ||
131 | |||
132 | while (it.hasNext()) { | ||
133 | // Get property | ||
134 | YoctoBspPropertyElement propElem = it.next(); | ||
135 | String type = propElem.getType(); | ||
136 | String name = propElem.getName(); | ||
137 | if (type.contentEquals("edit")) { | ||
138 | new Label (propertyGroup, SWT.FILL).setText(name + ":"); | ||
139 | |||
140 | Composite textContainer = new Composite(propertyGroup, SWT.NONE); | ||
141 | textContainer.setLayout(new GridLayout(1, false)); | ||
142 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); | ||
143 | Text text = new Text(textContainer, SWT.BORDER | SWT.SINGLE); | ||
144 | text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
145 | propertyControlMap.put(propElem, text); | ||
146 | |||
147 | } else if (type.contentEquals("boolean")) { | ||
148 | String default_value = propElem.getDefaultValue(); | ||
149 | Composite labelContainer = new Composite(propertyGroup, SWT.NONE); | ||
150 | labelContainer.setLayout(new GridLayout(2, false)); | ||
151 | labelContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, false, 2, 1)); | ||
152 | Button button = new Button(propertyGroup, SWT.CHECK); | ||
153 | button.setText(name); | ||
154 | if (default_value.equalsIgnoreCase("y")) { | ||
155 | button.setSelection(true); | ||
156 | } else | ||
157 | button.setSelection(false); | ||
158 | propertyControlMap.put(propElem, button); | ||
159 | } else if (type.contentEquals("choicelist")) { | ||
160 | new Label (propertyGroup, SWT.NONE).setText(name + ":"); | ||
161 | |||
162 | Composite textContainer = new Composite(propertyGroup, SWT.NONE); | ||
163 | textContainer.setLayout(new GridLayout(1, false)); | ||
164 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); | ||
165 | Combo combo = new Combo(textContainer, SWT.READ_ONLY); | ||
166 | combo.setLayout(new GridLayout(2, false)); | ||
167 | combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
168 | combo.setItems(getBSPComboProperties(name)); | ||
169 | propertyControlMap.put(propElem, combo); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); | ||
174 | composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); | ||
175 | controlContainer.pack(); | ||
176 | this.composite.layout(true, true); | ||
177 | } | ||
178 | } catch (Exception e) { | ||
179 | e.printStackTrace(); | ||
180 | } | ||
181 | |||
182 | |||
183 | } | ||
184 | |||
185 | |||
186 | @Override | ||
187 | public void createControl(Composite parent) { | ||
188 | this.composite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); | ||
189 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); | ||
190 | GridLayout layout = new GridLayout(2, true); | ||
191 | this.composite.setLayout(layout); | ||
192 | |||
193 | gd= new GridData(SWT.FILL, SWT.FILL, true, false); | ||
194 | gd.horizontalSpan = 2; | ||
195 | this.composite.setLayoutData(gd); | ||
196 | |||
197 | setControl(this.composite); | ||
198 | |||
199 | controlContainer = new Composite(composite, SWT.NONE); | ||
200 | controlContainer.setLayout(new GridLayout(1, true)); | ||
201 | controlContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | ||
202 | |||
203 | kGroup = new Group(controlContainer, SWT.FILL); | ||
204 | kGroup.setLayout(new GridLayout(2, false)); | ||
205 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); | ||
206 | kGroup.setLayoutData(data); | ||
207 | kGroup.setText("Kernel Settings:"); | ||
208 | |||
209 | new Label (kGroup, SWT.NONE).setText("Kernel:"); | ||
210 | Composite textContainer = new Composite(kGroup, SWT.NONE); | ||
211 | textContainer.setLayout(new GridLayout(1, false)); | ||
212 | textContainer.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1)); | ||
213 | |||
214 | kernelCombo = new Combo(textContainer, SWT.READ_ONLY); | ||
215 | kernelCombo.setLayout(new GridLayout(2, false)); | ||
216 | kernelCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
217 | |||
218 | kernelCombo.addSelectionListener(new SelectionListener() { | ||
219 | |||
220 | @Override | ||
221 | public void widgetSelected(SelectionEvent e) { | ||
222 | controlChanged(e.widget); | ||
223 | } | ||
224 | |||
225 | @Override | ||
226 | public void widgetDefaultSelected(SelectionEvent e) { | ||
227 | } | ||
228 | }); | ||
229 | |||
230 | kbGroup = new Group(kGroup, SWT.FILL); | ||
231 | kbGroup.setLayout(new GridLayout(2, true)); | ||
232 | data = new GridData(SWT.FILL, SWT.FILL, true, false); | ||
233 | data.horizontalSpan = 2; | ||
234 | kbGroup.setLayoutData(data); | ||
235 | kbGroup.setText("Branch Settings:"); | ||
236 | |||
237 | textContainer = new Composite(kbGroup, SWT.NONE); | ||
238 | textContainer.setLayout(new GridLayout(2, false)); | ||
239 | textContainer.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1)); | ||
240 | |||
241 | new Label(textContainer, SWT.NONE).setText("Kernel branch:"); | ||
242 | |||
243 | branchesCombo = new Combo(textContainer, SWT.READ_ONLY); | ||
244 | branchesCombo.setLayout(new GridLayout(1, false)); | ||
245 | branchesCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
246 | branchesCombo.addSelectionListener(new SelectionListener() { | ||
247 | |||
248 | @Override | ||
249 | public void widgetSelected(SelectionEvent e) { | ||
250 | controlChanged(e.widget); | ||
251 | } | ||
252 | |||
253 | @Override | ||
254 | public void widgetDefaultSelected(SelectionEvent e) { | ||
255 | } | ||
256 | }); | ||
257 | branchesCombo.setSize(200, 200); | ||
258 | |||
259 | newBranchButton = new Button(kbGroup, SWT.RADIO); | ||
260 | newBranchButton.setText("Create a new branch from an existing one"); | ||
261 | newBranchButton.setSelection(true); | ||
262 | newBranchButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); | ||
263 | SelectionListener listener = new SelectionListener() { | ||
264 | @Override | ||
265 | public void widgetDefaultSelected(SelectionEvent e) {} | ||
266 | |||
267 | @Override | ||
268 | public void widgetSelected(SelectionEvent e) { | ||
269 | controlChanged(e.widget); | ||
270 | } | ||
271 | }; | ||
272 | |||
273 | newBranchButton.addSelectionListener(listener); | ||
274 | |||
275 | existingBranchButton = new Button(kbGroup, SWT.RADIO); | ||
276 | existingBranchButton.setText("Use existing branch"); | ||
277 | existingBranchButton.setSelection(false); | ||
278 | existingBranchButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); | ||
279 | existingBranchButton.addSelectionListener(listener); | ||
280 | |||
281 | // otherSettingsGroup = new Group(controlContainer, SWT.FILL); | ||
282 | // otherSettingsGroup.setLayout(new GridLayout(2, true)); | ||
283 | // data = new GridData(SWT.FILL, SWT.FILL, true, false); | ||
284 | // data.horizontalSpan = 2; | ||
285 | // otherSettingsGroup.setLayoutData(data); | ||
286 | // otherSettingsGroup.setText("Other Settings:"); | ||
287 | |||
288 | smpButton = new Button(kGroup, SWT.CHECK); | ||
289 | smpButton.setText("Enable SMP support"); | ||
290 | smpButton.setSelection(true); | ||
291 | |||
292 | propertyGroup = new Group(controlContainer, SWT.NONE); | ||
293 | propertyGroup.setLayout(new GridLayout(2, false)); | ||
294 | data = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1); | ||
295 | propertyGroup.setLayoutData(data); | ||
296 | propertyGroup.setText("BSP specific settings:"); | ||
297 | |||
298 | this.composite.layout(true, true); | ||
299 | |||
300 | composite.setContent(controlContainer); | ||
301 | composite.setExpandHorizontal(true); | ||
302 | composite.setExpandVertical(true); | ||
303 | composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); | ||
304 | controlContainer.pack(); | ||
305 | composite.pack(); | ||
306 | } | ||
307 | |||
308 | @Override | ||
309 | public boolean canFlipToNextPage() { | ||
310 | return false; | ||
311 | } | ||
312 | |||
313 | public HashSet<YoctoBspPropertyElement> getProperties() { | ||
314 | String kcSelection = kernelCombo.getText(); | ||
315 | String kbSelection = branchesCombo.getText(); | ||
316 | YoctoBspPropertyElement kcElement = new YoctoBspPropertyElement(); | ||
317 | kcElement.setName(KERNEL_CHOICE); | ||
318 | kcElement.setValue(kcSelection); | ||
319 | properties.add(kcElement); | ||
320 | YoctoBspPropertyElement defaultElement = new YoctoBspPropertyElement(); | ||
321 | defaultElement.setName(DEFAULT_KERNEL); | ||
322 | defaultElement.setValue("n"); | ||
323 | properties.add(defaultElement); | ||
324 | |||
325 | YoctoBspPropertyElement smpElement = new YoctoBspPropertyElement(); | ||
326 | smpElement.setName(SMP_NAME); | ||
327 | if (smpButton.getSelection()) | ||
328 | smpElement.setValue("y"); | ||
329 | else | ||
330 | smpElement.setValue("n"); | ||
331 | properties.add(smpElement); | ||
332 | |||
333 | YoctoBspPropertyElement newKbElement = new YoctoBspPropertyElement(); | ||
334 | YoctoBspPropertyElement kbElement = new YoctoBspPropertyElement(); | ||
335 | |||
336 | newKbElement.setName(NEED_NEW_KBRANCH_NAME); | ||
337 | if (newBranchButton.getSelection()) { | ||
338 | newKbElement.setValue("y"); | ||
339 | properties.add(newKbElement); | ||
340 | kbElement.setName(NEW_KBRANCH_NAME); | ||
341 | kbElement.setValue(kbSelection); | ||
342 | properties.add(kbElement); | ||
343 | } else { | ||
344 | newKbElement.setValue("n"); | ||
345 | properties.add(newKbElement); | ||
346 | kbElement.setName(EXISTING_KBRANCH_NAME); | ||
347 | kbElement.setValue(kbSelection); | ||
348 | properties.add(kbElement); | ||
349 | } | ||
350 | |||
351 | return properties; | ||
352 | } | ||
353 | |||
354 | public boolean validatePage() { | ||
355 | if (kernelCombo == null) | ||
356 | return false; | ||
357 | |||
358 | if ((kernelCombo != null) && (branchesCombo != null)) { | ||
359 | String kcSelection = kernelCombo.getText(); | ||
360 | String kbSelection = branchesCombo.getText(); | ||
361 | if ((kcSelection == null) || (kbSelection == null) || (kcSelection.isEmpty()) || (kbSelection.isEmpty())) { | ||
362 | setErrorMessage("Please choose a kernel and a specific branch!"); | ||
363 | return false; | ||
364 | } | ||
365 | } | ||
366 | if ((propertyControlMap != null)) { | ||
367 | if (!propertyControlMap.isEmpty()) { | ||
368 | Enumeration<YoctoBspPropertyElement> keys = propertyControlMap.keys(); | ||
369 | while (keys.hasMoreElements()) { | ||
370 | YoctoBspPropertyElement key = keys.nextElement(); | ||
371 | Control control = propertyControlMap.get(key); | ||
372 | String type = key.getType(); | ||
373 | |||
374 | if (type.contentEquals("edit")) { | ||
375 | String text_value = ((Text)control).getText(); | ||
376 | if (text_value == null) { | ||
377 | setErrorMessage("Field "+ key.getName() +" is not set. All of the field on this screen must be set!"); | ||
378 | return false; | ||
379 | } else { | ||
380 | key.setValue(text_value); | ||
381 | } | ||
382 | } else if (type.contentEquals("choicelist")) { | ||
383 | String choice_value = ((Combo)control).getText(); | ||
384 | if (choice_value == null) { | ||
385 | setErrorMessage("Field "+ key.getName() +" is not set. All of the field on this screen must be set!"); | ||
386 | return false; | ||
387 | } else { | ||
388 | key.setValue(choice_value); | ||
389 | } | ||
390 | } else { | ||
391 | boolean button_select = ((Button)control).getSelection(); | ||
392 | if (button_select) | ||
393 | key.setValue("y"); | ||
394 | else | ||
395 | key.setValue("n"); | ||
396 | } | ||
397 | updateProperties(key); | ||
398 | } | ||
399 | } | ||
400 | } | ||
401 | return true; | ||
402 | } | ||
403 | |||
404 | private void updateProperties(YoctoBspPropertyElement element) { | ||
405 | Iterator<YoctoBspPropertyElement> it = properties.iterator(); | ||
406 | |||
407 | while (it.hasNext()) { | ||
408 | YoctoBspPropertyElement propElem = it.next(); | ||
409 | if (propElem.getName().contentEquals(element.getName())) { | ||
410 | properties.remove(propElem); | ||
411 | properties.add(element); | ||
412 | break; | ||
413 | } else | ||
414 | continue; | ||
415 | } | ||
416 | } | ||
417 | private void controlChanged(Widget widget) { | ||
418 | setErrorMessage(null); | ||
419 | |||
420 | String kernel_choice = kernelCombo.getText(); | ||
421 | if ((kernel_choice == null) || (kernel_choice.isEmpty())) { | ||
422 | setErrorMessage("Please choose kernel !"); | ||
423 | return; | ||
424 | } | ||
425 | if (widget == kernelCombo) { | ||
426 | updateKernelValues(KERNEL_BRANCHES, "\\\"" + kernel_choice + "\\\"." + NEW_KBRANCH_NAME); | ||
427 | } else if (widget == branchesCombo) { | ||
428 | setErrorMessage(null); | ||
429 | branchesCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT); | ||
430 | } else if (widget == newBranchButton || widget == existingBranchButton) { | ||
431 | if (newBranchButton.getSelection()) { | ||
432 | updateKernelValues(KERNEL_BRANCHES, "\"" + kernel_choice + "\"." + NEW_KBRANCH_NAME); | ||
433 | } else { | ||
434 | updateKernelValues(KERNEL_BRANCHES, "\"" + kernel_choice + "\"." + EXISTING_KBRANCH_NAME); | ||
435 | } | ||
436 | branchesCombo.deselectAll(); | ||
437 | } | ||
438 | canFlipToNextPage(); | ||
439 | getWizard().getContainer().updateButtons(); | ||
440 | this.composite.layout(true, true); | ||
441 | composite.pack(); | ||
442 | } | ||
443 | |||
444 | private void updateKernelValues(final String value, String property) { | ||
445 | String build_dir = ""; | ||
446 | if ((bspElem.getBuildLoc() == null) || bspElem.getBuildLoc().isEmpty()) | ||
447 | build_dir = bspElem.getMetadataLoc()+"/build"; | ||
448 | else | ||
449 | build_dir = bspElem.getBuildLoc(); | ||
450 | |||
451 | String metadataLoc = bspElem.getMetadataLoc(); | ||
452 | String valuesCmd = "source " + metadataLoc + "/oe-init-build-env;" + metadataLoc + "/scripts/" + VALUES_CMD_PREFIX + bspElem.getKarch() + VALUES_CMD_SURFIX + property; | ||
453 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new KernelBranchesGetter(valuesCmd), "Loading Kernel " + value); | ||
454 | if (value.equals(KERNEL_CHOICES)) | ||
455 | progressDialog.run(false); | ||
456 | else if (value.equals(KERNEL_BRANCHES)) | ||
457 | progressDialog.run(true); | ||
458 | |||
459 | BSPAction action = progressDialog.getBspAction(); | ||
460 | if (action.getItems() != null) { | ||
461 | if (value.equals(KERNEL_CHOICES)) { | ||
462 | kernelCombo.setItems(action.getItems()); | ||
463 | kernelCombo.pack(); | ||
464 | kernelCombo.deselectAll(); | ||
465 | branchesCombo.setEnabled(false); | ||
466 | branchesCombo.deselectAll(); | ||
467 | } else if (value.equals(KERNEL_BRANCHES)) { | ||
468 | branchesCombo.setItems(action.getItems()); | ||
469 | branchesCombo.pack(); | ||
470 | branchesCombo.setEnabled(true); | ||
471 | } | ||
472 | composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); | ||
473 | } else if (action.getMessage() != null) | ||
474 | MessageDialog.openError(getShell(), "Yocto-BSP", action.getMessage()); | ||
475 | composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); | ||
476 | } | ||
477 | |||
478 | private String[] getBSPComboProperties(String property) { | ||
479 | String build_dir = ""; | ||
480 | if ((bspElem.getBuildLoc() == null) || bspElem.getBuildLoc().isEmpty()) | ||
481 | build_dir = bspElem.getMetadataLoc()+"/build"; | ||
482 | else | ||
483 | build_dir = bspElem.getBuildLoc(); | ||
484 | |||
485 | String valuesCmd = "export BUILDDIR=" + build_dir + ";" + bspElem.getMetadataLoc() + "/scripts/" + VALUES_CMD_PREFIX + bspElem.getKarch() + VALUES_CMD_SURFIX + property; | ||
486 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new KernelBranchesGetter(valuesCmd), "Loading property " + property + "values"); | ||
487 | progressDialog.run(false); | ||
488 | BSPAction action = progressDialog.getBspAction(); | ||
489 | |||
490 | if (action.getItems() != null) { | ||
491 | return action.getItems(); | ||
492 | } else if (action.getMessage() != null) { | ||
493 | MessageDialog.openError(getShell(), "Yocto-BSP", action.getMessage()); | ||
494 | return new String[]{}; | ||
495 | } | ||
496 | return new String[]{}; | ||
497 | } | ||
498 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/QemuArchGetter.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/QemuArchGetter.java new file mode 100644 index 0000000..e235695 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/QemuArchGetter.java | |||
@@ -0,0 +1,27 @@ | |||
1 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
2 | |||
3 | /** | ||
4 | * BSPThread that processes the output of running "yocto-bsp list qemu property qemuarch" | ||
5 | * @author ioana.grigoropol | ||
6 | * | ||
7 | */ | ||
8 | public class QemuArchGetter extends BSPThread { | ||
9 | |||
10 | public QemuArchGetter(String command) { | ||
11 | super(command); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected String[] processLine(String line) { | ||
16 | if (!line.startsWith("[")) | ||
17 | return new String[]{ERROR, line + "\n"}; | ||
18 | |||
19 | String[] values = line.split(","); | ||
20 | |||
21 | String value = values[0]; | ||
22 | value = value.replace("[\"", ""); | ||
23 | value = value.replaceAll("\"$", ""); | ||
24 | return new String[]{SUCCESS, value}; | ||
25 | } | ||
26 | |||
27 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/YoctoBSPWizard.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/YoctoBSPWizard.java new file mode 100644 index 0000000..3ab24c0 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/YoctoBSPWizard.java | |||
@@ -0,0 +1,99 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 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 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.wizards.bsp; | ||
12 | |||
13 | import java.util.HashSet; | ||
14 | |||
15 | import org.eclipse.jface.dialogs.MessageDialog; | ||
16 | import org.eclipse.jface.wizard.IWizardPage; | ||
17 | import org.eclipse.jface.wizard.Wizard; | ||
18 | import org.yocto.sdk.remotetools.YoctoBspElement; | ||
19 | import org.yocto.sdk.remotetools.YoctoBspPropertyElement; | ||
20 | import org.yocto.sdk.remotetools.YoctoJSONHelper; | ||
21 | |||
22 | /** | ||
23 | * A wizard for creating Yocto BSP. | ||
24 | * | ||
25 | * @author jzhang | ||
26 | * | ||
27 | */ | ||
28 | public class YoctoBSPWizard extends Wizard { | ||
29 | private static final String CREATE_CMD = "/scripts/yocto-bsp create "; | ||
30 | private static final String PROPERTY_VALUE_FILE = "/tmp/propertyvalues.json"; | ||
31 | |||
32 | private MainPage mainPage; | ||
33 | private PropertiesPage propertiesPage; | ||
34 | private final YoctoBspElement bspElem; | ||
35 | |||
36 | public YoctoBSPWizard() { | ||
37 | super(); | ||
38 | bspElem = new YoctoBspElement(); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public IWizardPage getNextPage(IWizardPage page) { | ||
43 | propertiesPage.onEnterPage(mainPage.getBSPElement()); | ||
44 | return propertiesPage; | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public void addPages() { | ||
49 | mainPage = new MainPage(bspElem); | ||
50 | addPage(mainPage); | ||
51 | propertiesPage = new PropertiesPage(bspElem); | ||
52 | addPage(propertiesPage); | ||
53 | } | ||
54 | |||
55 | private BSPAction createBSP(){ | ||
56 | YoctoBspElement element = mainPage.getBSPElement(); | ||
57 | String createBspCmd = element.getMetadataLoc() + CREATE_CMD + | ||
58 | element.getBspName() + " " + element.getKarch(); | ||
59 | |||
60 | if (!element.getBspOutLoc().isEmpty()) | ||
61 | createBspCmd = createBspCmd + " -o " + element.getBspOutLoc(); | ||
62 | else | ||
63 | createBspCmd = createBspCmd + " -o " + element.getMetadataLoc() + "/meta-" + element.getBspName(); | ||
64 | createBspCmd = createBspCmd + " -i " + PROPERTY_VALUE_FILE; | ||
65 | |||
66 | BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new OutputCollectorThread(createBspCmd), "Creating BSP "); | ||
67 | progressDialog.run(true); | ||
68 | return progressDialog.getBspAction(); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public boolean performFinish() { | ||
73 | if (propertiesPage.validatePage()) { | ||
74 | HashSet<YoctoBspPropertyElement> properties = propertiesPage.getProperties(); | ||
75 | YoctoJSONHelper.createBspJSONFile(properties); | ||
76 | |||
77 | BSPAction createBSPAction = createBSP(); | ||
78 | if (createBSPAction.getMessage() != null && !createBSPAction.getMessage().isEmpty()) { | ||
79 | MessageDialog.openError(getShell(),"Yocto-BSP", createBSPAction.getMessage()); | ||
80 | return false; | ||
81 | } else { | ||
82 | String message = ""; | ||
83 | for (String item : createBSPAction.getItems()) | ||
84 | message += item + "\n"; | ||
85 | MessageDialog.openInformation(getShell(), "Yocto-BSP", message); | ||
86 | return true; | ||
87 | } | ||
88 | } else { | ||
89 | MessageDialog.openError(getShell(), "Yocto-BSP", "Property settings contains error!"); | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public boolean canFinish() { | ||
97 | return (mainPage.validatePage() && propertiesPage.validatePage()); | ||
98 | } | ||
99 | } | ||