Author: vsiveton Date: Wed May 27 12:06:13 2009 New Revision: 779133 URL: http://svn.apache.org/viewvc?rev=779133&view=rev Log: o add unique message for ambiguous/modified links
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?rev=779133&r1=779132&r2=779133&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java Wed May 27 12:06:13 2009 @@ -38,8 +38,11 @@ import java.io.StringReader; import java.io.StringWriter; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; +import java.util.TreeSet; /** * The APT parser. @@ -160,6 +163,12 @@ /** a line of AptSource. */ protected String line; + /** Used to add warn message when links are ambiguous. */ + private Set ambiguousLinks; + + /** Used to add warn message when links are modified. */ + private Set modifiedLinks; + private static final int NUMBER_OF_SPACES = 85; static @@ -221,6 +230,28 @@ // TODO handle column number throw new AptParseException( ape.getMessage(), ape, getSourceName(), getSourceLineNumber(), -1 ); } + + if ( getLog().isWarnEnabled() ) + { + if ( this.ambiguousLinks != null ) + { + for ( Iterator it = this.ambiguousLinks.iterator(); it.hasNext(); ) + { + getLog().warn( it.next().toString() ); + } + + this.ambiguousLinks = null; + } + if ( this.modifiedLinks != null ) + { + for ( Iterator it = this.modifiedLinks.iterator(); it.hasNext(); ) + { + getLog().warn( it.next().toString() ); + } + + this.modifiedLinks = null; + } + } } /** @@ -452,16 +483,16 @@ if ( hash.endsWith( ".html" ) && !hash.startsWith( "./" ) ) { - getLog().warn( "[Apt Parser] Ambiguous link: '" + hash - + "'. If this is a local link, prepend \"./\"!" ); + addAmbiguousLinkMessage( hash ); } if ( !DoxiaUtils.isValidId( hash ) ) { - getLog().warn( "[Apt Parser] Modified invalid link: " + hash ); + linkAnchor = + linkAnchor.substring( 0, hashIndex ) + "#" + + DoxiaUtils.encodeId( hash, true ); - linkAnchor = linkAnchor.substring( 0, hashIndex ) + "#" - + DoxiaUtils.encodeId( hash, true ); + addModifiedLinkMessage( hash, linkAnchor ); } } @@ -1552,6 +1583,35 @@ return buffer.toString().trim(); } + /** + * @param hash not null + */ + private void addAmbiguousLinkMessage( String hash ) + { + if ( ambiguousLinks == null ) + { + ambiguousLinks = new TreeSet(); + } + + String msg = "[Apt Parser] Ambiguous link: '" + hash + "'. If this is a local link, prepend \"./\"!"; + ambiguousLinks.add( msg ); + } + + /** + * @param hash not null + * @param linkAnchor not null + */ + private void addModifiedLinkMessage( String hash, String linkAnchor ) + { + if ( modifiedLinks == null ) + { + modifiedLinks = new TreeSet(); + } + + String msg = "[Apt Parser] Modified invalid link: '" + hash + "' to '" + linkAnchor + "'"; + modifiedLinks.add( msg ); + } + // ----------------------------------------------------------------------- /** A block of an apt source document. */