001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.plugin; 020 021import java.io.File; 022 023import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 024import org.codehaus.plexus.util.FileUtils; 025import org.junit.Before; 026import org.junit.Test; 027import org.junit.runner.RunWith; 028import org.junit.runners.JUnit4; 029 030import static org.apache.maven.scm.ScmTestCase.checkScmPresence; 031 032/** 033 * 034 */ 035@RunWith(JUnit4.class) 036public class ExportMojoTest extends AbstractJUnit4MojoTestCase { 037 File exportDir; 038 039 File repository; 040 041 @Before 042 public void setUp() throws Exception { 043 super.setUp(); 044 045 exportDir = getTestFile("target/export"); 046 047 repository = getTestFile("target/repository"); 048 049 FileUtils.forceDelete(exportDir); 050 } 051 052 @Test 053 public void testExport() throws Exception { 054 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE); 055 056 SvnScmTestUtils.initializeRepository(repository); 057 058 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE); 059 060 ExportMojo mojo = (ExportMojo) lookupMojo("export", getTestFile("src/test/resources/mojos/export/export.xml")); 061 062 mojo.setExportDirectory(exportDir.getAbsoluteFile()); 063 064 mojo.execute(); 065 066 assertTrue(exportDir.listFiles().length > 0); 067 assertFalse(new File(exportDir, ".svn").exists()); 068 } 069 070 @Test 071 public void testSkipExportIfExists() throws Exception { 072 exportDir.mkdirs(); 073 074 ExportMojo mojo = (ExportMojo) lookupMojo( 075 "export", getTestFile("src/test/resources/mojos/export/exportWhenExportDirectoryExistsAndSkip.xml")); 076 077 mojo.setExportDirectory(exportDir); 078 079 mojo.execute(); 080 081 assertEquals(0, exportDir.listFiles().length); 082 } 083 084 @Test 085 public void testExcludeInclude() throws Exception { 086 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE); 087 088 SvnScmTestUtils.initializeRepository(repository); 089 090 exportDir.mkdirs(); 091 092 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE); 093 094 ExportMojo mojo = (ExportMojo) 095 lookupMojo("export", getTestFile("src/test/resources/mojos/export/exportWithExcludesIncludes.xml")); 096 097 mojo.setExportDirectory(exportDir); 098 099 mojo.execute(); 100 101 assertTrue(exportDir.listFiles().length > 0); 102 assertTrue(new File(exportDir, "pom.xml").exists()); 103 assertFalse(new File(exportDir, "readme.txt").exists()); 104 assertFalse(new File(exportDir, "src/test").exists()); 105 } 106}