Skip to content

Commit d3963ce

Browse files
Check all project parents for SCM information.
During the project transformation, we need to verify all parent projects. Otherwise, modules at deeper levels may have an SCM tag added unnecessarily. fix #1420
1 parent abdc76d commit d3963ce

File tree

11 files changed

+367
-36
lines changed

11 files changed

+367
-36
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.file.Paths;
2929
import java.util.Map;
3030

31-
import org.apache.maven.artifact.ArtifactUtils;
3231
import org.apache.maven.model.Model;
3332
import org.apache.maven.model.Scm;
3433
import org.apache.maven.project.MavenProject;
@@ -82,24 +81,20 @@ protected void transformScm(
8281
throw new ReleaseExecutionException(e.getMessage(), e);
8382
}
8483
} else {
85-
MavenProject parent = project.getParent();
86-
if (parent != null) {
87-
// If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to
88-
// the release process and so has not been modified, so the values will not be correct on the tag),
89-
String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());
90-
if (!releaseDescriptor.hasOriginalScmInfo(parentId)) {
91-
// we need to add it, since it has changed from the inherited value
92-
scmRoot = new Scm();
93-
// reset default value (HEAD)
94-
scmRoot.setTag(null);
95-
96-
try {
97-
if (translateScm(project, releaseDescriptor, scmRoot, scmRepository, result)) {
98-
modelTarget.setScm(scmRoot);
99-
}
100-
} catch (IOException e) {
101-
throw new ReleaseExecutionException(e.getMessage(), e);
84+
// If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to
85+
// the release process and so has not been modified, so the values will not be correct on the tag),
86+
if (ReleaseUtil.hasNoOriginalScmInfoInParents(project, releaseDescriptor)) {
87+
// we need to add it, since it has changed from the inherited value
88+
scmRoot = new Scm();
89+
// reset default value (HEAD)
90+
scmRoot.setTag(null);
91+
92+
try {
93+
if (translateScm(project, releaseDescriptor, scmRoot, scmRepository, result)) {
94+
modelTarget.setScm(scmRoot);
10295
}
96+
} catch (IOException e) {
97+
throw new ReleaseExecutionException(e.getMessage(), e);
10398
}
10499
}
105100
}

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.file.Paths;
2929
import java.util.Map;
3030

31-
import org.apache.maven.artifact.ArtifactUtils;
3231
import org.apache.maven.model.Model;
3332
import org.apache.maven.model.Scm;
3433
import org.apache.maven.project.MavenProject;
@@ -81,24 +80,20 @@ protected void transformScm(
8180
throw new ReleaseExecutionException(e.getMessage(), e);
8281
}
8382
} else {
84-
MavenProject parent = project.getParent();
85-
if (parent != null) {
86-
// If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to
87-
// the release process and so has not been modified, so the values will not be correct on the tag),
88-
String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());
89-
if (!releaseDescriptor.hasOriginalScmInfo(parentId)) {
90-
// we need to add it, since it has changed from the inherited value
91-
Scm scmTarget = new Scm();
92-
// reset default value (HEAD)
93-
scmTarget.setTag(null);
94-
95-
try {
96-
if (translateScm(project, releaseDescriptor, scmTarget, scmRepository, result)) {
97-
modelTarget.setScm(scmTarget);
98-
}
99-
} catch (IOException e) {
100-
throw new ReleaseExecutionException(e.getMessage(), e);
83+
// If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to
84+
// the release process and so has not been modified, so the values will not be correct on the tag),
85+
if (ReleaseUtil.hasNoOriginalScmInfoInParents(project, releaseDescriptor)) {
86+
// we need to add it, since it has changed from the inherited value
87+
Scm scmTarget = new Scm();
88+
// reset default value (HEAD)
89+
scmTarget.setTag(null);
90+
91+
try {
92+
if (translateScm(project, releaseDescriptor, scmTarget, scmRepository, result)) {
93+
modelTarget.setScm(scmTarget);
10194
}
95+
} catch (IOException e) {
96+
throw new ReleaseExecutionException(e.getMessage(), e);
10297
}
10398
}
10499
}

maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Arrays;
2727
import java.util.List;
2828

29+
import org.apache.maven.artifact.ArtifactUtils;
2930
import org.apache.maven.model.Model;
3031
import org.apache.maven.project.MavenProject;
3132
import org.apache.maven.shared.release.ReleaseExecutionException;
@@ -204,4 +205,20 @@ public static String interpolate(String value, Model model) throws ReleaseExecut
204205
}
205206
return value;
206207
}
208+
209+
/**
210+
* Check if none of the parent projects have original SCM info in the release descriptor.
211+
*/
212+
public static boolean hasNoOriginalScmInfoInParents(MavenProject project, ReleaseDescriptor releaseDescriptor) {
213+
MavenProject parent = project.getParent();
214+
while (parent != null) {
215+
String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());
216+
if (releaseDescriptor.hasOriginalScmInfo(parentId)) {
217+
return false;
218+
}
219+
parent = parent.getParent();
220+
}
221+
222+
return true;
223+
}
207224
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.codehaus.maven.plugins.release.its</groupId>
25+
<artifactId>module1</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
<artifactId>module2</artifactId>
29+
<packaging>pom</packaging>
30+
31+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.codehaus.maven.plugins.release.its</groupId>
25+
<artifactId>gh-1420</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>module1</artifactId>
30+
31+
<packaging>pom</packaging>
32+
33+
<modules>
34+
<module>module2</module>
35+
</modules>
36+
37+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<groupId>org.codehaus.maven.plugins.release.its</groupId>
25+
<artifactId>gh-1420</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
<packaging>pom</packaging>
28+
29+
<url>https://github.com/apache/maven-release/issues/1420</url>
30+
<description>Check whether the child modules do not have an SCM tag</description>
31+
32+
<scm>
33+
<connection>scm:git|sd_pa/tools/release-test</connection>
34+
<tag>HEAD</tag>
35+
</scm>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-release-plugin</artifactId>
42+
<version>@project.version@</version>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<modules>
48+
<module>module1</module>
49+
</modules>
50+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import groovy.xml.XmlSlurper
21+
22+
def pom = new XmlSlurper().parse( new File( basedir, 'pom.xml.branch' ) )
23+
assert pom.scm.tag.text() == 'gh-1420-1.0-SNAPSHOT'
24+
assert pom.version.text() == '1.0-SNAPSHOT'
25+
26+
def pomNext = new XmlSlurper().parse( new File( basedir, 'pom.xml.next' ) )
27+
assert pomNext.scm.tag.text() == 'HEAD'
28+
assert pomNext.version.text() == '1.1-SNAPSHOT'
29+
30+
def pom1 = new XmlSlurper().parse( new File( basedir, 'module1/pom.xml.branch' ) )
31+
assert pom1.scm.size() == 0
32+
assert pom1.parent.version.text() == '1.0-SNAPSHOT'
33+
34+
def pom1Next = new XmlSlurper().parse( new File( basedir, 'module1/pom.xml.next' ) )
35+
assert pom1Next.scm.size() == 0
36+
assert pom1Next.parent.version.text() == '1.1-SNAPSHOT'
37+
38+
def pom2 = new XmlSlurper().parse( new File( basedir, 'module1/module2/pom.xml.branch' ) )
39+
assert pom2.scm.size() == 0
40+
assert pom2.parent.version.text() == '1.0-SNAPSHOT'
41+
42+
def pom2Next = new XmlSlurper().parse( new File( basedir, 'module1/module2/pom.xml.next' ) )
43+
assert pom2Next.scm.size() == 0
44+
assert pom2Next.parent.version.text() == '1.1-SNAPSHOT'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.codehaus.maven.plugins.release.its</groupId>
25+
<artifactId>module1</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
<artifactId>module2</artifactId>
29+
<packaging>pom</packaging>
30+
31+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.codehaus.maven.plugins.release.its</groupId>
25+
<artifactId>gh-1420</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>module1</artifactId>
30+
31+
<packaging>pom</packaging>
32+
33+
<modules>
34+
<module>module2</module>
35+
</modules>
36+
37+
</project>

0 commit comments

Comments
 (0)