Main Page | Class List | File List | Class Members | Related Pages

DoxygenConfig.java

00001 // -*- Mode: Java; indent-tabs-mode: nil; c-basic-offset: 4; -*-
00002 /*
00003  * The Apache Software License, Version 1.1
00004  *
00005  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution, if
00021  *    any, must include the following acknowlegement:
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowlegement may appear in the software itself,
00025  *    if and wherever such third-party acknowlegements normally appear.
00026  *
00027  * 4. The names "The Jakarta Project", "Ant", and "Apache Software
00028  *    Foundation" must not be used to endorse or promote products derived
00029  *    from this software without prior written permission. For written
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache"
00033  *    nor may "Apache" appear in their names without prior written
00034  *    permission of the Apache Group.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation.  For more
00052  * information on the Apache Software Foundation, please see
00053  * <http://www.apache.org/>.
00054  */
00055 //----------------------------------------------------------------------
00056 // $Header: /cvsroot/ant-doxygen/ant_task/src/org/doxygen/tools/Attic/DoxygenConfig.java,v 1.1.2.2 2004/01/31 01:38:56 akkumar Exp $
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 /*            activityLog(false, "Updated Doxygen config file: "
00302                         + "[" + DoxygenTask.CONFIG_FILE + "]");
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")) {      // bug ID=xxxxxx
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")) {       // bug ID=xxxxxx
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 }

Generated on Sat Jan 31 02:17:29 2004 for Ant-Doxygen by doxygen 1.3.4