2 <<The file is used to update the Build Preferences file, target.txt>>
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. >>
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
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.
18 Module Name: FrameworkWizard
22 package org
.tianocore
.frameworkwizard
.toolchain
;
24 import java
.awt
.event
.ActionEvent
;
26 import java
.util
.Vector
;
27 import java
.util
.Iterator
;
30 // import javax.swing.JScrollPane;
31 import javax
.swing
.JTextField
;
32 import javax
.swing
.JFrame
;
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
;
46 * The class is used to update the target.txt file.
51 public class Preferences
extends IFrame
{
54 // / Define class Serial Version UID
56 private static final long serialVersionUID
= -4777906991966638888L;
58 private final boolean Debug
= false;
61 // Define class members
63 private final int oneRowHeight
= 20;
65 private final int twoRowHeight
= 40;
67 private final int threeRowHeight
= 60;
69 private final int sepHeight
= 6;
71 private final int rowOne
= 12;
73 private final int rowTwo
= rowOne
+ oneRowHeight
+ sepHeight
;
75 private final int rowThree
= rowTwo
+ oneRowHeight
+ sepHeight
;
77 private final int rowFour
= rowThree
+ threeRowHeight
+ sepHeight
;
79 private final int rowFive
= rowFour
+ threeRowHeight
+ sepHeight
;
81 private final int buttonRow
= rowFive
+ oneRowHeight
+ sepHeight
+ sepHeight
;
83 private final int dialogHeight
= buttonRow
+ twoRowHeight
+ twoRowHeight
;
85 private final int dialogWidth
= 540;
87 private final int lastButtonXLoc
= 430;
89 private final int next2LastButtonLoc
= 329;
92 * Define the contents for this dialog box
94 private static Preferences bTarget
= null;
96 private WorkspaceTools wt
= new WorkspaceTools();
100 private JPanel jContentPane
= null;
102 private JLabel jLabelToolsConfigFile
= null;
104 private JTextField jTextFieldToolsConfigFile
= null;
106 private final int toolConfigFileRow
= rowOne
;
108 private final int toolDefFileId
= 3;
110 private JLabel jLabelActivePlatform
= null;
112 private JComboBox jComboBoxActivePlatform
= null;
114 private final int activePlatformId
= 0;
116 private final int activePlatformRow
= rowTwo
;
118 private JLabel jLabelToolChainTagName
= null;
120 private JScrollPane jScrollPaneTagName
= null;
122 private ICheckBoxList iCheckBoxListTagName
= null;
124 private final int toolChainTagNameRow
= rowThree
;
126 private final int tagNameId
= 4;
128 private JLabel jLabelBuildTarget
= null;
130 private JScrollPane jScrollPaneBuildTarget
= null;
132 private ICheckBoxList iCheckBoxListBuildTarget
= null;
134 private final int buildTargetRow
= rowFour
;
136 private final int buildTargetId
= 1;
138 private JLabel jLabelTargetArch
= null;
140 private ArchCheckBox jArchCheckBox
= null;
142 private final int targetArchRow
= rowFive
;
144 private final int targetArchId
= 2;
146 private JButton jButtonBrowse
= null;
148 private JButton jButtonSave
= null;
150 private JButton jButtonCancel
= null;
152 private final int labelColumn
= 12;
154 private final int labelWidth
= 155;
156 private final int valueColumn
= 168;
158 private final int valueWidth
= 352;
160 private final int valueWidthShort
= 260;
162 private final int buttonWidth
= 90;
164 private String workspaceDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator");
166 private String toolsDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + "Tools"
167 + System
.getProperty("file.separator") + "Conf";
169 private String defaultToolsConf
= toolsDir
+ System
.getProperty("file.separator") + "tools_def.txt";
171 private String targetFile
= toolsDir
+ System
.getProperty("file.separator") + "target.txt";
173 private String
[] targetFileContents
= new String
[500];
175 // private String[] toolsConfContents;
177 private String
[] targetLines
= new String
[5];
179 private int targetLineNumber
[] = new int[5];
181 private String toolsConfFile
;
183 private String toolsDefTargetNames
= null;
185 private final int toolsDefTargetNameField
= 0;
187 private String toolsDefTagNames
= null;
189 private final int toolsDefTagNameField
= 1;
191 private String toolsDefArchNames
= null;
193 private final int toolsDefArchNameField
= 2;
195 private String toolsDefIdentifier
= null;
197 private int targetLineNumberMax
;
199 private Vector
<String
> vArchList
= null;
204 // private Preferences id = null;
206 // private EnumerationData ed = new EnumerationData();
209 This method initializes jTextFieldToolsConfigFile
211 @return javax.swing.JTextField jTextFieldToolsConfigFile
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());
219 jTextFieldToolsConfigFile
= new JTextField();
221 jTextFieldToolsConfigFile
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolConfigFileRow
, valueWidthShort
,
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>");
232 return jTextFieldToolsConfigFile
;
236 * This method initializes jComboBoxActivePlatform
238 * @return javax.swing.JComboBox jComboBoxActivePlatform
241 private JComboBox
getActivePlatform() {
242 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
244 if (jComboBoxActivePlatform
== null) {
245 jComboBoxActivePlatform
= new JComboBox();
246 jComboBoxActivePlatform
.setBounds(new java
.awt
.Rectangle(valueColumn
, activePlatformRow
, valueWidth
,
248 jComboBoxActivePlatform
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
249 jComboBoxActivePlatform
.setToolTipText("<html>Select "Do Not Set" 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>");
254 * Generate the data, selecting what is in target.txt
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());
265 if (targetLines
[activePlatformId
] == null)
266 jComboBoxActivePlatform
.setSelectedItem("Do Not Set");
268 jComboBoxActivePlatform
.setSelectedItem(targetLines
[activePlatformId
]);
270 return jComboBoxActivePlatform
;
274 * This method initializes jScrollPaneTagName
276 * @return javax.swing.JScrollPane jScrollPaneTagName
279 private JScrollPane
getJScrollPaneTagName() {
281 if (jScrollPaneTagName
== null) {
282 jScrollPaneTagName
= new JScrollPane();
283 jScrollPaneTagName
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolChainTagNameRow
, valueWidth
,
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);
296 return jScrollPaneTagName
;
299 private ICheckBoxList
getICheckBoxListTagName() {
300 if (iCheckBoxListTagName
== null) {
301 iCheckBoxListTagName
= new ICheckBoxList();
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
]);
310 iCheckBoxListTagName
.setAllItems(vTags
);
312 Vector
<String
> defaultTags
= stringToVector("MYTOOLS");
313 iCheckBoxListTagName
.setAllItems(defaultTags
);
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
);
330 return iCheckBoxListTagName
;
334 * This method initializes jScrollPaneBuildTarget
336 * @return javax.swing.JComboBox jScrollPaneBuildTarget
339 private JScrollPane
getJScrollPaneBuildTarget() {
340 if (jScrollPaneBuildTarget
== null) {
341 jScrollPaneBuildTarget
= new JScrollPane();
342 jScrollPaneBuildTarget
.setBounds(new java
.awt
.Rectangle(valueColumn
, buildTargetRow
, valueWidth
,
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>");
356 return jScrollPaneBuildTarget
;
359 private ICheckBoxList
getICheckBoxListBuildTarget() {
360 if (iCheckBoxListBuildTarget
== null) {
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
]);
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>");
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
);
385 return iCheckBoxListBuildTarget
;
389 This method initializes jButtonBrowse
391 @return javax.swing.JButton
393 private JButton
getJButtonBrowse() {
394 if (jButtonBrowse
== null) {
395 jButtonBrowse
= new JButton();
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() {
404 private static final long serialVersionUID
= 1L;
406 public void actionPerformed(ActionEvent e
) {
408 // Select files from current workspace
410 String dirPrefix
= toolsDir
+ System
.getProperty("file.separator");
411 JFileChooser chooser
= new JFileChooser(dirPrefix
);
413 // String headerDest = null;
415 chooser
.setMultiSelectionEnabled(false);
416 chooser
.setFileSelectionMode(JFileChooser
.FILES_ONLY
);
417 int retval
= chooser
.showOpenDialog(frame
);
418 if (retval
== JFileChooser
.APPROVE_OPTION
) {
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!");
430 jTextFieldToolsConfigFile
.setText("Tools/Conf/" + theFile
.getName());
437 return jButtonBrowse
;
441 * This method initializes jButtonOk
443 * @return javax.swing.JButton
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);
457 * This method initializes jButtonCancel
459 * @return javax.swing.JButton
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);
469 return jButtonCancel
;
472 public static void main(String
[] args
) {
473 // TODO Auto-generated method stub
477 public static Preferences
getInstance() {
478 if (bTarget
== null) {
479 bTarget
= new Preferences();
485 * This is the default constructor
487 public Preferences() {
493 * This method initializes this
496 private void init() {
498 for (int i
= 0; i
< 5; i
++) {
499 targetLines
[i
] = null;
500 targetLineNumber
[i
] = -1;
503 this.setSize(dialogWidth
, dialogHeight
);
504 this.setContentPane(getJContentPane());
505 this.setTitle("Build Preferences [" + toolsDefIdentifier
+ "]");
506 this.setDefaultCloseOperation(IFrame
.EXIT_ON_CLOSE
);
508 this.setVisible(true);
512 * This method initializes this Fill values to all fields if these values are
515 * @param initReadFiles
518 private void initReadFiles() {
521 * Read Current target.txt file first
522 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
526 boolean haveBuildTargets
= readToolDefinitionFile();
527 if (!haveBuildTargets
) {
528 // Lookup Build Targets from the platforms
529 readPlatformFileBuildTargets();
533 private void readPlatformFileBuildTargets() {
534 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
535 String sBuildTargets
= "";
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(
545 sBuildTargets
+= fpd
.getPlatformDefinitions().getBuildTargets().toString() + " ";
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
] + " ";
555 private boolean readToolDefinitionFile() {
557 // Parse the tool definition file looking for targets and architectures
558 toolsConfFile
= null;
559 boolean buildTargetsExist
= true;
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>"
573 toolsConfFile
= defaultToolsConf
;
576 toolsConfFile
= defaultToolsConf
;
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()) {
584 FileReader fileReader
= new FileReader(toolDefFile
);
585 BufferedReader reader
= new BufferedReader(fileReader
);
589 while ((rLine
= reader
.readLine()) != null) {
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() + " ";
602 if (toolsDefTagNames
== null) {
603 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
604 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).trim())) {
605 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
607 if (toolsDefArchNames
== null) {
608 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
609 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).trim())) {
610 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
616 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
617 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
619 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
621 buildTargetsExist
= false;
623 } catch (IOException e
) {
624 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());
628 return buildTargetsExist
;
631 private void readTargetTxtFile() {
632 File tFile
= new File(targetFile
);
634 if (tFile
.exists()) {
636 FileReader fileReader
= new FileReader(targetFile
);
637 BufferedReader reader
= new BufferedReader(fileReader
);
638 targetLineNumberMax
= 0;
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
;
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(",", " ");
653 targetLines
[buildTargetId
] = rLine
.trim();
654 targetLineNumber
[buildTargetId
] = targetLineNumberMax
;
656 if (rLine
.startsWith("TARGET_ARCH")) {
657 // Handle multiple Target Architectures
658 if (rLine
.contains(","))
659 targetLines
[targetArchId
] = rLine
.trim().replaceAll(",", " ");
661 targetLines
[targetArchId
] = rLine
.trim();
662 targetLineNumber
[targetArchId
] = targetLineNumberMax
;
664 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
665 // Only one file is permitted
666 targetLines
[toolDefFileId
] = rLine
.trim();
667 targetLineNumber
[toolDefFileId
] = targetLineNumberMax
;
670 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
671 // Handle multiple Tool TagNames
672 if (rLine
.contains(","))
673 targetLines
[tagNameId
] = rLine
.trim().replaceAll(",", " ");
675 targetLines
[tagNameId
] = rLine
.trim();
676 targetLineNumber
[tagNameId
] = targetLineNumberMax
;
678 targetLineNumberMax
++;
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]);
693 for (int i
= 0; i
<= tagNameId
; i
++)
694 System
.out
.println("targetLines[" + i
+ "] contains: " + targetLines
[i
] + " index is: "
695 + targetLineNumber
[i
]);
697 } catch (IOException e
) {
698 Log
.log(this.targetFile
+ " Read Error ", e
.getMessage());
706 * This method initializes jContentPane
708 * @return javax.swing.JPanel jContentPane
711 private JPanel
getJContentPane() {
712 if (jContentPane
== null) {
713 jLabelToolsConfigFile
= new JLabel();
714 jLabelToolsConfigFile
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolConfigFileRow
, labelWidth
,
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
,
721 jLabelToolChainTagName
= new JLabel();
722 jLabelToolChainTagName
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolChainTagNameRow
, labelWidth
,
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
));
735 jContentPane
= new JPanel();
736 jContentPane
.setLayout(null);
737 jContentPane
.setPreferredSize(new java
.awt
.Dimension(dialogWidth
- 10, dialogHeight
- 10));
739 jContentPane
.add(jLabelToolsConfigFile
, null);
740 jContentPane
.add(getJTextFieldToolsConfigFile(), null);
741 jContentPane
.add(getJButtonBrowse(), null);
743 jContentPane
.add(jLabelActivePlatform
, null);
744 jContentPane
.add(getActivePlatform(), null);
746 jContentPane
.add(jLabelToolChainTagName
, null);
747 jContentPane
.add(getJScrollPaneTagName(), null);
749 jContentPane
.add(jLabelBuildTarget
, null);
750 jContentPane
.add(getJScrollPaneBuildTarget(), null);
752 jContentPane
.add(jLabelTargetArch
, null);
754 jArchCheckBox
.setSelectedItems(vArchList
);
755 jContentPane
.add(jArchCheckBox
, null);
757 jContentPane
.add(getJButtonSave(), null);
758 jContentPane
.add(getJButtonCancel(), null);
766 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
768 * Override actionPerformed to listen all actions
771 public void actionPerformed(ActionEvent arg0
) {
773 if (arg0
.getSource() == jButtonBrowse
) {
774 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
778 if (arg0
.getSource() == jButtonSave
) {
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>");
786 if (arg0
.getSource() == jButtonCancel
) {
791 private void updateActivePlatform() {
793 if (targetLines
[activePlatformId
] != null) {
794 lineAP
= targetLineNumber
[activePlatformId
];
796 lineAP
= targetLineNumberMax
;
797 targetLineNumber
[activePlatformId
] = lineAP
;
798 targetLineNumberMax
++;
800 if (jComboBoxActivePlatform
.getSelectedItem() == "Do Not Set") {
801 targetFileContents
[lineAP
] = "";
802 targetLines
[activePlatformId
] = "";
804 targetFileContents
[lineAP
] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform
.getSelectedItem() + "\r\n";
805 targetLines
[activePlatformId
] = targetFileContents
[lineAP
];
808 System
.out
.println("Active Platform: " + targetFileContents
[lineAP
]);
811 private void updateToolDefFile() {
813 if (targetLines
[toolDefFileId
] != null) {
814 lineTDF
= targetLineNumber
[toolDefFileId
];
816 lineTDF
= targetLineNumberMax
;
817 targetLineNumber
[toolDefFileId
] = lineTDF
;
818 targetLineNumberMax
++;
821 System
.out
.println("Tool Config File: " + jTextFieldToolsConfigFile
.getText());
822 if (jTextFieldToolsConfigFile
.getText() == null) {
823 targetFileContents
[lineTDF
] = "";
824 targetLines
[toolDefFileId
] = "";
826 targetFileContents
[lineTDF
] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile
.getText() + "\r\n";
827 targetLines
[toolDefFileId
] = targetFileContents
[lineTDF
];
831 private void updateToolTagNames() {
832 String sTagNames
= vectorToString(iCheckBoxListTagName
.getAllCheckedItemsString());
835 if (targetLines
[tagNameId
] != null) {
836 lineTTN
= targetLineNumber
[tagNameId
];
838 lineTTN
= targetLineNumberMax
;
839 targetLineNumber
[tagNameId
] = lineTTN
;
840 targetLineNumberMax
++;
844 System
.out
.println("Tag Name(s): " + sTagNames
);
846 if (sTagNames
.length() > 0) {
847 targetFileContents
[lineTTN
] = "TOOL_CHAIN_TAG = " + sTagNames
+ "\r\n";
848 targetLines
[tagNameId
] = targetFileContents
[lineTTN
];
850 targetFileContents
[lineTTN
] = "";
851 targetLines
[tagNameId
] = "";
855 private void updateBuildTargets() {
856 String sBuildTargets
= vectorToString(iCheckBoxListBuildTarget
.getAllCheckedItemsString());
859 if (targetLines
[buildTargetId
] != null) {
860 lineBT
= targetLineNumber
[buildTargetId
];
862 lineBT
= targetLineNumberMax
;
863 targetLineNumber
[buildTargetId
] = lineBT
;
864 targetLineNumberMax
++;
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
];
872 targetFileContents
[lineBT
] = "";
873 targetLines
[buildTargetId
] = "";
878 private void updateArchitectures() {
879 String sArchList
= jArchCheckBox
.getSelectedItemsString().trim();
882 System
.out
.println("Architectures: " + sArchList
);
885 if (targetLines
[targetArchId
] != null) {
886 lineSA
= targetLineNumber
[targetArchId
];
888 lineSA
= targetLineNumberMax
;
889 targetLineNumber
[targetArchId
] = lineSA
;
890 targetLineNumberMax
++;
892 if (sArchList
== "") {
893 targetFileContents
[lineSA
] = "";
894 targetLines
[targetArchId
] = "";
896 targetFileContents
[lineSA
] = "TARGET_ARCH = " + sArchList
+ "\r\n";
897 targetLines
[targetArchId
] = targetFileContents
[lineSA
];
902 private String
vectorToString(Vector
<String
> v
) {
904 for (int i
= 0; i
< v
.size(); ++i
) {
911 protected Vector
<String
> stringToVector(String s
) {
915 String
[] sArray
= s
.split(" ");
916 Vector
<String
> v
= new Vector
<String
>();
917 for (int i
= 0; i
< sArray
.length
; ++i
) {
923 private void saveTargetFile() {
924 updateActivePlatform();
926 updateToolTagNames();
927 updateBuildTargets();
928 updateArchitectures();
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");
938 } catch (IOException e
) {
939 Log
.err(toolsConfFile
+ " Write Error ", e
.getMessage());
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;
950 fromTxt
= new FileInputStream(fromFile
);
951 toBak
= new FileOutputStream(toFile
);
952 byte[] buffer
= new byte[4096];
954 while ((bytes_read
= fromTxt
.read(buffer
)) != -1) {
955 toBak
.write(buffer
, 0, bytes_read
);
961 } catch (IOException e
) {
962 Log
.err(toolsConfFile
+ " Read Error ", e
.getMessage());
968 } catch (IOException e
) {
969 Log
.err(toolsConfFile
+ ".bak Write Error ", e
.getMessage());
974 private void exit() {
975 this.setVisible(false);
976 if (bTarget
!= null) {