You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bw...@apache.org on 2003/01/30 11:59:22 UTC

cvs commit: jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/test1 test1.html

bwalding    2003/01/30 02:59:22

  Added:       src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation
                        LinkValidatorManager.java ValidationResult.java
                        FileLinkValidator.java LinkValidator.java
                        MailtoLinkValidator.java LinkValidatorCache.java
                        LinkValidationItem.java HTTPLinkValidator.java
                        LinkValidationResult.java
               src/plugins-build/linkcheck/src/test/org/apache/maven/linkcheck
                        LinkCheckTest.java
               src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck
                        linkcheck.xml
               src/plugins-build/linkcheck/src/plugin-resources
                        linkcheck.jsl linkcheck-temp.xml
               src/plugins-build/linkcheck/src/test-resources nolink.html
                        testA.html
               src/plugins-build/linkcheck/src/test-resources/test-resources
                        nolink.html
               src/plugins-build/linkcheck/src/test-resources/test-resources/test1
                        test2.html test1.html
               src/plugins-build/linkcheck/src/test-resources/test1
                        test1.html
  Log:
  MAVEN-214: LinkChecker plugin
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java
  
  Index: LinkValidatorManager.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
   
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * @author Ben Walding
   *
   */
  
  public class LinkValidatorManager {
      /**
       * Log for debug output
       */
      private static Log LOG = LogFactory.getLog(LinkValidatorManager.class);
  
      private List validators = new ArrayList();
      private LinkValidatorCache cache = new LinkValidatorCache(this);
      private String exclude;
  
      public LinkValidatorManager() {
  
      }
  
      public void addLinkValidator(LinkValidator lv) {
          validators.add(lv);
      }
  
      public List getValidators() {
          return validators;
      }
  
      public LinkValidationResult validateLink(LinkValidationItem lvi)
          throws Exception {
          {
              LinkValidationResult status = cache.getCachedResult(lvi);
              if (status != null) {
                  return status;
              }
          }
  
          if (exclude != null && lvi.getLink().startsWith(exclude)) {
              return new LinkValidationResult(LinkValidationResult.VALID, false);
          }
  
          Iterator iter = validators.iterator();
          while (iter.hasNext()) {
              LinkValidator lv = (LinkValidator) iter.next();
  
              Object resourceKey = lv.getResourceKey(lvi);
  
              if (resourceKey != null) {
  
                  LinkValidationResult lvr = lv.validateLink(lvi);
  
                  if (lvr.getStatus() == LinkValidationResult.NOTMINE) {
                      continue;
                  }
  
                  cache.setCachedResult(resourceKey, lvr);
                  return lvr;
  
              }
  
          }
  
          LOG.info("Unable to validate link : " + lvi.getLink());
          return new LinkValidationResult(LinkValidationResult.UNKNOWN, false);
      }
  
      public void loadCache(String cacheFilename) {
          try {
              File f = new File(cacheFilename);
              if (f.exists()) {
                  this.cache.load(new FileInputStream(cacheFilename));
              }
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
      }
  
      public void saveCache(String cacheFilename) {
          try {
              this.cache.save(new FileOutputStream(cacheFilename));
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
      }
  
      /**
       * Returns the exclude.
       * @return String
       */
      public String getExclude() {
          return exclude;
      }
  
      /**
       * Sets the exclude.
       * @param exclude The exclude to set
       */
      public void setExclude(String exclude) {
          this.exclude = exclude;
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/ValidationResult.java
  
  Index: ValidationResult.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  /**
   * @author Ben Walding
   *
   */
  public class ValidationResult {
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java
  
  Index: FileLinkValidator.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  import java.io.File;
  
  /**
   * @author Ben Walding
   *
   */
  public class FileLinkValidator implements LinkValidator {
      private final static LinkValidationResult LVR_INVALID =
          new LinkValidationResult(LinkValidationResult.INVALID, false);
          
      private final static LinkValidationResult LVR_VALID =
          new LinkValidationResult(LinkValidationResult.VALID, false);
  
      /**
       * @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem)
       */
      public LinkValidationResult validateLink(LinkValidationItem lvi) {
          File f = getFile(lvi);
  
          if (f.exists())
              return LVR_VALID;
          else
              return LVR_INVALID;
      }
  
      protected File getFile(LinkValidationItem lvi) {
          String link = lvi.getLink();
          if (link.indexOf('#') != -1) {
              link = link.substring(0, link.indexOf('#'));
  
              //If the link was just #fred or similar, then the file is the file it came from
              //XXX: Theoretically we could even validate the anchor tag?
              if (link.trim().length() == 0)
                  return lvi.getSource();
          }
  
          File f = new File(lvi.getSource().getParentFile(), link);
          return f;
      }
  
      /**
       * @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem)
       */
      public Object getResourceKey(LinkValidationItem lvi) {
          String link = lvi.getLink();
  
          if (link.indexOf(':') != -1)
              return null;
  
          return getFile(lvi).getAbsolutePath();
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java
  
  Index: LinkValidator.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  import java.io.File;
  
  /**
   * @author Ben Walding
   *
   */
  public interface LinkValidator {
      
      /**
       * If getResource(lvi) returned null, this will NOT be called.
       * @param lvi
       * @return int
       * @throws Exception
       */
      public LinkValidationResult validateLink(LinkValidationItem lvi) throws Exception;
      
      
      /**
       * The resource key is used by the cache to determine if it really needs to
       * validate the link.  No actual validation should be done at this point.
       * @param lvi
       * @return Object null if this validator should not be doing this work.
       * @throws Exception
       */
      public Object getResourceKey(LinkValidationItem lvi);
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java
  
  Index: MailtoLinkValidator.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  /**
   * @author Ben Walding
   *
   */
  public class MailtoLinkValidator implements LinkValidator {
      private static final LinkValidationResult LVR =
          new LinkValidationResult(LinkValidationResult.VALID, false);
      /**
       * @see org.apache.maven.linkcheck.validation.LinkValidator#validateLink(org.apache.maven.linkcheck.validation.LinkValidationItem)
       */
      public LinkValidationResult validateLink(LinkValidationItem lvi)
          throws Exception {
          return LVR;
      }
      /**
       * @see org.apache.maven.linkcheck.validation.LinkValidator#getResourceKey(org.apache.maven.linkcheck.validation.LinkValidationItem)
       */
      public Object getResourceKey(LinkValidationItem lvi) {
          return lvi.getLink();
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java
  
  Index: LinkValidatorCache.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
   
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Properties;
  
  /**
   * @author Ben Walding
   *
   */
  public class LinkValidatorCache {
      private LinkValidatorManager lvm;
      private Map cache = new HashMap();
  
      public LinkValidatorCache(LinkValidatorManager lvm) {
          this.lvm = lvm;
      }
      public void setCachedResult(Object resourceKey, LinkValidationResult lvr) {
          cache.put(resourceKey, lvr);
      }
  
      /**
           * 
           * @param lvi
           * @return int Will return a status level, VALID, INVALID, UNKNOWN
           */
      public LinkValidationResult getCachedResult(LinkValidationItem lvi) {
          Iterator iter = lvm.getValidators().iterator();
  
          while (iter.hasNext()) {
              LinkValidator lv = (LinkValidator) iter.next();
  
              Object resourceKey = lv.getResourceKey(lvi);
  
              if (resourceKey != null) {
                  return (LinkValidationResult) cache.get(resourceKey);
              }
          }
          return null;
  
      }
  
      public void load(InputStream is) {
          final LinkValidationResult LVR_VALID =
              new LinkValidationResult(LinkValidationResult.VALID, true);
          final LinkValidationResult LVR_INVALID =
              new LinkValidationResult(LinkValidationResult.INVALID, true);
          try {
              Properties p = new Properties();
              p.load(is);
  
              Iterator iter = p.keySet().iterator();
              while (iter.hasNext()) {
                  String key = (String) iter.next();
                  String value = (String) p.getProperty(key);
  
                  if (value.equals("VALID"))
                      cache.put(key, LVR_VALID);
  
                  if (value.equals("INVALID"))
                      cache.put(key, LVR_INVALID);
  
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      public void save(OutputStream os) {
  
          try {
              Properties p = new Properties();
              Iterator iter = cache.keySet().iterator();
              while (iter.hasNext()) {
                  String key = (String) iter.next();
                  LinkValidationResult lvr =
                      (LinkValidationResult) cache.get(key);
                  if (lvr.isPersistent()) {
                      if (lvr.getStatus() == LinkValidationResult.VALID) {
                          p.setProperty(key, "VALID");
                      }
  
                      if (lvr.getStatus() == LinkValidationResult.INVALID) {
                          p.setProperty(key, "INVALID");
                      }
                  }
              }
  
              p.store(os, "LinkCheck Cache");
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java
  
  Index: LinkValidationItem.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  import java.io.File;
  
  /**
   * @author Ben Walding
   *
   */
  public class LinkValidationItem {
      private File source;
      private String link;
      
      public LinkValidationItem(File source, String link) {
          if (source == null) {
              throw new NullPointerException("source can't be null");
          }
          
          if (link == null) {
              throw new NullPointerException("link can't be null");
          }
          
          this.source = source;
          this.link = link;
      }
  
      /**
       * @see java.lang.Object#equals(java.lang.Object)
       */
      public boolean equals(Object obj) {
          LinkValidationItem lvi = (LinkValidationItem) obj;
          
          if (!lvi.link.equals(link))
              return false;
              
          if (!lvi.source.equals(source))
          return false;
          return true;
      }
  
      /**
       * @see java.lang.Object#hashCode()
       */
      public int hashCode() {
          return source.hashCode() ^ link.hashCode();
      }
  
      
      /**
       * Returns the link.
       * @return String
       */
      public String getLink() {
          return link;
      }
  
      /**
       * Returns the source.
       * @return File
       */
      public File getSource() {
          return source;
      }
  
      /**
       * Sets the link.
       * @param link The link to set
       */
      public void setLink(String link) {
          this.link = link;
      }
  
      /**
       * Sets the source.
       * @param source The source to set
       */
      public void setSource(File source) {
          this.source = source;
      }
  
      
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java
  
  Index: HTTPLinkValidator.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import com.meterware.httpunit.GetMethodWebRequest;
  import com.meterware.httpunit.WebConversation;
  import com.meterware.httpunit.WebRequest;
  import com.meterware.httpunit.WebResponse;
  
  /**
   * @author Ben Walding
   *
   */
  public class HTTPLinkValidator implements LinkValidator {
      /**
       * Log for debug output
       */
      private static Log LOG = LogFactory.getLog(HTTPLinkValidator.class);
  
      private final static LinkValidationResult LVR_INVALID =
          new LinkValidationResult(LinkValidationResult.INVALID, true);
  
      private final static LinkValidationResult LVR_VALID =
          new LinkValidationResult(LinkValidationResult.VALID, true);
  
      /**
       * @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem)
       */
      public LinkValidationResult validateLink(LinkValidationItem lvi) {
          try {
              String link = lvi.getLink();
              LOG.debug("Checking web link:" + link);
              WebConversation wc = new WebConversation();
              wc.setExceptionsThrownOnErrorStatus(false);
              WebRequest req = new GetMethodWebRequest(link);
              WebResponse resp = wc.getResponse(req);
  
              //FIXME: This constant is defined somewhere, but I can't remember where...
              if (resp.getResponseCode() == 200) {
                  return LVR_VALID;
              } else {
                  return LVR_INVALID;
              }
          } catch (Exception e) {
              LOG.warn("Error accessing " + lvi.getLink(), e);
              e.printStackTrace();
              return LVR_INVALID;
          }
  
      }
  
      /**
       * @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem)
       */
      public Object getResourceKey(LinkValidationItem lvi) {
          String link = lvi.getLink();
  
          if (!link.startsWith("http://"))
              return null;
  
          int hashPos = link.indexOf("#");
          if (hashPos != -1)
              link = link.substring(0, hashPos);
  
          return link;
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java
  
  Index: LinkValidationResult.java
  ===================================================================
  package org.apache.maven.linkcheck.validation;
  
  /**
   * @author Ben Walding
   *
   * <b>This is an immutable class.</b><br/>
   * <p>
   *   This  class is used to return status responses from the
   *   validation handlers.  A persistent result means that it
   *   can be stored in the persistent cache and used across runs.
   * </p>
   */
  public class LinkValidationResult {
      public static final int NOTMINE = 0;
      public static final int INVALID = 1;
      public static final int VALID   = 2;
      public static final int UNKNOWN = 3;
      
      private int status = UNKNOWN;
      
      public LinkValidationResult(int status, boolean persistent) {
          this.status = status;
          this.persistent = persistent;
      }
      
      boolean persistent;
      public boolean isPersistent() {
          return persistent;
      }
      
      
      /**
       * Returns the status.
       * @return int
       */
      public int getStatus() {
          return status;
      }
  
      
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java
  
  Index: LinkCheckTest.java
  ===================================================================
  package org.apache.maven.linkcheck;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  import java.io.File;
  import java.util.Iterator;
  
  import junit.framework.TestCase;
  
  /**
   * @author Ben Walding
   *
   */
  public class LinkCheckTest extends TestCase {
      String baseDir;
  
      public void setUp() {
          baseDir = System.getProperty("basedir");
      }
  
      public void testScan()
          throws Exception {
          File f = new File(baseDir + "/src/test-resources");
          LinkCheck lc = new LinkCheck();
          lc.setBasedir(f);
          lc.setOutput(new File(baseDir + "/target/linkcheck.xml"));
          lc.setOutputEncoding("ISO8859-1");
          lc.setCache(baseDir + "/target/linkcheck-cache.xml");
          lc.doExecute();
          
          
          Iterator iter =        lc.getFiles().iterator();
          while (iter.hasNext()) {
              FileToCheck ftc = (FileToCheck) iter.next();
              System.out.println(ftc.getName());
          }
          
          //Iterator iter = Collections.EMPTY_LIST.iterator();
  
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/linkcheck.xml
  
  Index: linkcheck.xml
  ===================================================================
  <linkcheck>
  	<file name="asd.html">
  		<link
  			url="bob"
  			status="OK"/>
  	</file>
  </linkcheck>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/plugin-resources/linkcheck.jsl
  
  Index: linkcheck.jsl
  ===================================================================
  <?xml version="1.0"?>
  
  <jsl:stylesheet
    select="$doc"
    xmlns:j="jelly:core"
    xmlns:util="jelly:util"
    xmlns:jsl="jelly:jsl"
    xmlns:x="jelly:xml"
    xmlns="dummy" 
    trim="false">
  
    <jsl:template match="linkcheck">
      <document>
  
        <properties>
          <title>Link Check Report</title>
        </properties>
        <body>
          <section name="Link Check Report">
            <table>
              <tr>
                <th>URL</th>
              </tr>
              <x:set var="files" select="file[@unsuccessful!=0]"/>
              <j:forEach var="file" items="${files}">
                <tr>
                  <td colspan="2">
                    <util:replace var="name" oldChar="\\" newChar="/">
                    	 ${file.attribute('name').value}
                    </util:replace>
                    <a href="${name}">${name}</a>
                  </td>
                </tr>
                <tr>
                	<td>
                    <x:forEach var="result" select="$file/result">
                      <j:set var="status"><x:expr select="$result/@status"/></j:set>
          	      	<j:set var="target"><x:expr select="$result/@target"/></j:set>
          	      	<j:if test="${status != 'OK'}">
                  	  <span style="pad-left:60px">${status} - ${target}</span>
                    	  <br/> 
                  	</j:if>
        	  	      </x:forEach>	
          	    </td>
                </tr>
              </j:forEach>
            </table>
          </section>
        </body>
      </document>
    </jsl:template>
  </jsl:stylesheet>
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/plugin-resources/linkcheck-temp.xml
  
  Index: linkcheck-temp.xml
  ===================================================================
  <?xml version="1.0"?>
  <document>
    <properties>
      <title>Maven LinkCheck Plug-in</title>
      <author email="ben@walding.com">Ben Walding</author>
    </properties>
  
    <body>
      <section name="Maven LinkCheck Temporary File">
        <p>
        	This file is used as a placeholder until the final link check can occur.
        </p>
      </section>
   </body>
  </document>
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/nolink.html
  
  Index: nolink.html
  ===================================================================
  <html>
  <body>
  
  
  </body>
  
  </html>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/testA.html
  
  Index: testA.html
  ===================================================================
  <a href="#bumpkin">test2</a>
  
  
  
  <a href="testnothere.html">test that isn't here</a>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/test-resources/nolink.html
  
  Index: nolink.html
  ===================================================================
  <html>
  <body>
  
  
  </body>
  </html>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/test-resources/test1/test2.html
  
  	<<Binary file>>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/test-resources/test1/test1.html
  
  	<<Binary file>>
  
  
  1.1                  jakarta-turbine-maven/src/plugins-build/linkcheck/src/test-resources/test1/test1.html
  
  	<<Binary file>>