00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 package org.doxygen.tools;
00059
00060 import org.apache.tools.ant.BuildException;
00061 import org.apache.tools.ant.Task;
00062 import org.apache.tools.ant.taskdefs.PumpStreamHandler;
00063 import org.apache.tools.ant.taskdefs.Execute;
00064
00065 import java.util.List;
00066 import java.util.TreeMap;
00067 import java.util.Vector;
00068 import java.util.Enumeration;
00069 import java.util.Set;
00070 import java.util.Iterator;
00071 import java.util.Properties;
00072 import java.util.Map;
00073
00074 import java.io.PrintStream;
00075 import java.io.FileOutputStream;
00076 import java.io.FileInputStream;
00077 import java.io.IOException;
00078
00084 public class DoxygenConfig {
00085
00086
00088 private TreeMap taskAttributes = new TreeMap();
00089
00091 private List nestedAttributes = new Vector();
00092
00093
00094
00095
00122 public DoxygenConfig() {
00123 setProperty("DETAILS_AT_TOP", true);
00124 setProperty("FILE_PATTERNS", "*.java");
00125 setProperty("GENERATE_LATEX", false);
00126 setProperty("HAVE_DOT", false);
00127 setProperty("HIDE_UNDOC_MEMBERS", true);
00128 setProperty("INLINE_SOURCES", true);
00129 setProperty("INPUT", "src");
00130 setProperty("GENERATE_TREEVIEW", true);
00131 setProperty("OPTIMIZE_OUTPUT_JAVA", true);
00132 setProperty("OUTPUT_DIRECTORY", "doc");
00133 setProperty("QUIET", true);
00134 setProperty("RECURSIVE", true);
00135 setProperty("SOURCE_BROWSER", true);
00136 setProperty("TOC_EXPAND", true);
00137 }
00138
00151 public final void setProperty(final String keyName,
00152 final String value) {
00153 DoxygenTask.Property attribute = getAttribute(keyName);
00154 taskAttributes.put(keyName, attribute);
00155
00156 String val = value;
00157 if (val.indexOf(' ') > -1) { val = "\"" + val + "\""; }
00158 attribute.setValue(val);
00159
00160 }
00161
00162
00163
00164
00165
00174 public final void setProperty(final String keyName,
00175 final int value) {
00176 DoxygenTask.Property attribute = getAttribute(keyName);
00177 taskAttributes.put(keyName, attribute);
00178 attribute.setValue("" + value);
00179 }
00180
00181
00182
00183
00184
00195 public final void setProperty(final String keyName,
00196 final boolean value) {
00197 DoxygenTask.Property attribute = getAttribute(keyName);
00198 taskAttributes.put(keyName, attribute);
00199
00200 String val = "YES";
00201 if (!value) { val = "NO"; }
00202 attribute.setValue(val);
00203 }
00204
00205
00206
00207
00208
00209
00218 public final TreeMap getTaskAttributes() {
00219 return taskAttributes;
00220 }
00221
00222
00223
00224
00225
00226
00235 public final List getNestedAttributes() {
00236 return nestedAttributes;
00237 }
00238
00239
00240
00241
00242
00243
00252 public final DoxygenTask.Property getAttribute(final String keyName) {
00253 DoxygenTask.Property retval = null;
00254 if (taskAttributes.containsKey(keyName)) {
00255 retval = (DoxygenTask.Property) taskAttributes.get(keyName);
00256 }
00257 if (retval == null) {
00258 retval = new DoxygenTask.Property();
00259 retval.setName(keyName);
00260 }
00261 return retval;
00262 }
00263
00264
00268 public void addNestedAttribute(DoxygenTask.Property attr) {
00269 nestedAttributes.add(attr);
00270
00271 }
00272
00273
00282 public final void writeDoxygenConfig(final String theConfigFilename) {
00283
00284 PrintStream ps = null;
00285 TreeMap map = readDoxygenConfig(theConfigFilename);
00286 cascadeDoxygenConfig(map);
00287 try {
00288 ps = new PrintStream(
00289 new FileOutputStream(DoxygenTask.CONFIG_FILE));
00290 Set keys = map.entrySet();
00291
00292 Iterator i = keys.iterator();
00293 while (i.hasNext()) {
00294 Map.Entry me = (Map.Entry) i.next();
00295 String param = (String) me.getKey();
00296 String value = (String) me.getValue();
00297 String line = param + "\t=";
00298 if (value != null) { line += " " + value; }
00299 ps.println(line);
00300 }
00301
00302
00303
00304 } catch (IOException ioe) {
00305 throw new BuildException("Unable to update Doxygen config file: "
00306 + "[" + theConfigFilename + "]", ioe);
00307 } finally {
00308 if (ps != null) {
00309 ps.close();
00310 ps = null;
00311 }
00312 }
00313 }
00314
00315
00316
00317
00318
00319
00343 public final TreeMap readDoxygenConfig(String theConfigFilename) {
00344 TreeMap map = new TreeMap();
00345 Properties p = new Properties();
00346 try {
00347 p.load(new FileInputStream(theConfigFilename));
00348 if (p.containsKey("Configuration")) {
00349 p.remove("Configuration");
00350 p.remove("to");
00351 p.remove("doxygen");
00352 p.remove("Now");
00353 p.remove("");
00354 }
00355 if (p.containsKey("ROJECT_NUMBER")) {
00356 p.setProperty("PROJECT_NUMBER", p.getProperty("ROJECT_NUMBER"));
00357 p.remove("ROJECT_NUMBER");
00358 }
00359 Enumeration e = p.keys();
00360 while (e.hasMoreElements()) {
00361 String arg = (String) e.nextElement();
00362 map.put(arg, p.getProperty(arg));
00363 }
00364 } catch (IOException ioe) {
00365 throw new BuildException("Unable to read Doxygen config file: "
00366 + "[" + theConfigFilename + "]", ioe);
00367 }
00368 return map;
00369 }
00370
00371
00392 public final void cascadeDoxygenConfig(final TreeMap map) {
00393 if (taskAttributes.size() > 0) {
00394 Iterator iter = taskAttributes.values().iterator();
00395 while (iter.hasNext()) {
00396 DoxygenTask.Property attribute =
00397 (DoxygenTask.Property) iter.next();
00398 map.put(attribute.getName(), attribute.getValue());
00399 }
00400 }
00401 if (nestedAttributes.size() > 0) {
00402 Iterator iter = nestedAttributes.iterator();
00403 while (iter.hasNext()) {
00404 DoxygenTask.Property attribute =
00405 (DoxygenTask.Property) iter.next();
00406 map.put(attribute.getName(), attribute.getValue());
00407 }
00408 }
00409 }
00410 }