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;
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  	 * Use <code>ScmConfig</code> instead
32  	 */
33  	@Deprecated
34  	public static ScmService getScmService(String url) {
35  		Assert.hasText(url, "URL has no text");
36  		// scm:svn:https://svn.kuali.org/repos/student/trunk
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  }