View Javadoc

1   package org.apache.continuum.purge.repository.utils;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.util.SelectorUtils;
23  
24  import java.util.Arrays;
25  import java.util.List;
26  
27  /**
28   * Codes were taken from Archiva and made some changes.
29   */
30  public class FileTypes
31  {
32      private List<String> artifactFileTypePatterns;
33  
34      private List<String> ignoredFileTypePatterns;
35  
36      public static final List<String> DEFAULT_EXCLUSIONS = Arrays.asList( "**/maven-metadata.xml",
37                                                                           "**/maven-metadata-*.xml", "**/*.sha1",
38                                                                           "**/*.asc", "**/*.md5", "**/*.pgp" );
39  
40      public List<String> getIgnoredFileTypePatterns()
41      {
42          if ( ignoredFileTypePatterns == null )
43          {
44              ignoredFileTypePatterns = DEFAULT_EXCLUSIONS;
45          }
46  
47          return ignoredFileTypePatterns;
48      }
49  
50      public List<String> getArtifactFileTypePatterns()
51      {
52          return artifactFileTypePatterns;
53      }
54  
55      public synchronized boolean matchesArtifactPattern( String relativePath )
56      {
57          // Correct the slash pattern.
58          relativePath = relativePath.replace( '\\', '/' );
59  
60          if ( artifactFileTypePatterns == null )
61          {
62              return false;
63          }
64  
65          for ( String pattern : artifactFileTypePatterns )
66          {
67              if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
68              {
69                  // Found match
70                  return true;
71              }
72          }
73  
74          // No match.
75          return false;
76      }
77  
78      public boolean matchesDefaultExclusions( String relativePath )
79      {
80          // Correct the slash pattern.
81          relativePath = relativePath.replace( '\\', '/' );
82  
83          for ( String pattern : DEFAULT_EXCLUSIONS )
84          {
85              if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
86              {
87                  // Found match
88                  return true;
89              }
90          }
91  
92          // No match.
93          return false;
94      }
95  }