Hello,
These patches are refinements of the one I sent to the mailing list last
week that added an option to the Javadoc task which allowed you to
specify the maximum memory size of the javadoc JVM.
What I did at first
--------------------
Following the suggestions from the list I tried to place the memory
options on the Java task and have the Javadoc task inherit from the Java
task. After I finished this, I realized it didn't seem to work very
well. Some problems were:
- How to handle the case where the child and parent task have the
same option name (classpath).
- How to disable options available in the parent task (fork)
- How to handle options in the parent task that must be fixed in
the child task (classname = sun.tools.javadoc.Main)
- How to document all this in a clear way.
I still have this code and will be happy to submit/discuss it if anyone
is interested.
What I actually did
-------------------
Java task:
- Added a maxmemory and minmemory option
Javadoc task:
- Added a maxmemory option and minmemory option by hand without
inheriting from the Java task
- Fixed and wired up the docletpath option
Documentation:
- Added documentation for the new memory options in the Java and
Javac tasks.
- Added documentation for the (existing but undocumented) classpath
option on the Java task.
Possible future suggestions
----------------------------
- Separate the forked and in-process Java tasks into two tasks.
- Added documentation that explains java classes should be
executed in-process whenever possible, and that the JAVACMD
environment variable can be used to raise the memory limits
of the Ant JVM (and thus all in-process subtasks)
- Factor the common code in java fork and javadoc into a common class.
I would be happy to look into implementing these or other suggestions
after these patches are committed.
Thanks,
Jay Handfield
Index: Java.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
retrieving revision 1.6
diff -u -r1.6 Java.java
--- Java.java 2000/03/29 17:13:31 1.6
+++ Java.java 2000/03/30 20:40:01
@@ -69,6 +69,8 @@
private String classname = null;
private String args = null;
private String jvmargs = null;
+ private String maxmemory = null;
+ private String minmemory = null;
private String classpath = null;
private boolean fork = false;
@@ -91,6 +93,31 @@
b.append(classpath);
b.append(" ");
}
+
+ boolean java1 = (Project.getJavaVersion() == Project.JAVA_1_1);
+
+ if(maxmemory != null){
+ if(java1){
+ b.append("-mx");
+ }
+ else{
+ b.append("-Xmx");
+ }
+ b.append(maxmemory);
+ b.append(" ");
+ }
+
+ if(minmemory != null){
+ if(java1){
+ b.append("-ms");
+ }
+ else{
+ b.append("-Xms");
+ }
+ b.append(minmemory);
+ b.append(" ");
+ }
+
if (jvmargs != null) {
b.append(jvmargs);
b.append(" ");
@@ -146,6 +173,20 @@
*/
public void setFork(String s) {
this.fork = Project.toBoolean(s);
+ }
+
+ /**
+ * Set the maximum heap size.
+ */
+ public void setMaxmemory(String src){
+ maxmemory = src;
+ }
+
+ /**
+ * Set the minimum heap size.
+ */
+ public void setMinmemory(String src){
+ minmemory = src;
}
/**
Index: Javadoc.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javadoc.java,v
retrieving revision 1.7
diff -u -r1.7 Javadoc.java
--- Javadoc.java 2000/03/03 14:15:42 1.7
+++ Javadoc.java 2000/03/30 18:48:29
@@ -91,7 +91,7 @@
private boolean author = true;
private boolean version = true;
private String doclet = null;
- private File docletpath = null;
+ private String docletpath = null;
private boolean old = false;
private String classpath = null;
private String bootclasspath = null;
@@ -150,8 +150,8 @@
public void setDoclet(String src) {
doclet = src;
}
- public void setDocletPath(String src) {
- docletpath = project.resolveFile(src);
+ public void setDocletpath(String src) {
+ docletpath = project.translatePath(src);
}
public void setOld(String src) {
old = Project.toBoolean(src);
@@ -235,6 +235,7 @@
docencoding = src;
}
+
public void execute() throws BuildException {
if (sourcePath == null && destDir == null ) {
String msg = "sourcePath and destDir attributes must be set!";
@@ -321,6 +322,10 @@
if (doclet != null) {
argList.addElement("-doclet");
argList.addElement(doclet);
+ }
+ if (docletpath != null) {
+ argList.addElement("-docletpath");
+ argList.addElement(docletpath);
}
if (bootclasspath != null) {
argList.addElement("-bootclasspath");
Index: Javadoc.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javadoc.java,v
retrieving revision 1.7
diff -u -r1.7 Javadoc.java
--- Javadoc.java 2000/03/03 14:15:42 1.7
+++ Javadoc.java 2000/03/30 19:17:03
@@ -79,6 +79,8 @@
public class Javadoc extends Exec {
+ private String maxmemory = null;
+ private String minmemory = null;
private String sourcePath = null;
private File destDir = null;
private File overviewFile = null;
@@ -120,6 +122,14 @@
private String docencoding = null;
private Vector compileList = new Vector(10);
+ public void setMaxmemory(String src){
+ maxmemory = src;
+ }
+
+ public void setMinmemory(String src){
+ minmemory = src;
+ }
+
public void setSourcepath(String src) {
sourcePath = project.translatePath(src);
}
@@ -250,6 +260,24 @@
// ------------------------------------------------ general javadoc arguments
if (classpath == null)
classpath = System.getProperty("java.class.path");
+
+ if(maxmemory != null){
+ if(javadoc1){
+ argList.addElement("-J-mx" + maxmemory);
+ }
+ else{
+ argList.addElement("-J-Xmx" + maxmemory);
+ }
+ }
+
+ if(minmemory != null){
+ if(javadoc1){
+ argList.addElement("-J-ms" + minmemory);
+ }
+ else{
+ argList.addElement("-J-Xms" + minmemory);
+ }
+ }
if ( (!javadoc1) || (sourcePath == null) ) {
argList.addElement("-classpath");
Index: index.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
retrieving revision 1.14
diff -u -r1.14 index.html
--- index.html 2000/03/05 19:43:47 1.14
+++ index.html 2000/03/30 20:08:13
@@ -1225,6 +1225,24 @@
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">classpath</td>
+ <td valign="top">Sets the classpath to use(ignored if fork is
+ disabled)</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">maxmemory</td>
+ <td valign="top">Sets the maximum heap size of the JVM (ignored if fork is
+ disabled)</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">minmemory</td>
+ <td valign="top">Sets the minimum heap size of the JVM (ignored if fork is
+ disabled)</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">jvmargs</td>
<td valign="top">the arguments to pass to the forked VM (ignored if fork is
disabled)</td>
@@ -1235,7 +1253,10 @@
<pre> <java classname="test.Main" /></pre>
<pre> <java classname="test.Main" args="-h" /></pre>
<pre> <java classname="test.Main"
+ classpath="classes"
args="-h"
+ maxmemory="64m"
+ minmemory="32m"
fork="yes"
jvmargs="-Xrunhprof:cpu=samples,file=log.txt,depth=3"
/></pre>
@@ -1423,6 +1444,18 @@
<td align="center" valign="top">all</td>
</tr>
<tr>
+ <td valign="top">maxmemory</td>
+ <td valign="top">Specify maximum heap size to use in forked JVM</td>
+ <td align="center" valign="top">all</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">minmemory</td>
+ <td valign="top">Specify minimum heap size to use in forked JVM</td>
+ <td align="center" valign="top">all</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">Classpath</td>
<td valign="top">Specify where to find user class files</td>
<td align="center" valign="top">all</td>
@@ -1550,6 +1583,18 @@
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">doclet</td>
+ <td valign="top">Specifies a custom doclet to use</td>
+ <td align="center" valign="top">1.2</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">docletpath</td>
+ <td valign="top">Specifies classpath to use for custom doclet</td>
+ <td align="center" valign="top">1.2</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">link</td>
<td valign="top">Create links to javadoc output at the given URL</td>
<td align="center" valign="top">1.2</td>
@@ -1640,6 +1685,7 @@
<pre> <javadoc packagenames="com.dummy.test.*"
sourcepath="src"
destdir="docs/api"
+ maxmemory="64m"
author="true"
version="true"
use="true"