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  
25  import java.io.File;
26  
27  /**
28   * @version $Id: PrefixedArchivedFileSet.java 727431 2008-12-17 16:38:37Z jdcasey $
29   */
30  public class PrefixedArchivedFileSet
31      implements ArchivedFileSet
32  {
33  
34      private final String rootPrefix;
35      private final ArchivedFileSet fileSet;
36      private final FileSelector[] selectors;
37  
38      public PrefixedArchivedFileSet( ArchivedFileSet fileSet, String rootPrefix, FileSelector[] selectors )
39      {
40          this.fileSet = fileSet;
41          this.selectors = selectors;
42  
43          if ( rootPrefix.length() > 0 && ! rootPrefix.endsWith( "/" ) )
44          {
45              this.rootPrefix = rootPrefix + "/";
46          }
47          else
48          {
49              this.rootPrefix = rootPrefix;
50          }
51      }
52  
53      public File getArchive()
54      {
55          return fileSet.getArchive();
56      }
57  
58      public String[] getExcludes()
59      {
60          return fileSet.getExcludes();
61      }
62  
63      public FileSelector[] getFileSelectors()
64      {
65          FileSelector[] sel = fileSet.getFileSelectors();
66          if ( ( sel != null ) && ( selectors != null ) )
67          {
68              FileSelector[] temp = new FileSelector[ sel.length + selectors.length ];
69  
70              System.arraycopy( sel, 0, temp, 0, sel.length );
71              System.arraycopy( selectors, 0, temp, sel.length, selectors.length );
72  
73              sel = temp;
74          }
75          else if ( ( sel == null ) && ( selectors != null ) )
76          {
77              sel = selectors;
78          }
79  
80          return sel;
81      }
82  
83      public String[] getIncludes()
84      {
85          return fileSet.getIncludes();
86      }
87  
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     public boolean isCaseSensitive()
107     {
108         return fileSet.isCaseSensitive();
109     }
110 
111     public boolean isIncludingEmptyDirectories()
112     {
113         return fileSet.isIncludingEmptyDirectories();
114     }
115 
116     public boolean isUsingDefaultExcludes()
117     {
118         return fileSet.isUsingDefaultExcludes();
119     }
120 
121 }