View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.assembly.archive.archiver;
20  
21  import java.io.File;
22  
23  import org.codehaus.plexus.archiver.ArchivedFileSet;
24  import org.codehaus.plexus.components.io.filemappers.FileMapper;
25  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
26  import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
27  
28  /**
29   *
30   */
31  class PrefixedArchivedFileSet implements ArchivedFileSet {
32      private static final FileMapper[] EMPTY_FILE_MAPPERS_ARRAY = new FileMapper[0];
33  
34      private final String rootPrefix;
35  
36      private final ArchivedFileSet fileSet;
37  
38      private final FileSelector[] selectors;
39  
40      /**
41       * @param fileSet    The archived file set.
42       * @param rootPrefix The root prefix.
43       * @param selectors  The file selectors.
44       */
45      PrefixedArchivedFileSet(ArchivedFileSet fileSet, String rootPrefix, FileSelector[] selectors) {
46          this.fileSet = fileSet;
47          this.selectors = selectors;
48  
49          if (rootPrefix.length() > 0 && !rootPrefix.endsWith("/")) {
50              this.rootPrefix = rootPrefix + "/";
51          } else {
52              this.rootPrefix = rootPrefix;
53          }
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public File getArchive() {
61          return fileSet.getArchive();
62      }
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public String[] getExcludes() {
69          return fileSet.getExcludes();
70      }
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public FileSelector[] getFileSelectors() {
77          return PrefixedFileSet.combineSelectors(fileSet.getFileSelectors(), selectors);
78      }
79  
80      /**
81       * {@inheritDoc}
82       */
83      @Override
84      public String[] getIncludes() {
85          return fileSet.getIncludes();
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public String getPrefix() {
93          String prefix = fileSet.getPrefix();
94          if (prefix.startsWith("/")) {
95              if (prefix.length() > 1) {
96                  prefix = prefix.substring(1);
97              } else {
98                  prefix = "";
99              }
100         }
101 
102         return rootPrefix + prefix;
103     }
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public boolean isCaseSensitive() {
110         return fileSet.isCaseSensitive();
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public boolean isIncludingEmptyDirectories() {
118         return fileSet.isIncludingEmptyDirectories();
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public boolean isUsingDefaultExcludes() {
126         return fileSet.isUsingDefaultExcludes();
127     }
128 
129     @Override
130     public InputStreamTransformer getStreamTransformer() {
131         return fileSet.getStreamTransformer();
132     }
133 
134     @Override
135     public FileMapper[] getFileMappers() {
136         return EMPTY_FILE_MAPPERS_ARRAY;
137     }
138 }