001/** 002 * Copyright 2010-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.scm; 017 018import java.io.File; 019import java.util.ArrayList; 020import java.util.Arrays; 021import java.util.List; 022 023import org.kuali.common.util.Assert; 024import org.kuali.common.util.CollectionUtils; 025import org.kuali.common.util.LocationUtils; 026import org.kuali.common.util.service.DefaultExecService; 027 028public class SvnService extends DefaultExecService implements ScmService { 029 030 private static final String SVN = "svn"; 031 032 @Override 033 public void version() { 034 executeAndValidate(SVN, Arrays.asList("--version")); 035 } 036 037 @Override 038 public void add(List<File> paths) { 039 if (CollectionUtils.isEmpty(paths)) { 040 // Nothing to do 041 return; 042 } 043 String command = "add"; 044 List<String> cpaths = LocationUtils.getCanonicalPaths(paths); 045 List<String> options = Arrays.asList("--force", "--parents", "--depth", "infinity"); 046 047 List<String> arguments = new ArrayList<String>(); 048 arguments.add(command); 049 arguments.addAll(cpaths); 050 arguments.addAll(options); 051 052 executeAndValidate(SVN, arguments); 053 } 054 055 @Override 056 public void delete(List<File> paths) { 057 if (CollectionUtils.isEmpty(paths)) { 058 // Nothing to do 059 return; 060 } 061 String command = "delete"; 062 List<String> cpaths = LocationUtils.getCanonicalPaths(paths); 063 List<String> options = Arrays.asList("--force"); 064 065 List<String> arguments = new ArrayList<String>(); 066 arguments.add(command); 067 arguments.addAll(cpaths); 068 arguments.addAll(options); 069 070 executeAndValidate(SVN, arguments); 071 } 072 073 @Override 074 public void commit(List<File> paths, String message) { 075 if (CollectionUtils.isEmpty(paths)) { 076 // Nothing to do 077 return; 078 } 079 Assert.noBlanks("Commit message is blank", message); 080 String command = "commit"; 081 List<String> cpaths = LocationUtils.getCanonicalPaths(paths); 082 List<String> options = Arrays.asList("--depth", "infinity", "--message", message); 083 084 List<String> arguments = new ArrayList<String>(); 085 arguments.add(command); 086 arguments.addAll(cpaths); 087 arguments.addAll(options); 088 089 executeAndValidate(SVN, arguments); 090 } 091 092}