You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2003/08/27 13:40:01 UTC

cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/goal DeployURLTest.java

jdillon     2003/08/27 04:40:01

  Modified:    modules/core/src/java/org/apache/geronimo/deployment/goal
                        DeployURL.java
  Added:       modules/core/src/test/org/apache/geronimo/deployment/goal
                        DeployURLTest.java
  Log:
   o Applied deploy-url-* patches from bug GERONIMO-22 (spaces in deploy url)
     by Brent Worden
   * This only fixes part of the problem as far as I can tell
  
  Revision  Changes    Path
  1.3       +58 -4     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DeployURL.java	12 Aug 2003 07:10:15 -0000	1.2
  +++ DeployURL.java	27 Aug 2003 11:40:01 -0000	1.3
  @@ -55,8 +55,12 @@
    */
   package org.apache.geronimo.deployment.goal;
   
  +import java.io.File;
  +import java.net.MalformedURLException;
   import java.net.URL;
   
  +import org.apache.geronimo.common.NullArgumentException;
  +
   import org.apache.geronimo.deployment.scanner.URLType;
   
   /**
  @@ -64,12 +68,21 @@
    *
    * @version $Revision$ $Date$
    */
  -public class DeployURL extends DeploymentGoal {
  +public class DeployURL
  +    extends DeploymentGoal
  +{
       private final URL url;
       private final URLType type;
   
  -    public DeployURL(URL url, URLType type) {
  -        this.url = url;
  +    public DeployURL(final URL url, final URLType type) {
  +        if (url == null) {
  +            throw new NullArgumentException("url");
  +        }
  +        if (type == null) {
  +            throw new NullArgumentException("type");
  +        }
  +        
  +        this.url = normalize(url);
           this.type = type;
       }
   
  @@ -79,5 +92,46 @@
   
       public URLType getType() {
           return type;
  +    }
  +    
  +    private static URL normalize(URL url) {
  +        assert url != null;
  +        
  +        File f = toFile(url);
  +        if (f != null) {
  +            try {
  +                url = f.toURI().toURL();
  +            }
  +            catch (MalformedURLException ignore) {
  +                // ignore, return passed in url
  +            }
  +        }
  +        
  +        return url;
  +    }
  +    
  +    /**
  +     * Convert from a <code>URL</code> to a <code>File</code>.
  +     *
  +     * @param url   File URL.
  +     * @return      The equivalent <code>File</code> object, or <code>null</code>
  +     *              if the URL's protocol is not <code>file</code>
  +     * 
  +     * @todo this method was taken from commons-sandbox-io.  if/when that
  +     *       project is promoted to commons proper, remove this method and use
  +     *       said library.
  +     */
  +    private static File toFile(final URL url) {
  +        if (url == null) {
  +            throw new NullArgumentException("url");
  +        }
  +        
  +        if (!url.getProtocol().equals("file")) {
  +            return null;
  +        }
  +        else {
  +            String filename = url.getFile().replace('/', File.separatorChar);
  +            return new File(filename);
  +        }
       }
   }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/goal/DeployURLTest.java
  
  Index: DeployURLTest.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.goal;
  
  import java.net.MalformedURLException;
  import java.net.URI;
  import java.net.URL;
  
  import org.apache.geronimo.deployment.scanner.URLType;
  
  import junit.framework.TestCase;
  
  /**
   * Unit tests for {@link DeployURL} class.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 11:40:01 $
   */
  public class DeployURLTest
      extends TestCase
  {
      public void testFileUrlWithSpace() {
          try {
              DeployURL goal = new DeployURL(new URL("file:///C:/Program Files/Apache Group/Geronimo"), URLType.UNPACKED_ARCHIVE);
              URL url = goal.getUrl();
              URI baseURI = URI.create(url.toString()).normalize();;        
          } catch (MalformedURLException e){
              fail(e.getMessage());
          }
      }
  }