geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/scanner FileSystemScannerTest.java WebDAVScannerTest.java
Date Tue, 12 Aug 2003 07:10:16 GMT
jboynes     2003/08/12 00:10:16

  Modified:    modules/core/src/java/org/apache/geronimo/deployment
                        DeploymentController.java
               modules/core/src/java/org/apache/geronimo/deployment/goal
                        DeployURL.java
               modules/core/src/java/org/apache/geronimo/deployment/scanner
                        FileSystemScanner.java Scanner.java
                        WebDAVScanner.java
               modules/core/src/java/org/apache/geronimo/deployment/service
                        ClassSpaceMetadataXMLLoader.java
  Added:       modules/core/src/java/org/apache/geronimo/deployment/scanner
                        URLInfo.java URLType.java
               modules/core/src/test/org/apache/geronimo/deployment/scanner
                        FileSystemScannerTest.java WebDAVScannerTest.java
  Log:
  Make the scanners clasify the type of the URL they find
  Added tests for File and WebDAV scan
  
  Revision  Changes    Path
  1.4       +23 -11    incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentController.java
  
  Index: DeploymentController.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentController.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DeploymentController.java	11 Aug 2003 17:59:10 -0000	1.3
  +++ DeploymentController.java	12 Aug 2003 07:10:15 -0000	1.4
  @@ -65,6 +65,7 @@
   import java.util.List;
   import java.util.Map;
   import java.util.Set;
  +import java.io.IOException;
   import javax.management.MBeanRegistration;
   import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
  @@ -80,6 +81,8 @@
   import org.apache.geronimo.deployment.goal.RedeployURL;
   import org.apache.geronimo.deployment.goal.UndeployURL;
   import org.apache.geronimo.deployment.plan.DeploymentPlan;
  +import org.apache.geronimo.deployment.scanner.URLInfo;
  +import org.apache.geronimo.deployment.scanner.URLType;
   import org.apache.geronimo.jmx.JMXUtil;
   
   /**
  @@ -142,28 +145,30 @@
       public void postDeregister() {
       }
   
  -    public synchronized void planDeployment(ObjectName source, Set urls) {
  -        // find new and existing urls
  -        for (Iterator i = urls.iterator(); i.hasNext();) {
  -            URL url = (URL) i.next();
  +    public synchronized void planDeployment(ObjectName source, Set urlInfos) {
  +        // find new and existing urlInfos
  +        for (Iterator i = urlInfos.iterator(); i.hasNext();) {
  +            URLInfo urlInfo = (URLInfo) i.next();
  +            URL url = urlInfo.getUrl();
               if (!isDeployed(url)) {
  -                goals.add(new DeployURL(url));
  +                goals.add(new DeployURL(url, urlInfo.getType()));
               } else {
                   goals.add(new RedeployURL(url));
               }
           }
   
  -        // create remove goals for all urls that were found last time but not now
  +        // create remove goals for all urlInfos that were found last time but not now
           Set lastScan = (Set) scanResults.get(source);
           if (lastScan != null) {
               for (Iterator i = lastScan.iterator(); i.hasNext();) {
  -                URL url = (URL) i.next();
  -                if (!urls.contains(url) && isDeployed(url)) {
  +                URLInfo urlInfo = (URLInfo) i.next();
  +                URL url = urlInfo.getUrl();
  +                if (!urlInfos.contains(urlInfo) && isDeployed(url)) {
                       goals.add(new UndeployURL(url));
                   }
               }
           }
  -        scanResults.put(source, urls);
  +        scanResults.put(source, urlInfos);
   
           try {
               generatePlans();
  @@ -194,8 +199,15 @@
               return;
           }
   
  +        URLType type = null;
           try {
  -            DeployURL goal = new DeployURL(url);
  +            type = URLType.getType(url);
  +        } catch (IOException e) {
  +            throw new DeploymentException(e);
  +        }
  +
  +        try {
  +            DeployURL goal = new DeployURL(url, type);
               goals.add(goal);
               generatePlans();
               executePlans();
  
  
  
  1.2       +10 -2     incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/goal/DeployURL.java
  
  Index: DeployURL.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/goal/DeployURL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeployURL.java	11 Aug 2003 17:59:10 -0000	1.1
  +++ DeployURL.java	12 Aug 2003 07:10:15 -0000	1.2
  @@ -57,6 +57,8 @@
   
   import java.net.URL;
   
  +import org.apache.geronimo.deployment.scanner.URLType;
  +
   /**
    *
    *
  @@ -64,12 +66,18 @@
    */
   public class DeployURL extends DeploymentGoal {
       private final URL url;
  +    private final URLType type;
   
  -    public DeployURL(URL url) {
  +    public DeployURL(URL url, URLType type) {
           this.url = url;
  +        this.type = type;
       }
   
       public URL getUrl() {
           return url;
  +    }
  +
  +    public URLType getType() {
  +        return type;
       }
   }
  
  
  
  1.4       +12 -8     incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/FileSystemScanner.java
  
  Index: FileSystemScanner.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/FileSystemScanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileSystemScanner.java	11 Aug 2003 17:59:11 -0000	1.3
  +++ FileSystemScanner.java	12 Aug 2003 07:10:15 -0000	1.4
  @@ -61,6 +61,9 @@
   import java.util.HashSet;
   import java.util.LinkedList;
   import java.util.Set;
  +import java.util.zip.ZipException;
  +import java.util.jar.JarFile;
  +import java.util.jar.Manifest;
   
   /**
    *
  @@ -103,13 +106,14 @@
   
               for (int i = 0; i < files.length; i++) {
                   File file = files[i];
  -                // we consider a File deployable if it is not a directory,
  -                // or if it is and it contains a META-INF subdirectory
  -                if (!file.isDirectory() || new File(file, "META-INF").isDirectory()) {
  -                    result.add(file.toURL());
  -                } else if (recurse) {
  -                    // add this to the end of the list so we go breadth first
  -                    toScan.addLast(file);
  +                URLType type = URLType.getType(file);
  +                if (type == URLType.COLLECTION) {
  +                    if (recurse) {
  +                        // add this to the end of the list so we go breadth first
  +                        toScan.addLast(file);
  +                    }
  +                } else {
  +                    result.add(new URLInfo(file.toURL(), type));
                   }
               }
           }
  
  
  
  1.4       +2 -3      incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/Scanner.java
  
  Index: Scanner.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/Scanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Scanner.java	11 Aug 2003 17:59:11 -0000	1.3
  +++ Scanner.java	12 Aug 2003 07:10:15 -0000	1.4
  @@ -61,13 +61,12 @@
   /**
    * Interface for scanning a location for deployments
    *
  - *
    * @version $Revision$ $Date$
    */
   public interface Scanner {
       /**
        * Scan for any deployments
  -     * @return a Set<DeploymentInfo> of deployables found by this scanner
  +     * @return a Set<URLInfo> of deployables found by this scanner
        * @throws IOException
        */
       public Set scan() throws IOException;
  
  
  
  1.4       +35 -33    incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/WebDAVScanner.java
  
  Index: WebDAVScanner.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/WebDAVScanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebDAVScanner.java	11 Aug 2003 17:59:11 -0000	1.3
  +++ WebDAVScanner.java	12 Aug 2003 07:10:15 -0000	1.4
  @@ -57,12 +57,14 @@
   
   import java.io.IOException;
   import java.io.InputStream;
  +import java.net.JarURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.Set;
  +import java.util.zip.ZipException;
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
   
  @@ -73,16 +75,17 @@
   import org.apache.commons.httpclient.HttpMethodBase;
   import org.apache.commons.httpclient.URI;
   import org.apache.commons.httpclient.URIException;
  +import org.apache.commons.httpclient.methods.GetMethod;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.DefaultHandler;
   
   /**
    * Scanner that searches a remote site using WebDAV looking for deployments.
  - * Sub-collections that themselves contain a META-INF sub-collection are
  + * Sub-collections that themselves contain a Manifest are
    * assumed to be deployable; others may be recursed into
    *
  - *
  + * @todo we should cache results between scans to reduce network traffic
    * @version $Revision$ $Date$
    */
   public class WebDAVScanner implements Scanner {
  @@ -134,18 +137,17 @@
                   Set scanResult = scanCollection(scanURL);
                   for (Iterator i = scanResult.iterator(); i.hasNext();) {
                       URL url = (URL) i.next();
  -                    if (!url.toString().endsWith("/")) {
  -                        // plain file - add it
  -                        result.add(url);
  -                    } else if (scanURL.equals(url)) {
  +                    if (scanURL.equals(url)) {
                           // ignore the collection we scanned
                           continue;
  -                    } else if (hasMetaInf(url)) {
  -                        // a sub-collection with META-INF - add it
  -                        result.add(url);
  -                    } else if (recurse) {
  -                        // a sub-collection without META-INF and we are recursing
  -                        toScan.addLast(url);
  +                    }
  +                    URLType type = getType(url);
  +                    if (type == URLType.COLLECTION) {
  +                        if (recurse) {
  +                            toScan.addLast(url);
  +                        }
  +                    } else {
  +                        result.add(new URLInfo(url, type));
                       }
                   }
                   handler.result.clear();
  @@ -160,30 +162,30 @@
       }
   
       /**
  -     * See if the specified URL has a META-INF sub-collection
  +     * See if the specified URL has a manifest
        * @param url the URL to check
  -     * @return true if the URL has a META-INF sub-collection
  +     * @return true if the URL has a manifest
        * @throws IOException if there was a problem talking to the server
        */
  -    private boolean hasMetaInf(URL url) throws IOException {
  -        assert (url.toString().endsWith("/"));
  -        URL metaInfURL = new URL(url, "META-INF/");
  -        HttpMethod method = new PropfindMethod(metaInfURL.toString());
  -        try {
  -            method.setFollowRedirects(false);
  -            method.setRequestHeader("DAV", "1");
  -            method.setRequestHeader("Depth", "0");
  -            int status = httpClient.executeMethod(method);
  -            method.getResponseBody();
  -            if (status == 404) {
  -                return false;
  -            } else if (status == 207) {
  -                return true;
  -            } else {
  -                throw new IOException("Unexpected result " + status);
  +    private URLType getType(URL url) throws IOException {
  +        if (url.toString().endsWith("/")) {
  +            URL metaInfURL = new URL(url, "META-INF/MANIFEST.MF");
  +            HttpMethod getMethod = new GetMethod(metaInfURL.toString());
  +            try {
  +                int status = httpClient.executeMethod(getMethod);
  +                return status == 200 ? URLType.UNPACKED_ARCHIVE : URLType.COLLECTION;
  +            } finally {
  +                getMethod.releaseConnection();
  +            }
  +        } else {
  +            URL jarURL = new URL("jar:" + url.toString() + "!/");
  +            JarURLConnection jarConnection = (JarURLConnection) jarURL.openConnection();
  +            try {
  +                jarConnection.getManifest();
  +                return URLType.PACKED_ARCHIVE;
  +            } catch (ZipException e) {
  +                return URLType.RESOURCE;
               }
  -        } finally {
  -            method.releaseConnection();
           }
       }
   
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/URLInfo.java
  
  Index: URLInfo.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" 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 Geronimo", 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.net.URL;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/12 07:10:15 $
   */
  public class URLInfo {
      private final URL url;
      private final URLType type;
  
      public URLInfo(URL url, URLType type) {
          assert (url != null) : "url was null";
          assert (type != null) : "type was null";
          this.url = url;
          this.type = type;
      }
  
      public URLType getType() {
          return type;
      }
  
      public URL getUrl() {
          return url;
      }
  
      public String toString() {
          return url + " (" + type.toString() + ")";
      }
  
      public boolean equals(Object obj) {
          if (obj instanceof URLInfo) {
              return this.url.equals(((URLInfo) obj).url);
          }
          return false;
      }
  
      public int hashCode() {
          return url.hashCode();
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/URLType.java
  
  Index: URLType.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" 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 Geronimo", 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.JarURLConnection;
  import java.net.URL;
  import java.net.URLConnection;
  import java.util.jar.JarFile;
  import java.util.zip.ZipException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/12 07:10:15 $
   */
  public class URLType {
      private final String desc;
      public static final URLType RESOURCE = new URLType("RESOURCE");
      public static final URLType COLLECTION = new URLType("COLLECTION");
      public static final URLType PACKED_ARCHIVE = new URLType("PACKED_ARCHIVE");
      public static final URLType UNPACKED_ARCHIVE = new URLType("UNPACKED_ARCHIVE");
  
      public static URLType getType(File file) throws IOException {
          if (file.isDirectory()) {
              // file is a directory - see if it has a manifest
              // we check for an actual manifest file to keep things consistent with a packed
archive
              if (new File(file, "META-INF/MANIFEST.MF").exists()) {
                  return UNPACKED_ARCHIVE;
              } else {
                  return COLLECTION;
              }
          } else {
              // we have a regular file - see if it contains a manifest
              try {
                  JarFile jar = new JarFile(file);
                  jar.getManifest();
                  return PACKED_ARCHIVE;
              } catch (ZipException e) {
                  return RESOURCE;
              }
          }
      }
  
      public static URLType getType(URL url) throws IOException {
          if (url.toString().endsWith("/")) {
              URL metaInfURL = new URL(url, "META-INF/MANIFEST.MF");
              URLConnection urlConnection = metaInfURL.openConnection();
              urlConnection.connect();
              try {
                  InputStream is = urlConnection.getInputStream();
                  is.close();
                  return UNPACKED_ARCHIVE;
              } catch (IOException e) {
                  return COLLECTION;
              }
          } else {
              URL jarURL = new URL("jar:" + url.toString() + "!/");
              JarURLConnection jarConnection = (JarURLConnection) jarURL.openConnection();
              try {
                  jarConnection.getManifest();
                  return PACKED_ARCHIVE;
              } catch (ZipException e) {
                  return RESOURCE;
              }
          }
      }
  
      private URLType(String desc) {
          this.desc = desc;
      }
  
      public boolean equals(Object obj) {
          return this == obj;
      }
  
      public String toString() {
          return desc;
      }
  }
  
  
  
  1.2       +8 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/service/ClassSpaceMetadataXMLLoader.java
  
  Index: ClassSpaceMetadataXMLLoader.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/service/ClassSpaceMetadataXMLLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassSpaceMetadataXMLLoader.java	11 Aug 2003 17:59:11 -0000	1.1
  +++ ClassSpaceMetadataXMLLoader.java	12 Aug 2003 07:10:16 -0000	1.2
  @@ -61,6 +61,7 @@
   import java.net.URL;
   import java.util.Collection;
   import java.util.List;
  +import java.util.Iterator;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   
  @@ -68,6 +69,7 @@
   import org.apache.geronimo.deployment.scanner.FileSystemScanner;
   import org.apache.geronimo.deployment.scanner.Scanner;
   import org.apache.geronimo.deployment.scanner.WebDAVScanner;
  +import org.apache.geronimo.deployment.scanner.URLInfo;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   
  @@ -101,7 +103,11 @@
                           String archive = archiveElement.getAttribute("name");
                           if ("*".equals(archive)) {
                               // scan location and add all
  -                            urls.addAll(scan(codebase));
  +                            Collection c = scan(codebase);
  +                            for (Iterator k = c.iterator(); k.hasNext();) {
  +                                URLInfo urlInfo = (URLInfo) k.next();
  +                                urls.add(urlInfo.getUrl());
  +                            }
                           } else {
                               // add explicit archive
                               URL url = new URL(codebase, archive);
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/scanner/FileSystemScannerTest.java
  
  Index: FileSystemScannerTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" 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 Geronimo", 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.util.HashSet;
  import java.util.Set;
  import java.util.jar.JarOutputStream;
  import java.util.zip.ZipEntry;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/12 07:10:16 $
   */
  public class FileSystemScannerTest extends TestCase {
      private File testRoot;
      private Set rootURLs;
  
      public void testURLTypes() throws Exception {
          assertEquals(URLType.COLLECTION, URLType.getType(testRoot));
          assertEquals(URLType.RESOURCE, URLType.getType(new File(testRoot, "f1-service.xml")));
          assertEquals(URLType.PACKED_ARCHIVE, URLType.getType(new File(testRoot, "z1.jar")));
          assertEquals(URLType.UNPACKED_ARCHIVE, URLType.getType(new File(testRoot, "z2.jar")));
      }
  
      public void testScan() throws Exception {
          Scanner scanner = new FileSystemScanner(testRoot, false);
          Set results = scanner.scan();
          assertEquals(rootURLs, results);
      }
  
      public void testRecursiveScan() throws Exception {
      }
  
      protected void setUp() throws Exception {
          File tempDir = new File(System.getProperty("java.io.tmpdir"));
          testRoot = new File(tempDir, "testScan");
          testRoot.mkdir();
  
          rootURLs = new HashSet();
          rootURLs.add(createFile(testRoot, "f1-service.xml"));
          rootURLs.add(createFile(testRoot, "f2-service.xml"));
          rootURLs.add(createJarFile(testRoot, "z1.jar"));
          rootURLs.add(createUnpacked(testRoot, "z2.jar"));
      }
  
      protected void tearDown() throws Exception {
          recursiveDelete(testRoot);
      }
  
      private URLInfo createFile(File root, String path) throws Exception {
          File newFile = new File(root, path);
          newFile.createNewFile();
          return new URLInfo(newFile.toURL(), URLType.RESOURCE);
      }
  
      private URLInfo createJarFile(File root, String path) throws Exception {
          File newFile = new File(root, path);
          newFile.createNewFile();
          JarOutputStream jos = new JarOutputStream(new FileOutputStream(newFile));
          ZipEntry entry = new ZipEntry("index.txt");
          jos.putNextEntry(entry);
          jos.close();
          return new URLInfo(newFile.toURL(), URLType.PACKED_ARCHIVE);
      }
  
      private URLInfo createUnpacked(File root, String path) throws Exception {
          File newFile = new File(root, path);
          newFile.mkdir();
          File manifest = new File(newFile, "META-INF/MANIFEST.MF");
          manifest.getParentFile().mkdirs();
          manifest.createNewFile();
          return new URLInfo(newFile.toURL(), URLType.UNPACKED_ARCHIVE);
      }
  
      private void recursiveDelete(File root) throws Exception {
          File[] files = root.listFiles();
          for (int i = 0; i < files.length; i++) {
              File file = files[i];
              if (file.isDirectory()) {
                  recursiveDelete(file);
              } else {
                  file.delete();
              }
          }
          root.delete();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/scanner/WebDAVScannerTest.java
  
  Index: WebDAVScannerTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" 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 Geronimo", 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.net.URL;
  import java.util.Iterator;
  import java.util.Set;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/12 07:10:16 $
   */
  public class WebDAVScannerTest extends TestCase {
      private WebDAVScanner scanner;
      private URL baseURL;
  
      public void testScan() throws Exception {
          scanner = new WebDAVScanner(baseURL, false);
          Set result = scanner.scan();
          for (Iterator i = result.iterator(); i.hasNext();) {
              URLInfo urlInfo = (URLInfo) i.next();
              System.out.println("urlInfo = " + urlInfo);
          }
      }
  
      public void testTypes() throws Exception {
          scanner = new WebDAVScanner(baseURL, false);
          Set result = scanner.scan();
          for (Iterator i = result.iterator(); i.hasNext();) {
              URLInfo urlInfo = (URLInfo) i.next();
              assertEquals(urlInfo.getType(), URLType.getType(urlInfo.getUrl()));
          }
      }
  
      protected void setUp() throws Exception {
          baseURL = new URL("http://localhost/testScan/");
      }
  }
  
  
  

Mime
View raw message