--- /dev/null
+package org.tizen.nativeplatform.indexer;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+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 javax.xml.parsers.ParserConfigurationException;
+
+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.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.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+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 DefaultIncludePathImporter {
+ private IProject project = null;
+
+ private final String DEFAULT_INCLUDES_X86_XMLFILE = "platform_includes_x86.xml";
+ private final String DEFAULT_INCLUDES_ARM_XMLFILE = "platform_includes_arm.xml";
+
+ private final Logger logger = LoggerFactory.getLogger(DefaultIncludePathImporter.class);
+
+ public DefaultIncludePathImporter(IProject project) {
+ this.project = project;
+ }
+
+ public boolean process() {
+ IPath idePath = new Path(InstallPathConfig.getSDKPath()).append("ide");
+
+ IPath x86IncludeFilePath = idePath.append(DEFAULT_INCLUDES_X86_XMLFILE);
+ if (!x86IncludeFilePath.toFile().exists()) {
+ logger.warn(String.format("File could not be imported: %s",
+ x86IncludeFilePath.toOSString()));
+ return false;
+ }
+ String x86IncludeFile = x86IncludeFilePath.toOSString();
+
+ IPath armIncludeFilePath = idePath.append(DEFAULT_INCLUDES_ARM_XMLFILE);
+ if (!armIncludeFilePath.toFile().exists()) {
+ logger.warn(String.format("File could not be imported: %s",
+ armIncludeFilePath.toOSString()));
+ return false;
+ }
+ String armIncludeFile = armIncludeFilePath.toOSString();
+
+ List<ISettingsProcessor> processors = getSettingProcessor();
+ Map<String, ISettingsProcessor> importers = new HashMap<String, ISettingsProcessor>();
+ for (ISettingsProcessor processor : processors) {
+ importers.put(processor.getSectionName(), processor);
+ }
+
+ List<ISettingsProcessor> processors2 = getSettingProcessor();
+ Map<String, ISettingsProcessor> importers2 = new HashMap<String, ISettingsProcessor>();
+ for (ISettingsProcessor processor : processors2) {
+ importers2.put(processor.getSectionName(), processor);
+ }
+
+ try {
+ // make x86 pair list (importer, section)
+ List<ImporterSectionPair> x86Pairs = setImporterSectionPair(x86IncludeFile, importers);
+
+ // make arm pair list (importer, section)
+ List<ImporterSectionPair> armPairs = setImporterSectionPair(armIncludeFile, importers2);
+
+ // read xml and set it to project description
+ ICProjectDescription writableDescription = readSectionXML(project, x86Pairs, armPairs);
+ // set changed project description by xml
+ CoreModel.getDefault().setProjectDescription(project, writableDescription);
+ } catch (FileNotFoundException e) {
+ logger.warn("Could not open the specified file", e);
+ return false;
+ } catch (SettingsImportExportException e) {
+ logger.warn("File could not be imported", e);
+ return false;
+ } catch (CoreException e) {
+ CUIPlugin.log(e);
+ logger.warn("Could not save imported data", e);
+ return false;
+ }
+
+ return true;
+ }
+
+ 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> x86Pairs, List<ImporterSectionPair> armPairs)
+ 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();
+ if (config.getName().endsWith("Emulator")) {
+ for (ImporterSectionPair pair : x86Pairs) {
+ pair.importer.readSectionXML(writableProjectRoot, pair.section);
+ }
+ } else if (config.getName().endsWith("Device")) {
+ for (ImporterSectionPair pair : armPairs) {
+ 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 (ParserConfigurationException e) {
+ e.printStackTrace();
+ throw new SettingsImportExportException(e);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ throw new SettingsImportExportException(e);
+ } catch (IOException e) {
+ e.printStackTrace();
+ 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 static class ImporterSectionPair {
+ Element section;
+ ISettingsProcessor importer;
+
+ ImporterSectionPair(ISettingsProcessor importer, Element section) {
+ this.importer = importer;
+ this.section = section;
+ }
+ }
+}
--- /dev/null
+package org.tizen.nativeplatform.indexer;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
+import org.eclipse.cdt.core.settings.model.ICProjectDescriptionPreferences;
+import org.eclipse.cdt.internal.core.CCoreInternals;
+import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.nativeplatform.build.PlatformConfigurationManager;
+
+@SuppressWarnings("restriction")
+public class IndexerPreferenceProcessor {
+ private IProject project;
+
+ private final Logger logger = LoggerFactory.getLogger(IndexerPreferenceProcessor.class);
+
+ public IndexerPreferenceProcessor(IProject project) {
+ this.project = project;
+ }
+
+ public boolean process() {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ IConfiguration config = info.getDefaultConfiguration();
+ IManagedProject managedProject = config.getManagedProject();
+ String projectArtifactType = managedProject.getProjectType() != null ? managedProject
+ .getProjectType().getBuildArtefactType().getId()
+ : null;
+ if (projectArtifactType != null
+ && (!projectArtifactType
+ .equals(PlatformConfigurationManager.TIZEN_PLATFORM_ARTIFACT_TYPE))) {
+ return false;
+ }
+
+ int scope = IndexerPreferences.SCOPE_PROJECT_PRIVATE;
+ if (project != null) {
+ IndexerPreferences.setScope(project, scope);
+ }
+ boolean useActive = true;
+ ICProjectDescriptionManager prjDescMgr = CCorePlugin.getDefault()
+ .getProjectDescriptionManager();
+ ICProjectDescription prefs = prjDescMgr.getProjectDescription(project, true);
+ if (scope == IndexerPreferences.SCOPE_INSTANCE) {
+ prefs.useDefaultConfigurationRelations();
+ } else {
+ prefs.setConfigurationRelations(useActive ?
+ ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE :
+ ICProjectDescriptionPreferences.CONFIGS_INDEPENDENT);
+ }
+ try {
+ prjDescMgr.setProjectDescription(project, prefs);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ logger.warn("Failed to set default indexer", e);
+ return false;
+ }
+ CCoreInternals.savePreferences(project, scope == IndexerPreferences.SCOPE_PROJECT_SHARED);
+ return true;
+ }
+}
package org.tizen.nativeplatform.templateengine.process;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-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 javax.xml.parsers.ParserConfigurationException;
-
-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;
+import org.tizen.nativeplatform.indexer.DefaultIncludePathImporter;
+import org.tizen.nativeplatform.indexer.IndexerPreferenceProcessor;
-@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 (ParserConfigurationException e) {
- e.printStackTrace();
- throw new SettingsImportExportException(e);
- } catch (SAXException e) {
- e.printStackTrace();
- throw new SettingsImportExportException(e);
- } catch (IOException e) {
- e.printStackTrace();
- 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;
- }
+ DefaultIncludePathImporter importer = new DefaultIncludePathImporter(projectHandle);
+ importer.process();
- public void warning(SAXParseException e) throws SAXException {
- throw e;
- }
- };
-
- private static class ImporterSectionPair {
- Element section;
- ISettingsProcessor importer;
-
- ImporterSectionPair(ISettingsProcessor importer, Element section) {
- this.importer = importer;
- this.section = section;
- }
+ IndexerPreferenceProcessor processor = new IndexerPreferenceProcessor(projectHandle);
+ processor.process();
}
}