1 package org.apache.maven.plugin.assembly.archive.archiver;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }