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
;
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 rowSix
= rowFive
+ oneRowHeight
+ sepHeight
;
83 private final int buttonRow
= rowSix
+ oneRowHeight
+ sepHeight
+ sepHeight
;
85 private final int dialogHeight
= buttonRow
+ twoRowHeight
+ twoRowHeight
;
87 private final int dialogWidth
= 540;
89 private final int lastButtonXLoc
= 430;
91 private final int next2LastButtonLoc
= 329;
94 * Define the contents for this dialog box
96 private static Preferences bTarget
= null;
98 private WorkspaceTools wt
= new WorkspaceTools();
100 private final int activePlatformId
= 0;
102 private final int buildTargetId
= 1;
104 private final int targetArchId
= 2;
106 private final int toolDefFileId
= 3;
108 private final int tagNameId
= 4;
110 private final int threadEnableId
= 5;
112 private final int threadCountId
= 6;
114 private final int maxTargetLines
= threadCountId
+ 1;
116 private JPanel jContentPane
= null;
118 private JLabel jLabelToolsConfigFile
= null;
120 private JTextField jTextFieldToolsConfigFile
= null;
122 private final int toolConfigFileRow
= rowOne
;
124 private JLabel jLabelActivePlatform
= null;
126 private JComboBox jComboBoxActivePlatform
= null;
128 private final int activePlatformRow
= rowTwo
;
130 private JLabel jLabelToolChainTagName
= null;
132 private JScrollPane jScrollPaneTagName
= null;
134 private ICheckBoxList iCheckBoxListTagName
= null;
136 private final int toolChainTagNameRow
= rowThree
;
138 private JLabel jLabelBuildTarget
= null;
140 private JScrollPane jScrollPaneBuildTarget
= null;
142 private ICheckBoxList iCheckBoxListBuildTarget
= null;
144 private final int buildTargetRow
= rowFour
;
146 private JLabel jLabelTargetArch
= null;
148 private ArchCheckBox jArchCheckBox
= null;
150 private final int targetArchRow
= rowFive
;
152 private JLabel jLabelEnableThreads
= null;
154 private JLabel jLabelThreadCount
= null;
156 private final int threadRow
= rowSix
;
158 private JCheckBox jCheckBoxEnableThreads
= null;
160 private JTextField jTextFieldThreadCount
= null;
162 private String threadCount
= "";
164 private boolean threadEnabled
= false;
166 private JButton jButtonBrowse
= null;
168 private JButton jButtonSave
= null;
170 private JButton jButtonCancel
= null;
172 private final int labelColumn
= 12;
174 private final int labelWidth
= 155;
176 private final int valueColumn
= 168;
178 private final int valueWidth
= 352;
180 private final int valueWidthShort
= 260;
182 private final int buttonWidth
= 90;
184 private String workspaceDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator");
186 private String toolsDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + "Tools"
187 + System
.getProperty("file.separator") + "Conf";
189 private String defaultToolsConf
= toolsDir
+ System
.getProperty("file.separator") + "tools_def.txt";
191 private String targetFile
= toolsDir
+ System
.getProperty("file.separator") + "target.txt";
193 private String
[] targetFileContents
= new String
[500];
195 // private String[] toolsConfContents;
197 private String
[] targetLines
= new String
[maxTargetLines
];
199 private int targetLineNumber
[] = new int[maxTargetLines
];
201 private String toolsConfFile
;
203 private String toolsDefTargetNames
= null;
205 private final int toolsDefTargetNameField
= 0;
207 private String toolsDefTagNames
= null;
209 private final int toolsDefTagNameField
= 1;
211 private String toolsDefArchNames
= null;
213 private final int toolsDefArchNameField
= 2;
215 private String toolsDefIdentifier
= null;
217 private int targetLineNumberMax
;
219 private final int toolDefFieldCount
= 5;
221 private Vector
<String
> vArchList
= null;
223 private Vector
<String
> vDisableArchList
= null;
228 // private Preferences id = null;
230 // private EnumerationData ed = new EnumerationData();
233 This method initializes jTextFieldToolsConfigFile
235 @return javax.swing.JTextField jTextFieldToolsConfigFile
237 private JTextField
getJTextFieldToolsConfigFile() {
238 if (jTextFieldToolsConfigFile
== null) {
239 if (targetLines
[toolDefFileId
] != null) {
240 String sLine
[] = targetLines
[toolDefFileId
].trim().split("=");
241 jTextFieldToolsConfigFile
= new JTextField(sLine
[1].trim());
243 jTextFieldToolsConfigFile
= new JTextField();
245 jTextFieldToolsConfigFile
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolConfigFileRow
, valueWidthShort
,
247 jTextFieldToolsConfigFile
.setPreferredSize(new java
.awt
.Dimension(valueWidthShort
, oneRowHeight
));
248 jTextFieldToolsConfigFile
249 .setToolTipText("<html>"
250 + "Specify the name of the filename to use for specifying"
251 + "<br>the tools to use for the build. If not specified,"
252 + "<br>tools_def.txt will be used for the build. This file"
253 + "<br>MUST be located in the WORKSPACE/Tools/Conf directory.</html>");
256 return jTextFieldToolsConfigFile
;
260 * This method initializes jComboBoxActivePlatform
262 * @return javax.swing.JComboBox jComboBoxActivePlatform
265 private JComboBox
getActivePlatform() {
266 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
268 if (jComboBoxActivePlatform
== null) {
269 jComboBoxActivePlatform
= new JComboBox();
270 jComboBoxActivePlatform
.setBounds(new java
.awt
.Rectangle(valueColumn
, activePlatformRow
, valueWidth
,
272 jComboBoxActivePlatform
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
273 jComboBoxActivePlatform
274 .setToolTipText("<html>Select "Do Not Set" if you want to build a platform"
275 + "<br>from the directory where the FPD file exists,"
276 + "<br>otherwise scroll down to select the platform.</html>");
279 * Generate the data, selecting what is in target.txt
281 jComboBoxActivePlatform
.addItem("Do Not Set");
282 Iterator
<PlatformIdentification
> iter
= vPlatformId
.iterator();
283 while (iter
.hasNext()) {
284 PlatformIdentification item
= iter
.next();
285 String path
= item
.getPath().trim();
286 String str
= path
.substring(workspaceDir
.length(), path
.length());
287 str
.replace(System
.getProperty("file.separator"), "/");
288 jComboBoxActivePlatform
.addItem(str
.trim());
290 if (targetLines
[activePlatformId
] == null)
291 jComboBoxActivePlatform
.setSelectedItem("Do Not Set");
293 jComboBoxActivePlatform
.setSelectedItem(targetLines
[activePlatformId
]);
295 return jComboBoxActivePlatform
;
299 * This method initializes jScrollPaneTagName
301 * @return javax.swing.JScrollPane jScrollPaneTagName
304 private JScrollPane
getJScrollPaneTagName() {
306 if (jScrollPaneTagName
== null) {
307 jScrollPaneTagName
= new JScrollPane();
308 jScrollPaneTagName
.setBounds(new java
.awt
.Rectangle(valueColumn
, toolChainTagNameRow
, valueWidth
,
310 jScrollPaneTagName
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, threeRowHeight
));
311 jScrollPaneTagName
.setHorizontalScrollBarPolicy(JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
312 jScrollPaneTagName
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_AS_NEEDED
);
313 jScrollPaneTagName
.setViewportView(getICheckBoxListTagName());
314 jScrollPaneTagName
.setToolTipText("<html>"
315 + "Specify the TagName(s) from the tool configuration file to use"
316 + "<br>for your builds. If not specified, all applicable TagName"
317 + " <br>tools will be used for the build.</html>");
318 jScrollPaneTagName
.setVisible(true);
321 return jScrollPaneTagName
;
324 private ICheckBoxList
getICheckBoxListTagName() {
325 if (iCheckBoxListTagName
== null) {
326 iCheckBoxListTagName
= new ICheckBoxList();
328 if (toolsDefTagNames
!= null) {
329 toolsDefTagNames
.trim();
330 String aTagNames
[] = toolsDefTagNames
.trim().split(" ");
331 Vector
<String
> vTags
= new Vector
<String
>();
332 for (int i
= 0; i
< aTagNames
.length
; i
++) {
333 vTags
.add(aTagNames
[i
]);
335 iCheckBoxListTagName
.setAllItems(vTags
);
337 Vector
<String
> defaultTags
= stringToVector("MYTOOLS");
338 iCheckBoxListTagName
.setAllItems(defaultTags
);
341 iCheckBoxListTagName
.setAllItemsUnchecked();
342 iCheckBoxListTagName
.setToolTipText("<html>"
343 + "Specify the TagName(s) from the tool configuration file to use"
344 + "<br>for your builds. If not specified, all applicable TagName"
345 + " <br>tools will be used for the build.</html>");
346 Vector
<String
> vSelectedTags
= new Vector
<String
>();
347 if (targetLines
[tagNameId
] != null) {
348 targetLines
[tagNameId
].trim();
349 String targetTags
[] = targetLines
[tagNameId
].trim().split(" ");
350 for (int j
= 0; j
< targetTags
.length
; j
++)
351 vSelectedTags
.add(targetTags
[j
]);
352 iCheckBoxListTagName
.initCheckedItem(true, vSelectedTags
);
355 return iCheckBoxListTagName
;
359 * This method initializes jScrollPaneBuildTarget
361 * @return javax.swing.JComboBox jScrollPaneBuildTarget
364 private JScrollPane
getJScrollPaneBuildTarget() {
365 if (jScrollPaneBuildTarget
== null) {
366 jScrollPaneBuildTarget
= new JScrollPane();
367 jScrollPaneBuildTarget
.setBounds(new java
.awt
.Rectangle(valueColumn
, buildTargetRow
, valueWidth
,
369 jScrollPaneBuildTarget
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, threeRowHeight
));
370 jScrollPaneBuildTarget
.setHorizontalScrollBarPolicy(JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
371 jScrollPaneBuildTarget
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_AS_NEEDED
);
372 jScrollPaneBuildTarget
.setViewportView(getICheckBoxListBuildTarget());
373 jScrollPaneBuildTarget
.setVisible(true);
374 jScrollPaneBuildTarget
.setToolTipText("<html>"
375 + "Select the TARGET Names that you want to build, such as<BR>"
376 + "BUILD or BUILD and RELEASE"
377 + "<br>If you do not set any of these, all available targets"
378 + "<br>will be built.</html>");
381 return jScrollPaneBuildTarget
;
384 private JCheckBox
getCheckBoxEnableThreads() {
385 if (jCheckBoxEnableThreads
== null) {
386 jCheckBoxEnableThreads
= new JCheckBox();
387 jCheckBoxEnableThreads
.setBounds(valueColumn
, threadRow
, 20, oneRowHeight
);
388 jCheckBoxEnableThreads
.setToolTipText("Select this if you want to enable parallel compilation.");
389 jCheckBoxEnableThreads
.setSelected(threadEnabled
);
390 jCheckBoxEnableThreads
.addActionListener(this);
393 return jCheckBoxEnableThreads
;
396 private JTextField
getTextFieldThreadCount() {
397 if (jTextFieldThreadCount
== null) {
398 jTextFieldThreadCount
= new JTextField();
399 jTextFieldThreadCount
.setBounds(valueColumn
+ 215, threadRow
, 30, oneRowHeight
);
400 if (threadCount
.length() > 0)
401 jTextFieldThreadCount
.setText(threadCount
);
402 jTextFieldThreadCount
.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");
403 // If CheckBoxEnableThreads is selected, then enable editing
406 return jTextFieldThreadCount
;
409 private ICheckBoxList
getICheckBoxListBuildTarget() {
410 if (iCheckBoxListBuildTarget
== null) {
412 String aBuildTargets
[] = toolsDefTargetNames
.trim().split(" ");
413 Vector
<String
> vBuildTargets
= new Vector
<String
>();
414 for (int i
= 0; i
< aBuildTargets
.length
; i
++) {
415 vBuildTargets
.add(aBuildTargets
[i
]);
417 iCheckBoxListBuildTarget
= new ICheckBoxList();
418 iCheckBoxListBuildTarget
.setAllItems(vBuildTargets
);
419 iCheckBoxListBuildTarget
.setAllItemsUnchecked();
420 iCheckBoxListBuildTarget
.setToolTipText("<html>"
421 + "Select the TARGET Names that you want to build, such as<BR>"
422 + "BUILD or BUILD and RELEASE"
423 + "<br>If you do not set any of these, all available targets"
424 + "<br>will be built.</html>");
426 Vector
<String
> vSelectedTags
= new Vector
<String
>();
427 if (targetLines
[buildTargetId
] != null) {
428 targetLines
[buildTargetId
].trim();
429 String targetTags
[] = targetLines
[buildTargetId
].trim().split(" ");
430 for (int j
= 0; j
< targetTags
.length
; j
++)
431 vSelectedTags
.add(targetTags
[j
]);
432 iCheckBoxListBuildTarget
.initCheckedItem(true, vSelectedTags
);
435 return iCheckBoxListBuildTarget
;
439 This method initializes jButtonBrowse
441 @return javax.swing.JButton
443 private JButton
getJButtonBrowse() {
444 if (jButtonBrowse
== null) {
445 jButtonBrowse
= new JButton();
447 .setBounds(new java
.awt
.Rectangle(lastButtonXLoc
, toolConfigFileRow
, buttonWidth
, oneRowHeight
));
448 jButtonBrowse
.setText("Browse");
449 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(buttonWidth
, oneRowHeight
));
450 jButtonBrowse
.addActionListener(new AbstractAction() {
454 private static final long serialVersionUID
= 1L;
456 public void actionPerformed(ActionEvent e
) {
458 // Select files from current workspace
460 String dirPrefix
= toolsDir
+ System
.getProperty("file.separator");
461 JFileChooser chooser
= new JFileChooser(dirPrefix
);
463 // String headerDest = null;
465 chooser
.setMultiSelectionEnabled(false);
466 chooser
.setFileSelectionMode(JFileChooser
.FILES_ONLY
);
467 int retval
= chooser
.showOpenDialog(Preferences
.this);
468 if (retval
== JFileChooser
.APPROVE_OPTION
) {
470 theFile
= chooser
.getSelectedFile();
471 String file
= theFile
.getPath();
472 if (!file
.startsWith(dirPrefix
)) {
473 JOptionPane
.showMessageDialog(Preferences
.this, "You can only select files in the Tools"
474 + System
.getProperty("file.separator")
475 + "Conf directory!");
480 jTextFieldToolsConfigFile
.setText("Tools/Conf/" + theFile
.getName());
487 return jButtonBrowse
;
491 * This method initializes jButtonOk
493 * @return javax.swing.JButton
496 private JButton
getJButtonSave() {
497 if (jButtonSave
== null) {
498 jButtonSave
= new JButton();
499 jButtonSave
.setBounds(new java
.awt
.Rectangle(next2LastButtonLoc
, buttonRow
, buttonWidth
, oneRowHeight
));
500 jButtonSave
.setText("Save");
501 jButtonSave
.addActionListener(this);
507 * This method initializes jButtonCancel
509 * @return javax.swing.JButton
512 private JButton
getJButtonCancel() {
513 if (jButtonCancel
== null) {
514 jButtonCancel
= new JButton();
515 jButtonCancel
.setBounds(new java
.awt
.Rectangle(lastButtonXLoc
, buttonRow
, buttonWidth
, oneRowHeight
));
516 jButtonCancel
.setText("Cancel");
517 jButtonCancel
.addActionListener(this);
519 return jButtonCancel
;
522 public static void main(String
[] args
) {
523 // TODO Auto-generated method stub
527 public static Preferences
getInstance() {
528 if (bTarget
== null) {
529 bTarget
= new Preferences();
535 * This is the default constructor
537 public Preferences() {
543 * This method initializes this
546 private void init() {
547 for (int i
= 0; i
< maxTargetLines
; i
++) {
548 targetLines
[i
] = null;
549 targetLineNumber
[i
] = -1;
552 this.setSize(dialogWidth
, dialogHeight
);
553 this.setContentPane(getJContentPane());
554 this.setTitle("Build Preferences [" + toolsDefIdentifier
+ "]");
555 this.setDefaultCloseOperation(IFrame
.DISPOSE_ON_CLOSE
);
557 this.setVisible(true);
561 * This method initializes this Fill values to all fields if these values are
564 * @param initReadFiles
567 private void initReadFiles() {
570 * Read Current target.txt file first
571 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
574 boolean haveBuildTargets
= readToolDefinitionFile();
575 if (!haveBuildTargets
) {
576 // Lookup Build Targets from the platforms
577 readPlatformFileBuildTargets();
581 private void readPlatformFileBuildTargets() {
582 Vector
<PlatformIdentification
> vPlatformId
= wt
.getAllPlatforms();
583 String sBuildTargets
= "";
585 // foreach platform, build a list of BuildTargets
586 Iterator
<PlatformIdentification
> iter
= vPlatformId
.iterator();
587 while (iter
.hasNext()) {
588 PlatformIdentification item
= iter
.next();
589 PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
= GlobalData
.openingPlatformList
590 .getOpeningPlatformById(
593 sBuildTargets
+= fpd
.getPlatformDefinitions().getBuildTargets().toString() + " ";
595 String allTargets
[] = sBuildTargets
.trim().split(" ");
596 for (int i
= 0; i
< allTargets
.length
; i
++) {
597 if (!toolsDefTargetNames
.contains(allTargets
[i
])) {
598 toolsDefTargetNames
+= allTargets
[i
] + " ";
603 private boolean readToolDefinitionFile() {
605 // Parse the tool definition file looking for targets and architectures
606 toolsConfFile
= null;
607 boolean buildTargetsExist
= true;
609 if (targetLines
[toolDefFileId
] != null) {
610 String
[] result
= new String
[2];
611 targetLines
[toolDefFileId
].trim();
612 result
= (targetLines
[toolDefFileId
]).split("=");
613 String resString
= (Tools
.convertPathToCurrentOsType(result
[1])).trim();
614 toolsConfFile
= workspaceDir
.trim() + resString
.trim();
615 File toolsDefFile
= new File(toolsConfFile
);
616 if (!toolsDefFile
.exists()) {
617 JOptionPane
.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile
618 + "<br>specified in the target.txt file does not exist!"
619 + "<br>Using the default Tool Definition File:<br>"
621 toolsConfFile
= defaultToolsConf
;
624 toolsConfFile
= defaultToolsConf
;
626 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
627 for (int i
= 0; i
< toolDefFieldCount
; i
++)
628 toolsDefFields
[i
] = null;
629 File toolDefFile
= new File(toolsConfFile
);
630 if (toolDefFile
.exists()) {
632 FileReader fileReader
= new FileReader(toolDefFile
);
633 BufferedReader reader
= new BufferedReader(fileReader
);
637 while ((rLine
= reader
.readLine()) != null) {
639 if (rLine
.startsWith("IDENTIFIER")) {
640 result
= rLine
.split("=");
641 toolsDefIdentifier
= (result
[1]).trim();
642 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
643 result
= rLine
.split("=");
644 toolsDefFields
= ((result
[0]).trim()).split("_");
645 if (toolsDefTargetNames
== null) {
646 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).trim() + " ";
647 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).trim())) {
648 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).trim() + " ";
650 if (toolsDefTagNames
== null) {
651 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
652 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).trim())) {
653 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).trim() + " ";
655 if (toolsDefArchNames
== null) {
656 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
657 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).trim())) {
658 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).trim() + " ";
664 // Only enable Architecture selection based on tool chain installations
666 if (!toolsDefArchNames
.contains("EBC"))
668 if (!toolsDefArchNames
.contains("PPC"))
670 if (!toolsDefArchNames
.contains("IPF"))
672 if (!toolsDefArchNames
.contains("X64"))
674 if (!toolsDefArchNames
.contains("IA32"))
676 if (!toolsDefArchNames
.contains("ARM"))
678 turnOff
= turnOff
.trim();
679 vDisableArchList
= stringToVector(turnOff
);
681 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
682 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
684 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
686 buildTargetsExist
= false;
688 } catch (IOException e
) {
689 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());
693 return buildTargetsExist
;
696 private void readTargetTxtFile() {
697 File tFile
= new File(targetFile
);
699 if (tFile
.exists()) {
701 FileReader fileReader
= new FileReader(targetFile
);
702 BufferedReader reader
= new BufferedReader(fileReader
);
703 targetLineNumberMax
= 0;
705 while ((rLine
= reader
.readLine()) != null) {
706 targetFileContents
[targetLineNumberMax
] = rLine
;
707 if (rLine
.startsWith("ACTIVE_PLATFORM")) {
708 // Only one active platform is permitted!
709 targetLines
[activePlatformId
] = rLine
;
710 targetLineNumber
[activePlatformId
] = targetLineNumberMax
;
712 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
713 || (rLine
.startsWith("TARGET="))) {
714 // Handle multiple Target Names
715 if (rLine
.contains(","))
716 targetLines
[buildTargetId
] = rLine
.trim().replaceAll(",", " ");
718 targetLines
[buildTargetId
] = rLine
.trim();
719 targetLineNumber
[buildTargetId
] = targetLineNumberMax
;
721 if (rLine
.startsWith("TARGET_ARCH")) {
722 // Handle multiple Target Architectures
723 if (rLine
.contains(","))
724 targetLines
[targetArchId
] = rLine
.trim().replaceAll(",", " ");
726 targetLines
[targetArchId
] = rLine
.trim();
727 targetLineNumber
[targetArchId
] = targetLineNumberMax
;
729 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
730 // Only one file is permitted
731 targetLines
[toolDefFileId
] = rLine
.trim();
732 targetLineNumber
[toolDefFileId
] = targetLineNumberMax
;
735 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
736 // Handle multiple Tool TagNames
737 if (rLine
.contains(","))
738 targetLines
[tagNameId
] = rLine
.trim().replaceAll(",", " ");
740 targetLines
[tagNameId
] = rLine
.trim();
741 targetLineNumber
[tagNameId
] = targetLineNumberMax
;
744 if (rLine
.startsWith("MULTIPLE_THREAD")) {
745 // Handle Thread Enable flag
746 targetLines
[threadEnableId
] = rLine
.trim();
747 targetLineNumber
[threadEnableId
] = targetLineNumberMax
;
748 if ((rLine
.trim().toLowerCase().contains("enabled")) || (rLine
.trim().toLowerCase().contains("true"))) {
749 threadEnabled
= true;
751 threadEnabled
= false;
755 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
756 // Handle Thread Enable flag
757 targetLines
[threadCountId
] = rLine
.trim();
758 targetLineNumber
[threadCountId
] = targetLineNumberMax
;
760 targetLineNumberMax
++;
763 String archLine
[] = new String
[2];
764 if (targetLines
[targetArchId
] != null) {
765 if (targetLines
[targetArchId
].contains("=")) {
766 if (targetLines
[targetArchId
].contains(","))
767 targetLines
[targetArchId
] = targetLines
[targetArchId
].trim().replaceAll(",", " ");
768 if (targetLines
[targetArchId
].length() > 0)
769 archLine
= targetLines
[targetArchId
].trim().split("=");
770 vArchList
= stringToVector(archLine
[1]);
774 if (targetLines
[threadCountId
] != null) {
775 String tcLine
[] = new String
[2];
776 tcLine
= targetLines
[threadCountId
].trim().split("=");
777 threadCount
= tcLine
[1];
782 for (int i
= 0; i
<= maxTargetLines
; i
++)
783 System
.out
.println("targetLines[" + i
+ "] contains: " + targetLines
[i
] + " index is: "
784 + targetLineNumber
[i
]);
785 } catch (IOException e
) {
786 Log
.log(this.targetFile
+ " Read Error ", e
.getMessage());
794 * This method initializes jContentPane
796 * @return javax.swing.JPanel jContentPane
799 private JPanel
getJContentPane() {
800 if (jContentPane
== null) {
801 jLabelToolsConfigFile
= new JLabel();
802 jLabelToolsConfigFile
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolConfigFileRow
, labelWidth
,
804 jLabelToolsConfigFile
.setText("Tool Chain Definition File");
805 jLabelActivePlatform
= new JLabel();
806 jLabelActivePlatform
.setText("Select Active Platform");
807 jLabelActivePlatform
.setBounds(new java
.awt
.Rectangle(labelColumn
, activePlatformRow
, labelWidth
,
809 jLabelToolChainTagName
= new JLabel();
810 jLabelToolChainTagName
.setBounds(new java
.awt
.Rectangle(labelColumn
, toolChainTagNameRow
, labelWidth
,
812 jLabelToolChainTagName
.setText("Select Tool Tag Name");
813 jLabelBuildTarget
= new JLabel();
814 jLabelBuildTarget
.setBounds(new java
.awt
.Rectangle(labelColumn
, buildTargetRow
, labelWidth
, oneRowHeight
));
815 jLabelBuildTarget
.setText("Select Build Target");
816 jLabelTargetArch
= new JLabel();
817 jLabelTargetArch
.setBounds(new java
.awt
.Rectangle(labelColumn
, targetArchRow
, labelWidth
, oneRowHeight
));
818 jLabelTargetArch
.setText("Build Architectures");
820 jArchCheckBox
= new ArchCheckBox();
821 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(valueColumn
, targetArchRow
, valueWidth
, oneRowHeight
));
822 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(valueWidth
, oneRowHeight
));
824 jLabelEnableThreads
= new JLabel();
825 jLabelEnableThreads
.setBounds(new java
.awt
.Rectangle(labelColumn
, threadRow
, labelWidth
, oneRowHeight
));
826 jLabelEnableThreads
.setText("Enable Compiler Threading");
828 jLabelThreadCount
= new JLabel();
829 jLabelThreadCount
.setBounds(new java
.awt
.Rectangle(valueColumn
+ 60, threadRow
, labelWidth
, oneRowHeight
));
830 jLabelThreadCount
.setText("Number of threads to start");
832 jContentPane
= new JPanel();
833 jContentPane
.setLayout(null);
834 jContentPane
.setPreferredSize(new java
.awt
.Dimension(dialogWidth
- 10, dialogHeight
- 10));
836 jContentPane
.add(jLabelToolsConfigFile
, null);
837 jContentPane
.add(getJTextFieldToolsConfigFile(), null);
838 jContentPane
.add(getJButtonBrowse(), null);
840 jContentPane
.add(jLabelActivePlatform
, null);
841 jContentPane
.add(getActivePlatform(), null);
843 jContentPane
.add(jLabelToolChainTagName
, null);
844 jContentPane
.add(getJScrollPaneTagName(), null);
846 jContentPane
.add(jLabelBuildTarget
, null);
847 jContentPane
.add(getJScrollPaneBuildTarget(), null);
849 jContentPane
.add(jLabelTargetArch
, null);
851 jArchCheckBox
.setDisabledItems(vDisableArchList
);
852 jArchCheckBox
.setSelectedItems(vArchList
);
853 jContentPane
.add(jArchCheckBox
, null);
855 jContentPane
.add(jLabelEnableThreads
, null);
856 jContentPane
.add(getCheckBoxEnableThreads(), null);
858 jContentPane
.add(jLabelThreadCount
, null);
859 jContentPane
.add(getTextFieldThreadCount(), null);
861 jContentPane
.add(getJButtonSave(), null);
862 jContentPane
.add(getJButtonCancel(), null);
870 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
872 * Override actionPerformed to listen all actions
875 public void actionPerformed(ActionEvent arg0
) {
877 if (arg0
.getSource() == jButtonBrowse
) {
878 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
882 if (arg0
.getSource() == jButtonSave
) {
884 JOptionPane
.showMessageDialog(this, "<html>The target.txt file has been saved!"
885 + "<br>A copy of the original file, target.txt.bak has"
886 + "<br>also been created.</html>");
890 if (arg0
.getSource() == jButtonCancel
) {
894 if (arg0
.getSource() == jCheckBoxEnableThreads
) {
895 if (jCheckBoxEnableThreads
.isSelected() == false) {
897 jTextFieldThreadCount
.setText(threadCount
);
903 private void updateActivePlatform() {
905 if (targetLines
[activePlatformId
] != null) {
906 lineAP
= targetLineNumber
[activePlatformId
];
908 lineAP
= targetLineNumberMax
;
909 targetLineNumber
[activePlatformId
] = lineAP
;
910 targetLineNumberMax
++;
912 if (jComboBoxActivePlatform
.getSelectedItem() == "Do Not Set") {
913 targetFileContents
[lineAP
] = "";
914 targetLines
[activePlatformId
] = "";
916 targetFileContents
[lineAP
] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform
.getSelectedItem() + "\r\n";
917 targetLines
[activePlatformId
] = targetFileContents
[lineAP
];
920 System
.out
.println("Active Platform: " + targetFileContents
[lineAP
]);
923 private void updateToolDefFile() {
925 if (targetLines
[toolDefFileId
] != null) {
926 lineTDF
= targetLineNumber
[toolDefFileId
];
928 lineTDF
= targetLineNumberMax
;
929 targetLineNumber
[toolDefFileId
] = lineTDF
;
930 targetLineNumberMax
++;
933 System
.out
.println("Tool Config File: " + jTextFieldToolsConfigFile
.getText());
934 if (jTextFieldToolsConfigFile
.getText() == null) {
935 targetFileContents
[lineTDF
] = "#MT#";
936 targetLines
[toolDefFileId
] = "";
938 targetFileContents
[lineTDF
] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile
.getText();
939 targetLines
[toolDefFileId
] = targetFileContents
[lineTDF
];
943 private void updateToolTagNames() {
944 String sTagNames
= vectorToString(iCheckBoxListTagName
.getAllCheckedItemsString());
947 if (targetLines
[tagNameId
] != null) {
948 lineTTN
= targetLineNumber
[tagNameId
];
950 lineTTN
= targetLineNumberMax
;
951 targetLineNumber
[tagNameId
] = lineTTN
;
952 targetLineNumberMax
++;
956 System
.out
.println("Tag Name(s): " + sTagNames
);
958 if (sTagNames
.length() > 0) {
959 targetFileContents
[lineTTN
] = "TOOL_CHAIN_TAG = " + sTagNames
;
960 targetLines
[tagNameId
] = targetFileContents
[lineTTN
];
962 targetFileContents
[lineTTN
] = "#MT#";
963 targetLines
[tagNameId
] = "";
967 private void updateBuildTargets() {
968 String sBuildTargets
= vectorToString(iCheckBoxListBuildTarget
.getAllCheckedItemsString());
971 if (targetLines
[buildTargetId
] != null) {
972 lineBT
= targetLineNumber
[buildTargetId
];
974 lineBT
= targetLineNumberMax
;
975 targetLineNumber
[buildTargetId
] = lineBT
;
976 targetLineNumberMax
++;
979 System
.out
.println("Build Target(s): " + sBuildTargets
);
980 if (sBuildTargets
.length() > 0) {
981 targetFileContents
[lineBT
] = "TARGET = " + sBuildTargets
;
982 targetLines
[buildTargetId
] = targetFileContents
[lineBT
];
984 targetFileContents
[lineBT
] = "#MT#";
985 targetLines
[buildTargetId
] = "";
990 private void updateArchitectures() {
991 String sArchList
= jArchCheckBox
.getSelectedItemsString().trim();
994 System
.out
.println("Architectures: " + sArchList
);
997 if (targetLines
[targetArchId
] != null) {
998 lineSA
= targetLineNumber
[targetArchId
];
1000 lineSA
= targetLineNumberMax
;
1001 targetLineNumber
[targetArchId
] = lineSA
;
1002 targetLineNumberMax
++;
1004 if (sArchList
== "") {
1005 targetFileContents
[lineSA
] = "#MT#";
1006 targetLines
[targetArchId
] = "";
1008 targetFileContents
[lineSA
] = "TARGET_ARCH = " + sArchList
;
1009 targetLines
[targetArchId
] = targetFileContents
[lineSA
];
1014 private void updateEnableThreads() {
1016 if (targetLines
[threadEnableId
] != null) {
1017 lineET
= targetLineNumber
[threadEnableId
];
1019 lineET
= targetLineNumberMax
;
1020 targetLineNumber
[threadEnableId
] = lineET
;
1021 targetLineNumberMax
++;
1023 if (jCheckBoxEnableThreads
.isSelected() == true) {
1024 targetFileContents
[lineET
] = "MULTIPLE_THREAD = enabled";
1025 targetLines
[threadEnableId
] = targetFileContents
[lineET
];
1027 targetFileContents
[lineET
] = "#MT#";
1028 targetLines
[threadEnableId
] = "";
1032 private void updateThreadCount() {
1035 if (targetLines
[threadCountId
] != null) {
1036 lineTC
= targetLineNumber
[threadCountId
];
1038 lineTC
= targetLineNumberMax
;
1039 targetLineNumber
[threadCountId
] = lineTC
;
1040 targetLineNumberMax
++;
1042 if (jCheckBoxEnableThreads
.isSelected() == true) {
1043 // Threading must be enabled
1044 if (jTextFieldThreadCount
.getText().length() > 0) {
1045 // Thread Count must be greater than 0
1046 Scanner scan
= new Scanner(jTextFieldThreadCount
.getText().trim());
1047 if (scan
.nextInt() > 0) {
1048 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount
.getText().trim();
1049 targetLines
[threadCountId
] = targetFileContents
[lineTC
];
1051 Log
.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1052 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1053 targetLines
[threadCountId
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1056 Log
.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1057 targetFileContents
[lineTC
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1058 targetLines
[threadCountId
] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1061 // Don't track threads if threading is not enabled
1062 targetFileContents
[lineTC
] = "#MT#";
1063 targetLines
[threadCountId
] = "";
1068 private String
vectorToString(Vector
<String
> v
) {
1070 for (int i
= 0; i
< v
.size(); ++i
) {
1077 protected Vector
<String
> stringToVector(String s
) {
1081 String
[] sArray
= s
.split(" ");
1082 Vector
<String
> v
= new Vector
<String
>();
1083 for (int i
= 0; i
< sArray
.length
; ++i
) {
1089 private void saveTargetFile() {
1090 updateActivePlatform();
1091 updateToolDefFile();
1092 updateToolTagNames();
1093 updateBuildTargets();
1094 updateArchitectures();
1095 updateEnableThreads();
1096 updateThreadCount();
1099 copy(targetFile
, targetFile
+ ".bak");
1100 FileWriter fileWriter
= new FileWriter(targetFile
);
1101 BufferedWriter writer
= new BufferedWriter(fileWriter
);
1102 for (int i
= 0; i
< targetLineNumberMax
; i
++) {
1103 if (! targetFileContents
[i
].contains("#MT#"))
1104 writer
.write(targetFileContents
[i
] + "\n");
1107 } catch (IOException e
) {
1108 Log
.err(toolsConfFile
+ " Write Error ", e
.getMessage());
1109 e
.printStackTrace();
1113 private void copy(String txtFile
, String bakFile
) throws IOException
{
1114 File fromFile
= new File(txtFile
);
1115 File toFile
= new File(bakFile
);
1116 FileInputStream fromTxt
= null;
1117 FileOutputStream toBak
= null;
1118 if (!fromFile
.exists()) {
1119 fromFile
.createNewFile();
1122 fromTxt
= new FileInputStream(fromFile
);
1123 toBak
= new FileOutputStream(toFile
);
1124 byte[] buffer
= new byte[4096];
1126 while ((bytes_read
= fromTxt
.read(buffer
)) != -1) {
1127 toBak
.write(buffer
, 0, bytes_read
);
1130 if (fromTxt
!= null)
1133 } catch (IOException e
) {
1134 Log
.err(toolsConfFile
+ " Read Error ", e
.getMessage());
1140 } catch (IOException e
) {
1141 Log
.err(toolsConfFile
+ ".bak Write Error ", e
.getMessage());
1146 private void exit() {
1147 this.setVisible(false);
1148 if (bTarget
!= null) {