View Javadoc
1   package org.apache.maven.plugins.assembly.archive.archiver;
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.archiver.ArchivedFileSet;
23  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
24  import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
25  
26  import java.io.File;
27  import org.codehaus.plexus.components.io.filemappers.FileMapper;
28  
29  /**
30   *
31   */
32  class PrefixedArchivedFileSet
33      implements ArchivedFileSet
34  {
35      private final static FileMapper[] EMPTY_FILE_MAPPERS_ARRAY = new FileMapper[0];
36  
37      private final String rootPrefix;
38  
39      private final ArchivedFileSet fileSet;
40  
41      private final FileSelector[] selectors;
42  
43      /**
44       * @param fileSet    The archived file set.
45       * @param rootPrefix The root prefix.
46       * @param selectors  The file selectors.
47       */
48      PrefixedArchivedFileSet( ArchivedFileSet fileSet, String rootPrefix, FileSelector[] selectors )
49      {
50          this.fileSet = fileSet;
51          this.selectors = selectors;
52  
53          if ( rootPrefix.length() > 0 && !rootPrefix.endsWith( "/" ) )
54          {
55              this.rootPrefix = rootPrefix + "/";
56          }
57          else
58          {
59              this.rootPrefix = rootPrefix;
60          }
61      }
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public File getArchive()
68      {
69          return fileSet.getArchive();
70      }
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public String[] getExcludes()
77      {
78          return fileSet.getExcludes();
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      @Override
85      public FileSelector[] getFileSelectors()
86      {
87          return PrefixedFileSet.combineSelectors( fileSet.getFileSelectors(), selectors );
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      public String[] getIncludes()
95      {
96          return fileSet.getIncludes();
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public String getPrefix()
104     {
105         String prefix = fileSet.getPrefix();
106         if ( prefix.startsWith( "/" ) )
107         {
108             if ( prefix.length() > 1 )
109             {
110                 prefix = prefix.substring( 1 );
111             }
112             else
113             {
114                 prefix = "";
115             }
116         }
117 
118         return rootPrefix + prefix;
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public boolean isCaseSensitive()
126     {
127         return fileSet.isCaseSensitive();
128     }
129 
130     /**
131      * {@inheritDoc}
132      */
133     @Override
134     public boolean isIncludingEmptyDirectories()
135     {
136         return fileSet.isIncludingEmptyDirectories();
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public boolean isUsingDefaultExcludes()
144     {
145         return fileSet.isUsingDefaultExcludes();
146     }
147 
148     @Override
149     public InputStreamTransformer getStreamTransformer()
150     {
151         return fileSet.getStreamTransformer();
152     }
153 
154     @Override
155     public FileMapper[] getFileMappers()
156     {
157         return EMPTY_FILE_MAPPERS_ARRAY;
158     }
159 }