588
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.helium.quality.ant.taskdefs;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.util.Vector;
|
628
|
21 |
|
588
|
22 |
import org.apache.tools.ant.BuildException;
|
|
23 |
import org.apache.tools.ant.Task;
|
|
24 |
import org.apache.tools.ant.taskdefs.ExecTask;
|
|
25 |
|
|
26 |
import com.nokia.helium.core.ant.types.VariableImpl;
|
|
27 |
import com.nokia.helium.core.ant.types.VariableSet;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* To run the coverity commands.
|
|
31 |
*
|
|
32 |
*
|
|
33 |
* <pre>
|
|
34 |
* <hlm:coverity command="cov-link" dir="${build.drive}/">
|
|
35 |
* <hlm:arg name="--dir" value="${coverity.output.dir}/intermidiate"/>
|
|
36 |
* <hlm:arg name="--compile-arg" value="armv5"/>
|
|
37 |
* <hlm:arg name="--output" value="${coverity.output.dir}/coveritylink/armv5.link"/>
|
|
38 |
* <hlm:arg name="${coverity.output.dir}/coveritylink/all.link" value=""/>
|
|
39 |
* </hlm:coverity >
|
|
40 |
*
|
|
41 |
* </pre>
|
|
42 |
*
|
|
43 |
* @ant.task name="coverity" category="Quality".
|
|
44 |
*
|
|
45 |
*/
|
|
46 |
|
|
47 |
public class CoverityTask extends Task {
|
|
48 |
|
|
49 |
private String command;
|
|
50 |
private boolean failOnError;
|
|
51 |
private boolean execute = true;
|
628
|
52 |
private boolean append;
|
|
53 |
private File error;
|
588
|
54 |
private String dir;
|
|
55 |
private Vector<VariableSet> coverityOptions = new Vector<VariableSet>();
|
|
56 |
private Vector<VariableImpl> coverityArgs = new Vector<VariableImpl>();
|
|
57 |
|
|
58 |
public void execute() {
|
|
59 |
|
|
60 |
validateParameters();
|
|
61 |
|
|
62 |
runCommand(command);
|
|
63 |
|
|
64 |
}
|
|
65 |
|
|
66 |
/**
|
|
67 |
* To run the command passed into coverity task.
|
|
68 |
*
|
|
69 |
* @param command
|
|
70 |
*/
|
|
71 |
private void runCommand(String command) {
|
|
72 |
|
|
73 |
String commandString = command;
|
|
74 |
if (!command.startsWith("cov-")) {
|
|
75 |
throw new BuildException(
|
|
76 |
"Coverity task can run only coverity prevent tool commands.");
|
|
77 |
}
|
|
78 |
|
|
79 |
ExecTask task = new ExecTask();
|
|
80 |
task.setProject(getProject());
|
|
81 |
task.setTaskName(this.getTaskName());
|
|
82 |
task.setFailonerror(failOnError);
|
628
|
83 |
task.setError(this.error);
|
|
84 |
task.setAppend(isAppend());
|
588
|
85 |
task.setExecutable(command);
|
|
86 |
task.setDir(new File(this.dir));
|
|
87 |
|
|
88 |
for (VariableSet coverityArg : coverityOptions) {
|
|
89 |
task.createArg().setLine(coverityArg.getParameter(" "));
|
|
90 |
commandString += " " + coverityArg.getParameter(" ");
|
|
91 |
}
|
|
92 |
for (VariableImpl coverityArg : coverityArgs) {
|
|
93 |
task.createArg().setLine(coverityArg.getParameter(" "));
|
|
94 |
commandString += " " + coverityArg.getParameter(" ");
|
|
95 |
}
|
|
96 |
|
|
97 |
try {
|
|
98 |
log("run command: " + commandString);
|
|
99 |
if (execute) {
|
|
100 |
task.execute();
|
|
101 |
}
|
|
102 |
} catch (BuildException be) {
|
|
103 |
if (failOnError) {
|
|
104 |
throw new BuildException("exception during coverity command '"
|
|
105 |
+ command + "' execution:", be);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* To validate the parameters passed into coverity task.
|
|
113 |
*/
|
|
114 |
private void validateParameters() {
|
|
115 |
if (command == null) {
|
|
116 |
throw new BuildException(
|
|
117 |
"'command' parameter should not be null for coverity task.");
|
|
118 |
}
|
|
119 |
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* @param command
|
|
124 |
* the command to set
|
|
125 |
* @ant.required
|
|
126 |
*/
|
|
127 |
public void setCommand(String command) {
|
|
128 |
this.command = command;
|
|
129 |
}
|
|
130 |
|
|
131 |
/**
|
|
132 |
* @return the command
|
|
133 |
*/
|
|
134 |
public String getCommand() {
|
|
135 |
return command;
|
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
|
139 |
* @param failOnError
|
|
140 |
* the failOnError to set
|
|
141 |
* @ant.not-required
|
|
142 |
*/
|
|
143 |
public void setFailOnError(boolean failOnError) {
|
|
144 |
this.failOnError = failOnError;
|
|
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* @return the dir
|
|
149 |
*/
|
|
150 |
public String getDir() {
|
|
151 |
return dir;
|
|
152 |
}
|
|
153 |
|
|
154 |
/**
|
|
155 |
* @param dir
|
|
156 |
* the dir to set
|
|
157 |
* @ant.not-required
|
|
158 |
*/
|
|
159 |
public void setDir(String dir) {
|
|
160 |
this.dir = dir;
|
|
161 |
}
|
|
162 |
|
|
163 |
/**
|
|
164 |
* @param execute
|
|
165 |
* the execute to set
|
|
166 |
*/
|
|
167 |
public void setExecute(boolean execute) {
|
|
168 |
this.execute = execute;
|
|
169 |
}
|
|
170 |
|
|
171 |
/**
|
628
|
172 |
* @return the errorFile
|
|
173 |
*/
|
|
174 |
public File getError() {
|
|
175 |
return error;
|
|
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* @param errorFile the errorFile to set
|
|
180 |
*/
|
|
181 |
public void setError(File errorFile) {
|
|
182 |
this.error = errorFile;
|
|
183 |
}
|
|
184 |
|
|
185 |
/**
|
|
186 |
* @param append the append to set
|
|
187 |
*/
|
|
188 |
public void setAppend(boolean append) {
|
|
189 |
this.append = append;
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* @return the append
|
|
194 |
*/
|
|
195 |
public boolean isAppend() {
|
|
196 |
return append;
|
|
197 |
}
|
|
198 |
|
|
199 |
/**
|
588
|
200 |
* To read the coverity arguments for coverity commands.
|
|
201 |
*
|
|
202 |
* @param variableArg
|
|
203 |
*/
|
|
204 |
public void addCoverityOptions(VariableSet coverityArg) {
|
|
205 |
if (!coverityOptions.contains(coverityArg)) {
|
|
206 |
coverityOptions.add(coverityArg);
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
/**
|
|
211 |
* To read the individual arguments.
|
|
212 |
*
|
|
213 |
* @param coverityArg
|
|
214 |
*/
|
|
215 |
public void addArg(VariableImpl coverityArg) {
|
|
216 |
if (!coverityArgs.contains(coverityArg)) {
|
|
217 |
coverityArgs.add(coverityArg);
|
|
218 |
}
|
|
219 |
}
|
628
|
220 |
|
588
|
221 |
|
|
222 |
}
|