1 package org.apache.archiva.consumers.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.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.collections.Predicate;
27 import org.apache.commons.io.FilenameUtils;
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.tools.ant.types.selectors.SelectorUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import java.nio.file.Paths;
34 import java.util.List;
37 * ConsumerWantsFilePredicate
39 public class ConsumerWantsFilePredicate
42 private BaseFile basefile;
44 private boolean isCaseSensitive = true;
46 private int wantedFileCount = 0;
48 private long changesSince = 0;
50 private ManagedRepository managedRepository;
52 private Logger logger = LoggerFactory.getLogger( getClass() );
55 * @deprecated use constructor with ManagedRepository
57 public ConsumerWantsFilePredicate()
62 public ConsumerWantsFilePredicate( ManagedRepository managedRepository )
64 this.managedRepository = managedRepository;
68 public boolean evaluate( Object object )
70 boolean satisfies = false;
72 if ( object instanceof RepositoryContentConsumer )
74 RepositoryContentConsumer consumer = (RepositoryContentConsumer) object;
75 if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) )
79 // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid
82 if ( !consumer.isProcessUnmodified() )
84 // Timestamp finished points to the last successful scan, not this current one.
85 if ( basefile.lastModified() < changesSince )
87 // Skip file as no change has occurred.
97 public BaseFile getBasefile()
102 public int getWantedFileCount()
104 return wantedFileCount;
107 public boolean isCaseSensitive()
109 return isCaseSensitive;
112 public void setBasefile( BaseFile basefile )
114 this.basefile = basefile;
115 this.wantedFileCount = 0;
118 public void setCaseSensitive( boolean isCaseSensitive )
120 this.isCaseSensitive = isCaseSensitive;
123 private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
125 // Test excludes first.
126 List<String> excludes = consumer.getExcludes();
127 if ( excludes != null )
129 for ( String pattern : excludes )
131 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
133 // Definately does NOT WANT FILE.
139 if ( managedRepository != null )
141 String indexDirectory;
142 if (managedRepository.supportsFeature( IndexCreationFeature.class )) {
143 IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get();
144 if (icf.getIndexPath()==null) {
145 indexDirectory=".index";
148 indexDirectory = ( icf.getIndexPath( ).getScheme( ) == null ? Paths.get( icf.getIndexPath( ).getPath( ) ) : Paths.get( icf.getIndexPath( ) ) ).toString( );
151 indexDirectory = ".index";
153 if (StringUtils.isEmpty( indexDirectory )) {
154 indexDirectory = ".index";
156 if ( StringUtils.startsWith( relativePath, indexDirectory ) )
158 logger.debug( "ignore file {} part of the index directory {}", relativePath, indexDirectory );
163 // Now test includes.
164 for ( String pattern : consumer.getIncludes() )
166 if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
168 // Specifically WANTS FILE.
173 // Not included, and Not excluded? Default to EXCLUDE.
177 public void setChangesSince( long changesSince )
179 this.changesSince = changesSince;