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.plugin.testing.AbstractMojoTestCase; 024import org.apache.maven.scm.ScmTestCase; 025import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 026import org.codehaus.plexus.util.FileUtils; 027 028/** 029 * 030 */ 031public class ExportMojoTest extends AbstractMojoTestCase { 032 File exportDir; 033 034 File repository; 035 036 protected void setUp() throws Exception { 037 super.setUp(); 038 039 exportDir = getTestFile("target/export"); 040 041 repository = getTestFile("target/repository"); 042 043 FileUtils.forceDelete(exportDir); 044 } 045 046 public void testExport() throws Exception { 047 if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) { 048 ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName()); 049 return; 050 } 051 052 SvnScmTestUtils.initializeRepository(repository); 053 054 if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) { 055 ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName()); 056 return; 057 } 058 059 ExportMojo mojo = (ExportMojo) lookupMojo("export", getTestFile("src/test/resources/mojos/export/export.xml")); 060 061 mojo.setExportDirectory(exportDir.getAbsoluteFile()); 062 063 mojo.execute(); 064 065 assertTrue(exportDir.listFiles().length > 0); 066 assertFalse(new File(exportDir, ".svn").exists()); 067 } 068 069 public void testSkipExportIfExists() throws Exception { 070 exportDir.mkdirs(); 071 072 ExportMojo mojo = (ExportMojo) lookupMojo( 073 "export", getTestFile("src/test/resources/mojos/export/exportWhenExportDirectoryExistsAndSkip.xml")); 074 075 mojo.setExportDirectory(exportDir); 076 077 mojo.execute(); 078 079 assertEquals(0, exportDir.listFiles().length); 080 } 081 082 public void testExcludeInclude() throws Exception { 083 if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) { 084 ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName()); 085 return; 086 } 087 088 SvnScmTestUtils.initializeRepository(repository); 089 090 exportDir.mkdirs(); 091 092 if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) { 093 ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName()); 094 return; 095 } 096 097 ExportMojo mojo = (ExportMojo) 098 lookupMojo("export", getTestFile("src/test/resources/mojos/export/exportWithExcludesIncludes.xml")); 099 100 mojo.setExportDirectory(exportDir); 101 102 mojo.execute(); 103 104 assertTrue(exportDir.listFiles().length > 0); 105 assertTrue(new File(exportDir, "pom.xml").exists()); 106 assertFalse(new File(exportDir, "readme.txt").exists()); 107 assertFalse(new File(exportDir, "src/test").exists()); 108 } 109}