src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java
// lists all the values a token can take in a pattern, as listed by a given url lister

lists all the values a token can take in a pattern, as listed by a given url lister
lists all the values a token can take in a pattern as listed by a given url lister
public static String[] listTokenValues(Repository rep, String pattern, String token) {
        String fileSep = rep.getFileSeparator();
        pattern = rep.standardize(pattern);
        String tokenString = IvyPatternHelper.getTokenString(token);
        int index = pattern.indexOf(tokenString);
        if (index == -1) {
            Message.verbose("unable to list "+token+" in "+pattern+": token not found in pattern");
            return null;
        }
        if (((pattern.length() <= index + tokenString.length()) 
                || fileSep.equals(pattern.substring(index + tokenString.length(), index + tokenString.length() + 1)))
                && (index == 0 || fileSep.equals(pattern.substring(index - 1, index)))) {
            String root = pattern.substring(0, index);
            return listAll(rep, root);
        } else {
            int slashIndex = pattern.substring(0, index).lastIndexOf(fileSep);
            String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex);
            try {
                Message.debug("\tusing "+rep+" to list all in "+root);
                List all = rep.list(root);
                if (all != null) {
                    Message.debug("\t\tfound "+all.size()+" urls");
                    List ret = new ArrayList(all.size());
                    int endNameIndex = pattern.indexOf(fileSep, slashIndex + 1);
                    String namePattern;
                    if (endNameIndex != -1) {
                        namePattern = pattern.substring(slashIndex+1, endNameIndex);
                    } else {
                        namePattern = pattern.substring(slashIndex + 1);
                    }
                    String acceptNamePattern = IvyPatternHelper.substituteToken(namePattern, token, "(.+)");
                    Pattern p = Pattern.compile(acceptNamePattern);
                    for (Iterator iter = all.iterator(); iter.hasNext();) {
                        String path = (String)iter.next();
                        int pathSlashIndex = path.lastIndexOf(fileSep);
                        String name = pathSlashIndex == -1 ? path : path.substring(pathSlashIndex+1);
                        Matcher m = p.matcher(name);
                        if (m.matches()) {
                            String value = m.group(1);
                            ret.add(value);
                        }
                    }
                    Message.debug("\t\t"+ret.size()+" matched "+pattern);
                    return (String[])ret.toArray(new String[ret.size()]);
                } else {
                    return null;
                }
            } catch (Exception e) {
                Message.warn("problem while listing resources in "+root+" with "+rep+": "+e.getClass()+" "+e.getMessage());
                return null;
            }
        }
    }
public static String [ ] listTokenValues ( Repository rep , String pattern , String token ) { String fileSep = rep . getFileSeparator ( ) ; pattern = rep . standardize ( pattern ) ; String tokenString = IvyPatternHelper . getTokenString ( token ) ; int index = pattern . indexOf ( tokenString ) ; if ( index == - 1 ) { Message . verbose ( "unable to list " + token + " in " + pattern + ": token not found in pattern" ) ; return null ; } if ( ( ( pattern . length ( ) <= index + tokenString . length ( ) ) || fileSep . equals ( pattern . substring ( index + tokenString . length ( ) , index + tokenString . length ( ) + 1 ) ) ) && ( index == 0 || fileSep . equals ( pattern . substring ( index - 1 , index ) ) ) ) { String root = pattern . substring ( 0 , index ) ; return listAll ( rep , root ) ; } else { int slashIndex = pattern . substring ( 0 , index ) . lastIndexOf ( fileSep ) ; String root = slashIndex == - 1 ? "" : pattern . substring ( 0 , slashIndex ) ; try { Message . debug ( "\tusing " + rep + " to list all in " + root ) ; List all = rep . list ( root ) ; if ( all != null ) { Message . debug ( "\t\tfound " + all . size ( ) + " urls" ) ; List ret = new ArrayList ( all . size ( ) ) ; int endNameIndex = pattern . indexOf ( fileSep , slashIndex + 1 ) ; String namePattern ; if ( endNameIndex != - 1 ) { namePattern = pattern . substring ( slashIndex + 1 , endNameIndex ) ; } else { namePattern = pattern . substring ( slashIndex + 1 ) ; } String acceptNamePattern = IvyPatternHelper . substituteToken ( namePattern , token , "(.+)" ) ; Pattern p = Pattern . compile ( acceptNamePattern ) ; for ( Iterator iter = all . iterator ( ) ; iter . hasNext ( ) ; ) { String path = ( String ) iter . next ( ) ; int pathSlashIndex = path . lastIndexOf ( fileSep ) ; String name = pathSlashIndex == - 1 ? path : path . substring ( pathSlashIndex + 1 ) ; Matcher m = p . matcher ( name ) ; if ( m . matches ( ) ) { String value = m . group ( 1 ) ; ret . add ( value ) ; } } Message . debug ( "\t\t" + ret . size ( ) + " matched " + pattern ) ; return ( String [ ] ) ret . toArray ( new String [ ret . size ( ) ] ) ; } else { return null ; } } catch ( Exception e ) { Message . warn ( "problem while listing resources in " + root + " with " + rep + ": " + e . getClass ( ) + " " + e . getMessage ( ) ) ; return null ; } } }
lists all the values a token can take in a pattern, as listed by a given url lister
lists all the values a token can take in a pattern as listed by a given url lister
// the searched token is a whole name
