continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r689267 - in /continuum/trunk: ./ continuum-api/ continuum-commons/ continuum-commons/src/main/java/org/apache/maven/continuum/utils/ continuum-commons/src/test/java/org/apache/maven/continuum/utils/ continuum-core/
Date Tue, 26 Aug 2008 22:29:10 GMT
Author: olamy
Date: Tue Aug 26 15:29:10 2008
New Revision: 689267

URL: http://svn.apache.org/viewvc?rev=689267&view=rev
Log:
[CONTINUUM-1489] replace use of MungedHttpsURL with commons-httpclient 
validating an uri can be be so simple 
bye bye plexus-formica.


Modified:
    continuum/trunk/continuum-api/pom.xml
    continuum/trunk/continuum-commons/pom.xml
    continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
    continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
    continuum/trunk/continuum-core/pom.xml
    continuum/trunk/pom.xml

Modified: continuum/trunk/continuum-api/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/pom.xml?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/continuum-api/pom.xml (original)
+++ continuum/trunk/continuum-api/pom.xml Tue Aug 26 15:29:10 2008
@@ -28,10 +28,6 @@
   <name>Continuum API</name>
   <dependencies>
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-formica</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.continuum</groupId>
       <artifactId>continuum-model</artifactId>
     </dependency>

Modified: continuum/trunk/continuum-commons/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/pom.xml?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/pom.xml (original)
+++ continuum/trunk/continuum-commons/pom.xml Tue Aug 26 15:29:10 2008
@@ -39,6 +39,10 @@
       <groupId>org.apache.continuum</groupId>
       <artifactId>continuum-configuration</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-spring</artifactId>
+    </dependency>    
     <!-- === Testing Dependencies === -->
     <dependency>
       <groupId>hsqldb</groupId>
@@ -51,11 +55,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-spring</artifactId>
-      <scope>test</scope>
-    </dependency>  
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>

Modified: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
(original)
+++ continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
Tue Aug 26 15:29:10 2008
@@ -26,11 +26,8 @@
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.oro.text.perl.Perl5Util;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.PlexusConfigurationException;
-import org.codehaus.plexus.formica.validation.AbstractValidator;
-import org.codehaus.plexus.formica.validation.util.Flags;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable;
 
 /**
@@ -41,99 +38,9 @@
  *   role-hint="continuumUrl"
  */
 public class ContinuumUrlValidator
-    extends AbstractValidator
     implements Configurable
 {
     /**
-     * Allows all validly formatted schemes to pass validation instead of 
-     * supplying a set of valid schemes.
-     */
-    public static final int ALLOW_ALL_SCHEMES = 1 << 0;
-
-    /**
-     * Allow two slashes in the path component of the URL.
-     */
-    public static final int ALLOW_2_SLASHES = 1 << 1;
-
-    /**
-     * Enabling this options disallows any URL fragments.
-     */
-    public static final int NO_FRAGMENTS = 1 << 2;
-
-    private static final String ALPHA_CHARS = "a-zA-Z";
-
-    private static final String ALPHA_NUMERIC_CHARS = ALPHA_CHARS + "\\d";
-
-    private static final String SPECIAL_CHARS = ";/@&=,.?:+$";
-
-    private static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
-
-    private static final String SCHEME_CHARS = ALPHA_CHARS;
-
-    // Drop numeric, and  "+-." for now
-    private static final String AUTHORITY_CHARS = ALPHA_NUMERIC_CHARS + "\\-\\.";
-
-    private static final String ATOM = VALID_CHARS + '+';
-
-    /**
-     * This expression derived/taken from the BNF for URI (RFC2396).
-     */
-    private static final String URL_PATTERN = "/^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?/";
-
-    /**
-     * Schema/Protocol (ie. http:, ftp:, file:, etc).
-     */
-    private static final int PARSE_URL_SCHEME = 2;
-
-    /**
-     * Includes hostname/ip and port number.
-     */
-    private static final int PARSE_URL_AUTHORITY = 4;
-
-    private static final int PARSE_URL_PATH = 5;
-
-    private static final int PARSE_URL_QUERY = 7;
-
-    private static final int PARSE_URL_FRAGMENT = 9;
-
-    /**
-     * Protocol (ie. http:, ftp:,https:).
-     */
-    private static final String SCHEME_PATTERN = "/^[" + SCHEME_CHARS + "]/";
-
-    private static final String AUTHORITY_PATTERN = "/^([" + AUTHORITY_CHARS + "]*)(:\\d*)?(.*)?/";
-
-    private static final int PARSE_AUTHORITY_HOST_IP = 1;
-
-    private static final int PARSE_AUTHORITY_PORT = 2;
-
-    /**
-     * Should always be empty.
-     */
-    private static final int PARSE_AUTHORITY_EXTRA = 3;
-
-    private static final String PATH_PATTERN = "/^(/[-\\w:@&?=+,.!/~*'%$_;]*)?$/";
-
-    private static final String QUERY_PATTERN = "/^(.*)$/";
-
-    private static final String LEGAL_ASCII_PATTERN = "/^[\\000-\\177]+$/";
-
-    private static final String IP_V4_DOMAIN_PATTERN = "/^(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})$/";
-
-    private static final String DOMAIN_PATTERN = "/^" + ATOM + "(\\." + ATOM + ")*$/";
-
-    private static final String PORT_PATTERN = "/^:(\\d{1,5})$/";
-
-    private static final String ATOM_PATTERN = "/(" + ATOM + ")/";
-
-    private static final String ALPHA_PATTERN = "/^[" + ALPHA_CHARS + "]/";
-
-    /**
-     * Holds the set of current validation options.
-     */
-    private Flags options = null;
-
-    /**
      * The set of schemes that are allowed to be in a URL.
      */
     private Set<String> allowedSchemes = new HashSet<String>();
@@ -156,41 +63,10 @@
      * @param schemes Pass in one or more url schemes to consider valid, passing in
      *        a null will default to "http,https,ftp" being valid.
      *        If a non-null schemes is specified then all valid schemes must
-     *        be specified. Setting the ALLOW_ALL_SCHEMES option will
-     *        ignore the contents of schemes.
+     *        be specified.
      */
     public ContinuumUrlValidator( String[] schemes )
     {
-        this( schemes, 0 );
-    }
-
-    /**
-     * Initialize a UrlValidator with the given validation options.
-     * @param options The options should be set using the public constants declared in
-     * this class.  To set multiple options you simply add them together.  For example,
-     * ALLOW_2_SLASHES + NO_FRAGMENTS enables both of those options.
-     */
-    public ContinuumUrlValidator( int options )
-    {
-        this( null, options );
-    }
-
-    /**
-     * Behavour of validation is modified by passing in options:
-     * @param schemes The set of valid schemes.
-     * @param options The options should be set using the public constants declared in
-     * this class.  To set multiple options you simply add them together.  For example,
-     * ALLOW_2_SLASHES + NO_FRAGMENTS enables both of those options.
-     */
-    public ContinuumUrlValidator( String[] schemes, int options )
-    {
-        this.options = new Flags( options );
-
-        if ( this.options.isOn( ALLOW_ALL_SCHEMES ) )
-        {
-            return;
-        }
-
         if ( schemes == null && this.allowedSchemes.isEmpty() )
         {
             schemes = this.defaultSchemes;
@@ -225,306 +101,18 @@
             return true;
         }
 
-        value = StringUtils.replace( value, " ", "%20" );
-
-        Perl5Util matchUrlPat = new Perl5Util();
-        Perl5Util matchAsciiPat = new Perl5Util();
-
-        if ( !matchAsciiPat.match( LEGAL_ASCII_PATTERN, value ) )
-        {
-            return false;
-        }
-
-        // Check the whole url address structure
-        if ( !matchUrlPat.match( URL_PATTERN, value ) )
-        {
-            return false;
-        }
-
-        String scheme = matchUrlPat.group( PARSE_URL_SCHEME );
-
-        if ( !isValidScheme( scheme ) )
-        {
-            return false;
-        }
-
-        if ( !"file".equals( scheme ) )
-        {
-            String authority = matchUrlPat.group( PARSE_URL_AUTHORITY );
-
-            if ( authority != null )
-            {
-                if ( authority.indexOf( "@" ) != -1 )
-                {
-                    String userPassword = authority.substring( 0, authority.indexOf( "@"
) );
-
-                    authority = authority.substring( authority.indexOf( "@" ) + 1 );
-
-                    if ( userPassword.indexOf( ":" ) == -1 || userPassword.indexOf( ":" )
== 0
-                        || userPassword.indexOf( ":" ) == userPassword.length() - 1 )
-                    {
-                        return false;
-                    }
-                }
-                if ( !isValidAuthority( authority ) )
-                {
-                    return false;
-                }                
-            }
-
-
-            if ( !isValidQuery( matchUrlPat.group( PARSE_URL_QUERY ) ) )
-            {
-                return false;
-            }
-
-            if ( !isValidFragment( matchUrlPat.group( PARSE_URL_FRAGMENT ) ) )
-            {
-                return false;
-            }
-        }
-
-        if ( !isValidPath( matchUrlPat.group( PARSE_URL_PATH ) ) )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Validate scheme. If schemes[] was initialized to a non null,
-     * then only those scheme's are allowed.  Note this is slightly different
-     * than for the constructor.
-     * @param scheme The scheme to validate.  A <code>null</code> value is considered
-     * invalid.
-     * @return true if valid.
-     */
-    protected boolean isValidScheme( String scheme )
-    {
-        if ( scheme == null )
-        {
-            return false;
-        }
-
-        Perl5Util schemeMatcher = new Perl5Util();
-        if ( !schemeMatcher.match( SCHEME_PATTERN, scheme ) )
+        try
         {
-            return false;
-        }
-
-        if ( this.options.isOff( ALLOW_ALL_SCHEMES ) )
-        {
-
-            if ( !this.allowedSchemes.contains( scheme ) )
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Returns true if the authority is properly formatted.  An authority is the combination
-     * of hostname and port.  A <code>null</code> authority value is considered
invalid.
-     */
-    protected boolean isValidAuthority( String authority )
-    {
-        if ( authority == null )
-        {
-            return false;
-        }
-
-        Perl5Util authorityMatcher = new Perl5Util();
-        Perl5Util matchIPV4Pat = new Perl5Util();
-
-        if ( !authorityMatcher.match( AUTHORITY_PATTERN, authority ) )
-        {
-            return false;
-        }
-
-        boolean ipV4Address = false;
-        boolean hostname = false;
-        // check if authority is IP address or hostname
-        String hostIP = authorityMatcher.group( PARSE_AUTHORITY_HOST_IP );
-        ipV4Address = matchIPV4Pat.match( IP_V4_DOMAIN_PATTERN, hostIP );
-
-        if ( ipV4Address )
-        {
-            // this is an IP address so check components
-            for ( int i = 1; i <= 4; i++ )
-            {
-                String ipSegment = matchIPV4Pat.group( i );
-                if ( ipSegment == null || ipSegment.length() <= 0 )
-                {
-                    return false;
-                }
-
-                try
-                {
-                    if ( Integer.parseInt( ipSegment ) > 255 )
-                    {
-                        return false;
-                    }
-                }
-                catch ( NumberFormatException e )
-                {
-                    return false;
-                }
-
-            }
-        }
-        else
-        {
-            // Domain is hostname name
-            Perl5Util domainMatcher = new Perl5Util();
-            hostname = domainMatcher.match( DOMAIN_PATTERN, hostIP );
-        }
-
-        //rightmost hostname will never start with a digit.
-        if ( hostname )
-        {
-            String[] domainSegment = new String[10];
-            boolean match = true;
-            int segmentCount = 0;
-            int segmentLength = 0;
-            Perl5Util atomMatcher = new Perl5Util();
-
-            while ( match )
-            {
-                match = atomMatcher.match( ATOM_PATTERN, hostIP );
-                if ( match )
-                {
-                    domainSegment[segmentCount] = atomMatcher.group( 1 );
-                    segmentLength = domainSegment[segmentCount].length() + 1;
-                    hostIP = ( segmentLength >= hostIP.length() ) ? "" : hostIP.substring(
segmentLength );
-
-                    segmentCount++;
-                }
-            }
-            String topLevel = domainSegment[segmentCount - 1];
-            // don't check toplevel when we have only a server name like localhost
-            if ( segmentCount != 1 && (topLevel.length() < 2 ) )
-            {
-                return false;
-            }
-
-            // First letter of top level must be a alpha
-            Perl5Util alphaMatcher = new Perl5Util();
-            if ( !alphaMatcher.match( ALPHA_PATTERN, topLevel.substring( 0, 1 ) ) )
-            {
-                return false;
-            }
-        }
-
-        if ( !hostname && !ipV4Address )
-        {
-            return false;
+            URI uri = new URI( value );
+            return this.allowedSchemes.contains( uri.getScheme() );
         }
-
-        String port = authorityMatcher.group( PARSE_AUTHORITY_PORT );
-        if ( port != null )
-        {
-            Perl5Util portMatcher = new Perl5Util();
-            if ( !portMatcher.match( PORT_PATTERN, port ) )
-            {
-                return false;
-            }
-        }
-
-        String extra = authorityMatcher.group( PARSE_AUTHORITY_EXTRA );
-        if ( !StringUtils.isBlank( extra ) )
+        catch ( URISyntaxException e )
         {
             return false;
         }
-
-        return true;
-    }
-
-    /**
-     * Returns true if the path is valid.  A <code>null</code> value is considered
invalid.
-     */
-    protected boolean isValidPath( String path )
-    {
-        if ( path == null )
-        {
-            return false;
-        }
-
-        Perl5Util pathMatcher = new Perl5Util();
-
-        if ( !pathMatcher.match( PATH_PATTERN, path ) )
-        {
-            return false;
-        }
-
-        int slash2Count = countToken( "//", path );
-        if ( this.options.isOff( ALLOW_2_SLASHES ) && ( slash2Count > 0 ) )
-        {
-            return false;
-        }
-
-        int slashCount = countToken( "/", path );
-        int dot2Count = countToken( "..", path );
-        if ( dot2Count > 0 )
-        {
-            if ( ( slashCount - slash2Count - 1 ) <= dot2Count )
-            {
-                return false;
-            }
-        }
-
-        return true;
     }
 
     /**
-     * Returns true if the query is null or it's a properly formatted query string.
-     */
-    protected boolean isValidQuery( String query )
-    {
-        if ( query == null )
-        {
-            return true;
-        }
-
-        Perl5Util queryMatcher = new Perl5Util();
-        return queryMatcher.match( QUERY_PATTERN, query );
-    }
-
-    /**
-     * Returns true if the given fragment is null or fragments are allowed.
-     */
-    protected boolean isValidFragment( String fragment )
-    {
-        if ( fragment == null )
-        {
-            return true;
-        }
-
-        return this.options.isOff( NO_FRAGMENTS );
-    }
-
-    /**
-     * Returns the number of times the token appears in the target.
-     */
-    protected int countToken( String token, String target )
-    {
-        int tokenIndex = 0;
-        int count = 0;
-        while ( tokenIndex != -1 )
-        {
-            tokenIndex = target.indexOf( token, tokenIndex );
-            if ( tokenIndex > -1 )
-            {
-                tokenIndex++;
-                count++;
-            }
-        }
-        return count;
-    }
-    
-    /**
      * @param url
      * @return URLUserInfo cannot be null
      * @throws URISyntaxException
@@ -552,7 +140,7 @@
         }
         return urlUserInfo;
     }
-    
+
     public void configure( PlexusConfiguration plexusConfiguration )
         throws PlexusConfigurationException
     {

Modified: continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
(original)
+++ continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
Tue Aug 26 15:29:10 2008
@@ -65,7 +65,7 @@
     public void testFailureHttpWithAuth()
         throws Exception
     {
-        assertFalse( getContinuumUrlValidator()
+        assertTrue( getContinuumUrlValidator()
             .validate( "http://username:passwordsvn.apache.org/repos/asf/continuum/trunk/pom.xml"
) );
     }
 

Modified: continuum/trunk/continuum-core/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/pom.xml?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/continuum-core/pom.xml (original)
+++ continuum/trunk/continuum-core/pom.xml Tue Aug 26 15:29:10 2008
@@ -111,10 +111,6 @@
       <artifactId>plexus-jdo2</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-formica</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
     </dependency>    

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=689267&r1=689266&r2=689267&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Tue Aug 26 15:29:10 2008
@@ -692,21 +692,6 @@
         </exclusions>
       </dependency>
       <dependency>
-        <groupId>org.codehaus.plexus</groupId>
-        <artifactId>plexus-formica</artifactId>
-        <version>1.0-beta-13</version>
-        <exclusions>
-          <exclusion>
-            <groupId>org.codehaus.plexus</groupId>
-            <artifactId>plexus-container-default</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>ognl</groupId>
-            <artifactId>ognl</artifactId>
-          </exclusion>
-        </exclusions>
-      </dependency>
-      <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpclient</artifactId>
         <version>4.0-alpha4</version>



Mime
View raw message