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.ArrayList;
20 import java.util.List;
21
22 import org.kuali.common.util.Assert;
23 import org.kuali.common.util.CollectionUtils;
24 import org.kuali.common.util.LocationUtils;
25 import org.kuali.common.util.SimpleScanner;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32
33
34
35
36 @Deprecated
37 public class FileCopyExecutable implements Executable {
38
39 private static final Logger logger = LoggerFactory.getLogger(FileCopyExecutable.class);
40
41 private String sourceDir;
42 private String filePatterns;
43 private String destinationDir;
44
45 @Override
46 public void execute() {
47 Assert.isTrue(LocationUtils.exists(sourceDir));
48 Assert.notNull(destinationDir);
49 Assert.notNull(filePatterns);
50
51 String sourceDirPath = LocationUtils.getCanonicalPath(new File(sourceDir));
52
53 logger.info("Starting File Copy");
54 logger.info("From: " + sourceDirPath);
55 logger.info("To: " + destinationDir);
56 logger.info("Using patterns: " + filePatterns);
57
58 List<String> patterns = CollectionUtils.getTrimmedListFromCSV(filePatterns);
59
60 SimpleScanner scanner = new SimpleScanner();
61 scanner.setBasedir(sourceDir);
62 scanner.setIncludes(patterns.toArray(new String[patterns.size()]));
63
64 List<File> sourceFiles = scanner.getFiles();
65 logger.info("Found " + sourceFiles.size() + " matching source files.");
66
67 List<String> sourceLocations = new ArrayList<String>(sourceFiles.size());
68 List<File> destinationFiles = new ArrayList<File>(sourceFiles.size());
69 for (File f : sourceFiles) {
70 String sourcePath = LocationUtils.getCanonicalPath(f);
71 sourceLocations.add(sourcePath);
72
73 String destinationPath = sourcePath.replace(sourceDirPath, (destinationDir + File.separator));
74 destinationFiles.add(new File(destinationPath));
75 }
76
77 LocationUtils.copyLocationsToFiles(sourceLocations, destinationFiles);
78
79 logger.info("File Copy Complete");
80 }
81
82 public String getDestinationDir() {
83 return destinationDir;
84 }
85
86 public void setDestinationDir(String destinationDir) {
87 this.destinationDir = destinationDir;
88 }
89
90 public String getFilePatterns() {
91 return filePatterns;
92 }
93
94 public void setFilePatterns(String filePatterns) {
95 this.filePatterns = filePatterns;
96 }
97
98 public String getSourceDir() {
99 return sourceDir;
100 }
101
102 public void setSourceDir(String sourceDir) {
103 this.sourceDir = sourceDir;
104 }
105 }