diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard | |
download | eclipse-poky-juno-master.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard')
2 files changed, 351 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java new file mode 100644 index 0000000..f467dac --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java | |||
@@ -0,0 +1,81 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2012 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.wizard; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.InputStream; | ||
16 | import java.io.InputStreamReader; | ||
17 | |||
18 | import org.eclipse.cdt.core.templateengine.TemplateCore; | ||
19 | import org.eclipse.cdt.core.templateengine.process.ProcessArgument; | ||
20 | import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; | ||
21 | import org.eclipse.cdt.core.templateengine.process.ProcessRunner; | ||
22 | import org.eclipse.cdt.core.templateengine.process.processes.Messages; | ||
23 | import org.eclipse.core.resources.IProject; | ||
24 | import org.eclipse.core.resources.ResourcesPlugin; | ||
25 | import org.eclipse.core.runtime.IPath; | ||
26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
27 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
28 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
29 | |||
30 | public class NewYoctoAutotoolsProjectPostProcess extends ProcessRunner { | ||
31 | |||
32 | public static final String CHMOD_COMMAND = "chmod +x "; //$NON-NLS-1$ | ||
33 | public static final String AUTOGEN_SCRIPT_NAME = "autogen.sh"; //$NON-NLS-1$ | ||
34 | |||
35 | public NewYoctoAutotoolsProjectPostProcess() {} | ||
36 | |||
37 | public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException { | ||
38 | |||
39 | String projectName = args[0].getSimpleValue(); | ||
40 | |||
41 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); | ||
42 | try { | ||
43 | if (!project.exists()) { | ||
44 | throw new ProcessFailureException(Messages.getString("NewManagedProject.4") + projectName); //$NON-NLS-1$ | ||
45 | } else if (!project.hasNature(YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID)) { | ||
46 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + //$NON-NLS-1$ | ||
47 | YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.WrongProjectNature", //$NON-NLS-1$ | ||
48 | projectName)); | ||
49 | } else { | ||
50 | IPath path = project.getLocation(); | ||
51 | String path_str = path.toString(); | ||
52 | String autogen_cmd = CHMOD_COMMAND + path_str + File.separator + AUTOGEN_SCRIPT_NAME; | ||
53 | try { | ||
54 | Runtime rt = Runtime.getRuntime(); | ||
55 | Process proc = rt.exec(autogen_cmd); | ||
56 | InputStream stdin = proc.getInputStream(); | ||
57 | InputStreamReader isr = new InputStreamReader(stdin); | ||
58 | BufferedReader br = new BufferedReader(isr); | ||
59 | String line = null; | ||
60 | String error_message = ""; //$NON-NLS-1$ | ||
61 | |||
62 | while ( (line = br.readLine()) != null) { | ||
63 | error_message = error_message + line; | ||
64 | } | ||
65 | |||
66 | int exitVal = proc.waitFor(); | ||
67 | if (exitVal != 0) { | ||
68 | throw new ProcessFailureException( | ||
69 | YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.ChmodFailure", //$NON-NLS-1$ | ||
70 | projectName)); | ||
71 | } | ||
72 | } catch (Throwable t) { | ||
73 | t.printStackTrace(); | ||
74 | |||
75 | } | ||
76 | } | ||
77 | } catch (Exception e) { | ||
78 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage(), e); //$NON-NLS-1$ | ||
79 | } | ||
80 | } | ||
81 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java new file mode 100644 index 0000000..d8c1232 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java | |||
@@ -0,0 +1,270 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.wizard; | ||
12 | |||
13 | import java.util.Arrays; | ||
14 | import java.util.LinkedHashMap; | ||
15 | import java.util.List; | ||
16 | import java.util.regex.Matcher; | ||
17 | import java.util.regex.Pattern; | ||
18 | |||
19 | import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; | ||
20 | import org.eclipse.cdt.core.CCorePlugin; | ||
21 | import org.eclipse.cdt.core.templateengine.TemplateCore; | ||
22 | import org.eclipse.cdt.core.templateengine.process.ProcessArgument; | ||
23 | import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; | ||
24 | import org.eclipse.cdt.core.templateengine.process.ProcessRunner; | ||
25 | import org.eclipse.cdt.core.templateengine.process.processes.Messages; | ||
26 | import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfigurationManager; | ||
27 | import org.eclipse.cdt.make.core.MakeCorePlugin; | ||
28 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager; | ||
29 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; | ||
30 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerProjectDiscoveredPathInfo; | ||
31 | import org.eclipse.cdt.make.internal.core.scannerconfig.util.SymbolEntry; | ||
32 | import org.eclipse.cdt.managedbuilder.core.BuildException; | ||
33 | import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
34 | import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; | ||
35 | import org.eclipse.cdt.managedbuilder.core.IOption; | ||
36 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; | ||
37 | import org.eclipse.cdt.managedbuilder.templateengine.ProjectCreatedActions; | ||
38 | import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager; | ||
39 | import org.eclipse.jface.wizard.IWizardPage; | ||
40 | import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; | ||
41 | import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard; | ||
42 | import org.eclipse.core.resources.IProject; | ||
43 | import org.eclipse.core.resources.IWorkspace; | ||
44 | import org.eclipse.core.resources.IWorkspaceDescription; | ||
45 | import org.eclipse.core.resources.ResourcesPlugin; | ||
46 | import org.eclipse.core.runtime.CoreException; | ||
47 | import org.eclipse.core.runtime.IPath; | ||
48 | import org.eclipse.core.runtime.IProgressMonitor; | ||
49 | import org.eclipse.core.runtime.OperationCanceledException; | ||
50 | import org.eclipse.core.runtime.Path; | ||
51 | import org.eclipse.jface.preference.IPreferenceStore; | ||
52 | import org.yocto.sdk.ide.YoctoGeneralException; | ||
53 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
54 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
55 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
56 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
57 | import org.yocto.sdk.ide.YoctoUIElement; | ||
58 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
59 | import org.yocto.sdk.ide.natures.YoctoSDKCMakeProjectNature; | ||
60 | import org.yocto.sdk.ide.natures.YoctoSDKEmptyProjectNature; | ||
61 | import org.yocto.sdk.ide.natures.YoctoSDKNatureUtils; | ||
62 | import org.yocto.sdk.ide.natures.YoctoSDKProjectNature; | ||
63 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
64 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
65 | |||
66 | @SuppressWarnings("restriction") | ||
67 | public class NewYoctoProjectTemplateProcess extends ProcessRunner { | ||
68 | protected boolean savedAutoBuildingValue; | ||
69 | protected ProjectCreatedActions pca; | ||
70 | protected IManagedBuildInfo info; | ||
71 | protected List<Character> illegalChars = Arrays.asList('$', '"','#','%','&','\'','(',')','*', '+', ',','.','/',':',';','<','=','>','?','@','[','\\',']','^','`','{','|','}','~'); | ||
72 | private static final String PROJECT_NAME_ERROR = "Wizard.SDK.Error.ProjectName"; | ||
73 | |||
74 | private boolean isCProject; | ||
75 | private boolean isEmptyProject; | ||
76 | private boolean isAutotoolsProject; | ||
77 | private boolean isCMakeProject; | ||
78 | |||
79 | public NewYoctoProjectTemplateProcess() { | ||
80 | pca = new ProjectCreatedActions(); | ||
81 | |||
82 | isCProject = false; | ||
83 | isEmptyProject = false; | ||
84 | isAutotoolsProject = false; | ||
85 | isCMakeProject = false; | ||
86 | } | ||
87 | |||
88 | private String printIllegalChars(){ | ||
89 | String print = ""; | ||
90 | for (Character ch : illegalChars) | ||
91 | print += ch + ", "; | ||
92 | print = print.substring(0, print.length() - 2); | ||
93 | return print; | ||
94 | } | ||
95 | |||
96 | public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException { | ||
97 | |||
98 | String projectName = args[0].getSimpleValue(); | ||
99 | String location = args[1].getSimpleValue(); | ||
100 | String artifactExtension = args[2].getSimpleValue(); | ||
101 | String isCProjectValue = args[3].getSimpleValue(); | ||
102 | String isEmptyProjetValue = args[4].getSimpleValue(); | ||
103 | String isAutotoolsProjectValue = args[5].getSimpleValue(); | ||
104 | String isCMakeProjectValue = args[6].getSimpleValue(); | ||
105 | |||
106 | isCProject = Boolean.valueOf(isCProjectValue).booleanValue(); | ||
107 | isEmptyProject = Boolean.valueOf(isEmptyProjetValue).booleanValue(); | ||
108 | isAutotoolsProject = Boolean.valueOf(isAutotoolsProjectValue).booleanValue(); | ||
109 | isCMakeProject = Boolean.valueOf(isCMakeProjectValue).booleanValue(); | ||
110 | |||
111 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); | ||
112 | try { | ||
113 | if (!isValidProjectName(projectName)) { | ||
114 | |||
115 | IWizardPage[] pages = MBSCustomPageManager.getPages(); | ||
116 | if(pages != null && pages.length > 0) { | ||
117 | CDTMainWizardPage cdtMainPage = (CDTMainWizardPage)pages[0]; | ||
118 | cdtMainPage.setPageComplete(false); | ||
119 | ICDTCommonProjectWizard wizard = (ICDTCommonProjectWizard) pages[0].getWizard(); | ||
120 | wizard.performCancel(); | ||
121 | |||
122 | project.delete(true, null); | ||
123 | } | ||
124 | throw new ProcessFailureException(YoctoSDKMessages.getFormattedString(PROJECT_NAME_ERROR, new Object[]{projectName, printIllegalChars()})); | ||
125 | } | ||
126 | |||
127 | if (!project.exists()) { | ||
128 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
129 | turnOffAutoBuild(workspace); | ||
130 | |||
131 | IPath locationPath = null; | ||
132 | if (location != null && !location.trim().equals("")) { //$NON-NLS-1$ | ||
133 | locationPath = Path.fromPortableString(location); | ||
134 | } | ||
135 | |||
136 | List<?> configs = template.getTemplateInfo().getConfigurations(); | ||
137 | |||
138 | if (configs == null || configs.size() == 0) { | ||
139 | throw new ProcessFailureException(Messages.getString("NewManagedProject.4") + projectName); //$NON-NLS-1$ | ||
140 | } | ||
141 | |||
142 | pca.setProject(project); | ||
143 | pca.setProjectLocation(locationPath); | ||
144 | pca.setConfigs((IConfiguration[]) configs.toArray(new IConfiguration[configs.size()])); | ||
145 | pca.setArtifactExtension(artifactExtension); | ||
146 | info = pca.createProject(monitor, CCorePlugin.DEFAULT_INDEXER, isCProject); | ||
147 | |||
148 | addNatures(project, false, monitor); | ||
149 | |||
150 | info.setValid(true); | ||
151 | ManagedBuildManager.saveBuildInfo(project, true); | ||
152 | |||
153 | restoreAutoBuild(workspace); | ||
154 | } else { | ||
155 | |||
156 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
157 | turnOffAutoBuild(workspace); | ||
158 | |||
159 | YoctoSDKChecker.checkIfGloballySelectedYoctoProfileIsValid(); | ||
160 | |||
161 | addNatures(project, true, monitor); | ||
162 | |||
163 | //restoreAutoBuild(workspace); | ||
164 | IDiscoveredPathManager manager = MakeCorePlugin.getDefault().getDiscoveryManager(); | ||
165 | IDiscoveredPathInfo pathInfo = manager.getDiscoveredInfo(project); | ||
166 | |||
167 | if (pathInfo instanceof IPerProjectDiscoveredPathInfo) { | ||
168 | IPerProjectDiscoveredPathInfo projectPathInfo = | ||
169 | (IPerProjectDiscoveredPathInfo) pathInfo; | ||
170 | projectPathInfo.setIncludeMap(new LinkedHashMap<String, Boolean>()); | ||
171 | projectPathInfo.setSymbolMap(new LinkedHashMap<String, SymbolEntry>()); | ||
172 | manager.removeDiscoveredInfo(project); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | catch (CoreException e) | ||
177 | { | ||
178 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage(), e); //$NON-NLS-1$ | ||
179 | } | ||
180 | catch (BuildException e) | ||
181 | { | ||
182 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage()); //$NON-NLS-1$ | ||
183 | } | ||
184 | catch (YoctoGeneralException e) | ||
185 | { | ||
186 | try { | ||
187 | project.delete(true, monitor); | ||
188 | } catch (CoreException err) { | ||
189 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage() //$NON-NLS-1$ | ||
190 | + " " + err.getMessage()); //$NON-NLS-1$ | ||
191 | } | ||
192 | throw new OperationCanceledException(Messages.getString("NewManagedProject.3") + e.getMessage()); //$NON-NLS-1$ | ||
193 | } | ||
194 | } | ||
195 | |||
196 | private boolean isValidProjectName(String projectName) { | ||
197 | Pattern pattern = Pattern.compile("^[a-zA-Z][a-zA-Z0-9_\\-]*$"); //$NON-NLS-1$ | ||
198 | Matcher matcher = pattern.matcher(projectName); | ||
199 | return matcher.find(); | ||
200 | } | ||
201 | |||
202 | private void addNatures(IProject project, boolean projectExists, IProgressMonitor monitor) | ||
203 | throws CoreException, YoctoGeneralException { | ||
204 | YoctoSDKNatureUtils.addNature(project, YoctoSDKProjectNature.YoctoSDK_NATURE_ID, monitor); | ||
205 | |||
206 | YoctoSDKChecker.checkIfGloballySelectedYoctoProfileIsValid(); | ||
207 | |||
208 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
209 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
210 | |||
211 | IPreferenceStore selecteProfileStore = YoctoSDKPlugin.getProfilePreferenceStore(profileElement.getSelectedProfile()); | ||
212 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(selecteProfileStore); | ||
213 | YoctoSDKUtils.setEnvironmentVariables(project, elem); | ||
214 | |||
215 | if (isEmptyProject) { | ||
216 | YoctoSDKNatureUtils.addNature(project, YoctoSDKEmptyProjectNature.YoctoSDK_EMPTY_NATURE_ID, monitor); | ||
217 | } | ||
218 | |||
219 | if (isAutotoolsProject) { | ||
220 | AutotoolsNewProjectNature.addAutotoolsNature(project, monitor); | ||
221 | |||
222 | if (!projectExists) { | ||
223 | // For each IConfiguration, create a corresponding Autotools Configuration | ||
224 | for (IConfiguration cfg : pca.getConfigs()) { | ||
225 | AutotoolsConfigurationManager.getInstance().getConfiguration(project, cfg.getName(), true); | ||
226 | } | ||
227 | AutotoolsConfigurationManager.getInstance().saveConfigs(project); | ||
228 | } | ||
229 | |||
230 | YoctoSDKNatureUtils.addNature(project, YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID, monitor); | ||
231 | YoctoSDKAutotoolsProjectNature.configureAutotoolsOptions(project); | ||
232 | } else if (isCMakeProject) { | ||
233 | YoctoSDKNatureUtils.addNature(project, YoctoSDKCMakeProjectNature.YoctoSDK_CMAKE_NATURE_ID, monitor); | ||
234 | YoctoSDKCMakeProjectNature.extendProjectEnvironmentForCMake(project); | ||
235 | } | ||
236 | |||
237 | YoctoSDKUtils.createRemoteDebugAndQemuLaunchers(project, elem); | ||
238 | } | ||
239 | |||
240 | protected final void turnOffAutoBuild(IWorkspace workspace) throws CoreException { | ||
241 | IWorkspaceDescription workspaceDesc = workspace.getDescription(); | ||
242 | savedAutoBuildingValue = workspaceDesc.isAutoBuilding(); | ||
243 | workspaceDesc.setAutoBuilding(false); | ||
244 | workspace.setDescription(workspaceDesc); | ||
245 | } | ||
246 | |||
247 | protected final void restoreAutoBuild(IWorkspace workspace) throws CoreException { | ||
248 | IWorkspaceDescription workspaceDesc = workspace.getDescription(); | ||
249 | workspaceDesc.setAutoBuilding(savedAutoBuildingValue); | ||
250 | workspace.setDescription(workspaceDesc); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * setOptionValue | ||
255 | * @param config | ||
256 | * @param option | ||
257 | * @param val | ||
258 | * @throws BuildException | ||
259 | */ | ||
260 | protected void setOptionValue(IConfiguration config, IOption option, String val) throws BuildException { | ||
261 | if (val != null) { | ||
262 | if (!option.isExtensionElement()) { | ||
263 | option.setValue(val); | ||
264 | } else { | ||
265 | IOption newOption = config.getToolChain().createOption(option, option.getId() + "." + ManagedBuildManager.getRandomNumber(), option.getName(), false); //$NON-NLS-1$ | ||
266 | newOption.setValue(val); | ||
267 | } | ||
268 | } | ||
269 | } | ||
270 | } | ||