1 | |
package org.apache.maven.archiva.repository.scanner.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.commons.collections.Predicate; |
25 | |
import org.apache.commons.io.FilenameUtils; |
26 | |
import org.apache.maven.archiva.common.utils.BaseFile; |
27 | |
import org.apache.maven.archiva.consumers.RepositoryContentConsumer; |
28 | |
import org.codehaus.plexus.util.SelectorUtils; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class ConsumerWantsFilePredicate |
36 | |
implements Predicate |
37 | |
{ |
38 | |
private BaseFile basefile; |
39 | |
|
40 | 0 | private boolean isCaseSensitive = true; |
41 | |
|
42 | 0 | private int wantedFileCount = 0; |
43 | |
|
44 | 0 | private long changesSince = 0; |
45 | |
|
46 | |
public boolean evaluate( Object object ) |
47 | |
{ |
48 | 0 | boolean satisfies = false; |
49 | |
|
50 | 0 | if ( object instanceof RepositoryContentConsumer ) |
51 | |
{ |
52 | 0 | RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; |
53 | 0 | if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) ) |
54 | |
{ |
55 | 0 | satisfies = true; |
56 | |
|
57 | |
|
58 | 0 | wantedFileCount++; |
59 | |
|
60 | 0 | if ( !consumer.isProcessUnmodified() ) |
61 | |
{ |
62 | |
|
63 | 0 | if ( basefile.lastModified() < changesSince ) |
64 | |
{ |
65 | |
|
66 | 0 | satisfies = false; |
67 | |
} |
68 | |
} |
69 | |
} |
70 | |
} |
71 | |
|
72 | 0 | return satisfies; |
73 | |
} |
74 | |
|
75 | |
public BaseFile getBasefile() |
76 | |
{ |
77 | 0 | return basefile; |
78 | |
} |
79 | |
|
80 | |
public int getWantedFileCount() |
81 | |
{ |
82 | 0 | return wantedFileCount; |
83 | |
} |
84 | |
|
85 | |
public boolean isCaseSensitive() |
86 | |
{ |
87 | 0 | return isCaseSensitive; |
88 | |
} |
89 | |
|
90 | |
public void setBasefile( BaseFile basefile ) |
91 | |
{ |
92 | 0 | this.basefile = basefile; |
93 | 0 | this.wantedFileCount = 0; |
94 | 0 | } |
95 | |
|
96 | |
public void setCaseSensitive( boolean isCaseSensitive ) |
97 | |
{ |
98 | 0 | this.isCaseSensitive = isCaseSensitive; |
99 | 0 | } |
100 | |
|
101 | |
private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath ) |
102 | |
{ |
103 | |
|
104 | 0 | List<String> excludes = consumer.getExcludes(); |
105 | 0 | if ( excludes != null ) |
106 | |
{ |
107 | 0 | for ( String pattern : excludes ) |
108 | |
{ |
109 | 0 | if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) |
110 | |
{ |
111 | |
|
112 | 0 | return false; |
113 | |
} |
114 | |
} |
115 | |
} |
116 | |
|
117 | |
|
118 | 0 | for ( String pattern : consumer.getIncludes() ) |
119 | |
{ |
120 | 0 | if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) |
121 | |
{ |
122 | |
|
123 | 0 | return true; |
124 | |
} |
125 | |
} |
126 | |
|
127 | |
|
128 | 0 | return false; |
129 | |
} |
130 | |
|
131 | |
public void setChangesSince( long changesSince ) |
132 | |
{ |
133 | 0 | this.changesSince = changesSince; |
134 | 0 | } |
135 | |
} |