+++ /dev/null
-package org.tizen.nativeplatform.build;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class DefaultIncludePaths {
- private static String INCLUDE_DIR = "${SBI_SYSROOT}/usr/include";
- private static String[] INCLUDE_PATH = { "appfw", "arpa", "asm", "asm-generic", "bits", "c++",
- "curl", "dbus-1.0", "dlog", "ecore-1", "e_dbus-1", "edje-1", "eet-1", "efreet-1",
- "elementary-1", "embryo-1", "emotion-1", "ethumb-1", "evas-1", "fontconfig",
- "freetype2", "fribidi", "gio-unix-2.0", "glib-2.0", "gnu", "harfbuzz", "kerneldrm",
- "libexif", "linux", "lzo", "mtd", "net", "netash", "netatalk", "netax25", "neteconet",
- "netinet", "netipx", "netiucv", "netpacket", "netrom", "netrose", "nfs", "pixman-1",
- "protocols", "rdma", "rpc", "rpcsvc", "scsi", "sound", "sys", "video", "xen",
-
- };
-
- public static List<String> getIncludePaths() {
- List<String> list = new ArrayList<String>();
- list.add(INCLUDE_DIR);
- for (String s : INCLUDE_PATH) {
- String path = INCLUDE_DIR + "/" + s;
- list.add(path);
- }
-
- return list;
- }
-}
static final String GBS_TOOL_ID = "org.tizen.nativeide.tool.gbs";
static final String GBS_TOOL_INCLUDE_OPTION_ID = "org.tizen.gbs.include.paths";
- static final String SBI_PLATFORM_CPP_COMPILER_TOOL_ID = "org.tizen.nativeide.tool.sbi.gnu.cpp.compiler.platform.base";
- static final String SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID = "sbi.gnu.cpp.compiler.option.gbs.platform";
+ static final String GBS_TOOL_OPTIONS_ID = "org.tizen.gbs.options";
// get compiler flags
public static String getAllCFlags(IConfiguration config) {
return compilerFlags;
}
- public static void setGBSOptions(IConfiguration config, Tool tool, ArrayList<String> optionList) {
- String tool_id = tool.getBaseId();
- String option_id = "";
-
- if (tool_id.contains(SBI_PLATFORM_CPP_COMPILER_TOOL_ID)) {
- option_id = SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID;
- } else {
- return;
- }
-
- ITool cpp_linkerTool = config.getToolsBySuperClassId(tool_id)[0];
- IOption dynamicAnalysisOption = cpp_linkerTool.getOptionBySuperClassId(option_id);
- ManagedBuildManager.setOption(config, cpp_linkerTool, dynamicAnalysisOption,
- optionList.toArray(new String[0]));
- }
-
public static void setGBSOptions(IConfiguration config, ArrayList<String> optionList) {
if (config instanceof MultiConfiguration) {
Object o[] = ((MultiConfiguration) config).getItems();
}
private static void internalSetGBSOptions(IConfiguration config, ArrayList<String> optionList) {
- String cpp_compiler_id = SBI_PLATFORM_CPP_COMPILER_TOOL_ID;
- String option_id = SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID;
+ String gbs_tool_id = GBS_TOOL_ID;
+ String option_id = GBS_TOOL_OPTIONS_ID;
// cpp compiler
- ITool tool = config.getToolsBySuperClassId(cpp_compiler_id)[0];
+ ITool tool = config.getToolsBySuperClassId(gbs_tool_id)[0];
IOption gbsOption = tool.getOptionBySuperClassId(option_id);
ManagedBuildManager.setOption(config, tool, gbsOption, optionList.toArray(new String[0]));
}
}
private static void internalAddGBSOption(IConfiguration config, String newOption) {
- String cpp_compiler_id = SBI_PLATFORM_CPP_COMPILER_TOOL_ID;
- String option_id = SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID;
+ String gbs_tool_id = GBS_TOOL_ID;
+ String option_id = GBS_TOOL_OPTIONS_ID;
// cpp compiler
- ITool tool = config.getToolsBySuperClassId(cpp_compiler_id)[0];
+ ITool tool = config.getToolsBySuperClassId(gbs_tool_id)[0];
IOption gbsOption = tool.getOptionBySuperClassId(option_id);
ArrayList<String> oldOptions = getGBSOptions(config);
}
private static void internalRemoveGBSOption(IConfiguration config, String option) {
- String cpp_compiler_id = SBI_PLATFORM_CPP_COMPILER_TOOL_ID;
- String option_id = SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID;
+ String gbs_tool_id = GBS_TOOL_ID;
+ String option_id = GBS_TOOL_OPTIONS_ID;
// cpp compiler
- ITool tool = config.getToolsBySuperClassId(cpp_compiler_id)[0];
+ ITool tool = config.getToolsBySuperClassId(gbs_tool_id)[0];
IOption gbsOption = tool.getOptionBySuperClassId(option_id);
ArrayList<String> oldOptions = getGBSOptions(config);
ArrayList<String> newOptions = new ArrayList<String>();
}
public static ArrayList<String> getGBSOptions(IConfiguration config) {
- String cpp_compiler_id = SBI_PLATFORM_CPP_COMPILER_TOOL_ID;
- String option_id = SBI_PLATFORM_CPP_COMPILER_GBS_OPTION_ID;
+ String gbs_tool_id = GBS_TOOL_ID;
+ String option_id = GBS_TOOL_OPTIONS_ID;
ArrayList<String> flags = new ArrayList<String>();
// c compiler
- ITool tool = config.getToolsBySuperClassId(cpp_compiler_id)[0];
+ ITool tool = config.getToolsBySuperClassId(gbs_tool_id)[0];
IOption gbsOption = tool.getOptionBySuperClassId(option_id);
try {
--- /dev/null
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.nativeplatform.templateengine.process;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICFolderDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.ISettingsProcessor;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePathsSettingsProcessor;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.MacroSettingsProcessor;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.ProjectSettingsExportStrategy;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.SettingsImportExportException;
+import org.eclipse.cdt.internal.ui.wizards.settingswizards.XMLUtils;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.core.application.InstallPathConfig;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+@SuppressWarnings("restriction")
+public class SetDefaultIncludePaths extends ProcessRunner {
+ private final Logger logger = LoggerFactory.getLogger(SetDefaultIncludePaths.class);
+ private final String DEFAULT_INCLUDES_XMLFILE = "platform_includes.xml";
+
+ @Override
+ public void process(TemplateCore template, ProcessArgument[] args, String processId,
+ IProgressMonitor monitor) throws ProcessFailureException {
+
+ IPath idePath = new Path(InstallPathConfig.getSDKPath()).append("ide");
+ IPath includeFilePath = idePath.append(DEFAULT_INCLUDES_XMLFILE);
+ if (!includeFilePath.toFile().exists()) {
+ logger.warn(String.format("File could not be imported: %s",
+ includeFilePath.toOSString()));
+ return;
+ }
+
+ String filePath = includeFilePath.toOSString();
+
+ // project name
+ String projectName = args[0].getSimpleValue();
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (projectHandle == null) {
+ return;
+ }
+ /*
+ * Codes are from CDT source (import include path settings) -
+ * org.eclipse
+ * .cdt.internal.ui.wizards.settingswizards.ProjectSettingsImportStrategy
+ * - org.eclipse.cdt.internal.ui.wizards.settingswizards.
+ * ProjectSettingsWizardPage
+ */
+ List<ISettingsProcessor> processors = getSettingProcessor();
+ Map<String, ISettingsProcessor> importers = new HashMap<String, ISettingsProcessor>();
+ for (ISettingsProcessor processor : processors) {
+ importers.put(processor.getSectionName(), processor);
+ }
+ try {
+ // make pair list (importer, section)
+ List<ImporterSectionPair> pairs = setImporterSectionPair(filePath, importers);
+ // read xml and set it to project description
+ ICProjectDescription writableDescription = readSectionXML(projectHandle, pairs);
+ // set changed project description by xml
+ CoreModel.getDefault().setProjectDescription(projectHandle, writableDescription);
+ } catch (FileNotFoundException e) {
+ logger.warn("Could not open the specified file", e);
+ return;
+ } catch (SettingsImportExportException e) {
+ logger.warn("File could not be imported", e);
+ return;
+ } catch (CoreException e) {
+ CUIPlugin.log(e);
+ logger.warn("Could not save imported data", e);
+ return;
+ }
+ }
+
+ private List<ISettingsProcessor> getSettingProcessor() {
+ return Arrays.<ISettingsProcessor> asList(new IncludePathsSettingsProcessor(),
+ new MacroSettingsProcessor());
+ }
+
+ private List<ImporterSectionPair> setImporterSectionPair(String filePath,
+ Map<String, ISettingsProcessor> importers) throws FileNotFoundException,
+ SettingsImportExportException {
+ FileInputStream in = new FileInputStream(filePath);
+ // try to parse the file as generic XML with no schema
+ Document document = parse(in);
+
+ // now try to get a list of <section> elements
+ Element root = document.getDocumentElement();
+ List<Element> sections = XMLUtils.extractChildElements(root,
+ ProjectSettingsExportStrategy.SECTION_ELEMENT);
+ List<ImporterSectionPair> pairs = new ArrayList<ImporterSectionPair>();
+
+ // associate an importer with each section
+ for (Element section : sections) {
+ String sectionName = section
+ .getAttribute(ProjectSettingsExportStrategy.SECTION_NAME_ATTRIBUTE);
+ if (sectionName != null) {
+ ISettingsProcessor importer = importers.get(sectionName);
+
+ // if there is an importer available for the section then
+ // delegate to it
+ if (importer != null)
+ pairs.add(new ImporterSectionPair(importer, section));
+ }
+ }
+ return pairs;
+ }
+
+ private ICProjectDescription readSectionXML(IProject project, List<ImporterSectionPair> pairs)
+ throws SettingsImportExportException {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ IConfiguration defaultConfig = info.getDefaultConfiguration();
+ ICProjectDescription writableDescription = CoreModel.getDefault().getProjectDescription(
+ project, true);
+ for (IConfiguration config : defaultConfig.getManagedProject().getConfigurations()) {
+ ICConfigurationDescription writableConfig = writableDescription
+ .getConfigurationById(config.getId());
+ ICFolderDescription writableProjectRoot = writableConfig.getRootFolderDescription();
+ for (ImporterSectionPair pair : pairs) {
+ pair.importer.readSectionXML(writableProjectRoot, pair.section);
+ }
+ }
+ return writableDescription;
+ }
+
+ private Document parse(InputStream in) throws SettingsImportExportException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(false);
+ factory.setIgnoringComments(true);
+
+ try {
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ // causes SAXException to be thrown on any parse error
+ parser.setErrorHandler(ABORTING_ERROR_HANDER);
+ // TODO should I be using an InputSource?
+ InputSource input = new InputSource(in);
+ Document doc = parser.parse(input);
+ return doc;
+
+ } catch (Exception e) {
+ throw new SettingsImportExportException(e);
+ }
+ }
+
+ /**
+ * An error handler that aborts the XML parse at the first sign of any kind
+ * of problem.
+ */
+ private ErrorHandler ABORTING_ERROR_HANDER = new ErrorHandler() {
+ public void error(SAXParseException e) throws SAXException {
+ throw e;
+ }
+
+ public void fatalError(SAXParseException e) throws SAXException {
+ throw e;
+ }
+
+ public void warning(SAXParseException e) throws SAXException {
+ throw e;
+ }
+ };
+
+ private class ImporterSectionPair {
+ Element section;
+ ISettingsProcessor importer;
+
+ ImporterSectionPair(ISettingsProcessor importer, Element section) {
+ this.importer = importer;
+ this.section = section;
+ }
+ }
+}