001package org.apache.maven.scm.provider.cvslib;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import junit.framework.Assert;
023import org.apache.maven.scm.ScmTestCase;
024import org.codehaus.plexus.PlexusTestCase;
025import org.codehaus.plexus.util.FileUtils;
026
027import java.io.File;
028import java.io.IOException;
029
030/**
031 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
032 *
033 */
034public final class CvsScmTestUtils
035{
036    /** 'cvs' command line */
037    public static final String CVS_COMMAND_LINE = "cvs";
038
039    private CvsScmTestUtils()
040    {
041    }
042
043    public static String getScmUrl( File repository, String module )
044    {
045        return "scm:cvs|local|" + repository + "|" + module;
046    }
047
048    public static void executeCVS( File workingDirectory, String arguments )
049        throws Exception
050    {
051        ScmTestCase.execute( workingDirectory, CVS_COMMAND_LINE, arguments );
052    }
053
054    public static void initRepo( File repository, File workingDirectory, File assertionDirectory )
055        throws IOException
056    {
057        initRepo( "src/test/repository/", repository, workingDirectory );
058
059        FileUtils.deleteDirectory( assertionDirectory );
060
061        Assert.assertTrue( assertionDirectory.mkdirs() );
062    }
063
064    public static void initRepo( String source, File repository, File workingDirectory )
065        throws IOException
066    {
067        // Copy the repository to target
068        File src = PlexusTestCase.getTestFile( source );
069
070        FileUtils.deleteDirectory( repository );
071
072        Assert.assertTrue( repository.mkdirs() );
073
074        FileUtils.copyDirectoryStructure( src, repository );
075
076        FileUtils.deleteDirectory( workingDirectory );
077
078        Assert.assertTrue( workingDirectory.mkdirs() );
079    }
080}