Skip to content

Commit 7848425

Browse files
committed
[MRELEASE-1054] Add some unit test cases.
1 parent e236be7 commit 7848425

File tree

10 files changed

+303
-14
lines changed

10 files changed

+303
-14
lines changed

maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,10 @@ protected List<File> createPomFiles(ReleaseDescriptor releaseDescriptor, List<Ma
310310

311311
final String path = project.getFile().getPath();
312312

313-
boolean isExcludedPathFound = false;
314-
for (String exclusionPattern : exclusionPatterns) {
315-
if (FileSystems.getDefault()
316-
.getPathMatcher("glob:" + exclusionPattern)
317-
.matches(Paths.get(path))) {
318-
isExcludedPathFound = true;
319-
break;
320-
}
321-
}
313+
boolean isExcludedPathFound = exclusionPatterns.stream()
314+
.anyMatch(exclusionPattern -> FileSystems.getDefault()
315+
.getPathMatcher("glob:" + exclusionPattern)
316+
.matches(Paths.get(path)));
322317
if (!isExcludedPathFound) {
323318
pomFiles.addAll(createPomFiles(releaseDescriptor, project));
324319
}

maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,21 +2454,47 @@ public void testSimulateRelease_CheckModificationExcludes() throws Exception {
24542454
MapReleaseVersionsPhase phase =
24552455
new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies);
24562456

2457-
List<MavenProject> reactorProjects = Collections.singletonList(createProjectWithPomFile("artifactId", "1.2"));
2457+
List<MavenProject> reactorProjects = new ArrayList<>();
2458+
Collections.addAll(
2459+
reactorProjects,
2460+
createProject("bar", "1.11-SNAPSHOT"),
2461+
createProjectWithPomFile(
2462+
"artifactId", "1.2-SNAPSHOT", "src/test/resources/projects/scm-commit/multiple-poms/pom.xml"),
2463+
createProjectWithPomFile(
2464+
"subproject1",
2465+
"2.0",
2466+
"src/test/resources/projects/scm-commit/multiple-poms/subproject1/pom.xml"));
24582467

24592468
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
2460-
builder.setCheckModificationExcludes(Collections.singletonList("**/pom1.xml"));
2469+
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject1/pom.xml"));
2470+
builder.setInteractive(false);
24612471

24622472
// test
24632473
phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
24642474

24652475
// verify
2466-
assertNull(
2476+
assertEquals(
24672477
"Check release versions",
2478+
"1.2",
24682479
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId"));
24692480
assertNull(
24702481
"Check development versions",
24712482
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId"));
2483+
2484+
assertEquals(
2485+
"Check release versions",
2486+
"1.11",
2487+
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:bar"));
2488+
assertNull(
2489+
"Check development versions",
2490+
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:bar"));
2491+
2492+
assertNull(
2493+
"Check release versions",
2494+
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:subproject1"));
2495+
assertNull(
2496+
"Check development versions",
2497+
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:subproject1"));
24722498
}
24732499

24742500
private static MavenProject createProject(String artifactId, String version) {
@@ -2479,13 +2505,13 @@ private static MavenProject createProject(String artifactId, String version) {
24792505
return new MavenProject(model);
24802506
}
24812507

2482-
private static MavenProject createProjectWithPomFile(String artifactId, String version) {
2508+
private static MavenProject createProjectWithPomFile(String artifactId, String version, String pathName) {
24832509
Model model = new Model();
24842510
model.setGroupId("groupId");
24852511
model.setArtifactId(artifactId);
24862512
model.setVersion(version);
24872513
MavenProject mavenProject = new MavenProject(model);
2488-
mavenProject.setFile(new File("src/test/resources/pomfinder/pom1.xml"));
2514+
mavenProject.setFile(new File(pathName));
24892515
return mavenProject;
24902516
}
24912517
}

maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.nio.file.Path;
24+
import java.util.Collections;
2425
import java.util.Iterator;
2526
import java.util.List;
2627
import java.util.Objects;
@@ -454,4 +455,19 @@ public void testRewritePomWithDifferentVersionsAcrossModules() throws Exception
454455

455456
assertTrue(comparePomFiles(reactorProjects));
456457
}
458+
459+
@Test
460+
public void testRewritePomWithCheckModificationExcludes() throws Exception {
461+
List<MavenProject> reactorProjects = createReactorProjects("multimodule-with-check-modification-excludes");
462+
463+
ReleaseDescriptorBuilder builder =
464+
createDescriptorFromProjects(reactorProjects, "multimodule-with-check-modification-excludes");
465+
builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION);
466+
builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION);
467+
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject2/*"));
468+
469+
phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
470+
471+
assertTrue(comparePomFiles(reactorProjects));
472+
}
457473
}

maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,52 @@ public void testSuppressCommitAfterBranch() throws Exception {
521521
verifyNoMoreInteractions(scmProviderMock);
522522
}
523523

524+
@Test
525+
public void testCommitMultiModuleWithCheckModificationExcludes() throws Exception {
526+
// prepare
527+
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
528+
String dir = "scm-commit/multiple-poms";
529+
List<MavenProject> reactorProjects = createReactorProjects(dir, dir, null);
530+
builder.setScmSourceUrl("scm-url");
531+
MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
532+
builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath());
533+
builder.setScmReleaseLabel("release-label");
534+
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject2/*"));
535+
536+
List<File> poms = new ArrayList<>();
537+
for (Iterator<MavenProject> i = reactorProjects.iterator(); i.hasNext(); ) {
538+
MavenProject project = i.next();
539+
// This is a mock match that verifies that the project has not been submitted
540+
if (!"subproject2".equals(project.getName())) {
541+
poms.add(project.getFile());
542+
}
543+
}
544+
ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), poms);
545+
546+
ScmProvider scmProviderMock = mock(ScmProvider.class);
547+
when(scmProviderMock.checkIn(
548+
isA(ScmRepository.class),
549+
argThat(new IsScmFileSetEquals(fileSet)),
550+
isNull(ScmVersion.class),
551+
eq(PREFIX + "release-label")))
552+
.thenReturn(new CheckInScmResult(
553+
"...",
554+
Collections.singletonList(
555+
new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN))));
556+
ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class);
557+
stub.setScmProvider(scmProviderMock);
558+
559+
// execute
560+
phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
561+
562+
// verify
563+
verify(scmProviderMock)
564+
.checkIn(
565+
isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)),
566+
isNull(ScmVersion.class), eq(PREFIX + "release-label"));
567+
verifyNoMoreInteractions(scmProviderMock);
568+
}
569+
524570
private List<MavenProject> createReactorProjects() throws Exception {
525571
String dir = "scm-commit/single-pom";
526572
return createReactorProjects(dir, dir, null);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>groupId</groupId>
23+
<artifactId>artifactId</artifactId>
24+
<version>1.0</version>
25+
<packaging>pom</packaging>
26+
27+
<scm>
28+
<connection>scm:svn:file://localhost/tmp/scm-repo/tags/release-label</connection>
29+
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/tags/release-label</developerConnection>
30+
<url>file://localhost/tmp/scm-repo/tags/release-label</url>
31+
</scm>
32+
33+
<modules>
34+
<module>subproject1</module>
35+
<module>subproject2</module>
36+
</modules>
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>groupId</groupId>
23+
<artifactId>artifactId</artifactId>
24+
<version>1.0-SNAPSHOT</version>
25+
<packaging>pom</packaging>
26+
27+
<scm>
28+
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk</connection>
29+
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk</developerConnection>
30+
<url>file://localhost/tmp/scm-repo/trunk</url>
31+
</scm>
32+
33+
<modules>
34+
<module>subproject1</module>
35+
<module>subproject2</module>
36+
</modules>
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>groupId</groupId>
24+
<artifactId>artifactId</artifactId>
25+
<version>1.0</version>
26+
</parent>
27+
28+
<artifactId>subproject1</artifactId>
29+
<version>2.0</version>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>groupId</groupId>
24+
<artifactId>artifactId</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>subproject1</artifactId>
29+
<version>2.0-SNAPSHOT</version>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>groupId</groupId>
24+
<artifactId>artifactId</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<scm>
29+
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</connection>
30+
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</developerConnection>
31+
<url>file://localhost/tmp/scm-repo/trunk/subproject2</url>
32+
</scm>
33+
34+
<artifactId>subproject2</artifactId>
35+
<version>2.0-SNAPSHOT</version>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
20+
<project>
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>groupId</groupId>
24+
<artifactId>artifactId</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<scm>
29+
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</connection>
30+
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</developerConnection>
31+
<url>file://localhost/tmp/scm-repo/trunk/subproject2</url>
32+
</scm>
33+
34+
<artifactId>subproject2</artifactId>
35+
<version>2.0-SNAPSHOT</version>
36+
</project>

0 commit comments

Comments
 (0)