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.FileSet;
23  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
24  
25  import java.io.File;
26  
27  /**
28   * @version $Id: PrefixedFileSet.java 999628 2010-09-21 20:41:59Z jdcasey $
29   */
30  public class PrefixedFileSet
31      implements FileSet
32  {
33  
34      private final String rootPrefix;
35  
36      private final FileSet fileSet;
37  
38      private final FileSelector[] selectors;
39  
40      public PrefixedFileSet( final FileSet fileSet, final String rootPrefix, final FileSelector[] selectors )
41      {
42          this.fileSet = fileSet;
43          this.selectors = selectors;
44  
45          if ( rootPrefix.length() > 0 && !rootPrefix.endsWith( "/" ) )
46          {
47              this.rootPrefix = rootPrefix + "/";
48          }
49          else
50          {
51              this.rootPrefix = rootPrefix;
52          }
53      }
54  
55      public String[] getExcludes()
56      {
57          return fileSet.getExcludes();
58      }
59  
60      public FileSelector[] getFileSelectors()
61      {
62          FileSelector[] sel = fileSet.getFileSelectors();
63          if ( ( sel != null ) && ( selectors != null ) )
64          {
65              final FileSelector[] temp = new FileSelector[sel.length + selectors.length];
66  
67              System.arraycopy( sel, 0, temp, 0, sel.length );
68              System.arraycopy( selectors, 0, temp, sel.length, selectors.length );
69  
70              sel = temp;
71          }
72          else if ( ( sel == null ) && ( selectors != null ) )
73          {
74              sel = selectors;
75          }
76  
77          return sel;
78      }
79  
80      public String[] getIncludes()
81      {
82          return fileSet.getIncludes();
83      }
84  
85      public String getPrefix()
86      {
87          String prefix = fileSet.getPrefix();
88          if ( prefix == null )
89          {
90              return rootPrefix;
91          }
92  
93          if ( prefix.startsWith( "/" ) )
94          {
95              if ( prefix.length() > 1 )
96              {
97                  prefix = prefix.substring( 1 );
98              }
99              else
100             {
101                 prefix = "";
102             }
103         }
104 
105         return rootPrefix + prefix;
106     }
107 
108     public boolean isCaseSensitive()
109     {
110         return fileSet.isCaseSensitive();
111     }
112 
113     public boolean isIncludingEmptyDirectories()
114     {
115         return fileSet.isIncludingEmptyDirectories();
116     }
117 
118     public boolean isUsingDefaultExcludes()
119     {
120         return fileSet.isUsingDefaultExcludes();
121     }
122 
123     public File getDirectory()
124     {
125         return fileSet.getDirectory();
126     }
127 
128 }