diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java')
-rw-r--r-- | plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java new file mode 100644 index 0000000..a06a03c --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java | |||
@@ -0,0 +1,240 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
3 | * Copyright (c) 2010 Intel Corporation. | ||
4 | * All rights reserved. This program and the accompanying materials | ||
5 | * are made available under the terms of the Eclipse Public License v1.0 | ||
6 | * which accompanies this distribution, and is available at | ||
7 | * http://www.eclipse.org/legal/epl-v10.html | ||
8 | * | ||
9 | * Contributors: | ||
10 | * Intel - initial implementation | ||
11 | * BMW Car IT - initial implementation and refactoring | ||
12 | *******************************************************************************/ | ||
13 | package org.yocto.sdk.ide.utils; | ||
14 | |||
15 | import java.io.IOException; | ||
16 | |||
17 | import org.eclipse.cdt.core.CCorePlugin; | ||
18 | import org.eclipse.cdt.core.ConsoleOutputStream; | ||
19 | import org.eclipse.cdt.core.resources.IConsole; | ||
20 | import org.eclipse.core.resources.IProject; | ||
21 | import org.eclipse.core.resources.ProjectScope; | ||
22 | import org.eclipse.core.runtime.CoreException; | ||
23 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | ||
24 | import org.eclipse.core.runtime.preferences.IScopeContext; | ||
25 | import org.eclipse.jface.preference.IPreferenceStore; | ||
26 | import org.osgi.service.prefs.BackingStoreException; | ||
27 | import org.yocto.sdk.ide.YoctoGeneralException; | ||
28 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
29 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
30 | import org.yocto.sdk.ide.YoctoUIElement; | ||
31 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
32 | import org.yocto.sdk.ide.natures.YoctoSDKCMakeProjectNature; | ||
33 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
34 | |||
35 | public class ProjectPreferenceUtils { | ||
36 | private static final String CONSOLE_MESSAGE = "Menu.SDK.Console.Configure.Message"; | ||
37 | |||
38 | /* Get POKY Preference settings from project's preference store */ | ||
39 | public static YoctoUIElement getElem(IProject project) { | ||
40 | IScopeContext projectScope = new ProjectScope(project); | ||
41 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
42 | if (projectNode == null) { | ||
43 | return getElemFromProjectEnv(project); | ||
44 | } | ||
45 | |||
46 | YoctoUIElement elem = new YoctoUIElement(); | ||
47 | elem.setStrToolChainRoot(projectNode.get(PreferenceConstants.TOOLCHAIN_ROOT,"")); | ||
48 | elem.setStrTarget(projectNode.get(PreferenceConstants.TOOLCHAIN_TRIPLET,"")); | ||
49 | elem.setStrQemuKernelLoc(projectNode.get(PreferenceConstants.QEMU_KERNEL,"")); | ||
50 | elem.setStrSysrootLoc(projectNode.get(PreferenceConstants.SYSROOT,"")); | ||
51 | elem.setStrQemuOption(projectNode.get(PreferenceConstants.QEMU_OPTION,"")); | ||
52 | String sTemp = projectNode.get(PreferenceConstants.TARGET_ARCH_INDEX,""); | ||
53 | if (!sTemp.isEmpty()) { | ||
54 | elem.setIntTargetIndex(Integer.valueOf(sTemp).intValue()); | ||
55 | } | ||
56 | |||
57 | if (projectNode.get(PreferenceConstants.SDK_MODE,"").equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
58 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
59 | } else { | ||
60 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
61 | } | ||
62 | |||
63 | if(projectNode.get(PreferenceConstants.TARGET_MODE,"").equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
64 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
65 | } else { | ||
66 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
67 | } | ||
68 | return elem; | ||
69 | } | ||
70 | |||
71 | /* Get POKY Preference settings from project's environment */ | ||
72 | public static YoctoUIElement getElemFromProjectEnv(IProject project) { | ||
73 | YoctoUIElement elem = new YoctoUIElement(); | ||
74 | elem.setStrToolChainRoot(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TOOLCHAIN_ROOT)); | ||
75 | elem.setStrTarget(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TOOLCHAIN_TRIPLET)); | ||
76 | elem.setStrQemuKernelLoc(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.QEMU_KERNEL)); | ||
77 | elem.setStrSysrootLoc(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.SYSROOT)); | ||
78 | elem.setStrQemuOption(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.QEMU_OPTION)); | ||
79 | String sTemp = YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TARGET_ARCH_INDEX); | ||
80 | |||
81 | if (!sTemp.isEmpty()) { | ||
82 | elem.setIntTargetIndex(Integer.valueOf(sTemp).intValue()); | ||
83 | } | ||
84 | |||
85 | if (YoctoSDKUtils.getEnvValue(project, PreferenceConstants.SDK_MODE).equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
86 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
87 | } else { | ||
88 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
89 | } | ||
90 | |||
91 | if(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TARGET_MODE).equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
92 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
93 | } else { | ||
94 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
95 | } | ||
96 | |||
97 | return elem; | ||
98 | } | ||
99 | |||
100 | /* Get profiles and selected profile from the project's preference store */ | ||
101 | public static YoctoProfileElement getProfiles(IProject project) { | ||
102 | IScopeContext projectScope = new ProjectScope(project); | ||
103 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
104 | |||
105 | if (projectNode == null) { | ||
106 | return YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
107 | } | ||
108 | |||
109 | String profiles = projectNode.get(PreferenceConstants.PROFILES, ""); | ||
110 | String selectedProfile = projectNode.get(PreferenceConstants.SELECTED_PROFILE, ""); | ||
111 | |||
112 | return new YoctoProfileElement(profiles, selectedProfile); | ||
113 | } | ||
114 | |||
115 | public static boolean getUseProjectSpecificOption(IProject project) { | ||
116 | IScopeContext projectScope = new ProjectScope(project); | ||
117 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
118 | if (projectNode == null) { | ||
119 | return false; | ||
120 | } | ||
121 | |||
122 | String useProjectSpecificSettingString = projectNode.get(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, | ||
123 | IPreferenceStore.FALSE); | ||
124 | |||
125 | if (useProjectSpecificSettingString.equals(IPreferenceStore.FALSE)) { | ||
126 | return false; | ||
127 | } | ||
128 | |||
129 | return true; | ||
130 | } | ||
131 | |||
132 | /* Save POKY Preference settings to project's preference store */ | ||
133 | public static void saveElem(YoctoUIElement elem, IProject project) { | ||
134 | IScopeContext projectScope = new ProjectScope(project); | ||
135 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
136 | if (projectNode == null) { | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | projectNode.putInt(PreferenceConstants.TARGET_ARCH_INDEX, elem.getIntTargetIndex()); | ||
141 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
142 | projectNode.put(PreferenceConstants.SDK_MODE, IPreferenceStore.TRUE); | ||
143 | } else { | ||
144 | projectNode.put(PreferenceConstants.SDK_MODE, IPreferenceStore.FALSE); | ||
145 | } | ||
146 | projectNode.put(PreferenceConstants.QEMU_KERNEL, elem.getStrQemuKernelLoc()); | ||
147 | projectNode.put(PreferenceConstants.QEMU_OPTION, elem.getStrQemuOption()); | ||
148 | projectNode.put(PreferenceConstants.SYSROOT, elem.getStrSysrootLoc()); | ||
149 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
150 | projectNode.put(PreferenceConstants.TARGET_MODE, IPreferenceStore.TRUE); | ||
151 | } else { | ||
152 | projectNode.put(PreferenceConstants.TARGET_MODE, IPreferenceStore.FALSE); | ||
153 | } | ||
154 | projectNode.put(PreferenceConstants.TOOLCHAIN_ROOT, elem.getStrToolChainRoot()); | ||
155 | projectNode.put(PreferenceConstants.TOOLCHAIN_TRIPLET, elem.getStrTarget()); | ||
156 | |||
157 | try { | ||
158 | projectNode.flush(); | ||
159 | } catch (BackingStoreException e) { | ||
160 | e.printStackTrace(); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | /* Save POKY Preference settings to project's environment */ | ||
165 | public static void saveElemToProjectEnv(YoctoUIElement elem, IProject project) { | ||
166 | ConsoleOutputStream consoleOutStream = null; | ||
167 | |||
168 | try { | ||
169 | YoctoSDKUtils.setEnvironmentVariables(project, elem); | ||
170 | YoctoSDKUtils.createRemoteDebugAndQemuLaunchers(project, elem); | ||
171 | |||
172 | if (project.hasNature(YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID)) { | ||
173 | YoctoSDKAutotoolsProjectNature.configureAutotoolsOptions(project); | ||
174 | } else if (project.hasNature(YoctoSDKCMakeProjectNature.YoctoSDK_CMAKE_NATURE_ID)) { | ||
175 | YoctoSDKCMakeProjectNature.extendProjectEnvironmentForCMake(project); | ||
176 | } | ||
177 | |||
178 | IConsole console = CCorePlugin.getDefault().getConsole("org.yocto.sdk.ide.YoctoConsole"); | ||
179 | console.start(project); | ||
180 | consoleOutStream = console.getOutputStream(); | ||
181 | String messages = YoctoSDKMessages.getString(CONSOLE_MESSAGE); | ||
182 | consoleOutStream.write(messages.getBytes()); | ||
183 | } catch (CoreException e) { | ||
184 | System.out.println(e.getMessage()); | ||
185 | } catch (IOException e) { | ||
186 | System.out.println(e.getMessage()); | ||
187 | } catch (YoctoGeneralException e) { | ||
188 | System.out.println(e.getMessage()); | ||
189 | } finally { | ||
190 | if (consoleOutStream != null) { | ||
191 | try { | ||
192 | consoleOutStream.flush(); | ||
193 | consoleOutStream.close(); | ||
194 | } catch (IOException e) { | ||
195 | // ignore | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
201 | /* Save profiles and selected profile to the project's preference store */ | ||
202 | public static void saveProfiles(YoctoProfileElement profileElement, IProject project) { | ||
203 | IScopeContext projectScope = new ProjectScope(project); | ||
204 | IEclipsePreferences projectPreferences = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
205 | |||
206 | if (projectPreferences == null) { | ||
207 | return; | ||
208 | } | ||
209 | |||
210 | projectPreferences.put(PreferenceConstants.PROFILES, profileElement.getProfilesAsString()); | ||
211 | projectPreferences.put(PreferenceConstants.SELECTED_PROFILE, profileElement.getSelectedProfile()); | ||
212 | |||
213 | try { | ||
214 | projectPreferences.flush(); | ||
215 | } catch (BackingStoreException e) { | ||
216 | // TODO Auto-generated catch block | ||
217 | e.printStackTrace(); | ||
218 | } | ||
219 | } | ||
220 | |||
221 | public static void saveUseProjectSpecificOption(IProject project, boolean useProjectSpecificSetting) { | ||
222 | IScopeContext projectScope = new ProjectScope(project); | ||
223 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
224 | if (projectNode == null) { | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | if (useProjectSpecificSetting) { | ||
229 | projectNode.put(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, IPreferenceStore.TRUE); | ||
230 | } else { | ||
231 | projectNode.put(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, IPreferenceStore.FALSE); | ||
232 | } | ||
233 | |||
234 | try { | ||
235 | projectNode.flush(); | ||
236 | } catch (BackingStoreException e) { | ||
237 | e.printStackTrace(); | ||
238 | } | ||
239 | } | ||
240 | } | ||