diff options
author | Henrik Rentz-Reichert | 2013-10-18 09:20:26 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2013-10-18 14:04:19 +0000 |
commit | f7bda43431d2a50ad75c50ed5cfcf5c1dc2db5fe (patch) | |
tree | e11fcdbcba8a69ebb512b2d0a3eeb5034da7e228 | |
parent | 96f2e440762f22e656aa26289b6cb3ff2317c3b3 (diff) | |
download | org.eclipse.etrice-f7bda43431d2a50ad75c50ed5cfcf5c1dc2db5fe.tar.gz org.eclipse.etrice-f7bda43431d2a50ad75c50ed5cfcf5c1dc2db5fe.tar.xz org.eclipse.etrice-f7bda43431d2a50ad75c50ed5cfcf5c1dc2db5fe.zip |
[generator.ui] Bug 419819: for C projects the new model files wizard should add include paths
https://bugs.eclipse.org/419819
3 files changed, 92 insertions, 4 deletions
diff --git a/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF index a416efe46..cf0868f4d 100644 --- a/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF @@ -14,7 +14,9 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.etrice.core.room.ui;bundle-version="0.4.0", org.eclipse.jdt.core;bundle-version="3.9.1", org.eclipse.jdt.launching;bundle-version="3.7.0", - org.eclipse.ui.ide;bundle-version="3.9.1" + org.eclipse.cdt.core;bundle-version="5.5.0", + org.eclipse.ui.ide;bundle-version="3.9.1", + org.eclipse.cdt.managedbuilder.core;bundle-version="8.2.1" Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.etrice.generator.ui.Activator Export-Package: org.eclipse.etrice.generator.ui.preferences 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 53128692e..50b2919b2 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 @@ -98,10 +98,12 @@ public class NewSetOfModelsWizard extends Wizard implements INewWizard { ProjectCreator.createMappingModel(mapModelURI, baseName); IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = workspace.getRoot().getFolder(page.getPath()).getProject(); + IProject project = (page.getPath().segmentCount()==1)? + workspace.getRoot().getProject(page.getPath().lastSegment()) + : workspace.getRoot().getFolder(page.getPath()).getProject(); ProjectCreator.createRunAndLaunchConfigurations(baseName, project, page.getPath().toString(), additionalLaunchConfigLines); - + ProjectCreator.addIncludePathsAndLibraries(project); ProjectCreator.addXtextNature(project, progressMonitor); } catch (Exception e) { 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 f026880c5..b7caad7ce 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,6 +21,17 @@ 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; @@ -484,7 +495,80 @@ public class ProjectCreator { } public static void addIncludePathsAndLibraries(IProject project) { - //IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project); + 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, |