View Javadoc
1   package org.apache.maven.plugin.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  import static org.apache.maven.plugin.assembly.archive.archiver.PrefixedFileSet.combineSelectors;
29  
30  /**
31   * @version $Id: PrefixedArchivedFileSet.java 1639422 2014-11-13 18:08:07Z krosenvold $
32   */
33  class PrefixedArchivedFileSet
34      implements ArchivedFileSet
35  {
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      public 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      public File getArchive()
67      {
68          return fileSet.getArchive();
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      public String[] getExcludes()
75      {
76          return fileSet.getExcludes();
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      public FileSelector[] getFileSelectors()
83      {
84          return combineSelectors( fileSet.getFileSelectors(), selectors );
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      public String[] getIncludes()
91      {
92          return fileSet.getIncludes();
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public String getPrefix()
99      {
100         String prefix = fileSet.getPrefix();
101         if ( prefix.startsWith( "/" ) )
102         {
103             if ( prefix.length() > 1 )
104             {
105                 prefix = prefix.substring( 1 );
106             }
107             else
108             {
109                 prefix = "";
110             }
111         }
112 
113         return rootPrefix + prefix;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public boolean isCaseSensitive()
120     {
121         return fileSet.isCaseSensitive();
122     }
123 
124     /**
125      * {@inheritDoc}
126      */
127     public boolean isIncludingEmptyDirectories()
128     {
129         return fileSet.isIncludingEmptyDirectories();
130     }
131 
132     /**
133      * {@inheritDoc}
134      */
135     public boolean isUsingDefaultExcludes()
136     {
137         return fileSet.isUsingDefaultExcludes();
138     }
139 
140     public InputStreamTransformer getStreamTransformer()
141     {
142         return fileSet.getStreamTransformer();
143     }
144 
145 }