001package org.apache.maven.scm.plugin; 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 org.apache.maven.plugin.testing.AbstractMojoTestCase; 023import org.apache.maven.scm.ScmTestCase; 024import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 025import org.codehaus.plexus.util.FileUtils; 026import org.codehaus.plexus.util.StringUtils; 027 028import java.io.File; 029 030/** 031 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 032 * 033 */ 034public class BranchMojoTest 035 extends AbstractMojoTestCase 036{ 037 File checkoutDir; 038 039 File repository; 040 041 protected void setUp() 042 throws Exception 043 { 044 super.setUp(); 045 046 checkoutDir = getTestFile( "target/checkout" ); 047 048 FileUtils.forceDelete( checkoutDir ); 049 050 repository = getTestFile( "target/repository" ); 051 052 FileUtils.forceDelete( repository ); 053 054 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) ) 055 { 056 System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE 057 + "' is not a system command. Ignored setUp." ); 058 return; 059 } 060 061 SvnScmTestUtils.initializeRepository( repository ); 062 063 CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( 064 "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) ); 065 checkoutMojo.setWorkingDirectory( new File( getBasedir() ) ); 066 067 String connectionUrl = checkoutMojo.getConnectionUrl(); 068 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 069 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 070 checkoutMojo.setConnectionUrl( connectionUrl ); 071 072 checkoutMojo.setCheckoutDirectory( checkoutDir ); 073 074 checkoutMojo.execute(); 075 } 076 077 public void testBranch() 078 throws Exception 079 { 080 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) ) 081 { 082 System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE 083 + "' is not a system command. Ignored " + getName() + "." ); 084 return; 085 } 086 087 BranchMojo mojo = 088 (BranchMojo) lookupMojo( "branch", getTestFile( "src/test/resources/mojos/branch/branch.xml" ) ); 089 mojo.setWorkingDirectory( checkoutDir ); 090 091 String connectionUrl = mojo.getConnectionUrl(); 092 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 093 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 094 mojo.setConnectionUrl( connectionUrl ); 095 096 mojo.execute(); 097 098 CheckoutMojo checkoutMojo = 099 (CheckoutMojo) lookupMojo( "checkout", getTestFile( "src/test/resources/mojos/branch/checkout.xml" ) ); 100 checkoutMojo.setWorkingDirectory( new File( getBasedir() ) ); 101 102 connectionUrl = checkoutMojo.getConnectionUrl(); 103 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 104 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 105 checkoutMojo.setConnectionUrl( connectionUrl ); 106 107 File branchCheckoutDir = getTestFile( "target/branches/mybranch" ); 108 if ( branchCheckoutDir.exists() ) 109 { 110 FileUtils.deleteDirectory( branchCheckoutDir ); 111 } 112 checkoutMojo.setCheckoutDirectory( branchCheckoutDir ); 113 114 assertFalse( new File( branchCheckoutDir, "pom.xml" ).exists() ); 115 checkoutMojo.execute(); 116 assertTrue( new File( branchCheckoutDir, "pom.xml" ).exists() ); 117 } 118}