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 import org.xerial.util.opt.OptionParser;
37 import org.xerial.util.opt.OptionParserException;
38
39
40
41
42
43
44
45 public class SVNAdd extends UTGBShellSubCommandBase {
46
47 private static Logger _logger = Logger.getLogger(SVNAdd.class);
48
49 private OptionParser optionParser = new OptionParser(this);
50
51 public SVNAdd() {
52
53 }
54
55 private static String[] addTargetFiles = { "README", "pom.xml" };
56 private static String[] addTargetDirs = { "config", "eclipse", "src" };
57 private static String[] ignoreTargetFiles = { "target", "gwt-home", "www", ".project", ".classpath" };
58
59 SVNClientManager svnClientManager = null;
60 SVNWCClient workingCopyClient = null;
61
62 @Override
63 public void execute(String[] args) throws UTGBShellException {
64
65 try {
66 optionParser.parse(args);
67
68 if (!isInProjectRoot())
69 throw new UTGBShellException("must be in the project root");
70
71 svnClientManager = SVNClientManager.newInstance();
72 workingCopyClient = svnClientManager.getWCClient();
73
74
75
76 svnAddDir(globalOption.projectDir, false);
77
78
79 for (String target : addTargetDirs) {
80
81 svnAddDir(target, true);
82 }
83 for (String target : addTargetFiles) {
84 svnAddFile(target);
85 }
86
87
88 String ignoreTarget = StringUtil.join(ignoreTargetFiles, "\n");
89 svnIgnore(".", ignoreTarget, false);
90
91
92 svnAddDir("db", false);
93 svnIgnore("db", "*.db", false);
94
95
96 svnAddDir("tomcat", false);
97 svnAddDir("tomcat/conf", true);
98 svnAddDir("tomcat/webapps", true);
99 svnIgnore("tomcat", "work", false);
100 }
101 catch (OptionParserException e) {
102 throw new UTGBShellException(e);
103 }
104 catch (SVNException e) {
105 throw new UTGBShellException(e);
106 }
107 }
108
109 public void svnAddDir(String dir, boolean isRecursive) throws SVNException {
110 assert (workingCopyClient != null);
111 _logger.info("svn add " + dir);
112 File f = new File(dir);
113 boolean createDir = !f.exists();
114
115
116 workingCopyClient.doAdd(f, true, createDir, false, SVNDepth.fromRecurse(isRecursive), false, true);
117
118 }
119
120 public void svnAddFile(String file) throws SVNException {
121 assert (workingCopyClient != null);
122 _logger.info("svn add " + file);
123 File f = new File(file);
124
125 workingCopyClient.doAdd(new File(file), true, false, false, SVNDepth.fromRecurse(false), false, false);
126 }
127
128 public void svnIgnore(String file, String ignoreTargets, boolean isRecursive) throws SVNException {
129 assert (workingCopyClient != null);
130 _logger.info("set svn:ignore on directory =" + file + ", targets = " + ignoreTargets);
131
132
133 workingCopyClient.doSetProperty(new File(file), "svn:ignore", SVNPropertyValue.create(ignoreTargets), false, SVNDepth.fromRecurse(isRecursive), null,
134 null);
135 }
136
137 @Override
138 public String name() {
139 return "svn-add";
140 }
141
142 public String getDetailedDescription() {
143 return loadUsage("help-svnadd.txt");
144 }
145
146 public String getOneLinerDescription() {
147 return "add the current project to the SVN repostiory";
148 }
149
150 public String getOptionList() {
151 return optionParser.getUsage();
152 }
153
154 }