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:
parent
fcc5cf6cb8
commit
6e89eaf4cf
@ -79,6 +79,12 @@
|
||||
|
||||
<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"
|
||||
value="Copyright &copy; ${year} ${pom.organization.name}. All Rights Reserved." />
|
||||
|
||||
@ -90,6 +96,8 @@
|
||||
<jxr:jxr
|
||||
sourceDir="${pom.build.sourceDirectory}"
|
||||
destDir="${maven.jxr.destdir}"
|
||||
inputEncoding="${inputEncoding}"
|
||||
outputEncoding="${outputEncoding}"
|
||||
templateDir="${maven.jxr.templateDir}"
|
||||
javadocDir="${javadocDestdir}"
|
||||
windowTitle="${title}"
|
||||
|
||||
@ -32,13 +32,19 @@ package org.apache.maven.jxr;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
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;
|
||||
|
||||
@ -183,6 +189,10 @@ public class CodeTransform implements Serializable
|
||||
*/
|
||||
private String sourcedir = null;
|
||||
|
||||
private String inputEncoding = null;
|
||||
private String outputEncoding = null;
|
||||
private String lang = null;
|
||||
|
||||
/**
|
||||
* Relative path to javadocs, suitable for hyperlinking
|
||||
*/
|
||||
@ -597,19 +607,27 @@ public class CodeTransform implements Serializable
|
||||
|
||||
/**
|
||||
* Gets the header attribute of the CodeTransform object
|
||||
* @todo make language and encoding headers customizable
|
||||
* @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("<!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("<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")
|
||||
try
|
||||
@ -654,11 +672,14 @@ public class CodeTransform implements Serializable
|
||||
* 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 javadocLinkDir, String revision)
|
||||
public final void transform(String sourcefile, String destfile, String lang, String inputEncoding, String outputEncoding, String javadocLinkDir, String revision)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
@ -666,18 +687,33 @@ public class CodeTransform implements Serializable
|
||||
|
||||
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();
|
||||
|
||||
FileReader fr = null;
|
||||
FileWriter fw = null;
|
||||
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);
|
||||
|
||||
@ -29,7 +29,7 @@ import org.apache.tools.ant.DirectoryScanner;
|
||||
* Main entry point into Maven used to kick off the XReference code building.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
@ -53,6 +53,10 @@ public class JXR
|
||||
*/
|
||||
private String dest = "";
|
||||
|
||||
private String lang;
|
||||
private String inputEncoding;
|
||||
private String outputEncoding;
|
||||
|
||||
/**
|
||||
* Relative path to javadocs, suitable for hyperlinking
|
||||
*/
|
||||
@ -81,12 +85,18 @@ public class JXR
|
||||
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;
|
||||
|
||||
@ -223,7 +233,7 @@ public class JXR
|
||||
|
||||
log.debug(source + " -> " + dest);
|
||||
|
||||
transformer.transform(source, dest, javadocLinkDir, this.revision);
|
||||
transformer.transform(source, dest, lang, inputEncoding, outputEncoding, javadocLinkDir, this.revision);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ 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;
|
||||
@ -41,7 +42,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @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: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
|
||||
{
|
||||
@ -53,6 +54,9 @@ public class JxrBean
|
||||
*/
|
||||
private List sourceDirs;
|
||||
private String destDir;
|
||||
private String lang;
|
||||
private String inputEncoding;
|
||||
private String outputEncoding;
|
||||
private String javadocDir;
|
||||
private String windowTitle;
|
||||
private String docTitle;
|
||||
@ -84,6 +88,8 @@ public class JxrBean
|
||||
// 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();)
|
||||
{
|
||||
@ -92,7 +98,7 @@ public class JxrBean
|
||||
|
||||
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
|
||||
@ -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
|
||||
* the appropriate javadoc pages.
|
||||
|
||||
@ -38,6 +38,7 @@ public class 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()
|
||||
@ -57,7 +58,7 @@ public class FileManager
|
||||
|
||||
if (real == null)
|
||||
{
|
||||
real = new JavaFileImpl(name);
|
||||
real = new JavaFileImpl(name, this.getEncoding());
|
||||
this.addFile(real);
|
||||
}
|
||||
|
||||
@ -70,4 +71,23 @@ public class FileManager
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import java.util.*;
|
||||
* Interface for objects which wish to provide metainfo about a JavaFile.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
@ -34,6 +34,7 @@ public abstract class JavaFile
|
||||
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()
|
||||
@ -87,4 +88,17 @@ public abstract class JavaFile
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ import java.io.*;
|
||||
* determine package, class, and imports
|
||||
*
|
||||
* @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
|
||||
{
|
||||
@ -37,10 +37,11 @@ public class JavaFileImpl extends JavaFile
|
||||
* @param filename
|
||||
* @exception IOException
|
||||
*/
|
||||
public JavaFileImpl(String filename)
|
||||
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
|
||||
@ -134,7 +135,14 @@ public class JavaFileImpl extends JavaFile
|
||||
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;
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
</properties>
|
||||
<body>
|
||||
<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="fix" issue="MPJXR-13">Remove NullPointerException for empty java files.</action>
|
||||
<action dev="dion" type="update">Reduce output for non-debug run.</action>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user