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     */
016    package org.kuali.common.util.service;
017    
018    import java.io.File;
019    import java.util.ArrayList;
020    import java.util.Arrays;
021    import java.util.List;
022    
023    import org.kuali.common.util.Assert;
024    import org.kuali.common.util.CollectionUtils;
025    import org.kuali.common.util.LocationUtils;
026    
027    public class SvnService extends DefaultExecService implements ScmService {
028    
029            private static final String SVN = "svn";
030    
031            @Override
032            public void version() {
033                    executeAndValidate(SVN, Arrays.asList("--version"));
034            }
035    
036            @Override
037            public void add(List<File> paths) {
038                    if (CollectionUtils.isEmpty(paths)) {
039                            // Nothing to do
040                            return;
041                    }
042                    String command = "add";
043                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
044                    List<String> options = Arrays.asList("--force", "--parents", "--depth", "infinity");
045    
046                    List<String> arguments = new ArrayList<String>();
047                    arguments.add(command);
048                    arguments.addAll(cpaths);
049                    arguments.addAll(options);
050    
051                    executeAndValidate(SVN, arguments);
052            }
053    
054            @Override
055            public void delete(List<File> paths) {
056                    if (CollectionUtils.isEmpty(paths)) {
057                            // Nothing to do
058                            return;
059                    }
060                    String command = "delete";
061                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
062                    List<String> options = Arrays.asList("--force");
063    
064                    List<String> arguments = new ArrayList<String>();
065                    arguments.add(command);
066                    arguments.addAll(cpaths);
067                    arguments.addAll(options);
068    
069                    executeAndValidate(SVN, arguments);
070            }
071    
072            @Override
073            public void commit(List<File> paths, String message) {
074                    if (CollectionUtils.isEmpty(paths)) {
075                            // Nothing to do
076                            return;
077                    }
078                    Assert.notBlank(message, "Commit message is blank");
079                    String command = "commit";
080                    List<String> cpaths = LocationUtils.getCanonicalPaths(paths);
081                    List<String> options = Arrays.asList("--depth", "infinity", "--message", message);
082    
083                    List<String> arguments = new ArrayList<String>();
084                    arguments.add(command);
085                    arguments.addAll(cpaths);
086                    arguments.addAll(options);
087    
088                    executeAndValidate(SVN, arguments);
089            }
090    
091    }