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