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
;
28 import java
.util
.Scanner
;
31 import javax
.swing
.JScrollPane
;
32 import javax
.swing
.JTextField
;
33 import javax
.swing
.JFrame
;
35 import org
.tianocore
.frameworkwizard
.common
.GlobalData
;
36 import org
.tianocore
.frameworkwizard
.common
.Tools
;
37 import org
.tianocore
.frameworkwizard
.common
.Log
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
39 import org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
.*;
40 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
41 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
42 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
44 import org
.tianocore
.PlatformSurfaceAreaDocument
;
47 * The class is used to update the target.txt file.
52 public class Preferences
extends IFrame
{
55 // / Define class Serial Version UID
57 private static final long serialVersionUID
= -4777906991966638888L;
59 private final boolean Debug
= false;
62 // Define class members
64 private final int oneRowHeight
= 20;
66 private final int twoRowHeight
= 40;
68 private final int threeRowHeight
= 60;
70 private final int sepHeight
= 6;
72 private final int rowOne
= 12;
74 private final int rowTwo
= rowOne
+ oneRowHeight
+ sepHeight
;
76 private final int rowThree
= rowTwo
+ oneRowHeight
+ sepHeight
;
78 private final int rowFour
= rowThree
+ threeRowHeight
+ sepHeight
;
80 private final int rowFive
= rowFour
+ threeRowHeight
+ sepHeight
;
82 private final int rowSix
= rowFive
+ oneRowHeight
+ sepHeight
;
84 private final int buttonRow
= rowSix
+ oneRowHeight
+ sepHeight
+ sepHeight
;
86 private final int dialogHeight
= buttonRow
+ twoRowHeight
+ twoRowHeight
;
88 private final int dialogWidth
= 540;
90 private final int lastButtonXLoc
= 430;
92 private final int next2LastButtonLoc
= 329;
95 * Define the contents for this dialog box
97 private static Preferences bTarget
= null;
99 private WorkspaceTools wt
= new WorkspaceTools();
101 private JFrame frame
;
103 private final int activePlatformId
= 0;
105 private final int buildTargetId
= 1;
107 private final int targetArchId
= 2;
109 private final int toolDefFileId
= 3;
111 private final int tagNameId
= 4;
113 private final int threadEnableId
= 5;
115 private final int threadCountId
= 6;
117 private final int maxTargetLines
= threadCountId
+ 1;
119 private JPanel jContentPane
= null;
121 private JLabel jLabelToolsConfigFile
= null;
123 private JTextField jTextFieldToolsConfigFile
= null;
125 private final int toolConfigFileRow
= rowOne
;
127 private JLabel jLabelActivePlatform
= null;
129 private JComboBox jComboBoxActivePlatform
= null;
131 private final int activePlatformRow
= rowTwo
;
133 private JLabel jLabelToolChainTagName
= null;
135 private JScrollPane jScrollPaneTagName
= null;
137 private ICheckBoxList iCheckBoxListTagName
= null;
139 private final int toolChainTagNameRow
= rowThree
;
141 private JLabel jLabelBuildTarget
= null;
143 private JScrollPane jScrollPaneBuildTarget
= null;
145 private ICheckBoxList iCheckBoxListBuildTarget
= null;
147 private final int buildTargetRow
= rowFour
;
149 private JLabel jLabelTargetArch
= null;
151 private ArchCheckBox jArchCheckBox
= null;
153 private final int targetArchRow
= rowFive
;
155 private JLabel jLabelEnableThreads
= null;
157 private JLabel jLabelThreadCount
= null;
159 private final int threadRow
= rowSix
;
161 private JCheckBox jCheckBoxEnableThreads
= null;
163 private JTextField jTextFieldThreadCount
= null;
165 private String threadCount
;
167 private boolean threadEnabled
= false;
169 private JButton jButtonBrowse
= null;
171 private JButton jButtonSave
= null;
173 private JButton jButtonCancel
= null;
175 private final int labelColumn
= 12;
177 private final int labelWidth
= 155;
179 private final int valueColumn
= 168;
181 private final int valueWidth
= 352;
183 private final int valueWidthShort
= 260;
185 private final int buttonWidth
= 90;
187 private String workspaceDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator");
189 private String toolsDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + "Tools"
190 + System
.getProperty("file.separator") + "Conf";
192 private String defaultToolsConf
= toolsDir
+ System
.getProperty("file.separator") + "tools_def.txt";
194 private String targetFile
= toolsDir
+ System
.getProperty("file.separator") + "target.txt";
196 private String
[] targetFileContents
= new String
[500];
198 // private String[] toolsConfContents;
200 private String
[] targetLines
= new String
[maxTargetLines
];
202 private int targetLineNumber
[] = new int[maxTargetLines
];
204 private String toolsConfFile
;
206 private String toolsDefTargetNames
= null;
208 private final int toolsDefTargetNameField
= 0;
210 private String toolsDefTagNames
= null;
212 private final int toolsDefTagNameField
= 1;
214 private String toolsDefArchNames
= null;
216 private final int toolsDefArchNameField
= 2;
218 private String toolsDefIdentifier
= null;
220 private int targetLineNumberMax
;
222 private final int toolDefFieldCount
= 5;
224 private Vector
<String
> vArchList
= null;
226 private Vector
<String
> vDisableArchList
= null;
231 // private Preferences id = null;
233 // private EnumerationData ed = new EnumerationData();
236 This method initializes jTextFieldToolsConfigFile
238 @return javax.swing.JTextField jTextFieldToolsConfigFile
240 private JTextField
getJTextFieldToolsConfigFile() {
241 if (jTextFieldToolsConfigFile
== null) {
242 if (targetLines
[toolDefFileId
] != null) {
243 String sLine
[] = targetLines
[toolDefFileId
].trim().split("=");
244 jTextFieldToolsConfigFile
= new JTextField(sLine
[1].trim());
246 jTextFieldToolsConfigFile
= new JTextField();
248 jTextFieldToolsConfigFile
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolConfigFileRow
, valueWidthShort
,
250 jTextFieldToolsConfigFile
.setPreferredSize(new java
.awt
.Dimension(valueWidthShort
, oneRowHeight
));
251 jTextFieldToolsConfigFile
252 .setToolTipText("<html>"
253 + "Specify the name of the filename to use for specifying"
254 + "<br>the tools to use for the build. If not specified,"
255 + "<br>tools_def.txt will be used for the build. This file"
256 + "<br>MUST be located in the WORKSPACE/Tools/Conf directory.</html>");
259 return jTextFieldToolsConfigFile
;
263 * This method initializes jComboBoxActivePlatform
265 * @return javax.swing.JComboBox jComboBoxActivePlatform
268 private JComboBox
getActivePlatform() {
269 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
271 if (jComboBoxActivePlatform
== null) {
272 jComboBoxActivePlatform
= new JComboBox();
273 jComboBoxActivePlatform
.setBounds(new java
.awt
.Rectangle(valueColumn
, activePlatformRow
, valueWidth
,
275 jComboBoxActivePlatform
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
276 jComboBoxActivePlatform
277 .setToolTipText("<html>Select "Do Not Set" if you want to build a platform"
278 + "<br>from the directory where the FPD file exists,"
279 + "<br>otherwise scroll down to select the platform.</html>");
282 * Generate the data, selecting what is in target.txt
284 jComboBoxActivePlatform
.addItem("Do Not Set");
285 Iterator
<PlatformIdentification
> iter
= vPlatformId
.iterator();
286 while (iter
.hasNext()) {
287 PlatformIdentification item
= iter
.next();
288 String path
= item
.getPath().trim();
289 String str
= path
.substring(workspaceDir
.length(), path
.length());
290 str
.replace(System
.getProperty("file.separator"), "/");
291 jComboBoxActivePlatform
.addItem(str
.trim());
293 if (targetLines
[activePlatformId
] == null)
294 jComboBoxActivePlatform
.setSelectedItem("Do Not Set");
296 jComboBoxActivePlatform
.setSelectedItem(targetLines
[activePlatformId
]);
298 return jComboBoxActivePlatform
;
302 * This method initializes jScrollPaneTagName
304 * @return javax.swing.JScrollPane jScrollPaneTagName
307 private JScrollPane
getJScrollPaneTagName() {
309 if (jScrollPaneTagName
== null) {
310 jScrollPaneTagName
= new JScrollPane();
311 jScrollPaneTagName
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolChainTagNameRow
, valueWidth
,
313 jScrollPaneTagName
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, threeRowHeight
));
314 jScrollPaneTagName
.setHorizontalScrollBarPolicy(JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
315 jScrollPaneTagName
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_AS_NEEDED
);
316 jScrollPaneTagName
.setViewportView(getICheckBoxListTagName());
317 jScrollPaneTagName
.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 jScrollPaneTagName
.setVisible(true);
324 return jScrollPaneTagName
;
327 private ICheckBoxList
getICheckBoxListTagName() {
328 if (iCheckBoxListTagName
== null) {
329 iCheckBoxListTagName
= new ICheckBoxList();
331 if (toolsDefTagNames
!= null) {
332 toolsDefTagNames
.trim();
333 String aTagNames
[] = toolsDefTagNames
.trim().split(" ");
334 Vector
<String
> vTags
= new Vector
<String
>();
335 for (int i
= 0; i
< aTagNames
.length
; i
++) {
336 vTags
.add(aTagNames
[i
]);
338 iCheckBoxListTagName
.setAllItems(vTags
);
340 Vector
<String
> defaultTags
= stringToVector("MYTOOLS");
341 iCheckBoxListTagName
.setAllItems(defaultTags
);
344 iCheckBoxListTagName
.setAllItemsUnchecked();
345 iCheckBoxListTagName
.setToolTipText("<html>"
346 + "Specify the TagName(s) from the tool configuration file to use"
347 + "<br>for your builds. If not specified, all applicable TagName"
348 + " <br>tools will be used for the build.</html>");
349 Vector
<String
> vSelectedTags
= new Vector
<String
>();
350 if (targetLines
[tagNameId
] != null) {
351 targetLines
[tagNameId
].trim();
352 String targetTags
[] = targetLines
[tagNameId
].trim().split(" ");
353 for (int j
= 0; j
< targetTags
.length
; j
++)
354 vSelectedTags
.add(targetTags
[j
]);
355 iCheckBoxListTagName
.initCheckedItem(true, vSelectedTags
);
358 return iCheckBoxListTagName
;
362 * This method initializes jScrollPaneBuildTarget
364 * @return javax.swing.JComboBox jScrollPaneBuildTarget
367 private JScrollPane
getJScrollPaneBuildTarget() {
368 if (jScrollPaneBuildTarget
== null) {
369 jScrollPaneBuildTarget
= new JScrollPane();
370 jScrollPaneBuildTarget
.setBounds(new java
.awt
.Rectangle(valueColumn
, buildTargetRow
, valueWidth
,
372 jScrollPaneBuildTarget
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, threeRowHeight
));
373 jScrollPaneBuildTarget
.setHorizontalScrollBarPolicy(JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
374 jScrollPaneBuildTarget
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_AS_NEEDED
);
375 jScrollPaneBuildTarget
.setViewportView(getICheckBoxListBuildTarget());
376 jScrollPaneBuildTarget
.setVisible(true);
377 jScrollPaneBuildTarget
.setToolTipText("<html>"
378 + "Select the TARGET Names that you want to build, such as<BR>"
379 + "BUILD or BUILD and RELEASE"
380 + "<br>If you do not set any of these, all available targets"
381 + "<br>will be built.</html>");
384 return jScrollPaneBuildTarget
;
387 private JCheckBox
getCheckBoxEnableThreads() {
388 if (jCheckBoxEnableThreads
== null) {
389 jCheckBoxEnableThreads
= new JCheckBox();
390 jCheckBoxEnableThreads
.setBounds(valueColumn
, threadRow
, 20, oneRowHeight
);
391 jCheckBoxEnableThreads
.setToolTipText("Select this if you want to enable parallel compilation.");
392 jCheckBoxEnableThreads
.setSelected(threadEnabled
);
393 jCheckBoxEnableThreads
.addActionListener(this);
396 return jCheckBoxEnableThreads
;
399 private JTextField
getTextFieldThreadCount() {
400 if (jTextFieldThreadCount
== null) {
401 jTextFieldThreadCount
= new JTextField();
402 jTextFieldThreadCount
.setBounds(valueColumn
+ 215, threadRow
, 30, oneRowHeight
);
403 if (threadCount
.length() > 0)
404 jTextFieldThreadCount
.setText(threadCount
);
405 jTextFieldThreadCount
.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");
406 // If CheckBoxEnableThreads is selected, then enable editing
409 return jTextFieldThreadCount
;
412 private ICheckBoxList
getICheckBoxListBuildTarget() {
413 if (iCheckBoxListBuildTarget
== null) {
415 String aBuildTargets
[] = toolsDefTargetNames
.trim().split(" ");
416 Vector
<String
> vBuildTargets
= new Vector
<String
>();
417 for (int i
= 0; i
< aBuildTargets
.length
; i
++) {
418 vBuildTargets
.add(aBuildTargets
[i
]);
420 iCheckBoxListBuildTarget
= new ICheckBoxList();
421 iCheckBoxListBuildTarget
.setAllItems(vBuildTargets
);
422 iCheckBoxListBuildTarget
.setAllItemsUnchecked();
423 iCheckBoxListBuildTarget
.setToolTipText("<html>"
424 + "Select the TARGET Names that you want to build, such as<BR>"
425 + "BUILD or BUILD and RELEASE"
426 + "<br>If you do not set any of these, all available targets"
427 + "<br>will be built.</html>");
429 Vector
<String
> vSelectedTags
= new Vector
<String
>();
430 if (targetLines
[buildTargetId
] != null) {
431 targetLines
[buildTargetId
].trim();
432 String targetTags
[] = targetLines
[buildTargetId
].trim().split(" ");
433 for (int j
= 0; j
< targetTags
.length
; j
++)
434 vSelectedTags
.add(targetTags
[j
]);
435 iCheckBoxListBuildTarget
.initCheckedItem(true, vSelectedTags
);
438 return iCheckBoxListBuildTarget
;
442 This method initializes jButtonBrowse
444 @return javax.swing.JButton
446 private JButton
getJButtonBrowse() {
447 if (jButtonBrowse
== null) {
448 jButtonBrowse
= new JButton();
450 .setBounds(new java
.awt
.Rectangle(lastButtonXLoc
, toolConfigFileRow
, buttonWidth
, oneRowHeight
));
451 jButtonBrowse
.setText("Browse");
452 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(buttonWidth
, oneRowHeight
));
453 jButtonBrowse
.addActionListener(new AbstractAction() {
457 private static final long serialVersionUID
= 1L;
459 public void actionPerformed(ActionEvent e
) {
461 // Select files from current workspace
463 String dirPrefix
= toolsDir
+ System
.getProperty("file.separator");
464 JFileChooser chooser
= new JFileChooser(dirPrefix
);
466 // String headerDest = null;
468 chooser
.setMultiSelectionEnabled(false);
469 chooser
.setFileSelectionMode(JFileChooser
.FILES_ONLY
);
470 int retval
= chooser
.showOpenDialog(frame
);
471 if (retval
== JFileChooser
.APPROVE_OPTION
) {
473 theFile
= chooser
.getSelectedFile();
474 String file
= theFile
.getPath();
475 if (!file
.startsWith(dirPrefix
)) {
476 JOptionPane
.showMessageDialog(frame
, "You can only select files in the Tools"
477 + System
.getProperty("file.separator")
478 + "Conf directory!");
483 jTextFieldToolsConfigFile
.setText("Tools/Conf/" + theFile
.getName());
490 return jButtonBrowse
;
494 * This method initializes jButtonOk
496 * @return javax.swing.JButton
499 private JButton
getJButtonSave() {
500 if (jButtonSave
== null) {
501 jButtonSave
= new JButton();
502 jButtonSave
.setBounds(new java
.awt
.Rectangle(next2LastButtonLoc
, buttonRow
, buttonWidth
, oneRowHeight
));
503 jButtonSave
.setText("Save");
504 jButtonSave
.addActionListener(this);
510 * This method initializes jButtonCancel
512 * @return javax.swing.JButton
515 private JButton
getJButtonCancel() {
516 if (jButtonCancel
== null) {
517 jButtonCancel
= new JButton();
518 jButtonCancel
.setBounds(new java
.awt
.Rectangle(lastButtonXLoc
, buttonRow
, buttonWidth
, oneRowHeight
));
519 jButtonCancel
.setText("Cancel");
520 jButtonCancel
.addActionListener(this);
522 return jButtonCancel
;
525 public static void main(String
[] args
) {
526 // TODO Auto-generated method stub
530 public static Preferences
getInstance() {
531 if (bTarget
== null) {
532 bTarget
= new Preferences();
538 * This is the default constructor
540 public Preferences() {
546 * This method initializes this
549 private void init() {
551 for (int i
= 0; i
< maxTargetLines
; i
++) {
552 targetLines
[i
] = null;
553 targetLineNumber
[i
] = -1;
556 this.setSize(dialogWidth
, dialogHeight
);
557 this.setContentPane(getJContentPane());
558 this.setTitle("Build Preferences [" + toolsDefIdentifier
+ "]");
559 this.setDefaultCloseOperation(IFrame
.EXIT_ON_CLOSE
);
561 this.setVisible(true);
565 * This method initializes this Fill values to all fields if these values are
568 * @param initReadFiles
571 private void initReadFiles() {
574 * Read Current target.txt file first
575 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
578 boolean haveBuildTargets
= readToolDefinitionFile();
579 if (!haveBuildTargets
) {
580 // Lookup Build Targets from the platforms
581 readPlatformFileBuildTargets();
585 private void readPlatformFileBuildTargets() {
586 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
587 String sBuildTargets
= "";
589 // foreach platform, build a list of BuildTargets
590 Iterator
<PlatformIdentification
> iter
= vPlatformId
.iterator();
591 while (iter
.hasNext()) {
592 PlatformIdentification item
= iter
.next();
593 PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
= GlobalData
.openingPlatformList
594 .getOpeningPlatformById(
597 sBuildTargets
+= fpd
.getPlatformDefinitions().getBuildTargets().toString() + " ";
599 String allTargets
[] = sBuildTargets
.trim().split(" ");
600 for (int i
= 0; i
< allTargets
.length
; i
++) {
601 if (!toolsDefTargetNames
.contains(allTargets
[i
])) {
602 toolsDefTargetNames
+= allTargets
[i
] + " ";
607 private boolean readToolDefinitionFile() {
609 // Parse the tool definition file looking for targets and architectures
610 toolsConfFile
= null;
611 boolean buildTargetsExist
= true;
613 if (targetLines
[toolDefFileId
] != null) {
614 String
[] result
= new String
[2];
615 targetLines
[toolDefFileId
].trim();
616 result
= (targetLines
[toolDefFileId
]).split("=");
617 String resString
= (Tools
.convertPathToCurrentOsType(result
[1])).trim();
618 toolsConfFile
= workspaceDir
.trim() + resString
.trim();
619 File toolsDefFile
= new File(toolsConfFile
);
620 if (!toolsDefFile
.exists()) {
621 JOptionPane
.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile
622 + "<br>specified in the target.txt file does not exist!"
623 + "<br>Using the default Tool Definition File:<br>"
625 toolsConfFile
= defaultToolsConf
;
628 toolsConfFile
= defaultToolsConf
;
630 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
631 for (int i
= 0; i
< toolDefFieldCount
; i
++)
632 toolsDefFields
[i
] = null;
633 File toolDefFile
= new File(toolsConfFile
);
634 if (toolDefFile
.exists()) {
636 FileReader fileReader
= new FileReader(toolDefFile
);
637 BufferedReader reader
= new BufferedReader(fileReader
);
641 while ((rLine
= reader
.readLine()) != null) {
643 if (rLine
.startsWith("IDENTIFIER")) {
644 result
= rLine
.split("=");
645 toolsDefIdentifier
= (result
[1]).trim();
646 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
647 result
= rLine
.split("=");
648 toolsDefFields
= ((result
[0]).trim()).split("_");
649 if (toolsDefTargetNames
== null) {
650 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).trim() + " ";
651 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).trim())) {
652 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).trim() + " ";
654 if (toolsDefTagNames
== null) {
655 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
656 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).trim())) {
657 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
659 if (toolsDefArchNames
== null) {
660 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
661 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).trim())) {
662 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
668 // Only enable Architecture selection based on tool chain installations
670 if (!toolsDefArchNames
.contains("EBC"))
672 if (!toolsDefArchNames
.contains("PPC"))
674 if (!toolsDefArchNames
.contains("IPF"))
676 if (!toolsDefArchNames
.contains("X64"))
678 if (!toolsDefArchNames
.contains("IA32"))
680 if (!toolsDefArchNames
.contains("ARM"))
682 turnOff
= turnOff
.trim();
683 vDisableArchList
= stringToVector(turnOff
);
685 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
686 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
688 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
690 buildTargetsExist
= false;
692 } catch (IOException e
) {
693 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());
697 return buildTargetsExist
;
700 private void readTargetTxtFile() {
701 File tFile
= new File(targetFile
);
703 if (tFile
.exists()) {
705 FileReader fileReader
= new FileReader(targetFile
);
706 BufferedReader reader
= new BufferedReader(fileReader
);
707 targetLineNumberMax
= 0;
709 while ((rLine
= reader
.readLine()) != null) {
710 targetFileContents
[targetLineNumberMax
] = rLine
;
711 if (rLine
.startsWith("ACTIVE_PLATFORM")) {
712 // Only one active platform is permitted!
713 targetLines
[activePlatformId
] = rLine
;
714 targetLineNumber
[activePlatformId
] = targetLineNumberMax
;
716 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
717 || (rLine
.startsWith("TARGET="))) {
718 // Handle multiple Target Names
719 if (rLine
.contains(","))
720 targetLines
[buildTargetId
] = rLine
.trim().replaceAll(",", " ");
722 targetLines
[buildTargetId
] = rLine
.trim();
723 targetLineNumber
[buildTargetId
] = targetLineNumberMax
;
725 if (rLine
.startsWith("TARGET_ARCH")) {
726 // Handle multiple Target Architectures
727 if (rLine
.contains(","))
728 targetLines
[targetArchId
] = rLine
.trim().replaceAll(",", " ");
730 targetLines
[targetArchId
] = rLine
.trim();
731 targetLineNumber
[targetArchId
] = targetLineNumberMax
;
733 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
734 // Only one file is permitted
735 targetLines
[toolDefFileId
] = rLine
.trim();
736 targetLineNumber
[toolDefFileId
] = targetLineNumberMax
;
739 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
740 // Handle multiple Tool TagNames
741 if (rLine
.contains(","))
742 targetLines
[tagNameId
] = rLine
.trim().replaceAll(",", " ");
744 targetLines
[tagNameId
] = rLine
.trim();
745 targetLineNumber
[tagNameId
] = targetLineNumberMax
;
748 if (rLine
.startsWith("MULTIPLE_THREAD")) {
749 // Handle Thread Enable flag
750 targetLines
[threadEnableId
] = rLine
.trim();
751 targetLineNumber
[threadEnableId
] = targetLineNumberMax
;
752 if ((rLine
.trim().toLowerCase().contains("enabled")) || (rLine
.trim().toLowerCase().contains("true"))) {
753 threadEnabled
= true;
755 threadEnabled
= false;
759 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
760 // Handle Thread Enable flag
761 targetLines
[threadCountId
] = rLine
.trim();
762 targetLineNumber
[threadCountId
] = targetLineNumberMax
;
764 targetLineNumberMax
++;
767 String archLine
[] = new String
[2];
768 if (targetLines
[targetArchId
] != null) {
769 if (targetLines
[targetArchId
].contains("=")) {
770 if (targetLines
[targetArchId
].contains(","))
771 targetLines
[targetArchId
] = targetLines
[targetArchId
].trim().replaceAll(",", " ");
772 if (targetLines
[targetArchId
].length() > 0)
773 archLine
= targetLines
[targetArchId
].trim().split("=");
774 vArchList
= stringToVector(archLine
[1]);
778 if (targetLines
[threadCountId
] != null) {
779 String tcLine
[] = new String
[2];
780 tcLine
= targetLines
[threadCountId
].trim().split("=");
781 threadCount
= tcLine
[1];
786 for (int i
= 0; i
<= maxTargetLines
; i
++)
787 System
.out
.println("targetLines[" + i
+ "] contains: " + targetLines
[i
] + " index is: "
788 + targetLineNumber
[i
]);
789 } catch (IOException e
) {
790 Log
.log(this.targetFile
+ " Read Error ", e
.getMessage());
798 * This method initializes jContentPane
800 * @return javax.swing.JPanel jContentPane
803 private JPanel
getJContentPane() {
804 if (jContentPane
== null) {
805 jLabelToolsConfigFile
= new JLabel();
806 jLabelToolsConfigFile
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolConfigFileRow
, labelWidth
,
808 jLabelToolsConfigFile
.setText("Tool Chain Definition File");
809 jLabelActivePlatform
= new JLabel();
810 jLabelActivePlatform
.setText("Select Active Platform");
811 jLabelActivePlatform
.setBounds(new java
.awt
.Rectangle(labelColumn
, activePlatformRow
, labelWidth
,
813 jLabelToolChainTagName
= new JLabel();
814 jLabelToolChainTagName
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolChainTagNameRow
, labelWidth
,
816 jLabelToolChainTagName
.setText("Select Tool Tag Name");
817 jLabelBuildTarget
= new JLabel();
818 jLabelBuildTarget
.setBounds(new java
.awt
.Rectangle(labelColumn
, buildTargetRow
, labelWidth
, oneRowHeight
));
819 jLabelBuildTarget
.setText("Select Build Target");
820 jLabelTargetArch
= new JLabel();
821 jLabelTargetArch
.setBounds(new java
.awt
.Rectangle(labelColumn
, targetArchRow
, labelWidth
, oneRowHeight
));
822 jLabelTargetArch
.setText("Build Architectures");
824 jArchCheckBox
= new ArchCheckBox();
825 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(valueColumn
, targetArchRow
, valueWidth
, oneRowHeight
));
826 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
828 jLabelEnableThreads
= new JLabel();
829 jLabelEnableThreads
.setBounds(new java
.awt
.Rectangle(labelColumn
, threadRow
, labelWidth
, oneRowHeight
));
830 jLabelEnableThreads
.setText("Enable Compiler Threading");
832 jLabelThreadCount
= new JLabel();
833 jLabelThreadCount
.setBounds(new java
.awt
.Rectangle(valueColumn
+ 60, threadRow
, labelWidth
, oneRowHeight
));
834 jLabelThreadCount
.setText("Number of threads to start");
836 jContentPane
= new JPanel();
837 jContentPane
.setLayout(null);
838 jContentPane
.setPreferredSize(new java
.awt
.Dimension(dialogWidth
- 10, dialogHeight
- 10));
840 jContentPane
.add(jLabelToolsConfigFile
, null);
841 jContentPane
.add(getJTextFieldToolsConfigFile(), null);
842 jContentPane
.add(getJButtonBrowse(), null);
844 jContentPane
.add(jLabelActivePlatform
, null);
845 jContentPane
.add(getActivePlatform(), null);
847 jContentPane
.add(jLabelToolChainTagName
, null);
848 jContentPane
.add(getJScrollPaneTagName(), null);
850 jContentPane
.add(jLabelBuildTarget
, null);
851 jContentPane
.add(getJScrollPaneBuildTarget(), null);
853 jContentPane
.add(jLabelTargetArch
, null);
855 jArchCheckBox
.setDisabledItems(vDisableArchList
);
856 jArchCheckBox
.setSelectedItems(vArchList
);
857 jContentPane
.add(jArchCheckBox
, null);
859 jContentPane
.add(jLabelEnableThreads
, null);
860 jContentPane
.add(getCheckBoxEnableThreads(), null);
862 jContentPane
.add(jLabelThreadCount
, null);
863 jContentPane
.add(getTextFieldThreadCount(), null);
865 jContentPane
.add(getJButtonSave(), null);
866 jContentPane
.add(getJButtonCancel(), null);
874 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
876 * Override actionPerformed to listen all actions
879 public void actionPerformed(ActionEvent arg0
) {
881 if (arg0
.getSource() == jButtonBrowse
) {
882 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
886 if (arg0
.getSource() == jButtonSave
) {
888 JOptionPane
.showMessageDialog(this, "<html>The target.txt file has been saved!"
889 + "<br>A copy of the original file, target.txt.bak has"
890 + "<br>also been created.</html>");
894 if (arg0
.getSource() == jButtonCancel
) {
898 if (arg0
.getSource() == jCheckBoxEnableThreads
) {
899 if (jCheckBoxEnableThreads
.isSelected() == false) {
901 jTextFieldThreadCount
.setText(threadCount
);
907 private void updateActivePlatform() {
909 if (targetLines
[activePlatformId
] != null) {
910 lineAP
= targetLineNumber
[activePlatformId
];
912 lineAP
= targetLineNumberMax
;
913 targetLineNumber
[activePlatformId
] = lineAP
;
914 targetLineNumberMax
++;
916 if (jComboBoxActivePlatform
.getSelectedItem() == "Do Not Set") {
917 targetFileContents
[lineAP
] = "";
918 targetLines
[activePlatformId
] = "";
920 targetFileContents
[lineAP
] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform
.getSelectedItem() + "\r\n";
921 targetLines
[activePlatformId
] = targetFileContents
[lineAP
];
924 System
.out
.println("Active Platform: " + targetFileContents
[lineAP
]);
927 private void updateToolDefFile() {
929 if (targetLines
[toolDefFileId
] != null) {
930 lineTDF
= targetLineNumber
[toolDefFileId
];
932 lineTDF
= targetLineNumberMax
;
933 targetLineNumber
[toolDefFileId
] = lineTDF
;
934 targetLineNumberMax
++;
937 System
.out
.println("Tool Config File: " + jTextFieldToolsConfigFile
.getText());
938 if (jTextFieldToolsConfigFile
.getText() == null) {
939 targetFileContents
[lineTDF
] = "#MT#";
940 targetLines
[toolDefFileId
] = "";
942 targetFileContents
[lineTDF
] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile
.getText();
943 targetLines
[toolDefFileId
] = targetFileContents
[lineTDF
];
947 private void updateToolTagNames() {
948 String sTagNames
= vectorToString(iCheckBoxListTagName
.getAllCheckedItemsString());
951 if (targetLines
[tagNameId
] != null) {
952 lineTTN
= targetLineNumber
[tagNameId
];
954 lineTTN
= targetLineNumberMax
;
955 targetLineNumber
[tagNameId
] = lineTTN
;
956 targetLineNumberMax
++;
960 System
.out
.println("Tag Name(s): " + sTagNames
);
962 if (sTagNames
.length() > 0) {
963 targetFileContents
[lineTTN
] = "TOOL_CHAIN_TAG = " + sTagNames
;
964 targetLines
[tagNameId
] = targetFileContents
[lineTTN
];
966 targetFileContents
[lineTTN
] = "#MT#";
967 targetLines
[tagNameId
] = "";
971 private void updateBuildTargets() {
972 String sBuildTargets
= vectorToString(iCheckBoxListBuildTarget
.getAllCheckedItemsString());
975 if (targetLines
[buildTargetId
] != null) {
976 lineBT
= targetLineNumber
[buildTargetId
];
978 lineBT
= targetLineNumberMax
;
979 targetLineNumber
[buildTargetId
] = lineBT
;
980 targetLineNumberMax
++;
983 System
.out
.println("Build Target(s): " + sBuildTargets
);
984 if (sBuildTargets
.length() > 0) {
985 targetFileContents
[lineBT
] = "TARGET = " + sBuildTargets
;
986 targetLines
[buildTargetId
] = targetFileContents
[lineBT
];
988 targetFileContents
[lineBT
] = "#MT#";
989 targetLines
[buildTargetId
] = "";
994 private void updateArchitectures() {
995 String sArchList
= jArchCheckBox
.getSelectedItemsString().trim();
998 System
.out
.println("Architectures: " + sArchList
);
1001 if (targetLines
[targetArchId
] != null) {
1002 lineSA
= targetLineNumber
[targetArchId
];
1004 lineSA
= targetLineNumberMax
;
1005 targetLineNumber
[targetArchId
] = lineSA
;
1006 targetLineNumberMax
++;
1008 if (sArchList
== "") {
1009 targetFileContents
[lineSA
] = "#MT#";
1010 targetLines
[targetArchId
] = "";
1012 targetFileContents
[lineSA
] = "TARGET_ARCH = " + sArchList
;
1013 targetLines
[targetArchId
] = targetFileContents
[lineSA
];
1018 private void updateEnableThreads() {
1020 if (targetLines
[threadEnableId
] != null) {
1021 lineET
= targetLineNumber
[threadEnableId
];
1023 lineET
= targetLineNumberMax
;
1024 targetLineNumber
[threadEnableId
] = lineET
;
1025 targetLineNumberMax
++;
1027 if (jCheckBoxEnableThreads
.isSelected() == true) {
1028 targetFileContents
[lineET
] = "MULTIPLE_THREAD = enabled";
1029 targetLines
[threadEnableId
] = targetFileContents
[lineET
];
1031 targetFileContents
[lineET
] = "#MT#";
1032 targetLines
[threadEnableId
] = "";
1036 private void updateThreadCount() {
1039 if (targetLines
[threadCountId
] != null) {
1040 lineTC
= targetLineNumber
[threadCountId
];
1042 lineTC
= targetLineNumberMax
;
1043 targetLineNumber
[threadCountId
] = lineTC
;
1044 targetLineNumberMax
++;
1046 if (jCheckBoxEnableThreads
.isSelected() == true) {
1047 // Threading must be enabled
1048 if (jTextFieldThreadCount
.getText().length() > 0) {
1049 // Thread Count must be greater than 0
1050 Scanner scan
= new Scanner(jTextFieldThreadCount
.getText().trim());
1051 if (scan
.nextInt() > 0) {
1052 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount
.getText().trim();
1053 targetLines
[threadCountId
] = targetFileContents
[lineTC
];
1055 Log
.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1056 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1057 targetLines
[threadCountId
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1060 Log
.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1061 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1062 targetLines
[threadCountId
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1065 // Don't track threads if threading is not enabled
1066 targetFileContents
[lineTC
] = "#MT#";
1067 targetLines
[threadCountId
] = "";
1072 private String
vectorToString(Vector
<String
> v
) {
1074 for (int i
= 0; i
< v
.size(); ++i
) {
1081 protected Vector
<String
> stringToVector(String s
) {
1085 String
[] sArray
= s
.split(" ");
1086 Vector
<String
> v
= new Vector
<String
>();
1087 for (int i
= 0; i
< sArray
.length
; ++i
) {
1093 private void saveTargetFile() {
1094 updateActivePlatform();
1095 updateToolDefFile();
1096 updateToolTagNames();
1097 updateBuildTargets();
1098 updateArchitectures();
1099 updateEnableThreads();
1100 updateThreadCount();
1103 copy(targetFile
, targetFile
+ ".bak");
1104 FileWriter fileWriter
= new FileWriter(targetFile
);
1105 BufferedWriter writer
= new BufferedWriter(fileWriter
);
1106 for (int i
= 0; i
< targetLineNumberMax
; i
++) {
1107 if (! targetFileContents
[i
].contains("#MT#"))
1108 writer
.write(targetFileContents
[i
] + "\n");
1111 } catch (IOException e
) {
1112 Log
.err(toolsConfFile
+ " Write Error ", e
.getMessage());
1113 e
.printStackTrace();
1117 private void copy(String txtFile
, String bakFile
) throws IOException
{
1118 File fromFile
= new File(txtFile
);
1119 File toFile
= new File(bakFile
);
1120 FileInputStream fromTxt
= null;
1121 FileOutputStream toBak
= null;
1123 fromTxt
= new FileInputStream(fromFile
);
1124 toBak
= new FileOutputStream(toFile
);
1125 byte[] buffer
= new byte[4096];
1127 while ((bytes_read
= fromTxt
.read(buffer
)) != -1) {
1128 toBak
.write(buffer
, 0, bytes_read
);
1131 if (fromTxt
!= null)
1134 } catch (IOException e
) {
1135 Log
.err(toolsConfFile
+ " Read Error ", e
.getMessage());
1141 } catch (IOException e
) {
1142 Log
.err(toolsConfFile
+ ".bak Write Error ", e
.getMessage());
1147 private void exit() {
1148 this.setVisible(false);
1149 if (bTarget
!= null) {