1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package nl.geodienstencentrum.maven.plugin.sass;
21
22 import java.io.File;
23 import java.util.LinkedHashMap;
24 import java.util.Map;
25
26 import org.apache.commons.io.FilenameUtils;
27 import org.apache.maven.model.FileSet;
28 import org.apache.maven.plugin.logging.Log;
29 import org.codehaus.plexus.util.DirectoryScanner;
30 import org.codehaus.plexus.util.StringUtils;
31
32
33
34
35 public class Resource {
36
37
38 protected FileSet source;
39
40
41
42
43
44
45
46
47 protected String relativeOutputDirectory;
48
49
50 protected File destination;
51
52
53
54
55
56
57
58
59
60 public Map<String, String> getDirectoriesAndDestinations(final Log log) {
61 final File sourceDirectory = new File(this.source.getDirectory());
62 final Map<String, String> result = new LinkedHashMap<>();
63
64 if (!sourceDirectory.exists()) {
65 log.error("Specified sourcedirectory (" + sourceDirectory
66 + ") does not exist.");
67 return result;
68 }
69
70
71 final DirectoryScanner scanner = new DirectoryScanner();
72 scanner.setBasedir(sourceDirectory);
73 scanner.setIncludes(this.source.getIncludes().toArray(
74 new String[this.source.getIncludes().size()]));
75 scanner.setExcludes(this.source.getExcludes().toArray(
76 new String[this.source.getExcludes().size()]));
77
78 scanner.addDefaultExcludes();
79 scanner.scan();
80
81 result.put(FilenameUtils.separatorsToUnix(sourceDirectory.toString()),
82 FilenameUtils.separatorsToUnix(this.destination.toString()));
83
84 for (final String included : scanner.getIncludedDirectories()) {
85 if (!included.isEmpty()) {
86 final String subdir = StringUtils.difference(
87 sourceDirectory.toString(), included);
88
89 final File sourceDir = new File(sourceDirectory, included);
90
91 File destDir = new File(this.destination, subdir);
92 if (this.relativeOutputDirectory != null
93 && !this.relativeOutputDirectory.isEmpty()) {
94 destDir = new File(destDir, this.relativeOutputDirectory);
95 }
96
97 result.put(
98 FilenameUtils.separatorsToUnix(sourceDir.toString()),
99 FilenameUtils.separatorsToUnix(destDir.toString()));
100 }
101 }
102
103 return result;
104 }
105 }