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 static org.apache.maven.plugin.assembly.archive.archiver.PrefixedFileSet.combineSelectors;
23  
24  import org.codehaus.plexus.archiver.ArchivedFileSet;
25  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
26  import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
27  
28  import java.io.File;
29  
30  /**
31   * @version $Id: PrefixedArchivedFileSet.java 1633832 2014-10-23 15:03:47Z 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      /** {@inheritDoc} */
64      public File getArchive()
65      {
66          return fileSet.getArchive();
67      }
68  
69      /** {@inheritDoc} */
70      public String[] getExcludes()
71      {
72          return fileSet.getExcludes();
73      }
74  
75      /** {@inheritDoc} */
76      public FileSelector[] getFileSelectors()
77      {
78          return combineSelectors( fileSet.getFileSelectors(), selectors );
79      }
80  
81      /** {@inheritDoc} */
82      public String[] getIncludes()
83      {
84          return fileSet.getIncludes();
85      }
86  
87      /** {@inheritDoc} */
88      public String getPrefix()
89      {
90          String prefix = fileSet.getPrefix();
91          if ( prefix.startsWith( "/" ) )
92          {
93              if ( prefix.length() > 1 )
94              {
95                  prefix = prefix.substring( 1 );
96              }
97              else
98              {
99                  prefix = "";
100             }
101         }
102 
103         return rootPrefix + prefix;
104     }
105 
106     /** {@inheritDoc} */
107     public boolean isCaseSensitive()
108     {
109         return fileSet.isCaseSensitive();
110     }
111 
112     /** {@inheritDoc} */
113     public boolean isIncludingEmptyDirectories()
114     {
115         return fileSet.isIncludingEmptyDirectories();
116     }
117 
118     /** {@inheritDoc} */
119     public boolean isUsingDefaultExcludes()
120     {
121         return fileSet.isUsingDefaultExcludes();
122     }
123 
124     public InputStreamTransformer getStreamTransformer()
125     {
126         return fileSet.getStreamTransformer();
127     }
128 
129 }