]>
Commit | Line | Data |
---|---|---|
dbf5dd75 | 1 | /** @file\r |
2 | <<The file is used to update the Build Preferences file, target.txt>>\r | |
3 | \r | |
4 | <<The program will use target.txt, the tools config file specified in that file,\r | |
5 | or it will use the default tools_def.txt file, and it will also scan the \r | |
6 | FrameworkDatabase.db file for certain parameters. >>\r | |
7 | \r | |
8 | Copyright (c) 2006, Intel Corporation\r | |
9 | All rights reserved. This program and the accompanying materials\r | |
10 | are licensed and made available under the terms and conditions of the BSD License\r | |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
17 | Package Name: Tools\r | |
18 | Module Name: FrameworkWizard\r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | package org.tianocore.frameworkwizard.toolchain;\r | |
23 | \r | |
24 | import java.awt.event.ActionEvent;\r | |
25 | import java.io.*;\r | |
26 | import java.util.Vector;\r | |
27 | import java.util.Iterator;\r | |
bf6aed4d | 28 | import java.util.Scanner;\r |
dbf5dd75 | 29 | \r |
30 | import javax.swing.*;\r | |
bf6aed4d | 31 | import javax.swing.JScrollPane;\r |
dbf5dd75 | 32 | import javax.swing.JTextField;\r |
33 | import javax.swing.JFrame;\r | |
34 | \r | |
35 | import org.tianocore.frameworkwizard.common.GlobalData;\r | |
36 | import org.tianocore.frameworkwizard.common.Tools;\r | |
37 | import org.tianocore.frameworkwizard.common.Log;\r | |
38 | import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r | |
39 | import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.*;\r | |
40 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r | |
41 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
42 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
43 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r | |
44 | import org.tianocore.PlatformSurfaceAreaDocument;\r | |
45 | \r | |
46 | /**\r | |
47 | * The class is used to update the target.txt file.\r | |
48 | * \r | |
49 | * It extends IDialog\r | |
50 | * \r | |
51 | */\r | |
52 | public class Preferences extends IFrame {\r | |
53 | \r | |
54 | // /\r | |
55 | // / Define class Serial Version UID\r | |
56 | // /\r | |
57 | private static final long serialVersionUID = -4777906991966638888L;\r | |
58 | \r | |
59 | private final boolean Debug = false;\r | |
60 | \r | |
61 | //\r | |
62 | // Define class members\r | |
63 | //\r | |
64 | private final int oneRowHeight = 20;\r | |
65 | \r | |
66 | private final int twoRowHeight = 40;\r | |
67 | \r | |
68 | private final int threeRowHeight = 60;\r | |
69 | \r | |
70 | private final int sepHeight = 6;\r | |
71 | \r | |
72 | private final int rowOne = 12;\r | |
73 | \r | |
74 | private final int rowTwo = rowOne + oneRowHeight + sepHeight;\r | |
75 | \r | |
76 | private final int rowThree = rowTwo + oneRowHeight + sepHeight;\r | |
77 | \r | |
78 | private final int rowFour = rowThree + threeRowHeight + sepHeight;\r | |
79 | \r | |
80 | private final int rowFive = rowFour + threeRowHeight + sepHeight;\r | |
81 | \r | |
bf6aed4d | 82 | private final int rowSix = rowFive + oneRowHeight + sepHeight;\r |
83 | \r | |
84 | private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;\r | |
dbf5dd75 | 85 | \r |
86 | private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;\r | |
87 | \r | |
88 | private final int dialogWidth = 540;\r | |
89 | \r | |
90 | private final int lastButtonXLoc = 430;\r | |
91 | \r | |
92 | private final int next2LastButtonLoc = 329;\r | |
93 | \r | |
94 | /*\r | |
95 | * Define the contents for this dialog box\r | |
96 | */\r | |
97 | private static Preferences bTarget = null;\r | |
98 | \r | |
99 | private WorkspaceTools wt = new WorkspaceTools();\r | |
100 | \r | |
101 | private JFrame frame;\r | |
102 | \r | |
bf6aed4d | 103 | private final int activePlatformId = 0;\r |
104 | \r | |
105 | private final int buildTargetId = 1;\r | |
106 | \r | |
107 | private final int targetArchId = 2;\r | |
108 | \r | |
109 | private final int toolDefFileId = 3;\r | |
110 | \r | |
111 | private final int tagNameId = 4;\r | |
112 | \r | |
113 | private final int threadEnableId = 5;\r | |
114 | \r | |
115 | private final int threadCountId = 6;\r | |
116 | \r | |
117 | private final int maxTargetLines = threadCountId + 1;\r | |
118 | \r | |
dbf5dd75 | 119 | private JPanel jContentPane = null;\r |
120 | \r | |
121 | private JLabel jLabelToolsConfigFile = null;\r | |
122 | \r | |
123 | private JTextField jTextFieldToolsConfigFile = null;\r | |
124 | \r | |
125 | private final int toolConfigFileRow = rowOne;\r | |
126 | \r | |
dbf5dd75 | 127 | private JLabel jLabelActivePlatform = null;\r |
128 | \r | |
129 | private JComboBox jComboBoxActivePlatform = null;\r | |
130 | \r | |
dbf5dd75 | 131 | private final int activePlatformRow = rowTwo;\r |
132 | \r | |
133 | private JLabel jLabelToolChainTagName = null;\r | |
134 | \r | |
135 | private JScrollPane jScrollPaneTagName = null;\r | |
136 | \r | |
137 | private ICheckBoxList iCheckBoxListTagName = null;\r | |
138 | \r | |
139 | private final int toolChainTagNameRow = rowThree;\r | |
140 | \r | |
dbf5dd75 | 141 | private JLabel jLabelBuildTarget = null;\r |
142 | \r | |
143 | private JScrollPane jScrollPaneBuildTarget = null;\r | |
144 | \r | |
145 | private ICheckBoxList iCheckBoxListBuildTarget = null;\r | |
146 | \r | |
147 | private final int buildTargetRow = rowFour;\r | |
148 | \r | |
dbf5dd75 | 149 | private JLabel jLabelTargetArch = null;\r |
150 | \r | |
151 | private ArchCheckBox jArchCheckBox = null;\r | |
152 | \r | |
153 | private final int targetArchRow = rowFive;\r | |
154 | \r | |
bf6aed4d | 155 | private JLabel jLabelEnableThreads = null;\r |
156 | \r | |
157 | private JLabel jLabelThreadCount = null;\r | |
158 | \r | |
159 | private final int threadRow = rowSix;\r | |
160 | \r | |
161 | private JCheckBox jCheckBoxEnableThreads = null;\r | |
162 | \r | |
163 | private JTextField jTextFieldThreadCount = null;\r | |
164 | \r | |
1fd225e0 | 165 | private String threadCount = "";\r |
bf6aed4d | 166 | \r |
167 | private boolean threadEnabled = false;\r | |
dbf5dd75 | 168 | \r |
169 | private JButton jButtonBrowse = null;\r | |
170 | \r | |
171 | private JButton jButtonSave = null;\r | |
172 | \r | |
173 | private JButton jButtonCancel = null;\r | |
174 | \r | |
175 | private final int labelColumn = 12;\r | |
176 | \r | |
177 | private final int labelWidth = 155;\r | |
178 | \r | |
179 | private final int valueColumn = 168;\r | |
180 | \r | |
181 | private final int valueWidth = 352;\r | |
182 | \r | |
183 | private final int valueWidthShort = 260;\r | |
184 | \r | |
185 | private final int buttonWidth = 90;\r | |
186 | \r | |
187 | private String workspaceDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator");\r | |
188 | \r | |
189 | private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"\r | |
190 | + System.getProperty("file.separator") + "Conf";\r | |
191 | \r | |
192 | private String defaultToolsConf = toolsDir + System.getProperty("file.separator") + "tools_def.txt";\r | |
193 | \r | |
194 | private String targetFile = toolsDir + System.getProperty("file.separator") + "target.txt";\r | |
195 | \r | |
196 | private String[] targetFileContents = new String[500];\r | |
197 | \r | |
198 | // private String[] toolsConfContents;\r | |
199 | \r | |
bf6aed4d | 200 | private String[] targetLines = new String[maxTargetLines];\r |
dbf5dd75 | 201 | \r |
bf6aed4d | 202 | private int targetLineNumber[] = new int[maxTargetLines];\r |
dbf5dd75 | 203 | \r |
204 | private String toolsConfFile;\r | |
205 | \r | |
206 | private String toolsDefTargetNames = null;\r | |
207 | \r | |
208 | private final int toolsDefTargetNameField = 0;\r | |
209 | \r | |
210 | private String toolsDefTagNames = null;\r | |
211 | \r | |
212 | private final int toolsDefTagNameField = 1;\r | |
213 | \r | |
214 | private String toolsDefArchNames = null;\r | |
215 | \r | |
216 | private final int toolsDefArchNameField = 2;\r | |
217 | \r | |
218 | private String toolsDefIdentifier = null;\r | |
219 | \r | |
220 | private int targetLineNumberMax;\r | |
bf6aed4d | 221 | \r |
222 | private final int toolDefFieldCount = 5;\r | |
dbf5dd75 | 223 | \r |
224 | private Vector<String> vArchList = null;\r | |
225 | \r | |
8a11d13a | 226 | private Vector<String> vDisableArchList = null;\r |
52ee46a6 | 227 | \r |
dbf5dd75 | 228 | //\r |
229 | // Not used by UI\r | |
230 | //\r | |
231 | // private Preferences id = null;\r | |
232 | \r | |
233 | // private EnumerationData ed = new EnumerationData();\r | |
234 | \r | |
235 | /**\r | |
236 | This method initializes jTextFieldToolsConfigFile \r | |
237 | \r | |
238 | @return javax.swing.JTextField jTextFieldToolsConfigFile\r | |
239 | **/\r | |
240 | private JTextField getJTextFieldToolsConfigFile() {\r | |
241 | if (jTextFieldToolsConfigFile == null) {\r | |
242 | if (targetLines[toolDefFileId] != null) {\r | |
243 | String sLine[] = targetLines[toolDefFileId].trim().split("=");\r | |
244 | jTextFieldToolsConfigFile = new JTextField(sLine[1].trim());\r | |
245 | } else\r | |
246 | jTextFieldToolsConfigFile = new JTextField();\r | |
247 | \r | |
248 | jTextFieldToolsConfigFile.setBounds(new java.awt.Rectangle(valueColumn, toolConfigFileRow, valueWidthShort,\r | |
249 | oneRowHeight));\r | |
250 | jTextFieldToolsConfigFile.setPreferredSize(new java.awt.Dimension(valueWidthShort, oneRowHeight));\r | |
251 | jTextFieldToolsConfigFile\r | |
252 | .setToolTipText("<html>"\r | |
253 | + "Specify the name of the filename to use for specifying"\r | |
254 | + "<br>the tools to use for the build. If not specified,"\r | |
255 | + "<br>tools_def.txt will be used for the build. This file"\r | |
256 | + "<br>MUST be located in the WORKSPACE/Tools/Conf directory.</html>");\r | |
257 | \r | |
258 | }\r | |
259 | return jTextFieldToolsConfigFile;\r | |
260 | }\r | |
261 | \r | |
262 | /**\r | |
263 | * This method initializes jComboBoxActivePlatform\r | |
264 | * \r | |
265 | * @return javax.swing.JComboBox jComboBoxActivePlatform\r | |
266 | * \r | |
267 | */\r | |
268 | private JComboBox getActivePlatform() {\r | |
269 | Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();\r | |
270 | \r | |
271 | if (jComboBoxActivePlatform == null) {\r | |
272 | jComboBoxActivePlatform = new JComboBox();\r | |
273 | jComboBoxActivePlatform.setBounds(new java.awt.Rectangle(valueColumn, activePlatformRow, valueWidth,\r | |
274 | oneRowHeight));\r | |
275 | jComboBoxActivePlatform.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));\r | |
8a11d13a | 276 | jComboBoxActivePlatform\r |
277 | .setToolTipText("<html>Select "Do Not Set" if you want to build a platform"\r | |
dbf5dd75 | 278 | + "<br>from the directory where the FPD file exists,"\r |
279 | + "<br>otherwise scroll down to select the platform.</html>");\r | |
280 | \r | |
281 | /*\r | |
282 | * Generate the data, selecting what is in target.txt\r | |
283 | */\r | |
284 | jComboBoxActivePlatform.addItem("Do Not Set");\r | |
285 | Iterator<PlatformIdentification> iter = vPlatformId.iterator();\r | |
286 | while (iter.hasNext()) {\r | |
287 | PlatformIdentification item = iter.next();\r | |
288 | String path = item.getPath().trim();\r | |
289 | String str = path.substring(workspaceDir.length(), path.length());\r | |
290 | str.replace(System.getProperty("file.separator"), "/");\r | |
291 | jComboBoxActivePlatform.addItem(str.trim());\r | |
292 | }\r | |
293 | if (targetLines[activePlatformId] == null)\r | |
294 | jComboBoxActivePlatform.setSelectedItem("Do Not Set");\r | |
295 | else\r | |
296 | jComboBoxActivePlatform.setSelectedItem(targetLines[activePlatformId]);\r | |
297 | }\r | |
298 | return jComboBoxActivePlatform;\r | |
299 | }\r | |
300 | \r | |
301 | /**\r | |
302 | * This method initializes jScrollPaneTagName\r | |
303 | * \r | |
304 | * @return javax.swing.JScrollPane jScrollPaneTagName\r | |
305 | * \r | |
306 | */\r | |
307 | private JScrollPane getJScrollPaneTagName() {\r | |
308 | \r | |
309 | if (jScrollPaneTagName == null) {\r | |
310 | jScrollPaneTagName = new JScrollPane();\r | |
311 | jScrollPaneTagName.setBounds(new java.awt.Rectangle(valueColumn, toolChainTagNameRow, valueWidth,\r | |
312 | threeRowHeight));\r | |
313 | jScrollPaneTagName.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));\r | |
314 | jScrollPaneTagName.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r | |
315 | jScrollPaneTagName.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);\r | |
316 | jScrollPaneTagName.setViewportView(getICheckBoxListTagName());\r | |
317 | jScrollPaneTagName.setToolTipText("<html>"\r | |
318 | + "Specify the TagName(s) from the tool configuration file to use"\r | |
319 | + "<br>for your builds. If not specified, all applicable TagName"\r | |
320 | + " <br>tools will be used for the build.</html>");\r | |
321 | jScrollPaneTagName.setVisible(true);\r | |
322 | \r | |
323 | }\r | |
324 | return jScrollPaneTagName;\r | |
325 | }\r | |
326 | \r | |
327 | private ICheckBoxList getICheckBoxListTagName() {\r | |
328 | if (iCheckBoxListTagName == null) {\r | |
329 | iCheckBoxListTagName = new ICheckBoxList();\r | |
8a11d13a | 330 | \r |
dbf5dd75 | 331 | if (toolsDefTagNames != null) {\r |
332 | toolsDefTagNames.trim();\r | |
333 | String aTagNames[] = toolsDefTagNames.trim().split(" ");\r | |
334 | Vector<String> vTags = new Vector<String>();\r | |
335 | for (int i = 0; i < aTagNames.length; i++) {\r | |
336 | vTags.add(aTagNames[i]);\r | |
337 | }\r | |
338 | iCheckBoxListTagName.setAllItems(vTags);\r | |
339 | } else {\r | |
340 | Vector<String> defaultTags = stringToVector("MYTOOLS");\r | |
341 | iCheckBoxListTagName.setAllItems(defaultTags);\r | |
342 | }\r | |
8a11d13a | 343 | \r |
dbf5dd75 | 344 | iCheckBoxListTagName.setAllItemsUnchecked();\r |
345 | iCheckBoxListTagName.setToolTipText("<html>"\r | |
346 | + "Specify the TagName(s) from the tool configuration file to use"\r | |
347 | + "<br>for your builds. If not specified, all applicable TagName"\r | |
348 | + " <br>tools will be used for the build.</html>");\r | |
349 | Vector<String> vSelectedTags = new Vector<String>();\r | |
350 | if (targetLines[tagNameId] != null) {\r | |
351 | targetLines[tagNameId].trim();\r | |
352 | String targetTags[] = targetLines[tagNameId].trim().split(" ");\r | |
353 | for (int j = 0; j < targetTags.length; j++)\r | |
354 | vSelectedTags.add(targetTags[j]);\r | |
355 | iCheckBoxListTagName.initCheckedItem(true, vSelectedTags);\r | |
356 | }\r | |
357 | }\r | |
358 | return iCheckBoxListTagName;\r | |
359 | }\r | |
360 | \r | |
361 | /**\r | |
362 | * This method initializes jScrollPaneBuildTarget\r | |
363 | * \r | |
364 | * @return javax.swing.JComboBox jScrollPaneBuildTarget\r | |
365 | * \r | |
366 | */\r | |
367 | private JScrollPane getJScrollPaneBuildTarget() {\r | |
368 | if (jScrollPaneBuildTarget == null) {\r | |
369 | jScrollPaneBuildTarget = new JScrollPane();\r | |
370 | jScrollPaneBuildTarget.setBounds(new java.awt.Rectangle(valueColumn, buildTargetRow, valueWidth,\r | |
371 | threeRowHeight));\r | |
372 | jScrollPaneBuildTarget.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));\r | |
373 | jScrollPaneBuildTarget.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r | |
374 | jScrollPaneBuildTarget.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);\r | |
375 | jScrollPaneBuildTarget.setViewportView(getICheckBoxListBuildTarget());\r | |
376 | jScrollPaneBuildTarget.setVisible(true);\r | |
377 | jScrollPaneBuildTarget.setToolTipText("<html>"\r | |
378 | + "Select the TARGET Names that you want to build, such as<BR>"\r | |
379 | + "BUILD or BUILD and RELEASE"\r | |
380 | + "<br>If you do not set any of these, all available targets"\r | |
381 | + "<br>will be built.</html>");\r | |
382 | \r | |
383 | }\r | |
384 | return jScrollPaneBuildTarget;\r | |
385 | }\r | |
386 | \r | |
bf6aed4d | 387 | private JCheckBox getCheckBoxEnableThreads() {\r |
388 | if (jCheckBoxEnableThreads == null) {\r | |
389 | jCheckBoxEnableThreads = new JCheckBox();\r | |
390 | jCheckBoxEnableThreads.setBounds(valueColumn, threadRow, 20, oneRowHeight);\r | |
391 | jCheckBoxEnableThreads.setToolTipText("Select this if you want to enable parallel compilation.");\r | |
392 | jCheckBoxEnableThreads.setSelected(threadEnabled);\r | |
393 | jCheckBoxEnableThreads.addActionListener(this);\r | |
394 | \r | |
395 | }\r | |
396 | return jCheckBoxEnableThreads;\r | |
397 | }\r | |
398 | \r | |
399 | private JTextField getTextFieldThreadCount() {\r | |
400 | if (jTextFieldThreadCount == null) {\r | |
401 | jTextFieldThreadCount = new JTextField();\r | |
402 | jTextFieldThreadCount.setBounds(valueColumn + 215, threadRow, 30, oneRowHeight);\r | |
403 | if (threadCount.length() > 0)\r | |
404 | jTextFieldThreadCount.setText(threadCount);\r | |
405 | jTextFieldThreadCount.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");\r | |
406 | // If CheckBoxEnableThreads is selected, then enable editing\r | |
407 | \r | |
408 | }\r | |
409 | return jTextFieldThreadCount;\r | |
410 | }\r | |
411 | \r | |
dbf5dd75 | 412 | private ICheckBoxList getICheckBoxListBuildTarget() {\r |
413 | if (iCheckBoxListBuildTarget == null) {\r | |
8a11d13a | 414 | \r |
dbf5dd75 | 415 | String aBuildTargets[] = toolsDefTargetNames.trim().split(" ");\r |
416 | Vector<String> vBuildTargets = new Vector<String>();\r | |
417 | for (int i = 0; i < aBuildTargets.length; i++) {\r | |
418 | vBuildTargets.add(aBuildTargets[i]);\r | |
419 | }\r | |
420 | iCheckBoxListBuildTarget = new ICheckBoxList();\r | |
421 | iCheckBoxListBuildTarget.setAllItems(vBuildTargets);\r | |
422 | iCheckBoxListBuildTarget.setAllItemsUnchecked();\r | |
423 | iCheckBoxListBuildTarget.setToolTipText("<html>"\r | |
424 | + "Select the TARGET Names that you want to build, such as<BR>"\r | |
425 | + "BUILD or BUILD and RELEASE"\r | |
426 | + "<br>If you do not set any of these, all available targets"\r | |
427 | + "<br>will be built.</html>");\r | |
428 | \r | |
429 | Vector<String> vSelectedTags = new Vector<String>();\r | |
430 | if (targetLines[buildTargetId] != null) {\r | |
431 | targetLines[buildTargetId].trim();\r | |
432 | String targetTags[] = targetLines[buildTargetId].trim().split(" ");\r | |
433 | for (int j = 0; j < targetTags.length; j++)\r | |
434 | vSelectedTags.add(targetTags[j]);\r | |
435 | iCheckBoxListBuildTarget.initCheckedItem(true, vSelectedTags);\r | |
436 | }\r | |
437 | }\r | |
438 | return iCheckBoxListBuildTarget;\r | |
439 | }\r | |
440 | \r | |
441 | /**\r | |
442 | This method initializes jButtonBrowse \r | |
443 | \r | |
444 | @return javax.swing.JButton \r | |
445 | **/\r | |
446 | private JButton getJButtonBrowse() {\r | |
447 | if (jButtonBrowse == null) {\r | |
448 | jButtonBrowse = new JButton();\r | |
449 | jButtonBrowse\r | |
450 | .setBounds(new java.awt.Rectangle(lastButtonXLoc, toolConfigFileRow, buttonWidth, oneRowHeight));\r | |
451 | jButtonBrowse.setText("Browse");\r | |
452 | jButtonBrowse.setPreferredSize(new java.awt.Dimension(buttonWidth, oneRowHeight));\r | |
453 | jButtonBrowse.addActionListener(new AbstractAction() {\r | |
454 | /**\r | |
455 | * \r | |
456 | */\r | |
457 | private static final long serialVersionUID = 1L;\r | |
458 | \r | |
459 | public void actionPerformed(ActionEvent e) {\r | |
460 | //\r | |
461 | // Select files from current workspace\r | |
462 | //\r | |
463 | String dirPrefix = toolsDir + System.getProperty("file.separator");\r | |
464 | JFileChooser chooser = new JFileChooser(dirPrefix);\r | |
465 | File theFile = null;\r | |
466 | // String headerDest = null;\r | |
467 | \r | |
468 | chooser.setMultiSelectionEnabled(false);\r | |
469 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);\r | |
470 | int retval = chooser.showOpenDialog(frame);\r | |
471 | if (retval == JFileChooser.APPROVE_OPTION) {\r | |
472 | \r | |
473 | theFile = chooser.getSelectedFile();\r | |
474 | String file = theFile.getPath();\r | |
475 | if (!file.startsWith(dirPrefix)) {\r | |
476 | JOptionPane.showMessageDialog(frame, "You can only select files in the Tools"\r | |
477 | + System.getProperty("file.separator")\r | |
478 | + "Conf directory!");\r | |
479 | \r | |
480 | return;\r | |
481 | }\r | |
482 | \r | |
483 | jTextFieldToolsConfigFile.setText("Tools/Conf/" + theFile.getName());\r | |
484 | } else {\r | |
485 | return;\r | |
486 | }\r | |
487 | }\r | |
488 | });\r | |
489 | }\r | |
490 | return jButtonBrowse;\r | |
491 | }\r | |
492 | \r | |
493 | /**\r | |
494 | * This method initializes jButtonOk\r | |
495 | * \r | |
496 | * @return javax.swing.JButton\r | |
497 | * \r | |
498 | */\r | |
499 | private JButton getJButtonSave() {\r | |
500 | if (jButtonSave == null) {\r | |
501 | jButtonSave = new JButton();\r | |
502 | jButtonSave.setBounds(new java.awt.Rectangle(next2LastButtonLoc, buttonRow, buttonWidth, oneRowHeight));\r | |
503 | jButtonSave.setText("Save");\r | |
504 | jButtonSave.addActionListener(this);\r | |
505 | }\r | |
506 | return jButtonSave;\r | |
507 | }\r | |
508 | \r | |
509 | /**\r | |
510 | * This method initializes jButtonCancel\r | |
511 | * \r | |
512 | * @return javax.swing.JButton\r | |
513 | * \r | |
514 | */\r | |
515 | private JButton getJButtonCancel() {\r | |
516 | if (jButtonCancel == null) {\r | |
517 | jButtonCancel = new JButton();\r | |
518 | jButtonCancel.setBounds(new java.awt.Rectangle(lastButtonXLoc, buttonRow, buttonWidth, oneRowHeight));\r | |
519 | jButtonCancel.setText("Cancel");\r | |
520 | jButtonCancel.addActionListener(this);\r | |
521 | }\r | |
522 | return jButtonCancel;\r | |
523 | }\r | |
524 | \r | |
525 | public static void main(String[] args) {\r | |
526 | // TODO Auto-generated method stub\r | |
527 | \r | |
528 | }\r | |
529 | \r | |
530 | public static Preferences getInstance() {\r | |
531 | if (bTarget == null) {\r | |
532 | bTarget = new Preferences();\r | |
533 | }\r | |
534 | return bTarget;\r | |
535 | }\r | |
536 | \r | |
537 | /**\r | |
538 | * This is the default constructor\r | |
539 | */\r | |
540 | public Preferences() {\r | |
541 | super();\r | |
542 | init();\r | |
543 | }\r | |
544 | \r | |
545 | /**\r | |
546 | * This method initializes this\r | |
547 | * \r | |
548 | */\r | |
549 | private void init() {\r | |
bf6aed4d | 550 | for (int i = 0; i < maxTargetLines; i++) {\r |
dbf5dd75 | 551 | targetLines[i] = null;\r |
552 | targetLineNumber[i] = -1;\r | |
553 | }\r | |
554 | initReadFiles();\r | |
555 | this.setSize(dialogWidth, dialogHeight);\r | |
556 | this.setContentPane(getJContentPane());\r | |
557 | this.setTitle("Build Preferences [" + toolsDefIdentifier + "]");\r | |
558 | this.setDefaultCloseOperation(IFrame.EXIT_ON_CLOSE);\r | |
559 | this.centerWindow();\r | |
560 | this.setVisible(true);\r | |
561 | }\r | |
562 | \r | |
563 | /**\r | |
564 | * This method initializes this Fill values to all fields if these values are\r | |
565 | * not empty\r | |
566 | * \r | |
567 | * @param initReadFiles\r | |
568 | * \r | |
569 | */\r | |
570 | private void initReadFiles() {\r | |
571 | /*\r | |
572 | * TODO\r | |
573 | * Read Current target.txt file first\r | |
574 | * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt\r | |
575 | */\r | |
dbf5dd75 | 576 | readTargetTxtFile();\r |
577 | boolean haveBuildTargets = readToolDefinitionFile();\r | |
578 | if (!haveBuildTargets) {\r | |
579 | // Lookup Build Targets from the platforms\r | |
580 | readPlatformFileBuildTargets();\r | |
581 | }\r | |
582 | }\r | |
583 | \r | |
584 | private void readPlatformFileBuildTargets() {\r | |
585 | Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();\r | |
586 | String sBuildTargets = "";\r | |
587 | \r | |
588 | // foreach platform, build a list of BuildTargets\r | |
589 | Iterator<PlatformIdentification> iter = vPlatformId.iterator();\r | |
590 | while (iter.hasNext()) {\r | |
591 | PlatformIdentification item = iter.next();\r | |
592 | PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd = GlobalData.openingPlatformList\r | |
593 | .getOpeningPlatformById(\r | |
594 | item)\r | |
595 | .getXmlFpd();\r | |
596 | sBuildTargets += fpd.getPlatformDefinitions().getBuildTargets().toString() + " ";\r | |
597 | }\r | |
598 | String allTargets[] = sBuildTargets.trim().split(" ");\r | |
599 | for (int i = 0; i < allTargets.length; i++) {\r | |
600 | if (!toolsDefTargetNames.contains(allTargets[i])) {\r | |
601 | toolsDefTargetNames += allTargets[i] + " ";\r | |
602 | }\r | |
603 | }\r | |
604 | }\r | |
605 | \r | |
606 | private boolean readToolDefinitionFile() {\r | |
607 | \r | |
608 | // Parse the tool definition file looking for targets and architectures\r | |
609 | toolsConfFile = null;\r | |
610 | boolean buildTargetsExist = true;\r | |
611 | \r | |
612 | if (targetLines[toolDefFileId] != null) {\r | |
613 | String[] result = new String[2];\r | |
614 | targetLines[toolDefFileId].trim();\r | |
615 | result = (targetLines[toolDefFileId]).split("=");\r | |
616 | String resString = (Tools.convertPathToCurrentOsType(result[1])).trim();\r | |
617 | toolsConfFile = workspaceDir.trim() + resString.trim();\r | |
618 | File toolsDefFile = new File(toolsConfFile);\r | |
619 | if (!toolsDefFile.exists()) {\r | |
620 | JOptionPane.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile\r | |
621 | + "<br>specified in the target.txt file does not exist!"\r | |
622 | + "<br>Using the default Tool Definition File:<br>"\r | |
623 | + defaultToolsConf);\r | |
624 | toolsConfFile = defaultToolsConf;\r | |
625 | }\r | |
626 | } else {\r | |
627 | toolsConfFile = defaultToolsConf;\r | |
628 | }\r | |
bf6aed4d | 629 | String[] toolsDefFields = new String[toolDefFieldCount];\r |
630 | for (int i = 0; i < toolDefFieldCount; i++)\r | |
dbf5dd75 | 631 | toolsDefFields[i] = null;\r |
632 | File toolDefFile = new File(toolsConfFile);\r | |
633 | if (toolDefFile.exists()) {\r | |
634 | try {\r | |
635 | FileReader fileReader = new FileReader(toolDefFile);\r | |
636 | BufferedReader reader = new BufferedReader(fileReader);\r | |
637 | String rLine = null;\r | |
638 | String result[];\r | |
639 | int lineCounter = 0;\r | |
640 | while ((rLine = reader.readLine()) != null) {\r | |
641 | \r | |
642 | if (rLine.startsWith("IDENTIFIER")) {\r | |
643 | result = rLine.split("=");\r | |
644 | toolsDefIdentifier = (result[1]).trim();\r | |
645 | } else if ((!rLine.startsWith("#")) && (rLine.contains("="))) {\r | |
646 | result = rLine.split("=");\r | |
647 | toolsDefFields = ((result[0]).trim()).split("_");\r | |
648 | if (toolsDefTargetNames == null) {\r | |
649 | toolsDefTargetNames = (toolsDefFields[toolsDefTargetNameField]).trim() + " ";\r | |
650 | } else if (!toolsDefTargetNames.contains((toolsDefFields[toolsDefTargetNameField]).trim())) {\r | |
651 | toolsDefTargetNames += (toolsDefFields[toolsDefTargetNameField]).trim() + " ";\r | |
652 | }\r | |
653 | if (toolsDefTagNames == null) {\r | |
654 | toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).trim() + " ";\r | |
655 | } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).trim())) {\r | |
656 | toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).trim() + " ";\r | |
657 | }\r | |
658 | if (toolsDefArchNames == null) {\r | |
659 | toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).trim() + " ";\r | |
660 | } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).trim())) {\r | |
661 | toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).trim() + " ";\r | |
662 | }\r | |
663 | }\r | |
664 | lineCounter++;\r | |
665 | }\r | |
666 | reader.close();\r | |
8a11d13a | 667 | // Only enable Architecture selection based on tool chain installations\r |
668 | String turnOff = "";\r | |
669 | if (!toolsDefArchNames.contains("EBC"))\r | |
670 | turnOff = "EBC ";\r | |
671 | if (!toolsDefArchNames.contains("PPC"))\r | |
672 | turnOff += "PPC ";\r | |
673 | if (!toolsDefArchNames.contains("IPF"))\r | |
674 | turnOff += "IPF ";\r | |
675 | if (!toolsDefArchNames.contains("X64"))\r | |
676 | turnOff += "X64 ";\r | |
677 | if (!toolsDefArchNames.contains("IA32"))\r | |
678 | turnOff += "X64 ";\r | |
679 | if (!toolsDefArchNames.contains("ARM"))\r | |
680 | turnOff += "ARM ";\r | |
681 | turnOff = turnOff.trim();\r | |
682 | vDisableArchList = stringToVector(turnOff);\r | |
683 | \r | |
dbf5dd75 | 684 | if (!toolsDefTargetNames.matches("[A-Z]+")) {\r |
685 | toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();\r | |
686 | if (Debug)\r | |
687 | System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames\r | |
688 | + "'");\r | |
689 | buildTargetsExist = false;\r | |
690 | }\r | |
691 | } catch (IOException e) {\r | |
692 | Log.log(toolsConfFile + " Read Error ", e.getMessage());\r | |
693 | e.printStackTrace();\r | |
694 | }\r | |
695 | }\r | |
696 | return buildTargetsExist;\r | |
697 | }\r | |
698 | \r | |
699 | private void readTargetTxtFile() {\r | |
700 | File tFile = new File(targetFile);\r | |
701 | \r | |
702 | if (tFile.exists()) {\r | |
703 | try {\r | |
704 | FileReader fileReader = new FileReader(targetFile);\r | |
705 | BufferedReader reader = new BufferedReader(fileReader);\r | |
706 | targetLineNumberMax = 0;\r | |
707 | String rLine = null;\r | |
708 | while ((rLine = reader.readLine()) != null) {\r | |
709 | targetFileContents[targetLineNumberMax] = rLine;\r | |
710 | if (rLine.startsWith("ACTIVE_PLATFORM")) {\r | |
711 | // Only one active platform is permitted!\r | |
712 | targetLines[activePlatformId] = rLine;\r | |
713 | targetLineNumber[activePlatformId] = targetLineNumberMax;\r | |
714 | }\r | |
715 | if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t"))\r | |
716 | || (rLine.startsWith("TARGET="))) {\r | |
717 | // Handle multiple Target Names\r | |
718 | if (rLine.contains(","))\r | |
719 | targetLines[buildTargetId] = rLine.trim().replaceAll(",", " ");\r | |
720 | else\r | |
721 | targetLines[buildTargetId] = rLine.trim();\r | |
722 | targetLineNumber[buildTargetId] = targetLineNumberMax;\r | |
723 | }\r | |
724 | if (rLine.startsWith("TARGET_ARCH")) {\r | |
725 | // Handle multiple Target Architectures\r | |
726 | if (rLine.contains(","))\r | |
727 | targetLines[targetArchId] = rLine.trim().replaceAll(",", " ");\r | |
728 | else\r | |
729 | targetLines[targetArchId] = rLine.trim();\r | |
730 | targetLineNumber[targetArchId] = targetLineNumberMax;\r | |
731 | }\r | |
732 | if (rLine.startsWith("TOOL_CHAIN_CONF")) {\r | |
733 | // Only one file is permitted\r | |
734 | targetLines[toolDefFileId] = rLine.trim();\r | |
735 | targetLineNumber[toolDefFileId] = targetLineNumberMax;\r | |
736 | }\r | |
737 | \r | |
738 | if (rLine.startsWith("TOOL_CHAIN_TAG")) {\r | |
739 | // Handle multiple Tool TagNames\r | |
740 | if (rLine.contains(","))\r | |
741 | targetLines[tagNameId] = rLine.trim().replaceAll(",", " ");\r | |
742 | else\r | |
743 | targetLines[tagNameId] = rLine.trim();\r | |
744 | targetLineNumber[tagNameId] = targetLineNumberMax;\r | |
745 | }\r | |
bf6aed4d | 746 | \r |
747 | if (rLine.startsWith("MULTIPLE_THREAD")) {\r | |
748 | // Handle Thread Enable flag\r | |
749 | targetLines[threadEnableId] = rLine.trim();\r | |
750 | targetLineNumber[threadEnableId] = targetLineNumberMax;\r | |
751 | if ((rLine.trim().toLowerCase().contains("enabled")) || (rLine.trim().toLowerCase().contains("true"))) { \r | |
752 | threadEnabled = true;\r | |
753 | } else {\r | |
754 | threadEnabled = false;\r | |
755 | }\r | |
756 | }\r | |
757 | \r | |
758 | if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {\r | |
759 | // Handle Thread Enable flag\r | |
760 | targetLines[threadCountId] = rLine.trim();\r | |
761 | targetLineNumber[threadCountId] = targetLineNumberMax;\r | |
762 | }\r | |
dbf5dd75 | 763 | targetLineNumberMax++;\r |
764 | }\r | |
765 | reader.close();\r | |
766 | String archLine[] = new String[2];\r | |
767 | if (targetLines[targetArchId] != null) {\r | |
768 | if (targetLines[targetArchId].contains("=")) {\r | |
769 | if (targetLines[targetArchId].contains(","))\r | |
770 | targetLines[targetArchId] = targetLines[targetArchId].trim().replaceAll(",", " ");\r | |
771 | if (targetLines[targetArchId].length() > 0)\r | |
772 | archLine = targetLines[targetArchId].trim().split("=");\r | |
773 | vArchList = stringToVector(archLine[1]);\r | |
774 | }\r | |
775 | }\r | |
776 | \r | |
bf6aed4d | 777 | if (targetLines[threadCountId] != null) {\r |
778 | String tcLine[] = new String[2];\r | |
779 | tcLine = targetLines[threadCountId].trim().split("=");\r | |
780 | threadCount = tcLine[1];\r | |
781 | } else\r | |
782 | threadCount = "";\r | |
783 | \r | |
dbf5dd75 | 784 | if (Debug == true)\r |
bf6aed4d | 785 | for (int i = 0; i <= maxTargetLines; i++)\r |
dbf5dd75 | 786 | System.out.println("targetLines[" + i + "] contains: " + targetLines[i] + " index is: "\r |
787 | + targetLineNumber[i]);\r | |
dbf5dd75 | 788 | } catch (IOException e) {\r |
789 | Log.log(this.targetFile + " Read Error ", e.getMessage());\r | |
790 | e.printStackTrace();\r | |
791 | }\r | |
792 | }\r | |
793 | \r | |
794 | }\r | |
795 | \r | |
796 | /**\r | |
797 | * This method initializes jContentPane\r | |
798 | * \r | |
799 | * @return javax.swing.JPanel jContentPane\r | |
800 | * \r | |
801 | */\r | |
802 | private JPanel getJContentPane() {\r | |
803 | if (jContentPane == null) {\r | |
804 | jLabelToolsConfigFile = new JLabel();\r | |
805 | jLabelToolsConfigFile.setBounds(new java.awt.Rectangle(labelColumn, toolConfigFileRow, labelWidth,\r | |
806 | oneRowHeight));\r | |
807 | jLabelToolsConfigFile.setText("Tool Chain Definition File");\r | |
808 | jLabelActivePlatform = new JLabel();\r | |
809 | jLabelActivePlatform.setText("Select Active Platform");\r | |
810 | jLabelActivePlatform.setBounds(new java.awt.Rectangle(labelColumn, activePlatformRow, labelWidth,\r | |
811 | oneRowHeight));\r | |
812 | jLabelToolChainTagName = new JLabel();\r | |
813 | jLabelToolChainTagName.setBounds(new java.awt.Rectangle(labelColumn, toolChainTagNameRow, labelWidth,\r | |
814 | oneRowHeight));\r | |
815 | jLabelToolChainTagName.setText("Select Tool Tag Name");\r | |
816 | jLabelBuildTarget = new JLabel();\r | |
817 | jLabelBuildTarget.setBounds(new java.awt.Rectangle(labelColumn, buildTargetRow, labelWidth, oneRowHeight));\r | |
818 | jLabelBuildTarget.setText("Select Build Target");\r | |
819 | jLabelTargetArch = new JLabel();\r | |
820 | jLabelTargetArch.setBounds(new java.awt.Rectangle(labelColumn, targetArchRow, labelWidth, oneRowHeight));\r | |
821 | jLabelTargetArch.setText("Build Architectures");\r | |
bf6aed4d | 822 | \r |
dbf5dd75 | 823 | jArchCheckBox = new ArchCheckBox();\r |
824 | jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));\r | |
825 | jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));\r | |
826 | \r | |
bf6aed4d | 827 | jLabelEnableThreads = new JLabel();\r |
828 | jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));\r | |
829 | jLabelEnableThreads.setText("Enable Compiler Threading");\r | |
830 | \r | |
831 | jLabelThreadCount = new JLabel();\r | |
832 | jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));\r | |
833 | jLabelThreadCount.setText("Number of threads to start");\r | |
834 | \r | |
dbf5dd75 | 835 | jContentPane = new JPanel();\r |
836 | jContentPane.setLayout(null);\r | |
837 | jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));\r | |
838 | \r | |
839 | jContentPane.add(jLabelToolsConfigFile, null);\r | |
840 | jContentPane.add(getJTextFieldToolsConfigFile(), null);\r | |
841 | jContentPane.add(getJButtonBrowse(), null);\r | |
842 | \r | |
843 | jContentPane.add(jLabelActivePlatform, null);\r | |
844 | jContentPane.add(getActivePlatform(), null);\r | |
845 | \r | |
846 | jContentPane.add(jLabelToolChainTagName, null);\r | |
847 | jContentPane.add(getJScrollPaneTagName(), null);\r | |
848 | \r | |
849 | jContentPane.add(jLabelBuildTarget, null);\r | |
850 | jContentPane.add(getJScrollPaneBuildTarget(), null);\r | |
851 | \r | |
852 | jContentPane.add(jLabelTargetArch, null);\r | |
853 | \r | |
8a11d13a | 854 | jArchCheckBox.setDisabledItems(vDisableArchList);\r |
dbf5dd75 | 855 | jArchCheckBox.setSelectedItems(vArchList);\r |
856 | jContentPane.add(jArchCheckBox, null);\r | |
857 | \r | |
bf6aed4d | 858 | jContentPane.add(jLabelEnableThreads, null);\r |
859 | jContentPane.add(getCheckBoxEnableThreads(), null);\r | |
860 | \r | |
861 | jContentPane.add(jLabelThreadCount, null);\r | |
862 | jContentPane.add(getTextFieldThreadCount(), null);\r | |
863 | \r | |
dbf5dd75 | 864 | jContentPane.add(getJButtonSave(), null);\r |
865 | jContentPane.add(getJButtonCancel(), null);\r | |
866 | }\r | |
867 | return jContentPane;\r | |
868 | }\r | |
869 | \r | |
870 | /*\r | |
871 | * (non-Javadoc)\r | |
872 | * \r | |
873 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
874 | * \r | |
875 | * Override actionPerformed to listen all actions\r | |
876 | * \r | |
877 | */\r | |
878 | public void actionPerformed(ActionEvent arg0) {\r | |
879 | \r | |
880 | if (arg0.getSource() == jButtonBrowse) {\r | |
881 | // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory\r | |
882 | \r | |
883 | }\r | |
884 | \r | |
885 | if (arg0.getSource() == jButtonSave) {\r | |
886 | saveTargetFile();\r | |
887 | JOptionPane.showMessageDialog(this, "<html>The target.txt file has been saved!"\r | |
888 | + "<br>A copy of the original file, target.txt.bak has"\r | |
889 | + "<br>also been created.</html>");\r | |
890 | this.exit();\r | |
891 | }\r | |
892 | \r | |
893 | if (arg0.getSource() == jButtonCancel) {\r | |
894 | this.exit();\r | |
895 | }\r | |
bf6aed4d | 896 | \r |
897 | if (arg0.getSource() == jCheckBoxEnableThreads) {\r | |
898 | if (jCheckBoxEnableThreads.isSelected() == false) {\r | |
899 | threadCount = "";\r | |
900 | jTextFieldThreadCount.setText(threadCount);\r | |
901 | }\r | |
902 | }\r | |
dbf5dd75 | 903 | }\r |
bf6aed4d | 904 | \r |
dbf5dd75 | 905 | \r |
906 | private void updateActivePlatform() {\r | |
907 | int lineAP;\r | |
908 | if (targetLines[activePlatformId] != null) {\r | |
909 | lineAP = targetLineNumber[activePlatformId];\r | |
910 | } else {\r | |
911 | lineAP = targetLineNumberMax;\r | |
912 | targetLineNumber[activePlatformId] = lineAP;\r | |
913 | targetLineNumberMax++;\r | |
914 | }\r | |
915 | if (jComboBoxActivePlatform.getSelectedItem() == "Do Not Set") {\r | |
916 | targetFileContents[lineAP] = "";\r | |
917 | targetLines[activePlatformId] = "";\r | |
918 | } else {\r | |
919 | targetFileContents[lineAP] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform.getSelectedItem() + "\r\n";\r | |
920 | targetLines[activePlatformId] = targetFileContents[lineAP];\r | |
921 | }\r | |
922 | if (Debug)\r | |
923 | System.out.println("Active Platform: " + targetFileContents[lineAP]);\r | |
924 | }\r | |
925 | \r | |
926 | private void updateToolDefFile() {\r | |
927 | int lineTDF;\r | |
928 | if (targetLines[toolDefFileId] != null) {\r | |
929 | lineTDF = targetLineNumber[toolDefFileId];\r | |
930 | } else {\r | |
931 | lineTDF = targetLineNumberMax;\r | |
932 | targetLineNumber[toolDefFileId] = lineTDF;\r | |
933 | targetLineNumberMax++;\r | |
934 | }\r | |
935 | if (Debug)\r | |
936 | System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());\r | |
937 | if (jTextFieldToolsConfigFile.getText() == null) {\r | |
bf6aed4d | 938 | targetFileContents[lineTDF] = "#MT#";\r |
dbf5dd75 | 939 | targetLines[toolDefFileId] = "";\r |
940 | } else {\r | |
bf6aed4d | 941 | targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();\r |
dbf5dd75 | 942 | targetLines[toolDefFileId] = targetFileContents[lineTDF];\r |
943 | }\r | |
944 | }\r | |
945 | \r | |
946 | private void updateToolTagNames() {\r | |
947 | String sTagNames = vectorToString(iCheckBoxListTagName.getAllCheckedItemsString());\r | |
948 | int lineTTN;\r | |
949 | \r | |
950 | if (targetLines[tagNameId] != null) {\r | |
951 | lineTTN = targetLineNumber[tagNameId];\r | |
952 | } else {\r | |
953 | lineTTN = targetLineNumberMax;\r | |
954 | targetLineNumber[tagNameId] = lineTTN;\r | |
955 | targetLineNumberMax++;\r | |
956 | }\r | |
957 | \r | |
958 | if (Debug)\r | |
959 | System.out.println("Tag Name(s): " + sTagNames);\r | |
960 | \r | |
961 | if (sTagNames.length() > 0) {\r | |
bf6aed4d | 962 | targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;\r |
dbf5dd75 | 963 | targetLines[tagNameId] = targetFileContents[lineTTN];\r |
964 | } else {\r | |
bf6aed4d | 965 | targetFileContents[lineTTN] = "#MT#";\r |
dbf5dd75 | 966 | targetLines[tagNameId] = "";\r |
967 | }\r | |
968 | }\r | |
969 | \r | |
970 | private void updateBuildTargets() {\r | |
971 | String sBuildTargets = vectorToString(iCheckBoxListBuildTarget.getAllCheckedItemsString());\r | |
972 | int lineBT;\r | |
973 | \r | |
974 | if (targetLines[buildTargetId] != null) {\r | |
975 | lineBT = targetLineNumber[buildTargetId];\r | |
976 | } else {\r | |
977 | lineBT = targetLineNumberMax;\r | |
978 | targetLineNumber[buildTargetId] = lineBT;\r | |
979 | targetLineNumberMax++;\r | |
980 | }\r | |
981 | if (Debug)\r | |
982 | System.out.println("Build Target(s): " + sBuildTargets);\r | |
983 | if (sBuildTargets.length() > 0) {\r | |
bf6aed4d | 984 | targetFileContents[lineBT] = "TARGET = " + sBuildTargets;\r |
dbf5dd75 | 985 | targetLines[buildTargetId] = targetFileContents[lineBT];\r |
986 | } else {\r | |
bf6aed4d | 987 | targetFileContents[lineBT] = "#MT#";\r |
dbf5dd75 | 988 | targetLines[buildTargetId] = "";\r |
989 | }\r | |
990 | \r | |
991 | }\r | |
992 | \r | |
993 | private void updateArchitectures() {\r | |
994 | String sArchList = jArchCheckBox.getSelectedItemsString().trim();\r | |
995 | \r | |
996 | if (Debug)\r | |
997 | System.out.println("Architectures: " + sArchList);\r | |
998 | \r | |
999 | int lineSA;\r | |
1000 | if (targetLines[targetArchId] != null) {\r | |
1001 | lineSA = targetLineNumber[targetArchId];\r | |
1002 | } else {\r | |
1003 | lineSA = targetLineNumberMax;\r | |
1004 | targetLineNumber[targetArchId] = lineSA;\r | |
1005 | targetLineNumberMax++;\r | |
1006 | }\r | |
1007 | if (sArchList == "") {\r | |
bf6aed4d | 1008 | targetFileContents[lineSA] = "#MT#";\r |
dbf5dd75 | 1009 | targetLines[targetArchId] = "";\r |
1010 | } else {\r | |
bf6aed4d | 1011 | targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;\r |
dbf5dd75 | 1012 | targetLines[targetArchId] = targetFileContents[lineSA];\r |
1013 | }\r | |
1014 | \r | |
1015 | }\r | |
1016 | \r | |
bf6aed4d | 1017 | private void updateEnableThreads() {\r |
1018 | int lineET;\r | |
1019 | if (targetLines[threadEnableId] != null) {\r | |
1020 | lineET = targetLineNumber[threadEnableId];\r | |
1021 | } else {\r | |
1022 | lineET = targetLineNumberMax;\r | |
1023 | targetLineNumber[threadEnableId] = lineET;\r | |
1024 | targetLineNumberMax++;\r | |
1025 | }\r | |
1026 | if (jCheckBoxEnableThreads.isSelected() == true) {\r | |
1027 | targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";\r | |
1028 | targetLines[threadEnableId] = targetFileContents[lineET];\r | |
1029 | } else {\r | |
1030 | targetFileContents[lineET] = "#MT#";\r | |
1031 | targetLines[threadEnableId] = "";\r | |
1032 | }\r | |
1033 | }\r | |
1034 | \r | |
1035 | private void updateThreadCount() {\r | |
1036 | int lineTC;\r | |
1037 | \r | |
1038 | if (targetLines[threadCountId] != null) {\r | |
1039 | lineTC = targetLineNumber[threadCountId];\r | |
1040 | } else {\r | |
1041 | lineTC = targetLineNumberMax;\r | |
1042 | targetLineNumber[threadCountId] = lineTC;\r | |
1043 | targetLineNumberMax++;\r | |
1044 | }\r | |
1045 | if (jCheckBoxEnableThreads.isSelected() == true) {\r | |
1046 | // Threading must be enabled\r | |
1047 | if (jTextFieldThreadCount.getText().length() > 0) {\r | |
1048 | // Thread Count must be greater than 0\r | |
1049 | Scanner scan = new Scanner(jTextFieldThreadCount.getText().trim()); \r | |
1050 | if (scan.nextInt() > 0) { \r | |
1051 | targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount.getText().trim();\r | |
1052 | targetLines[threadCountId] = targetFileContents[lineTC];\r | |
1053 | } else {\r | |
1054 | Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r | |
1055 | targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r | |
1056 | targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r | |
1057 | }\r | |
1058 | } else {\r | |
1059 | Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r | |
1060 | targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r | |
1061 | targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r | |
1062 | }\r | |
1063 | } else {\r | |
1064 | // Don't track threads if threading is not enabled\r | |
1065 | targetFileContents[lineTC] = "#MT#";\r | |
1066 | targetLines[threadCountId] = "";\r | |
1067 | threadCount = "";\r | |
1068 | }\r | |
1069 | \r | |
1070 | }\r | |
dbf5dd75 | 1071 | private String vectorToString(Vector<String> v) {\r |
1072 | String s = " ";\r | |
1073 | for (int i = 0; i < v.size(); ++i) {\r | |
1074 | s += v.get(i);\r | |
1075 | s += " ";\r | |
1076 | }\r | |
1077 | return s.trim();\r | |
1078 | }\r | |
1079 | \r | |
1080 | protected Vector<String> stringToVector(String s) {\r | |
1081 | if (s == null) {\r | |
1082 | return null;\r | |
1083 | }\r | |
1084 | String[] sArray = s.split(" ");\r | |
1085 | Vector<String> v = new Vector<String>();\r | |
1086 | for (int i = 0; i < sArray.length; ++i) {\r | |
1087 | v.add(sArray[i]);\r | |
1088 | }\r | |
1089 | return v;\r | |
1090 | }\r | |
1091 | \r | |
1092 | private void saveTargetFile() {\r | |
1093 | updateActivePlatform();\r | |
1094 | updateToolDefFile();\r | |
1095 | updateToolTagNames();\r | |
1096 | updateBuildTargets();\r | |
1097 | updateArchitectures();\r | |
bf6aed4d | 1098 | updateEnableThreads();\r |
1099 | updateThreadCount();\r | |
dbf5dd75 | 1100 | \r |
1101 | try {\r | |
1102 | copy(targetFile, targetFile + ".bak");\r | |
1103 | FileWriter fileWriter = new FileWriter(targetFile);\r | |
1104 | BufferedWriter writer = new BufferedWriter(fileWriter);\r | |
1105 | for (int i = 0; i < targetLineNumberMax; i++) {\r | |
bf6aed4d | 1106 | if (! targetFileContents[i].contains("#MT#"))\r |
1107 | writer.write(targetFileContents[i] + "\n");\r | |
dbf5dd75 | 1108 | }\r |
1109 | writer.close();\r | |
1110 | } catch (IOException e) {\r | |
1111 | Log.err(toolsConfFile + " Write Error ", e.getMessage());\r | |
1112 | e.printStackTrace();\r | |
1113 | }\r | |
1114 | }\r | |
1115 | \r | |
1116 | private void copy(String txtFile, String bakFile) throws IOException {\r | |
1117 | File fromFile = new File(txtFile);\r | |
1118 | File toFile = new File(bakFile);\r | |
1119 | FileInputStream fromTxt = null;\r | |
1120 | FileOutputStream toBak = null;\r | |
1fd225e0 | 1121 | if (!fromFile.exists()) {\r |
1122 | fromFile.createNewFile();\r | |
1123 | }\r | |
dbf5dd75 | 1124 | try {\r |
1125 | fromTxt = new FileInputStream(fromFile);\r | |
1126 | toBak = new FileOutputStream(toFile);\r | |
1127 | byte[] buffer = new byte[4096];\r | |
1128 | int bytes_read;\r | |
1129 | while ((bytes_read = fromTxt.read(buffer)) != -1) {\r | |
1130 | toBak.write(buffer, 0, bytes_read);\r | |
1131 | }\r | |
1132 | } finally {\r | |
1133 | if (fromTxt != null)\r | |
1134 | try {\r | |
1135 | fromTxt.close();\r | |
1136 | } catch (IOException e) {\r | |
1137 | Log.err(toolsConfFile + " Read Error ", e.getMessage());\r | |
1138 | \r | |
1139 | }\r | |
1140 | if (toBak != null)\r | |
1141 | try {\r | |
1142 | toBak.close();\r | |
1143 | } catch (IOException e) {\r | |
1144 | Log.err(toolsConfFile + ".bak Write Error ", e.getMessage());\r | |
1145 | }\r | |
1146 | }\r | |
1147 | }\r | |
1148 | \r | |
1149 | private void exit() {\r | |
1150 | this.setVisible(false);\r | |
1151 | if (bTarget != null) {\r | |
1152 | bTarget.dispose();\r | |
1153 | }\r | |
1154 | }\r | |
1155 | }\r |