From 4bdc2322a82279051981716284f145965321ba07 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 8 Aug 2012 16:45:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4543 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- tools/eclipse/config_wizard/META-INF/MANIFEST.MF | 2 +- .../resources/gencfg/lib/code_snippets.xml | 50 +++++++ .../resources/gencfg/lib/libsnippets.ftl | 33 +++++ .../resources/gencfg/processors/processors.xml | 24 +++- .../gencfg/schema/common/code_snippets.xsd | 59 +++++++++ .../eclipse/config/handlers/GenerateFiles.java | 1 + .../tools/eclipse/config/utils/TemplateEngine.java | 10 +- .../config/wizards/ConfigurationNewWizardPage.java | 18 +-- .../wizards/NewApplicationProjectWizardPage.java | 146 +++++++++++++++------ 9 files changed, 280 insertions(+), 63 deletions(-) create mode 100644 tools/eclipse/config_wizard/resources/gencfg/lib/code_snippets.xml create mode 100644 tools/eclipse/config_wizard/resources/gencfg/lib/libsnippets.ftl create mode 100644 tools/eclipse/config_wizard/resources/gencfg/schema/common/code_snippets.xsd (limited to 'tools') diff --git a/tools/eclipse/config_wizard/META-INF/MANIFEST.MF b/tools/eclipse/config_wizard/META-INF/MANIFEST.MF index 6b14e432e..b7cea1ead 100644 --- a/tools/eclipse/config_wizard/META-INF/MANIFEST.MF +++ b/tools/eclipse/config_wizard/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ChibiOS-RT_Configuration_Support Bundle-SymbolicName: org.chibios.tools.eclipse.config;singleton:=true -Bundle-Version: 1.1.0 +Bundle-Version: 1.2.0 Bundle-Activator: config_wizard.Activator Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, diff --git a/tools/eclipse/config_wizard/resources/gencfg/lib/code_snippets.xml b/tools/eclipse/config_wizard/resources/gencfg/lib/code_snippets.xml new file mode 100644 index 000000000..2d0e5959a --- /dev/null +++ b/tools/eclipse/config_wizard/resources/gencfg/lib/code_snippets.xml @@ -0,0 +1,50 @@ + + + + + + thread_body + Empty + + + + + thread_body + Checks for Termination + + + + + thread_body + Message Server + + + + + diff --git a/tools/eclipse/config_wizard/resources/gencfg/lib/libsnippets.ftl b/tools/eclipse/config_wizard/resources/gencfg/lib/libsnippets.ftl new file mode 100644 index 000000000..a0680af04 --- /dev/null +++ b/tools/eclipse/config_wizard/resources/gencfg/lib/libsnippets.ftl @@ -0,0 +1,33 @@ +[#ftl] +[#-- + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + --] + +[#-- + -- Find and return a code template from the templates archive. + --] +[#function GetThreadCode name] + [#list doc_snippets.code.snippets.snippet as snippet] + [#if (snippet.type[0] == "thread_body") && + ((snippet.name[0]!"")?trim?lower_case == name?trim?lower_case)] + [#return snippet.text[0]!"" /] + [/#if] + [/#list] + [#return "/* Thread style not found: " + name + " */" /] +[/#function] diff --git a/tools/eclipse/config_wizard/resources/gencfg/processors/processors.xml b/tools/eclipse/config_wizard/resources/gencfg/processors/processors.xml index 6dba55fcd..30a70c069 100644 --- a/tools/eclipse/config_wizard/resources/gencfg/processors/processors.xml +++ b/tools/eclipse/config_wizard/resources/gencfg/processors/processors.xml @@ -1,20 +1,38 @@ - + STM32F0xx Board Configuration resources/gencfg/processors/boards/stm32f0xx/templates resources/gencfg/xml/stm32f0board.xml board - + STM32F4xx Board Configuration resources/gencfg/processors/boards/stm32f4xx/templates resources/gencfg/xml/stm32f4board.xml board - + STM32L1xx Board Configuration resources/gencfg/processors/boards/stm32l1xx/templates resources/gencfg/xml/stm32l1board.xml board + + STM32F0xx Build Environment Configuration + resources/gencfg/processors/builds/stm32f0xx/templates + resources/gencfg/xml/stm32f0build.xml + build + + + STM32F4xx Build Environment Configuration + resources/gencfg/processors/builds/stm32f4xx/templates + resources/gencfg/xml/stm32f4build.xml + build + + + STM32L1xx Build Environment Configuration + resources/gencfg/processors/builds/stm32l1xx/templates + resources/gencfg/xml/stm32l1build.xml + build + diff --git a/tools/eclipse/config_wizard/resources/gencfg/schema/common/code_snippets.xsd b/tools/eclipse/config_wizard/resources/gencfg/schema/common/code_snippets.xsd new file mode 100644 index 000000000..ad0bad11a --- /dev/null +++ b/tools/eclipse/config_wizard/resources/gencfg/schema/common/code_snippets.xsd @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java index e6e9b3790..c742d9072 100644 --- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java +++ b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/handlers/GenerateFiles.java @@ -118,6 +118,7 @@ public class GenerateFiles extends AbstractHandler { return null; } } + /* TODO: refresh output path.*/ return null; } } diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java index 272d6a5c2..60a33f0e2 100644 --- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java +++ b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/utils/TemplateEngine.java @@ -20,6 +20,7 @@ package org.chibios.tools.eclipse.config.utils; +import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -165,9 +166,12 @@ public class TemplateEngine { } catch (ParserConfigurationException e) { throw new TemplateException(e.getMessage()); } - Document dom1; + Document dom1, dom_snippets; try { dom1 = db.parse(xmldata); + java.io.File xmlsnippets = new File(libdir.toString() + + "/code_snippets.xml"); + dom_snippets = db.parse(xmlsnippets); } catch (SAXException e) { throw new TemplateException(e.getMessage()); } catch (IOException e) { @@ -176,10 +180,14 @@ public class TemplateEngine { NodeModel.removeComments(dom1); NodeModel.mergeAdjacentText(dom1); + NodeModel.removeComments(dom_snippets); TemplateNodeModel doc1 = NodeModel.wrap(dom1); + NodeModel.mergeAdjacentText(dom_snippets); + TemplateNodeModel doc_snippets = NodeModel.wrap(dom_snippets); HashMap xmls = new HashMap(); xmls.put("doc1", doc1); + xmls.put("doc_snippets", doc_snippets); /* Setting libraries path. */ HashMap libs = new HashMap(); diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java index 2cc7b830b..d503d9748 100644 --- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java +++ b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/ConfigurationNewWizardPage.java @@ -122,7 +122,6 @@ public class ConfigurationNewWizardPage extends WizardPage { } }); - populateWizardPanel(); initialize(); setControl(container); } @@ -171,18 +170,9 @@ public class ConfigurationNewWizardPage extends WizardPage { container.setEnabled(false); updateStatus("Container for the resource not selected."); } - } - - /** - * Fills the wizard configuration panel from XML data. - * - * @param configurationTemplateCombo - * the combo box to be populated - */ - private void populateWizardPanel() { - String fpath; /* Retrieving the resource path of the processors.xml file. */ + String fpath; try { Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); IPath path = new Path("resources/gencfg/processors/processors.xml"); @@ -205,10 +195,8 @@ public class ConfigurationNewWizardPage extends WizardPage { return; } - /* - * Parsing the content of the processors.xml file in order to populate the - * panel objects. - */ + /* Parsing the content of the processors.xml file in order to populate the + panel objects.*/ Element root = processorsDocument.getRootElement(); for (Element processor : root.getChildren("processor")) { String name = processor.getChildText("name"); diff --git a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java index d771b68e8..efc377014 100644 --- a/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java +++ b/tools/eclipse/config_wizard/src/org/chibios/tools/eclipse/config/wizards/NewApplicationProjectWizardPage.java @@ -1,17 +1,21 @@ package org.chibios.tools.eclipse.config.wizards; import java.io.File; +import java.io.IOException; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Button; @@ -19,6 +23,15 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.widgets.Combo; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; +import org.osgi.framework.Bundle; + +import config_wizard.Activator; public class NewApplicationProjectWizardPage extends WizardPage { @@ -26,11 +39,13 @@ public class NewApplicationProjectWizardPage extends WizardPage { private Composite container; private Text projectParentPathText; private Button btnBrowse; - private Label lblProjectName; + private Label lbl1; private Text projectNameText; private Button useCustomPathButton; - private Label lblFinalProjectPath; + private Label lbl3; private Text projectFinalPathText; + private Label lbl4; + private Combo platformCombo; /** * Constructor for SampleNewWizardPage. @@ -53,19 +68,20 @@ public class NewApplicationProjectWizardPage extends WizardPage { container.setLayout(layout); layout.numColumns = 3; layout.verticalSpacing = 9; - - lblProjectName = new Label(container, SWT.NONE); - lblProjectName.setText("Project name:"); + /* Layout row 1.*/ + lbl1 = new Label(container, SWT.NONE); + lbl1.setText("Project name:"); projectNameText = new Text(container, SWT.BORDER); projectNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - projectNameUpdated(); + projectPageUpdated(); } }); projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); new Label(container, SWT.NONE); - + + /* Layout row 2.*/ useCustomPathButton = new Button(container, SWT.CHECK); useCustomPathButton.addSelectionListener(new SelectionAdapter() { @Override @@ -73,11 +89,13 @@ public class NewApplicationProjectWizardPage extends WizardPage { if (useCustomPathButton.getSelection()) { projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()); projectParentPathText.setEnabled(false); + btnBrowse.setEnabled(false); updateFinalProjectPathText(); } else { projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()); projectParentPathText.setEnabled(true); + btnBrowse.setEnabled(true); updateFinalProjectPathText(); } } @@ -86,33 +104,49 @@ public class NewApplicationProjectWizardPage extends WizardPage { new Label(container, SWT.NONE); new Label(container, SWT.NONE); - Label lbl1 = new Label(container, SWT.NULL); - lbl1.setText("Project parent path:"); - + /* Layout row 3.*/ + Label lbl2 = new Label(container, SWT.NULL); + lbl2.setText("Project parent path:"); projectParentPathText = new Text(container, SWT.BORDER | SWT.SINGLE); projectParentPathText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - projectPathUpdated(); + projectPageUpdated(); } }); projectParentPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - btnBrowse = new Button(container, SWT.NONE); btnBrowse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + /* Prompts the user for a parent directory for the new project.*/ + DirectoryDialog dlg = new DirectoryDialog(getShell()); + dlg.setFilterPath(projectParentPathText.getText()); + dlg.setText("New ChibiOS/RT Project"); + dlg.setMessage("Select the parent directory for the new ChibiOS/RT application project."); + String parent = dlg.open(); + if (parent != null) { + projectParentPathText.setText(parent); + projectPageUpdated(); + } } }); btnBrowse.setText("Browse..."); - lblFinalProjectPath = new Label(container, SWT.NONE); - lblFinalProjectPath.setText("Final project path:"); - + /* Layout row 4.*/ + lbl3 = new Label(container, SWT.NONE); + lbl3.setText("Final project path:"); projectFinalPathText = new Text(container, SWT.BORDER); projectFinalPathText.setEditable(false); projectFinalPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + new Label(container, SWT.NONE); + + /* Layout row 5.*/ + lbl4 = new Label(container, SWT.NONE); + lbl4.setText("Target platform:"); + platformCombo = new Combo(container, SWT.READ_ONLY); + platformCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + new Label(container, SWT.NONE); - populateWizardPanel(); initialize(); setControl(container); } @@ -121,49 +155,60 @@ public class NewApplicationProjectWizardPage extends WizardPage { * Tests if the current workbench selection is a suitable container to use. */ private void initialize() { - + /* Initial state of the check box and project path text.*/ useCustomPathButton.setSelection(true); projectParentPathText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()); projectParentPathText.setEnabled(false); + btnBrowse.setEnabled(false); - /* Update checks on the fields.*/ - projectNameUpdated(); - } - /** - * Fills the wizard configuration panel from XML data. - * - * @param configurationTemplateCombo - * the combo box to be populated - */ - private void populateWizardPanel() { - - } - - private void projectNameUpdated() { - String name = projectNameText.getText(); - - updateFinalProjectPathText(); - - if (!isValidFilename(name)) { - updateStatus("Invalid project name."); + /* Retrieving the resource path of the processors.xml file. */ + String fpath; + try { + Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); + IPath path = new Path("resources/gencfg/processors/processors.xml"); + fpath = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile(); + } catch (IOException e) { + e.printStackTrace(); return; } - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); - if (project.exists()) { - updateStatus("Project exists."); + /* DOM tree creation. */ + SAXBuilder builder = new SAXBuilder(); + Document document; + try { + document = builder.build(fpath); + } catch (JDOMException e) { + e.printStackTrace(); + return; + } catch (IOException e) { + e.printStackTrace(); return; } - updateStatus(null); + + /* Parsing the content of the processors.xml file in order to populate the + panel objects.*/ + Element root = document.getRootElement(); + for (Element processor : root.getChildren("processor")) { + String class_attr = processor.getAttributeValue("class", ""); + if (class_attr.compareToIgnoreCase("build") == 0) { + String name = processor.getAttributeValue("target", "internal error"); + platformCombo.add(name); + } + } + platformCombo.select(0); + + /* Update checks on the fields.*/ + projectPageUpdated(); } - private void projectPathUpdated() { - File path = new File(projectParentPathText.getText()); + private void projectPageUpdated() { updateFinalProjectPathText(); + /* Checks the project location.*/ + File path = new File(projectParentPathText.getText()); if (!path.exists()) { updateStatus("Project path is not valid."); return; @@ -172,6 +217,21 @@ public class NewApplicationProjectWizardPage extends WizardPage { updateStatus("Project path is a directory."); return; } + + /* Checks the project name.*/ + String name = projectNameText.getText(); + if (!isValidFilename(name)) { + updateStatus("Invalid project name."); + return; + } + + /* Checks if the project already exists in the workspace.*/ + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); + if (project.exists()) { + updateStatus("Project exists."); + return; + } + updateStatus(null); } -- cgit v1.2.3