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.io.IOException;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.codehaus.plexus.util.FileUtils;
25 import org.kuali.common.util.Assert;
26 import org.kuali.common.util.CollectionUtils;
27 import org.kuali.common.util.FileSystemUtils;
28 import org.kuali.common.util.LocationUtils;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35 @Deprecated
36 public class CopyFilePatternsExecutable implements Executable {
37
38 private static final Logger logger = LoggerFactory.getLogger(CopyFilePatternsExecutable.class);
39
40 public static final List<String> DEFAULT_INCLUDES = FileSystemUtils.DEFAULT_RECURSIVE_INCLUDES;
41 public static final List<String> DEFAULT_EXCLUDES = new ArrayList<String>();
42
43 List<String> includes = DEFAULT_INCLUDES;
44 List<String> excludes = DEFAULT_EXCLUDES;
45
46 File srcDir;
47 File dstDir;
48 File relativeDir;
49 boolean skip;
50
51 @Override
52 public void execute() {
53
54 if (skip) {
55 return;
56 }
57
58
59 Assert.notNull(srcDir, "srcDir is null");
60 Assert.notNull(dstDir, "dstDir is null");
61
62
63 Assert.isExistingDir(srcDir, "srcDir is not an existing directory");
64
65 try {
66
67 String includesCSV = StringUtils.trimToNull(CollectionUtils.getCSV(includes));
68 String excludesCSV = StringUtils.trimToNull(CollectionUtils.getCSV(excludes));
69
70
71 FileUtils.forceMkdir(dstDir);
72
73
74 logCopy();
75
76
77 FileUtils.copyDirectory(srcDir, dstDir, includesCSV, excludesCSV);
78 } catch (IOException e) {
79 throw new IllegalStateException("Unexpected IO error", e);
80 }
81
82 }
83
84 protected void logCopy() {
85 String path = FileSystemUtils.getRelativePathQuietly(relativeDir, dstDir);
86 Object[] args = { path, org.kuali.common.util.LoggerUtils.getLogMsg(includes, excludes) };
87 logger.debug("srcDir - [{}]", LocationUtils.getCanonicalPath(srcDir));
88 logger.info("Copying to - [{}] - {}", args);
89 }
90
91 public List<String> getIncludes() {
92 return includes;
93 }
94
95 public void setIncludes(List<String> includes) {
96 this.includes = includes;
97 }
98
99 public List<String> getExcludes() {
100 return excludes;
101 }
102
103 public void setExcludes(List<String> excludes) {
104 this.excludes = excludes;
105 }
106
107 public File getSrcDir() {
108 return srcDir;
109 }
110
111 public void setSrcDir(File srcDir) {
112 this.srcDir = srcDir;
113 }
114
115 public File getDstDir() {
116 return dstDir;
117 }
118
119 public void setDstDir(File dstDir) {
120 this.dstDir = dstDir;
121 }
122
123 public File getRelativeDir() {
124 return relativeDir;
125 }
126
127 public void setRelativeDir(File relativeDir) {
128 this.relativeDir = relativeDir;
129 }
130
131 public boolean isSkip() {
132 return skip;
133 }
134
135 public void setSkip(boolean skip) {
136 this.skip = skip;
137 }
138 }