blob: f467dac7747baac906235da4605bddfcda893b65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*******************************************************************************
* Copyright (c) 2012 Intel Corporation.
* 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:
* Intel - initial API and implementation
*******************************************************************************/
package org.yocto.sdk.ide.wizard;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
import org.eclipse.cdt.core.templateengine.process.processes.Messages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.yocto.sdk.ide.YoctoSDKMessages;
import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature;
public class NewYoctoAutotoolsProjectPostProcess extends ProcessRunner {
public static final String CHMOD_COMMAND = "chmod +x "; //$NON-NLS-1$
public static final String AUTOGEN_SCRIPT_NAME = "autogen.sh"; //$NON-NLS-1$
public NewYoctoAutotoolsProjectPostProcess() {}
public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
String projectName = args[0].getSimpleValue();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
try {
if (!project.exists()) {
throw new ProcessFailureException(Messages.getString("NewManagedProject.4") + projectName); //$NON-NLS-1$
} else if (!project.hasNature(YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID)) {
throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + //$NON-NLS-1$
YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.WrongProjectNature", //$NON-NLS-1$
projectName));
} else {
IPath path = project.getLocation();
String path_str = path.toString();
String autogen_cmd = CHMOD_COMMAND + path_str + File.separator + AUTOGEN_SCRIPT_NAME;
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(autogen_cmd);
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
String error_message = ""; //$NON-NLS-1$
while ( (line = br.readLine()) != null) {
error_message = error_message + line;
}
int exitVal = proc.waitFor();
if (exitVal != 0) {
throw new ProcessFailureException(
YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.ChmodFailure", //$NON-NLS-1$
projectName));
}
} catch (Throwable t) {
t.printStackTrace();
}
}
} catch (Exception e) {
throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage(), e); //$NON-NLS-1$
}
}
}
|