]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/toolchain/Preferences.java
17e5afe7ddf28ad75f9dd46d06d4ecb249fa070a
[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 import javax.swing.JFrame;
34
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;
45
46 /**
47 * The class is used to update the target.txt file.
48 *
49 * It extends IDialog
50 *
51 */
52 public class Preferences extends IFrame {
53
54 // /
55 // / Define class Serial Version UID
56 // /
57 private static final long serialVersionUID = -4777906991966638888L;
58
59 private final boolean Debug = false;
60
61 //
62 // Define class members
63 //
64 private final int oneRowHeight = 20;
65
66 private final int twoRowHeight = 40;
67
68 private final int threeRowHeight = 60;
69
70 private final int sepHeight = 6;
71
72 private final int rowOne = 12;
73
74 private final int rowTwo = rowOne + oneRowHeight + sepHeight;
75
76 private final int rowThree = rowTwo + oneRowHeight + sepHeight;
77
78 private final int rowFour = rowThree + threeRowHeight + sepHeight;
79
80 private final int rowFive = rowFour + threeRowHeight + sepHeight;
81
82 private final int rowSix = rowFive + oneRowHeight + sepHeight;
83
84 private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;
85
86 private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;
87
88 private final int dialogWidth = 540;
89
90 private final int lastButtonXLoc = 430;
91
92 private final int next2LastButtonLoc = 329;
93
94 /*
95 * Define the contents for this dialog box
96 */
97 private static Preferences bTarget = null;
98
99 private WorkspaceTools wt = new WorkspaceTools();
100
101 private JFrame frame;
102
103 private final int activePlatformId = 0;
104
105 private final int buildTargetId = 1;
106
107 private final int targetArchId = 2;
108
109 private final int toolDefFileId = 3;
110
111 private final int tagNameId = 4;
112
113 private final int threadEnableId = 5;
114
115 private final int threadCountId = 6;
116
117 private final int maxTargetLines = threadCountId + 1;
118
119 private JPanel jContentPane = null;
120
121 private JLabel jLabelToolsConfigFile = null;
122
123 private JTextField jTextFieldToolsConfigFile = null;
124
125 private final int toolConfigFileRow = rowOne;
126
127 private JLabel jLabelActivePlatform = null;
128
129 private JComboBox jComboBoxActivePlatform = null;
130
131 private final int activePlatformRow = rowTwo;
132
133 private JLabel jLabelToolChainTagName = null;
134
135 private JScrollPane jScrollPaneTagName = null;
136
137 private ICheckBoxList iCheckBoxListTagName = null;
138
139 private final int toolChainTagNameRow = rowThree;
140
141 private JLabel jLabelBuildTarget = null;
142
143 private JScrollPane jScrollPaneBuildTarget = null;
144
145 private ICheckBoxList iCheckBoxListBuildTarget = null;
146
147 private final int buildTargetRow = rowFour;
148
149 private JLabel jLabelTargetArch = null;
150
151 private ArchCheckBox jArchCheckBox = null;
152
153 private final int targetArchRow = rowFive;
154
155 private JLabel jLabelEnableThreads = null;
156
157 private JLabel jLabelThreadCount = null;
158
159 private final int threadRow = rowSix;
160
161 private JCheckBox jCheckBoxEnableThreads = null;
162
163 private JTextField jTextFieldThreadCount = null;
164
165 private String threadCount = "";
166
167 private boolean threadEnabled = false;
168
169 private JButton jButtonBrowse = null;
170
171 private JButton jButtonSave = null;
172
173 private JButton jButtonCancel = null;
174
175 private final int labelColumn = 12;
176
177 private final int labelWidth = 155;
178
179 private final int valueColumn = 168;
180
181 private final int valueWidth = 352;
182
183 private final int valueWidthShort = 260;
184
185 private final int buttonWidth = 90;
186
187 private String workspaceDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator");
188
189 private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"
190 + System.getProperty("file.separator") + "Conf";
191
192 private String defaultToolsConf = toolsDir + System.getProperty("file.separator") + "tools_def.txt";
193
194 private String targetFile = toolsDir + System.getProperty("file.separator") + "target.txt";
195
196 private String[] targetFileContents = new String[500];
197
198 // private String[] toolsConfContents;
199
200 private String[] targetLines = new String[maxTargetLines];
201
202 private int targetLineNumber[] = new int[maxTargetLines];
203
204 private String toolsConfFile;
205
206 private String toolsDefTargetNames = null;
207
208 private final int toolsDefTargetNameField = 0;
209
210 private String toolsDefTagNames = null;
211
212 private final int toolsDefTagNameField = 1;
213
214 private String toolsDefArchNames = null;
215
216 private final int toolsDefArchNameField = 2;
217
218 private String toolsDefIdentifier = null;
219
220 private int targetLineNumberMax;
221
222 private final int toolDefFieldCount = 5;
223
224 private Vector<String> vArchList = null;
225
226 private Vector<String> vDisableArchList = null;
227
228 //
229 // Not used by UI
230 //
231 // private Preferences id = null;
232
233 // private EnumerationData ed = new EnumerationData();
234
235 /**
236 This method initializes jTextFieldToolsConfigFile
237
238 @return javax.swing.JTextField jTextFieldToolsConfigFile
239 **/
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());
245 } else
246 jTextFieldToolsConfigFile = new JTextField();
247
248 jTextFieldToolsConfigFile.setBounds(new java.awt.Rectangle(valueColumn, toolConfigFileRow, valueWidthShort,
249 oneRowHeight));
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>");
257
258 }
259 return jTextFieldToolsConfigFile;
260 }
261
262 /**
263 * This method initializes jComboBoxActivePlatform
264 *
265 * @return javax.swing.JComboBox jComboBoxActivePlatform
266 *
267 */
268 private JComboBox getActivePlatform() {
269 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
270
271 if (jComboBoxActivePlatform == null) {
272 jComboBoxActivePlatform = new JComboBox();
273 jComboBoxActivePlatform.setBounds(new java.awt.Rectangle(valueColumn, activePlatformRow, valueWidth,
274 oneRowHeight));
275 jComboBoxActivePlatform.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
276 jComboBoxActivePlatform
277 .setToolTipText("<html>Select &quot;Do Not Set&quot; 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>");
280
281 /*
282 * Generate the data, selecting what is in target.txt
283 */
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());
292 }
293 if (targetLines[activePlatformId] == null)
294 jComboBoxActivePlatform.setSelectedItem("Do Not Set");
295 else
296 jComboBoxActivePlatform.setSelectedItem(targetLines[activePlatformId]);
297 }
298 return jComboBoxActivePlatform;
299 }
300
301 /**
302 * This method initializes jScrollPaneTagName
303 *
304 * @return javax.swing.JScrollPane jScrollPaneTagName
305 *
306 */
307 private JScrollPane getJScrollPaneTagName() {
308
309 if (jScrollPaneTagName == null) {
310 jScrollPaneTagName = new JScrollPane();
311 jScrollPaneTagName.setBounds(new java.awt.Rectangle(valueColumn, toolChainTagNameRow, valueWidth,
312 threeRowHeight));
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);
322
323 }
324 return jScrollPaneTagName;
325 }
326
327 private ICheckBoxList getICheckBoxListTagName() {
328 if (iCheckBoxListTagName == null) {
329 iCheckBoxListTagName = new ICheckBoxList();
330
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]);
337 }
338 iCheckBoxListTagName.setAllItems(vTags);
339 } else {
340 Vector<String> defaultTags = stringToVector("MYTOOLS");
341 iCheckBoxListTagName.setAllItems(defaultTags);
342 }
343
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);
356 }
357 }
358 return iCheckBoxListTagName;
359 }
360
361 /**
362 * This method initializes jScrollPaneBuildTarget
363 *
364 * @return javax.swing.JComboBox jScrollPaneBuildTarget
365 *
366 */
367 private JScrollPane getJScrollPaneBuildTarget() {
368 if (jScrollPaneBuildTarget == null) {
369 jScrollPaneBuildTarget = new JScrollPane();
370 jScrollPaneBuildTarget.setBounds(new java.awt.Rectangle(valueColumn, buildTargetRow, valueWidth,
371 threeRowHeight));
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>");
382
383 }
384 return jScrollPaneBuildTarget;
385 }
386
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);
394
395 }
396 return jCheckBoxEnableThreads;
397 }
398
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
407
408 }
409 return jTextFieldThreadCount;
410 }
411
412 private ICheckBoxList getICheckBoxListBuildTarget() {
413 if (iCheckBoxListBuildTarget == null) {
414
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]);
419 }
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>");
428
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);
436 }
437 }
438 return iCheckBoxListBuildTarget;
439 }
440
441 /**
442 This method initializes jButtonBrowse
443
444 @return javax.swing.JButton
445 **/
446 private JButton getJButtonBrowse() {
447 if (jButtonBrowse == null) {
448 jButtonBrowse = new JButton();
449 jButtonBrowse
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() {
454 /**
455 *
456 */
457 private static final long serialVersionUID = 1L;
458
459 public void actionPerformed(ActionEvent e) {
460 //
461 // Select files from current workspace
462 //
463 String dirPrefix = toolsDir + System.getProperty("file.separator");
464 JFileChooser chooser = new JFileChooser(dirPrefix);
465 File theFile = null;
466 // String headerDest = null;
467
468 chooser.setMultiSelectionEnabled(false);
469 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
470 int retval = chooser.showOpenDialog(frame);
471 if (retval == JFileChooser.APPROVE_OPTION) {
472
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!");
479
480 return;
481 }
482
483 jTextFieldToolsConfigFile.setText("Tools/Conf/" + theFile.getName());
484 } else {
485 return;
486 }
487 }
488 });
489 }
490 return jButtonBrowse;
491 }
492
493 /**
494 * This method initializes jButtonOk
495 *
496 * @return javax.swing.JButton
497 *
498 */
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);
505 }
506 return jButtonSave;
507 }
508
509 /**
510 * This method initializes jButtonCancel
511 *
512 * @return javax.swing.JButton
513 *
514 */
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);
521 }
522 return jButtonCancel;
523 }
524
525 public static void main(String[] args) {
526 // TODO Auto-generated method stub
527
528 }
529
530 public static Preferences getInstance() {
531 if (bTarget == null) {
532 bTarget = new Preferences();
533 }
534 return bTarget;
535 }
536
537 /**
538 * This is the default constructor
539 */
540 public Preferences() {
541 super();
542 init();
543 }
544
545 /**
546 * This method initializes this
547 *
548 */
549 private void init() {
550 for (int i = 0; i < maxTargetLines; i++) {
551 targetLines[i] = null;
552 targetLineNumber[i] = -1;
553 }
554 initReadFiles();
555 this.setSize(dialogWidth, dialogHeight);
556 this.setContentPane(getJContentPane());
557 this.setTitle("Build Preferences [" + toolsDefIdentifier + "]");
558 this.setDefaultCloseOperation(IFrame.DISPOSE_ON_CLOSE);
559 this.centerWindow();
560 this.setVisible(true);
561 }
562
563 /**
564 * This method initializes this Fill values to all fields if these values are
565 * not empty
566 *
567 * @param initReadFiles
568 *
569 */
570 private void initReadFiles() {
571 /*
572 * TODO
573 * Read Current target.txt file first
574 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
575 */
576 readTargetTxtFile();
577 boolean haveBuildTargets = readToolDefinitionFile();
578 if (!haveBuildTargets) {
579 // Lookup Build Targets from the platforms
580 readPlatformFileBuildTargets();
581 }
582 }
583
584 private void readPlatformFileBuildTargets() {
585 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
586 String sBuildTargets = "";
587
588 // foreach platform, build a list of BuildTargets
589 Iterator<PlatformIdentification> iter = vPlatformId.iterator();
590 while (iter.hasNext()) {
591 PlatformIdentification item = iter.next();
592 PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd = GlobalData.openingPlatformList
593 .getOpeningPlatformById(
594 item)
595 .getXmlFpd();
596 sBuildTargets += fpd.getPlatformDefinitions().getBuildTargets().toString() + " ";
597 }
598 String allTargets[] = sBuildTargets.trim().split(" ");
599 for (int i = 0; i < allTargets.length; i++) {
600 if (!toolsDefTargetNames.contains(allTargets[i])) {
601 toolsDefTargetNames += allTargets[i] + " ";
602 }
603 }
604 }
605
606 private boolean readToolDefinitionFile() {
607
608 // Parse the tool definition file looking for targets and architectures
609 toolsConfFile = null;
610 boolean buildTargetsExist = true;
611
612 if (targetLines[toolDefFileId] != null) {
613 String[] result = new String[2];
614 targetLines[toolDefFileId].trim();
615 result = (targetLines[toolDefFileId]).split("=");
616 String resString = (Tools.convertPathToCurrentOsType(result[1])).trim();
617 toolsConfFile = workspaceDir.trim() + resString.trim();
618 File toolsDefFile = new File(toolsConfFile);
619 if (!toolsDefFile.exists()) {
620 JOptionPane.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile
621 + "<br>specified in the target.txt file does not exist!"
622 + "<br>Using the default Tool Definition File:<br>"
623 + defaultToolsConf);
624 toolsConfFile = defaultToolsConf;
625 }
626 } else {
627 toolsConfFile = defaultToolsConf;
628 }
629 String[] toolsDefFields = new String[toolDefFieldCount];
630 for (int i = 0; i < toolDefFieldCount; i++)
631 toolsDefFields[i] = null;
632 File toolDefFile = new File(toolsConfFile);
633 if (toolDefFile.exists()) {
634 try {
635 FileReader fileReader = new FileReader(toolDefFile);
636 BufferedReader reader = new BufferedReader(fileReader);
637 String rLine = null;
638 String result[];
639 int lineCounter = 0;
640 while ((rLine = reader.readLine()) != null) {
641
642 if (rLine.startsWith("IDENTIFIER")) {
643 result = rLine.split("=");
644 toolsDefIdentifier = (result[1]).trim();
645 } else if ((!rLine.startsWith("#")) && (rLine.contains("="))) {
646 result = rLine.split("=");
647 toolsDefFields = ((result[0]).trim()).split("_");
648 if (toolsDefTargetNames == null) {
649 toolsDefTargetNames = (toolsDefFields[toolsDefTargetNameField]).trim() + " ";
650 } else if (!toolsDefTargetNames.contains((toolsDefFields[toolsDefTargetNameField]).trim())) {
651 toolsDefTargetNames += (toolsDefFields[toolsDefTargetNameField]).trim() + " ";
652 }
653 if (toolsDefTagNames == null) {
654 toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).trim() + " ";
655 } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).trim())) {
656 toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).trim() + " ";
657 }
658 if (toolsDefArchNames == null) {
659 toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).trim() + " ";
660 } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).trim())) {
661 toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).trim() + " ";
662 }
663 }
664 lineCounter++;
665 }
666 reader.close();
667 // Only enable Architecture selection based on tool chain installations
668 String turnOff = "";
669 if (!toolsDefArchNames.contains("EBC"))
670 turnOff = "EBC ";
671 if (!toolsDefArchNames.contains("PPC"))
672 turnOff += "PPC ";
673 if (!toolsDefArchNames.contains("IPF"))
674 turnOff += "IPF ";
675 if (!toolsDefArchNames.contains("X64"))
676 turnOff += "X64 ";
677 if (!toolsDefArchNames.contains("IA32"))
678 turnOff += "X64 ";
679 if (!toolsDefArchNames.contains("ARM"))
680 turnOff += "ARM ";
681 turnOff = turnOff.trim();
682 vDisableArchList = stringToVector(turnOff);
683
684 if (!toolsDefTargetNames.matches("[A-Z]+")) {
685 toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();
686 if (Debug)
687 System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames
688 + "'");
689 buildTargetsExist = false;
690 }
691 } catch (IOException e) {
692 Log.log(toolsConfFile + " Read Error ", e.getMessage());
693 e.printStackTrace();
694 }
695 }
696 return buildTargetsExist;
697 }
698
699 private void readTargetTxtFile() {
700 File tFile = new File(targetFile);
701
702 if (tFile.exists()) {
703 try {
704 FileReader fileReader = new FileReader(targetFile);
705 BufferedReader reader = new BufferedReader(fileReader);
706 targetLineNumberMax = 0;
707 String rLine = null;
708 while ((rLine = reader.readLine()) != null) {
709 targetFileContents[targetLineNumberMax] = rLine;
710 if (rLine.startsWith("ACTIVE_PLATFORM")) {
711 // Only one active platform is permitted!
712 targetLines[activePlatformId] = rLine;
713 targetLineNumber[activePlatformId] = targetLineNumberMax;
714 }
715 if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t"))
716 || (rLine.startsWith("TARGET="))) {
717 // Handle multiple Target Names
718 if (rLine.contains(","))
719 targetLines[buildTargetId] = rLine.trim().replaceAll(",", " ");
720 else
721 targetLines[buildTargetId] = rLine.trim();
722 targetLineNumber[buildTargetId] = targetLineNumberMax;
723 }
724 if (rLine.startsWith("TARGET_ARCH")) {
725 // Handle multiple Target Architectures
726 if (rLine.contains(","))
727 targetLines[targetArchId] = rLine.trim().replaceAll(",", " ");
728 else
729 targetLines[targetArchId] = rLine.trim();
730 targetLineNumber[targetArchId] = targetLineNumberMax;
731 }
732 if (rLine.startsWith("TOOL_CHAIN_CONF")) {
733 // Only one file is permitted
734 targetLines[toolDefFileId] = rLine.trim();
735 targetLineNumber[toolDefFileId] = targetLineNumberMax;
736 }
737
738 if (rLine.startsWith("TOOL_CHAIN_TAG")) {
739 // Handle multiple Tool TagNames
740 if (rLine.contains(","))
741 targetLines[tagNameId] = rLine.trim().replaceAll(",", " ");
742 else
743 targetLines[tagNameId] = rLine.trim();
744 targetLineNumber[tagNameId] = targetLineNumberMax;
745 }
746
747 if (rLine.startsWith("MULTIPLE_THREAD")) {
748 // Handle Thread Enable flag
749 targetLines[threadEnableId] = rLine.trim();
750 targetLineNumber[threadEnableId] = targetLineNumberMax;
751 if ((rLine.trim().toLowerCase().contains("enabled")) || (rLine.trim().toLowerCase().contains("true"))) {
752 threadEnabled = true;
753 } else {
754 threadEnabled = false;
755 }
756 }
757
758 if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
759 // Handle Thread Enable flag
760 targetLines[threadCountId] = rLine.trim();
761 targetLineNumber[threadCountId] = targetLineNumberMax;
762 }
763 targetLineNumberMax++;
764 }
765 reader.close();
766 String archLine[] = new String[2];
767 if (targetLines[targetArchId] != null) {
768 if (targetLines[targetArchId].contains("=")) {
769 if (targetLines[targetArchId].contains(","))
770 targetLines[targetArchId] = targetLines[targetArchId].trim().replaceAll(",", " ");
771 if (targetLines[targetArchId].length() > 0)
772 archLine = targetLines[targetArchId].trim().split("=");
773 vArchList = stringToVector(archLine[1]);
774 }
775 }
776
777 if (targetLines[threadCountId] != null) {
778 String tcLine[] = new String[2];
779 tcLine = targetLines[threadCountId].trim().split("=");
780 threadCount = tcLine[1];
781 } else
782 threadCount = "";
783
784 if (Debug == true)
785 for (int i = 0; i <= maxTargetLines; i++)
786 System.out.println("targetLines[" + i + "] contains: " + targetLines[i] + " index is: "
787 + targetLineNumber[i]);
788 } catch (IOException e) {
789 Log.log(this.targetFile + " Read Error ", e.getMessage());
790 e.printStackTrace();
791 }
792 }
793
794 }
795
796 /**
797 * This method initializes jContentPane
798 *
799 * @return javax.swing.JPanel jContentPane
800 *
801 */
802 private JPanel getJContentPane() {
803 if (jContentPane == null) {
804 jLabelToolsConfigFile = new JLabel();
805 jLabelToolsConfigFile.setBounds(new java.awt.Rectangle(labelColumn, toolConfigFileRow, labelWidth,
806 oneRowHeight));
807 jLabelToolsConfigFile.setText("Tool Chain Definition File");
808 jLabelActivePlatform = new JLabel();
809 jLabelActivePlatform.setText("Select Active Platform");
810 jLabelActivePlatform.setBounds(new java.awt.Rectangle(labelColumn, activePlatformRow, labelWidth,
811 oneRowHeight));
812 jLabelToolChainTagName = new JLabel();
813 jLabelToolChainTagName.setBounds(new java.awt.Rectangle(labelColumn, toolChainTagNameRow, labelWidth,
814 oneRowHeight));
815 jLabelToolChainTagName.setText("Select Tool Tag Name");
816 jLabelBuildTarget = new JLabel();
817 jLabelBuildTarget.setBounds(new java.awt.Rectangle(labelColumn, buildTargetRow, labelWidth, oneRowHeight));
818 jLabelBuildTarget.setText("Select Build Target");
819 jLabelTargetArch = new JLabel();
820 jLabelTargetArch.setBounds(new java.awt.Rectangle(labelColumn, targetArchRow, labelWidth, oneRowHeight));
821 jLabelTargetArch.setText("Build Architectures");
822
823 jArchCheckBox = new ArchCheckBox();
824 jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));
825 jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
826
827 jLabelEnableThreads = new JLabel();
828 jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));
829 jLabelEnableThreads.setText("Enable Compiler Threading");
830
831 jLabelThreadCount = new JLabel();
832 jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));
833 jLabelThreadCount.setText("Number of threads to start");
834
835 jContentPane = new JPanel();
836 jContentPane.setLayout(null);
837 jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));
838
839 jContentPane.add(jLabelToolsConfigFile, null);
840 jContentPane.add(getJTextFieldToolsConfigFile(), null);
841 jContentPane.add(getJButtonBrowse(), null);
842
843 jContentPane.add(jLabelActivePlatform, null);
844 jContentPane.add(getActivePlatform(), null);
845
846 jContentPane.add(jLabelToolChainTagName, null);
847 jContentPane.add(getJScrollPaneTagName(), null);
848
849 jContentPane.add(jLabelBuildTarget, null);
850 jContentPane.add(getJScrollPaneBuildTarget(), null);
851
852 jContentPane.add(jLabelTargetArch, null);
853
854 jArchCheckBox.setDisabledItems(vDisableArchList);
855 jArchCheckBox.setSelectedItems(vArchList);
856 jContentPane.add(jArchCheckBox, null);
857
858 jContentPane.add(jLabelEnableThreads, null);
859 jContentPane.add(getCheckBoxEnableThreads(), null);
860
861 jContentPane.add(jLabelThreadCount, null);
862 jContentPane.add(getTextFieldThreadCount(), null);
863
864 jContentPane.add(getJButtonSave(), null);
865 jContentPane.add(getJButtonCancel(), null);
866 }
867 return jContentPane;
868 }
869
870 /*
871 * (non-Javadoc)
872 *
873 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
874 *
875 * Override actionPerformed to listen all actions
876 *
877 */
878 public void actionPerformed(ActionEvent arg0) {
879
880 if (arg0.getSource() == jButtonBrowse) {
881 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
882
883 }
884
885 if (arg0.getSource() == jButtonSave) {
886 saveTargetFile();
887 JOptionPane.showMessageDialog(this, "<html>The target.txt file has been saved!"
888 + "<br>A copy of the original file, target.txt.bak has"
889 + "<br>also been created.</html>");
890 this.exit();
891 }
892
893 if (arg0.getSource() == jButtonCancel) {
894 this.exit();
895 }
896
897 if (arg0.getSource() == jCheckBoxEnableThreads) {
898 if (jCheckBoxEnableThreads.isSelected() == false) {
899 threadCount = "";
900 jTextFieldThreadCount.setText(threadCount);
901 }
902 }
903 }
904
905
906 private void updateActivePlatform() {
907 int lineAP;
908 if (targetLines[activePlatformId] != null) {
909 lineAP = targetLineNumber[activePlatformId];
910 } else {
911 lineAP = targetLineNumberMax;
912 targetLineNumber[activePlatformId] = lineAP;
913 targetLineNumberMax++;
914 }
915 if (jComboBoxActivePlatform.getSelectedItem() == "Do Not Set") {
916 targetFileContents[lineAP] = "";
917 targetLines[activePlatformId] = "";
918 } else {
919 targetFileContents[lineAP] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform.getSelectedItem() + "\r\n";
920 targetLines[activePlatformId] = targetFileContents[lineAP];
921 }
922 if (Debug)
923 System.out.println("Active Platform: " + targetFileContents[lineAP]);
924 }
925
926 private void updateToolDefFile() {
927 int lineTDF;
928 if (targetLines[toolDefFileId] != null) {
929 lineTDF = targetLineNumber[toolDefFileId];
930 } else {
931 lineTDF = targetLineNumberMax;
932 targetLineNumber[toolDefFileId] = lineTDF;
933 targetLineNumberMax++;
934 }
935 if (Debug)
936 System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());
937 if (jTextFieldToolsConfigFile.getText() == null) {
938 targetFileContents[lineTDF] = "#MT#";
939 targetLines[toolDefFileId] = "";
940 } else {
941 targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();
942 targetLines[toolDefFileId] = targetFileContents[lineTDF];
943 }
944 }
945
946 private void updateToolTagNames() {
947 String sTagNames = vectorToString(iCheckBoxListTagName.getAllCheckedItemsString());
948 int lineTTN;
949
950 if (targetLines[tagNameId] != null) {
951 lineTTN = targetLineNumber[tagNameId];
952 } else {
953 lineTTN = targetLineNumberMax;
954 targetLineNumber[tagNameId] = lineTTN;
955 targetLineNumberMax++;
956 }
957
958 if (Debug)
959 System.out.println("Tag Name(s): " + sTagNames);
960
961 if (sTagNames.length() > 0) {
962 targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;
963 targetLines[tagNameId] = targetFileContents[lineTTN];
964 } else {
965 targetFileContents[lineTTN] = "#MT#";
966 targetLines[tagNameId] = "";
967 }
968 }
969
970 private void updateBuildTargets() {
971 String sBuildTargets = vectorToString(iCheckBoxListBuildTarget.getAllCheckedItemsString());
972 int lineBT;
973
974 if (targetLines[buildTargetId] != null) {
975 lineBT = targetLineNumber[buildTargetId];
976 } else {
977 lineBT = targetLineNumberMax;
978 targetLineNumber[buildTargetId] = lineBT;
979 targetLineNumberMax++;
980 }
981 if (Debug)
982 System.out.println("Build Target(s): " + sBuildTargets);
983 if (sBuildTargets.length() > 0) {
984 targetFileContents[lineBT] = "TARGET = " + sBuildTargets;
985 targetLines[buildTargetId] = targetFileContents[lineBT];
986 } else {
987 targetFileContents[lineBT] = "#MT#";
988 targetLines[buildTargetId] = "";
989 }
990
991 }
992
993 private void updateArchitectures() {
994 String sArchList = jArchCheckBox.getSelectedItemsString().trim();
995
996 if (Debug)
997 System.out.println("Architectures: " + sArchList);
998
999 int lineSA;
1000 if (targetLines[targetArchId] != null) {
1001 lineSA = targetLineNumber[targetArchId];
1002 } else {
1003 lineSA = targetLineNumberMax;
1004 targetLineNumber[targetArchId] = lineSA;
1005 targetLineNumberMax++;
1006 }
1007 if (sArchList == "") {
1008 targetFileContents[lineSA] = "#MT#";
1009 targetLines[targetArchId] = "";
1010 } else {
1011 targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;
1012 targetLines[targetArchId] = targetFileContents[lineSA];
1013 }
1014
1015 }
1016
1017 private void updateEnableThreads() {
1018 int lineET;
1019 if (targetLines[threadEnableId] != null) {
1020 lineET = targetLineNumber[threadEnableId];
1021 } else {
1022 lineET = targetLineNumberMax;
1023 targetLineNumber[threadEnableId] = lineET;
1024 targetLineNumberMax++;
1025 }
1026 if (jCheckBoxEnableThreads.isSelected() == true) {
1027 targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";
1028 targetLines[threadEnableId] = targetFileContents[lineET];
1029 } else {
1030 targetFileContents[lineET] = "#MT#";
1031 targetLines[threadEnableId] = "";
1032 }
1033 }
1034
1035 private void updateThreadCount() {
1036 int lineTC;
1037
1038 if (targetLines[threadCountId] != null) {
1039 lineTC = targetLineNumber[threadCountId];
1040 } else {
1041 lineTC = targetLineNumberMax;
1042 targetLineNumber[threadCountId] = lineTC;
1043 targetLineNumberMax++;
1044 }
1045 if (jCheckBoxEnableThreads.isSelected() == true) {
1046 // Threading must be enabled
1047 if (jTextFieldThreadCount.getText().length() > 0) {
1048 // Thread Count must be greater than 0
1049 Scanner scan = new Scanner(jTextFieldThreadCount.getText().trim());
1050 if (scan.nextInt() > 0) {
1051 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount.getText().trim();
1052 targetLines[threadCountId] = targetFileContents[lineTC];
1053 } else {
1054 Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1055 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1056 targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1057 }
1058 } else {
1059 Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1060 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1061 targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1062 }
1063 } else {
1064 // Don't track threads if threading is not enabled
1065 targetFileContents[lineTC] = "#MT#";
1066 targetLines[threadCountId] = "";
1067 threadCount = "";
1068 }
1069
1070 }
1071 private String vectorToString(Vector<String> v) {
1072 String s = " ";
1073 for (int i = 0; i < v.size(); ++i) {
1074 s += v.get(i);
1075 s += " ";
1076 }
1077 return s.trim();
1078 }
1079
1080 protected Vector<String> stringToVector(String s) {
1081 if (s == null) {
1082 return null;
1083 }
1084 String[] sArray = s.split(" ");
1085 Vector<String> v = new Vector<String>();
1086 for (int i = 0; i < sArray.length; ++i) {
1087 v.add(sArray[i]);
1088 }
1089 return v;
1090 }
1091
1092 private void saveTargetFile() {
1093 updateActivePlatform();
1094 updateToolDefFile();
1095 updateToolTagNames();
1096 updateBuildTargets();
1097 updateArchitectures();
1098 updateEnableThreads();
1099 updateThreadCount();
1100
1101 try {
1102 copy(targetFile, targetFile + ".bak");
1103 FileWriter fileWriter = new FileWriter(targetFile);
1104 BufferedWriter writer = new BufferedWriter(fileWriter);
1105 for (int i = 0; i < targetLineNumberMax; i++) {
1106 if (! targetFileContents[i].contains("#MT#"))
1107 writer.write(targetFileContents[i] + "\n");
1108 }
1109 writer.close();
1110 } catch (IOException e) {
1111 Log.err(toolsConfFile + " Write Error ", e.getMessage());
1112 e.printStackTrace();
1113 }
1114 }
1115
1116 private void copy(String txtFile, String bakFile) throws IOException {
1117 File fromFile = new File(txtFile);
1118 File toFile = new File(bakFile);
1119 FileInputStream fromTxt = null;
1120 FileOutputStream toBak = null;
1121 if (!fromFile.exists()) {
1122 fromFile.createNewFile();
1123 }
1124 try {
1125 fromTxt = new FileInputStream(fromFile);
1126 toBak = new FileOutputStream(toFile);
1127 byte[] buffer = new byte[4096];
1128 int bytes_read;
1129 while ((bytes_read = fromTxt.read(buffer)) != -1) {
1130 toBak.write(buffer, 0, bytes_read);
1131 }
1132 } finally {
1133 if (fromTxt != null)
1134 try {
1135 fromTxt.close();
1136 } catch (IOException e) {
1137 Log.err(toolsConfFile + " Read Error ", e.getMessage());
1138
1139 }
1140 if (toBak != null)
1141 try {
1142 toBak.close();
1143 } catch (IOException e) {
1144 Log.err(toolsConfFile + ".bak Write Error ", e.getMessage());
1145 }
1146 }
1147 }
1148
1149 private void exit() {
1150 this.setVisible(false);
1151 if (bTarget != null) {
1152 bTarget.dispose();
1153 }
1154 }
1155 }