Date | 2007/07/27 |
---|---|
Codebase | 5801 |
Reviews | 11354 |
DPMO | 657 |
Sigma | 4.713 |
Name | Number | Min | Avg | Max | Total |
---|---|---|---|---|---|
Class complexity | 1 | 62.00 | 62.00 | 62.00 | 62.00 |
Code length | 16 | 1.00 | 19.87 | 153.00 | 318.00 |
File length | 1 | 526.00 | 526.00 | 526.00 | 526.00 |
Operation complexity | 16 | 1.00 | 3.87 | 21.00 | 62.00 |
Work order | 1 | 4.01 | 4.01 | 4.01 | 4.01 |
# | Line | Column | Name | Severity | Description |
---|---|---|---|---|---|
1 | 23 | 1 | ER-023 | 3 | Packages should begin with [] |
2 | 102 | 84 | ER-036 | 3 | Line is too long |
3 | 191 | 86 | ER-036 | 3 | Line is too long |
4 | 197 | 96 | ER-036 | 3 | Line is too long |
5 | 199 | 100 | ER-036 | 3 | Line is too long |
6 | 214 | 117 | ER-036 | 3 | Line is too long |
7 | 217 | 106 | ER-036 | 3 | Line is too long |
8 | 229 | 94 | ER-036 | 3 | Line is too long |
9 | 232 | 112 | ER-036 | 3 | Line is too long |
10 | 237 | 96 | ER-036 | 3 | Line is too long |
11 | 241 | 118 | ER-036 | 3 | Line is too long |
12 | 249 | 91 | ER-036 | 3 | Line is too long |
13 | 253 | 114 | ER-036 | 3 | Line is too long |
14 | 265 | 83 | ER-036 | 3 | Line is too long |
15 | 272 | 110 | ER-036 | 3 | Line is too long |
16 | 273 | 109 | ER-036 | 3 | Line is too long |
17 | 274 | 84 | ER-036 | 3 | Line is too long |
18 | 275 | 105 | ER-036 | 3 | Line is too long |
19 | 276 | 98 | ER-036 | 3 | Line is too long |
20 | 277 | 109 | ER-036 | 3 | Line is too long |
21 | 280 | 137 | ER-036 | 3 | Line is too long |
22 | 290 | 81 | ER-036 | 3 | Line is too long |
23 | 292 | 89 | ER-036 | 3 | Line is too long |
24 | 293 | 109 | ER-036 | 3 | Line is too long |
25 | 294 | 85 | ER-036 | 3 | Line is too long |
26 | 296 | 87 | ER-036 | 3 | Line is too long |
27 | 299 | 147 | ER-036 | 3 | Line is too long |
28 | 308 | 84 | ER-036 | 3 | Line is too long |
29 | 311 | 85 | ER-036 | 3 | Line is too long |
30 | 313 | 92 | ER-036 | 3 | Line is too long |
31 | 350 | 102 | ER-036 | 3 | Line is too long |
32 | 431 | 108 | ER-036 | 3 | Line is too long |
33 | 455 | 84 | ER-036 | 3 | Line is too long |
34 | 81 | 1 | ER-049 | 2 | Unify logging strategy - define individual logger for class |
35 | 91 | 30 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
36 | 101 | 40 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
37 | 112 | 30 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
38 | 123 | 31 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
39 | 134 | 34 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
40 | 134 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
41 | 149 | 33 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
42 | 159 | 31 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
43 | 166 | 35 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
44 | 166 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
45 | 182 | 42 | ER-028 | 3 | Avoid hardwired character literals |
46 | 184 | 28 | ER-030 | 3 | Avoid hardwired string literals |
47 | 187 | 29 | ER-017-E | 2 | Do not assign new value to a parameter. For comprehensibility, formal parameters should be final |
48 | 191 | 82 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
49 | 191 | 41 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
50 | 191 | 38 | ER-030 | 3 | Avoid hardwired string literals |
51 | 199 | 68 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
52 | 199 | 61 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
53 | 199 | 25 | ER-030 | 3 | Avoid hardwired string literals |
54 | 199 | 62 | ER-030 | 3 | Avoid hardwired string literals |
55 | 201 | 45 | ER-029 | 3 | Avoid hardwired numeric literals |
56 | 212 | 29 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
57 | 214 | 91 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
58 | 214 | 81 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
59 | 214 | 74 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
60 | 214 | 33 | ER-030 | 3 | Avoid hardwired string literals |
61 | 214 | 75 | ER-030 | 3 | Avoid hardwired string literals |
62 | 214 | 92 | ER-030 | 3 | Avoid hardwired string literals |
63 | 215 | 73 | ER-030 | 3 | Avoid hardwired string literals |
64 | 217 | 84 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
65 | 217 | 81 | ER-030 | 3 | Avoid hardwired string literals |
66 | 227 | 9 | ER-011 | 1 | Cyclomatic complexity (21) exceeds 12 |
67 | 227 | 9 | ER-041 | 2 | Method is too long |
68 | 227 | 38 | ER-047 | 2 | Operation (method or constructor) declares subclasses of RuntimeException in throws clause |
69 | 227 | 9 | ER-105 | 3 | Document all Interfaces and public methods. Use a Class header. Provide Javadoc |
70 | 233 | 59 | ER-030 | 3 | Avoid hardwired string literals |
71 | 237 | 51 | ER-030 | 3 | Avoid hardwired string literals |
72 | 237 | 83 | ER-030 | 3 | Avoid hardwired string literals |
73 | 237 | 91 | ER-030 | 3 | Avoid hardwired string literals |
74 | 241 | 51 | ER-030 | 3 | Avoid hardwired string literals |
75 | 241 | 105 | ER-030 | 3 | Avoid hardwired string literals |
76 | 241 | 113 | ER-030 | 3 | Avoid hardwired string literals |
77 | 245 | 51 | ER-030 | 3 | Avoid hardwired string literals |
78 | 249 | 51 | ER-030 | 3 | Avoid hardwired string literals |
79 | 253 | 51 | ER-030 | 3 | Avoid hardwired string literals |
80 | 257 | 51 | ER-030 | 3 | Avoid hardwired string literals |
81 | 262 | 51 | ER-030 | 3 | Avoid hardwired string literals |
82 | 265 | 71 | ER-030 | 3 | Avoid hardwired string literals |
83 | 269 | 39 | ER-102 | 2 | String Arrays are deprecated and are ONLY allowed for final variables |
84 | 269 | 39 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
85 | 273 | 72 | ER-030 | 3 | Avoid hardwired string literals |
86 | 275 | 98 | ER-030 | 3 | Avoid hardwired string literals |
87 | 280 | 97 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
88 | 280 | 53 | ER-030 | 3 | Avoid hardwired string literals |
89 | 280 | 98 | ER-030 | 3 | Avoid hardwired string literals |
90 | 285 | 69 | ER-030 | 3 | Avoid hardwired string literals |
91 | 293 | 56 | ER-030 | 3 | Avoid hardwired string literals |
92 | 294 | 76 | ER-030 | 3 | Avoid hardwired string literals |
93 | 297 | 39 | ER-102 | 2 | String Arrays are deprecated and are ONLY allowed for final variables |
94 | 297 | 39 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
95 | 299 | 104 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
96 | 299 | 101 | ER-030 | 3 | Avoid hardwired string literals |
97 | 299 | 142 | ER-028 | 3 | Avoid hardwired character literals |
98 | 308 | 56 | ER-030 | 3 | Avoid hardwired string literals |
99 | 310 | 60 | ER-116 | 3 | Use StringBuffer for excessive String concatenation |
100 | 310 | 57 | ER-030 | 3 | Avoid hardwired string literals |
101 | 311 | 76 | ER-030 | 3 | Avoid hardwired string literals |
102 | 317 | 59 | ER-030 | 3 | Avoid hardwired string literals |
103 | 323 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
104 | 325 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
105 | 327 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
106 | 329 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
107 | 339 | 46 | ER-030 | 3 | Avoid hardwired string literals |
108 | 350 | 29 | ER-030 | 3 | Avoid hardwired string literals |
109 | 358 | 9 | ER-011 | 1 | Cyclomatic complexity (16) exceeds 12 |
110 | 358 | 9 | ER-041 | 2 | Method is too long |
111 | 359 | 27 | ER-111 | 1 | LOG4J is mandatory for all logging in ERC. System.out.println will be lost in a system console of our web/app server. |
112 | 359 | 28 | ER-030 | 3 | Avoid hardwired string literals |
113 | 364 | 22 | ER-030 | 3 | Avoid hardwired string literals |
114 | 366 | 26 | ER-030 | 3 | Avoid hardwired string literals |
115 | 368 | 17 | ER-030 | 3 | Avoid hardwired string literals |
116 | 373 | 22 | ER-030 | 3 | Avoid hardwired string literals |
117 | 375 | 26 | ER-030 | 3 | Avoid hardwired string literals |
118 | 377 | 17 | ER-030 | 3 | Avoid hardwired string literals |
119 | 382 | 22 | ER-030 | 3 | Avoid hardwired string literals |
120 | 384 | 26 | ER-030 | 3 | Avoid hardwired string literals |
121 | 386 | 17 | ER-030 | 3 | Avoid hardwired string literals |
122 | 391 | 26 | ER-030 | 3 | Avoid hardwired string literals |
123 | 392 | 30 | ER-030 | 3 | Avoid hardwired string literals |
124 | 395 | 17 | ER-030 | 3 | Avoid hardwired string literals |
125 | 400 | 26 | ER-030 | 3 | Avoid hardwired string literals |
126 | 402 | 17 | ER-030 | 3 | Avoid hardwired string literals |
127 | 407 | 26 | ER-030 | 3 | Avoid hardwired string literals |
128 | 409 | 17 | ER-030 | 3 | Avoid hardwired string literals |
129 | 414 | 26 | ER-030 | 3 | Avoid hardwired string literals |
130 | 415 | 30 | ER-030 | 3 | Avoid hardwired string literals |
131 | 418 | 17 | ER-030 | 3 | Avoid hardwired string literals |
132 | 422 | 9 | ER-113 | 2 | Unused private/local variables |
133 | 423 | 22 | ER-030 | 3 | Avoid hardwired string literals |
134 | 425 | 26 | ER-030 | 3 | Avoid hardwired string literals |
135 | 427 | 17 | ER-030 | 3 | Avoid hardwired string literals |
136 | 431 | 57 | ER-030 | 3 | Avoid hardwired string literals |
137 | 431 | 104 | ER-030 | 3 | Avoid hardwired string literals |
138 | 438 | 11 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
139 | 444 | 28 | ER-030 | 3 | Avoid hardwired string literals |
140 | 453 | 23 | ER-102 | 2 | String Arrays are deprecated and are ONLY allowed for final variables |
141 | 453 | 23 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
142 | 453 | 54 | ER-028 | 3 | Avoid hardwired character literals |
143 | 458 | 15 | ER-102 | 2 | String Arrays are deprecated and are ONLY allowed for final variables |
144 | 458 | 15 | ER-104 | 2 | Use a Collection instead of arrays Object[] |
145 | 460 | 35 | ER-111 | 1 | LOG4J is mandatory for all logging in ERC. System.out.println will be lost in a system console of our web/app server. |
146 | 460 | 36 | ER-030 | 3 | Avoid hardwired string literals |
147 | 464 | 28 | ER-028 | 3 | Avoid hardwired character literals |
148 | 468 | 28 | ER-028 | 3 | Avoid hardwired character literals |
149 | 472 | 28 | ER-028 | 3 | Avoid hardwired character literals |
150 | 473 | 63 | ER-028 | 3 | Avoid hardwired character literals |
151 | 476 | 36 | ER-028 | 3 | Avoid hardwired character literals |
152 | 477 | 60 | ER-028 | 3 | Avoid hardwired character literals |
153 | 480 | 28 | ER-028 | 3 | Avoid hardwired character literals |
154 | 481 | 63 | ER-028 | 3 | Avoid hardwired character literals |
155 | 484 | 36 | ER-028 | 3 | Avoid hardwired character literals |
156 | 485 | 59 | ER-028 | 3 | Avoid hardwired character literals |
157 | 489 | 36 | ER-028 | 3 | Avoid hardwired character literals |
158 | 490 | 64 | ER-028 | 3 | Avoid hardwired character literals |
159 | 504 | 34 | ER-030 | 3 | Avoid hardwired string literals |
160 | 509 | 19 | ER-103 | 2 | Catch-blocks should log the exeption with Log4J.error("Context String" , exception ) |
161 | 511 | 37 | ER-029 | 3 | Avoid hardwired numeric literals |
162 | 521 | 42 | ER-082 | 3 | Avoid using method parameter names that conflict with class member names |
1/*
2 * Hammurapi
3 * Automated Java code review system.
4 * Copyright (C) 2004 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.org
21 * e-Mail: support@hammurapi.biz
22 */
23package org.hammurapi;
24
25import java.io.File;
26import java.io.FileInputStream;
27import java.io.FileOutputStream;
28import java.io.IOException;
29import java.text.SimpleDateFormat;
30import java.util.Collection;
31import java.util.Date;
32import java.util.HashSet;
33import java.util.Iterator;
34import java.util.LinkedList;
35import java.util.List;
36import java.util.Set;
37import java.util.zip.ZipEntry;
38import java.util.zip.ZipOutputStream;
39
40import javax.xml.parsers.DocumentBuilderFactory;
41import javax.xml.parsers.FactoryConfigurationError;
42import javax.xml.parsers.ParserConfigurationException;
43import javax.xml.transform.TransformerException;
44
45import org.apache.commons.cli.CommandLine;
46import org.apache.commons.cli.CommandLineParser;
47import org.apache.commons.cli.HelpFormatter;
48import org.apache.commons.cli.Option;
49import org.apache.commons.cli.OptionBuilder;
50import org.apache.commons.cli.Options;
51import org.apache.commons.cli.ParseException;
52import org.apache.commons.cli.PosixParser;
53import org.apache.tools.ant.BuildException;
54import org.apache.tools.ant.DirectoryScanner;
55import org.apache.tools.ant.Project;
56import org.apache.tools.ant.Task;
57import org.apache.tools.ant.types.FileSet;
58import org.apache.tools.ant.types.Path;
59import org.w3c.dom.Document;
60import org.w3c.dom.Element;
61
62import com.pavelvlasov.xml.dom.DOMUtils;
63
64/**
65 * Packages source files and classpath entries for Hammurapi review.
66 * <section name="Example" suppress-description="yes">
67If you copy content of Hammurapi lib directory to ant lib directory then you can
68invoke Hammurapi in the following way:
69 <pre><taskdef name="har" classname="org.hammurapi.HammurapiArchiver" /><br/></pre>
70or, if you didn't copy jar files to Ant lib directory, use this syntax:
71<pre><taskdef name="har" classname="org.hammurapi.HammurapiArchiver"><br/>
72 <tab/><classpath><br/>
73 <tab/><tab/><fileset dir="${hammurapi.home}/lib" includes="*.jar"/><br/>
74 <tab/></classpath><br/>
75</taskdef><br/></pre>
76</section>
77 * @ant.element name="har" display-name="Packager for automatic code review task"
78 * @author Pavel Vlasov
79 * @version $Revision: 1.8 $
80 */
81public class HammurapiArchiver extends Task {
82 static final String DATE_FORMAT="yyyy/MM/dd HH:mm:ss";
83
84 private Boolean force;
85
86 /**
87 * Force review even if the file is not changed
88 * @param force
89 * @ant.non-required
90 */
91 public void setForce(boolean force) {
92 this.force=force ? Boolean.TRUE : Boolean.FALSE;
93 }
94
95 private Boolean forceOnWarnings;
96
97 /**
98 * Force review of files with warnings, even if the file is not changed.
99 * @ant.non-required
100 */
101 public void setForceOnWarnings(boolean forceOnWarnings) {
102 this.forceOnWarnings=forceOnWarnings ? Boolean.TRUE : Boolean.FALSE;
103 }
104
105 private String title;
106
107 /**
108 * Review title
109 * @ant.non-required
110 * @param title
111 */
112 public void setTitle(String title) {
113 this.title=title;
114 }
115
116 private File output;
117
118 /**
119 * Output archive
120 * @ant.required
121 * @param output
122 */
123 public void setOutput(File output) {
124 this.output=output;
125 }
126
127 /**
128 * Classpath for loading classes. Classes and jars from the classpath
129 * are packaged into archive to be used during review.
130 * @ant:non-required
131 */
132 private Path classPath;
133
134 public void setClassPath(Path classPath) {
135 if (this.classPath == null) {
136 this.classPath = classPath;
137 } else {
138 this.classPath.append(classPath);
139 }
140 }
141
142 private Date baseLine;
143
144 /**
145 * Date of baseline report
146 * @ant.non-required
147 * @param baseLine
148 */
149 public void setBaseLine(Date baseLine) {
150 this.baseLine=baseLine;
151 }
152
153 private String hostId;
154
155 /**
156 * Host id to differentiate archives created on different machines.
157 * @ant.non-required
158 */
159 public void setHostId(String hostId) {
160 this.hostId=hostId;
161 }
162
163 //Anu 20050701 start : Added for baselining attribute
164 private String baselining;
165
166 public void setBaselining(String baselining){
167 this.baselining=baselining;
168 }
169
170 /**
171 * Maybe creates a nested classpath element.
172 * @ant:non-required
173 */
174 public Path createClasspath() {
175 if (classPath == null) {
176 classPath = new Path(project);
177 }
178 return classPath.createPath();
179 }
180
181 private String uniquilize(String name, Set names) {
182 int idx=name.lastIndexOf('.');
183 String newName = name;
184 String ext="";
185 if (idx!=-1) {
186 ext=name.substring(idx);
187 name=name.substring(0, idx);
188 }
189
190 for (int i=0; names.contains(newName.toLowerCase()); i++) {
191 newName=name+"_"+Integer.toString(i, Character.MAX_RADIX)+ext;
192 }
193 names.add(newName.toLowerCase());
194 return newName;
195 }
196
197 private int zipFile(File in, ZipOutputStream out, String entryName) throws IOException {
198 if (in.isFile()) {
199 log("Zipping file "+in.getAbsolutePath()+" as "+entryName, Project.MSG_VERBOSE);
200 out.putNextEntry(new ZipEntry(entryName));
201 byte[] buf=new byte[4096];
202 int l;
203 FileInputStream fis=new FileInputStream(in);
204 while ((l=fis.read(buf))!=-1) {
205 out.write(buf, 0, l);
206 }
207 fis.close();
208 out.closeEntry();
209 return 1;
210 } else if (in.isDirectory()) {
211 int ret=0;
212 File[] entries=in.listFiles();
213 if (entries!=null && entries.length>0) {
214 log("Zipping directory "+in.getAbsolutePath()+" as "+entryName+"/", Project.MSG_VERBOSE);
215 out.putNextEntry(new ZipEntry(entryName+"/"));
216 for (int i=0; i<entries.length; i++) {
217 ret+=zipFile(entries[i], out, entryName+"/"+entries[i].getName());
218 }
219 out.closeEntry();
220 }
221 return ret;
222 }
223
224 return 0;
225 }
226
227 public void execute() throws BuildException {
228 try {
229 ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(output));
230 Set entryNames=new HashSet();
231
232 Document config=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
233 Element root=config.createElement("hammurapi-archive");
234 config.appendChild(root);
235
236 if (force!=null) {
237 root.setAttribute("force", force.booleanValue() ? "yes" : "no");
238 }
239
240 if (forceOnWarnings!=null) {
241 root.setAttribute("force-on-warnings", forceOnWarnings.booleanValue() ? "yes" : "no");
242 }
243
244 if (title!=null) {
245 root.setAttribute("title", title);
246 }
247
248 if (reviewDescription!=null) {
249 root.setAttribute("review-description", reviewDescription);
250 }
251
252 if (baseLine!=null) {
253 root.setAttribute("baseline", new SimpleDateFormat(DATE_FORMAT).format(baseLine));
254 }
255
256 if (hostId!=null) {
257 root.setAttribute("host-id", hostId);
258 }
259
260 //Anu 20060701 : Baselining added
261 if (baselining!=null) {
262 root.setAttribute("baselining", baselining);
263 }
264
265 Element classPathElement=config.createElement("classpath");
266 root.appendChild(classPathElement);
267
268 if (classPath!=null) {
269 String[] path=classPath.list();
270 for (int i=0; i<path.length; i++) {
271 File cpEntry=new File(path[i]);
272 if (cpEntry.exists() && (cpEntry.isFile() || cpEntry.isDirectory())) {
273 String name=uniquilize("lib/"+cpEntry.getName(), entryNames);
274 if (zipFile(cpEntry, zos, name)>0) {
275 Element pathElement=config.createElement("path");
276 classPathElement.appendChild(pathElement);
277 pathElement.appendChild(config.createTextNode(name));
278 }
279 } else {
280 log("Classpath entry "+cpEntry.getAbsolutePath()+" does not exist", Project.MSG_VERBOSE);
281 }
282 }
283 }
284
285 Element sourcesElement=config.createElement("sources");
286 root.appendChild(sourcesElement);
287
288 Iterator it=srcFileSets.iterator();
289 while (it.hasNext()) {
290 HammurapiFileSet fs=(HammurapiFileSet) it.next();
291 fs.setDefaultIncludes();
292 DirectoryScanner scanner=fs.getDirectoryScanner(project);
293 String name=uniquilize("source/"+scanner.getBasedir().getName(), entryNames);
294 Element sourceElement=config.createElement("source");
295 sourcesElement.appendChild(sourceElement);
296 sourceElement.appendChild(config.createTextNode(name));
297 String[] files=scanner.getIncludedFiles();
298 for (int i=0; i<files.length; i++) {
299 zipFile(new File(scanner.getBasedir(), files[i]), zos, name+"/"+files[i].replace(File.separatorChar, '/'));
300 }
301 }
302
303 /**
304 * For command-line interface
305 */
306 it=srcFiles.iterator();
307 while (it.hasNext()) {
308 String name=uniquilize("source/source", entryNames);
309 File file = (File) it.next();
310 String entryName = name+"/"+file.getName();
311 Element sourceElement=config.createElement("source");
312 sourcesElement.appendChild(sourceElement);
313 sourceElement.appendChild(config.createTextNode(entryName));
314 zipFile(file, zos, entryName);
315 }
316
317 ZipEntry configEntry=new ZipEntry("config.xml");
318 zos.putNextEntry(configEntry);
319 DOMUtils.serialize(config, zos);
320 zos.closeEntry();
321
322 zos.close();
323 } catch (IOException e) {
324 throw new BuildException(e.getMessage(), e);
325 } catch (ParserConfigurationException e) {
326 throw new BuildException(e.getMessage(), e);
327 } catch (FactoryConfigurationError e) {
328 throw new BuildException(e.getMessage(), e);
329 } catch (TransformerException e) {
330 throw new BuildException(e.getMessage(), e);
331 }
332 }
333
334 /**
335 * Source files fileset.
336 * @ant.non-required
337 */
338 public FileSet createSrc() {
339 FileSet ret=new HammurapiFileSet("**/*.java");
340 srcFileSets.add(ret);
341 return ret;
342 }
343
344 private List srcFileSets = new LinkedList();
345
346 private Collection srcFiles=new LinkedList();
347
348 private static void printHelpAndExit(Options options) {
349 HelpFormatter formatter=new HelpFormatter();
350 formatter.printHelp("Usage: har [options] <output file> <source files/dirs>", options, false);
351 System.exit(1);
352 }
353
354 /**
355 * Use it for inspector debugging
356 * @param args
357 */
358 public static void main(String[] args) {
359 System.out.println("Hammurapi 3 Copyright (C) 2004 Hammurapi Group");
360
361 Options options=new Options();
362
363 Option classPathOption=OptionBuilder
364 .withArgName("classpath")
365 .hasArg()
366 .withDescription("ClassPath")
367 .isRequired(false)
368 .create("c");
369
370 options.addOption(classPathOption);
371
372 Option hostIdOption=OptionBuilder
373 .withArgName("hostId")
374 .hasArg()
375 .withDescription("Host id")
376 .isRequired(false)
377 .create("H");
378
379 options.addOption(hostIdOption);
380
381 Option titleOption=OptionBuilder
382 .withArgName("title")
383 .hasArg()
384 .withDescription("Report title")
385 .isRequired(false)
386 .create("T");
387
388 options.addOption(titleOption);
389
390 Option baseLineOption=OptionBuilder
391 .withDescription("Baseline date")
392 .withArgName("date")
393 .hasArg()
394 .isRequired(false)
395 .create("n");
396
397 options.addOption(baseLineOption);
398
399 Option forceOption=OptionBuilder
400 .withDescription("Force reviews on unchanged files")
401 .isRequired(false)
402 .create("f");
403
404 options.addOption(forceOption);
405
406 Option forceOnWarningsOption=OptionBuilder
407 .withDescription("Do not force reviews of files with warnings")
408 .isRequired(false)
409 .create("k");
410
411 options.addOption(forceOnWarningsOption);
412
413 Option descriptionOption=OptionBuilder
414 .withDescription("Review description")
415 .withArgName("description")
416 .hasArg()
417 .isRequired(false)
418 .create("y");
419 options.addOption(descriptionOption);
420
421 //Anu :20050701 Added baselining parameter
422 Option baseliningOption=OptionBuilder
423 .withArgName("off|on|set")
424 .hasArg()
425 .withDescription("Baselining mode")
426 .isRequired(false)
427 .create("B");
428
429 options.addOption(descriptionOption);
430
431 Option helpOption=OptionBuilder.withDescription("Print this message").isRequired(false).create("h");
432 options.addOption(helpOption);
433
434 CommandLineParser parser=new PosixParser();
435 CommandLine line=null;
436 try {
437 line=parser.parse(options, args);
438 } catch (ParseException e) {
439 System.err.println(e.getMessage());
440 System.err.flush();
441 printHelpAndExit(options);
442 }
443
444 if (line.hasOption("h")) {
445 printHelpAndExit(options);
446 }
447
448 HammurapiArchiver task=new HammurapiArchiver();
449 Project project = new Project();
450 task.setProject(project);
451 project.setCoreLoader(task.getClass().getClassLoader());
452
453 String[] values=line.getOptionValues('c');
454 for (int i=0; values!=null && i<values.length; i++) {
455 task.createClasspath().append(new Path(project, values[i]));
456 }
457
458 String[] largs=line.getArgs();
459 if (largs.length==0) {
460 System.out.println("Output file has to be provided");
461 printHelpAndExit(options);
462 }
463
464 if (line.hasOption('f')) {
465 task.setForce(true);
466 }
467
468 if (line.hasOption('k')) {
469 task.setForceOnWarnings(false);
470 }
471
472 if (line.hasOption('n')) {
473 task.setBaseLine(new Date(line.getOptionValue('n')));
474 }
475
476 if (line.hasOption('H')) {
477 task.setHostId(line.getOptionValue('H'));
478 }
479
480 if (line.hasOption('y')) {
481 task.setReviewDescription(line.getOptionValue('y'));
482 }
483
484 if (line.hasOption('T')) {
485 task.setTitle(line.getOptionValue('T'));
486 }
487
488 //Anu :20050701 Added for Baselining attribute
489 if (line.hasOption('B')) {
490 task.setBaselining(line.getOptionValue('B'));
491 }
492
493 task.setOutput(new File(largs[0]));
494
495 for (int i=1; i<largs.length; i++) {
496 File file = new File(largs[i]);
497 if (file.isFile()) {
498 task.srcFiles.add(file);
499 } else if (file.isDirectory()) {
500 task.createSrc().setDir(file);
501 }
502 }
503
504 task.setTaskName("har");
505
506 try {
507 task.execute();
508 System.exit(0);
509 } catch (Exception e) {
510 e.printStackTrace();
511 System.exit(2);
512 }
513 }
514
515 private String reviewDescription;
516
517 /**
518 * Description of review, e.g. release number. Appears in history annotation.
519 * @ant.non-required
520 */
521 public void setReviewDescription(String reviewDescription) {
522 this.reviewDescription=reviewDescription;
523 }
524
525}
526
527