diff --git a/jxr/plugin.properties b/jxr/plugin.properties index 611d96db..0f9d5c9f 100644 --- a/jxr/plugin.properties +++ b/jxr/plugin.properties @@ -24,4 +24,4 @@ maven.jxr.destdir = ${maven.docs.dest}/xref maven.jxr.destdir.test = ${maven.docs.dest}/xref-test maven.jxr.stylesheet = ${plugin.resources}/stylesheet.css -maven.jxr.templateDir = ${plugin.resources}/templates +maven.jxr.templateDir = templates diff --git a/jxr/project.properties b/jxr/project.properties deleted file mode 100644 index d66f96c3..00000000 --- a/jxr/project.properties +++ /dev/null @@ -1,19 +0,0 @@ -# ------------------------------------------------------------------- -# Copyright 2001-2004 The Apache Software Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ------------------------------------------------------------------- - -# ------------------------------------------------------------------- -# P R O J E C T P R O P E R T I E S -# ------------------------------------------------------------------- diff --git a/jxr/project.xml b/jxr/project.xml index c16f57df..c79fedd7 100644 --- a/jxr/project.xml +++ b/jxr/project.xml @@ -22,7 +22,7 @@ 3 maven-jxr-plugin Maven JXR Plug-in - 1.4.3 + 1.5-SNAPSHOT Create cross reference. Create cross reference http://maven.apache.org/reference/plugins/jxr/ @@ -56,77 +56,36 @@ - ant - ant - 1.5.3-1 - - root - - - - commons-jelly - commons-jelly - 1.0-beta-4 - - - commons-jelly - commons-jelly-tags-jsl - 1.0 - - - commons-jelly - commons-jelly-tags-xml - 1.0 - http://jakarta.apache.org/commons/jelly/libs/xml/ - - - commons-lang - commons-lang - 2.0 - - - dom4j - dom4j - 1.4-dev-8 - - - xerces - xerces - 2.4.0 - - - oro - oro - 2.0.7 + org.apache.maven + maven-jxr + 1.0-beta-1-SNAPSHOT commons-logging commons-logging 1.0.3 + - xml-apis - xml-apis - 1.0.b2 - - root - + oro + oro + 2.0.7 + + + plexus + plexus-utils + 1.0.3 + + + velocity + velocity + 1.4 commons-collections commons-collections 3.1 - - commons-beanutils - commons-beanutils-core - 1.7.0 - - - commons-jexl - commons-jexl - 1.0-beta-1 - diff --git a/jxr/src/main/org/apache/maven/jxr/CodeTransform.java b/jxr/src/main/org/apache/maven/jxr/CodeTransform.java deleted file mode 100644 index 416ef035..00000000 --- a/jxr/src/main/org/apache/maven/jxr/CodeTransform.java +++ /dev/null @@ -1,1425 +0,0 @@ -package org.apache.maven.jxr; - -/* - * CodeViewer.java - * CoolServlets.com - * March 2000 - * - * Copyright (C) 2000 CoolServlets.com - * - * 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) Neither the name CoolServlets.com nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY COOLSERVLETS.COM AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS 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 COOLSERVLETS.COM OR 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. - */ - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Serializable; -import java.io.Writer; -import java.util.Hashtable; -import java.util.Vector; - -import org.apache.commons.lang.StringUtils; -import org.apache.maven.jxr.pacman.ClassType; -import org.apache.maven.jxr.pacman.FileManager; -import org.apache.maven.jxr.pacman.ImportType; -import org.apache.maven.jxr.pacman.JavaFile; -import org.apache.maven.jxr.pacman.PackageManager; -import org.apache.maven.jxr.pacman.PackageType; -import org.apache.maven.jxr.util.SimpleWordTokenizer; -import org.apache.maven.jxr.util.StringEntry; - -/** - * Syntax highlights java by turning it into html. A codeviewer object is - * created and then keeps state as lines are passed in. Each line passed in as - * java test, is returned as syntax highlighted html text. Users of the class - * can set how the java code will be highlighted with setter methods. Only valid - * java lines should be passed in since the object maintains state and may not - * handle illegal code gracefully. The actual system is implemented as a series - * of filters that deal with specific portions of the java code. The filters are - * as follows:
- *  htmlFilter
- *     |__
- *        multiLineCommentFilter -> uriFilter
- *           |___
- *              inlineCommentFilter
- *                 |___
- *                    stringFilter
- *                       |___
- *                          keywordFilter
- *                             |___
- *                                uriFilter
- *                                   |___
- *                                      jxrFilter
- *                                         |___
- *                                            importFilter
- * 
- */ -public class CodeTransform implements Serializable -{ - - /** - * show line numbers - */ - public static final boolean LINE_NUMBERS = true; - - /** - * start comment delimeter - */ - public static final String COMMENT_START = ""; - - /** - * end comment delimeter - */ - public static final String COMMENT_END = ""; - - /** - * start javadoc comment delimeter - */ - public static final String JAVADOC_COMMENT_START = ""; - - /** - * end javadoc comment delimeter - */ - public static final String JAVADOC_COMMENT_END = ""; - - /** - * start String delimeter - */ - public static final String STRING_START = ""; - - /** - * end String delimeter - */ - public static final String STRING_END = ""; - - /** - * start reserved word delimeter - */ - public static final String RESERVED_WORD_START = ""; - - /** - * end reserved word delimeter - */ - public static final String RESERVED_WORD_END = ""; - - /** - * stylesheet file name - */ - public static final String STYLESHEET_FILENAME = "stylesheet.css"; - - /** - * Description of the Field - */ - public static final String[] VALID_URI_SCHEMES = {"http://", "mailto:"}; - - /** - * Specify the only characters that are allowed in a URI besides alpha and - * numeric characters. Refer RFC2396 - http://www.ietf.org/rfc/rfc2396.txt - */ - public static final char[] VALID_URI_CHARS = - { '?', '+', '%', '&', ':', '/', '.', '@', '_', ';', '=', '$', ',', '-', '!', '~', '*', '\'', '(', ')' }; - - /** - * HashTable containing java reserved words - */ - private Hashtable reservedWords = new Hashtable(); - - /** - * flag set to true when a multi line comment is started - */ - private boolean inMultiLineComment = false; - - /** - * flag set to true when a javadoc comment is started - */ - private boolean inJavadocComment = false; - - /** - * Set the filename that is currently being processed. - */ - private String currentFilename = null; - - /** - * The current CVS revision of the currently transformed documnt - */ - private String revision = null; - - /** - * The currently being transformed source file - */ - private String sourcefile = null; - - /** - * The currently being written destfile - */ - private String destfile = null; - - /** - * The virtual source directory that is being read from: src/java - */ - private String sourcedir = null; - - private String inputEncoding = null; - private String outputEncoding = null; - private String lang = null; - - /** - * Relative path to javadocs, suitable for hyperlinking - */ - private String javadocLinkDir; - - /** - * Package Manager for this project. - */ - private PackageManager packageManager; - - /** - * Constructor for the CodeTransform object - * @param packageManager PackageManager for this project - */ - public CodeTransform(PackageManager packageManager) - { - this.packageManager = packageManager; - loadHash(); - } - - /** - * Now different method of seeing if at end of input stream, closes inputs - * stream at end. - * @param line String - * @return filtered line of code - */ - public final String syntaxHighlight(String line) - { - return htmlFilter(line); - } - - /** - * Filter html tags into more benign text. - * @param line String - * @return html encoded line - */ - private final String htmlFilter(String line) - { - if (line == null || line.equals("")) - { - return ""; - } - line = replace(line, "&", "&"); - line = replace(line, "<", "<"); - line = replace(line, "\\\\", "//"); - line = replace(line, "\\\"", "\\""); - line = replace(line, "'\"'", "'"'"); - return multiLineCommentFilter(line); - } - - /** - * Filter out multiLine comments. State is kept with a private boolean variable. - * @param line String - * @return String - */ - private final String multiLineCommentFilter(String line) - { - if (line == null || line.equals("")) - { - return ""; - } - StringBuffer buf = new StringBuffer(); - int index; - - //First, check for the end of a java comment. - if (inJavadocComment && (index = line.indexOf("*/")) > -1 && !isInsideString(line, index)) - { - inJavadocComment = false; - buf.append(JAVADOC_COMMENT_START); - buf.append(line.substring(0, index)); - buf.append("*/").append(JAVADOC_COMMENT_END); - if (line.length() > index + 2) - { - buf.append(inlineCommentFilter(line.substring(index + 2))); - } - - return uriFilter(buf.toString()); - } - - //Second, check for the end of a multi-line comment. - if (inMultiLineComment && (index = line.indexOf("*/")) > -1 && !isInsideString(line, index)) - { - inMultiLineComment = false; - buf.append(COMMENT_START); - buf.append(line.substring(0, index)); - buf.append("*/").append(COMMENT_END); - if (line.length() > index + 2) - { - buf.append(inlineCommentFilter(line.substring(index + 2))); - } - return uriFilter(buf.toString()); - } - - //If there was no end detected and we're currently in a multi-line - //comment, we don't want to do anymore work, so return line. - else if (inMultiLineComment) - { - - StringBuffer buffer = new StringBuffer(line); - buffer.insert(0, COMMENT_START); - buffer.append(COMMENT_END); - return uriFilter(buffer.toString()); - } - else if (inJavadocComment) - { - - StringBuffer buffer = new StringBuffer(line); - buffer.insert(0, JAVADOC_COMMENT_START); - buffer.append(JAVADOC_COMMENT_END); - return uriFilter(buffer.toString()); - } - - //We're not currently in a Javadoc comment, so check to see if the start - //of a multi-line Javadoc comment is in this line. - else if ((index = line.indexOf("/**")) > -1 && !isInsideString(line, index)) - { - inJavadocComment = true; - //Return result of other filters + everything after the start - //of the multiline comment. We need to pass the through the - //to the multiLineComment filter again in case the comment ends - //on the same line. - buf.append(inlineCommentFilter(line.substring(0, index))); - buf.append(JAVADOC_COMMENT_START).append("/**"); - buf.append(multiLineCommentFilter(line.substring(index + 2))); - buf.append(JAVADOC_COMMENT_END); - return uriFilter(buf.toString()); - } - - //We're not currently in a comment, so check to see if the start - //of a multi-line comment is in this line. - else if ((index = line.indexOf("/*")) > -1 && !isInsideString(line, index)) - { - inMultiLineComment = true; - //Return result of other filters + everything after the start - //of the multiline comment. We need to pass the through the - //to the multiLineComment filter again in case the comment ends - //on the same line. - buf.append(inlineCommentFilter(line.substring(0, index))); - buf.append(COMMENT_START).append("/*"); - buf.append(multiLineCommentFilter(line.substring(index + 2))); - buf.append(COMMENT_END); - return uriFilter(buf.toString()); - } - - //Otherwise, no useful multi-line comment information was found so - //pass the line down to the next filter for processesing. - else - { - return inlineCommentFilter(line); - } - } - - /** - * Filter inline comments from a line and formats them properly. One problem - * we'll have to solve here: comments contained in a string should be - * ignored... this is also true of the multiline comments. So, we could - * either ignore the problem, or implement a function called something like - * isInsideString(line, index) where index points to some point in the line - * that we need to check... started doing this function below. - * @param line String - * @return String - */ - private final String inlineCommentFilter(String line) - { - if (line == null || line.equals("")) - { - return ""; - } - StringBuffer buf = new StringBuffer(); - int index; - if ((index = line.indexOf("//")) > -1 && !isInsideString(line, index)) - { - buf.append(stringFilter(line.substring(0, index))); - buf.append(COMMENT_START); - buf.append(line.substring(index)); - buf.append(COMMENT_END); - } - else - { - buf.append(stringFilter(line)); - } - return buf.toString(); - } - - /** - * Filters strings from a line of text and formats them properly. - * @param line String - * @return String - */ - private final String stringFilter(String line) - { - - if (line == null || line.equals("")) - { - return ""; - } - StringBuffer buf = new StringBuffer(); - if (line.indexOf("\"") <= -1) - { - return keywordFilter(line); - } - int start = 0; - int startStringIndex = -1; - int endStringIndex = -1; - int tempIndex; - //Keep moving through String characters until we want to stop... - while ((tempIndex = line.indexOf("\"")) > -1) - { - //We found the beginning of a string - if (startStringIndex == -1) - { - startStringIndex = 0; - buf.append(stringFilter(line.substring(start, tempIndex))); - buf.append(STRING_START).append("\""); - line = line.substring(tempIndex + 1); - } - //Must be at the end - else - { - startStringIndex = -1; - endStringIndex = tempIndex; - buf.append(line.substring(0, endStringIndex + 1)); - buf.append(STRING_END); - line = line.substring(endStringIndex + 1); - } - } - - buf.append(keywordFilter(line)); - - return buf.toString(); - } - - /** - * Filters keywords from a line of text and formats them properly. - * @param line String - * @return String - */ - private final String keywordFilter(String line) - { - if (line == null || line.equals("")) - { - return ""; - } - StringBuffer buf = new StringBuffer(); - Hashtable usedReservedWords = new Hashtable(); - int i = 0; - char ch; - StringBuffer temp = new StringBuffer(); - while (i < line.length()) - { - temp.setLength(0); - ch = line.charAt(i); - while (i < line.length() && ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))) - { - temp.append(ch); - i++; - if (i < line.length()) - { - ch = line.charAt(i); - } - } - String tempString = temp.toString(); - if (reservedWords.containsKey(tempString) && !usedReservedWords.containsKey(tempString)) - { - usedReservedWords.put(tempString, tempString); - line = replace(line, tempString, (RESERVED_WORD_START + tempString + RESERVED_WORD_END)); - i += (RESERVED_WORD_START.length() + RESERVED_WORD_END.length()); - } - else - { - i++; - } - } - buf.append(line); - return uriFilter(buf.toString()); - } - - /** - * Replace... I made it use a stringBuffer... hope it still works :) - * @param line String - * @param oldString String - * @param newString String - * @return String - */ - private final String replace(String line, String oldString, String newString) - { - int i = 0; - while ((i = line.indexOf(oldString, i)) >= 0) - { - line = - (new StringBuffer() - .append(line.substring(0, i)) - .append(newString) - .append(line.substring(i + oldString.length()))) - .toString(); - i += newString.length(); - } - return line; - } - - /** - * Checks to see if some position in a line is between String start and - * ending characters. Not yet used in code or fully working :) - * @param line String - * @param position int - * @return boolean - */ - private final boolean isInsideString(String line, int position) - { - if (line.indexOf("\"") < 0) - { - return false; - } - int index; - String left = line.substring(0, position); - String right = line.substring(position); - int leftCount = 0; - int rightCount = 0; - while ((index = left.indexOf("\"")) > -1) - { - leftCount++; - left = left.substring(index + 1); - } - while ((index = right.indexOf("\"")) > -1) - { - rightCount++; - right = right.substring(index + 1); - } - return (rightCount % 2 != 0 && leftCount % 2 != 0); - } - - /** - * Description of the Method - */ - private final void loadHash() - { - reservedWords.put("abstract", "abstract"); - reservedWords.put("do", "do"); - reservedWords.put("inner", "inner"); - reservedWords.put("public", "public"); - reservedWords.put("var", "var"); - reservedWords.put("boolean", "boolean"); - reservedWords.put("continue", "continue"); - reservedWords.put("int", "int"); - reservedWords.put("return", "return"); - reservedWords.put("void", "void"); - reservedWords.put("break", "break"); - reservedWords.put("else", "else"); - reservedWords.put("interface", "interface"); - reservedWords.put("short", "short"); - reservedWords.put("volatile", "volatile"); - reservedWords.put("byvalue", "byvalue"); - reservedWords.put("extends", "extends"); - reservedWords.put("long", "long"); - reservedWords.put("static", "static"); - reservedWords.put("while", "while"); - reservedWords.put("case", "case"); - reservedWords.put("final", "final"); - reservedWords.put("native", "native"); - reservedWords.put("super", "super"); - reservedWords.put("transient", "transient"); - reservedWords.put("cast", "cast"); - reservedWords.put("float", "float"); - reservedWords.put("new", "new"); - reservedWords.put("rest", "rest"); - reservedWords.put("catch", "catch"); - reservedWords.put("for", "for"); - reservedWords.put("null", "null"); - reservedWords.put("synchronized", "synchronized"); - reservedWords.put("char", "char"); - reservedWords.put("finally", "finally"); - reservedWords.put("operator", "operator"); - reservedWords.put("this", "this"); - reservedWords.put("class", "class"); - reservedWords.put("generic", "generic"); - reservedWords.put("outer", "outer"); - reservedWords.put("switch", "switch"); - reservedWords.put("const", "const"); - reservedWords.put("goto", "goto"); - reservedWords.put("package", "package"); - reservedWords.put("throw", "throw"); - reservedWords.put("double", "double"); - reservedWords.put("if", "if"); - reservedWords.put("private", "private"); - reservedWords.put("true", "true"); - reservedWords.put("default", "default"); - reservedWords.put("import", "import"); - reservedWords.put("protected", "protected"); - reservedWords.put("try", "try"); - } - - /** - * Description of the Method - * @param oos ObjectOutputStream - * @throws IOException - */ - final void writeObject(ObjectOutputStream oos) throws IOException - { - oos.defaultWriteObject(); - } - - /** - * Description of the Method - * @param ois ObjectInputStream - * @throws ClassNotFoundException - * @throws IOException - */ - final void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException - { - ois.defaultReadObject(); - } - - /** - * Gets the header attribute of the CodeTransform object - * @return String - */ - public String getHeader() - { - StringBuffer buffer = new StringBuffer(); - - String lang = this.lang; - if (lang == null) { - lang = "en"; - } - String outputEncoding = this.outputEncoding; - if (outputEncoding == null) { - outputEncoding = "ISO-8859-1"; - } - - // header - buffer - .append("\n") - .append("\n") - .append("\n") - .append(""); - - // title ("classname xref") - try - { - buffer - .append("") - .append(FileManager.getInstance().getFile(this.getCurrentFilename()).getClassType().getName()) - .append(" xref\n"); - - } - catch (IOException e) - { - buffer.append("xref\n"); - e.printStackTrace(); - } - - // stylesheet link - buffer - .append("\n"); - - buffer.append("\n").append("\n").append(this.getFileOverview()); - - // start code section - buffer.append("
\n");
-
-        return buffer.toString();
-    }
-
-    /**
-     * Gets the footer attribute of the CodeTransform object
-     * @return String
-     */
-    public final String getFooter()
-    {
-        return "
\n" + "
" + "
" + JXR.NOTICE + "
" + "\n" + "\n"; - } - - /** - * This is the public method for doing all transforms of code. - * @param sourcefile String - * @param destfile String - * @param lang String - * @param inputEncoding String - * @param outputEncoding String - * @param javadocLinkDir String - * @param revision String - * @throws IOException - */ - public final void transform(String sourcefile, String destfile, String lang, String inputEncoding, String outputEncoding, String javadocLinkDir, String revision) - throws IOException - { - - this.setCurrentFilename(sourcefile); - - this.sourcefile = sourcefile; - this.destfile = destfile; - this.lang = lang; - this.inputEncoding = inputEncoding; - this.outputEncoding = outputEncoding; - this.javadocLinkDir = javadocLinkDir; - this.revision = revision; - - //make sure that the parent directories exist... - new File(new File(destfile).getParent()).mkdirs(); - - Reader fr = null; - Writer fw = null; - try - { - if (inputEncoding != null) { - fr = new InputStreamReader(new FileInputStream(sourcefile), inputEncoding); - } - else - { - fr = new FileReader(sourcefile); - } - if (outputEncoding != null) { - fw = new OutputStreamWriter(new FileOutputStream(destfile), outputEncoding); - } - else - { - fw = new FileWriter(destfile); - } - BufferedReader in = new BufferedReader(fr); - - PrintWriter out = new PrintWriter(fw); - - String line = ""; - - out.println(getHeader()); - - int linenumber = 1; - while ((line = in.readLine()) != null) - { - if (LINE_NUMBERS) - { - out.print( - "" - + linenumber - + "" - + getLineWidth(linenumber)); - } - - out.println(this.syntaxHighlight(line)); - - ++linenumber; - } - - out.println(getFooter()); - out.flush(); - } - catch (FileNotFoundException e) - { - System.out.println("IGNORING: FileNotFoundException - file is probably in use by another process! Unable to process " + sourcefile + " => " + destfile); - } - catch (RuntimeException e) - { - System.out.println("Unable to process " + sourcefile + " => " + destfile); - throw e; - } - finally - { - if (fr != null) - { - try - { - fr.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - if (fw != null) - { - try - { - fw.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - } - - } - - /** - * Get an overview header for this file. - * @return String - */ - private final String getFileOverview() - { - StringBuffer overview = new StringBuffer(); - - // only add the header if javadocs are present - if (javadocLinkDir != null) - { - - overview.append("
"); - //get the URI to get Javadoc info. - StringBuffer javadocURI = new StringBuffer().append(getPackageRoot()).append(javadocLinkDir); - - try - { - JavaFile jf = FileManager.getInstance().getFile(this.getCurrentFilename()); - - javadocURI.append(StringUtils.replace(jf.getPackageType().getName(), ".", "/")); - javadocURI.append("/"); - if (jf.getClassType() != null) - { - javadocURI.append(jf.getClassType().getName()); - } - else - { - System.out.println(this.getCurrentFilename()); - } - javadocURI.append(".html"); - - } - catch (IOException e) - { - e.printStackTrace(); - } - - String javadocHREF = "View Javadoc"; - - //get the generation time... - overview.append(javadocHREF); - - overview.append("
"); - } - return overview.toString(); - } - - /** - * Handles line width which may need to change depending on which line - * number you are on. - * @param linenumber int - * @return String - */ - private final String getLineWidth(int linenumber) - { - if (linenumber < 10) - { - return " "; - } - else if (linenumber < 100) - { - return " "; - } - else - { - return " "; - } - } - - /** - * Handles finding classes based on the current filename and then makes - * HREFs for you to link to them with. - * @param line String - * @return String - */ - private final String jxrFilter(String line) - { - - JavaFile jf = null; - - try - { - - //if the current file isn't set then just return - if (this.getCurrentFilename() == null) - { - return line; - } - - jf = FileManager.getInstance().getFile(this.getCurrentFilename()); - } - catch (IOException e) - { - e.printStackTrace(); - return line; - } - - Vector v = new Vector(); - - //get the imported packages - ImportType[] imports = jf.getImportTypes(); - for (int j = 0; j < imports.length; ++j) - { - v.addElement(imports[j].getPackage()); - } - - //add the current package. - v.addElement(jf.getPackageType().getName()); - - String[] packages = new String[v.size()]; - v.copyInto(packages); - - StringEntry[] words = SimpleWordTokenizer.tokenize(line); - - //go through each word and then match them to the correct class if necessary. - for (int i = 0; i < words.length; ++i) - { - - //each word - StringEntry word = words[i]; - - for (int j = 0; j < packages.length; ++j) - { - - //get the package from teh PackageManager because this will hold - //the version with the classes also. - - PackageType currentImport = packageManager.getPackageType(packages[j]); - - //the package here might in fact be null because it wasn't parsed out - //this might be something that is either not included or os part - //of another package and wasn't parsed out. - - if (currentImport == null) - { - continue; - } - - //see if the current word is within the package - - //at this point the word could be a fully qualified package name - //(FQPN) or an imported package name. - - String wordName = word.toString(); - - if (wordName.indexOf(".") != -1) - { - - //if there is a "." in the string then we have to assume - //it is a package. - - String fqpn_package = null; - String fqpn_class = null; - - fqpn_package = wordName.substring(0, wordName.lastIndexOf(".")); - fqpn_class = wordName.substring(wordName.lastIndexOf(".") + 1, wordName.length()); - - //note. since this is a reference to a full package then - //it doesn't have to be explicitly imported so this information - //is useless. Instead just see if it was parsed out. - - PackageType pt = packageManager.getPackageType(fqpn_package); - - if (pt != null) - { - - ClassType ct = pt.getClassType(fqpn_class); - - if (ct != null) - { - //OK. the user specified a full package to be imported - //that is in the package manager so it is time to - //link to it. - - line = xrLine(line, pt.getName(), ct); - - } - - } - - if (fqpn_package.equals(currentImport.getName()) && currentImport.getClassType(fqpn_class) != null) - { - - //then the package we are currently in is the one specified in the string - //and the import class is correct. - line = xrLine(line, packages[j], currentImport.getClassType(fqpn_class)); - - } - - } - else if (currentImport.getClassType(wordName) != null) - { - - line = xrLine(line, packages[j], currentImport.getClassType(wordName)); - - } - - } - - } - - return importFilter(line); - } - - /** - * Get the current filename - * @return String - */ - public final String getCurrentFilename() - { - return this.currentFilename; - } - - /** - * Set the current filename - * @param filename String - */ - public final void setCurrentFilename(String filename) - { - this.currentFilename = filename; - } - - /** - * Given the current package, get an HREF to the package and class given - * @param dest String - * @param jc ClassType - * @return String - */ - private final String getHREF(String dest, ClassType jc) - { - - StringBuffer href = new StringBuffer(); - - //find out how to go back to the root - href.append(this.getPackageRoot()); - - //now find out how to get to the dest package - dest = StringUtils.replace(dest, ".*", ""); - dest = StringUtils.replace(dest, ".", "/"); - - href.append(dest); - - //now append the classname.html file - if (jc != null) - { - href.append("/"); - href.append(jc.getName()); - href.append(".html"); - } - - return href.toString(); - } - - /** - * Based on the destination package, get the HREF. - * @param dest String - * @return String - */ - private final String getHREF(String dest) - { - return getHREF(dest, null); - } - - /** - *

Given the name of a package... get the number of - * subdirectories/subpackages there would be.

- *

EX: org.apache.maven == 3

- * @param packageName String - * @return int - */ - private final int getPackageCount(String packageName) - { - - if (packageName == null) - { - return 0; - } - - int count = 0; - - int index = 0; - - while (true) - { - - index = packageName.indexOf(".", index); - - if (index == -1) - { - break; - } - ++index; - ++count; - } - - //need to increment this by one - count = ++count; - - return count; - } - - /** - * Parse out the current link and look for package/import statements and - * then create HREFs for them - * @param line String - * @return String - */ - private final String importFilter(String line) - { - - int start = -1; - - /* - Used for determining if this is a package declaration. If it is - then we can make some additional assumptions: - - that this isn't a Class import so the full String is valid - - that it WILL be on the disk since this is based on the current - - file. - */ - boolean isPackage = line.trim().startsWith("package "); - boolean isImport = line.trim().startsWith("import "); - - if (isImport || isPackage) - { - - start = line.trim().indexOf(" "); - } - - if (start != -1) - { - - //filter out this packagename... - - String pkg = line.substring(start, line.length()).trim(); - - //specify the classname of this import if any. - String classname = null; - - if (pkg.indexOf(".*") != -1) - { - - pkg = StringUtils.replace(pkg, ".*", ""); - - } - else if (!isPackage) - { - - //this is an explicit Class import - - String packageLine = pkg.toString(); - - // This catches a boundary problem where you have something like: - // - // Foo foo = FooMaster.getFooInstance(). - // danceLittleFoo(); - // - // This breaks Jxr and won't be a problem when we hook - // in the real parser. - - int a = packageLine.lastIndexOf(".") + 1; - int b = packageLine.length() - 1; - - if (a > b + 1) - { - classname = packageLine.substring(packageLine.lastIndexOf(".") + 1, packageLine.length() - 1); - - int end = pkg.lastIndexOf("."); - - if (end == -1) - { - end = pkg.length() - 1; - } - - pkg = pkg.substring(0, end); - } - - } - - pkg = StringUtils.replace(pkg, ";", ""); - String pkgHREF = getHREF(pkg); - //if this package is within the PackageManager then you can create an HREF for it. - - if (packageManager.getPackageType(pkg) != null || isPackage) - { - - //Create an HREF for explicit classname imports - if (classname != null) - { - - line = - StringUtils.replace( - line, - classname, - "" + classname + ""); - - } - - //now replace the given package with a href - line = - StringUtils.replace( - line, - pkg, - "" + pkg + ""); - } - - } - - return line; - } - - /** - * From the current file, determine the package root based on the current - * path. - * @return String - */ - public final String getPackageRoot() - { - - StringBuffer buff = new StringBuffer(); - - JavaFile jf = null; - - try - { - jf = FileManager.getInstance().getFile(this.getCurrentFilename()); - } - catch (IOException e) - { - e.printStackTrace(); - return null; - } - - String current = jf.getPackageType().getName(); - - int count = this.getPackageCount(current); - - for (int i = 0; i < count; ++i) - { - buff.append("../"); - } - - return buff.toString(); - } - - /** - * Given a line of text, search for URIs and make href's out of them - * @param line String - * @return String - */ - public final String uriFilter(String line) - { - - for (int i = 0; i < VALID_URI_SCHEMES.length; ++i) - { - - String scheme = VALID_URI_SCHEMES[i]; - - int index = line.indexOf(scheme); - - if (index != -1) - { - - int start = index; - - int end = -1; - - for (int j = start; j < line.length(); ++j) - { - - char current = line.charAt(j); - - if (!Character.isLetterOrDigit(current) && isInvalidURICharacter(current)) - { - end = j; - break; - } - - end = j; - - } - - //now you should have the full URI so you can replace this - //in the current buffer - - if (end != -1) - { - - String uri = line.substring(start, end); - - line = - StringUtils.replace( - line, - uri, - "" + uri + ""); - } - } - } - - //if we are in a multiline comment we should not call JXR here. - if (!inMultiLineComment && !inJavadocComment) - { - return jxrFilter(line); - } - else - { - return line; - } - - } - - /** - * if the given char is not one of the following in VALID_URI_CHARS then - * return true - * @param c char to check against VALID_URI_CHARS list - * @return true if c is a valid URI char - */ - private final boolean isInvalidURICharacter(char c) - { - - for (int i = 0; i < VALID_URI_CHARS.length; ++i) - { - if (VALID_URI_CHARS[i] == c) - { - return false; - } - } - - return true; - } - - /** - * The current revision of the CVS module - * @return String - */ - public final String getRevision() - { - return this.revision; - } - - /** - * The current source file being read - * @return source file name - */ - public final String getSourcefile() - { - return this.sourcefile; - } - - /** - * The current dest file being written - * @return destination file name - */ - public final String getDestfile() - { - return this.destfile; - } - - /** - * The current source directory being read from. - * @return source directory - */ - public final String getSourceDirectory() - { - return this.sourcedir; - } - - /** - * Cross Reference the given line with JXR returning the new content. - * @param line String - * @param packageName String - * @param classType ClassType - * @return String - */ - public final String xrLine(String line, String packageName, ClassType classType) - { - - StringBuffer buff = new StringBuffer(line); - - String link = null; - String find = null; - String href = null; - - if (classType != null) - { - href = this.getHREF(packageName, classType); - find = classType.getName(); - } - else - { - href = this.getHREF(packageName); - find = packageName; - } - - //build out what the link would be. - link = "" + find + ""; - - //use the SimpleWordTokenizer to find all entries - //that match word. Then replace these with the link - - //now replace the word in the buffer with the link - - String replace = link; - StringEntry[] tokens = SimpleWordTokenizer.tokenize(buff.toString(), find); - - for (int l = 0; l < tokens.length; ++l) - { - - int start = tokens[l].getIndex(); - int end = tokens[l].getIndex() + find.length(); - - buff.replace(start, end, replace); - - } - - return buff.toString(); - } - - /** - * Highlight the package in this line. - * @param line input line - * @param packageName package name - * @return input line with linked package - */ - public final String xrLine(String line, String packageName) - { - - String href = this.getHREF(packageName); - - String find = packageName; - - //build out what the link would be. - String link = "" + find + ""; - - return StringUtils.replace(line, find, link); - } - -} diff --git a/jxr/src/main/org/apache/maven/jxr/DirectoryIndexer.java b/jxr/src/main/org/apache/maven/jxr/DirectoryIndexer.java deleted file mode 100644 index 95102d6a..00000000 --- a/jxr/src/main/org/apache/maven/jxr/DirectoryIndexer.java +++ /dev/null @@ -1,358 +0,0 @@ -package org.apache.maven.jxr; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.commons.jelly.JellyContext; -import org.apache.commons.jelly.XMLOutput; -import org.apache.maven.jxr.pacman.ClassType; -import org.apache.maven.jxr.pacman.PackageManager; -import org.apache.maven.jxr.pacman.PackageType; -import org.apache.oro.text.perl.Perl5Util; - -/** - * This class creates the navigational pages for jxr's cross-referenced source - * files. The navigation is inspired by javadoc, so it should have a familiar feel. - * - * Creates the following files: - * - * - * - * @author Brian Leonard - * @version $Id$ - */ -public class DirectoryIndexer -{ - /* - * CodeTransform uses this to cross-reference package references - * with that package's main summary page. - */ - final static String INDEX = "package-summary.html"; - - /* - * Path to the root output directory. - */ - private String root; - - /* - * Package Manager for this project. - */ - private PackageManager packageManager; - - /* - * see the getter/setter docs for these properties - */ - private String outputEncoding; - private String templateDir; - private String windowTitle; - private String docTitle; - private String bottom; - - - /** - * Constructor for the DirectoryIndexer object - * - * @param packageManager PackageManager for this project - * @param root Path of the root output directory - */ - public DirectoryIndexer(PackageManager packageManager, String root) - { - this.packageManager = packageManager; - this.root = root; - } - - /** - * OutputEncoding is the encoding of output files. - * - * @param outputEncoding output Encoding - */ - public void setOutputEncoding(String outputEncoding) - { - this.outputEncoding = outputEncoding; - } - - /** - * see setOutputEncoding(String) - * - * @see setOutputEncoding(String) - */ - public String getOutputEncoding() - { - return outputEncoding; - } - - /** - * TemplateDir is the location of the jelly template files used - * to generate the navigation pages. - * - * @param templateDir location of the template directory - */ - public void setTemplateDir(String templateDir) - { - this.templateDir = templateDir; - } - - /** - * see setTemplateDir(String) - * - * @see setTemplateDir(String) - */ - public String getTemplateDir() - { - return templateDir; - } - - /** - * WindowTitle is used in the output's <title> tags - * see the javadoc documentation for the property of the same name - * - * @param windowTitle the <title> attribute - */ - public void setWindowTitle(String windowTitle) - { - this.windowTitle = windowTitle; - } - - /** - * see setWindowTitle(String) - * - * @see #setWindowTitle(String) setWindowTitle - */ - public String getWindowTitle() - { - return windowTitle; - } - - /** - * DocTitle is used as a page heading for the summary files - * see the javadoc documentation for the property of the same name - * - * @param docTitle major page heading - */ - public void setDocTitle(String docTitle) - { - this.docTitle = docTitle; - } - - /** - * see setDocTitle(String) - * - * @see #setDocTitle(String) setDocTitle - */ - public String getDocTitle() - { - return docTitle; - } - - /** - * Bottom is a footer for the navigation pages, usually a copyright - * see the javadoc documentation for the property of the same name - * - * @param bottom page footer - */ - public void setBottom(String bottom) - { - this.bottom = bottom; - } - - /** - * see setBottom(String) - * - * @see #setBottom(String) setBottom - */ - public String getBottom() - { - return bottom; - } - - /** - * Does the actual indexing. - * - * @throws Exception If something went wrong with jelly's processing. - */ - public void process() - throws Exception - { - Map info = getPackageInfo(); - - JellyContext mainContext = new JellyContext(); - mainContext.setVariable("outputEncoding", getOutputEncoding()); - mainContext.setVariable("windowTitle", getWindowTitle()); - mainContext.setVariable("docTitle", getDocTitle()); - mainContext.setVariable("bottom", getBottom()); - mainContext.setVariable("info", info); - - doJellyFile("index", root, mainContext); - doJellyFile("overview-frame", root, mainContext); - doJellyFile("allclasses-frame", root, mainContext); - doJellyFile("overview-summary", root, mainContext); - - Iterator iter = ((Map)info.get("allPackages")).values().iterator(); - while (iter.hasNext()) - { - Map pkgInfo = (Map)iter.next(); - - JellyContext subContext = mainContext.newJellyContext(); - subContext.setVariable("pkgInfo", pkgInfo); - - String outDir = root + "/" + (String)pkgInfo.get("dir"); - doJellyFile("package-summary", outDir, subContext); - doJellyFile("package-frame", outDir, subContext); - } - } - - /* - * executes a given jelly file with the given context and places the - * generated file in outDir. File names are assumed to be - * {templateName}.jelly for input and {templateName}.html for output - * - */ - private void doJellyFile(String templateName, String outDir, JellyContext context) - throws Exception - { - String outFile = outDir + "/" + templateName + ".html"; - OutputStream out = null; - try - { - // Throws FileNotFoundException - out = new FileOutputStream(outFile); - - String templateFileName = getTemplateDir() + "/" + templateName + ".jelly"; - File templateFile = new File(templateFileName); - - File theFile = new File(outFile); - File dir = theFile.getParentFile(); - if (dir != null) - { - dir.mkdirs(); - } - - XMLOutput xmlOutput = XMLOutput.createXMLOutput(out, false); - context.runScript(templateFile, xmlOutput); - xmlOutput.flush(); - } - catch (Throwable e) - { - System.out.println("IGNORING: Failed to process file [" + outFile + "]. Closing streams and moving on. Exception: " + e); - } - finally - { - try - { - if (out != null) - { - out.close(); - } - } - catch (IOException e) - { - System.out.println("Failed to close outputstream for file [" + outFile + "], which is a bad thing!"); - throw e; - } - } - } - - - /* - * Creates a Map of other Maps containing information about - * this project's packages and classes, obtained from the PackageManager. - * - * allPackages collection of Maps with package info, with the following format - * {name} package name (e.g., "org.apache.maven.jxr") - * {dir} package dir relative to the root output dir (e.g., "org/apache/maven/jxr") - * {rootRef} relative link to root output dir (e.g., "../../../../") note trailing slash - * {classes} collection of Maps with class info - * {name} class name (e.g., "DirectoryIndexer") - * {dir} duplicate of package {dir} - * - * allClasses collection of Maps with class info, format as above - * - */ - private Map getPackageInfo() - { - TreeMap allPackages = new TreeMap(); - TreeMap allClasses = new TreeMap(); - Perl5Util perl = new Perl5Util(); - - Enumeration packages = packageManager.getPackageTypes(); - while (packages.hasMoreElements()) - { - PackageType pkg = (PackageType)packages.nextElement(); - String pkgName = pkg.getName(); - String pkgDir = perl.substitute("s/\\./\\//g", pkgName); - String rootRef = perl.substitute("s/[^\\.]*(\\.|$)/\\.\\.\\//g", pkgName); - - // special case for the default package - // javadoc doesn't deal with it, but it's easy for us - if (pkgName.length() == 0) - { - pkgName = "(default package)"; - pkgDir = "."; - rootRef = "./"; - } - - TreeMap pkgClasses = new TreeMap(); - Enumeration classes = pkg.getClassTypes(); - while (classes.hasMoreElements()) - { - ClassType clazz = (ClassType)classes.nextElement(); - - String className = clazz.getName(); - Map classInfo = new HashMap(); - classInfo.put("name", className); - classInfo.put("dir", pkgDir); - - pkgClasses.put(className, classInfo); - allClasses.put(className, classInfo); - } - - Map pkgInfo = new HashMap(); - pkgInfo.put("name", pkgName); - pkgInfo.put("dir", pkgDir); - pkgInfo.put("classes", pkgClasses); - pkgInfo.put("rootRef", rootRef); - allPackages.put(pkgName, pkgInfo); - } - - Map info = new HashMap(); - info.put("allPackages", allPackages); - info.put("allClasses", allClasses); - - return info; - } -} diff --git a/jxr/src/main/org/apache/maven/jxr/JXR.java b/jxr/src/main/org/apache/maven/jxr/JXR.java deleted file mode 100644 index 6c38526f..00000000 --- a/jxr/src/main/org/apache/maven/jxr/JXR.java +++ /dev/null @@ -1,277 +0,0 @@ -package org.apache.maven.jxr; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.maven.jxr.ant.DirectoryScanner; -import org.apache.maven.jxr.pacman.PackageManager; - -/** - * Main entry point into Maven used to kick off the XReference code building. - * - * @author Kevin A. Burton - * @version $Id$ - */ -public class JXR -{ - /** Log. */ - private static final Log log = LogFactory.getLog(JxrBean.class); - - /** - * Description of the Field - */ - public final static String NOTICE = - "This page was automatically generated by " + - "Maven"; - - /** - * Path to all source.files - */ - private String source = ""; - - /** - * Path to destination - */ - private String dest = ""; - - private String lang; - private String inputEncoding; - private String outputEncoding; - - /** - * Relative path to javadocs, suitable for hyperlinking - */ - private String javadocLinkDir; - - /** - * Handles taking .java files and changing them into html. "More than meets - * the eye!" :) - */ - private CodeTransform transformer; - - /** - * The revision of the module currently being processed. - */ - private String revision; - - /** - * The constructor for the JXR class. - * - * @param packageManager The Package Manager for this project - * @param revision The CVS revision of this file. - * @param source The directory that files are being read from (src/java) - * @param source - * @param dest - */ - public JXR(PackageManager packageManager, - String source, - String dest, - String lang, - String inputEncoding, - String outputEncoding, - String javadocLinkDir, - String revision) - { - this.transformer = new CodeTransform(packageManager); - this.source = source; - this.dest = dest; - this.lang = lang; - this.inputEncoding = inputEncoding; - this.outputEncoding = outputEncoding; - this.javadocLinkDir = javadocLinkDir; - this.revision = revision; - - this.process(); - } - - - /** - * Now that we have instantiated everythign. Process this JXR task. - */ - private void process() - { - - DirectoryScanner ds = new DirectoryScanner(); - ds.addDefaultExcludes(); - - File dir = new File(this.getSource()); - - if (!dir.exists()) - { - if (dir.mkdirs() == false) - { - throw new IllegalStateException( - "Your source directory does not exist and could not be created:" + - this.getSource()); - } - } - - ds.setBasedir(this.getSource()); - ds.scan(); - - //now get the list of included files - - String[] files = ds.getIncludedFiles(); - - for (int i = 0; i < files.length; ++i) - { - if (!updated(files[i])) - { - String source = this.getSource() + - System.getProperty("file.separator") + files[i]; - - try - { - - if (isJavaFile(source)) - { - transform(source, getDestination(source)); - } - - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - } - - /** - * Check to see if the file is a Java source file - * - * @param filename The name of the file to check - * @return true - * - * if the file is a Java file - */ - public static boolean isJavaFile(String filename) - { - File file = new File(filename); - return filename.endsWith(".java") && file.length() > 0; - } - - /** - * Check to see if the file is a HTML file - * - * @param filename The name of the file to check - * @return true - * - * if the file is a HTML file - */ - public static boolean isHtmlFile(String filename) - { - return filename.endsWith(".html"); - } - - /** - * Given a filename get the destination on the filesystem of where to store - * the to be generated HTML file. Pay attention to the package name. - * - * @param filename The name of the file to find - * @return A String with the store destination. - */ - private String getDestination(String filename) - { - - String dest = new String(filename); - - //remove the source directory from the filename. - - dest = dest.substring(this.getSource().length(), dest.length()); - - int start = 0; - int end = dest.indexOf(".java"); - - if (end != -1) - { - //remove the .java from the filename - dest = dest.substring(start, end); - } - - //add the destination directory to the filename. - dest = this.getDest() + dest; - - //add .html to the filename - - dest = dest + ".html"; - - return dest; - } - - /** - * Given a source file transform it into HTML and write it to the - * destination (dest) file. - * - * @param source The jave source file - * @param dest The directory to put the HTML into - * @throws IOException Thrown if the transform can't happen for some reason. - */ - private void transform(String source, String dest) - throws IOException - { - - log.debug(source + " -> " + dest); - - transformer.transform(source, dest, lang, inputEncoding, outputEncoding, javadocLinkDir, this.revision); - - } - - /** - *

- * - * Given a java source file determine if this needs updating. This is - * determined by:

- *
    - *
  • The class doesn't exist in the destination directory
  • - *
  • The file does exist in the destination directory but is older
  • - * - *
- * - */ - private boolean updated(String file) - { - return false; - } - - /** - * Get the path to the source files - * - * @return The path to the source files - */ - public String getSource() - { - return this.source; - } - - /** - * Get the path to the destination files - * - * @return The path to the destination files - */ - public String getDest() - { - return this.dest; - } - -} - diff --git a/jxr/src/main/org/apache/maven/jxr/JxrBean.java b/jxr/src/main/org/apache/maven/jxr/JxrBean.java index e3df87f8..259ef469 100644 --- a/jxr/src/main/org/apache/maven/jxr/JxrBean.java +++ b/jxr/src/main/org/apache/maven/jxr/JxrBean.java @@ -17,23 +17,13 @@ package org.apache.maven.jxr; * ==================================================================== */ -import org.apache.maven.jxr.JXR; -import org.apache.maven.jxr.DirectoryIndexer; -import org.apache.maven.jxr.pacman.FileManager; -import org.apache.maven.jxr.pacman.PackageManager; -import org.apache.maven.jxr.pacman.PackageType; -import org.apache.maven.jxr.pacman.ClassType; -import java.util.Enumeration; - -import java.util.List; -import java.util.LinkedList; -import java.util.Iterator; -import java.io.File; -import java.io.IOException; -import java.io.FileNotFoundException; - -import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; /** * Creates an html-based, cross referenced version of Java source code @@ -46,23 +36,31 @@ import org.apache.commons.logging.LogFactory; */ public class JxrBean { - /** Log. */ - private static final Log log = LogFactory.getLog(JxrBean.class); - /* * See the doc comments for the corresponding getter/setter methods */ private List sourceDirs; + private String destDir; - private String lang; + + private Locale locale; + private String inputEncoding; + private String outputEncoding; + private String javadocDir; + private String windowTitle; + private String docTitle; + private String bottom; + private String templateDir; + private final Log log = LogFactory.getLog( JxrBean.class ); + /** * Default constructor */ @@ -73,109 +71,50 @@ public class JxrBean /** * Starts the cross-referencing and indexing. - * - * @throws IOException when any error occurs */ public void xref() - throws Exception + throws JxrException { - // get a relative link to the javadocs - String javadocLinkDir = null; - if (javadocDir != null) { - javadocLinkDir = getRelativeLink(destDir, javadocDir); - } - - // first collect package and class info - PackageManager pkgmgr = new PackageManager(); - - FileManager.getInstance().setEncoding(inputEncoding); - - // go through each source directory and xref the java files - for (Iterator i = sourceDirs.iterator(); i.hasNext();) + org.apache.maven.jxr.log.Log logger = new org.apache.maven.jxr.log.Log() { - String path = (String) i.next(); - path = new File(path).getCanonicalPath(); - - pkgmgr.process(path); - - new JXR(pkgmgr, path, destDir, lang, inputEncoding, outputEncoding, javadocLinkDir, "HEAD"); - } - - // once we have all the source files xref'd, create the index pages - DirectoryIndexer indexer = new DirectoryIndexer(pkgmgr, destDir); - indexer.setOutputEncoding(outputEncoding); - indexer.setTemplateDir(getTemplateDir()); - indexer.setWindowTitle(getWindowTitle()); - indexer.setDocTitle(getDocTitle()); - indexer.setBottom(getBottom()); - indexer.process(); - } - - /** - * 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 - - // create a List of toDir's parent directories - LinkedList parents = new LinkedList(); - File f = new File(toDir); - f = f.getCanonicalFile(); - while (f != null) - { - parents.add(f); - f = f.getParentFile(); - } - - // walk up fromDir to find the common parent - f = new File(fromDir); - f = f.getCanonicalFile(); - f = f.getParentFile(); - boolean found = false; - while (f != null && !found) - { - for (int i = 0; i < parents.size(); ++i) + public void info( String message ) { - 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; - } + log.info( message ); } - f = f.getParentFile(); - fromLink.append("../"); - } - if (!found) + public void debug( String message ) + { + log.info( message ); + } + + public void warn( String message ) + { + log.info( message ); + } + + public void error( String message ) + { + log.info( message ); + } + }; + + JXR jxr = new JXR(); + jxr.setDest( destDir ); + jxr.setLocale( locale ); + jxr.setInputEncoding( inputEncoding ); + jxr.setOutputEncoding( outputEncoding ); + jxr.setJavadocLinkDir( javadocDir ); + jxr.setRevision( "HEAD" ); + jxr.setLog( logger ); + + try { - throw new FileNotFoundException(fromDir + " and " + toDir + - " have no common parent."); + jxr.xref( sourceDirs, getTemplateDir(), getWindowTitle(), getDocTitle(), getBottom() ); + } + catch ( IOException e ) + { + throw new JxrException( "Error processing files", e ); } - - return fromLink.append(toLink.toString()).toString(); } /** @@ -183,13 +122,13 @@ public class JxrBean * * @param sourceDir The source directory to be cross-referenced. */ - public void setSourceDir(String sourceDir) + public void setSourceDir( String sourceDir ) { - if (!sourceDirs.isEmpty()) + if ( !sourceDirs.isEmpty() ) { sourceDirs.clear(); } - addSourceDir(sourceDir); + addSourceDir( sourceDir ); } /** @@ -197,9 +136,9 @@ public class JxrBean * * @param sourceDir The source directory to be cross-referenced. */ - public void addSourceDir(String sourceDir) + public void addSourceDir( String sourceDir ) { - sourceDirs.add(sourceDir); + sourceDirs.add( sourceDir ); } @@ -208,57 +147,41 @@ public class JxrBean * * @param destDir the destination directory for jxr output */ - public void setDestDir(String destDir) + public void setDestDir( String destDir ) { this.destDir = destDir; } /** * see setDestDir(String) - * - * @see setDestDir(String) */ public String getDestDir() { return destDir; } - - /** - * Lang attribute of output files. - * - * @param lang lang attribute of output files. - */ - public void setLang(String lang) + public Locale getLocale() { - this.lang = lang; + return locale; } - /** - * see setLang(String) - * - * @see setLang(String) - */ - public String getLang() + public void setLocale( Locale locale ) { - return lang; + this.locale = locale; } - /** * InputEncoding is the encoding of source files. * * @param inputEncoding encoding of source files */ - public void setInputEncoding(String inputEncoding) + public void setInputEncoding( String inputEncoding ) { this.inputEncoding = inputEncoding; } /** * see setInputEncoding(String) - * - * @see setInputEncoding(String) */ public String getInputEncoding() { @@ -271,15 +194,13 @@ public class JxrBean * * @param outputEncoding encoding of output files */ - public void setOutputEncoding(String outputEncoding) + public void setOutputEncoding( String outputEncoding ) { this.outputEncoding = outputEncoding; } /** * see setOutputEncoding(String) - * - * @see setOutputEncoding(String) */ public String getOutputEncoding() { @@ -290,20 +211,18 @@ public class JxrBean /** * JavadocDir is used to cross-reference the source code with * the appropriate javadoc pages. - * + * * If null, no javadoc link will be added. * * @param javadocDir The root directory containing javadocs */ - public void setJavadocDir(String javadocDir) + public void setJavadocDir( String javadocDir ) { this.javadocDir = javadocDir; } /** * see setJavadocDir(String) - * - * @see setJavadocDir(String) */ public String getJavadocDir() { @@ -316,7 +235,7 @@ public class JxrBean * @param windowTitle used by DirectoryIndexer * @see DirectoryIndexer#setWindowTitle(String) setWindowTitle(String) */ - public void setWindowTitle(String windowTitle) + public void setWindowTitle( String windowTitle ) { this.windowTitle = windowTitle; } @@ -337,7 +256,7 @@ public class JxrBean * @param docTitle used by DirectoryIndexer * @see DirectoryIndexer#setDocTitle(String) setDocTitle(String) */ - public void setDocTitle(String docTitle) + public void setDocTitle( String docTitle ) { this.docTitle = docTitle; } @@ -358,7 +277,7 @@ public class JxrBean * @param bottom used by DirectoryIndexer * @see DirectoryIndexer#setBottom(String) setBottom(String) */ - public void setBottom(String bottom) + public void setBottom( String bottom ) { this.bottom = bottom; } @@ -378,15 +297,13 @@ public class JxrBean * * @param templateDir the template directory */ - public void setTemplateDir(String templateDir) + public void setTemplateDir( String templateDir ) { this.templateDir = templateDir; } /** * see setTemplateDir(String) - * - * @see setTemplateDir(String) setTemplateDir(String) */ public String getTemplateDir() { diff --git a/jxr/src/main/org/apache/maven/jxr/ant/DirectoryScanner.java b/jxr/src/main/org/apache/maven/jxr/ant/DirectoryScanner.java deleted file mode 100644 index 08e371a6..00000000 --- a/jxr/src/main/org/apache/maven/jxr/ant/DirectoryScanner.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apache.maven.jxr.ant; - -import java.io.File; - -/** - * Workaround to ignore package-info.java files. - * - * @author Carlos Sanchez - */ -public class DirectoryScanner extends org.apache.tools.ant.DirectoryScanner { - - public void addDefaultExcludes() { - super.addDefaultExcludes(); - int excludesLength = excludes == null ? 0 : excludes.length; - String[] newExcludes; - newExcludes = new String[excludesLength + 1]; - if (excludesLength > 0) { - System.arraycopy(excludes, 0, newExcludes, 0, excludesLength); - } - newExcludes[excludesLength] = "**" + File.separatorChar - + "package-info.java"; - excludes = newExcludes; - } - -} diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/BaseType.java b/jxr/src/main/org/apache/maven/jxr/pacman/BaseType.java deleted file mode 100644 index 03a503dd..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/BaseType.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -/** - * put your documentation comment here - * - * @author jvanzyl - * @created February 23, 2002 - */ -public abstract class BaseType -{ - private String name = null; - - - /** - * Get the name for this type - * - * @return The name value - */ - public String getName() - { - if (name == null) - { - return ""; - } - return this.name; - } - - - /** - * Set the name for this type - * - * @param name The new name value - */ - public void setName(String name) - { - this.name = name; - } -} - diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/ClassType.java b/jxr/src/main/org/apache/maven/jxr/pacman/ClassType.java deleted file mode 100644 index 3868f24b..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/ClassType.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -/** Represents a Java class or interface */ -public class ClassType extends BaseType -{ - - /** - * Create a new ClassType - * - * @param name - */ - public ClassType(String name) - { - this.setName(name); - } - -} diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/FileManager.java b/jxr/src/main/org/apache/maven/jxr/pacman/FileManager.java deleted file mode 100644 index fbaa6450..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/FileManager.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; -import java.io.IOException; - -/** - *

- * - * Singleton that handles holding references to JavaFiles. This allows - * Alexandria to lookup and see if a file has already been parsed out and then - * it can load the information from memory instead of reparsing the file.

- *

- * - * Note. This assumes that the file will not be modified on disk while - * Alexandria is running.

- */ -public class FileManager -{ - - /** The Singleton instance of this FileManager */ - private static FileManager instance = new FileManager(); - - private Hashtable files = new Hashtable(); - private String encoding = null; - - /** Get an instance of the FileManager */ - public static FileManager getInstance() - { - return instance; - } - - /** - * Get a file from it's name. If the file does not exist within the - * FileManager, create a new one and return it. - */ - public JavaFile getFile(String name) - throws IOException - { - - JavaFile real = (JavaFile) this.files.get(name); - - if (real == null) - { - real = new JavaFileImpl(name, this.getEncoding()); - this.addFile(real); - } - - return real; - } - - /** Add a file to this filemanager. */ - public void addFile(JavaFile file) - { - this.files.put(file.getFilename(), file); - } - - /** - * Encoding is the encoding of source files. - * - * @param encoding encoding of source files - */ - public void setEncoding(String encoding) - { - this.encoding = encoding; - } - - /** - * see setEncoding(String) - * - * @see setEncoding(String) - */ - public String getEncoding() - { - return encoding; - } -} diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/ImportType.java b/jxr/src/main/org/apache/maven/jxr/pacman/ImportType.java deleted file mode 100644 index daf94f3a..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/ImportType.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -/** Represents an entry in a java "import" statement */ -public class ImportType extends BaseType -{ - - private boolean isclass = false; - private boolean ispackage = false; - private String packagename = null; - - /** - * Create a new ImportType with the specified name - * - * @param name - */ - public ImportType(String name) - { - this.setName(name); - - //compute member variables - - this.isclass = this.getName().indexOf("*") == -1; - - this.ispackage = this.getName().indexOf("*") != -1; - - int end = this.getName().lastIndexOf("."); - if (end != -1) - { - this.packagename = this.getName().substring(0, end); - } - - } - - /** Return true if this is a class import. Ex: test.Test */ - public boolean isClass() - { - return this.isclass; - } - - /** Return true if this is a package import. Ex: test.* */ - public boolean isPackage() - { - return this.ispackage; - } - - - /** - * Get the name of the package that this import is based on: EX: test.* will - * return "test" EX: test.Test will return "test" - */ - public String getPackage() - { - return this.packagename; - } - -} - diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/JavaFile.java b/jxr/src/main/org/apache/maven/jxr/pacman/JavaFile.java deleted file mode 100644 index 8e8c6335..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/JavaFile.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; - -/** - * Interface for objects which wish to provide metainfo about a JavaFile. - * - * @author Kevin A. Burton - * @version $Id$ - */ -public abstract class JavaFile -{ - - private Vector imports = new Vector(); - - private ClassType classType = null; - private PackageType packageType = new PackageType(); - - private String filename = null; - private String encoding = null; - - /** Get the imported packages/files that this package has. */ - public ImportType[] getImportTypes() - { - - ImportType[] it = new ImportType[this.imports.size()]; - this.imports.copyInto(it); - return it; - } - - /** Get the name of this class. */ - public ClassType getClassType() - { - return this.classType; - } - - /** Get the package of this class. */ - public PackageType getPackageType() - { - return this.packageType; - } - - - /** Add an ImportType to the current imports */ - public void addImportType(ImportType importType) - { - this.imports.addElement(importType); - } - - /** Set the name of this class. */ - public void setClassType(ClassType classType) - { - this.classType = classType; - } - - /** Set the PackageType of this class. */ - public void setPackageType(PackageType packageType) - { - this.packageType = packageType; - } - - - /** Gets the filename attribute of the JavaFile object */ - public String getFilename() - { - return this.filename; - } - - /** Sets the filename attribute of the JavaFile object */ - public void setFilename(String filename) - { - this.filename = filename; - } - - - /** Gets the encoding attribute of the JavaFile object */ - public String getEncoding() - { - return this.encoding; - } - - /** Sets the encoding attribute of the JavaFile object */ - public void setEncoding(String encoding) - { - this.encoding = encoding; - } -} diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/JavaFileImpl.java b/jxr/src/main/org/apache/maven/jxr/pacman/JavaFileImpl.java deleted file mode 100644 index 09d9b036..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/JavaFileImpl.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; -import java.io.*; - -/** - * PacMan implementation of a JavaFile. This will parse out the file and - * determine package, class, and imports - * - * @author Kevin A. Burton - * @version $Id$ - */ -public class JavaFileImpl extends JavaFile -{ - private Reader reader; - - /** - * Create a new JavaFileImpl that points to a given file... - * - * @param filename - * @exception IOException - */ - public JavaFileImpl(String filename, String encoding) - throws IOException - { - this.setFilename(filename); - this.setEncoding(encoding); - - //always add java.lang.* to the package imports because the JVM always - //does this implicitly. Unless we add this to the ImportTypes JXR - //won't pick up on this. - - this.addImportType(new ImportType("java.lang.*")); - - //now parse out this file. - - this.parse(); - } - - /** - * Open up the file and try to determine package, class and import - * statements. - */ - private void parse() - throws IOException - { - StreamTokenizer stok = null; - try - { - stok = this.getTokenizer(); - - while (stok.nextToken() != StreamTokenizer.TT_EOF) - { - - if (stok.sval == null) - { - continue; - } - - //set the package - if (stok.sval.equals("package")) - { - stok.nextToken(); - this.setPackageType(new PackageType(stok.sval)); - } - - //set the imports - if (stok.sval.equals("import")) - { - stok.nextToken(); - - String name = stok.sval; - - /* - WARNING: this is a bug/non-feature in the current - StreamTokenizer. We needed to set the comment char as "*" - and packages that are imported with this (ex "test.*") will be - stripped( and become "test." ). Here we need to test for this - and if necessary re-add the char. - */ - if (name.charAt(name.length() - 1) == '.') - { - name = name + "*"; - } - - this.addImportType(new ImportType(name)); - } - - //set the Class... if the class is found no more information is - //valid so just break out of the while loop at this point. - //set the imports - if (stok.sval.equals("class") || - stok.sval.equals("interface") || - stok.sval.equals("enum")) - { - stok.nextToken(); - this.setClassType(new ClassType(stok.sval)); - break; - } - - } - } - finally - { - stok = null; - if (this.reader != null) { - this.reader.close(); - } - } - } - - /** Get a StreamTokenizer for this file. */ - private StreamTokenizer getTokenizer() - throws IOException - { - - if (!new File(this.getFilename()).exists()) - { - throw new IOException(this.getFilename() + " does not exist!"); - } - - if (this.getEncoding() != null) - { - this.reader = new InputStreamReader(new FileInputStream(this.getFilename()), this.getEncoding()); - } - else - { - this.reader = new FileReader(this.getFilename()); - } - - StreamTokenizer stok = new StreamTokenizer(reader); - //int tok; - - stok.commentChar('*'); - stok.wordChars('_', '_'); - - // set tokenizer to skip comments - stok.slashStarComments(true); - stok.slashSlashComments(true); - - return stok; - } - -} diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/PackageManager.java b/jxr/src/main/org/apache/maven/jxr/pacman/PackageManager.java deleted file mode 100644 index d64d0b6c..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/PackageManager.java +++ /dev/null @@ -1,201 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; -import java.io.*; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.maven.jxr.util.*; -import org.apache.tools.ant.DirectoryScanner; - - -/** - * Given a list of directories, parse them out and store them as rendered - * packages, classes, imports, etc. - */ -public class PackageManager -{ - /** Log */ - private static final Log LOG = LogFactory.getLog(PackageManager.class); - - private Hashtable directories = new Hashtable(); - - /** - * All the packages that have been parsed - */ - private Hashtable packages = new Hashtable(); - - /** - * The default Java package. - */ - private PackageType defaultPackage = new PackageType(); - - /** - * Given the name of a package (Ex: org.apache.maven.util) obtain it from - * the PackageManager - */ - public PackageType getPackageType(String name) - { - - //return the default package if the name is null. - if (name == null) - { - return defaultPackage; - } - - return (PackageType) this.packages.get(name); - } - - /** - * Add a package to the PackageManager - */ - public void addPackageType(PackageType packageType) - { - this.packages.put(packageType.getName(), packageType); - } - - /** - * Get all of the packages in the PackageManager - */ - public Enumeration getPackageTypes() - { - return packages.elements(); - } - - /** - * Parse out all the directories on which this depends. - */ - private void parse(String directory) - { - // Go through each directory and get the java source - // files for this dir. - LOG.info("Scanning " + directory); - DirectoryScanner directoryScanner = new DirectoryScanner(); - File baseDir = new File(directory); - directoryScanner.setBasedir(baseDir); - String[] includes = { "**/*.java" }; - directoryScanner.setIncludes(includes); - directoryScanner.scan(); - String[] files = directoryScanner.getIncludedFiles(); - - for (int j = 0; j < files.length; ++j) - { - LOG.debug("parsing... " + files[j]); - - //now parse out this file to get the packages/classname/etc - try - { - String fileName = new File(baseDir,files[j]).getAbsolutePath(); - JavaFile jfi = FileManager.getInstance().getFile(fileName); - - // now that we have this parsed out blend its information - // with the current package structure - PackageType jp = this.getPackageType(jfi.getPackageType().getName()); - - if (jp == null) - { - this.addPackageType(jfi.getPackageType()); - jp = jfi.getPackageType(); - } - - //add the current class to this global package. - if (jfi.getClassType() != null && - jfi.getClassType().getName() != null) - { - jp.addClassType(jfi.getClassType()); - } - - } - catch (IOException e) - { - e.printStackTrace(); - } - - } - - } - - /** - * Description of the Method - */ - public void process(String directory) - { - if (this.directories.get(directory) == null) - { - this.parse(directory); - this.directories.put(directory, directory); - } - } - - /** - * Description of the Method - */ - public void process(String[] directories) - { - - for (int i = 0; i < directories.length; ++i) - { - this.process(directories[i]); - } - - } - - /** - * Simple logging facility - */ - public final static void log(String message) - { - System.out.println(" PackageManager -> " + message); - } - - /** - * Dump the package information to STDOUT. FOR DEBUG ONLY - */ - public void dump() - { - - LOG.debug("Dumping out PackageManager structure"); - - Enumeration pts = this.getPackageTypes(); - - while (pts.hasMoreElements()) - { - - //get the current package and print it. - PackageType current = (PackageType)pts.nextElement(); - - LOG.debug(current.getName()); - - //get the classes under the package and print those too. - Enumeration classes = current.getClassTypes(); - - while (classes.hasMoreElements()) - { - - ClassType currentClass = (ClassType) classes.nextElement(); - - LOG.debug("\t" + currentClass.getName()); - - } - } - } -} - diff --git a/jxr/src/main/org/apache/maven/jxr/pacman/PackageType.java b/jxr/src/main/org/apache/maven/jxr/pacman/PackageType.java deleted file mode 100644 index 6c01994b..00000000 --- a/jxr/src/main/org/apache/maven/jxr/pacman/PackageType.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.maven.jxr.pacman; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; - -/** Represents a Java package and its subclasses. */ -public class PackageType extends BaseType -{ - - private Hashtable classes = new Hashtable(); - - /** - * Create a Java package - * - * @param name - */ - public PackageType(String name) - { - this.setName(name); - } - - /** Create a Java package with no name IE the default Java package. */ - public PackageType() { } - - - /** Get all the known classes */ - public Enumeration getClassTypes() - { - - return classes.elements(); - } - - /** Add a class to this package. */ - public void addClassType(ClassType classType) - { - - this.classes.put(classType.getName(), classType); - - } - - /** - * Given the name of a class, get it from this package or null if it does - * not exist - */ - public ClassType getClassType(String classType) - { - - return (ClassType) this.classes.get(classType); - } - -} diff --git a/jxr/src/main/org/apache/maven/jxr/util/SimpleWordTokenizer.java b/jxr/src/main/org/apache/maven/jxr/util/SimpleWordTokenizer.java deleted file mode 100644 index 6ada6b5a..00000000 --- a/jxr/src/main/org/apache/maven/jxr/util/SimpleWordTokenizer.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.apache.maven.jxr.util; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.*; - -/** - * This is a small and fast word tokenizer. It has different characteristics - * from the normal Java tokenizer. It only considers clear words that are only - * ended with spaces as strings. EX: "Flight" would be a word but "Flight()" - * would not. - */ -public class SimpleWordTokenizer -{ - - /** Description of the Field */ - public final static char[] BREAKERS = {'(', ')', '[', ' ', '{', '}'}; - - /** Break the given line into multiple StringUtils */ - public static StringEntry[] tokenize(String line) - { - - /* - determine where to start processing this String... this could - either be the start of the line or just keep going until the first - */ - int start = getStart(line); - - //find the first non-BREAKER char and assume that is where you want to start - - if (line == null || - line.length() == 0 || - start == -1) - { - return new StringEntry[0]; - } - - return tokenize(line, start); - } - - - /** - * Tokenize the given line but only return StringUtils that match the parameter - * find. - * - * @param line String to search in - * @param find String to match. - */ - public static StringEntry[] tokenize(String line, String find) - { - - Vector v = new Vector(); - - StringEntry[] se = tokenize(line); - - for (int i = 0; i < se.length; ++i) - { - - if (se[i].toString().equals(find)) - { - v.addElement(se[i]); - } - - } - - StringEntry[] found = new StringEntry[v.size()]; - Collections.sort(v); - v.copyInto(found); - return found; - } - - /** Internal impl. Specify the start and end. */ - private static StringEntry[] tokenize(String line, int start) - { - - Vector words = new Vector(); - - //algorithm works like this... break the line out into segments - //that are separated by spaces, and if the entire String doesn't contain - //a non-Alpha char then assume it is a word. - while (true) - { - - int next = getNextBreak(line, start); - - if (next < 0 || - next <= start) - { - break; - } - - String word = line.substring(start, next); - - if (isWord(word)) - { - words.addElement(new StringEntry(word, start)); - } - - start = next + 1; - } - - StringEntry[] found = new StringEntry[words.size()]; - words.copyInto(found); - return found; - } - - - /** - * Go through the entire String and if any character is not a Letter( a, b, - * c, d, etc) then return false. - */ - private static boolean isWord(String string) - { - - if (string == null || - string.length() == 0) - { - - return false; - } - - for (int i = 0; i < string.length(); ++i) - { - - char c = string.charAt(i); - - if (Character.isLetter(c) == false && - c != '.') - { - return false; - } - - } - - return true; - } - - /** Go through the list of BREAKERS and find the closes one. */ - private static int getNextBreak(String string, int start) - { - - int breakPoint = -1; - - for (int i = 0; i < BREAKERS.length; ++i) - { - - int next = string.indexOf(BREAKERS[i], start); - - if (breakPoint == -1 || - next < breakPoint && - next != -1) - { - - breakPoint = next; - - } - - } - - //if the breakPoint is still -1 go to the end of the string - if (breakPoint == -1) - { - breakPoint = string.length(); - } - - return breakPoint; - } - - /** Go through the list of BREAKERS and find the closes one. */ - private static int getStart(String string) - { - - for (int i = 0; i < string.length(); ++i) - { - - if (isBreaker(string.charAt(i)) == false) - { - return i; - } - - } - - return -1; - } - - - /** Return true if the given char is considered a breaker. */ - private static boolean isBreaker(char c) - { - - for (int i = 0; i < BREAKERS.length; ++i) - { - - if (BREAKERS[i] == c) - { - return true; - } - - } - - return false; - } - -} - diff --git a/jxr/src/main/org/apache/maven/jxr/util/StringEntry.java b/jxr/src/main/org/apache/maven/jxr/util/StringEntry.java deleted file mode 100644 index eaeb30db..00000000 --- a/jxr/src/main/org/apache/maven/jxr/util/StringEntry.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.apache.maven.jxr.util; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -/** - * A StringEntry represents a value found by the tokenizer. The index is where - * this StringEntry was found in the source string - */ -public class StringEntry implements Comparable -{ - - private String value = null; - private int index = 0; - - /** - * Constructor for the StringEntry object - * - * @param value - * @param index - */ - public StringEntry(String value, - int index) - { - - this.value = value; - this.index = index; - } - - /** Gets the index attribute of the StringEntry object */ - public int getIndex() - { - return this.index; - } - - /** Description of the Method */ - public String toString() - { - return this.value; - } - - /** Compare two objects for equality. */ - public int compareTo(Object obj) - { - //right now only sort by the index. - - if (obj instanceof StringEntry == false) - { - - throw new IllegalArgumentException("object must be a StringEntry"); - } - - StringEntry se = (StringEntry) obj; - - if (se.getIndex() < this.getIndex()) - { - return -1; - } - else if (se.getIndex() == this.getIndex()) - { - return 0; - } - else - { - return 1; - } - - } - -} - diff --git a/jxr/src/plugin-resources/templates/allclasses-frame.jelly b/jxr/src/plugin-resources/templates/allclasses-frame.jelly deleted file mode 100644 index 4c5c03ae..00000000 --- a/jxr/src/plugin-resources/templates/allclasses-frame.jelly +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - All Classes - - - - -

All Classes

- - - - - -
diff --git a/jxr/src/plugin-resources/templates/index.jelly b/jxr/src/plugin-resources/templates/index.jelly deleted file mode 100644 index 23ae56fc..00000000 --- a/jxr/src/plugin-resources/templates/index.jelly +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - ${windowTitle} - - - - - - - - - - <h1>Frame Alert</h1> - <p> - You don't have frames. Go - <a href="overview-summary.html">here</a> - </p> - - - diff --git a/jxr/src/plugin-resources/templates/overview-frame.jelly b/jxr/src/plugin-resources/templates/overview-frame.jelly deleted file mode 100644 index 7e2d11c2..00000000 --- a/jxr/src/plugin-resources/templates/overview-frame.jelly +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - ${windowTitle} - - - - -

- All Classes -

- -

Packages

- - - - - -
diff --git a/jxr/src/plugin-resources/templates/overview-summary.jelly b/jxr/src/plugin-resources/templates/overview-summary.jelly deleted file mode 100644 index 0d4b0fc7..00000000 --- a/jxr/src/plugin-resources/templates/overview-summary.jelly +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - ${windowTitle} - - - - - -
- ${bottom} - - -
- - - -

${docTitle}

- - - - - - - - - - - - - - - -
Packages
- ${pkgInfo.name} -
- -
- - - - -
-
    -
  • Overview
  • -
  • Package
  • -
-
-
- -
- - -
-
-
diff --git a/jxr/src/plugin-resources/templates/package-frame.jelly b/jxr/src/plugin-resources/templates/package-frame.jelly deleted file mode 100644 index d2b9d2e5..00000000 --- a/jxr/src/plugin-resources/templates/package-frame.jelly +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - ${windowTitle} Package ${pkgInfo.name} - - - - -

- ${pkgInfo.name} -

- -

Classes

- - - - - -
diff --git a/jxr/src/plugin-resources/templates/package-summary.jelly b/jxr/src/plugin-resources/templates/package-summary.jelly deleted file mode 100644 index d20f867f..00000000 --- a/jxr/src/plugin-resources/templates/package-summary.jelly +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - ${windowTitle} Package ${name} - - - - - - -
- - ${bottom} - - -
- - -

Package ${pkgInfo.name}

- - - - - - - - - - - - - - - -
Class Summary
- ${classInfo.name} -
- -
- - - - -
- -
-
- -
- - - -
- -
-
diff --git a/jxr/src/test/org/apache/maven/jxr/CodeTransformTest.java b/jxr/src/test/org/apache/maven/jxr/CodeTransformTest.java deleted file mode 100644 index 197cf3e5..00000000 --- a/jxr/src/test/org/apache/maven/jxr/CodeTransformTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apache.maven.jxr; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.maven.jxr.pacman.PackageManager; - -public class CodeTransformTest - extends TestCase -{ - - private CodeTransform codeTransform; - - private PackageManager packageManager; - - protected void setUp() - throws Exception - { - super.setUp(); - packageManager = new PackageManager(); - codeTransform = new CodeTransform( packageManager ); - } - - public void testTransform() - throws Exception - { - File sourceFile = new File( System.getProperty( "basedir" ) - + "/src/test/org/apache/maven/jxr/CodeTransformTest.java" ); - assertTrue( sourceFile.exists() ); - codeTransform.transform( sourceFile.getAbsolutePath(), System.getProperty( "basedir" ) - + "/target/CodeTransformTest.html", "en", "ISO-8859-1", "ISO-8859-1", "", "" ); - // sourceFile = new File("src/test/org/apache/maven/jxr/package-info.java"); - // assertTrue(sourceFile.exists()); - // codeTransform.transform(sourceFile.getAbsolutePath(), - // "target/pakage-info.html", "en", "ISO-8859-1", "ISO-8859-1", - // "", ""); - } - -} diff --git a/jxr/src/test/org/apache/maven/jxr/JxrBeanTest.java b/jxr/src/test/org/apache/maven/jxr/JxrBeanTest.java index 4ff6db28..06e8eb3c 100644 --- a/jxr/src/test/org/apache/maven/jxr/JxrBeanTest.java +++ b/jxr/src/test/org/apache/maven/jxr/JxrBeanTest.java @@ -17,7 +17,7 @@ public class JxrBeanTest jxrBean.setDestDir( System.getProperty( "basedir" ) + "/target" ); jxrBean.setInputEncoding( "ISO-8859-1" ); jxrBean.setOutputEncoding( "ISO-8859-1" ); - jxrBean.setTemplateDir( System.getProperty( "basedir" ) + "/src/plugin-resources/templates" ); + jxrBean.setTemplateDir( "templates" ); jxrBean.setJavadocDir( "" ); jxrBean.setWindowTitle( "title" ); jxrBean.setDocTitle( "title" );