Here's a patch for several files that do a couple things.
1. jxr now accepts a sourcepathref or a sourcepath, like the javadoc task.
This means it can xref multiple source trees now.
2. it extends ant's Task, as I needed some info from Project.
3. the 'View Javadoc' link now points to ${javadoc.destdir} instead of
just blindly using "../../apidocs".
4. it now puts the xrefs into a new property ${jxr.destdir} and mirrors
the javadoc hierarchy to make linking a little more sane.
the new 'getRelativeLink' method is maybe overkill, but it works, is
only called once (typically), should be immune to "paths with spaces"
and whatnot, and only assumes that the two directories to be linked
have a common parent somewhere at or under the project's ${baseDir}.
? xdocs/stylesheets
Index: src/java/org/apache/maven/Jxr.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/Jxr.java,v
retrieving revision 1.1
diff -r1.1 Jxr.java
59a60,67
> import org.apache.tools.ant.types.Reference;
> import org.apache.tools.ant.types.Path;
> import org.apache.tools.ant.Project;
> import org.apache.tools.ant.Task;
> import org.apache.tools.ant.BuildException;
> import java.util.LinkedList;
> import java.io.File;
> import java.io.IOException;
70c78
< extends AbstractExecutor
---
> extends Task
73c81
< * the starting directory housing the .java files
---
> * Directories to be cross-referenced
75,76c83,84
< private String startDir;
<
---
> private Path sourcePath;
>
82a91,95
> * Root javadocs directory
> */
> private String javadocDir;
>
> /**
91a105
>
93c107
< * Description of the Method
---
> * Starts the cross-referencing and indexing.
96c110
< throws Exception
---
> throws BuildException
97a112,123
> // first, get a relative link to the javadocs
> String javadocLinkDir = null;
> try
> {
> javadocLinkDir = getRelativeLink(destDir, javadocDir);
> }
> catch (IOException ioe)
> {
> throw new BuildException("Error finding javadocs", ioe);
> }
>
> // go through each source directory and xref the java files
99,105c125,142
< pkgmgr.process(startDir);
<
< // It is certainly not clear what's going on here. I believe we
< // have some in-memory work going on and then the results of the
< // work are placed in 'destDir' by the DirectoryIndexer.
< new JXR(startDir, destDir, "HEAD");
< new DirectoryIndexer(destDir, imageFolder, imageFile, DirectoryIndexer.MODE_JAVA);
---
> String[] paths = sourcePath.list();
> for (int i = 0; i < paths.length; ++i)
> {
> pkgmgr.process(paths[i]);
>
> new JXR(paths[i], destDir, javadocLinkDir, "HEAD");
> }
>
> // once we have all the source files xref'd, create the index pages
> try
> {
> new DirectoryIndexer(destDir, imageFolder, imageFile,
> DirectoryIndexer.MODE_JAVA);
> }
> catch (IOException ioe)
> {
> throw new BuildException(ioe);
> }
108a146,206
> * Creates a relative link from one directory to another.
> *
> * Example:
> * given /foo/bar/baz/oink
> * and /foo/bar/schmoo
> *
> * this method will return a string of "../../schmoo/"
> *
> * @param fromDir The directory from which the link is relative.
> * @param toDir The directory into which the link points.
> * @throws IOException
> * If a problem is encountered while navigating through the directories.
> */
> private String getRelativeLink(String fromDir, String toDir)
> throws IOException
> {
> StringBuffer toLink = new StringBuffer(); // up from fromDir
> StringBuffer fromLink = new StringBuffer(); // down into toDir
>
> // assume they are both at least rooted at the project's baseDir
> File baseDir = new File(project.getBaseDir().getCanonicalPath());
>
> // create a List of toDir's parent directories
> LinkedList parents = new LinkedList();
> File f = new File(new File(javadocDir).getCanonicalPath());
> while (f != null && !f.equals(baseDir))
> {
> parents.add(f);
> f = new File(f.getParent());
> }
>
> // walk up fromDir to find the common parent
> f = new File(new File(destDir).getCanonicalPath());
> f = new File(f.getParent());
> boolean found = false;
> while (f != null && !found && !f.equals(baseDir))
> {
> for (int i = 0; i < parents.size(); ++i)
> {
> File parent = (File)parents.get(i);
> if (f.equals(parent))
> {
> // when we find the common parent, add the subdirectories
> // down to toDir itself
> for (int j = 0; j < i; ++j)
> {
> File p = (File)parents.get(j);
> toLink.insert(0, p.getName() + "/");
> }
> found = true;
> break;
> }
> }
> f = new File(f.getParent());
> fromLink.append("../");
> }
>
> return fromLink.append(toLink).toString();
> }
>
> /**
125c223,241
< * Sets the startDir attribute of the JxrTask object
---
> * Sets the source path to a single path, or
> * appends onto the existing source path.
> * @param src The source directory to be cross-referenced.
> */
> public void setSourcepath(Path src)
> {
> if (sourcePath == null)
> {
> sourcePath = src;
> }
> else
> {
> sourcePath.append(src);
> }
> }
>
> /**
> * Sets the source path to a reference object
> * @param ref The Reference object containing paths to be cross-referenced.
127c243
< public void setStartDir(String startDir)
---
> public void setSourcepathref(Reference ref)
129c245,250
< this.startDir = startDir;
---
> if (sourcePath == null)
> {
> sourcePath = new Path(project);
> }
>
> sourcePath.createPath().setRefid(ref);
137a259,267
> }
>
> /**
> * Sets the javadocDir attribute of the JxrTask object
> * @param javadocDir The root directory containing javadocs
> */
> public void setJavadocDir(String javadocDir)
> {
> this.javadocDir = javadocDir;
Index: src/java/org/apache/maven/jxr/CodeTransform.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/jxr/CodeTransform.java,v
retrieving revision 1.9
diff -r1.9 CodeTransform.java
171a172,176
> /**
> * Relative path to javadocs, suitable for hyperlinking
> */
> private String javadocLinkDir;
>
593a599
> String javadocLinkDir,
601a608
> this.javadocLinkDir = javadocLinkDir;
648c655
< .append("../../apidocs");
---
> .append(javadocLinkDir);
654d660
< javadocURI.append("/");
Index: src/java/org/apache/maven/jxr/JXR.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/jxr/JXR.java,v
retrieving revision 1.8
diff -r1.8 JXR.java
86a87,91
> * Relative path to javadocs, suitable for hyperlinking
> */
> private String javadocLinkDir;
>
> /**
106a112
> String javadocLinkDir,
110a117
> this.javadocLinkDir = javadocLinkDir;
245c252
< transformer.transform(source, dest, this.revision);
---
> transformer.transform(source, dest, javadocLinkDir, this.revision);
Index: src/templates/build/build-docs.xml
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/templates/build/build-docs.xml,v
retrieving revision 1.50
diff -r1.50 build-docs.xml
20d19
< <mkdir dir="${docs.dest}/xref"/>
21a21
> <mkdir dir="${jxr.destdir}"/>
64,65c64,66
< startDir="${src.dir}"
< destDir="${docs.dest}/xref"
---
> sourcepathref="src.set"
> destDir="${jxr.destdir}"
> javadocDir="${javadoc.destdir}"
Index: src/templates/build/default.properties
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/templates/build/default.properties,v
retrieving revision 1.19
diff -r1.19 default.properties
59a60,64
> # properties for jxr cross-referencing
> ##
> jxr.destdir = ${docs.dest}/xref
>
> ##
-bl