1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import java.io.File;
19 import java.util.ArrayList;
20
21 import org.codehaus.plexus.util.StringUtils;
22 import org.kuali.common.util.scm.ScmRequest;
23 import org.kuali.common.util.service.ScmService;
24 import org.kuali.common.util.service.ScmType;
25 import org.kuali.common.util.service.SvnService;
26 import org.springframework.util.Assert;
27
28 public class ScmUtils {
29
30
31
32
33 @Deprecated
34 public static ScmService getScmService(String url) {
35 Assert.hasText(url, "URL has no text");
36
37 String[] tokens = StringUtils.split(url, ":");
38 String scmType = tokens[1].toUpperCase();
39 ScmType type = ScmType.valueOf(scmType);
40 switch (type) {
41 case SVN:
42 return new SvnService();
43 case GIT:
44 throw new IllegalArgumentException("GIT support is coming soon!");
45 default:
46 throw new IllegalArgumentException("SCM type [" + scmType + "] is unknown");
47 }
48 }
49
50 public static ScmRequest cloneOrNew(ScmRequest request) {
51 if (request == null) {
52 return new ScmRequest();
53 } else {
54 return clone(request);
55 }
56 }
57
58 public static ScmRequest clone(ScmRequest request) {
59 ScmRequest clone = new ScmRequest();
60 clone.setCommitMessage(request.getCommitMessage());
61
62 if (!CollectionUtils.isEmpty(request.getAdds())) {
63 clone.setAdds(new ArrayList<File>(request.getAdds()));
64 }
65
66 if (!CollectionUtils.isEmpty(request.getDeletes())) {
67 clone.setDeletes(new ArrayList<File>(request.getDeletes()));
68 }
69
70 if (!CollectionUtils.isEmpty(request.getCommits())) {
71 clone.setCommits(new ArrayList<File>(request.getCommits()));
72 }
73 return clone;
74 }
75
76 }