View Javadoc
1   /*
2    * Copyright 2007 The Codehaus Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.codehaus.plexus.archiver.filters;
15  
16  import javax.annotation.Nonnull;
17  import javax.inject.Named;
18  import javax.inject.Singleton;
19  
20  import java.io.IOException;
21  
22  import org.codehaus.plexus.components.io.fileselectors.FileInfo;
23  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
24  import org.codehaus.plexus.util.SelectorUtils;
25  
26  /**
27   * @since 1.0-alpha-9
28   */
29  @Singleton
30  @Named("jar-security")
31  public class JarSecurityFileSelector implements FileSelector {
32      public static final String[] SECURITY_FILE_PATTERNS = {
33          "META-INF/*.RSA",
34          "META-INF/*.DSA",
35          "META-INF/*.SF",
36          "META-INF/*.EC",
37          "META-INF/*.rsa",
38          "META-INF/*.dsa",
39          "META-INF/*.sf",
40          "META-INF/*.ec"
41      };
42  
43      @Override
44      public boolean isSelected(@Nonnull FileInfo fileInfo) throws IOException {
45          String name = fileInfo.getName();
46  
47          for (String pattern : SECURITY_FILE_PATTERNS) {
48              if (SelectorUtils.match(pattern, name)) {
49                  return false;
50              }
51          }
52  
53          return true;
54      }
55  }