Added support for -parent ending root poms

This commit is contained in:
Marcin Grzejszczak
2017-03-07 13:42:27 +01:00
parent 6756df9916
commit ea32829d6f
5 changed files with 118 additions and 2 deletions

View File

@@ -51,6 +51,10 @@
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@@ -57,9 +57,10 @@ class PomUpdater {
* @return {@code true} if the project is on the list of projects to be updated
*/
boolean shouldProjectBeUpdated(File rootFolder, Versions versions) {
File rootPom = new File(rootFolder, "pom.xml");
File rootPom = rootPom(rootFolder);
Model model = this.pomReader.readPom(rootPom);
if (!versions.shouldBeUpdated(model.getArtifactId())) {
String artifactId = artifactId(model);
if (!versions.shouldBeUpdated(artifactId)) {
log.info("Skipping project [{}] since it's not on the list of projects to update", model.getArtifactId());
return false;
}
@@ -67,6 +68,21 @@ class PomUpdater {
return true;
}
private File rootPom(File rootFolder) {
if (rootFolder.getName().endsWith(".xml")) {
return rootFolder;
}
return new File(rootFolder, "pom.xml");
}
private String artifactId(Model model) {
boolean parent = model.getArtifactId().endsWith("-parent");
if (!parent) {
return model.getArtifactId();
}
return model.getArtifactId().substring(0, model.getArtifactId().indexOf("-parent"));
}
ModelWrapper readModel(File pom) {
return new ModelWrapper(this.pomReader.readPom(pom));
}

View File

@@ -54,6 +54,20 @@ public class PomUpdaterTests {
then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse();
}
@Test
public void should_not_update_pom_when_project_with_parent_suffix_is_not_on_the_versions_list() throws Exception {
File springCloud = pom("/projects/project", "pom_with_parent_suffix.xml");
then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versions)).isFalse();
}
@Test
public void should_update_pom_for_project_with_suffix_when_project_is_on_the_versions_list() throws Exception {
File springCloud = pom("/projects/project", "pom_matching_with_parent_suffix.xml");
then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versions)).isTrue();
}
@Test
public void should_update_pom_when_project_is_not_on_the_versions_list() throws Exception {
File springCloudSleuthPom = file("/projects/spring-cloud-sleuth");

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2013-2017 the original author or authors.
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-sleuth-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>foo</name>
<description>foo</description>
<parent>
<groupId>parentGroup</groupId>
<artifactId>parentArtifactId</artifactId>
<version>1.3.1.BUILD-SNAPSHOT</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<spring-cloud-foo.version>1.3.1.BUILD-SNAPSHOT</spring-cloud-foo.version>
<foo.version>1.2.0.BUILD-SNAPSHOT</foo.version>
</properties>
</project>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2013-2017 the original author or authors.
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>foo-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>foo</name>
<description>foo</description>
<parent>
<groupId>parentGroup</groupId>
<artifactId>parentArtifactId</artifactId>
<version>1.3.1.BUILD-SNAPSHOT</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<spring-cloud-foo.version>1.3.1.BUILD-SNAPSHOT</spring-cloud-foo.version>
<foo.version>1.2.0.BUILD-SNAPSHOT</foo.version>
</properties>
</project>