Don't use commons-collections 3.1 which is binary incompatible with commons-collections 2.1 (bundled in maven 1.0.2)

downgrade to 3.0

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@293038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
aheritier 2005-10-01 22:48:27 +00:00
parent 518f4fbddb
commit a0fa5497cc
3 changed files with 89 additions and 124 deletions

View File

@ -140,7 +140,7 @@
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections</artifactId>
<version>3.1</version> <version>3.0</version>
<type>jar</type> <type>jar</type>
<properties/> <properties/>
</dependency> </dependency>

View File

@ -17,26 +17,6 @@ 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.
*
* 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.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -46,13 +26,17 @@ import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.collections.SetUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
/** /**
* Converts the javadoc warnings into an xml (xdoc format) file. * Converts the javadoc warnings into an xml (xdoc format) file.
@ -103,20 +87,20 @@ public class JavadocWarningsTextToXml
* @throws IOException if an exception occurs opening, reading, or writing * @throws IOException if an exception occurs opening, reading, or writing
* files * files
*/ */
public static void main(final String[] args) public static void main( final String[] args )
throws IOException throws IOException
{ {
if (args.length != ARGS_LENGTH) if ( args.length != ARGS_LENGTH )
{ {
throw new IllegalArgumentException("Wrong number of arguments"); throw new IllegalArgumentException( "Wrong number of arguments" );
} }
JavadocWarningsTextToXml runner = new JavadocWarningsTextToXml(); JavadocWarningsTextToXml runner = new JavadocWarningsTextToXml();
int i = 0; int i = 0;
runner.setInputFileName(args[i++]); runner.setInputFileName( args[i++] );
runner.setOutputFileName(args[i++]); runner.setOutputFileName( args[i++] );
runner.setOutputEncoding(args[i++]); runner.setOutputEncoding( args[i++] );
runner.build(); runner.build();
} }
@ -126,12 +110,11 @@ public class JavadocWarningsTextToXml
* *
* @param inputFileNameValue the input file name * @param inputFileNameValue the input file name
*/ */
public void setInputFileName(final String inputFileNameValue) public void setInputFileName( final String inputFileNameValue )
{ {
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Setting input file name: '" + inputFileNameValue System.out.println( "Setting input file name: '" + inputFileNameValue + "'" );
+ "'");
} }
this.inputFileName = inputFileNameValue; this.inputFileName = inputFileNameValue;
@ -152,7 +135,7 @@ public class JavadocWarningsTextToXml
* *
* @param outputEncodingValue the output encoding * @param outputEncodingValue the output encoding
*/ */
public void setOutputEncoding(final String outputEncodingValue) public void setOutputEncoding( final String outputEncodingValue )
{ {
this.outputEncoding = outputEncodingValue; this.outputEncoding = outputEncodingValue;
} }
@ -172,12 +155,11 @@ public class JavadocWarningsTextToXml
* *
* @param outputFileNameValue the output file name * @param outputFileNameValue the output file name
*/ */
public void setOutputFileName(final String outputFileNameValue) public void setOutputFileName( final String outputFileNameValue )
{ {
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Setting output file name: '" + outputFileNameValue System.out.println( "Setting output file name: '" + outputFileNameValue + "'" );
+ "'");
} }
this.outputFileName = outputFileNameValue; this.outputFileName = outputFileNameValue;
@ -198,13 +180,13 @@ public class JavadocWarningsTextToXml
* *
* @param verboseValue the verbose mode. * @param verboseValue the verbose mode.
*/ */
public void setVerbose(final boolean verboseValue) public void setVerbose( final boolean verboseValue )
{ {
this.verbose = verboseValue; this.verbose = verboseValue;
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("verbose is true"); System.out.println( "verbose is true" );
} }
} }
@ -219,22 +201,20 @@ public class JavadocWarningsTextToXml
public void build() public void build()
throws FileNotFoundException, IOException, UnsupportedEncodingException throws FileNotFoundException, IOException, UnsupportedEncodingException
{ {
if (StringUtils.isBlank(getInputFileName())) if ( StringUtils.isBlank( getInputFileName() ) )
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException( "Input file name must be specified" );
"Input file name must be specified");
} }
if (StringUtils.isBlank(getOutputFileName())) if ( StringUtils.isBlank( getOutputFileName() ) )
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException( "Output file name must be specified" );
"Output file name must be specified");
} }
String[] lines = this.readInput(); String[] lines = this.readInput();
Map fileMap = this.buildMap(lines); Map fileMap = this.buildMap( lines );
this.buildOutput(fileMap); this.buildOutput( fileMap );
} }
/** /**
@ -252,73 +232,66 @@ public class JavadocWarningsTextToXml
* @param input the lines * @param input the lines
* @return the Map of files with javadoc errors. * @return the Map of files with javadoc errors.
*/ */
private Map buildMap(final String[] input) private Map buildMap( final String[] input )
{ {
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Building map from " + input.length System.out.println( "Building map from " + input.length + " input line(s)" );
+ " input line(s)");
} }
Map files = new TreeMap(); Map files = new TreeMap();
for (int i = 0; i < input.length; i++) for ( int i = 0; i < input.length; i++ )
{ {
String line = input[i]; String line = input[i];
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Parsing line " + line); System.out.println( "Parsing line " + line );
} }
try try
{ {
// Break up line into pieces // Break up line into pieces
int javaDocStart = line.indexOf("[javadoc]"); int javaDocStart = line.indexOf( "[javadoc]" );
int fileNameStart = javaDocStart += PADDING; int fileNameStart = javaDocStart += PADDING;
int warningStart = line.indexOf("warning - "); int warningStart = line.indexOf( "warning - " );
int fileNameEnd = warningStart - 1; int fileNameEnd = warningStart - 1;
String fileNameAndLineNumber = line.substring(fileNameStart, String fileNameAndLineNumber = line.substring( fileNameStart, fileNameEnd );
fileNameEnd); int lastColon = fileNameAndLineNumber.lastIndexOf( ':' );
int lastColon = fileNameAndLineNumber.lastIndexOf(':'); int nextToLastColon = fileNameAndLineNumber.lastIndexOf( ':', lastColon - 1 );
int nextToLastColon = fileNameAndLineNumber.lastIndexOf(':', String fileName = fileNameAndLineNumber.substring( 0, nextToLastColon );
lastColon - 1); String lineNumber = fileNameAndLineNumber.substring( nextToLastColon + 1, lastColon );
String fileName = fileNameAndLineNumber.substring(0,
nextToLastColon);
String lineNumber = fileNameAndLineNumber.substring(nextToLastColon
+ 1, lastColon);
int msgStart = warningStart + PADDING; int msgStart = warningStart + PADDING;
String msg = line.substring(msgStart); String msg = line.substring( msgStart );
// Get the messages for the file // Get the messages for the file
Map fileMessages = (Map) files.get(fileName); Map fileMessages = (Map) files.get( fileName );
if (fileMessages == null) if ( fileMessages == null )
{ {
fileMessages = new TreeMap(); fileMessages = new TreeMap();
files.put(fileName, fileMessages); files.put( fileName, fileMessages );
} }
// Get the messages for the line // Get the messages for the line
Set lineMessages = (Set) fileMessages.get(new Integer( Set lineMessages = (Set) fileMessages.get( new Integer( lineNumber ) );
lineNumber));
if (lineMessages == null) if ( lineMessages == null )
{ {
lineMessages = new ListOrderedSet(); lineMessages = SetUtils.orderedSet( new TreeSet() );
fileMessages.put(new Integer(lineNumber), lineMessages); fileMessages.put( new Integer( lineNumber ), lineMessages );
} }
// Put the message into the line messages set // Put the message into the line messages set
lineMessages.add(msg); lineMessages.add( msg );
} }
catch (Throwable t) catch ( Throwable t )
{ {
System.err.println("*** WARNING: exception parsing line '" System.err.println( "*** WARNING: exception parsing line '" + line + "': " + t.getMessage() );
+ line + "': " + t.getMessage());
if (this.isVerbose()) if ( this.isVerbose() )
{ {
t.printStackTrace(); t.printStackTrace();
} }
@ -334,21 +307,21 @@ public class JavadocWarningsTextToXml
* @throws FileNotFoundException If the file cannot be created. * @throws FileNotFoundException If the file cannot be created.
* @throws UnsupportedEncodingException If the encoding isn't supported. * @throws UnsupportedEncodingException If the encoding isn't supported.
*/ */
private void buildOutput(final Map fileMap) private void buildOutput( final Map fileMap )
throws FileNotFoundException, UnsupportedEncodingException throws FileNotFoundException, UnsupportedEncodingException
{ {
File output = new File(this.outputFileName); File output = new File( this.outputFileName );
File dir = output.getParentFile(); File dir = output.getParentFile();
if (dir != null) if ( dir != null )
{ {
dir.mkdirs(); dir.mkdirs();
} }
PrintWriter out = new PrintWriter(new OutputStreamWriter( PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( output ), this
new FileOutputStream(output), this.getOutputEncoding())); .getOutputEncoding() ) );
writeOutput(fileMap, out); writeOutput( fileMap, out );
out.flush(); out.flush();
out.close(); out.close();
} }
@ -362,35 +335,33 @@ public class JavadocWarningsTextToXml
private String[] readInput() private String[] readInput()
throws FileNotFoundException, IOException throws FileNotFoundException, IOException
{ {
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Reading '" + getInputFileName() + "'"); System.out.println( "Reading '" + getInputFileName() + "'" );
} }
BufferedReader reader = new BufferedReader(new FileReader( BufferedReader reader = new BufferedReader( new FileReader( getInputFileName() ) );
getInputFileName()));
List lines = new ArrayList(); List lines = new ArrayList();
String line = null; String line = null;
while ((line = reader.readLine()) != null) while ( ( line = reader.readLine() ) != null )
{ {
// Look for lines containing the string "warning - " // Look for lines containing the string "warning - "
if (line.indexOf("warning - ") >= 0) if ( line.indexOf( "warning - " ) >= 0 )
{ {
lines.add(line); lines.add( line );
} }
} }
reader.close(); reader.close();
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Read " + lines.size() System.out.println( "Read " + lines.size() + " line(s) from input file" );
+ " line(s) from input file");
} }
return (String[]) lines.toArray(new String[lines.size()]); return (String[]) lines.toArray( new String[lines.size()] );
} }
/** /**
@ -398,53 +369,47 @@ public class JavadocWarningsTextToXml
* @param fileMap The filemap to translate in XML. * @param fileMap The filemap to translate in XML.
* @param out The output to write. * @param out The output to write.
*/ */
private void writeOutput(final Map fileMap, final PrintWriter out) private void writeOutput( final Map fileMap, final PrintWriter out )
{ {
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Writing to output file '" + this.outputFileName); System.out.println( "Writing to output file '" + this.outputFileName );
} }
out.println("<?xml version=\"1.0\" encoding=\"" out.println( "<?xml version=\"1.0\" encoding=\"" + this.getOutputEncoding() + "\"?>" );
+ this.getOutputEncoding() + "\"?>"); out.println( "<javadoc>" );
out.println("<javadoc>");
for (Iterator fileMapIterator = fileMap.keySet().iterator(); for ( Iterator fileMapIterator = fileMap.keySet().iterator(); fileMapIterator.hasNext(); )
fileMapIterator.hasNext();)
{ {
String fileName = (String) fileMapIterator.next(); String fileName = (String) fileMapIterator.next();
out.println("<file name=\"" + fileName + "\">"); out.println( "<file name=\"" + fileName + "\">" );
Map fileMessages = (Map) fileMap.get(fileName); Map fileMessages = (Map) fileMap.get( fileName );
for (Iterator fileMessagesIterator = fileMessages.entrySet() for ( Iterator fileMessagesIterator = fileMessages.entrySet().iterator(); fileMessagesIterator.hasNext(); )
.iterator();
fileMessagesIterator.hasNext();)
{ {
Map.Entry entry = (Map.Entry) fileMessagesIterator.next(); Map.Entry entry = (Map.Entry) fileMessagesIterator.next();
Integer lineNumber = (Integer) entry.getKey(); Integer lineNumber = (Integer) entry.getKey();
Set lineMessages = (Set) entry.getValue(); Set lineMessages = (Set) entry.getValue();
for (Iterator lineMessagesIterator = lineMessages.iterator(); for ( Iterator lineMessagesIterator = lineMessages.iterator(); lineMessagesIterator.hasNext(); )
lineMessagesIterator.hasNext();)
{ {
String msg = (String) lineMessagesIterator.next(); String msg = (String) lineMessagesIterator.next();
out.println("<error line=\"" + lineNumber out.println( "<error line=\"" + lineNumber + "\" severity=\"warning\" message=\""
+ "\" severity=\"warning\" message=\"" + StringEscapeUtils.escapeXml( msg ) + "\"/>" );
+ StringEscapeUtils.escapeXml(msg) + "\"/>");
} }
} }
out.println("</file>"); out.println( "</file>" );
} }
out.println("</javadoc>"); out.println( "</javadoc>" );
if (this.isVerbose()) if ( this.isVerbose() )
{ {
System.out.println("Finished writing output file"); System.out.println( "Finished writing output file" );
} }
} }
} }

View File

@ -16,16 +16,16 @@ package org.apache.maven.javadoc;
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/** /**
* Test case. * Test case.
* *