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 TagMojoTest 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 testTag() 078 throws Exception 079 { 080 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) ) 081 { 082 System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE 083 + "' is not a system command. Ignored " + getName() + "." ); 084 return; 085 } 086 087 TagMojo mojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tag.xml" ) ); 088 mojo.setWorkingDirectory( checkoutDir ); 089 090 String connectionUrl = mojo.getConnectionUrl(); 091 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 092 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 093 mojo.setConnectionUrl( connectionUrl ); 094 095 mojo.execute(); 096 097 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) ) 098 { 099 System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE 100 + "' is not a system command. Ignored " + getName() + "." ); 101 return; 102 } 103 104 CheckoutMojo checkoutMojo = 105 (CheckoutMojo) lookupMojo( "checkout", getTestFile( "src/test/resources/mojos/tag/checkout.xml" ) ); 106 checkoutMojo.setWorkingDirectory( new File( getBasedir() ) ); 107 108 connectionUrl = checkoutMojo.getConnectionUrl(); 109 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 110 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 111 checkoutMojo.setConnectionUrl( connectionUrl ); 112 113 File tagCheckoutDir = getTestFile( "target/tags/mytag" ); 114 if ( tagCheckoutDir.exists() ) 115 { 116 FileUtils.deleteDirectory( tagCheckoutDir ); 117 } 118 checkoutMojo.setCheckoutDirectory( tagCheckoutDir ); 119 120 assertFalse( new File( tagCheckoutDir, "pom.xml" ).exists() ); 121 checkoutMojo.execute(); 122 assertTrue( new File( tagCheckoutDir, "pom.xml" ).exists() ); 123 } 124 125 public void testTagWithTimestamp() 126 throws Exception 127 { 128 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) ) 129 { 130 System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE 131 + "' is not a system command. Ignored " + getName() + "." ); 132 return; 133 } 134 135 TagMojo mojo = 136 (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tagWithTimestamp.xml" ) ); 137 mojo.setWorkingDirectory( checkoutDir ); 138 139 String connectionUrl = mojo.getConnectionUrl(); 140 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 141 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 142 mojo.setConnectionUrl( connectionUrl ); 143 144 mojo.execute(); 145 } 146}