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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* 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:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.autotools.ui.editors.automake;
import java.io.File;
import java.io.IOException;
/**
* Makefile : ( statement ) *
* statement : command | ..
* command : <tab> prefix_command string <nl>
* prefix_command : '-' | '@' | '+'
*/
public class Command extends Directive implements ICommand {
final public static char NL = '\n';
String command = ""; //$NON-NLS-1$
char prefix = '\0';
public Command(Directive parent, String cmd) {
super(parent);
parse(cmd);
}
/**
* - If the command prefix contains a hyphen, or the -i option is
* present, or the special target .IGNORE has either the current
* target as a prerequisite or has no prerequisites, any error
* found while executing the command will be ignored.
*/
public boolean shouldIgnoreError() {
// Check for the prefix hyphen in the command.
if (getPrefix() == HYPHEN) {
return true;
}
return false;
}
/**
* @ If the command prefix contains an at sign and the
* command-line -n option is not specified, or the -s option is
* present, or the special target .SILENT has either the current
* target as a prerequisite or has no prerequisites, the command
* will not be written to standard output before it is executed.
*/
public boolean shouldBeSilent() {
// Check for the prefix at sign
if (getPrefix() == AT) {
return true;
}
return false;
}
/**
* + If the command prefix contains a plus sign, this indicates a
* command line that will be executed even if -n, -q or -t is
* specified.
*/
public boolean shouldExecute() {
// Check for the prefix at sign
if (getPrefix() == PLUS) {
return true;
}
return false;
}
public String toString() {
StringBuffer cmd = new StringBuffer();
cmd.append( '\t');
if (getPrefix() != 0) {
cmd.append(getPrefix());
}
cmd.append(command).append('\n');
return cmd.toString();
}
public boolean equals(Object cmd) {
if (cmd instanceof Command)
return cmd.toString().equals(toString());
return false;
}
public int hashCode() {
return toString().hashCode();
}
char getPrefix() {
return prefix;
}
/**
* command : <tab> prefix_command string <nl>
*/
void parse(String cmd) {
command = cmd.trim();
if (command.startsWith(HYPHEN_STRING) || command.startsWith(AT_STRING) || command.startsWith(PLUS_STRING)) {
prefix = command.charAt(0);
command = command.substring(1).trim();
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.ICommand#execute(java.lang.String[], java.io.File)
*/
public Process execute(String shell, String[] envp, File dir) throws IOException {
String[] cmdArray = new String[] { shell, "-c", command}; //$NON-NLS-1$
return Runtime.getRuntime().exec(cmdArray, envp, dir);
}
}
|