]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/toolchain/Preferences.java
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / toolchain / Preferences.java
1 /** @file
2 <<The file is used to update the Build Preferences file, target.txt>>
3
4 <<The program will use target.txt, the tools config file specified in that file,
5 or it will use the default tools_def.txt file, and it will also scan the
6 FrameworkDatabase.db file for certain parameters. >>
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 Package Name: Tools
18 Module Name: FrameworkWizard
19
20 **/
21
22 package org.tianocore.frameworkwizard.toolchain;
23
24 import java.awt.event.ActionEvent;
25 import java.io.*;
26 import java.util.Vector;
27 import java.util.Iterator;
28 import java.util.Scanner;
29
30 import javax.swing.*;
31 import javax.swing.JScrollPane;
32 import javax.swing.JTextField;
33
34 import org.tianocore.frameworkwizard.common.GlobalData;
35 import org.tianocore.frameworkwizard.common.Tools;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
38 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.*;
39 import org.tianocore.frameworkwizard.common.ui.IFrame;
40 import org.tianocore.frameworkwizard.workspace.Workspace;
41 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
42 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
43 import org.tianocore.PlatformSurfaceAreaDocument;
44
45 /**
46 * The class is used to update the target.txt file.
47 *
48 * It extends IDialog
49 *
50 */
51 public class Preferences extends IFrame {
52
53 // /
54 // / Define class Serial Version UID
55 // /
56 private static final long serialVersionUID = -4777906991966638888L;
57
58 private final boolean Debug = false;
59
60 //
61 // Define class members
62 //
63 private final int oneRowHeight = 20;
64
65 private final int twoRowHeight = 40;
66
67 private final int threeRowHeight = 60;
68
69 private final int sepHeight = 6;
70
71 private final int rowOne = 12;
72
73 private final int rowTwo = rowOne + oneRowHeight + sepHeight;
74
75 private final int rowThree = rowTwo + oneRowHeight + sepHeight;
76
77 private final int rowFour = rowThree + threeRowHeight + sepHeight;
78
79 private final int rowFive = rowFour + threeRowHeight + sepHeight;
80
81 private final int rowSix = rowFive + oneRowHeight + sepHeight;
82
83 private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;
84
85 private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;
86
87 private final int dialogWidth = 540;
88
89 private final int lastButtonXLoc = 430;
90
91 private final int next2LastButtonLoc = 329;
92
93 /*
94 * Define the contents for this dialog box
95 */
96 private static Preferences bTarget = null;
97
98 private WorkspaceTools wt = new WorkspaceTools();
99
100 private final int activePlatformId = 0;
101
102 private final int buildTargetId = 1;
103
104 private final int targetArchId = 2;
105
106 private final int toolDefFileId = 3;
107
108 private final int tagNameId = 4;
109
110 private final int threadEnableId = 5;
111
112 private final int threadCountId = 6;
113
114 private final int maxTargetLines = threadCountId + 1;
115
116 private JPanel jContentPane = null;
117
118 private JLabel jLabelToolsConfigFile = null;
119
120 private JTextField jTextFieldToolsConfigFile = null;
121
122 private final int toolConfigFileRow = rowOne;
123
124 private JLabel jLabelActivePlatform = null;
125
126 private JComboBox jComboBoxActivePlatform = null;
127
128 private final int activePlatformRow = rowTwo;
129
130 private JLabel jLabelToolChainTagName = null;
131
132 private JScrollPane jScrollPaneTagName = null;
133
134 private ICheckBoxList iCheckBoxListTagName = null;
135
136 private final int toolChainTagNameRow = rowThree;
137
138 private JLabel jLabelBuildTarget = null;
139
140 private JScrollPane jScrollPaneBuildTarget = null;
141
142 private ICheckBoxList iCheckBoxListBuildTarget = null;
143
144 private final int buildTargetRow = rowFour;
145
146 private JLabel jLabelTargetArch = null;
147
148 private ArchCheckBox jArchCheckBox = null;
149
150 private final int targetArchRow = rowFive;
151
152 private JLabel jLabelEnableThreads = null;
153
154 private JLabel jLabelThreadCount = null;
155
156 private final int threadRow = rowSix;
157
158 private JCheckBox jCheckBoxEnableThreads = null;
159
160 private JTextField jTextFieldThreadCount = null;
161
162 private String threadCount = "";
163
164 private boolean threadEnabled = false;
165
166 private JButton jButtonBrowse = null;
167
168 private JButton jButtonSave = null;
169
170 private JButton jButtonCancel = null;
171
172 private final int labelColumn = 12;
173
174 private final int labelWidth = 155;
175
176 private final int valueColumn = 168;
177
178 private final int valueWidth = 352;
179
180 private final int valueWidthShort = 260;
181
182 private final int buttonWidth = 90;
183
184 private String workspaceDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator");
185
186 private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"
187 + System.getProperty("file.separator") + "Conf";
188
189 private String defaultToolsConf = toolsDir + System.getProperty("file.separator") + "tools_def.txt";
190
191 private String targetFile = toolsDir + System.getProperty("file.separator") + "target.txt";
192
193 private String[] targetFileContents = new String[500];
194
195 // private String[] toolsConfContents;
196
197 private String[] targetLines = new String[maxTargetLines];
198
199 private int targetLineNumber[] = new int[maxTargetLines];
200
201 private String toolsConfFile;
202
203 private String toolsDefTargetNames = null;
204
205 private final int toolsDefTargetNameField = 0;
206
207 private String toolsDefTagNames = null;
208
209 private final int toolsDefTagNameField = 1;
210
211 private String toolsDefArchNames = null;
212
213 private final int toolsDefArchNameField = 2;
214
215 private String toolsDefIdentifier = null;
216
217 private int targetLineNumberMax;
218
219 private final int toolDefFieldCount = 5;
220
221 private Vector<String> vArchList = null;
222
223 private Vector<String> vDisableArchList = null;
224
225 //
226 // Not used by UI
227 //
228 // private Preferences id = null;
229
230 // private EnumerationData ed = new EnumerationData();
231
232 /**
233 This method initializes jTextFieldToolsConfigFile
234
235 @return javax.swing.JTextField jTextFieldToolsConfigFile
236 **/
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());
242 } else
243 jTextFieldToolsConfigFile = new JTextField();
244
245 jTextFieldToolsConfigFile.setBounds(new java.awt.Rectangle(valueColumn, toolConfigFileRow, valueWidthShort,
246 oneRowHeight));
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>");
254
255 }
256 return jTextFieldToolsConfigFile;
257 }
258
259 /**
260 * This method initializes jComboBoxActivePlatform
261 *
262 * @return javax.swing.JComboBox jComboBoxActivePlatform
263 *
264 */
265 private JComboBox getActivePlatform() {
266 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
267
268 if (jComboBoxActivePlatform == null) {
269 jComboBoxActivePlatform = new JComboBox();
270 jComboBoxActivePlatform.setBounds(new java.awt.Rectangle(valueColumn, activePlatformRow, valueWidth,
271 oneRowHeight));
272 jComboBoxActivePlatform.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
273 jComboBoxActivePlatform
274 .setToolTipText("<html>Select &quot;Do Not Set&quot; 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>");
277
278 /*
279 * Generate the data, selecting what is in target.txt
280 */
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());
289 }
290 if (targetLines[activePlatformId] == null)
291 jComboBoxActivePlatform.setSelectedItem("Do Not Set");
292 else
293 jComboBoxActivePlatform.setSelectedItem(targetLines[activePlatformId]);
294 }
295 return jComboBoxActivePlatform;
296 }
297
298 /**
299 * This method initializes jScrollPaneTagName
300 *
301 * @return javax.swing.JScrollPane jScrollPaneTagName
302 *
303 */
304 private JScrollPane getJScrollPaneTagName() {
305
306 if (jScrollPaneTagName == null) {
307 jScrollPaneTagName = new JScrollPane();
308 jScrollPaneTagName.setBounds(new java.awt.Rectangle(valueColumn, toolChainTagNameRow, valueWidth,
309 threeRowHeight));
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);
319
320 }
321 return jScrollPaneTagName;
322 }
323
324 private ICheckBoxList getICheckBoxListTagName() {
325 if (iCheckBoxListTagName == null) {
326 iCheckBoxListTagName = new ICheckBoxList();
327
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]);
334 }
335 iCheckBoxListTagName.setAllItems(vTags);
336 } else {
337 Vector<String> defaultTags = stringToVector("MYTOOLS");
338 iCheckBoxListTagName.setAllItems(defaultTags);
339 }
340
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);
353 }
354 }
355 return iCheckBoxListTagName;
356 }
357
358 /**
359 * This method initializes jScrollPaneBuildTarget
360 *
361 * @return javax.swing.JComboBox jScrollPaneBuildTarget
362 *
363 */
364 private JScrollPane getJScrollPaneBuildTarget() {
365 if (jScrollPaneBuildTarget == null) {
366 jScrollPaneBuildTarget = new JScrollPane();
367 jScrollPaneBuildTarget.setBounds(new java.awt.Rectangle(valueColumn, buildTargetRow, valueWidth,
368 threeRowHeight));
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>");
379
380 }
381 return jScrollPaneBuildTarget;
382 }
383
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);
391
392 }
393 return jCheckBoxEnableThreads;
394 }
395
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
404
405 }
406 return jTextFieldThreadCount;
407 }
408
409 private ICheckBoxList getICheckBoxListBuildTarget() {
410 if (iCheckBoxListBuildTarget == null) {
411
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]);
416 }
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>");
425
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);
433 }
434 }
435 return iCheckBoxListBuildTarget;
436 }
437
438 /**
439 This method initializes jButtonBrowse
440
441 @return javax.swing.JButton
442 **/
443 private JButton getJButtonBrowse() {
444 if (jButtonBrowse == null) {
445 jButtonBrowse = new JButton();
446 jButtonBrowse
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() {
451 /**
452 *
453 */
454 private static final long serialVersionUID = 1L;
455
456 public void actionPerformed(ActionEvent e) {
457 //
458 // Select files from current workspace
459 //
460 String dirPrefix = toolsDir + System.getProperty("file.separator");
461 JFileChooser chooser = new JFileChooser(dirPrefix);
462 File theFile = null;
463 // String headerDest = null;
464
465 chooser.setMultiSelectionEnabled(false);
466 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
467 int retval = chooser.showOpenDialog(Preferences.this);
468 if (retval == JFileChooser.APPROVE_OPTION) {
469
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!");
476
477 return;
478 }
479
480 jTextFieldToolsConfigFile.setText("Tools/Conf/" + theFile.getName());
481 } else {
482 return;
483 }
484 }
485 });
486 }
487 return jButtonBrowse;
488 }
489
490 /**
491 * This method initializes jButtonOk
492 *
493 * @return javax.swing.JButton
494 *
495 */
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);
502 }
503 return jButtonSave;
504 }
505
506 /**
507 * This method initializes jButtonCancel
508 *
509 * @return javax.swing.JButton
510 *
511 */
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);
518 }
519 return jButtonCancel;
520 }
521
522 public static void main(String[] args) {
523 // TODO Auto-generated method stub
524
525 }
526
527 public static Preferences getInstance() {
528 if (bTarget == null) {
529 bTarget = new Preferences();
530 }
531 return bTarget;
532 }
533
534 /**
535 * This is the default constructor
536 */
537 public Preferences() {
538 super();
539 init();
540 }
541
542 /**
543 * This method initializes this
544 *
545 */
546 private void init() {
547 for (int i = 0; i < maxTargetLines; i++) {
548 targetLines[i] = null;
549 targetLineNumber[i] = -1;
550 }
551 initReadFiles();
552 this.setSize(dialogWidth, dialogHeight);
553 this.setContentPane(getJContentPane());
554 this.setTitle("Build Preferences [" + toolsDefIdentifier + "]");
555 this.setDefaultCloseOperation(IFrame.DISPOSE_ON_CLOSE);
556 this.centerWindow();
557 this.setVisible(true);
558 }
559
560 /**
561 * This method initializes this Fill values to all fields if these values are
562 * not empty
563 *
564 * @param initReadFiles
565 *
566 */
567 private void initReadFiles() {
568 /*
569 * TODO
570 * Read Current target.txt file first
571 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
572 */
573 readTargetTxtFile();
574 boolean haveBuildTargets = readToolDefinitionFile();
575 if (!haveBuildTargets) {
576 // Lookup Build Targets from the platforms
577 readPlatformFileBuildTargets();
578 }
579 }
580
581 private void readPlatformFileBuildTargets() {
582 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
583 String sBuildTargets = "";
584
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(
591 item)
592 .getXmlFpd();
593 sBuildTargets += fpd.getPlatformDefinitions().getBuildTargets().toString() + " ";
594 }
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] + " ";
599 }
600 }
601 }
602
603 private boolean readToolDefinitionFile() {
604
605 // Parse the tool definition file looking for targets and architectures
606 toolsConfFile = null;
607 boolean buildTargetsExist = true;
608
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>"
620 + defaultToolsConf);
621 toolsConfFile = defaultToolsConf;
622 }
623 } else {
624 toolsConfFile = defaultToolsConf;
625 }
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()) {
631 try {
632 FileReader fileReader = new FileReader(toolDefFile);
633 BufferedReader reader = new BufferedReader(fileReader);
634 String rLine = null;
635 String result[];
636 int lineCounter = 0;
637 while ((rLine = reader.readLine()) != null) {
638
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() + " ";
649 }
650 if (toolsDefTagNames == null) {
651 toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).trim() + " ";
652 } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).trim())) {
653 toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).trim() + " ";
654 }
655 if (toolsDefArchNames == null) {
656 toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).trim() + " ";
657 } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).trim())) {
658 toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).trim() + " ";
659 }
660 }
661 lineCounter++;
662 }
663 reader.close();
664 // Only enable Architecture selection based on tool chain installations
665 String turnOff = "";
666 if (!toolsDefArchNames.contains("EBC"))
667 turnOff = "EBC ";
668 if (!toolsDefArchNames.contains("PPC"))
669 turnOff += "PPC ";
670 if (!toolsDefArchNames.contains("IPF"))
671 turnOff += "IPF ";
672 if (!toolsDefArchNames.contains("X64"))
673 turnOff += "X64 ";
674 if (!toolsDefArchNames.contains("IA32"))
675 turnOff += "X64 ";
676 if (!toolsDefArchNames.contains("ARM"))
677 turnOff += "ARM ";
678 turnOff = turnOff.trim();
679 vDisableArchList = stringToVector(turnOff);
680
681 if (!toolsDefTargetNames.matches("[A-Z]+")) {
682 toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();
683 if (Debug)
684 System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames
685 + "'");
686 buildTargetsExist = false;
687 }
688 } catch (IOException e) {
689 Log.log(toolsConfFile + " Read Error ", e.getMessage());
690 e.printStackTrace();
691 }
692 }
693 return buildTargetsExist;
694 }
695
696 private void readTargetTxtFile() {
697 File tFile = new File(targetFile);
698
699 if (tFile.exists()) {
700 try {
701 FileReader fileReader = new FileReader(targetFile);
702 BufferedReader reader = new BufferedReader(fileReader);
703 targetLineNumberMax = 0;
704 String rLine = null;
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;
711 }
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(",", " ");
717 else
718 targetLines[buildTargetId] = rLine.trim();
719 targetLineNumber[buildTargetId] = targetLineNumberMax;
720 }
721 if (rLine.startsWith("TARGET_ARCH")) {
722 // Handle multiple Target Architectures
723 if (rLine.contains(","))
724 targetLines[targetArchId] = rLine.trim().replaceAll(",", " ");
725 else
726 targetLines[targetArchId] = rLine.trim();
727 targetLineNumber[targetArchId] = targetLineNumberMax;
728 }
729 if (rLine.startsWith("TOOL_CHAIN_CONF")) {
730 // Only one file is permitted
731 targetLines[toolDefFileId] = rLine.trim();
732 targetLineNumber[toolDefFileId] = targetLineNumberMax;
733 }
734
735 if (rLine.startsWith("TOOL_CHAIN_TAG")) {
736 // Handle multiple Tool TagNames
737 if (rLine.contains(","))
738 targetLines[tagNameId] = rLine.trim().replaceAll(",", " ");
739 else
740 targetLines[tagNameId] = rLine.trim();
741 targetLineNumber[tagNameId] = targetLineNumberMax;
742 }
743
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;
750 } else {
751 threadEnabled = false;
752 }
753 }
754
755 if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
756 // Handle Thread Enable flag
757 targetLines[threadCountId] = rLine.trim();
758 targetLineNumber[threadCountId] = targetLineNumberMax;
759 }
760 targetLineNumberMax++;
761 }
762 reader.close();
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]);
771 }
772 }
773
774 if (targetLines[threadCountId] != null) {
775 String tcLine[] = new String[2];
776 tcLine = targetLines[threadCountId].trim().split("=");
777 threadCount = tcLine[1];
778 } else
779 threadCount = "";
780
781 if (Debug == true)
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());
787 e.printStackTrace();
788 }
789 }
790
791 }
792
793 /**
794 * This method initializes jContentPane
795 *
796 * @return javax.swing.JPanel jContentPane
797 *
798 */
799 private JPanel getJContentPane() {
800 if (jContentPane == null) {
801 jLabelToolsConfigFile = new JLabel();
802 jLabelToolsConfigFile.setBounds(new java.awt.Rectangle(labelColumn, toolConfigFileRow, labelWidth,
803 oneRowHeight));
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,
808 oneRowHeight));
809 jLabelToolChainTagName = new JLabel();
810 jLabelToolChainTagName.setBounds(new java.awt.Rectangle(labelColumn, toolChainTagNameRow, labelWidth,
811 oneRowHeight));
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");
819
820 jArchCheckBox = new ArchCheckBox();
821 jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));
822 jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
823
824 jLabelEnableThreads = new JLabel();
825 jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));
826 jLabelEnableThreads.setText("Enable Compiler Threading");
827
828 jLabelThreadCount = new JLabel();
829 jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));
830 jLabelThreadCount.setText("Number of threads to start");
831
832 jContentPane = new JPanel();
833 jContentPane.setLayout(null);
834 jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));
835
836 jContentPane.add(jLabelToolsConfigFile, null);
837 jContentPane.add(getJTextFieldToolsConfigFile(), null);
838 jContentPane.add(getJButtonBrowse(), null);
839
840 jContentPane.add(jLabelActivePlatform, null);
841 jContentPane.add(getActivePlatform(), null);
842
843 jContentPane.add(jLabelToolChainTagName, null);
844 jContentPane.add(getJScrollPaneTagName(), null);
845
846 jContentPane.add(jLabelBuildTarget, null);
847 jContentPane.add(getJScrollPaneBuildTarget(), null);
848
849 jContentPane.add(jLabelTargetArch, null);
850
851 jArchCheckBox.setDisabledItems(vDisableArchList);
852 jArchCheckBox.setSelectedItems(vArchList);
853 jContentPane.add(jArchCheckBox, null);
854
855 jContentPane.add(jLabelEnableThreads, null);
856 jContentPane.add(getCheckBoxEnableThreads(), null);
857
858 jContentPane.add(jLabelThreadCount, null);
859 jContentPane.add(getTextFieldThreadCount(), null);
860
861 jContentPane.add(getJButtonSave(), null);
862 jContentPane.add(getJButtonCancel(), null);
863 }
864 return jContentPane;
865 }
866
867 /*
868 * (non-Javadoc)
869 *
870 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
871 *
872 * Override actionPerformed to listen all actions
873 *
874 */
875 public void actionPerformed(ActionEvent arg0) {
876
877 if (arg0.getSource() == jButtonBrowse) {
878 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
879
880 }
881
882 if (arg0.getSource() == jButtonSave) {
883 saveTargetFile();
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>");
887 this.exit();
888 }
889
890 if (arg0.getSource() == jButtonCancel) {
891 this.exit();
892 }
893
894 if (arg0.getSource() == jCheckBoxEnableThreads) {
895 if (jCheckBoxEnableThreads.isSelected() == false) {
896 threadCount = "";
897 jTextFieldThreadCount.setText(threadCount);
898 }
899 }
900 }
901
902
903 private void updateActivePlatform() {
904 int lineAP;
905 if (targetLines[activePlatformId] != null) {
906 lineAP = targetLineNumber[activePlatformId];
907 } else {
908 lineAP = targetLineNumberMax;
909 targetLineNumber[activePlatformId] = lineAP;
910 targetLineNumberMax++;
911 }
912 if (jComboBoxActivePlatform.getSelectedItem() == "Do Not Set") {
913 targetFileContents[lineAP] = "";
914 targetLines[activePlatformId] = "";
915 } else {
916 targetFileContents[lineAP] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform.getSelectedItem() + "\r\n";
917 targetLines[activePlatformId] = targetFileContents[lineAP];
918 }
919 if (Debug)
920 System.out.println("Active Platform: " + targetFileContents[lineAP]);
921 }
922
923 private void updateToolDefFile() {
924 int lineTDF;
925 if (targetLines[toolDefFileId] != null) {
926 lineTDF = targetLineNumber[toolDefFileId];
927 } else {
928 lineTDF = targetLineNumberMax;
929 targetLineNumber[toolDefFileId] = lineTDF;
930 targetLineNumberMax++;
931 }
932 if (Debug)
933 System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());
934 if (jTextFieldToolsConfigFile.getText() == null) {
935 targetFileContents[lineTDF] = "#MT#";
936 targetLines[toolDefFileId] = "";
937 } else {
938 targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();
939 targetLines[toolDefFileId] = targetFileContents[lineTDF];
940 }
941 }
942
943 private void updateToolTagNames() {
944 String sTagNames = vectorToString(iCheckBoxListTagName.getAllCheckedItemsString());
945 int lineTTN;
946
947 if (targetLines[tagNameId] != null) {
948 lineTTN = targetLineNumber[tagNameId];
949 } else {
950 lineTTN = targetLineNumberMax;
951 targetLineNumber[tagNameId] = lineTTN;
952 targetLineNumberMax++;
953 }
954
955 if (Debug)
956 System.out.println("Tag Name(s): " + sTagNames);
957
958 if (sTagNames.length() > 0) {
959 targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;
960 targetLines[tagNameId] = targetFileContents[lineTTN];
961 } else {
962 targetFileContents[lineTTN] = "#MT#";
963 targetLines[tagNameId] = "";
964 }
965 }
966
967 private void updateBuildTargets() {
968 String sBuildTargets = vectorToString(iCheckBoxListBuildTarget.getAllCheckedItemsString());
969 int lineBT;
970
971 if (targetLines[buildTargetId] != null) {
972 lineBT = targetLineNumber[buildTargetId];
973 } else {
974 lineBT = targetLineNumberMax;
975 targetLineNumber[buildTargetId] = lineBT;
976 targetLineNumberMax++;
977 }
978 if (Debug)
979 System.out.println("Build Target(s): " + sBuildTargets);
980 if (sBuildTargets.length() > 0) {
981 targetFileContents[lineBT] = "TARGET = " + sBuildTargets;
982 targetLines[buildTargetId] = targetFileContents[lineBT];
983 } else {
984 targetFileContents[lineBT] = "#MT#";
985 targetLines[buildTargetId] = "";
986 }
987
988 }
989
990 private void updateArchitectures() {
991 String sArchList = jArchCheckBox.getSelectedItemsString().trim();
992
993 if (Debug)
994 System.out.println("Architectures: " + sArchList);
995
996 int lineSA;
997 if (targetLines[targetArchId] != null) {
998 lineSA = targetLineNumber[targetArchId];
999 } else {
1000 lineSA = targetLineNumberMax;
1001 targetLineNumber[targetArchId] = lineSA;
1002 targetLineNumberMax++;
1003 }
1004 if (sArchList == "") {
1005 targetFileContents[lineSA] = "#MT#";
1006 targetLines[targetArchId] = "";
1007 } else {
1008 targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;
1009 targetLines[targetArchId] = targetFileContents[lineSA];
1010 }
1011
1012 }
1013
1014 private void updateEnableThreads() {
1015 int lineET;
1016 if (targetLines[threadEnableId] != null) {
1017 lineET = targetLineNumber[threadEnableId];
1018 } else {
1019 lineET = targetLineNumberMax;
1020 targetLineNumber[threadEnableId] = lineET;
1021 targetLineNumberMax++;
1022 }
1023 if (jCheckBoxEnableThreads.isSelected() == true) {
1024 targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";
1025 targetLines[threadEnableId] = targetFileContents[lineET];
1026 } else {
1027 targetFileContents[lineET] = "#MT#";
1028 targetLines[threadEnableId] = "";
1029 }
1030 }
1031
1032 private void updateThreadCount() {
1033 int lineTC;
1034
1035 if (targetLines[threadCountId] != null) {
1036 lineTC = targetLineNumber[threadCountId];
1037 } else {
1038 lineTC = targetLineNumberMax;
1039 targetLineNumber[threadCountId] = lineTC;
1040 targetLineNumberMax++;
1041 }
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];
1050 } else {
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";
1054 }
1055 } else {
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";
1059 }
1060 } else {
1061 // Don't track threads if threading is not enabled
1062 targetFileContents[lineTC] = "#MT#";
1063 targetLines[threadCountId] = "";
1064 threadCount = "";
1065 }
1066
1067 }
1068 private String vectorToString(Vector<String> v) {
1069 String s = " ";
1070 for (int i = 0; i < v.size(); ++i) {
1071 s += v.get(i);
1072 s += " ";
1073 }
1074 return s.trim();
1075 }
1076
1077 protected Vector<String> stringToVector(String s) {
1078 if (s == null) {
1079 return null;
1080 }
1081 String[] sArray = s.split(" ");
1082 Vector<String> v = new Vector<String>();
1083 for (int i = 0; i < sArray.length; ++i) {
1084 v.add(sArray[i]);
1085 }
1086 return v;
1087 }
1088
1089 private void saveTargetFile() {
1090 updateActivePlatform();
1091 updateToolDefFile();
1092 updateToolTagNames();
1093 updateBuildTargets();
1094 updateArchitectures();
1095 updateEnableThreads();
1096 updateThreadCount();
1097
1098 try {
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");
1105 }
1106 writer.close();
1107 } catch (IOException e) {
1108 Log.err(toolsConfFile + " Write Error ", e.getMessage());
1109 e.printStackTrace();
1110 }
1111 }
1112
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();
1120 }
1121 try {
1122 fromTxt = new FileInputStream(fromFile);
1123 toBak = new FileOutputStream(toFile);
1124 byte[] buffer = new byte[4096];
1125 int bytes_read;
1126 while ((bytes_read = fromTxt.read(buffer)) != -1) {
1127 toBak.write(buffer, 0, bytes_read);
1128 }
1129 } finally {
1130 if (fromTxt != null)
1131 try {
1132 fromTxt.close();
1133 } catch (IOException e) {
1134 Log.err(toolsConfFile + " Read Error ", e.getMessage());
1135
1136 }
1137 if (toBak != null)
1138 try {
1139 toBak.close();
1140 } catch (IOException e) {
1141 Log.err(toolsConfFile + ".bak Write Error ", e.getMessage());
1142 }
1143 }
1144 }
1145
1146 private void exit() {
1147 this.setVisible(false);
1148 if (bTarget != null) {
1149 bTarget.dispose();
1150 }
1151 }
1152 }