15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.helium.quality.ant.taskdefs; |
18 package com.nokia.helium.quality.ant.taskdefs; |
19 |
19 |
20 import java.io.*; |
20 import java.io.File; |
21 import java.util.Vector; |
21 import java.util.Vector; |
22 |
22 |
|
23 import org.apache.tools.ant.BuildException; |
23 import org.apache.tools.ant.Task; |
24 import org.apache.tools.ant.Task; |
24 import org.apache.tools.ant.BuildException; |
25 import org.apache.tools.ant.taskdefs.ExecTask; |
25 import org.apache.tools.ant.types.Path; |
26 import org.apache.tools.ant.types.Path; |
26 import org.apache.tools.ant.taskdefs.ExecTask; |
|
27 |
27 |
28 /** |
28 /** |
29 * This task executes codescanner - and writes the results to the output directory. |
29 * This task executes codescanner - and writes the results to the output directory. Codescanner |
30 * Codescanner parses C++ code and flags any inconsistencies or errors in output files. |
30 * parses C++ code and flags any inconsistencies or errors in output files. Configuration files are |
31 * Configuration files are used to determine what passes and fails the checking e.g. maximum length of lines, |
31 * used to determine what passes and fails the checking e.g. maximum length of lines, whether 'C' |
32 * whether 'C' type comments are allowed as well as C++ comments, does it adhere to the company coding |
32 * type comments are allowed as well as C++ comments, does it adhere to the company coding |
33 * guidelines and much more. Every person writing any C++ code |
33 * guidelines and much more. Every person writing any C++ code should run codescanner on their code |
34 * should run codescanner on their code to ensure it follows the coding guidelines. The output logs |
34 * to ensure it follows the coding guidelines. The output logs should have no errors and preferably |
35 * should have no errors and preferably no warnings before the code should be checked into SCM, e.g. synergy or SVN. |
35 * no warnings before the code should be checked into SCM, e.g. synergy or SVN. |
36 * |
36 * |
37 * Below is an example of how to use the target to run codescanner. |
37 * Below is an example of how to use the target to run codescanner. |
38 * |
38 * |
39 * <pre> |
39 * <pre> |
40 * <property name="codescanner.output.dir" location="./cs" /> |
40 * <property name="codescanner.output.dir" location="./cs" /> |
41 * <property name="codescanner.output.type" value="html" /> |
41 * <property name="codescanner.output.type" value="html" /> |
42 * <property name="codescanner.config" location="./codescanner_config.xml" /> |
42 * <property name="codescanner.config" location="./codescanner_config.xml" /> |
43 * |
43 * |
44 * <hlm:codescanner dest="${codescanner.output.dir}" |
44 * <hlm:codescanner dest="${codescanner.output.dir}" |
45 * format="${codescanner.output.type}" |
45 * format="${codescanner.output.type}" |
46 * failonerror="true" |
46 * failonerror="true" |
47 * configuration="${codescanner.config}"> |
47 * configuration="${codescanner.config}"> |
48 * <path refid="src.path"/> |
48 * <path refid="src.path"/> |
161 * {@inheritDoc} |
160 * {@inheritDoc} |
162 */ |
161 */ |
163 @Override |
162 @Override |
164 public void execute() { |
163 public void execute() { |
165 // creating the exec subtask |
164 // creating the exec subtask |
166 String osType = System.getProperty("os.name"); |
|
167 if (!osType.toLowerCase().startsWith("win")) { |
|
168 this.log("CODESCANNER: run in windows only"); |
|
169 return; |
|
170 } |
|
171 ExecTask task = new ExecTask(); |
165 ExecTask task = new ExecTask(); |
172 task.setProject(getProject()); |
166 task.setProject(getProject()); |
173 task.setTaskName(this.getTaskName()); |
167 task.setTaskName(this.getTaskName()); |
174 task.setFailonerror(failonerror); |
168 task.setFailonerror(failonerror); |
175 task.setExecutable("codescanner"); |
169 task.setExecutable("codescanner"); |
177 if (dest == null) { |
171 if (dest == null) { |
178 throw new BuildException("'dest' attribute must be defined"); |
172 throw new BuildException("'dest' attribute must be defined"); |
179 } |
173 } |
180 if (configuration != null) { |
174 if (configuration != null) { |
181 if (!configuration.exists()) { |
175 if (!configuration.exists()) { |
182 throw new BuildException("Could not find the file " |
176 throw new BuildException("Could not find the file " + configuration); |
183 + configuration); |
177 } |
184 } else { |
178 else { |
185 task.createArg().setValue("-c"); |
179 task.createArg().setValue("-c"); |
186 task.createArg().setValue(configuration.getAbsolutePath()); |
180 task.createArg().setValue(configuration.getAbsolutePath()); |
187 } |
181 } |
188 } else { |
182 } |
189 throw new BuildException( |
183 else { |
190 "'configuration' attribute must be defined"); |
184 throw new BuildException("'configuration' attribute must be defined"); |
191 } |
185 } |
192 if (!format.contains("xml")) { |
186 if (!format.contains("xml")) { |
193 setFormat("xml," + format); |
187 setFormat("xml," + format); |
194 } |
188 } |
195 this.log("Output format: " + format); |
189 this.log("Output format: " + format); |
196 // -t off |
190 // -t off |
197 task.createArg().setValue("-t"); |
191 task.createArg().setValue("-t"); |
198 task.createArg().setValue(auto ? "on" : "off"); |
192 task.createArg().setValue(auto ? "on" : "off"); |
222 } |
216 } |
223 for (int i = 0; i < srcs.size(); i++) { |
217 for (int i = 0; i < srcs.size(); i++) { |
224 if (i != srcs.size() - 1) { |
218 if (i != srcs.size() - 1) { |
225 task.createArg().setValue("-i"); |
219 task.createArg().setValue("-i"); |
226 task.createArg().setValue(srcs.elementAt(i)); |
220 task.createArg().setValue(srcs.elementAt(i)); |
227 } else { |
221 } |
|
222 else { |
228 task.createArg().setValue(srcs.elementAt(i)); |
223 task.createArg().setValue(srcs.elementAt(i)); |
229 task.createArg().setValue(dest.toString()); |
224 task.createArg().setValue(dest.toString()); |
230 } |
225 } |
231 } |
226 } |
232 // output path |
227 // output path |