001    package org.kuali.common.util.service;
002    
003    import java.io.File;
004    import java.util.ArrayList;
005    import java.util.Arrays;
006    import java.util.List;
007    
008    import org.kuali.common.util.Assert;
009    import org.kuali.common.util.CollectionUtils;
010    import org.kuali.common.util.LocationUtils;
011    
012    public class SubversionService extends DefaultExecService implements ScmService {
013    
014            private static final String SVN = "svn";
015    
016            @Override
017            public void add(List<File> paths) {
018                    if (CollectionUtils.isEmpty(paths)) {
019                            // Nothing to do
020                            return;
021                    }
022                    String command = "add";
023                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
024                    List<String> options = Arrays.asList("--force", "--parents", "--depth", "infinity");
025    
026                    List<String> arguments = new ArrayList<String>();
027                    arguments.add(command);
028                    arguments.addAll(cpaths);
029                    arguments.addAll(options);
030    
031                    executeAndValidate(SVN, arguments);
032            }
033    
034            @Override
035            public void delete(List<File> paths) {
036                    if (CollectionUtils.isEmpty(paths)) {
037                            // Nothing to do
038                            return;
039                    }
040                    String command = "delete";
041                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
042                    List<String> options = Arrays.asList("--force");
043    
044                    List<String> arguments = new ArrayList<String>();
045                    arguments.add(command);
046                    arguments.addAll(cpaths);
047                    arguments.addAll(options);
048    
049                    executeAndValidate(SVN, arguments);
050            }
051    
052            @Override
053            public void commit(List<File> paths, String message) {
054                    if (CollectionUtils.isEmpty(paths)) {
055                            // Nothing to do
056                            return;
057                    }
058                    Assert.notBlank(message, "Commit message is blank");
059                    String command = "commit";
060                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
061                    List<String> options = Arrays.asList("--depth", "infinity", "--message", message);
062    
063                    List<String> arguments = new ArrayList<String>();
064                    arguments.add(command);
065                    arguments.addAll(cpaths);
066                    arguments.addAll(options);
067    
068                    executeAndValidate(SVN, arguments);
069            }
070    
071    }