+ "been specified.");
}
log("Generating Javadoc", Project.MSG_INFO);
Commandline toExecute = (Commandline) cmd.clone();
// ------------------------------------------ general javadoc arguments
if (doctitle != null) {
toExecute.createArgument().setValue("-doctitle");
toExecute.createArgument().setValue(expand(doctitle.getText()));
}
if (header != null) {
toExecute.createArgument().setValue("-header");
toExecute.createArgument().setValue(expand(header.getText()));
}
if (footer != null) {
toExecute.createArgument().setValue("-footer");
toExecute.createArgument().setValue(expand(footer.getText()));
}
if (bottom != null) {
toExecute.createArgument().setValue("-bottom");
toExecute.createArgument().setValue(expand(bottom.getText()));
}
if (classpath == null) {
classpath = (new Path(getProject())).concatSystemClasspath("last");
} else {
classpath = classpath.concatSystemClasspath("ignore");
}
if (!javadoc1) {
if (classpath.size() > 0) {
toExecute.createArgument().setValue("-classpath");
toExecute.createArgument().setPath(classpath);
}
if (sourceDirs.size() > 0) {
toExecute.createArgument().setValue("-sourcepath");
toExecute.createArgument().setPath(sourceDirs);
}
} else {
//sourceDirs.append(classpath);
if (sourceDirs.size() > 0) {
toExecute.createArgument().setValue("-classpath");
toExecute.createArgument().setPath(sourceDirs);
}
}
if (version && doclet == null) {
toExecute.createArgument().setValue("-version");
}
if (author && doclet == null) {
toExecute.createArgument().setValue("-author");
}
if (javadoc1 || doclet == null) {
if (destDir == null) {
String msg = "destDir attribute must be set!";
throw new BuildException(msg);
}
}
// ---------------------------- javadoc2 arguments for default doclet
if (!javadoc1) {
if (doclet != null) {
if (doclet.getName() == null) {
throw new BuildException("The doclet name must be "
+ "specified.", getLocation());
} else {
toExecute.createArgument().setValue("-doclet");
toExecute.createArgument().setValue(doclet.getName());
if (doclet.getPath() != null) {
Path docletPath
= doclet.getPath().concatSystemClasspath("ignore");
if (docletPath.size() != 0) {
toExecute.createArgument().setValue("-docletpath");
toExecute.createArgument().setPath(docletPath);
}
}
for (Enumeration e = doclet.getParams();
e.hasMoreElements();) {
DocletParam param = (DocletParam) e.nextElement();
if (param.getName() == null) {
throw new BuildException("Doclet parameters must "
+ "have a name");
}
toExecute.createArgument().setValue(param.getName());
if (param.getValue() != null) {
toExecute.createArgument()
.setValue(param.getValue());
}
}
}
}
if (bootclasspath != null && bootclasspath.size() > 0) {
toExecute.createArgument().setValue("-bootclasspath");
toExecute.createArgument().setPath(bootclasspath);
}
// add the links arguments
if (links.size() != 0) {
for (Enumeration e = links.elements(); e.hasMoreElements();) {
LinkArgument la = (LinkArgument) e.nextElement();
if (la.getHref() == null || la.getHref().length() == 0) {
log("No href was given for the link - skipping",
Project.MSG_VERBOSE);
continue;
} else {
// is the href a valid URL
try {
URL base = new URL("file://.");
new URL(base, la.getHref());
} catch (MalformedURLException mue) {
// ok - just skip
log("Link href \"" + la.getHref()
+ "\" is not a valid url - skipping link",
Project.MSG_WARN);
continue;
}
}
if (la.isLinkOffline()) {
File packageListLocation = la.getPackagelistLoc();
if (packageListLocation == null) {
throw new BuildException("The package list "
+ " location for link " + la.getHref()
+ " must be provided because the link is "
+ "offline");
}
File packageListFile =
new File(packageListLocation, "package-list");
if (packageListFile.exists()) {
try {
String packageListURL =
fileUtils.getFileURL(packageListLocation)
.toExternalForm();
toExecute.createArgument()
.setValue("-linkoffline");
toExecute.createArgument()
.setValue(la.getHref());
toExecute.createArgument()
.setValue(packageListURL);
} catch (MalformedURLException ex) {
log("Warning: Package list location was "
+ "invalid " + packageListLocation,
Project.MSG_WARN);
}
} else {
log("Warning: No package list was found at "
+ packageListLocation, Project.MSG_VERBOSE);
}
} else {
toExecute.createArgument().setValue("-link");
toExecute.createArgument().setValue(la.getHref());
}
}
}
// add the single group arguments
// Javadoc 1.2 rules:
// Multiple -group args allowed.
// Each arg includes 3 strings: -group [name] [packagelist].
// Elements in [packagelist] are colon-delimited.
// An element in [packagelist] may end with the * wildcard.
// Ant javadoc task rules for group attribute:
// Args are comma-delimited.
// Each arg is 2 space-delimited strings.
// E.g., group="XSLT_Packages org.apache.xalan.xslt*,
// XPath_Packages org.apache.xalan.xpath*"
if (group != null) {
StringTokenizer tok = new StringTokenizer(group, ",", false);
while (tok.hasMoreTokens()) {
String grp = tok.nextToken().trim();
int space = grp.indexOf(" ");
if (space > 0){
String name = grp.substring(0, space);
String pkgList = grp.substring(space + 1);
toExecute.createArgument().setValue("-group");
toExecute.createArgument().setValue(name);
toExecute.createArgument().setValue(pkgList);
}
}
}
// add the group arguments
if (groups.size() != 0) {
for (Enumeration e = groups.elements(); e.hasMoreElements();) {
GroupArgument ga = (GroupArgument) e.nextElement();
String title = ga.getTitle();
String packages = ga.getPackages();
if (title == null || packages == null) {
throw new BuildException("The title and packages must "
+ "be specified for group "
+ "elements.");
}
toExecute.createArgument().setValue("-group");
toExecute.createArgument().setValue(expand(title));
toExecute.createArgument().setValue(packages);
}
}
// JavaDoc 1.4 parameters
if (javadoc4) {
for (Enumeration e = tags.elements(); e.hasMoreElements();) {
Object element = e.nextElement();
if (element instanceof TagArgument) {
TagArgument ta = (TagArgument) element;
toExecute.createArgument().setValue ("-tag");
toExecute.createArgument().setValue (ta.getParameter());
} else {
ExtensionInfo tagletInfo = (ExtensionInfo) element;
toExecute.createArgument().setValue("-taglet");
toExecute.createArgument().setValue(tagletInfo
.getName());
if (tagletInfo.getPath() != null) {
Path tagletPath = tagletInfo.getPath()
.concatSystemClasspath("ignore");
if (tagletPath.size() != 0) {
toExecute.createArgument()
.setValue("-tagletpath");
toExecute.createArgument().setPath(tagletPath);
}
}
}
}
if (source != null) {
toExecute.createArgument().setValue("-source");
toExecute.createArgument().setValue(source);
}
}
}
File tmpList = null;
PrintWriter srcListWriter = null;
try {
/**
* Write sourcefiles and package names to a temporary file
* if requested.
*/
if (useExternalFile) {
if (tmpList == null) {
tmpList = fileUtils.createTempFile("javadoc", "", null);
toExecute.createArgument()
.setValue("@" + tmpList.getAbsolutePath());
}
srcListWriter = new PrintWriter(
new FileWriter(tmpList.getAbsolutePath(),
true));
}
Enumeration e = packagesToDoc.elements();
while (e.hasMoreElements()) {
String packageName = (String) e.nextElement();
if (useExternalFile) {
srcListWriter.println(packageName);
} else {
toExecute.createArgument().setValue(packageName);
}
}
e = sourceFilesToDoc.elements();
while (e.hasMoreElements()) {
SourceFile sf = (SourceFile) e.nextElement();
String sourceFileName = sf.getFile().getAbsolutePath();
if (useExternalFile) {
srcListWriter.println(sourceFileName);
} else {
toExecute.createArgument().setValue(sourceFileName);
}
}
} catch (IOException e) {
tmpList.delete();
throw new BuildException("Error creating temporary file",
e, getLocation());
} finally {
if (srcListWriter != null) {
srcListWriter.close();
}
}
if (packageList != null) {
toExecute.createArgument().setValue("@" + packageList);
}
log(toExecute.describeCommand(), Project.MSG_VERBOSE);
log("Javadoc execution", Project.MSG_INFO);
JavadocOutputStream out = new JavadocOutputStream(Project.MSG_INFO);
JavadocOutputStream err = new JavadocOutputStream(Project.MSG_WARN);
Execute exe = new Execute(new PumpStreamHandler(out, err));
exe.setAntRun(getProject());
/*
* No reason to change the working directory as all filenames and
* path components have been resolved already.
*
* Avoid problems with command line length in some environments.
*/
exe.setWorkingDirectory(null);
try {
exe.setCommandline(toExecute.getCommandline());
int ret=0;
String[] arguments = toExecute.getArguments();
for (int i = 0; i < arguments.length; i++) {
String argument = arguments[i];
System.out.println(i+") "+argument);
}
Main.main(arguments);// int ret =exe.execute();