Whoops.  Small bug in my code:
   
  public static Filter getArtifactTypeFilter(String types) {
        if (types == null || types.trim().equals("*")) {
            return NO_FILTER;
        }
        String[] t = types.split(",");
        List acceptedTypes = new ArrayList(types.length());
        List negatedTypes = new ArrayList(types.length());
        for (int i = 0; i < t.length; i++) {
               String type = t[i].trim();
             if (type.startsWith("!")) {
                 negatedTypes.add(type.substring(1));
            } else {
                acceptedTypes.add(type);
            }
        }
       Filter acceptedTypesFilter = new ArtifactTypeFilter(acceptedTypes);
       Filter negatedTypesFilter;
       if (negatedTypes.isEmpty()) {
            negatedTypesFilter = new NotFilter(NO_FILTER);
       } else {
           negatedTypesFilter = new NotFilter(new 
ArtifactTypeFilter(negatedTypes));
      }
     return new OrFilter(acceptedTypesFilter, negatedTypesFilter);
  }

  Scott
  
Scott Goldstein <[EMAIL PROTECTED]> wrote:
  In my common build file, for organization purposes, I retrieve files by type 
and place them in particular directories. For example:

.../lib Contains win32 dlls
.../jlib Containes jar files
.../obl Contains Installscript libraries

This works, but I don't want to list out all of them. In other words, I want to 
choose a few well known types for their own directories and the rest I want to 
place in a directory called "misc".

One way to do this, is to have a type filter with negation capabilities. So, 
for the type attribute, you could specify, "!jar, !dll, !obl". I've done this 
will a small change in FitlerHelper:

public static Filter getArtifactTypeFilter(String types) {
if (types == null || types.trim().equals("*")) {
return NO_FILTER;
}
String[] t = types.split(",");
List acceptedTypes = new ArrayList(types.length());
List negatedTypes = new ArrayList(types.length());
for (int i = 0; i < t.length; i++) {
String type = t[i].trim();
if (type.startsWith("!")) {
negatedTypes.add(type.substring(1));
} else {
acceptedTypes.add(type);
}
}
Filter acceptedTypesFilter = new ArtifactTypeFilter(acceptedTypes);
Filter negatedTypesFilter = new NotFilter(new ArtifactTypeFilter(negatedTypes));
return new OrFilter(acceptedTypesFilter, negatedTypesFilter);
}

This works for my situation, but I don't know if it's the best long term 
approach. I would imagine a mechanism of providing filters in the same way that 
the ant fileset tag works. In other words, providing include and exclude tags. 
This would be extremely flexible, allowing the developer to perform any type of 
filtering desired.

I haven't thought through all of the implications, but I thought I would post 
the idea for discussion.

Thanks.

Scott

Reply via email to