/projects/netbeans-7.3/cnd.toolchain/src/org/netbeans/modules/cnd/toolchain/compilerset/ToolchainManagerImpl.java
Java | 1161 lines | 1060 code | 44 blank | 57 comment | 325 complexity | 291c2585bf4cc8dd6bbfddaf1912a254 MD5 | raw file
- /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- *
- * Contributor(s):
- *
- * Portions Copyrighted 2008 Sun Microsystems, Inc.
- */
- package org.netbeans.modules.cnd.toolchain.compilerset;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.MissingResourceException;
- import java.util.ResourceBundle;
- import java.util.Set;
- import java.util.TreeMap;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.netbeans.modules.cnd.api.toolchain.PlatformTypes;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.AlternativePath;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.BaseFolder;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.CMakeDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.CompilerDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.DebuggerDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.LinkerDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.MakeDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.PredefinedMacro;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.QMakeDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.ScannerDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.ScannerPattern;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.ToolDescriptor;
- import org.netbeans.modules.cnd.api.toolchain.ToolchainManager.ToolchainDescriptor;
- import org.openide.filesystems.FileLock;
- import org.openide.filesystems.FileObject;
- import org.openide.filesystems.FileUtil;
- import org.openide.util.Exceptions;
- import org.openide.util.NbBundle;
- import org.openide.util.NbPreferences;
- import org.openide.util.Utilities;
- import org.openide.xml.XMLUtil;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
- import org.xml.sax.XMLReader;
- import org.xml.sax.helpers.DefaultHandler;
- /**
- *
- * @author Alexander Simon
- */
- @SuppressWarnings({"PackageVisibleInnerClass","PackageVisibleField"})
- public final class ToolchainManagerImpl {
- private static final Logger LOG = Logger.getLogger(ToolchainManagerImpl.class.getName());
- public static final boolean TRACE = Boolean.getBoolean("cnd.toolchain.personality.trace"); // NOI18N
- private static final boolean CREATE_SHADOW = Boolean.getBoolean("cnd.toolchain.personality.create_shadow"); // NOI18N
- public static final String SHADOW_KEY = "toolchain_shadow"; // NOI18N
- public static final String ROOT_FOLDER = "CND"; // NOI18N
- public static final String SHADOW_FOLDER = "ToolChain"; // NOI18N
- public static final String TOOLCHAIN_FOLDER = "ToolChains"; // NOI18N
- public static final String TOOL_FOLDER = "Tool"; // NOI18N
- private static final ToolchainManagerImpl manager = new ToolchainManagerImpl();
- private List<ToolchainDescriptor> descriptors = new ArrayList<ToolchainDescriptor>();
- public static ToolchainManagerImpl getImpl() {
- return manager;
- }
- private ToolchainManagerImpl() {
- if (NbPreferences.forModule(ToolchainManagerImpl.class).getBoolean(SHADOW_KEY, false)) {
- initToolchainManager();
- } else {
- initToolchainManager2();
- }
- }
- private void initToolchainManager() {
- try {
- Map<Integer, CompilerVendor> vendors = new TreeMap<Integer, CompilerVendor>();
- Map<String, String> cache = new HashMap<String, String>();
- FileObject folder = FileUtil.getConfigFile(ROOT_FOLDER+"/"+SHADOW_FOLDER); // NOI18N
- int indefinedID = Integer.MAX_VALUE / 2;
- if (folder != null && folder.isFolder()) {
- FileObject[] files = folder.getChildren();
- for (FileObject file : files) {
- Integer position = (Integer) file.getAttribute("position"); // NOI18N
- if (position == null || vendors.containsKey(position)) {
- position = indefinedID++;
- }
- String displayName = (String) file.getAttribute("displayName"); // NOI18N
- CompilerVendor v = new CompilerVendor(file.getNameExt(), position.intValue());
- if (read(file, files, v, new HashSet<FileObject>(), cache)) {
- if (displayName != null && !displayName.isEmpty()) {
- v.toolChainDisplay = displayName;
- }
- vendors.put(position, v);
- }
- }
- }
- for (CompilerVendor v : vendors.values()) {
- descriptors.add(new ToolchainDescriptorImpl(v));
- }
- } catch (Throwable e) {
- e.printStackTrace(System.err);
- }
- if (CREATE_SHADOW && !NbPreferences.forModule(ToolchainManagerImpl.class).getBoolean(SHADOW_KEY, false)) {
- try {
- writeToolchains();
- NbPreferences.forModule(ToolchainManagerImpl.class).putBoolean(SHADOW_KEY, true);
- } catch (IOException ex) {
- ex.printStackTrace(System.err);
- }
- }
- }
- private void initToolchainManager2() {
- try {
- Map<Integer, CompilerVendor> vendors = new TreeMap<Integer, CompilerVendor>();
- Map<String, String> cache = new HashMap<String, String>();
- FileObject folder = FileUtil.getConfigFile(ROOT_FOLDER+"/"+TOOLCHAIN_FOLDER); // NOI18N
- FileObject[] files = FileUtil.getConfigFile(ROOT_FOLDER+"/"+TOOL_FOLDER).getChildren(); // NOI18N
- int indefinedID = Integer.MAX_VALUE / 2;
- if (folder != null && folder.isFolder()) {
- for (FileObject file : folder.getChildren()) {
- Integer position = (Integer) file.getAttribute("position"); // NOI18N
- if (position == null || vendors.containsKey(position)) {
- position = indefinedID++;
- }
- String displayName = null;
- String bundleName = (String)file.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
- if (bundleName != null) {
- try {
- bundleName = Utilities.translate(bundleName);
- ResourceBundle bundle = NbBundle.getBundle(bundleName);
- if (bundle != null) {
- displayName = bundle.getString(file.getPath());
- }
- } catch (MissingResourceException ex) {
- ex.printStackTrace(System.err);
- }
- }
- CompilerVendor v = new CompilerVendor(file.getNameExt()+".xml", position.intValue()); // NOI18N
- if (read2(file, files, v, cache)) {
- if (displayName != null && !displayName.isEmpty()) {
- v.toolChainDisplay = displayName;
- }
- vendors.put(position, v);
- }
- }
- }
- for (CompilerVendor v : vendors.values()) {
- descriptors.add(new ToolchainDescriptorImpl(v));
- }
- } catch (Throwable e) {
- e.printStackTrace(System.err);
- }
- if (CREATE_SHADOW && !NbPreferences.forModule(ToolchainManagerImpl.class).getBoolean(SHADOW_KEY, false)) {
- try {
- writeToolchains();
- NbPreferences.forModule(ToolchainManagerImpl.class).putBoolean(SHADOW_KEY, true);
- } catch (IOException ex) {
- ex.printStackTrace(System.err);
- }
- }
- }
- /**
- * available in package for testing only
- */
- public void reinitToolchainManager() {
- try {
- writeToolchains();
- NbPreferences.forModule(ToolchainManagerImpl.class).putBoolean(SHADOW_KEY, true);
- } catch (IOException ex) {
- ex.printStackTrace(System.err);
- }
- descriptors.clear();
- initToolchainManager();
- }
- public ToolchainDescriptor getToolchain(String name, int platform) {
- for (ToolchainDescriptor d : descriptors) {
- if (name.equals(d.getName()) && (ToolUtils.isPlatforSupported(platform, d)
- || ToolUtils.isPlatforSupported(PlatformTypes.PLATFORM_NONE, d))) {
- return d;
- }
- }
- for (ToolchainDescriptor d : descriptors) {
- if (ToolUtils.isPlatforSupported(PlatformTypes.PLATFORM_NONE, d)) {
- return d;
- }
- }
- return null;
- }
- public List<ToolchainDescriptor> getAllToolchains() {
- return new ArrayList<ToolchainDescriptor>(descriptors);
- }
- public List<ToolchainDescriptor> getToolchains(int platform) {
- List<ToolchainDescriptor> res = new ArrayList<ToolchainDescriptor>();
- for (ToolchainDescriptor d : descriptors) {
- if (ToolUtils.isPlatforSupported(platform, d)) {
- res.add(d);
- }
- }
- return res;
- }
- private boolean read(FileObject file, FileObject[] files, CompilerVendor v, Set<FileObject> antiloop, Map<String, String> cache) {
- if (antiloop.contains(file)) {
- LOG.log(Level.INFO, "Recursive inclusion of file {0}", file.getNameExt()); // NOI18N
- return false;
- }
- antiloop.add(file);
- String originalFile = (String) file.getAttribute("originalFile"); // NOI18N
- if (originalFile != null) {
- file = FileUtil.getConfigFile(originalFile);
- }
- String baseName = (String) file.getAttribute("extends"); // NOI18N
- if (baseName != null && baseName.length() > 0) {
- boolean find = false;
- for (FileObject base : files) {
- if (baseName.equals(base.getNameExt())) {
- if (!read(base, files, v, antiloop, cache)) {
- LOG.log(Level.INFO, "Cannot read base file {0}", base.getNameExt()); // NOI18N
- return false;
- }
- find = true;
- }
- }
- if (!find) {
- LOG.log(Level.INFO, "Cannot find base file {0}", baseName); // NOI18N
- }
- }
- try {
- read(file.getInputStream(), v, cache);
- return true;
- } catch (IOException ex) {
- ex.printStackTrace(System.err);
- }
- return false;
- }
- private boolean read2(FileObject file, FileObject[] files, CompilerVendor v, Map<String, String> cache) {
- for (FileObject fo : file.getChildren()){
- read(fo, files, v, new HashSet<FileObject>(), cache);
- }
- return true;
- }
- private boolean read(InputStream inputStream, CompilerVendor v, Map<String, String> cache) {
- SAXParserFactory spf = SAXParserFactory.newInstance();
- spf.setValidating(false);
- XMLReader xmlReader;
- try {
- SAXParser saxParser = spf.newSAXParser();
- xmlReader = saxParser.getXMLReader();
- } catch (Exception ex) {
- ex.printStackTrace(System.err);
- return false;
- }
- SAXHandler handler = new SAXHandler(v, cache);
- xmlReader.setContentHandler(handler);
- try {
- InputSource source = new InputSource(inputStream);
- xmlReader.parse(source);
- } catch (Exception ex) {
- ex.printStackTrace(System.err);
- return false;
- }
- return true;
- }
- private String unsplit(String[] array) {
- if (array == null) {
- return ""; // NOI18N
- }
- StringBuilder buf = new StringBuilder();
- for (String s : array) {
- if (buf.length() > 0) {
- buf.append(',');
- }
- buf.append(s);
- }
- return buf.toString();
- }
- /**
- * available in package for testing only
- */
- /*test*/public void writeToolchains() throws IOException {
- FileObject folder = FileUtil.getConfigFile(ROOT_FOLDER);
- FileObject shadow = folder.getFileObject(SHADOW_FOLDER);
- if (shadow == null) {
- shadow = folder.createFolder(SHADOW_FOLDER);
- }
- if (shadow != null && shadow.isFolder()) {
- for (ToolchainDescriptor descriptor : descriptors) {
- String name = descriptor.getFileName();
- FileObject file = shadow.getFileObject(name);
- if (file == null) {
- file = shadow.createData(name);
- }
- writeDescriptor(descriptor, file);
- ToolchainDescriptorImpl impl = (ToolchainDescriptorImpl) descriptor;
- file.setAttribute("position", Integer.valueOf(impl.v.position)); // NOI18N
- file.setAttribute("extends", ""); // NOI18N
- file.setAttribute("displayName", impl.v.toolChainDisplay); // NOI18N
- }
- }
- }
- private void writeDescriptor(ToolchainDescriptor descriptor, FileObject file) throws DOMException {
- //System.err.println("Found file " + file.getNameExt()); // NOI18N
- Document doc = XMLUtil.createDocument("toolchaindefinition", "http://www.netbeans.org/ns/cnd-toolchain-definition/1", null, null); // NOI18N
- Element root = doc.getDocumentElement();
- Element element;
- element = doc.createElement("toolchain"); // NOI18N
- element.setAttribute("name", descriptor.getName()); // NOI18N
- element.setAttribute("display", descriptor.getDisplayName()); // NOI18N
- element.setAttribute("family", unsplit(descriptor.getFamily())); // NOI18N
- if (descriptor.getQmakeSpec() != null) {
- element.setAttribute("qmakespec", descriptor.getQmakeSpec()); // NOI18N
- }
- if (descriptor.isAbstract()) {
- element.setAttribute("abstract", "true"); // NOI18N
- }
- if (!descriptor.isAutoDetected()) {
- element.setAttribute("auto_detected", "false"); // NOI18N
- }
- if (descriptor.getAliases().length > 0) {
- element.setAttribute("aliases", unsplit(descriptor.getAliases())); // NOI18N
- }
- if (descriptor.getSubsitute() != null) {
- element.setAttribute("subtitute", descriptor.getSubsitute()); // NOI18N
- }
- root.appendChild(element);
- if (descriptor.getUpdateCenterUrl() != null && descriptor.getModuleID() != null) {
- element = doc.createElement("download"); // NOI18N
- element.setAttribute("uc_url", descriptor.getUpdateCenterUrl()); // NOI18N
- element.setAttribute("module_id", descriptor.getModuleID()); // NOI18N
- element.setAttribute("uc_display", descriptor.getUpdateCenterDisplayName()); // NOI18N
- element.setAttribute("upgrade_url", descriptor.getUpgradeUrl()); // NOI18N
- root.appendChild(element);
- }
- element = doc.createElement("platforms"); // NOI18N
- element.setAttribute("stringvalue", unsplit(descriptor.getPlatforms())); // NOI18N
- root.appendChild(element);
- if (descriptor.getDriveLetterPrefix() != null) {
- element = doc.createElement("drive_letter_prefix"); // NOI18N
- element.setAttribute("stringvalue", descriptor.getDriveLetterPrefix()); // NOI18N
- root.appendChild(element);
- }
- if (descriptor.getMakefileWriter() != null) {
- element = doc.createElement("makefile_writer"); // NOI18N
- element.setAttribute("class", descriptor.getMakefileWriter()); // NOI18N
- root.appendChild(element);
- }
- if (descriptor.getBaseFolders() != null) {
- element = doc.createElement("base_folders"); // NOI18N
- root.appendChild(element);
- for (BaseFolder info : descriptor.getBaseFolders()) {
- Element p = doc.createElement("base_folder"); // NOI18N
- if (info.getFolderKey() != null) {
- p.setAttribute("regestry", info.getFolderKey()); // NOI18N
- }
- if (info.getFolderPattern() != null) {
- p.setAttribute("pattern", info.getFolderPattern()); // NOI18N
- }
- if (info.getFolderPathPattern() != null) {
- p.setAttribute("path_patern", info.getFolderPathPattern()); // NOI18N
- }
- if (info.getFolderSuffix() != null) {
- p.setAttribute("suffix", info.getFolderSuffix()); // NOI18N
- }
- element.appendChild(p);
- }
- }
- if (descriptor.getCommandFolders() != null) {
- element = doc.createElement("command_folders"); // NOI18N
- root.appendChild(element);
- for (BaseFolder info : descriptor.getCommandFolders()) {
- Element p = doc.createElement("command_folder"); // NOI18N
- if (info.getFolderKey() != null) {
- p.setAttribute("regestry", info.getFolderKey()); // NOI18N
- }
- if (info.getFolderPattern() != null) {
- p.setAttribute("pattern", info.getFolderPattern()); // NOI18N
- }
- if (info.getFolderPathPattern() != null) {
- p.setAttribute("path_patern", info.getFolderPathPattern()); // NOI18N
- }
- if (info.getFolderSuffix() != null) {
- p.setAttribute("suffix", info.getFolderSuffix()); // NOI18N
- }
- element.appendChild(p);
- }
- }
- if (descriptor.getDefaultLocations() != null) {
- element = doc.createElement("default_locations"); // NOI18N
- root.appendChild(element);
- for (Map.Entry<String, List<String>> e : descriptor.getDefaultLocations().entrySet()) {
- for (String st : e.getValue()) {
- Element p = doc.createElement("platform"); // NOI18N
- p.setAttribute("os", e.getKey()); // NOI18N
- p.setAttribute("directory", st); // NOI18N
- element.appendChild(p);
- }
- }
- }
- CompilerDescriptor compiler;
- compiler = descriptor.getC();
- if (compiler != null) {
- element = doc.createElement("c"); // NOI18N
- writeCompiler(doc, element, compiler);
- root.appendChild(element);
- }
- compiler = descriptor.getCpp();
- if (compiler != null) {
- element = doc.createElement("cpp"); // NOI18N
- writeCompiler(doc, element, compiler);
- root.appendChild(element);
- }
- compiler = descriptor.getFortran();
- if (compiler != null) {
- element = doc.createElement("fortran"); // NOI18N
- writeCompiler(doc, element, compiler);
- root.appendChild(element);
- }
- compiler = descriptor.getAssembler();
- if (compiler != null) {
- element = doc.createElement("assembler"); // NOI18N
- writeCompiler(doc, element, compiler);
- root.appendChild(element);
- }
- ScannerDescriptor scanner = descriptor.getScanner();
- if (scanner != null) {
- element = doc.createElement("scanner"); // NOI18N
- element.setAttribute("id", scanner.getID()); // NOI18N
- writeScanner(doc, element, scanner);
- root.appendChild(element);
- }
- LinkerDescriptor linker = descriptor.getLinker();
- if (linker != null) {
- element = doc.createElement("linker"); // NOI18N
- writeLinker(doc, element, linker);
- root.appendChild(element);
- }
- MakeDescriptor make = descriptor.getMake();
- if (make != null) {
- element = doc.createElement("make"); // NOI18N
- writeMake(doc, element, make);
- root.appendChild(element);
- }
- DebuggerDescriptor debugger = descriptor.getDebugger();
- if (debugger != null) {
- element = doc.createElement("debugger"); // NOI18N
- element.setAttribute("id", debugger.getID()); // NOI18N
- writeDebugger(doc, element, debugger);
- root.appendChild(element);
- }
- QMakeDescriptor qmake = descriptor.getQMake();
- if (qmake != null) {
- element = doc.createElement("qmake"); // NOI18N
- writeQMake(doc, element, qmake);
- root.appendChild(element);
- }
- CMakeDescriptor cmake = descriptor.getCMake();
- if (cmake != null) {
- element = doc.createElement("cmake"); // NOI18N
- writeCMake(doc, element, cmake);
- root.appendChild(element);
- }
- try {
- FileLock lock = file.lock();
- try {
- OutputStream os = file.getOutputStream(lock);
- try {
- XMLUtil.write(doc, os, "UTF-8"); // NOI18N
- } finally {
- os.close();
- }
- } finally {
- lock.releaseLock();
- }
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- private void writeCompiler(Document doc, Element element, CompilerDescriptor compiler) {
- Element e;
- e = doc.createElement("compiler"); // NOI18N
- e.setAttribute("name", unsplit(compiler.getNames())); // NOI18N
- if (compiler.skipSearch()) {
- e.setAttribute("skip", "true"); // NOI18N
- }
- element.appendChild(e);
- if (compiler.getPathPattern() != null ||
- compiler.getExistFolder() != null) {
- e = doc.createElement("recognizer"); // NOI18N
- if (compiler.getPathPattern() != null) {
- e.setAttribute("pattern", compiler.getPathPattern()); // NOI18N
- }
- if (compiler.getExistFolder() != null) {
- e.setAttribute("or_exist_folder", compiler.getExistFolder()); // NOI18N
- }
- element.appendChild(e);
- }
- if (compiler.getVersionFlags() != null ||
- compiler.getVersionPattern() != null) {
- e = doc.createElement("version"); // NOI18N
- if (compiler.getVersionFlags() != null) {
- e.setAttribute("flags", compiler.getVersionFlags()); // NOI18N
- }
- if (compiler.getVersionPattern() != null) {
- e.setAttribute("pattern", compiler.getVersionPattern()); // NOI18N
- }
- if (compiler.getFingerPrintFlags() != null) {
- e.setAttribute("fingerprint_flags", compiler.getFingerPrintFlags()); // NOI18N
- }
- if (compiler.getFingerPrintPattern() != null) {
- e.setAttribute("fingerprint_pattern", compiler.getFingerPrintPattern()); // NOI18N
- }
- element.appendChild(e);
- }
- writeAlternativePath(doc, element, compiler);
- if (compiler.getIncludeFlags() != null ||
- compiler.getIncludeParser() != null ||
- compiler.getRemoveIncludePathPrefix() != null ||
- compiler.getRemoveIncludeOutputPrefix() != null) {
- e = doc.createElement("system_include_paths"); // NOI18N
- if (compiler.getIncludeFlags() != null) {
- e.setAttribute("flags", compiler.getIncludeFlags()); // NOI18N
- }
- if (compiler.getIncludeParser() != null) {
- e.setAttribute("parser", compiler.getIncludeParser()); // NOI18N
- }
- if (compiler.getRemoveIncludePathPrefix() != null) {
- e.setAttribute("remove_in_path", compiler.getRemoveIncludePathPrefix()); // NOI18N
- }
- if (compiler.getRemoveIncludeOutputPrefix() != null) {
- e.setAttribute("remove_in_output", compiler.getRemoveIncludeOutputPrefix()); // NOI18N
- }
- element.appendChild(e);
- }
- if (compiler.getMacroFlags() != null ||
- compiler.getMacroParser() != null ||
- compiler.getPredefinedMacros() != null) {
- e = doc.createElement("system_macros"); // NOI18N
- if (compiler.getMacroFlags() != null) {
- e.setAttribute("flags", compiler.getMacroFlags()); // NOI18N
- }
- if (compiler.getMacroParser() != null) {
- e.setAttribute("parser", compiler.getMacroParser()); // NOI18N
- }
- element.appendChild(e);
- if (compiler.getPredefinedMacros() != null) {
- for(PredefinedMacro p : compiler.getPredefinedMacros()){
- Element ee = doc.createElement("macro"); // NOI18N
- ee.setAttribute("stringvalue", p.getMacro()); // NOI18N
- if (p.getFlags() != null) {
- ee.setAttribute("flags", p.getFlags()); // NOI18N
- }
- if (p.isHidden()) {
- ee.setAttribute("hide", "true"); // NOI18N
- }
- e.appendChild(ee);
- }
- }
- }
- if (compiler.getUserIncludeFlag() != null) {
- e = doc.createElement("user_include"); // NOI18N
- e.setAttribute("flags", compiler.getUserIncludeFlag()); // NOI18N
- element.appendChild(e);
- }
- if (compiler.getUserMacroFlag() != null) {
- e = doc.createElement("user_macro"); // NOI18N
- e.setAttribute("flags", compiler.getUserMacroFlag()); // NOI18N
- element.appendChild(e);
- }
- writeDevelopmentMode(doc, element, compiler);
- writeWarningLevel(doc, element, compiler);
- writeArchitecture(doc, element, compiler);
- if (compiler.getStripFlag() != null) {
- e = doc.createElement("strip"); // NOI18N
- e.setAttribute("flags", compiler.getStripFlag()); // NOI18N
- element.appendChild(e);
- }
- writeMultithreading(doc, element, compiler);
- writeStandard(doc, element, compiler);
- writeLanguageExtension(doc, element, compiler);
- writeCppStandard(doc, element, compiler);
- writeCStandard(doc, element, compiler);
- writeLibrary(doc, element, compiler);
- if (compiler.getOutputObjectFileFlags() != null) {
- e = doc.createElement("output_object_file"); // NOI18N
- e.setAttribute("flags", compiler.getOutputObjectFileFlags()); // NOI18N
- element.appendChild(e);
- }
- if (compiler.getDependencyGenerationFlags() != null) {
- e = doc.createElement("dependency_generation"); // NOI18N
- e.setAttribute("flags", compiler.getDependencyGenerationFlags()); // NOI18N
- element.appendChild(e);
- }
- if (compiler.getPrecompiledHeaderFlags() != null ||
- compiler.getPrecompiledHeaderSuffix() != null) {
- e = doc.createElement("precompiled_header"); // NOI18N
- if (compiler.getPrecompiledHeaderFlags() != null) {
- e.setAttribute("flags", compiler.getPrecompiledHeaderFlags()); // NOI18N
- }
- if (compiler.getPrecompiledHeaderSuffix() != null) {
- e.setAttribute("suffix", compiler.getPrecompiledHeaderSuffix()); // NOI18N
- }
- if (compiler.getPrecompiledHeaderSuffixAppend()) {
- e.setAttribute("append", "true"); // NOI18N
- }
- element.appendChild(e);
- }
- }
- private void writeDevelopmentMode(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getDevelopmentModeFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.developmentMode.default_selection;
- }
- Element e = doc.createElement("development_mode"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"fast_build", "debug", "performance_debug", // NOI18N
- "test_coverage", "diagnosable_release", "release", // NOI18N
- "performance_release"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeWarningLevel(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getWarningLevelFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.warningLevel.default_selection;
- }
- Element e = doc.createElement("warning_level"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"no_warnings", "default", "more_warnings", // NOI18N
- "warning2error"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeArchitecture(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getArchitectureFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.architecture.default_selection;
- }
- Element e = doc.createElement("architecture"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"default", "bits_32", "bits_64"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeMultithreading(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getMultithreadingFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.multithreading.default_selection;
- }
- Element e = doc.createElement("multithreading"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"none", "safe", "automatic", "open_mp"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeStandard(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getStandardFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.standard.default_selection;
- }
- Element e = doc.createElement("standard"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"old", "legacy", "default", "modern"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeLanguageExtension(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getLanguageExtensionFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.languageExtension.default_selection;
- }
- Element e = doc.createElement("language_extension"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"none", "default", "all"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeCppStandard(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getCppStandardFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.cppStandard.default_selection;
- }
- Element e = doc.createElement("cpp_standard"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"default", "cpp98", "cpp11"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeCStandard(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getCStandardFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.cStandard.default_selection;
- }
- Element e = doc.createElement("c_standard"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"default", "c89", "c99"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeLibrary(Document doc, Element element, CompilerDescriptor compiler) {
- String[] flags = compiler.getLibraryFlags();
- if (flags == null) {
- return;
- }
- int def = 0;
- if (compiler instanceof CompilerDescriptorImpl) {
- def = ((CompilerDescriptorImpl) compiler).tool.library.default_selection;
- }
- Element e = doc.createElement("library"); // NOI18N
- element.appendChild(e);
- Element c;
- String[] names = new String[]{"none", "runtime", "classic", // NOI18N
- "binary_standard", "conforming_standard"}; // NOI18N
- for (int i = 0; i < flags.length; i++) {
- c = doc.createElement(names[i]);
- c.setAttribute("flags", flags[i]); // NOI18N
- if (def == i) {
- c.setAttribute("default", "true"); // NOI18N
- }
- e.appendChild(c);
- }
- }
- private void writeScanner(Document doc, Element element, ScannerDescriptor scanner) {
- Element c;
- for (ScannerPattern pattern : scanner.getPatterns()) {
- c = doc.createElement("error"); // NOI18N
- c.setAttribute("pattern", pattern.getPattern()); // NOI18N
- if (pattern.getSeverity() != null) {
- c.setAttribute("severity", pattern.getSeverity()); // NOI18N
- }
- if (pattern.getLanguage() != null) {
- c.setAttribute("language", pattern.getLanguage()); // NOI18N
- }
- element.appendChild(c);
- }
- if (scanner.getStackHeaderPattern() != null) {
- c = doc.createElement("stack_header"); // NOI18N
- c.setAttribute("pattern", scanner.getStackHeaderPattern()); // NOI18N
- element.appendChild(c);
- }
- if (scanner.getStackNextPattern() != null) {
- c = doc.createElement("stack_next"); // NOI18N
- c.setAttribute("pattern", scanner.getStackNextPattern()); // NOI18N
- element.appendChild(c);
- }
- if (scanner.getEnterDirectoryPattern() != null) {
- c = doc.createElement("enter_directory"); // NOI18N
- c.setAttribute("pattern", scanner.getEnterDirectoryPattern()); // NOI18N
- element.appendChild(c);
- }
- if (scanner.getChangeDirectoryPattern() != null) {
- c = doc.createElement("change_directory"); // NOI18N
- c.setAttribute("pattern", scanner.getChangeDirectoryPattern()); // NOI18N
- element.appendChild(c);
- }
- if (scanner.getMakeAllInDirectoryPattern() != null) {
- c = doc.createElement("making_all_in_directory"); // NOI18N
- c.setAttribute("pattern", scanner.getMakeAllInDirectoryPattern()); // NOI18N
- element.appendChild(c);
- }
- if (scanner.getLeaveDirectoryPattern() != null) {
- c = doc.createElement("leave_directory"); // NOI18N
- c.setAttribute("pattern", scanner.getLeaveDirectoryPattern()); // NOI18N
- element.appendChild(c);
- }
- for (String pattern : scanner.getFilterOutPatterns()) {
- c = doc.createElement("filter_out"); // NOI18N
- c.setAttribute("pattern", pattern); // NOI18N
- element.appendChild(c);
- }
- }
- private void writeLinker(Document doc, Element element, LinkerDescriptor linker) {
- Element c;
- if (linker.getLibraryPrefix() != null) {
- c = doc.createElement("library_prefix"); // NOI18N
- c.setAttribute("stringvalue", linker.getLibraryPrefix()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getLibrarySearchFlag() != null) {
- c = doc.createElement("library_search"); // NOI18N
- c.setAttribute("flags", linker.getLibrarySearchFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getDynamicLibrarySearchFlag() != null) {
- c = doc.createElement("dynamic_library_search"); // NOI18N
- c.setAttribute("flags", linker.getDynamicLibrarySearchFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getLibraryFlag() != null) {
- c = doc.createElement("library_flag"); // NOI18N
- c.setAttribute("flags", linker.getLibraryFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getPICFlag() != null) {
- c = doc.createElement("PIC"); // NOI18N
- c.setAttribute("flags", linker.getPICFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getStaticLibraryFlag() != null) {
- c = doc.createElement("static_library"); // NOI18N
- c.setAttribute("flags", linker.getStaticLibraryFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getDynamicLibraryFlag() != null) {
- c = doc.createElement("dynamic_library"); // NOI18N
- c.setAttribute("flags", linker.getDynamicLibraryFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getDynamicLibraryBasicFlag() != null) {
- c = doc.createElement("dynamic_library_basic"); // NOI18N
- c.setAttribute("flags", linker.getDynamicLibraryBasicFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getOutputFileFlag() != null) {
- c = doc.createElement("output_file"); // NOI18N
- c.setAttribute("flags", linker.getOutputFileFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getStripFlag() != null) {
- c = doc.createElement("strip_flag"); // NOI18N
- c.setAttribute("flags", linker.getStripFlag()); // NOI18N
- element.appendChild(c);
- }
- if (linker.getPreferredCompiler() != null) {
- c = doc.createElement("preferred_compiler"); // NOI18N
- c.setAttribute("compiler", linker.getPreferredCompiler()); // NOI18N
- element.appendChild(c);
- }
- }
- private void writeMake(Document doc, Element element, MakeDescriptor make) {
- Element c;
- c = doc.createElement("tool"); // NOI18N
- c.setAttribute("name", unsplit(make.getNames())); // NOI18N
- if (make.skipSearch()) {
- c.setAttribute("skip", "true"); // NOI18N
- }
- element.appendChild(c);
- if (make.getVersionFlags() != null ||
- make.getVersionPattern() != null) {
- c = doc.createElement("version"); // NOI18N
- if (make.getVersionFlags() != null) {
- c.setAttribute("flags", make.getVersionFlags()); // NOI18N
- }
- if (make.getVersionPattern() != null) {
- c.setAttribute("pattern", make.getVersionPattern()); // NOI18N
- }
- element.appendChild(c);
- }
- writeAlternativePath(doc, element, make);
- if (make.getDependencySupportCode() != null) {
- c = doc.createElement("dependency_support"); // NOI18N
- c.setAttribute("code", make.getDependencySupportCode()); // NOI18N
- element.appendChild(c);
- }
- }
- private void writeDebugger(Document doc, Element element, DebuggerDescriptor debugger) {
- Element c;
- c = doc.createElement("tool"); // NOI18N
- c.setAttribute("name", unsplit(debugger.getNames())); // NOI18N
- if (debugger.skipSearch()) {
- c.setAttribute("skip", "true"); // NOI18N
- }
- element.appendChild(c);
- if (debugger.getVersionFlags() != null ||
- debugger.getVersionPattern() != null) {
- c = doc.createElement("version"); // NOI18N
- if (debugger.getVersionFlags() != null) {
- c.setAttribute("flags", debugger.getVersionFlags()); // NOI18N
- }
- if (debugger.getVersionPattern() != null) {
- c.setAttribute("pattern", debugger.getVersionPattern()); // NOI18N
- }
- element.appendChild(c);
- }
- writeAlternativePath(doc, element, debugger);
- }
- private void writeQMake(Document doc, Element element, QMakeDescriptor qmake) {
- Element c;
- c = doc.createElement("tool"); // NOI18N
- c.setAttribute("name", unsplit(qmake.getNames())); // NOI18N
- if (qmake.skipSearch()) {
- c.setAttribute("skip", "true"); // NOI18N
- }
- element.appendChild(c);
- if (qmake.getVersionFlags() != null ||
- qmake.getVersionPattern() != null) {
- c = doc.createElement("version"); // NOI18N
- if (qmake.getVersionFlags() != null) {
- c.setAttribute("flags", qmake.getVersionFlags()); // NOI18N
- }
- if (qmake.getVersionPattern() != null) {
- c.setAttribute("pattern", qmake.getVersionPattern()); // NOI18N
- }
- element.appendChild(c);
- }
- writeAlternativePath(doc, element, qmake);
- }
- private void writeCMake(Document doc, Element element, CMakeDescriptor cmake) {
- Element c;
- c = doc.createElement("tool"); // NOI18N
- c.setAttribute("name", unsplit(cmake.getNames())); // NOI18N
- if (cmake.skipSearch()) {
- c.setAttribute("skip", "true"); // NOI18N
- }
- element.appendChild(c);
- if (cmake.getVersionFlags() != null ||
- cmake.getVersionPattern() != null) {
- c = doc.createElement("version"); // NOI18N
- if (cmake.getVersionFlags() != null) {
- c.setAttribute("flags", cmake.getVersionFlags()); // NOI18N
- }
- if (cmake.getVersionPattern() != null) {
- c.setAttribute("pattern", cmake.getVersionPattern()); // NOI18N
- }
- element.appendChild(c);
- }
- writeAlternativePath(doc, element, cmake);
- }
- private void writeAlternativePath(Document doc, Element element, ToolDescriptor tool){
- AlternativePath[] paths = tool.getAlternativePath();
- if (paths != null) {
- Element c = doc.createElement("alternative_path"); // NOI18N
- element.appendChild(c);
- for(AlternativePath path : paths){
- Element p = doc.createElement("path"); // NOI18N
- c.appendChild(p);
- switch(path.getKind()){
- case PATH:
- p.setAttribute("directory", path.getPath()); // NOI18N
- break;
- case TOOL_FAMILY:
- p.setAttribute("toolchain_family", path.getPath()); // NOI18N
- break;
- case TOOL_NAME:
- p.setAttribute("toolchain_name", path.getPath()); // NOI18N
- break;
- }
- }
- }
- }
- /**
- * class package-local for testing only
- */
- static final class CompilerVendor {
- final String toolChainFileName;
- final int position;
- String toolChainName;
- String toolChainDisplay;
- Map<String, List<String>> default_locations;
- String family;
- String platforms;
- String uc;
- String ucName;
- String upgrage;
- String module;
- String aliases;
- String substitute;
- boolean isAbstract;
- boolean isAutoDetected;
- String driveLetterPrefix;
- List<FolderInfo> baseFolder;
- List<FolderInfo> commandFolder;
- String qmakespec;
- String makefileWriter;
- Compiler c = new Compiler();
- Compiler cpp = new Compiler();
- Compiler fortran = new Compiler();
- Compiler assembler = new Compiler();
- Scanner scanner = new Scanner();
- Linker linker = new Linker();
- Make make = new Make();
- Debugger debugger = new Debugger();
- QMake qmake = new QMake();
- CMake cmake = new CMake();
- private CompilerVendor(String fileName, int position) {
- toolChainFileName = fileName;
- this.position = position;
- }
- public boolean isValid() {
- return toolChainName != null && toolChainName.length() > 0 &&
- (c.isValid() || cpp.isValid() || fortran.isValid());
- }
- }
- static final class FolderInfo {
- String folderKey;
- String folderPattern;
- String folderSuffix;
- String folderPathPattern;
- }
- /**
- * class pa