1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.execute;
17
18 import java.io.File;
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.kuali.common.util.CollectionUtils;
23 import org.kuali.common.util.ComparisonResults;
24 import org.kuali.common.util.LocationUtils;
25 import org.kuali.common.util.PropertyUtils;
26 import org.kuali.common.util.SimpleScanner;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.util.Assert;
30
31
32
33
34
35
36
37 public class FileListComparisonExecutable implements Executable {
38
39 private static final Logger logger = LoggerFactory.getLogger(FileListComparisonExecutable.class);
40
41 private String newFilesBaseDir;
42 private String filePattern;
43 private String originalFilesBaseDir;
44 private List<String> propertyNames;
45 private Properties mavenProperties;
46
47 @Override
48 public void execute() {
49 Assert.notNull(mavenProperties);
50 Assert.notNull(propertyNames);
51 Assert.notNull(newFilesBaseDir);
52 Assert.notNull(originalFilesBaseDir);
53 Assert.notNull(filePattern);
54
55 logger.info("Starting File List Comparison");
56 logger.info("Original files dir: " + originalFilesBaseDir);
57 logger.info("New files dir: " + LocationUtils.getCanonicalPath(new File(newFilesBaseDir)));
58 logger.info("File pattern: " + filePattern);
59 logger.info("Property names: " + propertyNames);
60
61 List<String> filePatterns = CollectionUtils.getTrimmedListFromCSV(filePattern);
62 String[] includesArray = filePatterns.toArray(new String[filePatterns.size()]);
63
64 SimpleScanner scanner = new SimpleScanner();
65 scanner.setBasedir(newFilesBaseDir);
66 scanner.setIncludes(includesArray);
67
68 List<String> newLocations = LocationUtils.getAbsolutePaths(scanner.getFiles());
69 List<String> newFileNames = LocationUtils.getFilenames(newLocations);
70
71 scanner = new SimpleScanner();
72 scanner.setBasedir(originalFilesBaseDir);
73 scanner.setIncludes(includesArray);
74
75 List<String> originalLocations = LocationUtils.getAbsolutePaths(scanner.getFiles());
76 List<String> originalFileNames = LocationUtils.getFilenames(originalLocations);
77
78 ComparisonResults comparison = LocationUtils.getLocationListComparison(newFileNames, originalFileNames);
79
80 logger.info("Added {} files.", comparison.getAdded().size());
81 logger.info("Updated {} existing files.", comparison.getSame().size());
82 logger.info("Deleted {} files.", comparison.getDeleted().size());
83
84 PropertyUtils.addListComparisonProperties(mavenProperties, comparison, propertyNames);
85 }
86
87 public String getFilePattern() {
88 return filePattern;
89 }
90
91 public void setFilePattern(String filePattern) {
92 this.filePattern = filePattern;
93 }
94
95 public Properties getMavenProperties() {
96 return mavenProperties;
97 }
98
99 public void setMavenProperties(Properties mavenProperties) {
100 this.mavenProperties = mavenProperties;
101 }
102
103 public String getNewFilesBaseDir() {
104 return newFilesBaseDir;
105 }
106
107 public void setNewFilesBaseDir(String newFilesBaseDir) {
108 this.newFilesBaseDir = newFilesBaseDir;
109 }
110
111 public String getOriginalFilesBaseDir() {
112 return originalFilesBaseDir;
113 }
114
115 public void setOriginalFilesBaseDir(String originalFilesBaseDir) {
116 this.originalFilesBaseDir = originalFilesBaseDir;
117 }
118
119 public List<String> getPropertyNames() {
120 return propertyNames;
121 }
122
123 public void setPropertyNames(List<String> propertyNames) {
124 this.propertyNames = propertyNames;
125 }
126 }