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

DoxygenProcess.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  // $Header: /cvsroot/ant-doxygen/ant_task/src/org/doxygen/tools/Attic/DoxygenProcess.java,v 1.1.2.3 2004/01/31 01:38:56 akkumar Exp $
00056 package org.doxygen.tools;
00057 
00058 import java.util.StringTokenizer;
00059 
00060 import java.io.File;
00061 import java.io.IOException;
00062 import java.io.FileInputStream;
00063 import java.io.InputStreamReader;
00064 import java.io.BufferedReader;
00065 import java.io.FileOutputStream;
00066 
00067 import java.util.List;
00068 import java.util.ArrayList;
00069 
00070 import org.apache.tools.ant.BuildException;
00071 import org.apache.tools.ant.taskdefs.Execute;
00072 import org.apache.tools.ant.taskdefs.PumpStreamHandler;
00073 
00081 public class DoxygenProcess {
00082 
00083     String doxygenPath = "doxygen";
00084 
00089     public static final String DOXY_TEMP =
00090         System.getProperty("user.home") + File.separator + ".doxytemp";
00091 
00092     public void setDoxygenPath(String path) {
00093         doxygenPath = path;
00094     }
00095     
00096     
00097     //----------------------------------------------------------------------
00121     public final void checkVersion(String versionCompatible) {
00122         if (versionCompatible == null) {
00123             //Assume it is compatible with all versions. 
00124             //Safely ignore version checking. 
00125             return; 
00126         }
00127         try {
00128             List args = new ArrayList();
00129             args.add("--version");
00130             String fileVersion = invokeDoxygen(args);
00131 
00132             DoxygenVersion systemVersion = new DoxygenVersion(fileVersion);
00133 
00134 /*            activityLog(false, "Detected Doxygen version:" + fileVersion
00135                            + "  Task written for version: " + versionCompatible);
00136      */                      
00137             if (!systemVersion.isCompatible(versionCompatible)) {
00138 
00139                 String message = "Doxygen Version incompatible. "
00140                     + "This task is written for version "
00141                     + versionCompatible
00142                     + ". You seem to have a different version ( "
00143                     + fileVersion 
00144                     + " ) installed on your system. Please install the right version "
00145                     + "and try again. To get latest releases of Doxygen, please visit "
00146                     + " http://www.doxygen.org . ";
00147                     
00148                 throw new BuildException(message);
00149             }
00150         } catch (NumberFormatException nfe) {
00151             throw new BuildException("Unable to detect Doxygen version.", nfe);
00152         }
00153     }
00154     
00155     //----------------------------------------------------------------------
00171     public final void createConfig(final String theConfigFilename) {
00172         List args = new ArrayList();
00173         args.add("-s");                             // -s == Omit comments
00174         args.add("-g");                             // -g == Generate config
00175         args.add(theConfigFilename);                // filename
00176         invokeDoxygen(args);     // Let Doxygen create
00177     }
00178 
00179     //----------------------------------------------------------------------
00184     public void executeDoxygenConfig(String filename) {
00185         List args = new ArrayList();
00186         args.add(filename);                  // Amalgamated config
00187         invokeDoxygen(args);
00188     }     
00189     
00190     
00191     //----------------------------------------------------------------------
00207     private final String invokeDoxygen(final List args) {
00208         String [] arguments = new String[1 + args.size()];
00209         StringBuffer res = new StringBuffer();
00210         arguments[0] = doxygenPath;
00211         try {
00212             Execute doxygen = new Execute(
00213                                   new PumpStreamHandler(
00214                                       new FileOutputStream(DOXY_TEMP)));
00215             StringBuffer sb = new StringBuffer("Exec: " + arguments[0] + " ");
00216             for (int i = 0; (i < args.size()); i++) {
00217                 String arg = (String) args.get(i);
00218                 if  (arg.indexOf(" ") != -1) { arg = "\"" + arg + "\""; }
00219                 arguments[i + 1] = arg;
00220                 sb.append(arguments[i + 1] + " ");
00221             }
00222 //          activityLog(true, sb.toString());
00223             doxygen.setCommandline(arguments);
00224             doxygen.execute();
00225             
00226             BufferedReader br = new BufferedReader(
00227                          new InputStreamReader(
00228                              new FileInputStream(DOXY_TEMP)));
00229             String line = br.readLine();
00230             while (line != null) {
00231                 res.append(line);
00232                 line = br.readLine();
00233              }
00234             return res.toString();
00235         } catch (IOException ioe) {
00236             throw new BuildException("Doxygen not found on the PATH.", ioe);
00237         }
00238     }
00239 }

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