This commit is contained in:
Marcin Grzejszczak
2018-11-19 11:51:36 +01:00
parent e0da24bc1a
commit 4ab19000ab
36 changed files with 248 additions and 123 deletions

View File

@@ -79,6 +79,14 @@ public class ReleaserProperties implements Serializable {
*/
private String releaseTrainProjectName = "spring-cloud-release";
/**
* All the names of dependencies that should be updated with the release
* train project version
*/
private List<String> releaseTrainDependencyNames = Arrays.asList(
"spring-cloud", "spring-cloud-dependencies", "spring-cloud-starter"
);
/**
* The URL of the Git organization. We'll append each project's
* name to it
@@ -120,6 +128,14 @@ public class ReleaserProperties implements Serializable {
this.releaseTrainProjectName = releaseTrainProjectName;
}
public List<String> getReleaseTrainDependencyNames() {
return this.releaseTrainDependencyNames;
}
public void setReleaseTrainDependencyNames(List<String> releaseTrainDependencyNames) {
this.releaseTrainDependencyNames = releaseTrainDependencyNames;
}
public List<String> getProjectsToSkip() {
return this.projectsToSkip;
}

View File

@@ -18,9 +18,18 @@ package org.springframework.cloud.release.internal.git;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.List;
import com.jcraft.jsch.IdentityRepository;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.agentproxy.AgentProxyException;
import com.jcraft.jsch.agentproxy.Connector;
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository;
import com.jcraft.jsch.agentproxy.USocketFactory;
import com.jcraft.jsch.agentproxy.connector.SSHAgentConnector;
import com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory;
import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.CreateBranchCommand;
@@ -43,21 +52,11 @@ import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import com.jcraft.jsch.IdentityRepository;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.agentproxy.AgentProxyException;
import com.jcraft.jsch.agentproxy.Connector;
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository;
import com.jcraft.jsch.agentproxy.USocketFactory;
import com.jcraft.jsch.agentproxy.connector.SSHAgentConnector;
import com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory;
/**
* Abstraction over a Git repo. Can cloned repo from a given location
* and check its branch.

View File

@@ -1,16 +1,12 @@
package org.springframework.cloud.release.internal.git;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.jcabi.github.Coordinates;
import com.jcabi.github.Github;
import com.jcabi.github.Issue;
import com.jcabi.github.Milestone;
import com.jcabi.github.Repo;
import com.jcabi.github.RtGithub;
import com.jcabi.http.wire.RetryWire;

View File

@@ -3,7 +3,6 @@ package org.springframework.cloud.release.internal.gradle;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;

View File

@@ -58,7 +58,7 @@ class BomParser {
Versions allVersions() {
Versions boot = bootVersion();
Versions cloud = versionsFromSpringCloudBom();
Versions cloud = versionsFromBom();
return new Versions(boot.bootVersion, cloud.scBuildVersion, allProjects(boot, cloud));
}
@@ -71,6 +71,9 @@ class BomParser {
Versions bootVersion() {
Model model = pom(this.pomWithBootStarterParent);
if (model == null) {
return Versions.EMPTY_VERSION;
}
String bootArtifactId = model.getParent().getArtifactId();
log.debug("Boot artifact id is equal to [{}]", bootArtifactId);
if (!SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID.equals(bootArtifactId)) {
@@ -94,8 +97,11 @@ class BomParser {
}
// the BOM contains all versions of projects and its parent MUST be Spring Cloud Dependencies Parent
Versions versionsFromSpringCloudBom() {
Versions versionsFromBom() {
Model model = pom(this.thisTrainBom);
if (model == null) {
return Versions.EMPTY_VERSION;
}
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)) {

View File

@@ -18,10 +18,8 @@ package org.springframework.cloud.release.internal.pom;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;

View File

@@ -88,7 +88,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
if (log.isDebugEnabled()) {
log.debug("Will apply the following fixed versions {}", projectVersions);
}
return new Versions(projectVersions).toProjectVersions();
return new Versions(projectVersions, this.properties).toProjectVersions();
}
/**
@@ -103,7 +103,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
*/
public void updateProjectFromReleaseTrain(File projectRoot, Projects projects,
ProjectVersion versionFromReleaseTrain, boolean assertSnapshots) {
Versions versions = new Versions(projects);
Versions versions = new Versions(projects, this.properties);
if (!this.pomUpdater.shouldProjectBeUpdated(projectRoot, versions)) {
log.info("Skipping project updating");
return;
@@ -151,7 +151,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
ReleaserProperties properties, ProjectVersion versionFromScRelease,
boolean assertSnapshots) {
this.rootPom = rootPom;
this.versions = new Versions(projects);
this.versions = new Versions(projects, properties);
this.pomUpdater = pomUpdater;
this.properties = properties;
this.snapshotVersion = !assertSnapshots || versionFromScRelease.isSnapshot();

View File

@@ -52,7 +52,7 @@ public class Projects extends HashSet<ProjectVersion> {
public Projects postReleaseSnapshotVersion(List<String> projectsToSkip) {
Projects projects = this.stream()
.filter(v -> projectsToSkip.contains(v.projectName))
.filter(v -> projectsToSkip(projectsToSkip, v))
.collect(Collectors.toCollection(Projects::new));
Projects bumped = this.stream()
.map(v -> new ProjectVersion(v.projectName, v.postReleaseSnapshotVersion()))
@@ -62,6 +62,10 @@ public class Projects extends HashSet<ProjectVersion> {
return merged;
}
private boolean projectsToSkip(List<String> projectsToSkip, ProjectVersion version) {
return projectsToSkip.stream().anyMatch(version.projectName::startsWith);
}
public void remove(String projectName) {
ProjectVersion projectVersion = forName(projectName);
remove(projectVersion);

View File

@@ -21,15 +21,11 @@ package org.springframework.cloud.release.internal.pom;
*/
final class SpringCloudConstants {
static final String SPRING_BOOT = "spring-boot";
static final String CLOUD_DEPENDENCIES_ARTIFACT_ID = "spring-cloud-dependencies";
static final String BOOT_STARTER_ARTIFACT_ID = "spring-boot-starter";
static final String BOOT_STARTER_PARENT_ARTIFACT_ID = BOOT_STARTER_ARTIFACT_ID + "-parent";
static final String BOOT_DEPENDENCIES_ARTIFACT_ID = "spring-boot-dependencies";
static final String CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID = "spring-cloud-dependencies-parent";
static final String BUILD_ARTIFACT_ID = "spring-cloud-build";
static final String SPRING_CLOUD_RELEASE = "spring-cloud-release";
static final String SPRING_CLOUD = "spring-cloud";
static final String SPRING_CLOUD_STARTER = "spring-cloud-starter";
private SpringCloudConstants() {
throw new IllegalStateException("Don't instantiate a utility class");

View File

@@ -15,19 +15,20 @@
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.cloud.release.internal.ReleaserProperties;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.BOOT_DEPENDENCIES_ARTIFACT_ID;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.BUILD_ARTIFACT_ID;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.CLOUD_DEPENDENCIES_ARTIFACT_ID;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.SPRING_CLOUD;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.SPRING_CLOUD_RELEASE;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.SPRING_CLOUD_STARTER;
/**
* Represents versions taken out from Spring Cloud Release pom
@@ -42,35 +43,42 @@ class Versions {
String bootVersion;
String scBuildVersion;
Set<Project> projects = new HashSet<>();
ReleaserProperties properties;
Versions(String bootVersion) {
this.bootVersion = bootVersion;
this.projects.add(new Project(SPRING_BOOT_PROJECT_NAME, bootVersion));
this.projects.add(new Project(BOOT_STARTER_PARENT_ARTIFACT_ID, bootVersion));
this.projects.add(new Project(BOOT_DEPENDENCIES_ARTIFACT_ID, bootVersion));
add(SPRING_BOOT_PROJECT_NAME, bootVersion);
add(BOOT_STARTER_PARENT_ARTIFACT_ID, bootVersion);
add(BOOT_DEPENDENCIES_ARTIFACT_ID, bootVersion);
this.properties = new ReleaserProperties();
}
Versions(String scBuildVersion, Set<Project> projects) {
this.scBuildVersion = scBuildVersion;
this.projects.add(new Project(BUILD_ARTIFACT_ID, scBuildVersion));
this.projects.add(new Project(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, scBuildVersion));
this.projects.add(new Project(CLOUD_DEPENDENCIES_ARTIFACT_ID, scBuildVersion));
add(BUILD_ARTIFACT_ID, scBuildVersion);
add(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, scBuildVersion);
this.projects.addAll(projects);
this.properties = new ReleaserProperties();
}
Versions(String bootVersion, String scBuildVersion, Set<Project> projects) {
this(new ReleaserProperties(), bootVersion, scBuildVersion, projects);
}
Versions(ReleaserProperties properties, String bootVersion, String scBuildVersion, Set<Project> projects) {
this.properties = properties;
this.bootVersion = bootVersion;
this.scBuildVersion = scBuildVersion;
this.projects.add(new Project(SPRING_BOOT_PROJECT_NAME, bootVersion));
this.projects.add(new Project(BOOT_STARTER_PARENT_ARTIFACT_ID, bootVersion));
this.projects.add(new Project(BOOT_DEPENDENCIES_ARTIFACT_ID, bootVersion));
this.projects.add(new Project(BUILD_ARTIFACT_ID, scBuildVersion));
this.projects.add(new Project(CLOUD_DEPENDENCIES_ARTIFACT_ID, scBuildVersion));
this.projects.add(new Project(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, scBuildVersion));
add(SPRING_BOOT_PROJECT_NAME, bootVersion);
add(BOOT_STARTER_PARENT_ARTIFACT_ID, bootVersion);
add(BOOT_DEPENDENCIES_ARTIFACT_ID, bootVersion);
add(BUILD_ARTIFACT_ID, scBuildVersion);
add(dependenciesParentArtifactId(), scBuildVersion);
this.projects.addAll(projects);
}
Versions(Set<ProjectVersion> versions) {
Versions(Set<ProjectVersion> versions, ReleaserProperties properties) {
this.properties = properties;
this.bootVersion = versions.stream().filter(projectVersion -> SPRING_BOOT_PROJECT_NAME.equals(projectVersion.projectName))
.findFirst().orElse(new ProjectVersion(SPRING_BOOT_PROJECT_NAME, "")).version;
this.scBuildVersion = versions.stream().filter(projectVersion -> BUILD_ARTIFACT_ID.equals(projectVersion.projectName))
@@ -78,6 +86,19 @@ class Versions {
versions.forEach(projectVersion -> setVersion(projectVersion.projectName, projectVersion.version));
}
private String bomProjectName() {
return this.properties.getMetaRelease().getReleaseTrainProjectName();
}
private String dependenciesArtifactId() {
String artifactId = this.properties.getPom().getThisTrainBom();
return artifactId.split(File.separator)[0];
}
private String dependenciesParentArtifactId() {
return dependenciesArtifactId() + "-parent";
}
String versionForProject(String projectName) {
return this.projects.stream()
.filter(project -> nameMatches(projectName, project))
@@ -99,18 +120,33 @@ class Versions {
Projects toProjectVersions() {
return this.projects.stream()
.map(project -> new ProjectVersion(project.name, project.version))
.distinct().collect(Collectors.toCollection(Projects::new));
.collect(Collectors.toCollection(Projects::new));
}
/**
* The only exception is spring-cloud-dependencies (e.g. Greenwich.RELEASE) and
* spring-cloud-dependencies-parent (e.g. 2.1.0.RELEASE)
*/
private boolean nameMatches(String projectName, Project project) {
if (project.name.equals(projectName)) {
return true;
}
boolean parent = nameWithSuffix(projectName, "-parent", project);
return parent || nameWithSuffix(projectName, "-dependencies", project);
boolean parent = matchesNameWithSuffix(projectName, "-parent", project);
boolean bomArtifactId = comparisonOfBomArtifactAndParent(projectName, project);
return !bomArtifactId &&
(parent || matchesNameWithSuffix(projectName, "-dependencies", project));
}
private boolean nameWithSuffix(String projectName, String suffix, Project project) {
private boolean comparisonOfBomArtifactAndParent(String projectName, Project project) {
return artifactOrParent(projectName, project.name) || artifactOrParent(project.name, projectName);
}
private boolean artifactOrParent(String projectName, String otherProjectName) {
return projectName.equals(dependenciesArtifactId()) &&
otherProjectName.equals(dependenciesParentArtifactId());
}
private boolean matchesNameWithSuffix(String projectName, String suffix, Project project) {
boolean containsSuffix = projectName.endsWith(suffix);
if (!containsSuffix) {
return false;
@@ -124,42 +160,59 @@ class Versions {
case SPRING_BOOT_PROJECT_NAME:
case BOOT_STARTER_PARENT_ARTIFACT_ID:
case BOOT_DEPENDENCIES_ARTIFACT_ID:
this.bootVersion = version;
remove(SPRING_BOOT_PROJECT_NAME);
remove(BOOT_DEPENDENCIES_ARTIFACT_ID);
remove(BOOT_STARTER_PARENT_ARTIFACT_ID);
this.projects.add(new Project(SPRING_BOOT_PROJECT_NAME, version));
this.projects.add(new Project(BOOT_STARTER_PARENT_ARTIFACT_ID, version));
this.projects.add(new Project(BOOT_DEPENDENCIES_ARTIFACT_ID, version));
updateBootVersions(version);
break;
case BUILD_ARTIFACT_ID:
case CLOUD_DEPENDENCIES_ARTIFACT_ID:
case CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID:
this.scBuildVersion = version;
remove(BUILD_ARTIFACT_ID);
remove(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID);
remove(CLOUD_DEPENDENCIES_ARTIFACT_ID);
this.projects.add(new Project(BUILD_ARTIFACT_ID, version));
this.projects.add(new Project(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, version));
this.projects.add(new Project(CLOUD_DEPENDENCIES_ARTIFACT_ID, version));
break;
case SPRING_CLOUD_RELEASE:
case SPRING_CLOUD:
case SPRING_CLOUD_STARTER:
remove(SPRING_CLOUD_RELEASE);
remove(SPRING_CLOUD);
remove(SPRING_CLOUD_STARTER);
this.projects.add(new Project(SPRING_CLOUD_RELEASE, version));
this.projects.add(new Project(SPRING_CLOUD, version));
this.projects.add(new Project(SPRING_CLOUD_STARTER, version));
updateBuildVersions(version);
break;
default:
remove(projectName);
this.projects.add(new Project(projectName, version));
if (bomVersionProjectNames().contains(projectName)) {
updateBomVersions(version);
} else {
remove(projectName);
add(projectName, version);
}
}
return this;
}
private List<String> bomVersionProjectNames() {
List<String> names = new ArrayList<>(this.properties.getMetaRelease()
.getReleaseTrainDependencyNames());
names.add(this.properties.getMetaRelease().getReleaseTrainProjectName());
return names;
}
private void updateBuildVersions(String version) {
this.scBuildVersion = version;
remove(BUILD_ARTIFACT_ID);
remove(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID);
add(BUILD_ARTIFACT_ID, version);
add(CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, version);
}
private void updateBootVersions(String version) {
this.bootVersion = version;
remove(SPRING_BOOT_PROJECT_NAME);
remove(BOOT_DEPENDENCIES_ARTIFACT_ID);
remove(BOOT_STARTER_PARENT_ARTIFACT_ID);
add(SPRING_BOOT_PROJECT_NAME, version);
add(BOOT_STARTER_PARENT_ARTIFACT_ID, version);
add(BOOT_DEPENDENCIES_ARTIFACT_ID, version);
}
private void updateBomVersions(String version) {
remove(bomProjectName());
bomVersionProjectNames().forEach(this::remove);
add(bomProjectName(), version);
bomVersionProjectNames().forEach(s -> add(s, version));
}
private void add(String key, String value) {
this.projects.add(new Project(key, value));
}
private void remove(String expectedProjectName) {
this.projects.removeIf(project -> expectedProjectName.equals(project.name));
}

View File

@@ -114,8 +114,7 @@ public class PostReleaseActions implements Closeable {
List<String> value = e.getValue();
log.info("Running version update for project [{}] and samples {}", key, value);
ProjectVersion projectVersionForReleaseTrain = projects.forName(key);
Projects postRelease = projects
.postReleaseSnapshotVersion(this.properties.getMetaRelease().getProjectsToSkip());
Projects postRelease = getPostReleaseProjects(projects);
log.info("Versions to update the samples with \n" + postRelease.stream()
.map(v -> "[" + v.projectName + " => " + v.version + "]")
.collect(Collectors.joining("\n")));
@@ -127,6 +126,11 @@ public class PostReleaseActions implements Closeable {
});
}
Projects getPostReleaseProjects(Projects projects) {
return projects
.postReleaseSnapshotVersion(this.properties.getMetaRelease().getProjectsToSkip());
}
private void commitUpdatedProject(Projects projects, String key, ProjectVersion projectVersionForReleaseTrain, Projects postRelease, String url) {
String releaseTrainVersion = projects
.forName(this.properties.getMetaRelease().getReleaseTrainProjectName()).version;

View File

@@ -2,7 +2,6 @@ package org.springframework.cloud.release.internal.project;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;

View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Marcin Grzejszczak

View File

@@ -3,11 +3,9 @@ package org.springframework.cloud.release.internal.sagan;
import java.net.URI;
import java.util.List;
import edu.emory.mathcs.backport.java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;

View File

@@ -2,22 +2,17 @@ package org.springframework.cloud.release.internal.template;
import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.github.jknack.handlebars.Template;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.Projects;
import org.springframework.util.StringUtils;
import com.github.jknack.handlebars.Template;
import com.google.common.collect.ImmutableMap;
/**
* @author Marcin Grzejszczak