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