1 package org.apache.maven.archiva.repository.scanner.functors;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.collections.Predicate;
23 import org.apache.maven.archiva.common.utils.BaseFile;
24 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
25 import org.codehaus.plexus.util.SelectorUtils;
26 import org.codehaus.plexus.util.StringUtils;
28 import java.util.List;
31 * ConsumerWantsFilePredicate
33 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 public class ConsumerWantsFilePredicate
39 private BaseFile basefile;
41 private boolean isCaseSensitive = true;
43 private int wantedFileCount = 0;
45 private long changesSince = 0;
47 public boolean evaluate( Object object )
49 boolean satisfies = false;
51 if ( object instanceof RepositoryContentConsumer )
53 RepositoryContentConsumer consumer = (RepositoryContentConsumer) object;
54 if ( wantsFile( consumer, StringUtils.replace( basefile.getRelativePath(), "\\", "/" ) ) )
58 // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid
61 if ( !consumer.isProcessUnmodified() )
63 // Timestamp finished points to the last successful scan, not this current one.
64 if ( basefile.lastModified() < changesSince )
66 // Skip file as no change has occured.
76 public BaseFile getBasefile()
81 public int getWantedFileCount()
83 return wantedFileCount;
86 public boolean isCaseSensitive()
88 return isCaseSensitive;
91 public void setBasefile( BaseFile basefile )
93 this.basefile = basefile;
94 this.wantedFileCount = 0;
97 public void setCaseSensitive( boolean isCaseSensitive )
99 this.isCaseSensitive = isCaseSensitive;
102 private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
104 // Test excludes first.
105 List<String> excludes = consumer.getExcludes();
106 if ( excludes != null )
108 for ( String pattern : excludes )
110 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
112 // Definately does NOT WANT FILE.
118 // Now test includes.
119 for ( String pattern : consumer.getIncludes() )
121 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
123 // Specifically WANTS FILE.
128 // Not included, and Not excluded? Default to EXCLUDE.
132 public void setChangesSince( long changesSince )
134 this.changesSince = changesSince;