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;
201 private Vector
<String
> vDisableArchList
= null;
206 // private Preferences id = null;
208 // private EnumerationData ed = new EnumerationData();
211 This method initializes jTextFieldToolsConfigFile
213 @return javax.swing.JTextField jTextFieldToolsConfigFile
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());
221 jTextFieldToolsConfigFile
= new JTextField();
223 jTextFieldToolsConfigFile
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolConfigFileRow
, valueWidthShort
,
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>");
234 return jTextFieldToolsConfigFile
;
238 * This method initializes jComboBoxActivePlatform
240 * @return javax.swing.JComboBox jComboBoxActivePlatform
243 private JComboBox
getActivePlatform() {
244 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
246 if (jComboBoxActivePlatform
== null) {
247 jComboBoxActivePlatform
= new JComboBox();
248 jComboBoxActivePlatform
.setBounds(new java
.awt
.Rectangle(valueColumn
, activePlatformRow
, valueWidth
,
250 jComboBoxActivePlatform
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
251 jComboBoxActivePlatform
252 .setToolTipText("<html>Select "Do Not Set" 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>");
257 * Generate the data, selecting what is in target.txt
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());
268 if (targetLines
[activePlatformId
] == null)
269 jComboBoxActivePlatform
.setSelectedItem("Do Not Set");
271 jComboBoxActivePlatform
.setSelectedItem(targetLines
[activePlatformId
]);
273 return jComboBoxActivePlatform
;
277 * This method initializes jScrollPaneTagName
279 * @return javax.swing.JScrollPane jScrollPaneTagName
282 private JScrollPane
getJScrollPaneTagName() {
284 if (jScrollPaneTagName
== null) {
285 jScrollPaneTagName
= new JScrollPane();
286 jScrollPaneTagName
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolChainTagNameRow
, valueWidth
,
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);
299 return jScrollPaneTagName
;
302 private ICheckBoxList
getICheckBoxListTagName() {
303 if (iCheckBoxListTagName
== null) {
304 iCheckBoxListTagName
= new ICheckBoxList();
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
]);
313 iCheckBoxListTagName
.setAllItems(vTags
);
315 Vector
<String
> defaultTags
= stringToVector("MYTOOLS");
316 iCheckBoxListTagName
.setAllItems(defaultTags
);
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
);
333 return iCheckBoxListTagName
;
337 * This method initializes jScrollPaneBuildTarget
339 * @return javax.swing.JComboBox jScrollPaneBuildTarget
342 private JScrollPane
getJScrollPaneBuildTarget() {
343 if (jScrollPaneBuildTarget
== null) {
344 jScrollPaneBuildTarget
= new JScrollPane();
345 jScrollPaneBuildTarget
.setBounds(new java
.awt
.Rectangle(valueColumn
, buildTargetRow
, valueWidth
,
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>");
359 return jScrollPaneBuildTarget
;
362 private ICheckBoxList
getICheckBoxListBuildTarget() {
363 if (iCheckBoxListBuildTarget
== null) {
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
]);
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>");
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
);
388 return iCheckBoxListBuildTarget
;
392 This method initializes jButtonBrowse
394 @return javax.swing.JButton
396 private JButton
getJButtonBrowse() {
397 if (jButtonBrowse
== null) {
398 jButtonBrowse
= new JButton();
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() {
407 private static final long serialVersionUID
= 1L;
409 public void actionPerformed(ActionEvent e
) {
411 // Select files from current workspace
413 String dirPrefix
= toolsDir
+ System
.getProperty("file.separator");
414 JFileChooser chooser
= new JFileChooser(dirPrefix
);
416 // String headerDest = null;
418 chooser
.setMultiSelectionEnabled(false);
419 chooser
.setFileSelectionMode(JFileChooser
.FILES_ONLY
);
420 int retval
= chooser
.showOpenDialog(frame
);
421 if (retval
== JFileChooser
.APPROVE_OPTION
) {
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!");
433 jTextFieldToolsConfigFile
.setText("Tools/Conf/" + theFile
.getName());
440 return jButtonBrowse
;
444 * This method initializes jButtonOk
446 * @return javax.swing.JButton
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);
460 * This method initializes jButtonCancel
462 * @return javax.swing.JButton
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);
472 return jButtonCancel
;
475 public static void main(String
[] args
) {
476 // TODO Auto-generated method stub
480 public static Preferences
getInstance() {
481 if (bTarget
== null) {
482 bTarget
= new Preferences();
488 * This is the default constructor
490 public Preferences() {
496 * This method initializes this
499 private void init() {
501 for (int i
= 0; i
< 5; i
++) {
502 targetLines
[i
] = null;
503 targetLineNumber
[i
] = -1;
506 this.setSize(dialogWidth
, dialogHeight
);
507 this.setContentPane(getJContentPane());
508 this.setTitle("Build Preferences [" + toolsDefIdentifier
+ "]");
509 this.setDefaultCloseOperation(IFrame
.EXIT_ON_CLOSE
);
511 this.setVisible(true);
515 * This method initializes this Fill values to all fields if these values are
518 * @param initReadFiles
521 private void initReadFiles() {
524 * Read Current target.txt file first
525 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
529 boolean haveBuildTargets
= readToolDefinitionFile();
530 if (!haveBuildTargets
) {
531 // Lookup Build Targets from the platforms
532 readPlatformFileBuildTargets();
536 private void readPlatformFileBuildTargets() {
537 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
538 String sBuildTargets
= "";
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(
548 sBuildTargets
+= fpd
.getPlatformDefinitions().getBuildTargets().toString() + " ";
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
] + " ";
558 private boolean readToolDefinitionFile() {
560 // Parse the tool definition file looking for targets and architectures
561 toolsConfFile
= null;
562 boolean buildTargetsExist
= true;
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>"
576 toolsConfFile
= defaultToolsConf
;
579 toolsConfFile
= defaultToolsConf
;
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()) {
587 FileReader fileReader
= new FileReader(toolDefFile
);
588 BufferedReader reader
= new BufferedReader(fileReader
);
592 while ((rLine
= reader
.readLine()) != null) {
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() + " ";
605 if (toolsDefTagNames
== null) {
606 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
607 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).trim())) {
608 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
610 if (toolsDefArchNames
== null) {
611 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
612 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).trim())) {
613 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
619 // Only enable Architecture selection based on tool chain installations
621 if (!toolsDefArchNames
.contains("EBC"))
623 if (!toolsDefArchNames
.contains("PPC"))
625 if (!toolsDefArchNames
.contains("IPF"))
627 if (!toolsDefArchNames
.contains("X64"))
629 if (!toolsDefArchNames
.contains("IA32"))
631 if (!toolsDefArchNames
.contains("ARM"))
633 turnOff
= turnOff
.trim();
634 vDisableArchList
= stringToVector(turnOff
);
636 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
637 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
639 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
641 buildTargetsExist
= false;
643 } catch (IOException e
) {
644 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());
648 return buildTargetsExist
;
651 private void readTargetTxtFile() {
652 File tFile
= new File(targetFile
);
654 if (tFile
.exists()) {
656 FileReader fileReader
= new FileReader(targetFile
);
657 BufferedReader reader
= new BufferedReader(fileReader
);
658 targetLineNumberMax
= 0;
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
;
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(",", " ");
673 targetLines
[buildTargetId
] = rLine
.trim();
674 targetLineNumber
[buildTargetId
] = targetLineNumberMax
;
676 if (rLine
.startsWith("TARGET_ARCH")) {
677 // Handle multiple Target Architectures
678 if (rLine
.contains(","))
679 targetLines
[targetArchId
] = rLine
.trim().replaceAll(",", " ");
681 targetLines
[targetArchId
] = rLine
.trim();
682 targetLineNumber
[targetArchId
] = targetLineNumberMax
;
684 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
685 // Only one file is permitted
686 targetLines
[toolDefFileId
] = rLine
.trim();
687 targetLineNumber
[toolDefFileId
] = targetLineNumberMax
;
690 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
691 // Handle multiple Tool TagNames
692 if (rLine
.contains(","))
693 targetLines
[tagNameId
] = rLine
.trim().replaceAll(",", " ");
695 targetLines
[tagNameId
] = rLine
.trim();
696 targetLineNumber
[tagNameId
] = targetLineNumberMax
;
698 targetLineNumberMax
++;
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]);
713 for (int i
= 0; i
<= tagNameId
; i
++)
714 System
.out
.println("targetLines[" + i
+ "] contains: " + targetLines
[i
] + " index is: "
715 + targetLineNumber
[i
]);
717 } catch (IOException e
) {
718 Log
.log(this.targetFile
+ " Read Error ", e
.getMessage());
726 * This method initializes jContentPane
728 * @return javax.swing.JPanel jContentPane
731 private JPanel
getJContentPane() {
732 if (jContentPane
== null) {
733 jLabelToolsConfigFile
= new JLabel();
734 jLabelToolsConfigFile
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolConfigFileRow
, labelWidth
,
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
,
741 jLabelToolChainTagName
= new JLabel();
742 jLabelToolChainTagName
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolChainTagNameRow
, labelWidth
,
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
));
755 jContentPane
= new JPanel();
756 jContentPane
.setLayout(null);
757 jContentPane
.setPreferredSize(new java
.awt
.Dimension(dialogWidth
- 10, dialogHeight
- 10));
759 jContentPane
.add(jLabelToolsConfigFile
, null);
760 jContentPane
.add(getJTextFieldToolsConfigFile(), null);
761 jContentPane
.add(getJButtonBrowse(), null);
763 jContentPane
.add(jLabelActivePlatform
, null);
764 jContentPane
.add(getActivePlatform(), null);
766 jContentPane
.add(jLabelToolChainTagName
, null);
767 jContentPane
.add(getJScrollPaneTagName(), null);
769 jContentPane
.add(jLabelBuildTarget
, null);
770 jContentPane
.add(getJScrollPaneBuildTarget(), null);
772 jContentPane
.add(jLabelTargetArch
, null);
774 jArchCheckBox
.setDisabledItems(vDisableArchList
);
775 jArchCheckBox
.setSelectedItems(vArchList
);
776 jContentPane
.add(jArchCheckBox
, null);
778 jContentPane
.add(getJButtonSave(), null);
779 jContentPane
.add(getJButtonCancel(), null);
787 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
789 * Override actionPerformed to listen all actions
792 public void actionPerformed(ActionEvent arg0
) {
794 if (arg0
.getSource() == jButtonBrowse
) {
795 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
799 if (arg0
.getSource() == jButtonSave
) {
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>");
807 if (arg0
.getSource() == jButtonCancel
) {
812 private void updateActivePlatform() {
814 if (targetLines
[activePlatformId
] != null) {
815 lineAP
= targetLineNumber
[activePlatformId
];
817 lineAP
= targetLineNumberMax
;
818 targetLineNumber
[activePlatformId
] = lineAP
;
819 targetLineNumberMax
++;
821 if (jComboBoxActivePlatform
.getSelectedItem() == "Do Not Set") {
822 targetFileContents
[lineAP
] = "";
823 targetLines
[activePlatformId
] = "";
825 targetFileContents
[lineAP
] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform
.getSelectedItem() + "\r\n";
826 targetLines
[activePlatformId
] = targetFileContents
[lineAP
];
829 System
.out
.println("Active Platform: " + targetFileContents
[lineAP
]);
832 private void updateToolDefFile() {
834 if (targetLines
[toolDefFileId
] != null) {
835 lineTDF
= targetLineNumber
[toolDefFileId
];
837 lineTDF
= targetLineNumberMax
;
838 targetLineNumber
[toolDefFileId
] = lineTDF
;
839 targetLineNumberMax
++;
842 System
.out
.println("Tool Config File: " + jTextFieldToolsConfigFile
.getText());
843 if (jTextFieldToolsConfigFile
.getText() == null) {
844 targetFileContents
[lineTDF
] = "";
845 targetLines
[toolDefFileId
] = "";
847 targetFileContents
[lineTDF
] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile
.getText() + "\r\n";
848 targetLines
[toolDefFileId
] = targetFileContents
[lineTDF
];
852 private void updateToolTagNames() {
853 String sTagNames
= vectorToString(iCheckBoxListTagName
.getAllCheckedItemsString());
856 if (targetLines
[tagNameId
] != null) {
857 lineTTN
= targetLineNumber
[tagNameId
];
859 lineTTN
= targetLineNumberMax
;
860 targetLineNumber
[tagNameId
] = lineTTN
;
861 targetLineNumberMax
++;
865 System
.out
.println("Tag Name(s): " + sTagNames
);
867 if (sTagNames
.length() > 0) {
868 targetFileContents
[lineTTN
] = "TOOL_CHAIN_TAG = " + sTagNames
+ "\r\n";
869 targetLines
[tagNameId
] = targetFileContents
[lineTTN
];
871 targetFileContents
[lineTTN
] = "";
872 targetLines
[tagNameId
] = "";
876 private void updateBuildTargets() {
877 String sBuildTargets
= vectorToString(iCheckBoxListBuildTarget
.getAllCheckedItemsString());
880 if (targetLines
[buildTargetId
] != null) {
881 lineBT
= targetLineNumber
[buildTargetId
];
883 lineBT
= targetLineNumberMax
;
884 targetLineNumber
[buildTargetId
] = lineBT
;
885 targetLineNumberMax
++;
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
];
893 targetFileContents
[lineBT
] = "";
894 targetLines
[buildTargetId
] = "";
899 private void updateArchitectures() {
900 String sArchList
= jArchCheckBox
.getSelectedItemsString().trim();
903 System
.out
.println("Architectures: " + sArchList
);
906 if (targetLines
[targetArchId
] != null) {
907 lineSA
= targetLineNumber
[targetArchId
];
909 lineSA
= targetLineNumberMax
;
910 targetLineNumber
[targetArchId
] = lineSA
;
911 targetLineNumberMax
++;
913 if (sArchList
== "") {
914 targetFileContents
[lineSA
] = "";
915 targetLines
[targetArchId
] = "";
917 targetFileContents
[lineSA
] = "TARGET_ARCH = " + sArchList
+ "\r\n";
918 targetLines
[targetArchId
] = targetFileContents
[lineSA
];
923 private String
vectorToString(Vector
<String
> v
) {
925 for (int i
= 0; i
< v
.size(); ++i
) {
932 protected Vector
<String
> stringToVector(String s
) {
936 String
[] sArray
= s
.split(" ");
937 Vector
<String
> v
= new Vector
<String
>();
938 for (int i
= 0; i
< sArray
.length
; ++i
) {
944 private void saveTargetFile() {
945 updateActivePlatform();
947 updateToolTagNames();
948 updateBuildTargets();
949 updateArchitectures();
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");
959 } catch (IOException e
) {
960 Log
.err(toolsConfFile
+ " Write Error ", e
.getMessage());
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;
971 fromTxt
= new FileInputStream(fromFile
);
972 toBak
= new FileOutputStream(toFile
);
973 byte[] buffer
= new byte[4096];
975 while ((bytes_read
= fromTxt
.read(buffer
)) != -1) {
976 toBak
.write(buffer
, 0, bytes_read
);
982 } catch (IOException e
) {
983 Log
.err(toolsConfFile
+ " Read Error ", e
.getMessage());
989 } catch (IOException e
) {
990 Log
.err(toolsConfFile
+ ".bak Write Error ", e
.getMessage());
995 private void exit() {
996 this.setVisible(false);
997 if (bTarget
!= null) {