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.kuali.common.util.Assert;
24 import org.kuali.common.util.FileSystemUtils;
25 import org.kuali.common.util.SyncRequest;
26 import org.kuali.common.util.SyncResult;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 @Deprecated
31 public class SyncFilesExecutable implements Executable {
32
33 private static final Logger logger = LoggerFactory.getLogger(SyncFilesExecutable.class);
34
35 boolean skip;
36
37 boolean commitChanges;
38 org.kuali.common.util.service.ScmService service;
39 String message = "Automated update";
40 List<SyncRequest> requests;
41 List<File> commitPaths;
42
43 @Override
44 public void execute() {
45 if (skip) {
46 logger.info("Skipping file sync");
47 return;
48 }
49
50 Assert.notNull(requests);
51 Assert.notNull(service);
52 Assert.notNull(commitPaths);
53
54 List<File> adds = new ArrayList<File>();
55 List<File> deletes = new ArrayList<File>();
56
57 List<SyncResult> results = syncFiles();
58 for (SyncResult result : results) {
59 adds.addAll(result.getAdds());
60 deletes.addAll(result.getDeletes());
61 }
62
63 logger.info("---------- Sync results ----------");
64 logger.info("Files added - {}", adds.size());
65 logger.info("Files deleted - {}", deletes.size());
66 logger.info("---------- Sync results ----------");
67
68 if (commitChanges) {
69 service.add(adds);
70 service.delete(deletes);
71 service.commit(commitPaths, message);
72 } else {
73 logger.info("Skipping SCM commit");
74 }
75 }
76
77 public List<SyncResult> syncFiles() {
78 logger.info("Syncing {} requests", requests.size());
79 try {
80 return FileSystemUtils.syncFiles(requests);
81 } catch (IOException e) {
82 throw new IllegalStateException("Unexpected IO error", e);
83 }
84 }
85
86 public boolean isSkip() {
87 return skip;
88 }
89
90 public void setSkip(boolean skip) {
91 this.skip = skip;
92 }
93
94 public org.kuali.common.util.service.ScmService getService() {
95 return service;
96 }
97
98 public void setService(org.kuali.common.util.service.ScmService service) {
99 this.service = service;
100 }
101
102 public String getMessage() {
103 return message;
104 }
105
106 public void setMessage(String message) {
107 this.message = message;
108 }
109
110 public boolean isCommitChanges() {
111 return commitChanges;
112 }
113
114 public void setCommitChanges(boolean commitChanges) {
115 this.commitChanges = commitChanges;
116 }
117
118 public List<File> getCommitPaths() {
119 return commitPaths;
120 }
121
122 public void setCommitPaths(List<File> commitPaths) {
123 this.commitPaths = commitPaths;
124 }
125
126 public List<SyncRequest> getRequests() {
127 return requests;
128 }
129
130 public void setRequests(List<SyncRequest> requests) {
131 this.requests = requests;
132 }
133 }