+++ /dev/null
-/** @file\r
- <<The file is used to update the Build Preferences file, target.txt>>\r
- \r
- <<The program will use target.txt, the tools config file specified in that file,\r
- or it will use the default tools_def.txt file, and it will also scan the \r
- FrameworkDatabase.db file for certain parameters. >>\r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- \r
- Package Name: Tools\r
- Module Name: FrameworkWizard\r
- \r
- **/\r
-\r
-package org.tianocore.frameworkwizard.toolchain;\r
-\r
-import java.awt.event.ActionEvent;\r
-import java.io.*;\r
-import java.util.Vector;\r
-import java.util.Iterator;\r
-import java.util.Scanner;\r
-\r
-import javax.swing.*;\r
-import javax.swing.JScrollPane;\r
-import javax.swing.JTextField;\r
-\r
-import org.tianocore.frameworkwizard.common.GlobalData;\r
-import org.tianocore.frameworkwizard.common.Tools;\r
-import org.tianocore.frameworkwizard.common.Log;\r
-import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
-import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.*;\r
-import org.tianocore.frameworkwizard.common.ui.IFrame;\r
-import org.tianocore.frameworkwizard.workspace.Workspace;\r
-import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
-import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
-import org.tianocore.PlatformSurfaceAreaDocument;\r
-\r
-/**\r
- * The class is used to update the target.txt file.\r
- * \r
- * It extends IDialog\r
- * \r
- */\r
-public class Preferences extends IFrame {\r
-\r
- // /\r
- // / Define class Serial Version UID\r
- // /\r
- private static final long serialVersionUID = -4777906991966638888L;\r
-\r
- private final boolean Debug = false;\r
-\r
- //\r
- // Define class members\r
- //\r
- private final int oneRowHeight = 20;\r
-\r
- private final int twoRowHeight = 40;\r
-\r
- private final int threeRowHeight = 60;\r
-\r
- private final int sepHeight = 6;\r
-\r
- private final int rowOne = 12;\r
-\r
- private final int rowTwo = rowOne + oneRowHeight + sepHeight;\r
-\r
- private final int rowThree = rowTwo + oneRowHeight + sepHeight;\r
-\r
- private final int rowFour = rowThree + threeRowHeight + sepHeight;\r
-\r
- private final int rowFive = rowFour + threeRowHeight + sepHeight;\r
-\r
- private final int rowSix = rowFive + oneRowHeight + sepHeight;\r
-\r
- private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;\r
-\r
- private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;\r
-\r
- private final int dialogWidth = 540;\r
-\r
- private final int lastButtonXLoc = 430;\r
-\r
- private final int next2LastButtonLoc = 329;\r
-\r
- /*\r
- * Define the contents for this dialog box\r
- */\r
- private static Preferences bTarget = null;\r
-\r
- private WorkspaceTools wt = new WorkspaceTools();\r
-\r
- private final int activePlatformId = 0;\r
-\r
- private final int buildTargetId = 1;\r
-\r
- private final int targetArchId = 2;\r
-\r
- private final int toolDefFileId = 3;\r
-\r
- private final int tagNameId = 4;\r
-\r
- private final int threadEnableId = 5;\r
-\r
- private final int threadCountId = 6;\r
-\r
- private final int maxTargetLines = threadCountId + 1;\r
-\r
- private JPanel jContentPane = null;\r
-\r
- private JLabel jLabelToolsConfigFile = null;\r
-\r
- private JTextField jTextFieldToolsConfigFile = null;\r
-\r
- private final int toolConfigFileRow = rowOne;\r
-\r
- private JLabel jLabelActivePlatform = null;\r
-\r
- private JComboBox jComboBoxActivePlatform = null;\r
-\r
- private final int activePlatformRow = rowTwo;\r
-\r
- private JLabel jLabelToolChainTagName = null;\r
-\r
- private JScrollPane jScrollPaneTagName = null;\r
-\r
- private ICheckBoxList iCheckBoxListTagName = null;\r
-\r
- private final int toolChainTagNameRow = rowThree;\r
-\r
- private JLabel jLabelBuildTarget = null;\r
-\r
- private JScrollPane jScrollPaneBuildTarget = null;\r
-\r
- private ICheckBoxList iCheckBoxListBuildTarget = null;\r
-\r
- private final int buildTargetRow = rowFour;\r
-\r
- private JLabel jLabelTargetArch = null;\r
-\r
- private ArchCheckBox jArchCheckBox = null;\r
-\r
- private final int targetArchRow = rowFive;\r
-\r
- private JLabel jLabelEnableThreads = null;\r
-\r
- private JLabel jLabelThreadCount = null;\r
-\r
- private final int threadRow = rowSix;\r
-\r
- private JCheckBox jCheckBoxEnableThreads = null;\r
-\r
- private JTextField jTextFieldThreadCount = null;\r
- \r
- private String threadCount = "";\r
- \r
- private boolean threadEnabled = false;\r
-\r
- private JButton jButtonBrowse = null;\r
-\r
- private JButton jButtonSave = null;\r
-\r
- private JButton jButtonCancel = null;\r
-\r
- private final int labelColumn = 12;\r
-\r
- private final int labelWidth = 155;\r
-\r
- private final int valueColumn = 168;\r
-\r
- private final int valueWidth = 352;\r
-\r
- private final int valueWidthShort = 260;\r
-\r
- private final int buttonWidth = 90;\r
-\r
- private String workspaceDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator");\r
-\r
- private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"\r
- + System.getProperty("file.separator") + "Conf";\r
-\r
- private String defaultToolsConf = toolsDir + System.getProperty("file.separator") + "tools_def.txt";\r
-\r
- private String targetFile = toolsDir + System.getProperty("file.separator") + "target.txt";\r
-\r
- private String[] targetFileContents = new String[500];\r
-\r
- // private String[] toolsConfContents;\r
-\r
- private String[] targetLines = new String[maxTargetLines];\r
-\r
- private int targetLineNumber[] = new int[maxTargetLines];\r
-\r
- private String toolsConfFile;\r
-\r
- private String toolsDefTargetNames = null;\r
-\r
- private final int toolsDefTargetNameField = 0;\r
-\r
- private String toolsDefTagNames = null;\r
-\r
- private final int toolsDefTagNameField = 1;\r
-\r
- private String toolsDefArchNames = null;\r
-\r
- private final int toolsDefArchNameField = 2;\r
-\r
- private String toolsDefIdentifier = null;\r
-\r
- private int targetLineNumberMax;\r
- \r
- private final int toolDefFieldCount = 5;\r
-\r
- private Vector<String> vArchList = null;\r
-\r
- private Vector<String> vDisableArchList = null;\r
- \r
- //\r
- // Not used by UI\r
- //\r
- // private Preferences id = null;\r
-\r
- // private EnumerationData ed = new EnumerationData();\r
-\r
- /**\r
- This method initializes jTextFieldToolsConfigFile \r
- \r
- @return javax.swing.JTextField jTextFieldToolsConfigFile\r
- **/\r
- private JTextField getJTextFieldToolsConfigFile() {\r
- if (jTextFieldToolsConfigFile == null) {\r
- if (targetLines[toolDefFileId] != null) {\r
- String sLine[] = targetLines[toolDefFileId].trim().split("=");\r
- jTextFieldToolsConfigFile = new JTextField(sLine[1].trim());\r
- } else\r
- jTextFieldToolsConfigFile = new JTextField();\r
-\r
- jTextFieldToolsConfigFile.setBounds(new java.awt.Rectangle(valueColumn, toolConfigFileRow, valueWidthShort,\r
- oneRowHeight));\r
- jTextFieldToolsConfigFile.setPreferredSize(new java.awt.Dimension(valueWidthShort, oneRowHeight));\r
- jTextFieldToolsConfigFile\r
- .setToolTipText("<html>"\r
- + "Specify the name of the filename to use for specifying"\r
- + "<br>the tools to use for the build. If not specified,"\r
- + "<br>tools_def.txt will be used for the build. This file"\r
- + "<br>MUST be located in the WORKSPACE/Tools/Conf directory.</html>");\r
-\r
- }\r
- return jTextFieldToolsConfigFile;\r
- }\r
-\r
- /**\r
- * This method initializes jComboBoxActivePlatform\r
- * \r
- * @return javax.swing.JComboBox jComboBoxActivePlatform\r
- * \r
- */\r
- private JComboBox getActivePlatform() {\r
- Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();\r
-\r
- if (jComboBoxActivePlatform == null) {\r
- jComboBoxActivePlatform = new JComboBox();\r
- jComboBoxActivePlatform.setBounds(new java.awt.Rectangle(valueColumn, activePlatformRow, valueWidth,\r
- oneRowHeight));\r
- jComboBoxActivePlatform.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));\r
- jComboBoxActivePlatform\r
- .setToolTipText("<html>Select "Do Not Set" if you want to build a platform"\r
- + "<br>from the directory where the FPD file exists,"\r
- + "<br>otherwise scroll down to select the platform.</html>");\r
-\r
- /*\r
- * Generate the data, selecting what is in target.txt\r
- */\r
- jComboBoxActivePlatform.addItem("Do Not Set");\r
- Iterator<PlatformIdentification> iter = vPlatformId.iterator();\r
- while (iter.hasNext()) {\r
- PlatformIdentification item = iter.next();\r
- String path = item.getPath().trim();\r
- String str = path.substring(workspaceDir.length(), path.length());\r
- str.replace(System.getProperty("file.separator"), "/");\r
- jComboBoxActivePlatform.addItem(str.trim());\r
- }\r
- if (targetLines[activePlatformId] == null)\r
- jComboBoxActivePlatform.setSelectedItem("Do Not Set");\r
- else\r
- jComboBoxActivePlatform.setSelectedItem(targetLines[activePlatformId]);\r
- }\r
- return jComboBoxActivePlatform;\r
- }\r
-\r
- /**\r
- * This method initializes jScrollPaneTagName\r
- * \r
- * @return javax.swing.JScrollPane jScrollPaneTagName\r
- * \r
- */\r
- private JScrollPane getJScrollPaneTagName() {\r
-\r
- if (jScrollPaneTagName == null) {\r
- jScrollPaneTagName = new JScrollPane();\r
- jScrollPaneTagName.setBounds(new java.awt.Rectangle(valueColumn, toolChainTagNameRow, valueWidth,\r
- threeRowHeight));\r
- jScrollPaneTagName.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));\r
- jScrollPaneTagName.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r
- jScrollPaneTagName.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);\r
- jScrollPaneTagName.setViewportView(getICheckBoxListTagName());\r
- jScrollPaneTagName.setToolTipText("<html>"\r
- + "Specify the TagName(s) from the tool configuration file to use"\r
- + "<br>for your builds. If not specified, all applicable TagName"\r
- + " <br>tools will be used for the build.</html>");\r
- jScrollPaneTagName.setVisible(true);\r
-\r
- }\r
- return jScrollPaneTagName;\r
- }\r
-\r
- private ICheckBoxList getICheckBoxListTagName() {\r
- if (iCheckBoxListTagName == null) {\r
- iCheckBoxListTagName = new ICheckBoxList();\r
-\r
- if (toolsDefTagNames != null) {\r
- toolsDefTagNames.trim();\r
- String aTagNames[] = toolsDefTagNames.trim().split(" ");\r
- Vector<String> vTags = new Vector<String>();\r
- for (int i = 0; i < aTagNames.length; i++) {\r
- vTags.add(aTagNames[i]);\r
- }\r
- iCheckBoxListTagName.setAllItems(vTags);\r
- } else {\r
- Vector<String> defaultTags = stringToVector("MYTOOLS");\r
- iCheckBoxListTagName.setAllItems(defaultTags);\r
- }\r
-\r
- iCheckBoxListTagName.setAllItemsUnchecked();\r
- iCheckBoxListTagName.setToolTipText("<html>"\r
- + "Specify the TagName(s) from the tool configuration file to use"\r
- + "<br>for your builds. If not specified, all applicable TagName"\r
- + " <br>tools will be used for the build.</html>");\r
- Vector<String> vSelectedTags = new Vector<String>();\r
- if (targetLines[tagNameId] != null) {\r
- targetLines[tagNameId].trim();\r
- String targetTags[] = targetLines[tagNameId].trim().split(" ");\r
- for (int j = 0; j < targetTags.length; j++)\r
- vSelectedTags.add(targetTags[j]);\r
- iCheckBoxListTagName.initCheckedItem(true, vSelectedTags);\r
- }\r
- }\r
- return iCheckBoxListTagName;\r
- }\r
-\r
- /**\r
- * This method initializes jScrollPaneBuildTarget\r
- * \r
- * @return javax.swing.JComboBox jScrollPaneBuildTarget\r
- * \r
- */\r
- private JScrollPane getJScrollPaneBuildTarget() {\r
- if (jScrollPaneBuildTarget == null) {\r
- jScrollPaneBuildTarget = new JScrollPane();\r
- jScrollPaneBuildTarget.setBounds(new java.awt.Rectangle(valueColumn, buildTargetRow, valueWidth,\r
- threeRowHeight));\r
- jScrollPaneBuildTarget.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));\r
- jScrollPaneBuildTarget.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r
- jScrollPaneBuildTarget.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);\r
- jScrollPaneBuildTarget.setViewportView(getICheckBoxListBuildTarget());\r
- jScrollPaneBuildTarget.setVisible(true);\r
- jScrollPaneBuildTarget.setToolTipText("<html>"\r
- + "Select the TARGET Names that you want to build, such as<BR>"\r
- + "BUILD or BUILD and RELEASE"\r
- + "<br>If you do not set any of these, all available targets"\r
- + "<br>will be built.</html>");\r
-\r
- }\r
- return jScrollPaneBuildTarget;\r
- }\r
-\r
- private JCheckBox getCheckBoxEnableThreads() {\r
- if (jCheckBoxEnableThreads == null) {\r
- jCheckBoxEnableThreads = new JCheckBox();\r
- jCheckBoxEnableThreads.setBounds(valueColumn, threadRow, 20, oneRowHeight);\r
- jCheckBoxEnableThreads.setToolTipText("Select this if you want to enable parallel compilation.");\r
- jCheckBoxEnableThreads.setSelected(threadEnabled);\r
- jCheckBoxEnableThreads.addActionListener(this);\r
- \r
- }\r
- return jCheckBoxEnableThreads;\r
- }\r
-\r
- private JTextField getTextFieldThreadCount() {\r
- if (jTextFieldThreadCount == null) {\r
- jTextFieldThreadCount = new JTextField();\r
- jTextFieldThreadCount.setBounds(valueColumn + 215, threadRow, 30, oneRowHeight);\r
- if (threadCount.length() > 0)\r
- jTextFieldThreadCount.setText(threadCount);\r
- jTextFieldThreadCount.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");\r
- // If CheckBoxEnableThreads is selected, then enable editing\r
-\r
- }\r
- return jTextFieldThreadCount;\r
- }\r
-\r
- private ICheckBoxList getICheckBoxListBuildTarget() {\r
- if (iCheckBoxListBuildTarget == null) {\r
-\r
- String aBuildTargets[] = toolsDefTargetNames.trim().split(" ");\r
- Vector<String> vBuildTargets = new Vector<String>();\r
- for (int i = 0; i < aBuildTargets.length; i++) {\r
- vBuildTargets.add(aBuildTargets[i]);\r
- }\r
- iCheckBoxListBuildTarget = new ICheckBoxList();\r
- iCheckBoxListBuildTarget.setAllItems(vBuildTargets);\r
- iCheckBoxListBuildTarget.setAllItemsUnchecked();\r
- iCheckBoxListBuildTarget.setToolTipText("<html>"\r
- + "Select the TARGET Names that you want to build, such as<BR>"\r
- + "BUILD or BUILD and RELEASE"\r
- + "<br>If you do not set any of these, all available targets"\r
- + "<br>will be built.</html>");\r
-\r
- Vector<String> vSelectedTags = new Vector<String>();\r
- if (targetLines[buildTargetId] != null) {\r
- targetLines[buildTargetId].trim();\r
- String targetTags[] = targetLines[buildTargetId].trim().split(" ");\r
- for (int j = 0; j < targetTags.length; j++)\r
- vSelectedTags.add(targetTags[j]);\r
- iCheckBoxListBuildTarget.initCheckedItem(true, vSelectedTags);\r
- }\r
- }\r
- return iCheckBoxListBuildTarget;\r
- }\r
-\r
- /**\r
- This method initializes jButtonBrowse \r
- \r
- @return javax.swing.JButton \r
- **/\r
- private JButton getJButtonBrowse() {\r
- if (jButtonBrowse == null) {\r
- jButtonBrowse = new JButton();\r
- jButtonBrowse\r
- .setBounds(new java.awt.Rectangle(lastButtonXLoc, toolConfigFileRow, buttonWidth, oneRowHeight));\r
- jButtonBrowse.setText("Browse");\r
- jButtonBrowse.setPreferredSize(new java.awt.Dimension(buttonWidth, oneRowHeight));\r
- jButtonBrowse.addActionListener(new AbstractAction() {\r
- /**\r
- * \r
- */\r
- private static final long serialVersionUID = 1L;\r
-\r
- public void actionPerformed(ActionEvent e) {\r
- //\r
- // Select files from current workspace\r
- //\r
- String dirPrefix = toolsDir + System.getProperty("file.separator");\r
- JFileChooser chooser = new JFileChooser(dirPrefix);\r
- File theFile = null;\r
- // String headerDest = null;\r
-\r
- chooser.setMultiSelectionEnabled(false);\r
- chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);\r
- int retval = chooser.showOpenDialog(Preferences.this);\r
- if (retval == JFileChooser.APPROVE_OPTION) {\r
-\r
- theFile = chooser.getSelectedFile();\r
- String file = theFile.getPath();\r
- if (!file.startsWith(dirPrefix)) {\r
- JOptionPane.showMessageDialog(Preferences.this, "You can only select files in the Tools"\r
- + System.getProperty("file.separator")\r
- + "Conf directory!");\r
-\r
- return;\r
- }\r
-\r
- jTextFieldToolsConfigFile.setText("Tools/Conf/" + theFile.getName());\r
- } else {\r
- return;\r
- }\r
- }\r
- });\r
- }\r
- return jButtonBrowse;\r
- }\r
-\r
- /**\r
- * This method initializes jButtonOk\r
- * \r
- * @return javax.swing.JButton\r
- * \r
- */\r
- private JButton getJButtonSave() {\r
- if (jButtonSave == null) {\r
- jButtonSave = new JButton();\r
- jButtonSave.setBounds(new java.awt.Rectangle(next2LastButtonLoc, buttonRow, buttonWidth, oneRowHeight));\r
- jButtonSave.setText("Save");\r
- jButtonSave.addActionListener(this);\r
- }\r
- return jButtonSave;\r
- }\r
-\r
- /**\r
- * This method initializes jButtonCancel\r
- * \r
- * @return javax.swing.JButton\r
- * \r
- */\r
- private JButton getJButtonCancel() {\r
- if (jButtonCancel == null) {\r
- jButtonCancel = new JButton();\r
- jButtonCancel.setBounds(new java.awt.Rectangle(lastButtonXLoc, buttonRow, buttonWidth, oneRowHeight));\r
- jButtonCancel.setText("Cancel");\r
- jButtonCancel.addActionListener(this);\r
- }\r
- return jButtonCancel;\r
- }\r
-\r
- public static void main(String[] args) {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- public static Preferences getInstance() {\r
- if (bTarget == null) {\r
- bTarget = new Preferences();\r
- }\r
- return bTarget;\r
- }\r
-\r
- /**\r
- * This is the default constructor\r
- */\r
- public Preferences() {\r
- super();\r
- init();\r
- }\r
-\r
- /**\r
- * This method initializes this\r
- * \r
- */\r
- private void init() {\r
- for (int i = 0; i < maxTargetLines; i++) {\r
- targetLines[i] = null;\r
- targetLineNumber[i] = -1;\r
- }\r
- initReadFiles();\r
- this.setSize(dialogWidth, dialogHeight);\r
- this.setContentPane(getJContentPane());\r
- this.setTitle("Build Preferences [" + toolsDefIdentifier + "]");\r
- this.setDefaultCloseOperation(IFrame.DISPOSE_ON_CLOSE);\r
- this.centerWindow();\r
- this.setVisible(true);\r
- }\r
-\r
- /**\r
- * This method initializes this Fill values to all fields if these values are\r
- * not empty\r
- * \r
- * @param initReadFiles\r
- * \r
- */\r
- private void initReadFiles() {\r
- /*\r
- * TODO\r
- * Read Current target.txt file first\r
- * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt\r
- */\r
- readTargetTxtFile();\r
- boolean haveBuildTargets = readToolDefinitionFile();\r
- if (!haveBuildTargets) {\r
- // Lookup Build Targets from the platforms\r
- readPlatformFileBuildTargets();\r
- }\r
- }\r
-\r
- private void readPlatformFileBuildTargets() {\r
- Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();\r
- String sBuildTargets = "";\r
-\r
- // foreach platform, build a list of BuildTargets\r
- Iterator<PlatformIdentification> iter = vPlatformId.iterator();\r
- while (iter.hasNext()) {\r
- PlatformIdentification item = iter.next();\r
- PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd = GlobalData.openingPlatformList\r
- .getOpeningPlatformById(\r
- item)\r
- .getXmlFpd();\r
- sBuildTargets += fpd.getPlatformDefinitions().getBuildTargets().toString() + " ";\r
- }\r
- String allTargets[] = sBuildTargets.trim().split(" ");\r
- for (int i = 0; i < allTargets.length; i++) {\r
- if (!toolsDefTargetNames.contains(allTargets[i])) {\r
- toolsDefTargetNames += allTargets[i] + " ";\r
- }\r
- }\r
- }\r
-\r
- private boolean readToolDefinitionFile() {\r
-\r
- // Parse the tool definition file looking for targets and architectures\r
- toolsConfFile = null;\r
- boolean buildTargetsExist = true;\r
-\r
- if (targetLines[toolDefFileId] != null) {\r
- String[] result = new String[2];\r
- targetLines[toolDefFileId].trim();\r
- result = (targetLines[toolDefFileId]).split("=");\r
- String resString = (Tools.convertPathToCurrentOsType(result[1])).trim();\r
- toolsConfFile = workspaceDir.trim() + resString.trim();\r
- File toolsDefFile = new File(toolsConfFile);\r
- if (!toolsDefFile.exists()) {\r
- JOptionPane.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile\r
- + "<br>specified in the target.txt file does not exist!"\r
- + "<br>Using the default Tool Definition File:<br>"\r
- + defaultToolsConf);\r
- toolsConfFile = defaultToolsConf;\r
- }\r
- } else {\r
- toolsConfFile = defaultToolsConf;\r
- }\r
- String[] toolsDefFields = new String[toolDefFieldCount];\r
- for (int i = 0; i < toolDefFieldCount; i++)\r
- toolsDefFields[i] = null;\r
- File toolDefFile = new File(toolsConfFile);\r
- if (toolDefFile.exists()) {\r
- try {\r
- FileReader fileReader = new FileReader(toolDefFile);\r
- BufferedReader reader = new BufferedReader(fileReader);\r
- String rLine = null;\r
- String result[];\r
- int lineCounter = 0;\r
- while ((rLine = reader.readLine()) != null) {\r
-\r
- if (rLine.startsWith("IDENTIFIER")) {\r
- result = rLine.split("=");\r
- toolsDefIdentifier = (result[1]).trim();\r
- } else if ((!rLine.startsWith("#")) && (rLine.contains("="))) {\r
- result = rLine.split("=");\r
- toolsDefFields = ((result[0]).trim()).split("_");\r
- if (toolsDefTargetNames == null) {\r
- toolsDefTargetNames = (toolsDefFields[toolsDefTargetNameField]).trim() + " ";\r
- } else if (!toolsDefTargetNames.contains((toolsDefFields[toolsDefTargetNameField]).trim())) {\r
- toolsDefTargetNames += (toolsDefFields[toolsDefTargetNameField]).trim() + " ";\r
- }\r
- if (toolsDefTagNames == null) {\r
- toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).trim() + " ";\r
- } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).trim())) {\r
- toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).trim() + " ";\r
- }\r
- if (toolsDefArchNames == null) {\r
- toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).trim() + " ";\r
- } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).trim())) {\r
- toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).trim() + " ";\r
- }\r
- }\r
- lineCounter++;\r
- }\r
- reader.close();\r
- // Only enable Architecture selection based on tool chain installations\r
- String turnOff = "";\r
- if (!toolsDefArchNames.contains("EBC"))\r
- turnOff = "EBC ";\r
- if (!toolsDefArchNames.contains("PPC"))\r
- turnOff += "PPC ";\r
- if (!toolsDefArchNames.contains("IPF"))\r
- turnOff += "IPF ";\r
- if (!toolsDefArchNames.contains("X64"))\r
- turnOff += "X64 ";\r
- if (!toolsDefArchNames.contains("IA32"))\r
- turnOff += "X64 ";\r
- if (!toolsDefArchNames.contains("ARM"))\r
- turnOff += "ARM ";\r
- turnOff = turnOff.trim();\r
- vDisableArchList = stringToVector(turnOff);\r
-\r
- if (!toolsDefTargetNames.matches("[A-Z]+")) {\r
- toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();\r
- if (Debug)\r
- System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames\r
- + "'");\r
- buildTargetsExist = false;\r
- }\r
- } catch (IOException e) {\r
- Log.log(toolsConfFile + " Read Error ", e.getMessage());\r
- e.printStackTrace();\r
- }\r
- }\r
- return buildTargetsExist;\r
- }\r
-\r
- private void readTargetTxtFile() {\r
- File tFile = new File(targetFile);\r
-\r
- if (tFile.exists()) {\r
- try {\r
- FileReader fileReader = new FileReader(targetFile);\r
- BufferedReader reader = new BufferedReader(fileReader);\r
- targetLineNumberMax = 0;\r
- String rLine = null;\r
- while ((rLine = reader.readLine()) != null) {\r
- targetFileContents[targetLineNumberMax] = rLine;\r
- if (rLine.startsWith("ACTIVE_PLATFORM")) {\r
- // Only one active platform is permitted!\r
- targetLines[activePlatformId] = rLine;\r
- targetLineNumber[activePlatformId] = targetLineNumberMax;\r
- }\r
- if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t"))\r
- || (rLine.startsWith("TARGET="))) {\r
- // Handle multiple Target Names\r
- if (rLine.contains(","))\r
- targetLines[buildTargetId] = rLine.trim().replaceAll(",", " ");\r
- else\r
- targetLines[buildTargetId] = rLine.trim();\r
- targetLineNumber[buildTargetId] = targetLineNumberMax;\r
- }\r
- if (rLine.startsWith("TARGET_ARCH")) {\r
- // Handle multiple Target Architectures\r
- if (rLine.contains(","))\r
- targetLines[targetArchId] = rLine.trim().replaceAll(",", " ");\r
- else\r
- targetLines[targetArchId] = rLine.trim();\r
- targetLineNumber[targetArchId] = targetLineNumberMax;\r
- }\r
- if (rLine.startsWith("TOOL_CHAIN_CONF")) {\r
- // Only one file is permitted\r
- targetLines[toolDefFileId] = rLine.trim();\r
- targetLineNumber[toolDefFileId] = targetLineNumberMax;\r
- }\r
-\r
- if (rLine.startsWith("TOOL_CHAIN_TAG")) {\r
- // Handle multiple Tool TagNames\r
- if (rLine.contains(","))\r
- targetLines[tagNameId] = rLine.trim().replaceAll(",", " ");\r
- else\r
- targetLines[tagNameId] = rLine.trim();\r
- targetLineNumber[tagNameId] = targetLineNumberMax;\r
- }\r
- \r
- if (rLine.startsWith("MULTIPLE_THREAD")) {\r
- // Handle Thread Enable flag\r
- targetLines[threadEnableId] = rLine.trim();\r
- targetLineNumber[threadEnableId] = targetLineNumberMax;\r
- if ((rLine.trim().toLowerCase().contains("enabled")) || (rLine.trim().toLowerCase().contains("true"))) { \r
- threadEnabled = true;\r
- } else {\r
- threadEnabled = false;\r
- }\r
- }\r
- \r
- if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {\r
- // Handle Thread Enable flag\r
- targetLines[threadCountId] = rLine.trim();\r
- targetLineNumber[threadCountId] = targetLineNumberMax;\r
- }\r
- targetLineNumberMax++;\r
- }\r
- reader.close();\r
- String archLine[] = new String[2];\r
- if (targetLines[targetArchId] != null) {\r
- if (targetLines[targetArchId].contains("=")) {\r
- if (targetLines[targetArchId].contains(","))\r
- targetLines[targetArchId] = targetLines[targetArchId].trim().replaceAll(",", " ");\r
- if (targetLines[targetArchId].length() > 0)\r
- archLine = targetLines[targetArchId].trim().split("=");\r
- vArchList = stringToVector(archLine[1]);\r
- }\r
- }\r
-\r
- if (targetLines[threadCountId] != null) {\r
- String tcLine[] = new String[2];\r
- tcLine = targetLines[threadCountId].trim().split("=");\r
- threadCount = tcLine[1];\r
- } else\r
- threadCount = "";\r
- \r
- if (Debug == true)\r
- for (int i = 0; i <= maxTargetLines; i++)\r
- System.out.println("targetLines[" + i + "] contains: " + targetLines[i] + " index is: "\r
- + targetLineNumber[i]);\r
- } catch (IOException e) {\r
- Log.log(this.targetFile + " Read Error ", e.getMessage());\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- }\r
-\r
- /**\r
- * This method initializes jContentPane\r
- * \r
- * @return javax.swing.JPanel jContentPane\r
- * \r
- */\r
- private JPanel getJContentPane() {\r
- if (jContentPane == null) {\r
- jLabelToolsConfigFile = new JLabel();\r
- jLabelToolsConfigFile.setBounds(new java.awt.Rectangle(labelColumn, toolConfigFileRow, labelWidth,\r
- oneRowHeight));\r
- jLabelToolsConfigFile.setText("Tool Chain Definition File");\r
- jLabelActivePlatform = new JLabel();\r
- jLabelActivePlatform.setText("Select Active Platform");\r
- jLabelActivePlatform.setBounds(new java.awt.Rectangle(labelColumn, activePlatformRow, labelWidth,\r
- oneRowHeight));\r
- jLabelToolChainTagName = new JLabel();\r
- jLabelToolChainTagName.setBounds(new java.awt.Rectangle(labelColumn, toolChainTagNameRow, labelWidth,\r
- oneRowHeight));\r
- jLabelToolChainTagName.setText("Select Tool Tag Name");\r
- jLabelBuildTarget = new JLabel();\r
- jLabelBuildTarget.setBounds(new java.awt.Rectangle(labelColumn, buildTargetRow, labelWidth, oneRowHeight));\r
- jLabelBuildTarget.setText("Select Build Target");\r
- jLabelTargetArch = new JLabel();\r
- jLabelTargetArch.setBounds(new java.awt.Rectangle(labelColumn, targetArchRow, labelWidth, oneRowHeight));\r
- jLabelTargetArch.setText("Build Architectures");\r
-\r
- jArchCheckBox = new ArchCheckBox();\r
- jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));\r
- jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));\r
-\r
- jLabelEnableThreads = new JLabel();\r
- jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));\r
- jLabelEnableThreads.setText("Enable Compiler Threading");\r
-\r
- jLabelThreadCount = new JLabel();\r
- jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));\r
- jLabelThreadCount.setText("Number of threads to start");\r
-\r
- jContentPane = new JPanel();\r
- jContentPane.setLayout(null);\r
- jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));\r
-\r
- jContentPane.add(jLabelToolsConfigFile, null);\r
- jContentPane.add(getJTextFieldToolsConfigFile(), null);\r
- jContentPane.add(getJButtonBrowse(), null);\r
-\r
- jContentPane.add(jLabelActivePlatform, null);\r
- jContentPane.add(getActivePlatform(), null);\r
-\r
- jContentPane.add(jLabelToolChainTagName, null);\r
- jContentPane.add(getJScrollPaneTagName(), null);\r
-\r
- jContentPane.add(jLabelBuildTarget, null);\r
- jContentPane.add(getJScrollPaneBuildTarget(), null);\r
-\r
- jContentPane.add(jLabelTargetArch, null);\r
-\r
- jArchCheckBox.setDisabledItems(vDisableArchList);\r
- jArchCheckBox.setSelectedItems(vArchList);\r
- jContentPane.add(jArchCheckBox, null);\r
-\r
- jContentPane.add(jLabelEnableThreads, null);\r
- jContentPane.add(getCheckBoxEnableThreads(), null);\r
-\r
- jContentPane.add(jLabelThreadCount, null);\r
- jContentPane.add(getTextFieldThreadCount(), null);\r
-\r
- jContentPane.add(getJButtonSave(), null);\r
- jContentPane.add(getJButtonCancel(), null);\r
- }\r
- return jContentPane;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
- * \r
- * Override actionPerformed to listen all actions\r
- * \r
- */\r
- public void actionPerformed(ActionEvent arg0) {\r
-\r
- if (arg0.getSource() == jButtonBrowse) {\r
- // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory\r
-\r
- }\r
-\r
- if (arg0.getSource() == jButtonSave) {\r
- saveTargetFile();\r
- JOptionPane.showMessageDialog(this, "<html>The target.txt file has been saved!"\r
- + "<br>A copy of the original file, target.txt.bak has"\r
- + "<br>also been created.</html>");\r
- this.exit();\r
- }\r
-\r
- if (arg0.getSource() == jButtonCancel) {\r
- this.exit();\r
- }\r
- \r
- if (arg0.getSource() == jCheckBoxEnableThreads) {\r
- if (jCheckBoxEnableThreads.isSelected() == false) {\r
- threadCount = "";\r
- jTextFieldThreadCount.setText(threadCount);\r
- }\r
- }\r
- }\r
- \r
-\r
- private void updateActivePlatform() {\r
- int lineAP;\r
- if (targetLines[activePlatformId] != null) {\r
- lineAP = targetLineNumber[activePlatformId];\r
- } else {\r
- lineAP = targetLineNumberMax;\r
- targetLineNumber[activePlatformId] = lineAP;\r
- targetLineNumberMax++;\r
- }\r
- if (jComboBoxActivePlatform.getSelectedItem() == "Do Not Set") {\r
- targetFileContents[lineAP] = "";\r
- targetLines[activePlatformId] = "";\r
- } else {\r
- targetFileContents[lineAP] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform.getSelectedItem() + "\r\n";\r
- targetLines[activePlatformId] = targetFileContents[lineAP];\r
- }\r
- if (Debug)\r
- System.out.println("Active Platform: " + targetFileContents[lineAP]);\r
- }\r
-\r
- private void updateToolDefFile() {\r
- int lineTDF;\r
- if (targetLines[toolDefFileId] != null) {\r
- lineTDF = targetLineNumber[toolDefFileId];\r
- } else {\r
- lineTDF = targetLineNumberMax;\r
- targetLineNumber[toolDefFileId] = lineTDF;\r
- targetLineNumberMax++;\r
- }\r
- if (Debug)\r
- System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());\r
- if (jTextFieldToolsConfigFile.getText() == null) {\r
- targetFileContents[lineTDF] = "#MT#";\r
- targetLines[toolDefFileId] = "";\r
- } else {\r
- targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();\r
- targetLines[toolDefFileId] = targetFileContents[lineTDF];\r
- }\r
- }\r
-\r
- private void updateToolTagNames() {\r
- String sTagNames = vectorToString(iCheckBoxListTagName.getAllCheckedItemsString());\r
- int lineTTN;\r
-\r
- if (targetLines[tagNameId] != null) {\r
- lineTTN = targetLineNumber[tagNameId];\r
- } else {\r
- lineTTN = targetLineNumberMax;\r
- targetLineNumber[tagNameId] = lineTTN;\r
- targetLineNumberMax++;\r
- }\r
-\r
- if (Debug)\r
- System.out.println("Tag Name(s): " + sTagNames);\r
-\r
- if (sTagNames.length() > 0) {\r
- targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;\r
- targetLines[tagNameId] = targetFileContents[lineTTN];\r
- } else {\r
- targetFileContents[lineTTN] = "#MT#";\r
- targetLines[tagNameId] = "";\r
- }\r
- }\r
-\r
- private void updateBuildTargets() {\r
- String sBuildTargets = vectorToString(iCheckBoxListBuildTarget.getAllCheckedItemsString());\r
- int lineBT;\r
-\r
- if (targetLines[buildTargetId] != null) {\r
- lineBT = targetLineNumber[buildTargetId];\r
- } else {\r
- lineBT = targetLineNumberMax;\r
- targetLineNumber[buildTargetId] = lineBT;\r
- targetLineNumberMax++;\r
- }\r
- if (Debug)\r
- System.out.println("Build Target(s): " + sBuildTargets);\r
- if (sBuildTargets.length() > 0) {\r
- targetFileContents[lineBT] = "TARGET = " + sBuildTargets;\r
- targetLines[buildTargetId] = targetFileContents[lineBT];\r
- } else {\r
- targetFileContents[lineBT] = "#MT#";\r
- targetLines[buildTargetId] = "";\r
- }\r
-\r
- }\r
-\r
- private void updateArchitectures() {\r
- String sArchList = jArchCheckBox.getSelectedItemsString().trim();\r
-\r
- if (Debug)\r
- System.out.println("Architectures: " + sArchList);\r
-\r
- int lineSA;\r
- if (targetLines[targetArchId] != null) {\r
- lineSA = targetLineNumber[targetArchId];\r
- } else {\r
- lineSA = targetLineNumberMax;\r
- targetLineNumber[targetArchId] = lineSA;\r
- targetLineNumberMax++;\r
- }\r
- if (sArchList == "") {\r
- targetFileContents[lineSA] = "#MT#";\r
- targetLines[targetArchId] = "";\r
- } else {\r
- targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;\r
- targetLines[targetArchId] = targetFileContents[lineSA];\r
- }\r
-\r
- }\r
-\r
- private void updateEnableThreads() {\r
- int lineET;\r
- if (targetLines[threadEnableId] != null) {\r
- lineET = targetLineNumber[threadEnableId];\r
- } else {\r
- lineET = targetLineNumberMax;\r
- targetLineNumber[threadEnableId] = lineET;\r
- targetLineNumberMax++;\r
- }\r
- if (jCheckBoxEnableThreads.isSelected() == true) {\r
- targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";\r
- targetLines[threadEnableId] = targetFileContents[lineET];\r
- } else {\r
- targetFileContents[lineET] = "#MT#";\r
- targetLines[threadEnableId] = "";\r
- }\r
- }\r
- \r
- private void updateThreadCount() {\r
- int lineTC;\r
-\r
- if (targetLines[threadCountId] != null) {\r
- lineTC = targetLineNumber[threadCountId];\r
- } else {\r
- lineTC = targetLineNumberMax;\r
- targetLineNumber[threadCountId] = lineTC;\r
- targetLineNumberMax++;\r
- }\r
- if (jCheckBoxEnableThreads.isSelected() == true) {\r
- // Threading must be enabled\r
- if (jTextFieldThreadCount.getText().length() > 0) {\r
- // Thread Count must be greater than 0\r
- Scanner scan = new Scanner(jTextFieldThreadCount.getText().trim()); \r
- if (scan.nextInt() > 0) { \r
- targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount.getText().trim();\r
- targetLines[threadCountId] = targetFileContents[lineTC];\r
- } else {\r
- Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r
- targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
- targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
- }\r
- } else {\r
- Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r
- targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
- targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
- }\r
- } else {\r
- // Don't track threads if threading is not enabled\r
- targetFileContents[lineTC] = "#MT#";\r
- targetLines[threadCountId] = "";\r
- threadCount = "";\r
- }\r
- \r
- }\r
- private String vectorToString(Vector<String> v) {\r
- String s = " ";\r
- for (int i = 0; i < v.size(); ++i) {\r
- s += v.get(i);\r
- s += " ";\r
- }\r
- return s.trim();\r
- }\r
-\r
- protected Vector<String> stringToVector(String s) {\r
- if (s == null) {\r
- return null;\r
- }\r
- String[] sArray = s.split(" ");\r
- Vector<String> v = new Vector<String>();\r
- for (int i = 0; i < sArray.length; ++i) {\r
- v.add(sArray[i]);\r
- }\r
- return v;\r
- }\r
-\r
- private void saveTargetFile() {\r
- updateActivePlatform();\r
- updateToolDefFile();\r
- updateToolTagNames();\r
- updateBuildTargets();\r
- updateArchitectures();\r
- updateEnableThreads();\r
- updateThreadCount();\r
-\r
- try {\r
- copy(targetFile, targetFile + ".bak");\r
- FileWriter fileWriter = new FileWriter(targetFile);\r
- BufferedWriter writer = new BufferedWriter(fileWriter);\r
- for (int i = 0; i < targetLineNumberMax; i++) {\r
- if (! targetFileContents[i].contains("#MT#"))\r
- writer.write(targetFileContents[i] + "\n");\r
- }\r
- writer.close();\r
- } catch (IOException e) {\r
- Log.err(toolsConfFile + " Write Error ", e.getMessage());\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- private void copy(String txtFile, String bakFile) throws IOException {\r
- File fromFile = new File(txtFile);\r
- File toFile = new File(bakFile);\r
- FileInputStream fromTxt = null;\r
- FileOutputStream toBak = null;\r
- if (!fromFile.exists()) {\r
- fromFile.createNewFile();\r
- }\r
- try {\r
- fromTxt = new FileInputStream(fromFile);\r
- toBak = new FileOutputStream(toFile);\r
- byte[] buffer = new byte[4096];\r
- int bytes_read;\r
- while ((bytes_read = fromTxt.read(buffer)) != -1) {\r
- toBak.write(buffer, 0, bytes_read);\r
- }\r
- } finally {\r
- if (fromTxt != null)\r
- try {\r
- fromTxt.close();\r
- } catch (IOException e) {\r
- Log.err(toolsConfFile + " Read Error ", e.getMessage());\r
-\r
- }\r
- if (toBak != null)\r
- try {\r
- toBak.close();\r
- } catch (IOException e) {\r
- Log.err(toolsConfFile + ".bak Write Error ", e.getMessage());\r
- }\r
- }\r
- }\r
-\r
- private void exit() {\r
- this.setVisible(false);\r
- if (bTarget != null) {\r
- bTarget.dispose();\r
- }\r
- }\r
-}\r