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.commons.io.FilenameUtils;
24 import org.apache.maven.archiva.common.utils.BaseFile;
25 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
26 import org.codehaus.plexus.util.SelectorUtils;
28 import java.util.List;
31 * ConsumerWantsFilePredicate
35 public class ConsumerWantsFilePredicate
38 private BaseFile basefile;
40 private boolean isCaseSensitive = true;
42 private int wantedFileCount = 0;
44 private long changesSince = 0;
46 public boolean evaluate( Object object )
48 boolean satisfies = false;
50 if ( object instanceof RepositoryContentConsumer )
52 RepositoryContentConsumer consumer = (RepositoryContentConsumer) object;
53 if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) )
57 // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid
60 if ( !consumer.isProcessUnmodified() )
62 // Timestamp finished points to the last successful scan, not this current one.
63 if ( basefile.lastModified() < changesSince )
65 // Skip file as no change has occured.
75 public BaseFile getBasefile()
80 public int getWantedFileCount()
82 return wantedFileCount;
85 public boolean isCaseSensitive()
87 return isCaseSensitive;
90 public void setBasefile( BaseFile basefile )
92 this.basefile = basefile;
93 this.wantedFileCount = 0;
96 public void setCaseSensitive( boolean isCaseSensitive )
98 this.isCaseSensitive = isCaseSensitive;
101 private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
103 // Test excludes first.
104 List<String> excludes = consumer.getExcludes();
105 if ( excludes != null )
107 for ( String pattern : excludes )
109 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
111 // Definately does NOT WANT FILE.
117 // Now test includes.
118 for ( String pattern : consumer.getIncludes() )
120 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
122 // Specifically WANTS FILE.
127 // Not included, and Not excluded? Default to EXCLUDE.
131 public void setChangesSince( long changesSince )
133 this.changesSince = changesSince;