1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.shell;
26
27 import java.io.File;
28
29 import org.tmatesoft.svn.core.SVNDepth;
30 import org.tmatesoft.svn.core.SVNException;
31 import org.tmatesoft.svn.core.SVNPropertyValue;
32 import org.tmatesoft.svn.core.wc.SVNClientManager;
33 import org.tmatesoft.svn.core.wc.SVNWCClient;
34 import org.xerial.util.StringUtil;
35 import org.xerial.util.log.Logger;
36
37
38
39
40
41
42
43 public class SVNAdd extends UTGBShellCommand {
44
45 private static Logger _logger = Logger.getLogger(SVNAdd.class);
46
47 public SVNAdd() {
48
49 }
50
51 private static String[] addTargetFiles = { "README", "pom.xml" };
52 private static String[] addTargetDirs = { "config", "eclipse", "src" };
53 private static String[] ignoreTargetFiles = { "target" };
54
55 SVNClientManager svnClientManager = null;
56 SVNWCClient workingCopyClient = null;
57
58 @Override
59 public void execute(String[] args) throws Exception {
60
61 if (!isInProjectRoot())
62 throw new UTGBShellException("must be in the project root");
63
64 svnClientManager = SVNClientManager.newInstance();
65 workingCopyClient = svnClientManager.getWCClient();
66
67
68
69 svnAddDir(globalOption.projectDir != null ? globalOption.projectDir : "", false);
70
71
72 for (String target : addTargetDirs) {
73
74 svnAddDir(target, true);
75 }
76 for (String target : addTargetFiles) {
77 svnAddFile(target);
78 }
79
80
81 String ignoreTarget = StringUtil.join(ignoreTargetFiles, "\n");
82 svnIgnore(".", ignoreTarget, false);
83
84
85 svnAddDir("db", false);
86 svnIgnore("db", "*.db", false);
87
88
89
90
91
92
93
94 svnAddDir("war", false);
95 svnAddDir("war/WEB-INF", true);
96 svnIgnore("war", "utgb", false);
97
98 }
99
100 public void svnAddDir(String dir, boolean isRecursive) throws SVNException {
101 assert (workingCopyClient != null);
102 _logger.info("svn add " + dir);
103 File f = new File(dir);
104 boolean createDir = !f.exists();
105
106
107 workingCopyClient.doAdd(f, true, createDir, false, SVNDepth.fromRecurse(isRecursive), false, true);
108
109 }
110
111 public void svnAddFile(String file) throws SVNException {
112 assert (workingCopyClient != null);
113 _logger.info("svn add " + file);
114 File f = new File(file);
115
116 workingCopyClient.doAdd(new File(file), true, false, false, SVNDepth.fromRecurse(false), false, false);
117 }
118
119 public void svnIgnore(String file, String ignoreTargets, boolean isRecursive) throws SVNException {
120 assert (workingCopyClient != null);
121 _logger.info("set svn:ignore on directory =" + file + ", targets = " + ignoreTargets);
122
123
124 workingCopyClient.doSetProperty(new File(file), "svn:ignore", SVNPropertyValue.create(ignoreTargets), false, SVNDepth.fromRecurse(isRecursive), null,
125 null);
126 }
127
128 @Override
129 public String name() {
130 return "svn-add";
131 }
132
133 public String getOneLinerDescription() {
134 return "add the current project to the SVN repostiory";
135 }
136
137 }