Skip to content

Commit

Permalink
[SCM-939] Assume SCM is present
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Osipov <michaelo@apache.org>

This closes apache#150
  • Loading branch information
nielsbasjes authored and michael-o committed Apr 8, 2024
1 parent d77b92e commit 838331e
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 175 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ build
.java-version
.checkstyle
nbactions.xml
/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsexe/src/test/repository/CVSROOT/history
/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsjava/src/test/repository/CVSROOT/history
.DS_Store
.factorypath
.factorypath
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.scm.plugin;

import java.io.File;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.PlexusJUnit4TestCase;
import org.junit.After;
import org.junit.Before;

public abstract class AbstractJUnit4MojoTestCase extends AbstractMojoTestCase {
private static final PlexusJUnit4TestCase plexusJUnit4TestCase = new PlexusJUnit4TestCase();

@Before
public void setUp() throws Exception {
super.setUp();
plexusJUnit4TestCase.setUp();
}

@After
public void tearDown() throws Exception {
super.tearDown();
plexusJUnit4TestCase.tearDown();
}

public static String getBasedir() {
return plexusJUnit4TestCase.getBasedir();
}

public static File getTestFile(final String path) {
return plexusJUnit4TestCase.getTestFile(getBasedir(), path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@

import java.io.File;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Unit Test for BootstrapMojo
*
* @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
*
*/
public class BootstrapMojoTest extends AbstractMojoTestCase {
@RunWith(JUnit4.class)
public class BootstrapMojoTest extends AbstractJUnit4MojoTestCase {
File checkoutDir;

File projectDir;
Expand All @@ -38,7 +42,8 @@ public class BootstrapMojoTest extends AbstractMojoTestCase {

BootstrapMojo bootstrapMojo;

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
super.setUp();

checkoutDir = getTestFile("target/checkout");
Expand All @@ -54,6 +59,7 @@ protected void setUp() throws Exception {
bootstrapMojo = new BootstrapMojo();
}

@Test
public void testDetermineWorkingDirectoryPath() throws Exception {
// only checkout dir
assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.PlexusJUnit4TestCase;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.apache.maven.scm.ScmTestCase.checkScmPresence;

/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
*
*/
public class BranchMojoTest extends AbstractMojoTestCase {
@RunWith(JUnit4.class)
public class BranchMojoTest extends AbstractJUnit4MojoTestCase {
File checkoutDir;

File repository;

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
super.setUp();

checkoutDir = getTestFile("target/checkout");
Expand All @@ -46,17 +53,11 @@ protected void setUp() throws Exception {

FileUtils.forceDelete(repository);

if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp");
return;
}
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);

SvnScmTestUtils.initializeRepository(repository);

if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, "setUp");
return;
}
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);

CheckoutMojo checkoutMojo = (CheckoutMojo)
lookupMojo("checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml"));
Expand All @@ -72,32 +73,31 @@ protected void setUp() throws Exception {
checkoutMojo.execute();
}

@Test
public void testBranch() throws Exception {
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
return;
}
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);

BranchMojo mojo = (BranchMojo) lookupMojo("branch", getTestFile("src/test/resources/mojos/branch/branch.xml"));
BranchMojo mojo = (BranchMojo)
lookupMojo("branch", PlexusJUnit4TestCase.getTestFile("src/test/resources/mojos/branch/branch.xml"));
mojo.setWorkingDirectory(checkoutDir);

String connectionUrl = mojo.getConnectionUrl();
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
mojo.setConnectionUrl(connectionUrl);

mojo.execute();

CheckoutMojo checkoutMojo =
(CheckoutMojo) lookupMojo("checkout", getTestFile("src/test/resources/mojos/branch/checkout.xml"));
checkoutMojo.setWorkingDirectory(new File(getBasedir()));
CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo(
"checkout", PlexusJUnit4TestCase.getTestFile("src/test/resources/mojos/branch/checkout.xml"));
checkoutMojo.setWorkingDirectory(new File(PlexusJUnit4TestCase.getBasedir()));

connectionUrl = checkoutMojo.getConnectionUrl();
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
checkoutMojo.setConnectionUrl(connectionUrl);

File branchCheckoutDir = getTestFile("target/branches/mybranch");
File branchCheckoutDir = PlexusJUnit4TestCase.getTestFile("target/branches/mybranch");
if (branchCheckoutDir.exists()) {
FileUtils.deleteDirectory(branchCheckoutDir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,64 @@

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.PlexusJUnit4TestCase;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.apache.maven.scm.ScmTestCase.checkScmPresence;

/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
*
*/
public class ChangeLogMojoTest extends AbstractMojoTestCase {
@RunWith(JUnit4.class)
public class ChangeLogMojoTest extends AbstractJUnit4MojoTestCase {
File repository;

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
super.setUp();

repository = getTestFile("target/repository");

FileUtils.forceDelete(repository);

if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp");
return;
}
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);

SvnScmTestUtils.initializeRepository(repository);
}

@Test
public void testChangeLog() throws Exception {
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
return;
}

checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
ChangeLogMojo mojo = (ChangeLogMojo)
lookupMojo("changelog", getTestFile("src/test/resources/mojos/changelog/changelog.xml"));

String connectionUrl = mojo.getConnectionUrl();
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
mojo.setConnectionUrl(connectionUrl);
mojo.setWorkingDirectory(new File(getBasedir()));
mojo.setWorkingDirectory(new File(PlexusJUnit4TestCase.getBasedir()));
mojo.setConnectionType("connection");

mojo.execute();
}

@Test
public void testChangeLogWithParameters() throws Exception {
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
return;
}
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);

ChangeLogMojo mojo = (ChangeLogMojo)
lookupMojo("changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithParameters.xml"));

String connectionUrl = mojo.getConnectionUrl();
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
mojo.setConnectionUrl(connectionUrl);
mojo.setWorkingDirectory(new File(getBasedir()));
Expand All @@ -87,6 +86,7 @@ public void testChangeLogWithParameters() throws Exception {
mojo.execute();
}

@Test
public void testChangeLogWithBadUserDateFormat() throws Exception {
ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo(
"changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml"));
Expand All @@ -107,11 +107,9 @@ public void testChangeLogWithBadUserDateFormat() throws Exception {
}
}

@Test
public void testChangeLogWithBadConnectionUrl() throws Exception {
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
return;
}
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);

ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo(
"changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithBadConnectionUrl.xml"));
Expand Down
Loading

0 comments on commit 838331e

Please sign in to comment.