1 | |
package org.apache.maven.shared.io.scan.mapping; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.Collections; |
24 | |
import java.util.HashSet; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.Set; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public final class SuffixMapping |
33 | |
implements SourceMapping |
34 | |
{ |
35 | |
private final String sourceSuffix; |
36 | |
|
37 | |
private final Set targetSuffixes; |
38 | |
|
39 | |
public SuffixMapping( String sourceSuffix, String targetSuffix ) |
40 | 2 | { |
41 | 2 | this.sourceSuffix = sourceSuffix; |
42 | |
|
43 | 2 | this.targetSuffixes = Collections.singleton( targetSuffix ); |
44 | 2 | } |
45 | |
|
46 | |
public SuffixMapping( String sourceSuffix, Set targetSuffixes ) |
47 | 2 | { |
48 | 2 | this.sourceSuffix = sourceSuffix; |
49 | |
|
50 | 2 | this.targetSuffixes = Collections.unmodifiableSet( targetSuffixes ); |
51 | 2 | } |
52 | |
|
53 | |
public Set getTargetFiles( File targetDir, String source ) |
54 | |
{ |
55 | 4 | Set targetFiles = new HashSet(); |
56 | |
|
57 | 4 | if ( source.endsWith( sourceSuffix ) ) |
58 | |
{ |
59 | 2 | String base = source.substring( 0, source.length() - sourceSuffix.length() ); |
60 | |
|
61 | 2 | for ( Iterator it = targetSuffixes.iterator(); it.hasNext(); ) |
62 | |
{ |
63 | 3 | String suffix = (String) it.next(); |
64 | |
|
65 | 3 | targetFiles.add( new File( targetDir, base + suffix ) ); |
66 | 3 | } |
67 | |
} |
68 | |
|
69 | 4 | return targetFiles; |
70 | |
} |
71 | |
} |