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  
28  /**
29   * @version $Id: PrefixedArchivedFileSet.html 1000516 2016-11-05 01:04:48Z olamy $
30   */
31  class PrefixedArchivedFileSet
32      implements ArchivedFileSet
33  {
34  
35      private final String rootPrefix;
36  
37      private final ArchivedFileSet fileSet;
38  
39      private final FileSelector[] selectors;
40  
41      /**
42       * @param fileSet    The archived file set.
43       * @param rootPrefix The root prefix.
44       * @param selectors  The file selectors.
45       */
46      public PrefixedArchivedFileSet( ArchivedFileSet fileSet, String rootPrefix, FileSelector[] selectors )
47      {
48          this.fileSet = fileSet;
49          this.selectors = selectors;
50  
51          if ( rootPrefix.length() > 0 && !rootPrefix.endsWith( "/" ) )
52          {
53              this.rootPrefix = rootPrefix + "/";
54          }
55          else
56          {
57              this.rootPrefix = rootPrefix;
58          }
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      public File getArchive()
66      {
67          return fileSet.getArchive();
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      public String[] getExcludes()
75      {
76          return fileSet.getExcludes();
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public FileSelector[] getFileSelectors()
84      {
85          return PrefixedFileSet.combineSelectors( fileSet.getFileSelectors(), selectors );
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public String[] getIncludes()
93      {
94          return fileSet.getIncludes();
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public String getPrefix()
102     {
103         String prefix = fileSet.getPrefix();
104         if ( prefix.startsWith( "/" ) )
105         {
106             if ( prefix.length() > 1 )
107             {
108                 prefix = prefix.substring( 1 );
109             }
110             else
111             {
112                 prefix = "";
113             }
114         }
115 
116         return rootPrefix + prefix;
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public boolean isCaseSensitive()
124     {
125         return fileSet.isCaseSensitive();
126     }
127 
128     /**
129      * {@inheritDoc}
130      */
131     @Override
132     public boolean isIncludingEmptyDirectories()
133     {
134         return fileSet.isIncludingEmptyDirectories();
135     }
136 
137     /**
138      * {@inheritDoc}
139      */
140     @Override
141     public boolean isUsingDefaultExcludes()
142     {
143         return fileSet.isUsingDefaultExcludes();
144     }
145 
146     @Override
147     public InputStreamTransformer getStreamTransformer()
148     {
149         return fileSet.getStreamTransformer();
150     }
151 
152 }