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 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
00124
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
00135
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");
00174 args.add("-g");
00175 args.add(theConfigFilename);
00176 invokeDoxygen(args);
00177 }
00178
00179
00184 public void executeDoxygenConfig(String filename) {
00185 List args = new ArrayList();
00186 args.add(filename);
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
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 }