View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.service;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.List;
22  
23  import org.kuali.common.util.Assert;
24  import org.kuali.common.util.CollectionUtils;
25  import org.kuali.common.util.LocationUtils;
26  
27  public class SvnService extends DefaultExecService implements ScmService {
28  
29  	private static final String SVN = "svn";
30  
31  	@Override
32  	public void version() {
33  		executeAndValidate(SVN, Arrays.asList("--version"));
34  	}
35  
36  	@Override
37  	public void add(List<File> paths) {
38  		if (CollectionUtils.isEmpty(paths)) {
39  			// Nothing to do
40  			return;
41  		}
42  		String command = "add";
43  		List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
44  		List<String> options = Arrays.asList("--force", "--parents", "--depth", "infinity");
45  
46  		List<String> arguments = new ArrayList<String>();
47  		arguments.add(command);
48  		arguments.addAll(cpaths);
49  		arguments.addAll(options);
50  
51  		executeAndValidate(SVN, arguments);
52  	}
53  
54  	@Override
55  	public void delete(List<File> paths) {
56  		if (CollectionUtils.isEmpty(paths)) {
57  			// Nothing to do
58  			return;
59  		}
60  		String command = "delete";
61  		List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
62  		List<String> options = Arrays.asList("--force");
63  
64  		List<String> arguments = new ArrayList<String>();
65  		arguments.add(command);
66  		arguments.addAll(cpaths);
67  		arguments.addAll(options);
68  
69  		executeAndValidate(SVN, arguments);
70  	}
71  
72  	@Override
73  	public void commit(List<File> paths, String message) {
74  		if (CollectionUtils.isEmpty(paths)) {
75  			// Nothing to do
76  			return;
77  		}
78  		Assert.notBlank(message, "Commit message is blank");
79  		String command = "commit";
80  		List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
81  		List<String> options = Arrays.asList("--depth", "infinity", "--message", message);
82  
83  		List<String> arguments = new ArrayList<String>();
84  		arguments.add(command);
85  		arguments.addAll(cpaths);
86  		arguments.addAll(options);
87  
88  		executeAndValidate(SVN, arguments);
89  	}
90  
91  }