This project has retired. For details please refer to its
        
        Attic page.
      
 
ConsumerWantsFilePredicate xref
1   package org.apache.archiva.consumers.functors;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import java.util.List;
23  
24  import org.apache.archiva.admin.model.beans.ManagedRepository;
25  import org.apache.commons.collections.Predicate;
26  import org.apache.commons.io.FilenameUtils;
27  import org.apache.archiva.common.utils.BaseFile;
28  import org.apache.archiva.consumers.RepositoryContentConsumer;
29  import org.apache.commons.lang.StringUtils;
30  import org.apache.tools.ant.types.selectors.SelectorUtils;
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  
35  
36  
37  public class ConsumerWantsFilePredicate
38      implements Predicate
39  {
40      private BaseFile basefile;
41  
42      private boolean isCaseSensitive = true;
43  
44      private int wantedFileCount = 0;
45  
46      private long changesSince = 0;
47  
48      private ManagedRepository managedRepository;
49  
50      private Logger logger = LoggerFactory.getLogger( getClass() );
51  
52      
53  
54  
55      public ConsumerWantsFilePredicate()
56      {
57          
58      }
59  
60      public ConsumerWantsFilePredicate( ManagedRepository managedRepository )
61      {
62          this.managedRepository = managedRepository;
63      }
64  
65      @Override
66      public boolean evaluate( Object object )
67      {
68          boolean satisfies = false;
69  
70          if ( object instanceof RepositoryContentConsumer )
71          {
72              RepositoryContentConsumer consumer = (RepositoryContentConsumer) object;
73              if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) )
74              {
75                  satisfies = true;
76  
77                  
78                  wantedFileCount++;
79  
80                  if ( !consumer.isProcessUnmodified() )
81                  {
82                      
83                      if ( basefile.lastModified() < changesSince )
84                      {
85                          
86                          satisfies = false;
87                      }
88                  }
89              }
90          }
91  
92          return satisfies;
93      }
94  
95      public BaseFile getBasefile()
96      {
97          return basefile;
98      }
99  
100     public int getWantedFileCount()
101     {
102         return wantedFileCount;
103     }
104 
105     public boolean isCaseSensitive()
106     {
107         return isCaseSensitive;
108     }
109 
110     public void setBasefile( BaseFile basefile )
111     {
112         this.basefile = basefile;
113         this.wantedFileCount = 0;
114     }
115 
116     public void setCaseSensitive( boolean isCaseSensitive )
117     {
118         this.isCaseSensitive = isCaseSensitive;
119     }
120 
121     private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
122     {
123         
124         List<String> excludes = consumer.getExcludes();
125         if ( excludes != null )
126         {
127             for ( String pattern : excludes )
128             {
129                 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
130                 {
131                     
132                     return false;
133                 }
134             }
135         }
136 
137         if ( managedRepository != null )
138         {
139             String indexDirectory = managedRepository.getIndexDirectory();
140             if ( StringUtils.startsWith( relativePath, indexDirectory ) )
141             {
142                 logger.debug( "ignore file {} part of the index directory {}", relativePath, indexDirectory );
143                 return false;
144             }
145         }
146 
147         
148         for ( String pattern : consumer.getIncludes() )
149         {
150             if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
151             {
152                 
153                 return true;
154             }
155         }
156 
157         
158         return false;
159     }
160 
161     public void setChangesSince( long changesSince )
162     {
163         this.changesSince = changesSince;
164     }
165 }