Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-10-30 16:45:45 +0000
committerHenrik Rentz-Reichert2013-10-30 16:45:45 +0000
commit774e232a6aa9fa36f94fbab0eabc160c33a69ee9 (patch)
treec3258ea1354fbe55d3d25726ed74e12092846b5a /plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice
parentaa37935849add0f679127189ef5688b62bd59ea1 (diff)
downloadorg.eclipse.etrice-774e232a6aa9fa36f94fbab0eabc160c33a69ee9.tar.gz
org.eclipse.etrice-774e232a6aa9fa36f94fbab0eabc160c33a69ee9.tar.xz
org.eclipse.etrice-774e232a6aa9fa36f94fbab0eabc160c33a69ee9.zip
[generator.ui, site, new feature and plug-in] Bug 420133: make CDT dependency optional
https://bugs.eclipse.org/420133
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice')
-rw-r--r--plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java31
-rw-r--r--plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java105
-rw-r--r--plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java4
-rw-r--r--plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/ProjectCreator.java121
4 files changed, 145 insertions, 116 deletions
diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java
new file mode 100644
index 000000000..a0f5bb23b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.ui.configurator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.etrice.generator.ui.wizard.NewSetOfModelsWizard;
+
+/**
+ * This interface is used by the org.eclipse.etrice.generator.ui.project_configurator extension point.
+ * The method is called when a new set of models is created by the {@link NewSetOfModelsWizard}.
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IProjectConfigurator {
+
+ /**
+ * @param project the project to be configured
+ */
+ void configure(IProject project);
+}
diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java
new file mode 100644
index 000000000..7d325b540
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.ui.configurator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.etrice.generator.ui.wizard.NewSetOfModelsWizard;
+
+/**
+ * This singleton collects the extensions registered with {@link #ICONFIGURATOR_ID}.
+ * It is called by the {@link NewSetOfModelsWizard} and applies all configured project configurators
+ * if the project has the specified nature.
+ *
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ProjectConfigurationDelegator implements IProjectConfigurator {
+
+ private static final String ICONFIGURATOR_ID = "org.eclipse.etrice.generator.ui.project_configurator";
+
+ private static ProjectConfigurationDelegator instance = null;
+
+ private HashMap<String, ArrayList<IProjectConfigurator>> nature2configurators = new HashMap<String, ArrayList<IProjectConfigurator>>();
+
+ /**
+ * @return the singleton instance of this class
+ */
+ public static ProjectConfigurationDelegator getInstance() {
+ if (instance==null)
+ instance = new ProjectConfigurationDelegator();
+
+ return instance;
+ }
+
+ /**
+ * The constructor instantiates the configured extensions.
+ */
+ private ProjectConfigurationDelegator() {
+ IConfigurationElement[] config = Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(ICONFIGURATOR_ID);
+ for (IConfigurationElement e : config) {
+ try {
+ final Object ext = e.createExecutableExtension("class");
+ if (ext instanceof IProjectConfigurator) {
+ IProjectConfigurator configurator = (IProjectConfigurator) ext;
+ String nature = e.getAttribute("appliesToNature");
+ addConfigurator(nature, configurator);
+ }
+ }
+ catch (CoreException ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+ }
+
+ /**
+ * This helper method adds the configurator to our hash map
+ * @param nature the nature to which this configurator is applicable
+ * @param configurator the project configurator
+ */
+ private void addConfigurator(String nature, IProjectConfigurator configurator) {
+ ArrayList<IProjectConfigurator> configurators = nature2configurators.get(nature);
+ if (configurators==null)
+ nature2configurators.put(nature, configurators = new ArrayList<IProjectConfigurator>());
+
+ configurators.add(configurator);
+ }
+
+ /**
+ * This method applies all configurators configured with the {@link #ICONFIGURATOR_ID} extension point.
+ *
+ * @see org.eclipse.etrice.generator.ui.configurator.IProjectConfigurator#configure(org.eclipse.core.resources.IProject)
+ */
+ @Override
+ public void configure(IProject project) {
+ for (Entry<String, ArrayList<IProjectConfigurator>> entry : nature2configurators.entrySet()) {
+ try {
+ if (project.hasNature(entry.getKey())) {
+ for (IProjectConfigurator configurator : entry.getValue()) {
+ configurator.configure(project);
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java
index 50b2919b2..fff67e8f5 100644
--- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java
+++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java
@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.etrice.generator.ui.configurator.ProjectConfigurationDelegator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -103,9 +104,10 @@ public class NewSetOfModelsWizard extends Wizard implements INewWizard {
: workspace.getRoot().getFolder(page.getPath()).getProject();
ProjectCreator.createRunAndLaunchConfigurations(baseName, project, page.getPath().toString(), additionalLaunchConfigLines);
- ProjectCreator.addIncludePathsAndLibraries(project);
ProjectCreator.addXtextNature(project, progressMonitor);
+ ProjectConfigurationDelegator.getInstance().configure(project);
+
} catch (Exception e) {
Logger.getLogger(getClass()).error(e.getMessage(), e);
} finally {
diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/ProjectCreator.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/ProjectCreator.java
index 4fed12af5..03383d9e9 100644
--- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/ProjectCreator.java
+++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/ProjectCreator.java
@@ -21,17 +21,6 @@ import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
-import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
-import org.eclipse.cdt.core.settings.model.CLibraryPathEntry;
-import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
-import org.eclipse.cdt.core.settings.model.ICFolderDescription;
-import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
-import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
-import org.eclipse.cdt.core.settings.model.ICProjectDescription;
-import org.eclipse.cdt.core.settings.model.ICSettingEntry;
-import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
@@ -221,7 +210,7 @@ public class ProjectCreator {
* @param desc
* @param naturesToAdd
*/
- public static void addNatures(IProjectDescription desc,
+ private static void addNatures(IProjectDescription desc,
List<String> naturesToAdd) {
HashSet<String> natures = new HashSet<String>();
String[] ids = desc.getNatureIds();
@@ -238,7 +227,7 @@ public class ProjectCreator {
desc.setNatureIds(ids);
}
- public static void addBuilders(IProjectDescription desc,
+ private static void addBuilders(IProjectDescription desc,
List<String> buildersToAdd) {
HashMap<String, ICommand> builders = new HashMap<String, ICommand>();
ICommand[] buildSpecs = desc.getBuildSpec();
@@ -296,7 +285,7 @@ public class ProjectCreator {
}
}
- public static IContainer findOrCreateContainer(IPath path,
+ protected static IContainer findOrCreateContainer(IPath path,
boolean forceRefresh, IPath localLocation,
IProgressMonitor progressMonitor) throws CoreException {
String projectName = path.segment(0);
@@ -307,7 +296,7 @@ public class ProjectCreator {
progressMonitor);
}
- public static IContainer findOrCreateContainer(IPath path,
+ protected static IContainer findOrCreateContainer(IPath path,
boolean forceRefresh, IProjectDescription projectDescription,
IProgressMonitor progressMonitor) throws CoreException {
try {
@@ -392,109 +381,11 @@ public class ProjectCreator {
writeFile(uri, ProjectFileFragments.getLaunchCApplicationConfig(project));
}
- public static void addIncludePathsAndLibraries(IProject project)
- throws CoreException {
- if (project.getNature("org.eclipse.cdt.core.cnature") == null)
- return;
-
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IProject runtime = workspace.getRoot().getProject(
- "org.eclipse.etrice.runtime.c");
- IFolder common = runtime.getFolder("src/common");
- IFolder config = runtime.getFolder("src/config");
- IFolder posix = runtime.getFolder("src/platforms/MT_POSIX_GENERIC_GCC");
- IFolder mingw = runtime.getFolder("src/platforms/MT_WIN_MinGW");
- IFolder src_gen = project.getFolder("src-gen");
- IFolder mingw_debug = project.getFolder("MinGWDebug");
- IFolder mingw_release = project.getFolder("MinGWRelease");
- IFolder posix_debug = project.getFolder("PosixDebug");
- IFolder posix_release = project.getFolder("PosixRelease");
-
- ICProjectDescription projectDescription = CoreModel.getDefault()
- .getProjectDescription(project, true);
- ICConfigurationDescription configDecriptions[] = projectDescription
- .getConfigurations();
-
- for (ICConfigurationDescription configDescription : configDecriptions) {
- ICFolderDescription projectRoot = configDescription
- .getRootFolderDescription();
- ICLanguageSetting[] settings = projectRoot.getLanguageSettings();
- for (ICLanguageSetting setting : settings) {
- if (!"org.eclipse.cdt.core.gcc".equals(setting.getLanguageId())) {
- continue;
- }
-
- ICTargetPlatformSetting tgt = configDescription
- .getTargetPlatformSetting();
- String id = tgt.getId();
-
- ArrayList<ICLanguageSettingEntry> includes = new ArrayList<ICLanguageSettingEntry>();
- includes.add(new CIncludePathEntry(src_gen,
- ICSettingEntry.LOCAL));
- includes.add(new CIncludePathEntry(common, ICSettingEntry.LOCAL));
- includes.add(new CIncludePathEntry(config, ICSettingEntry.LOCAL));
- if (id.startsWith("cdt.managedbuild.target.gnu.platform.mingw.exe")) {
- includes.add(new CIncludePathEntry(mingw,
- ICSettingEntry.LOCAL));
- } else if (id
- .startsWith("cdt.managedbuild.target.gnu.platform.posix.exe")) {
- includes.add(new CIncludePathEntry(posix,
- ICSettingEntry.LOCAL));
- }
- addSettings(setting, ICSettingEntry.INCLUDE_PATH, includes);
-
- List<? extends ICLanguageSettingEntry> libPaths = null;
- if (id.startsWith("cdt.managedbuild.target.gnu.platform.mingw.exe.debug")) {
- libPaths = Collections.singletonList(new CLibraryPathEntry(
- mingw_debug, ICSettingEntry.LOCAL));
- } else if (id
- .startsWith("cdt.managedbuild.target.gnu.platform.mingw.exe.release")) {
- libPaths = Collections.singletonList(new CLibraryPathEntry(
- mingw_release, ICSettingEntry.LOCAL));
- } else if (id
- .startsWith("cdt.managedbuild.target.gnu.platform.posix.exe.debug")) {
- libPaths = Collections.singletonList(new CLibraryPathEntry(
- posix_debug, ICSettingEntry.LOCAL));
- } else if (id
- .startsWith("cdt.managedbuild.target.gnu.platform.posix.exe.release")) {
- libPaths = Collections.singletonList(new CLibraryPathEntry(
- posix_release, ICSettingEntry.LOCAL));
- }
- if (libPaths != null)
- addSettings(setting, ICSettingEntry.LIBRARY_PATH, libPaths);
-
- List<? extends ICLanguageSettingEntry> libs = Collections
- .singletonList(new CLibraryFileEntry(
- "org.eclipse.etrice.runtime.c", 0));
- addSettings(setting, ICSettingEntry.LIBRARY_FILE, libs);
- }
- }
- try {
- CoreModel.getDefault().setProjectDescription(project,
- projectDescription);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
- private static void addSettings(ICLanguageSetting setting, int kind,
- List<? extends ICLanguageSettingEntry> entries) {
- HashMap<String, ICLanguageSettingEntry> newEntries = new HashMap<String, ICLanguageSettingEntry>();
- for (ICLanguageSettingEntry entry : setting.getSettingEntriesList(kind)) {
- newEntries.put(entry.getName(), entry);
- }
- for (ICLanguageSettingEntry entry : entries) {
- newEntries.put(entry.getName(), entry);
- }
- setting.setSettingEntries(kind, new ArrayList<ICLanguageSettingEntry>(
- newEntries.values()));
- }
-
public static void createRunAndLaunchConfigurations(String baseName,
IProject project, String mdlPath,
String[] additionalLaunchConfigLines) throws CoreException {
- if (project.getNature(JavaCore.NATURE_ID) != null) {
+ if (project.hasNature(JavaCore.NATURE_ID)) {
ProjectCreator.createLaunchGeneratorConfig(
URI.createPlatformResourceURI("/" + project.getName()
+ "/gen_" + baseName + ".launch", true), "java",
@@ -504,7 +395,7 @@ public class ProjectCreator {
+ "/run_" + baseName + ".launch", true),
project.getName(), baseName,
"Node_nodeRef1_subSysRef1Runner");
- } else if (project.getNature("org.eclipse.cdt.core.cnature") != null) {
+ } else if (project.hasNature("org.eclipse.cdt.core.cnature")) {
ProjectCreator.createLaunchGeneratorConfig(
URI.createPlatformResourceURI("/" + project.getName()
+ "/gen_" + baseName + ".launch", true), "c",

Back to the top