jvanzyl 2002/07/06 05:57:00 Added: src/java/org/apache/maven/jxr JxrBean.java Removed: src/java/org/apache/maven/jxr Jxr.java Log: o Rename Jxr to JxrBean, causing problems on windows. Kill bill. Revision Changes Path 1.1 jakarta-turbine-maven/src/java/org/apache/maven/jxr/JxrBean.java Index: JxrBean.java =================================================================== package org.apache.maven.jxr; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Maven" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import org.apache.maven.jxr.JXR; import org.apache.maven.jxr.DirectoryIndexer; import org.apache.maven.jxr.pacman.PackageManager; import org.apache.maven.executor.AbstractExecutor; import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.BuildException; import java.util.LinkedList; import java.io.File; import java.io.IOException; /** * Creates an html-based, cross referenced version of Java source code * for a project. * * @author <a href="mailto:[EMAIL PROTECTED]">Josh Lucas</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @version $Id: JxrBean.java,v 1.1 2002/07/06 12:57:00 jvanzyl Exp $ */ public class JxrBean extends AbstractExecutor { /** * Directories to be cross-referenced */ private Path sourcePath; /** * Reference object contatining multiple paths to be cross-referenced */ private Reference ref; /** * the destination directory */ private String destDir; /** * Root javadocs directory */ private String javadocDir; /** * the location of the folder.gif */ private String imageFolder; /** * the location of the file.gif */ private String imageFile; /** * Starts the cross-referencing and indexing. * @throws BuildException when any error occurs */ public void execute() throws BuildException { // ant's TaskAdapter doesn't set the Project until this method, so // figure out which path to use here. if (sourcePath == null) { if (ref != null) { sourcePath = new Path(getProject()); sourcePath.createPath().setRefid(ref); } else { String err = "Must specify either sourcePathRef or sourcePath"; throw new BuildException(err); } } // 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 PackageManager pkgmgr = PackageManager.getInstance(); 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, destDir, imageFolder, imageFile, DirectoryIndexer.MODE_JAVA); } catch (IOException ioe) { throw new BuildException(ioe); } } /** * 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. * @return a string of format "../../schmoo/" */ 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(getProject().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(); } /** * Sets the imageFile attribute of the JxrTask object * @param imageFile the image to be used for the {@link DirectoryIndexer} */ public void setImageFile(String imageFile) { this.imageFile = imageFile; } /** * Sets the imageFolder attribute of the JxrTask object * @param imageFolder the folder for the {@link #imageFile} */ public void setImageFolder(String imageFolder) { this.imageFolder = imageFolder; } /** * 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. */ public void setSourcepathref(Reference ref) { this.ref = ref; } /** * Sets the destDir attribute of the JxrTask object * @param destDir the destination directory for jxr output */ public void setDestDir(String destDir) { this.destDir = destDir; } /** * Sets the javadocDir attribute of the JxrTask object * @param javadocDir The root directory containing javadocs */ public void setJavadocDir(String javadocDir) { this.javadocDir = javadocDir; } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
