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