Browse Source

Added useexternalfile attribute to <javadoc> - this makes javadoc use

a temporary file for source file and package names (via javadoc's
@file parameter) to defeat command line length limitations.

Inspired by:	Frederic Lavigne <fred@castify.net>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269045 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
7ded9a569f
5 changed files with 128 additions and 32 deletions
  1. +4
    -0
      WHATSNEW
  2. +1
    -0
      build.xml
  3. +11
    -0
      docs/manual/CoreTasks/javadoc.html
  4. +9
    -6
      src/main/org/apache/tools/ant/Main.java
  5. +103
    -26
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java

+ 4
- 0
WHATSNEW View File

@@ -68,6 +68,10 @@ Other changes:

* <execon> and <apply> can now optionally skip empty filesets.

* <javadoc> has a new useexternalfile attribute that makes it use a
temporary file for sourcefile and package names - helps to defeat
command line length limitations.

Fixed bugs:
-----------



+ 1
- 0
build.xml View File

@@ -553,6 +553,7 @@
description="--> creates the API documentation">
<mkdir dir="${build.javadocs}"/>
<javadoc packagenames="org.apache.*"
useexternalfile="yes"
sourcepath="${java.dir}"
destdir="${build.javadocs}"
author="true"


+ 11
- 0
docs/manual/CoreTasks/javadoc.html View File

@@ -375,6 +375,17 @@ instead.</i></p>
<td align="center" valign="top">all</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">useexternalfile</td>
<td valign="top">indicates whether the sourcefile name specified
in srcfiles or as nested source elements should be written to a
temporary file to make the command line shorter. Also applies to
the package names specified via the packagenames attribute or
nested package elements.
(<code>yes</code> | <code>no</code>). Default is no.</td>
<td align="center" valign="top">all</td>
<td valign="top" align="center">No</td>
</tr>
</table>

<h4><a name="groupattribute">Format of the group attribute</a></h4>


+ 9
- 6
src/main/org/apache/tools/ant/Main.java View File

@@ -509,7 +509,11 @@ public class Main {
System.out.println(msg.toString());
}

private static void printVersion() {
private static void printVersion() throws BuildException {
System.out.println(getAntVersion());
}

public static String getAntVersion() throws BuildException {
try {
Properties props = new Properties();
InputStream in =
@@ -523,13 +527,12 @@ public class Main {
msg.append(props.getProperty("VERSION"));
msg.append(" compiled on ");
msg.append(props.getProperty("DATE"));
msg.append(lSep);
System.out.println(msg.toString());
return msg.toString();
} catch (IOException ioe) {
System.err.println("Could not load the version information.");
System.err.println(ioe.getMessage());
throw new BuildException("Could not load the version information:"
+ ioe.getMessage());
} catch (NullPointerException npe) {
System.err.println("Could not load the version information.");
throw new BuildException("Could not load the version information.");
}
}



+ 103
- 26
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -264,6 +264,16 @@ public class Javadoc extends Task {
private Html header = null;
private Html footer = null;
private Html bottom = null;
private boolean useExternalFile = false;
private File tmpList = null;

/**
* Work around command line length limit by using an external file
* for the sourcefiles.
*/
public void setUseExternalFile(boolean b) {
useExternalFile = b;
}

/**
* Sets whether default exclusions should be used or not.
@@ -498,6 +508,7 @@ public class Javadoc extends Task {
header = text;
}
}

public void setFooter(String src) {
Html h = new Html();
h.addText(src);
@@ -508,6 +519,7 @@ public class Javadoc extends Task {
footer = text;
}
}

public void setBottom(String src) {
Html h = new Html();
h.addText(src);
@@ -518,6 +530,7 @@ public class Javadoc extends Task {
bottom = text;
}
}

public void setLinkoffline(String src) {
if (!javadoc1) {
LinkArgument le = createLink();
@@ -854,6 +867,7 @@ public class Javadoc extends Task {

}

tmpList = null;
if (packageNames.size() > 0) {
Vector packages = new Vector();
Enumeration enum = packageNames.elements();
@@ -881,10 +895,39 @@ public class Javadoc extends Task {
}

if (sourceFiles.size() > 0) {
Enumeration enum = sourceFiles.elements();
while (enum.hasMoreElements()) {
SourceFile sf = (SourceFile) enum.nextElement();
toExecute.createArgument().setValue(sf.getFile().getAbsolutePath());
PrintWriter srcListWriter = null;
try {

/**
* Write sourcefiles to a temporary file if requested.
*/
if (useExternalFile) {
if (tmpList == null) {
tmpList = createTempFile();
toExecute.createArgument().setValue("@" + tmpList.getAbsolutePath());
}
srcListWriter = new PrintWriter(new FileWriter(tmpList.getAbsolutePath(),
true));
}
Enumeration enum = sourceFiles.elements();
while (enum.hasMoreElements()) {
SourceFile sf = (SourceFile) enum.nextElement();
String sourceFileName = sf.getFile().getAbsolutePath();
if (useExternalFile) {
srcListWriter.println(sourceFileName);
} else {
toExecute.createArgument().setValue(sourceFileName);
}
}

} catch (IOException e) {
throw new BuildException("Error creating temporary file",
e, location);
} finally {
if (srcListWriter != null) {
srcListWriter.close();
}
}
}

@@ -909,6 +952,12 @@ public class Javadoc extends Task {
} catch (IOException e) {
throw new BuildException("Javadoc failed: " + e, e, location);
} finally {

if (tmpList != null) {
tmpList.delete();
tmpList = null;
}
out.logFlush();
err.logFlush();
try {
@@ -975,32 +1024,53 @@ public class Javadoc extends Task {
fs.createExclude().setName(pkg);
}
for (int j=0; j<list.length; j++) {
File source = project.resolveFile(list[j]);
fs.setDir(source);

DirectoryScanner ds = fs.getDirectoryScanner(project);
String[] packageDirs = ds.getIncludedDirectories();

for (int i=0; i<packageDirs.length; i++) {
File pd = new File(source, packageDirs[i]);
String[] files = pd.list(new FilenameFilter () {
public boolean accept(File dir1, String name) {
if (name.endsWith(".java")) {
return true;
}
return false; // ignore dirs
}
});
PrintWriter packageListWriter = null;
try {
if (useExternalFile) {
tmpList = createTempFile();
toExecute.createArgument().setValue("@" + tmpList.getAbsolutePath());
packageListWriter = new PrintWriter(new FileWriter(tmpList));
}

if (files.length > 0) {
String pkgDir = packageDirs[i].replace('/','.').replace('\\','.');
if (!addedPackages.contains(pkgDir)) {
toExecute.createArgument().setValue(pkgDir);
addedPackages.addElement(pkgDir);

for (int j=0; j<list.length; j++) {
File source = project.resolveFile(list[j]);
fs.setDir(source);
DirectoryScanner ds = fs.getDirectoryScanner(project);
String[] packageDirs = ds.getIncludedDirectories();
for (int i=0; i<packageDirs.length; i++) {
File pd = new File(source, packageDirs[i]);
String[] files = pd.list(new FilenameFilter () {
public boolean accept(File dir1, String name) {
if (name.endsWith(".java")) {
return true;
}
return false; // ignore dirs
}
});
if (files.length > 0) {
String pkgDir = packageDirs[i].replace('/','.').replace('\\','.');
if (!addedPackages.contains(pkgDir)) {
if (useExternalFile) {
packageListWriter.println(pkgDir);
} else {
toExecute.createArgument().setValue(pkgDir);
}
addedPackages.addElement(pkgDir);
}
}
}
}
} catch (IOException ioex) {
throw new BuildException("Error creating temporary file",
ioex, location);
} finally {
if (packageListWriter != null) {
packageListWriter.close();
}
}
}

@@ -1050,4 +1120,11 @@ public class Javadoc extends Task {
project.getProperties());
}

/**
* Creates a temporary file.
*/
private File createTempFile() {
return new File("javadoc" + (new Random(System.currentTimeMillis())).nextLong());
}
}

Loading…
Cancel
Save