Skip to content

Commit 95817d6

Browse files
nielsbasjesmichael-o
authored andcommitted
[SCM-939] Assume SCM is present
Co-authored-by: Michael Osipov <michaelo@apache.org> This closes #150
1 parent cb1efe4 commit 95817d6

File tree

17 files changed

+239
-175
lines changed

17 files changed

+239
-175
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ build
1111
.java-version
1212
.checkstyle
1313
nbactions.xml
14-
/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsexe/src/test/repository/CVSROOT/history
15-
/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvsjava/src/test/repository/CVSROOT/history
1614
.DS_Store
17-
.factorypath
15+
.factorypath
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.scm.plugin;
20+
21+
import java.io.File;
22+
23+
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24+
import org.apache.maven.scm.PlexusJUnit4TestCase;
25+
import org.junit.After;
26+
import org.junit.Before;
27+
28+
public abstract class AbstractJUnit4MojoTestCase extends AbstractMojoTestCase {
29+
private static final PlexusJUnit4TestCase plexusJUnit4TestCase = new PlexusJUnit4TestCase();
30+
31+
@Before
32+
public void setUp() throws Exception {
33+
super.setUp();
34+
plexusJUnit4TestCase.setUp();
35+
}
36+
37+
@After
38+
public void tearDown() throws Exception {
39+
super.tearDown();
40+
plexusJUnit4TestCase.tearDown();
41+
}
42+
43+
public static String getBasedir() {
44+
return plexusJUnit4TestCase.getBasedir();
45+
}
46+
47+
public static File getTestFile(final String path) {
48+
return plexusJUnit4TestCase.getTestFile(getBasedir(), path);
49+
}
50+
}

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BootstrapMojoTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020

2121
import java.io.File;
2222

23-
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
2423
import org.codehaus.plexus.util.FileUtils;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
2528

2629
/**
2730
* Unit Test for BootstrapMojo
2831
*
2932
* @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
3033
*
3134
*/
32-
public class BootstrapMojoTest extends AbstractMojoTestCase {
35+
@RunWith(JUnit4.class)
36+
public class BootstrapMojoTest extends AbstractJUnit4MojoTestCase {
3337
File checkoutDir;
3438

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

3943
BootstrapMojo bootstrapMojo;
4044

41-
protected void setUp() throws Exception {
45+
@Before
46+
public void setUp() throws Exception {
4247
super.setUp();
4348

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

62+
@Test
5763
public void testDetermineWorkingDirectoryPath() throws Exception {
5864
// only checkout dir
5965
assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", ""));

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,29 @@
2020

2121
import java.io.File;
2222

23-
import org.apache.commons.lang3.StringUtils;
24-
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
25-
import org.apache.maven.scm.ScmTestCase;
23+
import org.apache.maven.scm.PlexusJUnit4TestCase;
2624
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
2725
import org.codehaus.plexus.util.FileUtils;
26+
import org.codehaus.plexus.util.StringUtils;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
import org.junit.runners.JUnit4;
31+
32+
import static org.apache.maven.scm.ScmTestCase.checkScmPresence;
2833

2934
/**
3035
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
3136
*
3237
*/
33-
public class BranchMojoTest extends AbstractMojoTestCase {
38+
@RunWith(JUnit4.class)
39+
public class BranchMojoTest extends AbstractJUnit4MojoTestCase {
3440
File checkoutDir;
3541

3642
File repository;
3743

38-
protected void setUp() throws Exception {
44+
@Before
45+
public void setUp() throws Exception {
3946
super.setUp();
4047

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

4754
FileUtils.forceDelete(repository);
4855

49-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
50-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp");
51-
return;
52-
}
56+
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
5357

5458
SvnScmTestUtils.initializeRepository(repository);
5559

56-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
57-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, "setUp");
58-
return;
59-
}
60+
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
6061

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

76+
@Test
7577
public void testBranch() throws Exception {
76-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
77-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
78-
return;
79-
}
78+
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
8079

81-
BranchMojo mojo = (BranchMojo) lookupMojo("branch", getTestFile("src/test/resources/mojos/branch/branch.xml"));
80+
BranchMojo mojo = (BranchMojo)
81+
lookupMojo("branch", PlexusJUnit4TestCase.getTestFile("src/test/resources/mojos/branch/branch.xml"));
8282
mojo.setWorkingDirectory(checkoutDir);
8383

8484
String connectionUrl = mojo.getConnectionUrl();
85-
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
85+
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
8686
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
8787
mojo.setConnectionUrl(connectionUrl);
8888

8989
mojo.execute();
9090

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

9595
connectionUrl = checkoutMojo.getConnectionUrl();
96-
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
96+
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
9797
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
9898
checkoutMojo.setConnectionUrl(connectionUrl);
9999

100-
File branchCheckoutDir = getTestFile("target/branches/mybranch");
100+
File branchCheckoutDir = PlexusJUnit4TestCase.getTestFile("target/branches/mybranch");
101101
if (branchCheckoutDir.exists()) {
102102
FileUtils.deleteDirectory(branchCheckoutDir);
103103
}

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ChangeLogMojoTest.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,64 @@
2020

2121
import java.io.File;
2222

23-
import org.apache.commons.lang3.StringUtils;
2423
import org.apache.maven.plugin.MojoExecutionException;
25-
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
26-
import org.apache.maven.scm.ScmTestCase;
24+
import org.apache.maven.scm.PlexusJUnit4TestCase;
2725
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
2826
import org.codehaus.plexus.util.FileUtils;
27+
import org.codehaus.plexus.util.StringUtils;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
32+
33+
import static org.apache.maven.scm.ScmTestCase.checkScmPresence;
2934

3035
/**
3136
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
3237
*
3338
*/
34-
public class ChangeLogMojoTest extends AbstractMojoTestCase {
39+
@RunWith(JUnit4.class)
40+
public class ChangeLogMojoTest extends AbstractJUnit4MojoTestCase {
3541
File repository;
3642

37-
protected void setUp() throws Exception {
43+
@Before
44+
public void setUp() throws Exception {
3845
super.setUp();
3946

4047
repository = getTestFile("target/repository");
4148

4249
FileUtils.forceDelete(repository);
4350

44-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
45-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp");
46-
return;
47-
}
51+
checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
4852

4953
SvnScmTestUtils.initializeRepository(repository);
5054
}
5155

56+
@Test
5257
public void testChangeLog() throws Exception {
53-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
54-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
55-
return;
56-
}
57-
58+
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
5859
ChangeLogMojo mojo = (ChangeLogMojo)
5960
lookupMojo("changelog", getTestFile("src/test/resources/mojos/changelog/changelog.xml"));
6061

6162
String connectionUrl = mojo.getConnectionUrl();
62-
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
63+
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
6364
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
6465
mojo.setConnectionUrl(connectionUrl);
65-
mojo.setWorkingDirectory(new File(getBasedir()));
66+
mojo.setWorkingDirectory(new File(PlexusJUnit4TestCase.getBasedir()));
6667
mojo.setConnectionType("connection");
6768

6869
mojo.execute();
6970
}
7071

72+
@Test
7173
public void testChangeLogWithParameters() throws Exception {
72-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
73-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
74-
return;
75-
}
74+
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
7675

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

8079
String connectionUrl = mojo.getConnectionUrl();
81-
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
80+
connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
8281
connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
8382
mojo.setConnectionUrl(connectionUrl);
8483
mojo.setWorkingDirectory(new File(getBasedir()));
@@ -87,6 +86,7 @@ public void testChangeLogWithParameters() throws Exception {
8786
mojo.execute();
8887
}
8988

89+
@Test
9090
public void testChangeLogWithBadUserDateFormat() throws Exception {
9191
ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo(
9292
"changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml"));
@@ -107,11 +107,9 @@ public void testChangeLogWithBadUserDateFormat() throws Exception {
107107
}
108108
}
109109

110+
@Test
110111
public void testChangeLogWithBadConnectionUrl() throws Exception {
111-
if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
112-
ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
113-
return;
114-
}
112+
checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
115113

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

0 commit comments

Comments
 (0)