maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r800044 - in /maven/doxia/doxia-tools/trunk/doxia-linkcheck/src: main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java test/resources/linkincomment.html
Date Sun, 02 Aug 2009 12:28:50 GMT
Author: vsiveton
Date: Sun Aug  2 12:28:50 2009
New Revision: 800044

URL: http://svn.apache.org/viewvc?rev=800044&view=rev
Log:
o removed links in XML comments
o added test case

Added:
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html  
(with props)
Modified:
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java

Modified: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java?rev=800044&r1=800043&r2=800044&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
(original)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkMatcher.java
Sun Aug  2 12:28:50 2009
@@ -19,7 +19,6 @@
  * under the License.
  */
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
@@ -60,38 +59,33 @@
     }
 
     /**
-     * Reads a file and returns a StringBuffer with its contents.
+     * Reads a file and returns its contents without any XML comments.
      *
      * @param file the file we are reading
      * @param encoding the encoding file used
      * @return a StringBuffer with file's contents.
      * @throws IOException if something goes wrong.
+     * @see ReaderFactory#newReader(File, String)
+     * @see IOUtil#toString(Reader)
      */
-    private static StringBuffer fileToStringBuffer( File file, String encoding )
+    private static String toString( File file, String encoding )
         throws IOException
     {
-        final StringBuffer pageBuffer = new StringBuffer();
-
-        BufferedReader reader = null;
-        Reader r = null;
+        String content;
+        Reader reader = null;
         try
         {
-            r = ReaderFactory.newReader( file, encoding );
-            reader = new BufferedReader( r );
+            reader = ReaderFactory.newReader( file, encoding );
 
-            String line;
-            while ( ( line = reader.readLine() ) != null )
-            {
-                pageBuffer.append( line );
-            }
+            content = IOUtil.toString( reader );
         }
         finally
         {
-            IOUtil.close( r );
             IOUtil.close( reader );
         }
 
-        return pageBuffer;
+        // some link could be in comments, remove them
+        return content.replaceAll( "(?s)<!--.*?-->", "" );
     }
 
     /**
@@ -107,7 +101,7 @@
     {
         LINK_LIST.clear();
 
-        final Matcher m = MATCH_PATTERN.matcher( fileToStringBuffer( file, encoding ) );
+        final Matcher m = MATCH_PATTERN.matcher( toString( file, encoding ) );
 
         String link;
 
@@ -133,5 +127,4 @@
 
         return LINK_LIST;
     }
-
 }

Modified: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java?rev=800044&r1=800043&r2=800044&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
(original)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
Sun Aug  2 12:28:50 2009
@@ -73,7 +73,7 @@
             map.put( ftc.getRelativePath(), ftc );
         }
 
-        assertEquals( "files.size()", 8, result.getFiles().size() );
+        assertEquals( "files.size()", 9, result.getFiles().size() );
 
         check( map, "nolink.html", 0 );
         check( map, "test-resources/nolink.html", 0 );
@@ -81,6 +81,7 @@
         check( map, "test-resources/test1/test2.html", 0 );
         check( map, "test1/test1.html", 1 );
         check( map, "testA.html", 3 );
+        check( map, "linkincomment.html", 1 );
 
         /* test excludes */
         String fileName = "testExcludes.html";

Added: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html?rev=800044&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html (added)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html Sun
Aug  2 12:28:50 2009
@@ -0,0 +1,27 @@
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+ -->
+<html>
+<body>
+
+<!-- <a href="todo.html">test that isn't here</a> -->
+
+<a href="testA.html">real link</a>
+
+</body>
+</html>
\ No newline at end of file

Propchange: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/test/resources/linkincomment.html
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message