ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles Scokart" <gscok...@gmail.com>
Subject Re: svn commit: r695402 - in /ant/core/trunk/src/main/org/apache/tools/ant: DirectoryScanner.java types/selectors/PathPattern.java types/selectors/SelectorUtils.java
Date Mon, 15 Sep 2008 10:56:37 GMT
Cool,
I was thinking to do something like that but I was not sure about the
class to use, and wheter it was really usefull to store tokenized path
into an object in case we have a single include patterns.
I missed the fact that isDeeper was also requiring a tokenization.  So
clearly my doubt about the usefullness was invalid (I was thinking
that we could eliminate a tokenization only when we had 2 or more
includes pattern on which we loop).

However, with this change you are storing pattern and values in the
same class.  I think we should have two classes.  Both need to
tokenize a string using the same tokenizer, but what you can do with
both is different.

WDYT?

Gilles


2008/9/15  <bodewig@apache.org>:
> Author: bodewig
> Date: Mon Sep 15 02:54:06 2008
> New Revision: 695402
>
> URL: http://svn.apache.org/viewvc?rev=695402&view=rev
> Log:
> Avoid repeated tokenization, make DefaultExcludesTest happy.
>
> Modified:
>    ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
>    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PathPattern.java
>    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java?rev=695402&r1=695401&r2=695402&view=diff
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java Mon Sep 15 02:54:06
2008
> @@ -145,30 +145,30 @@
>      */
>     protected static final String[] DEFAULTEXCLUDES = {
>         // Miscellaneous typical temporary files
> -        SelectorUtils.DEEP_ROOT_MATCH + "*~",
> -        SelectorUtils.DEEP_ROOT_MATCH + "#*#",
> -        SelectorUtils.DEEP_ROOT_MATCH + ".#*",
> -        SelectorUtils.DEEP_ROOT_MATCH + "%*%",
> -        SelectorUtils.DEEP_ROOT_MATCH + "._*",
> +        SelectorUtils.DEEP_TREE_MATCH + "/*~",
> +        SelectorUtils.DEEP_TREE_MATCH + "/#*#",
> +        SelectorUtils.DEEP_TREE_MATCH + "/.#*",
> +        SelectorUtils.DEEP_TREE_MATCH + "/%*%",
> +        SelectorUtils.DEEP_TREE_MATCH + "/._*",
>
>         // CVS
> -        SelectorUtils.DEEP_ROOT_MATCH + "CVS",
> -        SelectorUtils.DEEP_ROOT_MATCH + "CVS" + SelectorUtils.DEEP_LEAVES_MATCH,
> -        SelectorUtils.DEEP_ROOT_MATCH + ".cvsignore",
> +        SelectorUtils.DEEP_TREE_MATCH + "/CVS",
> +        SelectorUtils.DEEP_TREE_MATCH + "/CVS/" + SelectorUtils.DEEP_TREE_MATCH,
> +        SelectorUtils.DEEP_TREE_MATCH + "/.cvsignore",
>
>         // SCCS
> -        SelectorUtils.DEEP_ROOT_MATCH + "SCCS",
> -        SelectorUtils.DEEP_ROOT_MATCH + "SCCS" + SelectorUtils.DEEP_LEAVES_MATCH,
> +        SelectorUtils.DEEP_TREE_MATCH + "/SCCS",
> +        SelectorUtils.DEEP_TREE_MATCH + "/SCCS/" + SelectorUtils.DEEP_TREE_MATCH,
>
>         // Visual SourceSafe
> -        SelectorUtils.DEEP_ROOT_MATCH + "vssver.scc",
> +        SelectorUtils.DEEP_TREE_MATCH + "/vssver.scc",
>
>         // Subversion
> -        SelectorUtils.DEEP_ROOT_MATCH + ".svn",
> -        SelectorUtils.DEEP_ROOT_MATCH + ".svn" + SelectorUtils.DEEP_LEAVES_MATCH,
> +        SelectorUtils.DEEP_TREE_MATCH + "/.svn",
> +        SelectorUtils.DEEP_TREE_MATCH + "/.svn/" + SelectorUtils.DEEP_TREE_MATCH,
>
>         // Mac
> -        SelectorUtils.DEEP_ROOT_MATCH + ".DS_Store"
> +        SelectorUtils.DEEP_TREE_MATCH + "/.DS_Store"
>     };
>
>     /**
> @@ -1295,10 +1295,13 @@
>      *         least one include pattern, or <code>false</code> otherwise.
>      */
>     protected boolean couldHoldIncluded(String name) {
> +        final PathPattern tokenizedName = new PathPattern(name);
>         for (int i = 0; i < includes.length; i++) {
> -            if (matchPatternStart(includes[i], name, isCaseSensitive())
> +            PathPattern tokenizedInclude = new PathPattern(includes[i]);
> +            if (tokenizedName.matchPatternStartOf(tokenizedInclude,
> +                                                  isCaseSensitive())
>                 && isMorePowerfulThanExcludes(name, includes[i])
> -                && isDeeper(includes[i], name)) {
> +                && isDeeper(tokenizedInclude, tokenizedName)) {
>                 return true;
>             }
>         }
> @@ -1313,13 +1316,9 @@
>      * @return whether the pattern is deeper than the name.
>      * @since Ant 1.6.3
>      */
> -    private boolean isDeeper(String pattern, String name) {
> -        Vector p = SelectorUtils.tokenizePath(pattern);
> -        if (!p.contains(SelectorUtils.DEEP_TREE_MATCH)) {
> -            Vector n = SelectorUtils.tokenizePath(name);
> -            return p.size() > n.size();
> -        }
> -        return true;
> +    private boolean isDeeper(PathPattern pattern, PathPattern name) {
> +        return pattern.containsPattern(SelectorUtils.DEEP_TREE_MATCH)
> +            || pattern.depth() > name.depth();
>     }
>
>     /**
> @@ -1341,7 +1340,8 @@
>      */
>     private boolean isMorePowerfulThanExcludes(String name,
>                                                String includepattern) {
> -        String soughtexclude = name + SelectorUtils.DEEP_LEAVES_MATCH;
> +        final String soughtexclude =
> +            name + File.separatorChar + SelectorUtils.DEEP_TREE_MATCH;
>         for (int counter = 0; counter < excludes.length; counter++) {
>             if (excludes[counter].equals(soughtexclude))  {
>                 return false;
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PathPattern.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PathPattern.java?rev=695402&r1=695401&r2=695402&view=diff
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PathPattern.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PathPattern.java Mon
Sep 15 02:54:06 2008
> @@ -70,6 +70,16 @@
>     }
>
>     /**
> +     * Tests whether or not this PathPattern matches the start of
> +     * another pattern.
> +     */
> +    public boolean matchPatternStartOf(PathPattern other,
> +                                       boolean caseSensitive) {
> +        return SelectorUtils.matchPatternStart(other.tokenizedPattern,
> +                                               tokenizedPattern, caseSensitive);
> +    }
> +
> +    /**
>      * @return The pattern String
>      */
>     public String toString() {
> @@ -79,4 +89,23 @@
>     public String getPattern() {
>         return pattern;
>     }
> +
> +    /**
> +     * The depth (or length) of a pattern.
> +     */
> +    public int depth() {
> +        return tokenizedPattern.length;
> +    }
> +
> +    /**
> +     * Does the tokenized pattern contain the given string?
> +     */
> +    public boolean containsPattern(String pat) {
> +        for (int i = 0; i < tokenizedPattern.length; i++) {
> +            if (tokenizedPattern[i].equals(pat)) {
> +                return true;
> +            }
> +        }
> +        return false;
> +    }
>  }
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java?rev=695402&r1=695401&r2=695402&view=diff
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java Mon
Sep 15 02:54:06 2008
> @@ -44,20 +44,6 @@
>      */
>     public static final String DEEP_TREE_MATCH = "**";
>
> -    /**
> -     * The pattern that matches an arbitrary number of directories at
> -     * the leaves.
> -     * @since Ant 1.8.0
> -     */
> -    public static final String DEEP_LEAVES_MATCH = File.separatorChar + "**";
> -
> -    /**
> -     * The pattern that matches an arbitrary number of directories at
> -     * the root.
> -     * @since Ant 1.8.0
> -     */
> -    public static final String DEEP_ROOT_MATCH = "**" + File.separatorChar;
> -
>     private static final SelectorUtils instance = new SelectorUtils();
>     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
>
> @@ -126,7 +112,30 @@
>
>         String[] patDirs = tokenizePathAsArray(pattern);
>         String[] strDirs = tokenizePathAsArray(str);
> +        return matchPatternStart(patDirs, strDirs, isCaseSensitive);
> +    }
> +
>
> +    /**
> +     * Tests whether or not a given path matches the start of a given
> +     * pattern up to the first "**".
> +     * <p>
> +     * This is not a general purpose test and should only be used if you
> +     * can live with false positives. For example, <code>pattern=**\a</code>
> +     * and <code>str=b</code> will yield <code>true</code>.
> +     *
> +     * @param patDirs The tokenized pattern to match against. Must not be
> +     *                <code>null</code>.
> +     * @param strDirs The tokenized path to match. Must not be
> +     *                <code>null</code>.
> +     * @param isCaseSensitive Whether or not matching should be performed
> +     *                        case sensitively.
> +     *
> +     * @return whether or not a given path matches the start of a given
> +     * pattern up to the first "**".
> +     */
> +    static boolean matchPatternStart(String[] patDirs, String[] strDirs,
> +                                     boolean isCaseSensitive) {
>         int patIdxStart = 0;
>         int patIdxEnd = patDirs.length - 1;
>         int strIdxStart = 0;
>
>
>



-- 
Gilles Scokart

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message