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 import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
25
26 import java.io.File;
27
28
29
30
31 class PrefixedFileSet
32 implements FileSet
33 {
34
35 private final String rootPrefix;
36
37 private final FileSet fileSet;
38
39 private final FileSelector[] selectors;
40
41
42
43
44
45
46 public PrefixedFileSet( final FileSet fileSet, final String rootPrefix, final FileSelector[] selectors )
47 {
48 this.fileSet = fileSet;
49 this.selectors = selectors;
50
51 if ( rootPrefix.length() > 0 && !rootPrefix.endsWith( "/" ) )
52 {
53 this.rootPrefix = rootPrefix + "/";
54 }
55 else
56 {
57 this.rootPrefix = rootPrefix;
58 }
59 }
60
61
62
63
64 public String[] getExcludes()
65 {
66 return fileSet.getExcludes();
67 }
68
69
70
71
72 public FileSelector[] getFileSelectors()
73 {
74 FileSelector[] sel = fileSet.getFileSelectors();
75 final FileSelector[] selectors1 = selectors;
76 return combineSelectors( sel, selectors1 );
77 }
78
79
80
81
82 static FileSelector[] combineSelectors( FileSelector[] first, FileSelector[] second )
83 {
84 if ( ( first != null ) && ( second != null ) )
85 {
86 final FileSelector[] temp = new FileSelector[first.length + second.length];
87
88 System.arraycopy( first, 0, temp, 0, first.length );
89 System.arraycopy( second, 0, temp, first.length, second.length );
90
91 first = temp;
92 }
93 else if ( ( first == null ) && ( second != null ) )
94 {
95 first = second;
96 }
97
98 return first;
99 }
100
101
102
103
104 public String[] getIncludes()
105 {
106 return fileSet.getIncludes();
107 }
108
109
110
111
112 public String getPrefix()
113 {
114 String prefix = fileSet.getPrefix();
115 if ( prefix == null )
116 {
117 return rootPrefix;
118 }
119
120 if ( prefix.startsWith( "/" ) )
121 {
122 if ( prefix.length() > 1 )
123 {
124 prefix = prefix.substring( 1 );
125 }
126 else
127 {
128 prefix = "";
129 }
130 }
131
132 return rootPrefix + prefix;
133 }
134
135
136
137
138 public boolean isCaseSensitive()
139 {
140 return fileSet.isCaseSensitive();
141 }
142
143
144
145
146 public boolean isIncludingEmptyDirectories()
147 {
148 return fileSet.isIncludingEmptyDirectories();
149 }
150
151
152
153
154 public boolean isUsingDefaultExcludes()
155 {
156 return fileSet.isUsingDefaultExcludes();
157 }
158
159
160
161
162 public File getDirectory()
163 {
164 return fileSet.getDirectory();
165 }
166
167 public InputStreamTransformer getStreamTransformer()
168 {
169 return fileSet.getStreamTransformer();
170 }
171 }