MPJXR-14. Support encoding and lang.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
evenisse 2004-08-23 13:12:44 +00:00
parent fcc5cf6cb8
commit 6e89eaf4cf
8 changed files with 183 additions and 17 deletions

View File

@ -79,6 +79,12 @@
<maven:pluginVar var="javadocDestdir" plugin='maven-javadoc-plugin' property='maven.javadoc.destdir'/> <maven:pluginVar var="javadocDestdir" plugin='maven-javadoc-plugin' property='maven.javadoc.destdir'/>
<j:set var="inputEncoding"
value="${maven.compile.encoding}" />
<j:set var="outputEncoding"
value="${maven.docs.outputencoding}" />
<j:set var="copyright" <j:set var="copyright"
value="Copyright &amp;copy; ${year} ${pom.organization.name}. All Rights Reserved." /> value="Copyright &amp;copy; ${year} ${pom.organization.name}. All Rights Reserved." />
@ -90,6 +96,8 @@
<jxr:jxr <jxr:jxr
sourceDir="${pom.build.sourceDirectory}" sourceDir="${pom.build.sourceDirectory}"
destDir="${maven.jxr.destdir}" destDir="${maven.jxr.destdir}"
inputEncoding="${inputEncoding}"
outputEncoding="${outputEncoding}"
templateDir="${maven.jxr.templateDir}" templateDir="${maven.jxr.templateDir}"
javadocDir="${javadocDestdir}" javadocDir="${javadocDestdir}"
windowTitle="${title}" windowTitle="${title}"

View File

@ -32,13 +32,19 @@ package org.apache.maven.jxr;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Reader;
import java.io.Serializable; import java.io.Serializable;
import java.io.Writer;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
@ -183,6 +189,10 @@ public class CodeTransform implements Serializable
*/ */
private String sourcedir = null; private String sourcedir = null;
private String inputEncoding = null;
private String outputEncoding = null;
private String lang = null;
/** /**
* Relative path to javadocs, suitable for hyperlinking * Relative path to javadocs, suitable for hyperlinking
*/ */
@ -597,19 +607,27 @@ public class CodeTransform implements Serializable
/** /**
* Gets the header attribute of the CodeTransform object * Gets the header attribute of the CodeTransform object
* @todo make language and encoding headers customizable
* @return String * @return String
*/ */
public String getHeader() public String getHeader()
{ {
StringBuffer buffer = new StringBuffer(); 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 // header
buffer buffer
.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n") .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")
.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n") .append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"").append(lang).append("\" lang=\"").append(lang).append("\">\n")
.append("<head>\n") .append("<head>\n")
.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />"); .append("<meta http-equiv=\"content-type\" content=\"text/html; charset=").append(outputEncoding).append("\" />");
// title ("classname xref") // title ("classname xref")
try try
@ -654,11 +672,14 @@ public class CodeTransform implements Serializable
* This is the public method for doing all transforms of code. * This is the public method for doing all transforms of code.
* @param sourcefile String * @param sourcefile String
* @param destfile String * @param destfile String
* @param lang String
* @param inputEncoding String
* @param outputEncoding String
* @param javadocLinkDir String * @param javadocLinkDir String
* @param revision String * @param revision String
* @throws IOException * @throws IOException
*/ */
public final void transform(String sourcefile, String destfile, String javadocLinkDir, String revision) public final void transform(String sourcefile, String destfile, String lang, String inputEncoding, String outputEncoding, String javadocLinkDir, String revision)
throws IOException throws IOException
{ {
@ -666,18 +687,33 @@ public class CodeTransform implements Serializable
this.sourcefile = sourcefile; this.sourcefile = sourcefile;
this.destfile = destfile; this.destfile = destfile;
this.lang = lang;
this.inputEncoding = inputEncoding;
this.outputEncoding = outputEncoding;
this.javadocLinkDir = javadocLinkDir; this.javadocLinkDir = javadocLinkDir;
this.revision = revision; this.revision = revision;
//make sure that the parent directories exist... //make sure that the parent directories exist...
new File(new File(destfile).getParent()).mkdirs(); new File(new File(destfile).getParent()).mkdirs();
FileReader fr = null; Reader fr = null;
FileWriter fw = null; Writer fw = null;
try try
{
if (inputEncoding != null) {
fr = new InputStreamReader(new FileInputStream(sourcefile), inputEncoding);
}
else
{ {
fr = new FileReader(sourcefile); fr = new FileReader(sourcefile);
}
if (outputEncoding != null) {
fw = new OutputStreamWriter(new FileOutputStream(destfile), outputEncoding);
}
else
{
fw = new FileWriter(destfile); fw = new FileWriter(destfile);
}
BufferedReader in = new BufferedReader(fr); BufferedReader in = new BufferedReader(fr);
PrintWriter out = new PrintWriter(fw); PrintWriter out = new PrintWriter(fw);

View File

@ -29,7 +29,7 @@ import org.apache.tools.ant.DirectoryScanner;
* Main entry point into Maven used to kick off the XReference code building. * Main entry point into Maven used to kick off the XReference code building.
* *
* @author <a href="mailto:burton@apache.org">Kevin A. Burton</a> * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
* @version $Id: JXR.java,v 1.8 2004/08/23 12:17:46 evenisse Exp $ * @version $Id: JXR.java,v 1.9 2004/08/23 13:12:44 evenisse Exp $
*/ */
public class JXR public class JXR
{ {
@ -53,6 +53,10 @@ public class JXR
*/ */
private String dest = ""; private String dest = "";
private String lang;
private String inputEncoding;
private String outputEncoding;
/** /**
* Relative path to javadocs, suitable for hyperlinking * Relative path to javadocs, suitable for hyperlinking
*/ */
@ -81,12 +85,18 @@ public class JXR
public JXR(PackageManager packageManager, public JXR(PackageManager packageManager,
String source, String source,
String dest, String dest,
String lang,
String inputEncoding,
String outputEncoding,
String javadocLinkDir, String javadocLinkDir,
String revision) String revision)
{ {
this.transformer = new CodeTransform(packageManager); this.transformer = new CodeTransform(packageManager);
this.source = source; this.source = source;
this.dest = dest; this.dest = dest;
this.lang = lang;
this.inputEncoding = inputEncoding;
this.outputEncoding = outputEncoding;
this.javadocLinkDir = javadocLinkDir; this.javadocLinkDir = javadocLinkDir;
this.revision = revision; this.revision = revision;
@ -223,7 +233,7 @@ public class JXR
log.debug(source + " -> " + dest); log.debug(source + " -> " + dest);
transformer.transform(source, dest, javadocLinkDir, this.revision); transformer.transform(source, dest, lang, inputEncoding, outputEncoding, javadocLinkDir, this.revision);
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.jxr;
import org.apache.maven.jxr.JXR; import org.apache.maven.jxr.JXR;
import org.apache.maven.jxr.DirectoryIndexer; 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.PackageManager;
import org.apache.maven.jxr.pacman.PackageType; import org.apache.maven.jxr.pacman.PackageType;
import org.apache.maven.jxr.pacman.ClassType; import org.apache.maven.jxr.pacman.ClassType;
@ -41,7 +42,7 @@ import org.apache.commons.logging.LogFactory;
* @author <a href="mailto:lucas@collab.net">Josh Lucas</a> * @author <a href="mailto:lucas@collab.net">Josh Lucas</a>
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a> * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @author <a href="mailto:brian@brainslug.com">Brian Leonard</a> * @author <a href="mailto:brian@brainslug.com">Brian Leonard</a>
* @version $Id: JxrBean.java,v 1.9 2004/03/02 15:08:12 evenisse Exp $ * @version $Id: JxrBean.java,v 1.10 2004/08/23 13:12:44 evenisse Exp $
*/ */
public class JxrBean public class JxrBean
{ {
@ -53,6 +54,9 @@ public class JxrBean
*/ */
private List sourceDirs; private List sourceDirs;
private String destDir; private String destDir;
private String lang;
private String inputEncoding;
private String outputEncoding;
private String javadocDir; private String javadocDir;
private String windowTitle; private String windowTitle;
private String docTitle; private String docTitle;
@ -84,6 +88,8 @@ public class JxrBean
// first collect package and class info // first collect package and class info
PackageManager pkgmgr = new PackageManager(); PackageManager pkgmgr = new PackageManager();
FileManager.getInstance().setEncoding(inputEncoding);
// go through each source directory and xref the java files // go through each source directory and xref the java files
for (Iterator i = sourceDirs.iterator(); i.hasNext();) for (Iterator i = sourceDirs.iterator(); i.hasNext();)
{ {
@ -92,7 +98,7 @@ public class JxrBean
pkgmgr.process(path); pkgmgr.process(path);
new JXR(pkgmgr, path, destDir, javadocLinkDir, "HEAD"); new JXR(pkgmgr, path, destDir, lang, inputEncoding, outputEncoding, javadocLinkDir, "HEAD");
} }
// once we have all the source files xref'd, create the index pages // once we have all the source files xref'd, create the index pages
@ -217,6 +223,69 @@ public class JxrBean
} }
/**
* Lang attribute of output files.
*
* @param lang lang attribute of output files.
*/
public void setLang(String lang)
{
this.lang = lang;
}
/**
* see setLang(String)
*
* @see setLang(String)
*/
public String getLang()
{
return lang;
}
/**
* InputEncoding is the encoding of source files.
*
* @param inputEncoding encoding of source files
*/
public void setInputEncoding(String inputEncoding)
{
this.inputEncoding = inputEncoding;
}
/**
* see setInputEncoding(String)
*
* @see setInputEncoding(String)
*/
public String getInputEncoding()
{
return inputEncoding;
}
/**
* OutputEncoding is the encoding of output files.
*
* @param outputEncoding encoding of output files
*/
public void setOutputEncoding(String outputEncoding)
{
this.outputEncoding = outputEncoding;
}
/**
* see setOutputEncoding(String)
*
* @see setOutputEncoding(String)
*/
public String getOutputEncoding()
{
return outputEncoding;
}
/** /**
* JavadocDir is used to cross-reference the source code with * JavadocDir is used to cross-reference the source code with
* the appropriate javadoc pages. * the appropriate javadoc pages.

View File

@ -38,6 +38,7 @@ public class FileManager
private static FileManager instance = new FileManager(); private static FileManager instance = new FileManager();
private Hashtable files = new Hashtable(); private Hashtable files = new Hashtable();
private String encoding = null;
/** Get an instance of the FileManager */ /** Get an instance of the FileManager */
public static FileManager getInstance() public static FileManager getInstance()
@ -57,7 +58,7 @@ public class FileManager
if (real == null) if (real == null)
{ {
real = new JavaFileImpl(name); real = new JavaFileImpl(name, this.getEncoding());
this.addFile(real); this.addFile(real);
} }
@ -70,4 +71,23 @@ public class FileManager
this.files.put(file.getFilename(), 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;
}
} }

View File

@ -23,7 +23,7 @@ import java.util.*;
* Interface for objects which wish to provide metainfo about a JavaFile. * Interface for objects which wish to provide metainfo about a JavaFile.
* *
* @author <a href="mailto:burton@apache.org">Kevin A. Burton</a> * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
* @version $Id: JavaFile.java,v 1.2 2004/03/02 15:08:12 evenisse Exp $ * @version $Id: JavaFile.java,v 1.3 2004/08/23 13:12:44 evenisse Exp $
*/ */
public abstract class JavaFile public abstract class JavaFile
{ {
@ -34,6 +34,7 @@ public abstract class JavaFile
private PackageType packageType = new PackageType(); private PackageType packageType = new PackageType();
private String filename = null; private String filename = null;
private String encoding = null;
/** Get the imported packages/files that this package has. */ /** Get the imported packages/files that this package has. */
public ImportType[] getImportTypes() public ImportType[] getImportTypes()
@ -87,4 +88,17 @@ public abstract class JavaFile
{ {
this.filename = 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;
}
} }

View File

@ -25,7 +25,7 @@ import java.io.*;
* determine package, class, and imports * determine package, class, and imports
* *
* @author <a href="mailto:burton@apache.org">Kevin A. Burton</a> * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
* @version $Id: JavaFileImpl.java,v 1.4 2004/03/02 15:08:12 evenisse Exp $ * @version $Id: JavaFileImpl.java,v 1.5 2004/08/23 13:12:44 evenisse Exp $
*/ */
public class JavaFileImpl extends JavaFile public class JavaFileImpl extends JavaFile
{ {
@ -37,10 +37,11 @@ public class JavaFileImpl extends JavaFile
* @param filename * @param filename
* @exception IOException * @exception IOException
*/ */
public JavaFileImpl(String filename) public JavaFileImpl(String filename, String encoding)
throws IOException throws IOException
{ {
this.setFilename(filename); this.setFilename(filename);
this.setEncoding(encoding);
//always add java.lang.* to the package imports because the JVM always //always add java.lang.* to the package imports because the JVM always
//does this implicitly. Unless we add this to the ImportTypes JXR //does this implicitly. Unless we add this to the ImportTypes JXR
@ -134,7 +135,14 @@ public class JavaFileImpl extends JavaFile
throw new IOException(this.getFilename() + " does not exist!"); 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()); this.reader = new FileReader(this.getFilename());
}
StreamTokenizer stok = new StreamTokenizer(reader); StreamTokenizer stok = new StreamTokenizer(reader);
//int tok; //int tok;

View File

@ -26,6 +26,7 @@
</properties> </properties>
<body> <body>
<release version="1.4.2-SNAPSHOT" date="in CVS"> <release version="1.4.2-SNAPSHOT" date="in CVS">
<action dev="evenisse" type="update" issue="MPJXR-14">Support encoding and lang.</action>
<action dev="evenisse" type="update" issue="MPJXR-17">Add the possibility to run JXR for tests classes if sources classes doesn't exists.</action> <action dev="evenisse" type="update" issue="MPJXR-17">Add the possibility to run JXR for tests classes if sources classes doesn't exists.</action>
<action dev="evenisse" type="fix" issue="MPJXR-13">Remove NullPointerException for empty java files.</action> <action dev="evenisse" type="fix" issue="MPJXR-13">Remove NullPointerException for empty java files.</action>
<action dev="dion" type="update">Reduce output for non-debug run.</action> <action dev="dion" type="update">Reduce output for non-debug run.</action>