1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.assembly.archive.archiver;
20
21 import java.io.File;
22
23 import org.codehaus.plexus.archiver.FileSet;
24 import org.codehaus.plexus.components.io.filemappers.FileMapper;
25 import org.codehaus.plexus.components.io.fileselectors.FileSelector;
26 import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
27
28
29
30
31 class PrefixedFileSet implements FileSet {
32 private static final FileMapper[] EMPTY_FILE_MAPPERS_ARRAY = new FileMapper[0];
33
34 private final String rootPrefix;
35
36 private final FileSet fileSet;
37
38 private final FileSelector[] selectors;
39
40
41
42
43
44
45 PrefixedFileSet(final FileSet fileSet, final String rootPrefix, final FileSelector[] selectors) {
46 this.fileSet = fileSet;
47 this.selectors = selectors;
48
49 if (rootPrefix.length() > 0 && !rootPrefix.endsWith("/")) {
50 this.rootPrefix = rootPrefix + "/";
51 } else {
52 this.rootPrefix = rootPrefix;
53 }
54 }
55
56
57
58
59 static FileSelector[] combineSelectors(FileSelector[] first, FileSelector[] second) {
60 if ((first != null) && (second != null)) {
61 final FileSelector[] temp = new FileSelector[first.length + second.length];
62
63 System.arraycopy(first, 0, temp, 0, first.length);
64 System.arraycopy(second, 0, temp, first.length, second.length);
65
66 first = temp;
67 } else if ((first == null) && (second != null)) {
68 first = second;
69 }
70
71 return first;
72 }
73
74
75
76
77 @Override
78 public String[] getExcludes() {
79 return fileSet.getExcludes();
80 }
81
82
83
84
85 @Override
86 public FileSelector[] getFileSelectors() {
87 FileSelector[] sel = fileSet.getFileSelectors();
88 return combineSelectors(sel, selectors);
89 }
90
91
92
93
94 @Override
95 public String[] getIncludes() {
96 return fileSet.getIncludes();
97 }
98
99
100
101
102 @Override
103 public String getPrefix() {
104 String prefix = fileSet.getPrefix();
105 if (prefix == null) {
106 return rootPrefix;
107 }
108
109 if (prefix.startsWith("/")) {
110 if (prefix.length() > 1) {
111 prefix = prefix.substring(1);
112 } else {
113 prefix = "";
114 }
115 }
116
117 return rootPrefix + prefix;
118 }
119
120
121
122
123 @Override
124 public boolean isCaseSensitive() {
125 return fileSet.isCaseSensitive();
126 }
127
128
129
130
131 @Override
132 public boolean isIncludingEmptyDirectories() {
133 return fileSet.isIncludingEmptyDirectories();
134 }
135
136
137
138
139 @Override
140 public boolean isUsingDefaultExcludes() {
141 return fileSet.isUsingDefaultExcludes();
142 }
143
144
145
146
147 @Override
148 public File getDirectory() {
149 return fileSet.getDirectory();
150 }
151
152 @Override
153 public InputStreamTransformer getStreamTransformer() {
154 return fileSet.getStreamTransformer();
155 }
156
157 @Override
158 public FileMapper[] getFileMappers() {
159 return EMPTY_FILE_MAPPERS_ARRAY;
160 }
161 }