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 org.apache.archiva.common.utils.BaseFile;
23 import org.apache.archiva.consumers.RepositoryContentConsumer;
24 import org.apache.archiva.repository.ManagedRepository;
25 import org.apache.archiva.repository.features.IndexCreationFeature;
26 import org.apache.commons.collections4.Predicate;
27 import org.apache.commons.io.FilenameUtils;
28 import org.apache.commons.lang3.StringUtils;
29 import org.apache.tools.ant.types.selectors.SelectorUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 import java.nio.file.Paths;
34 import java.util.List;
35
36
37
38
39 public class ConsumerWantsFilePredicate
40 implements Predicate<RepositoryContentConsumer>
41 {
42 private BaseFile basefile;
43
44 private boolean isCaseSensitive = true;
45
46 private int wantedFileCount = 0;
47
48 private long changesSince = 0;
49
50 private ManagedRepository managedRepository;
51
52 private Logger logger = LoggerFactory.getLogger( getClass( ) );
53
54
55
56
57 public ConsumerWantsFilePredicate( )
58 {
59
60 }
61
62 public ConsumerWantsFilePredicate( ManagedRepository managedRepository )
63 {
64 this.managedRepository = managedRepository;
65 }
66
67 @Override
68 public boolean evaluate( RepositoryContentConsumer object )
69 {
70 boolean satisfies = false;
71
72 RepositoryContentConsumerache/archiva/consumers/RepositoryContentConsumer.html#RepositoryContentConsumer">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 return satisfies;
92 }
93
94 public BaseFile getBasefile( )
95 {
96 return basefile;
97 }
98
99 public int getWantedFileCount( )
100 {
101 return wantedFileCount;
102 }
103
104 public boolean isCaseSensitive( )
105 {
106 return isCaseSensitive;
107 }
108
109 public void setBasefile( BaseFile basefile )
110 {
111 this.basefile = basefile;
112 this.wantedFileCount = 0;
113 }
114
115 public void setCaseSensitive( boolean isCaseSensitive )
116 {
117 this.isCaseSensitive = isCaseSensitive;
118 }
119
120 private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
121 {
122
123 List<String> excludes = consumer.getExcludes( );
124 if ( excludes != null )
125 {
126 for ( String pattern : excludes )
127 {
128 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
129 {
130
131 return false;
132 }
133 }
134 }
135
136 if ( managedRepository != null )
137 {
138 String indexDirectory;
139 if ( managedRepository.supportsFeature( IndexCreationFeature.class ) )
140 {
141 IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( );
142 if ( icf.getIndexPath( ) == null )
143 {
144 indexDirectory = ".index";
145 }
146 else
147 {
148 indexDirectory = ( icf.getIndexPath( ).getScheme( ) == null ? Paths.get( icf.getIndexPath( ).getPath( ) ) : Paths.get( icf.getIndexPath( ) ) ).toString( );
149 }
150 }
151 else
152 {
153 indexDirectory = ".index";
154 }
155 if ( StringUtils.isEmpty( indexDirectory ) )
156 {
157 indexDirectory = ".index";
158 }
159 if ( StringUtils.startsWith( relativePath, indexDirectory ) )
160 {
161 logger.debug( "ignore file {} part of the index directory {}", relativePath, indexDirectory );
162 return false;
163 }
164 }
165
166
167 for ( String pattern : consumer.getIncludes( ) )
168 {
169 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
170 {
171
172 return true;
173 }
174 }
175
176
177 return false;
178 }
179
180 public void setChangesSince( long changesSince )
181 {
182 this.changesSince = changesSince;
183 }
184 }