1 package org.apache.maven.shared.model.fileset.mappers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public class GlobPatternMapper
37 implements FileNameMapper
38 {
39
40
41
42 protected String fromPrefix = null;
43
44
45
46
47 protected String fromPostfix = null;
48
49
50
51
52 protected int prefixLength;
53
54
55
56
57 protected int postfixLength;
58
59
60
61
62 protected String toPrefix = null;
63
64
65
66
67 protected String toPostfix = null;
68
69 private boolean handleDirSep = false;
70
71 private boolean caseSensitive = true;
72
73
74
75
76
77
78 public void setHandleDirSep( boolean handleDirSep )
79 {
80 this.handleDirSep = handleDirSep;
81 }
82
83
84
85
86
87
88
89 public void setCaseSensitive( boolean caseSensitive )
90 {
91 this.caseSensitive = caseSensitive;
92 }
93
94
95 public void setFrom( String from )
96 {
97 int index = from.lastIndexOf( "*" );
98 if ( index == -1 )
99 {
100 fromPrefix = from;
101 fromPostfix = "";
102 }
103 else
104 {
105 fromPrefix = from.substring( 0, index );
106 fromPostfix = from.substring( index + 1 );
107 }
108 prefixLength = fromPrefix.length();
109 postfixLength = fromPostfix.length();
110 }
111
112
113 public void setTo( String to )
114 {
115 int index = to.lastIndexOf( "*" );
116 if ( index == -1 )
117 {
118 toPrefix = to;
119 toPostfix = "";
120 }
121 else
122 {
123 toPrefix = to.substring( 0, index );
124 toPostfix = to.substring( index + 1 );
125 }
126 }
127
128
129 public String mapFileName( String sourceFileName )
130 {
131 if ( fromPrefix == null || !modifyName( sourceFileName ).startsWith( modifyName( fromPrefix ) )
132 || !modifyName( sourceFileName ).endsWith( modifyName( fromPostfix ) ) )
133 {
134 return null;
135 }
136 return new String( toPrefix + extractVariablePart( sourceFileName ) + toPostfix );
137 }
138
139
140
141
142
143
144
145 protected String extractVariablePart( String name )
146 {
147 return name.substring( prefixLength, name.length() - postfixLength );
148 }
149
150
151
152
153
154
155 private String modifyName( String name )
156 {
157 if ( !caseSensitive )
158 {
159 name = name.toLowerCase();
160 }
161 if ( handleDirSep )
162 {
163 if ( name.indexOf( '\\' ) != -1 )
164 {
165 name = name.replace( '\\', '/' );
166 }
167 }
168 return name;
169 }
170 }