applied 'maven jalopy' to fix most of the checkstyle errors
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@116036 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
264554a748
commit
903b1038b2
2 files changed
+493
-529
No files matched your search
@@ -1,5 +1,9 @@
|
||||
package org.apache.maven.javadoc;
|
||||
|
||||
import org.apache.commons.collections.set.ListOrderedSet;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
@@ -16,7 +20,6 @@ package org.apache.maven.javadoc;
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -26,6 +29,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -33,379 +37,377 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.collections.set.ListOrderedSet;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Converts the javadoc warnings into an xml (xdoc format) file.
|
||||
*
|
||||
* @author Steven Caswell (stevencaswell at apache.org)
|
||||
* @version $Id: JavadocWarningsTextToXml.java,v 1.3 2004/09/03 22:25:03 aheritier Exp $
|
||||
* @version $Id: JavadocWarningsTextToXml.java,v 1.4 2004/09/05 21:00:34 felipeal Exp $
|
||||
*/
|
||||
public class JavadocWarningsTextToXml {
|
||||
//~ Static fields/initializers ----------------------------------------------
|
||||
public class JavadocWarningsTextToXml
|
||||
{
|
||||
/** Number of args on the command line.*/
|
||||
private static final int ARGS_LENGTH = 3;
|
||||
|
||||
/** Number of args on the command line.*/
|
||||
private static final int ARGS_LENGTH = 3;
|
||||
/** XML padding. */
|
||||
private static final int PADDING = 10;
|
||||
|
||||
/** XML padding. */
|
||||
private static final int PADDING = 10;
|
||||
/** Full path for the input file (javadoc plain text report). */
|
||||
private String inputFileName;
|
||||
|
||||
//~ Instance fields ---------------------------------------------------------
|
||||
/** XML encoding. */
|
||||
private String outputEncoding;
|
||||
|
||||
/** Full path for the input file (javadoc plain text report). */
|
||||
private String inputFileName;
|
||||
/** Full path for the generated XDoc file. */
|
||||
private String outputFileName;
|
||||
|
||||
/** XML encoding. */
|
||||
private String outputEncoding;
|
||||
/** Verbose flag. */
|
||||
private boolean verbose = false;
|
||||
|
||||
/** Full path for the generated XDoc file. */
|
||||
private String outputFileName;
|
||||
|
||||
/** Verbose flag. */
|
||||
private boolean verbose = false;
|
||||
|
||||
//~ Methods -----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Invokes an instance of <code>JavadocWarningsTextToXml</code> from the
|
||||
* command line. The following command line arguments are expected in this
|
||||
* order:
|
||||
*
|
||||
* <ol>
|
||||
* <li>
|
||||
* input file name
|
||||
* </li>
|
||||
* <li>
|
||||
* output file name
|
||||
* </li>
|
||||
* <li>
|
||||
* output encoding
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
*
|
||||
* @param args the command line arguments
|
||||
*
|
||||
* @throws IOException if an exception occurs opening, reading, or writing
|
||||
* files
|
||||
* @throws IllegalArgumentException if arguments aren't correctly setted.
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
throws IOException {
|
||||
if (args.length != ARGS_LENGTH) {
|
||||
throw new IllegalArgumentException("Wrong number of arguments");
|
||||
}
|
||||
|
||||
JavadocWarningsTextToXml runner = new JavadocWarningsTextToXml();
|
||||
int i = 0;
|
||||
runner.setInputFileName(args[i++]);
|
||||
runner.setOutputFileName(args[i++]);
|
||||
runner.setOutputEncoding(args[i++]);
|
||||
runner.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the input file. This file is expected to be a report
|
||||
* generated by Javadoc.
|
||||
*
|
||||
* @param inputFileName the input file name
|
||||
*/
|
||||
public void setInputFileName(final String inputFileName) {
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Setting input file name: '" + inputFileName + "'");
|
||||
}
|
||||
|
||||
this.inputFileName = inputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the input file.
|
||||
*
|
||||
* @return the inptu file name
|
||||
*/
|
||||
public String getInputFileName() {
|
||||
return this.inputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output encoding.
|
||||
*
|
||||
* @param outputEncoding the output encoding
|
||||
*/
|
||||
public void setOutputEncoding(final String outputEncoding) {
|
||||
this.outputEncoding = outputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output encoding.
|
||||
*
|
||||
* @return the output encoding
|
||||
*/
|
||||
public String getOutputEncoding() {
|
||||
return this.outputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file name.
|
||||
*
|
||||
* @param outputFileName the output file name
|
||||
*/
|
||||
public void setOutputFileName(final String outputFileName) {
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Setting output file name: '" + outputFileName + "'");
|
||||
}
|
||||
|
||||
this.outputFileName = outputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the output file.
|
||||
*
|
||||
* @return the output file name
|
||||
*/
|
||||
public String getOutputFileName() {
|
||||
return this.outputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the verbose mode. <br>
|
||||
*
|
||||
* @param verbose the verbose mode.
|
||||
*/
|
||||
public void setVerbose(final boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("verbose is true");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the xml file from the javadoc report input.
|
||||
*
|
||||
* @throws FileNotFoundException if the input file cannot be opened for
|
||||
* reading or the output file cannot be opened for writing
|
||||
* @throws IOException if an error occurs reading or writing
|
||||
* @throws UnsupportedEncodingException if an unknown encoding was specified
|
||||
* @throws IllegalArgumentException If a needed property isn't setted.
|
||||
*/
|
||||
public void build()
|
||||
throws FileNotFoundException,
|
||||
IOException,
|
||||
UnsupportedEncodingException {
|
||||
if (StringUtils.isBlank(getInputFileName())) {
|
||||
throw new IllegalArgumentException("Input file name must be specified");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(getOutputFileName())) {
|
||||
throw new IllegalArgumentException("Output file name must be specified");
|
||||
}
|
||||
|
||||
String[] lines = this.readInput();
|
||||
Map fileMap = this.buildMap(lines);
|
||||
this.buildOutput(fileMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the verbose.
|
||||
*
|
||||
* @return Returns the verbose.
|
||||
*/
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
private Map buildMap(final String[] input) {
|
||||
if (this.isVerbose()) {
|
||||
System.out.println(
|
||||
"Building map from " + input.length + " input line(s)"
|
||||
);
|
||||
}
|
||||
|
||||
Map files = new TreeMap();
|
||||
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
String line = input[i];
|
||||
if (this.isVerbose()) {
|
||||
System.out.println(
|
||||
"Parsing line " + line
|
||||
);
|
||||
}
|
||||
try {
|
||||
// Break up line into pieces
|
||||
int javaDocStart = line.indexOf("[javadoc]");
|
||||
int fileNameStart = javaDocStart += PADDING;
|
||||
int warningStart = line.indexOf("warning - ");
|
||||
int fileNameEnd = warningStart - 1;
|
||||
String fileNameAndLineNumber =
|
||||
line.substring(
|
||||
fileNameStart,
|
||||
fileNameEnd
|
||||
);
|
||||
int lastColon = fileNameAndLineNumber.lastIndexOf(':');
|
||||
int nextToLastColon =
|
||||
fileNameAndLineNumber.lastIndexOf(
|
||||
':',
|
||||
lastColon - 1
|
||||
);
|
||||
String fileName = fileNameAndLineNumber.substring(
|
||||
0,
|
||||
nextToLastColon
|
||||
);
|
||||
String lineNumber =
|
||||
fileNameAndLineNumber.substring(
|
||||
nextToLastColon + 1,
|
||||
lastColon
|
||||
);
|
||||
int msgStart = warningStart + PADDING;
|
||||
String msg = line.substring(msgStart);
|
||||
|
||||
// Get the messages for the file
|
||||
Map fileMessages = (Map) files.get(fileName);
|
||||
|
||||
if (fileMessages == null) {
|
||||
fileMessages = new TreeMap();
|
||||
files.put(
|
||||
fileName,
|
||||
fileMessages
|
||||
);
|
||||
/**
|
||||
* Invokes an instance of <code>JavadocWarningsTextToXml</code> from the
|
||||
* command line. The following command line arguments are expected in this
|
||||
* order:
|
||||
*
|
||||
* <ol>
|
||||
* <li>
|
||||
* input file name
|
||||
* </li>
|
||||
* <li>
|
||||
* output file name
|
||||
* </li>
|
||||
* <li>
|
||||
* output encoding
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
*
|
||||
* @param args the command line arguments
|
||||
*
|
||||
* @throws IOException if an exception occurs opening, reading, or writing
|
||||
* files
|
||||
* @throws IllegalArgumentException if arguments aren't correctly setted.
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
throws IOException
|
||||
{
|
||||
if (args.length != ARGS_LENGTH)
|
||||
{
|
||||
throw new IllegalArgumentException("Wrong number of arguments");
|
||||
}
|
||||
|
||||
// Get the messages for the line
|
||||
Set lineMessages = (Set) fileMessages.get(new Integer(lineNumber));
|
||||
JavadocWarningsTextToXml runner = new JavadocWarningsTextToXml();
|
||||
int i = 0;
|
||||
|
||||
if (lineMessages == null) {
|
||||
lineMessages = new ListOrderedSet();
|
||||
|
||||
fileMessages.put(
|
||||
new Integer(lineNumber),
|
||||
lineMessages
|
||||
);
|
||||
runner.setInputFileName(args[i++]);
|
||||
runner.setOutputFileName(args[i++]);
|
||||
runner.setOutputEncoding(args[i++]);
|
||||
runner.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the input file. This file is expected to be a report
|
||||
* generated by Javadoc.
|
||||
*
|
||||
* @param inputFileName the input file name
|
||||
*/
|
||||
public void setInputFileName(final String inputFileName)
|
||||
{
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Setting input file name: '" + inputFileName
|
||||
+ "'");
|
||||
}
|
||||
|
||||
// Put the message into the line messages set
|
||||
lineMessages.add(msg);
|
||||
} catch( Throwable t ) {
|
||||
System.err.println("*** WARNING: exception parsing line '" + line +
|
||||
"': " + t.getMessage() );
|
||||
if (this.isVerbose()) {
|
||||
t.printStackTrace();
|
||||
this.inputFileName = inputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the input file.
|
||||
*
|
||||
* @return the inptu file name
|
||||
*/
|
||||
public String getInputFileName()
|
||||
{
|
||||
return this.inputFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output encoding.
|
||||
*
|
||||
* @param outputEncoding the output encoding
|
||||
*/
|
||||
public void setOutputEncoding(final String outputEncoding)
|
||||
{
|
||||
this.outputEncoding = outputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output encoding.
|
||||
*
|
||||
* @return the output encoding
|
||||
*/
|
||||
public String getOutputEncoding()
|
||||
{
|
||||
return this.outputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file name.
|
||||
*
|
||||
* @param outputFileName the output file name
|
||||
*/
|
||||
public void setOutputFileName(final String outputFileName)
|
||||
{
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Setting output file name: '" + outputFileName
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
} // for
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private void buildOutput(final Map fileMap)
|
||||
throws FileNotFoundException,
|
||||
UnsupportedEncodingException {
|
||||
File output = new File(this.outputFileName);
|
||||
File dir = output.getParentFile();
|
||||
|
||||
if (dir != null) {
|
||||
dir.mkdirs();
|
||||
this.outputFileName = outputFileName;
|
||||
}
|
||||
|
||||
PrintWriter out =
|
||||
new PrintWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(output),
|
||||
this.getOutputEncoding()
|
||||
)
|
||||
);
|
||||
writeOutput(
|
||||
fileMap,
|
||||
out
|
||||
);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
private String[] readInput()
|
||||
throws FileNotFoundException,
|
||||
IOException {
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Reading '" + getInputFileName() + "'");
|
||||
/**
|
||||
* Returns the name of the output file.
|
||||
*
|
||||
* @return the output file name
|
||||
*/
|
||||
public String getOutputFileName()
|
||||
{
|
||||
return this.outputFileName;
|
||||
}
|
||||
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new FileReader(getInputFileName()));
|
||||
/**
|
||||
* Sets the verbose mode. <br>
|
||||
*
|
||||
* @param verbose the verbose mode.
|
||||
*/
|
||||
public void setVerbose(final boolean verbose)
|
||||
{
|
||||
this.verbose = verbose;
|
||||
|
||||
List lines = new ArrayList();
|
||||
String line = null;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// Look for lines containing the string "warning - "
|
||||
if (line.indexOf("warning - ") >= 0) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Read " + lines.size() + " line(s) from input file");
|
||||
}
|
||||
|
||||
return (String[]) lines.toArray(new String[lines.size()]);
|
||||
}
|
||||
|
||||
private void writeOutput(
|
||||
final Map fileMap,
|
||||
final PrintWriter out
|
||||
) {
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Writing to output file '" + this.outputFileName);
|
||||
}
|
||||
|
||||
out.println(
|
||||
"<?xml version=\"1.0\" encoding=\"" + this.getOutputEncoding() + "\"?>"
|
||||
);
|
||||
out.println("<javadoc>");
|
||||
|
||||
for (
|
||||
Iterator fileMapIterator = fileMap.keySet()
|
||||
.iterator();
|
||||
fileMapIterator.hasNext();
|
||||
) {
|
||||
String fileName = (String) fileMapIterator.next();
|
||||
out.println("<file name=\"" + fileName + "\">");
|
||||
|
||||
Map fileMessages = (Map) fileMap.get(fileName);
|
||||
|
||||
for (
|
||||
Iterator fileMessagesIterator = fileMessages.entrySet()
|
||||
.iterator();
|
||||
fileMessagesIterator.hasNext();
|
||||
) {
|
||||
Map.Entry entry = (Map.Entry) fileMessagesIterator.next();
|
||||
Integer lineNumber = (Integer) entry.getKey();
|
||||
Set lineMessages = (Set) entry.getValue();
|
||||
|
||||
for (
|
||||
Iterator lineMessagesIterator = lineMessages.iterator();
|
||||
lineMessagesIterator.hasNext();
|
||||
) {
|
||||
String msg = (String) lineMessagesIterator.next();
|
||||
out.println(
|
||||
"<error line=\"" + lineNumber
|
||||
+ "\" severity=\"warning\" message=\""
|
||||
+ StringEscapeUtils.escapeXml(msg) + "\"/>"
|
||||
);
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("verbose is true");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("</file>");
|
||||
}
|
||||
|
||||
out.println("</javadoc>");
|
||||
/**
|
||||
* Builds the xml file from the javadoc report input.
|
||||
*
|
||||
* @throws FileNotFoundException if the input file cannot be opened for
|
||||
* reading or the output file cannot be opened for writing
|
||||
* @throws IOException if an error occurs reading or writing
|
||||
* @throws UnsupportedEncodingException if an unknown encoding was specified
|
||||
* @throws IllegalArgumentException If a needed property isn't setted.
|
||||
*/
|
||||
public void build()
|
||||
throws FileNotFoundException, IOException, UnsupportedEncodingException
|
||||
{
|
||||
if (StringUtils.isBlank(getInputFileName()))
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"Input file name must be specified");
|
||||
}
|
||||
|
||||
if (this.isVerbose()) {
|
||||
System.out.println("Finished writing output file");
|
||||
if (StringUtils.isBlank(getOutputFileName()))
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"Output file name must be specified");
|
||||
}
|
||||
|
||||
String[] lines = this.readInput();
|
||||
Map fileMap = this.buildMap(lines);
|
||||
|
||||
this.buildOutput(fileMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the verbose.
|
||||
*
|
||||
* @return Returns the verbose.
|
||||
*/
|
||||
public boolean isVerbose()
|
||||
{
|
||||
return verbose;
|
||||
}
|
||||
|
||||
private Map buildMap(final String[] input)
|
||||
{
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Building map from " + input.length
|
||||
+ " input line(s)");
|
||||
}
|
||||
|
||||
Map files = new TreeMap();
|
||||
|
||||
for (int i = 0; i < input.length; i++)
|
||||
{
|
||||
String line = input[i];
|
||||
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Parsing line " + line);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Break up line into pieces
|
||||
int javaDocStart = line.indexOf("[javadoc]");
|
||||
int fileNameStart = javaDocStart += PADDING;
|
||||
int warningStart = line.indexOf("warning - ");
|
||||
int fileNameEnd = warningStart - 1;
|
||||
String fileNameAndLineNumber = line.substring(fileNameStart,
|
||||
fileNameEnd);
|
||||
int lastColon = fileNameAndLineNumber.lastIndexOf(':');
|
||||
int nextToLastColon = fileNameAndLineNumber.lastIndexOf(':',
|
||||
lastColon - 1);
|
||||
String fileName = fileNameAndLineNumber.substring(0,
|
||||
nextToLastColon);
|
||||
String lineNumber = fileNameAndLineNumber.substring(nextToLastColon
|
||||
+ 1, lastColon);
|
||||
int msgStart = warningStart + PADDING;
|
||||
String msg = line.substring(msgStart);
|
||||
|
||||
// Get the messages for the file
|
||||
Map fileMessages = (Map) files.get(fileName);
|
||||
|
||||
if (fileMessages == null)
|
||||
{
|
||||
fileMessages = new TreeMap();
|
||||
files.put(fileName, fileMessages);
|
||||
}
|
||||
|
||||
// Get the messages for the line
|
||||
Set lineMessages = (Set) fileMessages.get(new Integer(
|
||||
lineNumber));
|
||||
|
||||
if (lineMessages == null)
|
||||
{
|
||||
lineMessages = new ListOrderedSet();
|
||||
|
||||
fileMessages.put(new Integer(lineNumber), lineMessages);
|
||||
}
|
||||
|
||||
// Put the message into the line messages set
|
||||
lineMessages.add(msg);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.err.println("*** WARNING: exception parsing line '"
|
||||
+ line + "': " + t.getMessage());
|
||||
|
||||
if (this.isVerbose())
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
} // for
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private void buildOutput(final Map fileMap)
|
||||
throws FileNotFoundException, UnsupportedEncodingException
|
||||
{
|
||||
File output = new File(this.outputFileName);
|
||||
File dir = output.getParentFile();
|
||||
|
||||
if (dir != null)
|
||||
{
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
PrintWriter out = new PrintWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(output), this.getOutputEncoding()));
|
||||
|
||||
writeOutput(fileMap, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
private String[] readInput()
|
||||
throws FileNotFoundException, IOException
|
||||
{
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Reading '" + getInputFileName() + "'");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(
|
||||
getInputFileName()));
|
||||
|
||||
List lines = new ArrayList();
|
||||
String line = null;
|
||||
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
// Look for lines containing the string "warning - "
|
||||
if (line.indexOf("warning - ") >= 0)
|
||||
{
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Read " + lines.size()
|
||||
+ " line(s) from input file");
|
||||
}
|
||||
|
||||
return (String[]) lines.toArray(new String[lines.size()]);
|
||||
}
|
||||
|
||||
private void writeOutput(final Map fileMap, final PrintWriter out)
|
||||
{
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Writing to output file '" + this.outputFileName);
|
||||
}
|
||||
|
||||
out.println("<?xml version=\"1.0\" encoding=\""
|
||||
+ this.getOutputEncoding() + "\"?>");
|
||||
out.println("<javadoc>");
|
||||
|
||||
for (Iterator fileMapIterator = fileMap.keySet().iterator();
|
||||
fileMapIterator.hasNext();)
|
||||
{
|
||||
String fileName = (String) fileMapIterator.next();
|
||||
|
||||
out.println("<file name=\"" + fileName + "\">");
|
||||
|
||||
Map fileMessages = (Map) fileMap.get(fileName);
|
||||
|
||||
for (Iterator fileMessagesIterator = fileMessages.entrySet()
|
||||
.iterator();
|
||||
fileMessagesIterator.hasNext();)
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) fileMessagesIterator.next();
|
||||
Integer lineNumber = (Integer) entry.getKey();
|
||||
Set lineMessages = (Set) entry.getValue();
|
||||
|
||||
for (Iterator lineMessagesIterator = lineMessages.iterator();
|
||||
lineMessagesIterator.hasNext();)
|
||||
{
|
||||
String msg = (String) lineMessagesIterator.next();
|
||||
|
||||
out.println("<error line=\"" + lineNumber
|
||||
+ "\" severity=\"warning\" message=\""
|
||||
+ StringEscapeUtils.escapeXml(msg) + "\"/>");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("</file>");
|
||||
}
|
||||
|
||||
out.println("</javadoc>");
|
||||
|
||||
if (this.isVerbose())
|
||||
{
|
||||
System.out.println("Finished writing output file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.apache.maven.javadoc;
|
||||
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
@@ -16,11 +17,9 @@ package org.apache.maven.javadoc;
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -28,194 +27,157 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
|
||||
/**
|
||||
* Test case.
|
||||
*
|
||||
* @author Steven Caswell
|
||||
* @version $Id: JavadocWarningsTextToXmlTest.java,v 1.1 2004/08/21 18:42:05 aheritier Exp $
|
||||
* @version $Id: JavadocWarningsTextToXmlTest.java,v 1.2 2004/09/05 21:00:34 felipeal Exp $
|
||||
*/
|
||||
public class JavadocWarningsTextToXmlTest
|
||||
extends TestCase {
|
||||
//~ Static fields/initializers ----------------------------------------------
|
||||
public class JavadocWarningsTextToXmlTest extends TestCase
|
||||
{
|
||||
private static final String INPUT_FILE_NAME_EXCEPTION = "Input file name must be specified";
|
||||
private static final String OUTPUT_FILE_NAME_EXCEPTION = "Output file name must be specified";
|
||||
|
||||
private static final String INPUT_FILE_NAME_EXCEPTION =
|
||||
"Input file name must be specified";
|
||||
|
||||
private static final String OUTPUT_FILE_NAME_EXCEPTION =
|
||||
"Output file name must be specified";
|
||||
|
||||
//~ Constructors ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a new JavadocWarningsTextToXmlTest object.
|
||||
*
|
||||
*/
|
||||
public JavadocWarningsTextToXmlTest(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//~ Methods -----------------------------------------------------------------
|
||||
|
||||
public static void main(final String[] main) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(JavadocWarningsTextToXmlTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize per test data
|
||||
*
|
||||
* @throws Exception when there is an unexpected problem
|
||||
*/
|
||||
public void setUp()
|
||||
throws Exception {
|
||||
String baseDir = System.getProperty("basedir");
|
||||
System.out.println("Base dir : " + baseDir);
|
||||
assertNotNull(
|
||||
"The system property basedir was not defined.",
|
||||
baseDir
|
||||
);
|
||||
}
|
||||
|
||||
public void testBuild()
|
||||
throws Exception {
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
bean.setVerbose(true);
|
||||
bean.setInputFileName("target/test-classes/report.txt");
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1");
|
||||
bean.build();
|
||||
|
||||
// Read and test the output file contents
|
||||
BufferedReader reader = new BufferedReader(new FileReader("test.xml"));
|
||||
String line = reader.readLine();
|
||||
assertTrue(
|
||||
"line 1 start",
|
||||
line.startsWith("<?xml version=\"1.0\" encoding=\"")
|
||||
);
|
||||
assertTrue(
|
||||
"line 1 end",
|
||||
line.endsWith("ISO-8859-1\"?>")
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 2",
|
||||
"<javadoc>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertTrue(
|
||||
"line 3 start",
|
||||
line.startsWith("<file name")
|
||||
);
|
||||
assertTrue(
|
||||
"line 3 end",
|
||||
line.endsWith("Javadoc1.java\">")
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 4",
|
||||
"<error line=\"8\" severity=\"warning\" message=\"@inheritDoc used but method1() does not override or implement any method.\"/>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 5",
|
||||
"</file>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertTrue(
|
||||
"line 6 start",
|
||||
line.startsWith("<file name")
|
||||
);
|
||||
assertTrue(
|
||||
"line 6 end",
|
||||
line.endsWith("Javadoc2.java\">")
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 7",
|
||||
"<error line=\"8\" severity=\"warning\" message=\"@todo is an unknown tag.\"/>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 8",
|
||||
"<error line=\"15\" severity=\"warning\" message=\"Tag @link: malformed: "Javadoc1#method1("\"/>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 9",
|
||||
"</file>",
|
||||
line
|
||||
);
|
||||
line = reader.readLine();
|
||||
assertEquals(
|
||||
"line 10",
|
||||
"</javadoc>",
|
||||
line
|
||||
);
|
||||
|
||||
reader.close();
|
||||
|
||||
// Get rid of the xml file
|
||||
File file = new File("test.xml");
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public void testInputFile()
|
||||
throws Exception {
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try {
|
||||
bean.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals(
|
||||
"exception message",
|
||||
INPUT_FILE_NAME_EXCEPTION,
|
||||
e.getMessage()
|
||||
);
|
||||
/**
|
||||
* Creates a new JavadocWarningsTextToXmlTest object.
|
||||
*
|
||||
*/
|
||||
public JavadocWarningsTextToXmlTest(final String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void testInputFileNotFound()
|
||||
throws Exception {
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
bean.setInputFileName("junk.dat");
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try {
|
||||
bean.build();
|
||||
fail("Expected null pointer exception for input file name");
|
||||
} catch (FileNotFoundException e) {
|
||||
; // expected file not found
|
||||
public static void main(final String[] main)
|
||||
{
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
||||
public void testOutputFile()
|
||||
throws Exception {
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
bean.setInputFileName("report.txt");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try {
|
||||
bean.build();
|
||||
fail("Expected null pointer exception for input file name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals(
|
||||
"exception message",
|
||||
OUTPUT_FILE_NAME_EXCEPTION,
|
||||
e.getMessage()
|
||||
);
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite(JavadocWarningsTextToXmlTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize per test data
|
||||
*
|
||||
* @throws Exception when there is an unexpected problem
|
||||
*/
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
String baseDir = System.getProperty("basedir");
|
||||
|
||||
System.out.println("Base dir : " + baseDir);
|
||||
assertNotNull("The system property basedir was not defined.", baseDir);
|
||||
}
|
||||
|
||||
public void testBuild() throws Exception
|
||||
{
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
|
||||
bean.setVerbose(true);
|
||||
bean.setInputFileName("target/test-classes/report.txt");
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1");
|
||||
bean.build();
|
||||
|
||||
// Read and test the output file contents
|
||||
BufferedReader reader = new BufferedReader(new FileReader("test.xml"));
|
||||
String line = reader.readLine();
|
||||
|
||||
assertTrue("line 1 start",
|
||||
line.startsWith("<?xml version=\"1.0\" encoding=\""));
|
||||
assertTrue("line 1 end", line.endsWith("ISO-8859-1\"?>"));
|
||||
line = reader.readLine();
|
||||
assertEquals("line 2", "<javadoc>", line);
|
||||
line = reader.readLine();
|
||||
assertTrue("line 3 start", line.startsWith("<file name"));
|
||||
assertTrue("line 3 end", line.endsWith("Javadoc1.java\">"));
|
||||
line = reader.readLine();
|
||||
assertEquals("line 4",
|
||||
"<error line=\"8\" severity=\"warning\" message=\"@inheritDoc used but method1() does not override or implement any method.\"/>",
|
||||
line);
|
||||
line = reader.readLine();
|
||||
assertEquals("line 5", "</file>", line);
|
||||
line = reader.readLine();
|
||||
assertTrue("line 6 start", line.startsWith("<file name"));
|
||||
assertTrue("line 6 end", line.endsWith("Javadoc2.java\">"));
|
||||
line = reader.readLine();
|
||||
assertEquals("line 7",
|
||||
"<error line=\"8\" severity=\"warning\" message=\"@todo is an unknown tag.\"/>",
|
||||
line);
|
||||
line = reader.readLine();
|
||||
assertEquals("line 8",
|
||||
"<error line=\"15\" severity=\"warning\" message=\"Tag @link: malformed: "Javadoc1#method1("\"/>",
|
||||
line);
|
||||
line = reader.readLine();
|
||||
assertEquals("line 9", "</file>", line);
|
||||
line = reader.readLine();
|
||||
assertEquals("line 10", "</javadoc>", line);
|
||||
|
||||
reader.close();
|
||||
|
||||
// Get rid of the xml file
|
||||
File file = new File("test.xml");
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public void testInputFile()
|
||||
throws Exception
|
||||
{
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try
|
||||
{
|
||||
bean.build();
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
assertEquals("exception message", INPUT_FILE_NAME_EXCEPTION,
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testInputFileNotFound()
|
||||
throws Exception
|
||||
{
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
|
||||
bean.setInputFileName("junk.dat");
|
||||
bean.setOutputFileName("test.xml");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try
|
||||
{
|
||||
bean.build();
|
||||
fail("Expected null pointer exception for input file name");
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
; // expected file not found
|
||||
}
|
||||
}
|
||||
|
||||
public void testOutputFile()
|
||||
throws Exception
|
||||
{
|
||||
JavadocWarningsTextToXml bean = new JavadocWarningsTextToXml();
|
||||
|
||||
bean.setInputFileName("report.txt");
|
||||
bean.setOutputEncoding("ISO-8859-1]");
|
||||
|
||||
try
|
||||
{
|
||||
bean.build();
|
||||
fail("Expected null pointer exception for input file name");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
assertEquals("exception message", OUTPUT_FILE_NAME_EXCEPTION,
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user