BOM parametrization

* Allow parametrization of versions patterns, fixes gh-99
* Customize the BOM pom location, fixes gh-98
This commit is contained in:
Marcin Grzejszczak
2018-10-17 09:15:45 +02:00
parent 1f7edff29f
commit 1b7a162ebe
10 changed files with 301 additions and 113 deletions

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.release.internal;
import java.io.File;
import java.lang.invoke.MethodHandles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +50,7 @@ public class Releaser {
}
public Projects retrieveVersionsFromSCRelease() {
return this.projectPomUpdater.retrieveVersionsFromSCRelease();
return this.projectPomUpdater.retrieveVersionsFromReleaseTrainBom();
}
public Projects fixedVersions() {

View File

@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang.SerializationUtils;
@@ -139,7 +140,7 @@ public class ReleaserProperties implements Serializable {
/**
* URL to Spring Cloud Release Git repository
*/
private String springCloudReleaseGitUrl = "https://github.com/spring-cloud/spring-cloud-release";
private String releaseTrainBomUrl = "https://github.com/spring-cloud/spring-cloud-release";
/**
* URL to the documentation Git repository
@@ -192,12 +193,12 @@ public class ReleaserProperties implements Serializable {
*/
private boolean updateSpringGuides = true;
public String getSpringCloudReleaseGitUrl() {
return this.springCloudReleaseGitUrl;
public String getReleaseTrainBomUrl() {
return this.releaseTrainBomUrl;
}
public void setSpringCloudReleaseGitUrl(String springCloudReleaseGitUrl) {
this.springCloudReleaseGitUrl = springCloudReleaseGitUrl;
public void setReleaseTrainBomUrl(String releaseTrainBomUrl) {
this.releaseTrainBomUrl = releaseTrainBomUrl;
}
public String getDocumentationUrl() {
@@ -283,7 +284,7 @@ public class ReleaserProperties implements Serializable {
@Override
public String toString() {
return "Git{" +
"springCloudReleaseGitUrl='" + this.springCloudReleaseGitUrl + '\'' +
"releaseTrainBomUrl='" + this.releaseTrainBomUrl + '\'' +
", documentationUrl='" + this.documentationUrl + '\'' +
", documentationBranch='" + this.documentationBranch + '\'' +
", updateDocumentationRepo=" + this.updateDocumentationRepo +
@@ -299,10 +300,25 @@ public class ReleaserProperties implements Serializable {
public static class Pom implements Serializable {
/**
* Which branch of Spring Cloud Release should be checked out. Defaults to {@code master}
* Which branch of release train BOM should be checked out. Defaults to {@code master}
*/
private String branch = "master";
/**
* Subfolder of the pom that contains the {@code spring-boot-starer-parent} dependency
*/
private String pomWithBootStarterParent = "spring-cloud-starter-parent/pom.xml";
/**
* Subfolder of the pom that contains the versions for the release train
*/
private String thisTrainBom = "spring-cloud-dependencies/pom.xml";
/**
* The pattern to match a version property in a BOM
*/
private String bomVersionPattern = "^(spring-cloud-.*)\\.version$";
/**
* List of regular expressions of ignored poms. Defaults to test projects and samples.
*/
@@ -330,9 +346,39 @@ public class ReleaserProperties implements Serializable {
this.ignoredPomRegex = ignoredPomRegex;
}
@Override public String toString() {
return "Pom{" + "branch='" + this.branch + '\'' + ", ignoredPomRegex="
+ this.ignoredPomRegex + '}';
public String getPomWithBootStarterParent() {
return this.pomWithBootStarterParent;
}
public void setPomWithBootStarterParent(String pomWithBootStarterParent) {
this.pomWithBootStarterParent = pomWithBootStarterParent;
}
public String getThisTrainBom() {
return this.thisTrainBom;
}
public void setThisTrainBom(String thisTrainBom) {
this.thisTrainBom = thisTrainBom;
}
public String getBomVersionPattern() {
return this.bomVersionPattern;
}
public void setBomVersionPattern(String bomVersionPattern) {
this.bomVersionPattern = bomVersionPattern;
}
@Override
public String toString() {
return "Pom{" +
"branch='" + this.branch + '\'' +
", pomWithBootStarterParent='" + this.pomWithBootStarterParent + '\'' +
", thisTrainBom='" + this.thisTrainBom + '\'' +
", bomVersionPattern='" + this.bomVersionPattern + '\'' +
", ignoredPomRegex=" + this.ignoredPomRegex +
'}';
}
}

View File

@@ -1,9 +1,6 @@
package org.springframework.cloud.release.internal.git;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import org.eclipse.jgit.transport.URIish;
@@ -67,8 +64,8 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
gitRepo.commit(message);
}
public File cloneScReleaseProject() {
return cloneProject(this.properties.getGit().getSpringCloudReleaseGitUrl());
public File cloneReleaseTrainProject() {
return cloneProject(this.properties.getGit().getReleaseTrainBomUrl());
}
public File cloneDocumentationProject() {

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.release.internal.pom;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -30,37 +29,36 @@ import org.apache.maven.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
/**
* Parses the poms for a given project and populates versions from Spring Cloud Release
* Parses the poms for a given project and populates versions from a release train
*
* @author Marcin Grzejszczak
*/
class SCReleasePomParser {
class BomParser {
private static final Logger log = LoggerFactory.getLogger(SCReleasePomParser.class);
private static final Logger log = LoggerFactory.getLogger(BomParser.class);
private static final String STARTER_POM = "spring-cloud-starter-parent/pom.xml";
private static final String DEPENDENCIES_POM = "spring-cloud-dependencies/pom.xml";
private static final Pattern SC_VERSION_PATTERN = Pattern.compile("^(spring-cloud-.*)\\.version$");
private final File springCloudReleaseDir;
private final String bootPom;
private final String dependenciesPomPath;
private final File thisProjectRoot;
private final String pomWithBootStarterParent;
private final String thisTrainBom;
private final PomReader pomReader = new PomReader();
private final Pattern versionPattern;
private final ReleaserProperties properties;
SCReleasePomParser(File springCloudReleaseDir) {
this(springCloudReleaseDir, STARTER_POM, DEPENDENCIES_POM);
}
SCReleasePomParser(File springCloudReleaseDir, String bootPom, String dependenciesPom) {
this.springCloudReleaseDir = springCloudReleaseDir;
this.bootPom = bootPom;
this.dependenciesPomPath = dependenciesPom;
BomParser(ReleaserProperties properties, File thisProjectRoot) {
this.thisProjectRoot = thisProjectRoot;
this.pomWithBootStarterParent = properties.getPom().getPomWithBootStarterParent();
this.thisTrainBom = properties.getPom().getThisTrainBom();
this.versionPattern = Pattern.compile(properties.getPom().getBomVersionPattern());
this.properties = properties;
}
Versions allVersions() {
Versions boot = bootVersion();
Versions cloud = springCloudVersions();
Versions cloud = versionsFromSpringCloudBom();
return new Versions(boot.bootVersion, cloud.scBuildVersion, allProjects(boot, cloud));
}
@@ -72,7 +70,7 @@ class SCReleasePomParser {
}
Versions bootVersion() {
Model model = pom(this.bootPom);
Model model = pom(this.pomWithBootStarterParent);
String bootArtifactId = model.getParent().getArtifactId();
log.debug("Boot artifact id is equal to [{}]", bootArtifactId);
if (!SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID.equals(bootArtifactId)) {
@@ -88,15 +86,16 @@ class SCReleasePomParser {
if (pom == null) {
throw new IllegalStateException("Pom is not present");
}
File pomFile = new File(this.springCloudReleaseDir, pom);
File pomFile = new File(this.thisProjectRoot, pom);
if (!pomFile.exists()) {
throw new IllegalStateException("Pom is not present");
}
return this.pomReader.readPom(pomFile);
}
Versions springCloudVersions() {
Model model = pom(this.dependenciesPomPath);
// the BOM contains all versions of projects and its parent MUST be Spring Cloud Dependencies Parent
Versions versionsFromSpringCloudBom() {
Model model = pom(this.thisTrainBom);
String buildArtifact = model.getParent().getArtifactId();
log.debug("[{}] artifact id is equal to [{}]", SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, buildArtifact);
if (!SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID.equals(buildArtifact)) {
@@ -110,18 +109,18 @@ class SCReleasePomParser {
.filter(propertyMatchesSCPattern())
.map(toProject())
.collect(Collectors.toSet());
String scReleaseVersion = model.getVersion();
projects.add(new Project("spring-cloud-release", scReleaseVersion));
String releaseTrainProjectVersion = model.getVersion();
projects.add(new Project(this.properties.getMetaRelease().getReleaseTrainProjectName(), releaseTrainProjectVersion));
return new Versions(buildVersion, projects);
}
private Predicate<Map.Entry<Object, Object>> propertyMatchesSCPattern() {
return entry -> SC_VERSION_PATTERN.matcher(entry.getKey().toString()).matches();
return entry -> this.versionPattern.matcher(entry.getKey().toString()).matches();
}
private Function<Map.Entry<Object, Object>, Project> toProject() {
return entry -> {
Matcher matcher = SC_VERSION_PATTERN.matcher(entry.getKey().toString());
Matcher matcher = this.versionPattern.matcher(entry.getKey().toString());
// you have to first match to get info about the group
matcher.matches();
String name = matcher.group(1);

View File

@@ -24,10 +24,8 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.slf4j.Logger;
@@ -62,10 +60,10 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
* For the given root folder (typically the working directory) retrieves list of versions
* for a given release version.
*/
public Projects retrieveVersionsFromSCRelease() {
File clonedScRelease = this.gitRepo.cloneScReleaseProject();
public Projects retrieveVersionsFromReleaseTrainBom() {
File clonedScRelease = this.gitRepo.cloneReleaseTrainProject();
this.gitRepo.checkout(clonedScRelease, this.properties.getPom().getBranch());
SCReleasePomParser sCReleasePomParser = new SCReleasePomParser(clonedScRelease);
BomParser sCReleasePomParser = new BomParser(this.properties, clonedScRelease);
Versions versions = sCReleasePomParser.allVersions();
log.info("Will update the following versions manually [{}]", this.properties.getFixedVersions());
this.properties.getFixedVersions().forEach(versions::setVersion);