diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java')
-rw-r--r-- | plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java | 81 |
1 files changed, 81 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 | } | ||