Added checkstyle rules

This commit is contained in:
Marcin Grzejszczak
2019-02-15 12:13:54 +01:00
parent 02bbd93a81
commit 591d22ed83
376 changed files with 11007 additions and 5402 deletions

24
.editorconfig Normal file
View File

@@ -0,0 +1,24 @@
root = true
[*.java]
indent_style = tab
indent_size = 4
continuation_indent_size = 8
[*.groovy]
indent_style = tab
indent_size = 4
continuation_indent_size = 8
[*.xml]
indent_style = tab
indent_size = 4
continuation_indent_size = 8
[*.yml]
indent_style = space
indent_size = 2
[*.yaml]
indent_style = space
indent_size = 2

View File

@@ -1,73 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--
Turns on jdk8 for tests
-->
<id>ide</id>
<activation><activeByDefault>true</activeByDefault></activation>
</profile>
</profiles>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--
Turns on jdk8 for tests
-->
<id>ide</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
</settings>

1
.springformat Normal file
View File

@@ -0,0 +1 @@

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<parent>
<groupId>org.springframework.cloud.internal</groupId>

36
pom.xml
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.BUILD-SNAPSHOT</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
@@ -24,7 +24,13 @@
</modules>
<properties>
<spring-cloud-bom.version>Greenwich.RELEASE</spring-cloud-bom.version>
<spring-cloud-bom.version>Greenwich.BUILD-SNAPSHOT</spring-cloud-bom.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
</maven-checkstyle-plugin.failsOnViolation>
<maven-checkstyle-plugin.includeTestSourceDirectory>true
</maven-checkstyle-plugin.includeTestSourceDirectory>
</properties>
<dependencyManagement>
@@ -39,6 +45,28 @@
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<repositories>
<repository>
<id>spring-snapshots</id>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
import java.io.File;
@@ -22,24 +54,34 @@ import org.springframework.util.Assert;
* @author Marcin Grzejszczak
*/
public class Releaser {
private static final Logger log = LoggerFactory.getLogger(Releaser.class);
private static boolean ASSERT_SNAPSHOTS = true;
private static boolean SKIP_SNAPSHOT_ASSERTION = false;
private final ProjectPomUpdater projectPomUpdater;
private final ProjectBuilder projectBuilder;
private final ProjectGitHandler projectGitHandler;
private final TemplateGenerator templateGenerator;
private final GradleUpdater gradleUpdater;
private final SaganUpdater saganUpdater;
private final DocumentationUpdater documentationUpdater;
private final PostReleaseActions postReleaseActions;
public Releaser(ProjectPomUpdater projectPomUpdater, ProjectBuilder projectBuilder,
ProjectGitHandler projectGitHandler, TemplateGenerator templateGenerator,
GradleUpdater gradleUpdater, SaganUpdater saganUpdater,
DocumentationUpdater documentationUpdater, PostReleaseActions postReleaseActions) {
DocumentationUpdater documentationUpdater,
PostReleaseActions postReleaseActions) {
this.projectPomUpdater = projectPomUpdater;
this.projectBuilder = projectBuilder;
this.projectGitHandler = projectGitHandler;
@@ -71,8 +113,8 @@ public class Releaser {
ProjectVersion versionFromScRelease, boolean assertSnapshots) {
this.projectPomUpdater.updateProjectFromReleaseTrain(project, versions,
versionFromScRelease, assertSnapshots);
this.gradleUpdater.updateProjectFromBom(project, versions,
versionFromScRelease, assertSnapshots);
this.gradleUpdater.updateProjectFromBom(project, versions, versionFromScRelease,
assertSnapshots);
ProjectVersion changedVersion = new ProjectVersion(project);
log.info("\n\nProject was successfully updated to [{}]", changedVersion);
}
@@ -97,7 +139,8 @@ public class Releaser {
log.info("\nThe docs were published successfully");
}
public void rollbackReleaseVersion(File project, Projects projects, ProjectVersion scReleaseVersion) {
public void rollbackReleaseVersion(File project, Projects projects,
ProjectVersion scReleaseVersion) {
if (scReleaseVersion.isSnapshot()) {
log.info("\nWon't rollback a snapshot version");
return;
@@ -105,15 +148,17 @@ public class Releaser {
this.projectGitHandler.revertChangesIfApplicable(project, scReleaseVersion);
ProjectVersion originalVersion = originalVersion(project);
log.info("Original project version is [{}]", originalVersion);
if ((scReleaseVersion.isRelease() || scReleaseVersion
.isServiceRelease()) && originalVersion.isSnapshot()) {
if ((scReleaseVersion.isRelease() || scReleaseVersion.isServiceRelease())
&& originalVersion.isSnapshot()) {
Projects newProjects = Projects.forRollback(projects, originalVersion);
updateProjectFromBom(project, newProjects, originalVersion, SKIP_SNAPSHOT_ASSERTION);
updateProjectFromBom(project, newProjects, originalVersion,
SKIP_SNAPSHOT_ASSERTION);
this.projectGitHandler.commitAfterBumpingVersions(project, originalVersion);
log.info("\nSuccessfully reverted the commit and bumped snapshot versions");
}
else {
log.info("\nSuccessfully reverted the commit and came back to snapshot versions");
log.info(
"\nSuccessfully reverted the commit and came back to snapshot versions");
}
}
@@ -134,14 +179,17 @@ public class Releaser {
try {
this.projectGitHandler.closeMilestone(releaseVersion);
log.info("\nSuccessfully closed milestone");
} catch (Exception ex) {
}
catch (Exception ex) {
throw new MakeBuildUnstableException("Failed to create an email template");
}
}
public void createEmail(ProjectVersion releaseVersion, Projects projects) {
Assert.notNull(releaseVersion, "You must provide a release version for your project");
Assert.notNull(releaseVersion.version, "You must provide a release version for your project");
Assert.notNull(releaseVersion,
"You must provide a release version for your project");
Assert.notNull(releaseVersion.version,
"You must provide a release version for your project");
if (releaseVersion.isSnapshot()) {
log.info("\nWon't create email template for a SNAPSHOT version");
return;
@@ -152,11 +200,13 @@ public class Releaser {
log.info("\nSuccessfully created email template at location [{}]", email);
}
else {
throw new MakeBuildUnstableException("Failed to create an email template");
throw new MakeBuildUnstableException(
"Failed to create an email template");
}
}
catch (Exception ex) {
throw new MakeBuildUnstableException("Failed to create an email template", ex);
throw new MakeBuildUnstableException("Failed to create an email template",
ex);
}
}
@@ -181,14 +231,16 @@ public class Releaser {
public void updateSpringGuides(ProjectVersion releaseVersion, Projects projects) {
if (!(releaseVersion.isRelease() || releaseVersion.isServiceRelease())) {
log.info("\nWon't update Spring Guides for a non Release / Service Release version");
log.info(
"\nWon't update Spring Guides for a non Release / Service Release version");
return;
}
try {
this.projectGitHandler.createIssueInSpringGuides(projects, releaseVersion);
}
catch (Exception ex) {
throw new MakeBuildUnstableException("Successfully updated Spring Guides issues", ex);
throw new MakeBuildUnstableException(
"Successfully updated Spring Guides issues", ex);
}
}
@@ -237,10 +289,12 @@ public class Releaser {
}
}
public void updateDocumentationRepository(ReleaserProperties properties, ProjectVersion releaseVersion) {
public void updateDocumentationRepository(ReleaserProperties properties,
ProjectVersion releaseVersion) {
String releaseBranch = properties.getPom().getBranch();
this.documentationUpdater.updateDocsRepo(releaseVersion, releaseBranch);
log.info("\nSuccessfully updated documentation repository for branch [{}]", releaseBranch);
log.info("\nSuccessfully updated documentation repository for branch [{}]",
releaseBranch);
}
public void updateSpringProjectPage(Projects projects) {
@@ -271,4 +325,5 @@ public class Releaser {
this.documentationUpdater.updateReleaseTrainWiki(projects);
log.info("\nSuccessfully updated project wiki");
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
import java.io.Serializable;
@@ -29,8 +46,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
/**
* Since, we are making a deep copy of this object, remember to have all the
* nested classes to implement the Serializable interface.
* Since, we are making a deep copy of this object, remember to have all the nested
* classes to implement the Serializable interface.
*
* @author Marcin Grzejszczak
*/
@@ -44,7 +61,7 @@ public class ReleaserProperties implements Serializable {
private String workingDir;
/**
* If set to {@code true} will run only post release tasks
* If set to {@code true} will run only post release tasks.
*/
private boolean postReleaseTasksOnly = false;
@@ -61,40 +78,133 @@ public class ReleaserProperties implements Serializable {
private Template template = new Template();
/**
* Project name to its version - overrides all versions
* retrieved from a repository like Spring Cloud Release
* Project name to its version - overrides all versions retrieved from a repository
* like Spring Cloud Release.
*/
private Map<String, String> fixedVersions = new LinkedHashMap<>();
private MetaRelease metaRelease = new MetaRelease();
public String getWorkingDir() {
return StringUtils.hasText(this.workingDir) ? this.workingDir
: System.getProperty("user.dir");
}
public void setWorkingDir(String workingDir) {
this.workingDir = workingDir;
}
public Git getGit() {
return this.git;
}
public void setGit(Git git) {
this.git = git;
}
public Pom getPom() {
return this.pom;
}
public void setPom(Pom pom) {
this.pom = pom;
}
public Maven getMaven() {
return this.maven;
}
public void setMaven(Maven maven) {
this.maven = maven;
}
public Gradle getGradle() {
return this.gradle;
}
public void setGradle(Gradle gradle) {
this.gradle = gradle;
}
public Map<String, String> getFixedVersions() {
return this.fixedVersions;
}
public void setFixedVersions(Map<String, String> fixedVersions) {
this.fixedVersions = fixedVersions;
}
public MetaRelease getMetaRelease() {
return this.metaRelease;
}
public void setMetaRelease(MetaRelease metaRelease) {
this.metaRelease = metaRelease;
}
public Sagan getSagan() {
return this.sagan;
}
public void setSagan(Sagan sagan) {
this.sagan = sagan;
}
public Template getTemplate() {
return this.template;
}
public void setTemplate(Template template) {
this.template = template;
}
public boolean isPostReleaseTasksOnly() {
return this.postReleaseTasksOnly;
}
public void setPostReleaseTasksOnly(boolean postReleaseTasksOnly) {
this.postReleaseTasksOnly = postReleaseTasksOnly;
}
@Override
public String toString() {
return "ReleaserProperties{" + "workingDir='" + this.workingDir + '\'' + ", git="
+ this.git + ", pom=" + this.pom + ", maven=" + this.maven + ", gradle="
+ this.gradle + ", sagan=" + this.sagan + ", fixedVersions="
+ this.fixedVersions + ", metaRelease=" + this.metaRelease + ", template="
+ this.template + '}';
}
public ReleaserProperties copy() {
return (ReleaserProperties) SerializationUtils.clone(this);
}
public static class MetaRelease implements Serializable {
/**
* Are we releasing the whole suite of apps or only one?
*/
private boolean enabled = false;
/**
* Name of the release train project
* Name of the release train project.
*/
private String releaseTrainProjectName = "spring-cloud-release";
/**
* All the names of dependencies that should be updated with the release
* train project version
* 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"
);
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
* The URL of the Git organization. We'll append each project's name to it.
*/
private String gitOrgUrl = "https://github.com/spring-cloud";
/**
* Names of projects to skip deployment for meta-release
* Names of projects to skip deployment for meta-release.
*/
private List<String> projectsToSkip = new ArrayList<String>() {
{
@@ -132,7 +242,8 @@ public class ReleaserProperties implements Serializable {
return this.releaseTrainDependencyNames;
}
public void setReleaseTrainDependencyNames(List<String> releaseTrainDependencyNames) {
public void setReleaseTrainDependencyNames(
List<String> releaseTrainDependencyNames) {
this.releaseTrainDependencyNames = releaseTrainDependencyNames;
}
@@ -146,101 +257,102 @@ public class ReleaserProperties implements Serializable {
@Override
public String toString() {
return "MetaRelease{" +
"enabled=" + this.enabled +
", releaseTrainProjectName='" + this.releaseTrainProjectName + '\'' +
", gitOrgUrl='" + this.gitOrgUrl + '\'' +
", projectsToSkip=" + this.projectsToSkip +
'}';
return "MetaRelease{" + "enabled=" + this.enabled
+ ", releaseTrainProjectName='" + this.releaseTrainProjectName + '\''
+ ", gitOrgUrl='" + this.gitOrgUrl + '\'' + ", projectsToSkip="
+ this.projectsToSkip + '}';
}
}
public static class Git implements Serializable {
/**
* URL to Spring Cloud Release Git repository
* URL to Spring Cloud Release Git repository.
*/
private String releaseTrainBomUrl = "https://github.com/spring-cloud/spring-cloud-release";
/**
* URL to the documentation Git repository
* URL to the documentation Git repository.
*/
private String documentationUrl = "https://github.com/spring-cloud/spring-cloud-static";
/**
* URL to main release train project repository
* URL to main release train project repository.
*/
private String springProjectUrl = "https://github.com/spring-projects/spring-cloud";
/**
* URL to test samples
* URL to test samples.
*/
private String testSamplesProjectUrl = "https://github.com/spring-cloud/spring-cloud-core-tests";
/**
* URL to the release train documentation
* URL to the release train documentation.
*/
private String releaseTrainDocsUrl = "https://github.com/spring-cloud-samples/scripts";
/**
* URL to the release train wiki
* URL to the release train wiki.
*/
private String releaseTrainWikiUrl = "https://github.com/spring-projects/spring-cloud.wiki";
/**
* Branch to check out for the documentation project
* Branch to check out for the documentation project.
*/
private String documentationBranch = "gh-pages";
/**
* Branch to check out for the release train project
* Branch to check out for the release train project.
*/
private String springProjectBranch = "gh-pages";
/**
* Branch to check out for the test samples
* Branch to check out for the test samples.
*/
private String testSamplesBranch = "master";
/**
* Branch to check out for the release train docs
* Branch to check out for the release train docs.
*/
private String releaseTrainDocsBranch = "master";
/**
* Page prefix for the release train wiki. E.g. for [Spring-Cloud-Finchley-Release-Notes]
* it would be [Spring-Cloud].
* Page prefix for the release train wiki. E.g. for
* [Spring-Cloud-Finchley-Release-Notes] it would be [Spring-Cloud].
*/
private String releaseTrainWikiPagePrefix = "Spring-Cloud";
/**
* Where should the Spring Cloud Release repo get cloned to. If {@code null} defaults to a temporary directory
* Where should the Spring Cloud Release repo get cloned to. If {@code null}
* defaults to a temporary directory.
*/
private String cloneDestinationDir;
/**
* If {@code true} then should fill the map of versions from Git. If {@code false} then picks fixed versions
* If {@code true} then should fill the map of versions from Git. If {@code false}
* then picks fixed versions.
*/
private boolean fetchVersionsFromGit = true;
/**
* GitHub OAuth token to be used to interact with GitHub repo
* GitHub OAuth token to be used to interact with GitHub repo.
*/
private String oauthToken = "";
/**
* Optional Git username. If not passed keys will be used for authentication
* Optional Git username. If not passed keys will be used for authentication.
*/
private String username;
/**
* Optional Git password. If not passed keys will be used for authentication
* Optional Git password. If not passed keys will be used for authentication.
*/
private String password;
/**
* In order not to iterate endlessly over milestones we introduce a threshold of milestones
* that we will go through to find the matching milestone
* In order not to iterate endlessly over milestones we introduce a threshold of
* milestones that we will go through to find the matching milestone.
*/
private Integer numberOfCheckedMilestones = 50;
@@ -255,28 +367,29 @@ public class ReleaserProperties implements Serializable {
private boolean updateSpringGuides = true;
/**
* If set to {@code false}, will not update the Spring Project for a release train.
* E.g. for Spring Cloud will not update https://cloud.spring.io
* If set to {@code false}, will not update the Spring Project for a release
* train. E.g. for Spring Cloud will not update https://cloud.spring.io .
*/
private boolean updateSpringProject = true;
/**
* If set to {@code false}, will not update the test samples
* If set to {@code false}, will not update the test samples.
*/
private boolean runUpdatedSamples = true;
/**
* If set to {@code false}, will not update the release train docs
* If set to {@code false}, will not update the release train docs.
*/
private boolean updateReleaseTrainDocs = true;
/**
* If set to {@code false}, will not clone and update the release train wiki
* If set to {@code false}, will not clone and update the release train wiki.
*/
private boolean updateReleaseTrainWiki = true;
/**
* If set to {@code false}, will not clone and update the samples for all projects
* If set to {@code false}, will not clone and update the samples for all
* projects.
*/
private boolean updateAllTestSamples = true;
@@ -286,15 +399,13 @@ public class ReleaserProperties implements Serializable {
*/
private Map<String, List<String>> allTestSampleUrls = new HashMap<String, List<String>>() {
{
this.put("spring-cloud-sleuth" , Arrays.asList(
this.put("spring-cloud-sleuth", Arrays.asList(
"https://github.com/spring-cloud-samples/sleuth-issues",
"https://github.com/spring-cloud-samples/sleuth-documentation-apps")
);
this.put("spring-cloud-contract" , Arrays.asList(
"https://github.com/spring-cloud-samples/sleuth-documentation-apps"));
this.put("spring-cloud-contract", Arrays.asList(
"https://github.com/spring-cloud-samples/spring-cloud-contract-samples",
"https://github.com/spring-cloud-samples/the-legacy-app",
"https://github.com/spring-cloud-samples/sc-contract-car-rental")
);
"https://github.com/spring-cloud-samples/sc-contract-car-rental"));
}
};
@@ -366,6 +477,10 @@ public class ReleaserProperties implements Serializable {
return this.runUpdatedSamples;
}
public void setRunUpdatedSamples(boolean runUpdatedSamples) {
this.runUpdatedSamples = runUpdatedSamples;
}
public boolean isUpdateAllTestSamples() {
return this.updateAllTestSamples;
}
@@ -374,10 +489,6 @@ public class ReleaserProperties implements Serializable {
this.updateAllTestSamples = updateAllTestSamples;
}
public void setRunUpdatedSamples(boolean runUpdatedSamples) {
this.runUpdatedSamples = runUpdatedSamples;
}
public String getCloneDestinationDir() {
return this.cloneDestinationDir;
}
@@ -500,57 +611,57 @@ public class ReleaserProperties implements Serializable {
@Override
public String toString() {
return "Git{" +
"releaseTrainBomUrl='" + this.releaseTrainBomUrl + '\'' +
", documentationUrl='" + this.documentationUrl + '\'' +
", documentationBranch='" + this.documentationBranch + '\'' +
", releaseTrainWikiUrl='" + this.releaseTrainWikiUrl + '\'' +
", updateDocumentationRepo=" + this.updateDocumentationRepo +
", springProjectUrl=" + this.springProjectUrl+
", springProjectBranch=" + this.springProjectBranch +
", releaseTrainWikiPagePrefix=" + this.releaseTrainWikiPagePrefix +
", cloneDestinationDir='" + this.cloneDestinationDir + '\'' +
", fetchVersionsFromGit=" + this.fetchVersionsFromGit +
", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones +
", updateSpringGuides=" + this.updateSpringGuides +
", updateSpringProject=" + this.updateSpringProject +
", sampleUrlsSize=" + this.allTestSampleUrls.size() +
'}';
return "Git{" + "releaseTrainBomUrl='" + this.releaseTrainBomUrl + '\''
+ ", documentationUrl='" + this.documentationUrl + '\''
+ ", documentationBranch='" + this.documentationBranch + '\''
+ ", releaseTrainWikiUrl='" + this.releaseTrainWikiUrl + '\''
+ ", updateDocumentationRepo=" + this.updateDocumentationRepo
+ ", springProjectUrl=" + this.springProjectUrl
+ ", springProjectBranch=" + this.springProjectBranch
+ ", releaseTrainWikiPagePrefix=" + this.releaseTrainWikiPagePrefix
+ ", cloneDestinationDir='" + this.cloneDestinationDir + '\''
+ ", fetchVersionsFromGit=" + this.fetchVersionsFromGit
+ ", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones
+ ", updateSpringGuides=" + this.updateSpringGuides
+ ", updateSpringProject=" + this.updateSpringProject
+ ", sampleUrlsSize=" + this.allTestSampleUrls.size() + '}';
}
}
public static class Pom implements Serializable {
/**
* Which branch of release train BOM 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
* 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
* 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
* 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.
* List of regular expressions of ignored poms. Defaults to test projects and
* samples.
*/
@SuppressWarnings("unchecked")
private List<String> ignoredPomRegex = Arrays.asList(
"^.*\\.git/.*$",
private List<String> ignoredPomRegex = Arrays.asList("^.*\\.git/.*$",
"^.*spring-cloud-contract-maven-plugin/src/test/projects/.*$",
"^.*spring-cloud-contract-maven-plugin/target/.*$",
"^.*samples/standalone/[a-z]+/.*$"
);
"^.*samples/standalone/[a-z]+/.*$");
public String getBranch() {
return this.branch;
@@ -594,54 +705,57 @@ public class ReleaserProperties implements Serializable {
@Override
public String toString() {
return "Pom{" +
"branch='" + this.branch + '\'' +
", pomWithBootStarterParent='" + this.pomWithBootStarterParent + '\'' +
", thisTrainBom='" + this.thisTrainBom + '\'' +
", bomVersionPattern='" + this.bomVersionPattern + '\'' +
", ignoredPomRegex=" + this.ignoredPomRegex +
'}';
return "Pom{" + "branch='" + this.branch + '\''
+ ", pomWithBootStarterParent='" + this.pomWithBootStarterParent
+ '\'' + ", thisTrainBom='" + this.thisTrainBom + '\''
+ ", bomVersionPattern='" + this.bomVersionPattern + '\''
+ ", ignoredPomRegex=" + this.ignoredPomRegex + '}';
}
}
public static class Maven implements Serializable {
/**
* Command to be executed to build the project
* Placeholder for system properties.
*/
public static final String SYSTEM_PROPS_PLACEHOLDER = "{{systemProps}}";
/**
* Command to be executed to build the project.
*/
private String buildCommand = "./mvnw clean install -B -Pdocs {{systemProps}}";
/**
* Command to be executed to deploy a built project
* Command to be executed to deploy a built project.
*/
private String deployCommand = "./mvnw deploy -DskipTests -B -Pfast,deploy {{systemProps}}";
/**
* Command to be executed to publish documentation. If present "{{version}}" will be replaced by the
* provided version
* Command to be executed to publish documentation. If present "{{version}}" will
* be replaced by the provided version.
*/
private String[] publishDocsCommands = {
"mkdir -p target",
"wget https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/ghpages.sh -O target/gh-pages.sh",
"chmod +x target/gh-pages.sh",
"./target/gh-pages.sh -v {{version}} -c"
};
private String[] publishDocsCommands = { "mkdir -p target",
"wget https://raw.githubusercontent.com/spring-cloud/"
+ "spring-cloud-build/master/"
+ "docs/src/main/asciidoc/ghpages.sh -O target/gh-pages.sh",
"chmod +x target/gh-pages.sh", "./target/gh-pages.sh -v {{version}} -c" };
/**
* Command to be executed to generate release train documentation
* Command to be executed to generate release train documentation.
*/
private String generateReleaseTrainDocsCommand = "bash release_train.sh --retrieveversions --version {{version}} --ghpages --auto";
public static final String SYSTEM_PROPS_PLACEHOLDER = "{{systemProps}}";
private String generateReleaseTrainDocsCommand = "bash release_train.sh "
+ "--retrieveversions --version {{version}} --ghpages --auto";
/**
* Additional system properties that should be passed to the build / deploy commands.
* If present in other commands "{{systemProps}}" will be substituted with this property.
* Additional system properties that should be passed to the build / deploy
* commands. If present in other commands "{{systemProps}}" will be substituted
* with this property.
*/
private String systemProperties = "";
/**
* Max wait time in minutes for the process to finish
* Max wait time in minutes for the process to finish.
*/
private long waitTimeInMinutes = 20;
@@ -673,18 +787,19 @@ public class ReleaserProperties implements Serializable {
return this.publishDocsCommands;
}
public void setPublishDocsCommands(String[] publishDocsCommands) {
this.publishDocsCommands = publishDocsCommands;
}
public String getGenerateReleaseTrainDocsCommand() {
return this.generateReleaseTrainDocsCommand;
}
public void setGenerateReleaseTrainDocsCommand(String generateReleaseTrainDocsCommand) {
public void setGenerateReleaseTrainDocsCommand(
String generateReleaseTrainDocsCommand) {
this.generateReleaseTrainDocsCommand = generateReleaseTrainDocsCommand;
}
public void setPublishDocsCommands(String[] publishDocsCommands) {
this.publishDocsCommands = publishDocsCommands;
}
public String getSystemProperties() {
return this.systemProperties;
}
@@ -693,26 +808,29 @@ public class ReleaserProperties implements Serializable {
this.systemProperties = systemProperties;
}
@Override public String toString() {
return "Maven{" + "buildCommand='" + this.buildCommand + '\'' + ", deployCommand='"
+ this.deployCommand + '\'' + ", publishDocsCommands=" + Arrays
.toString(this.publishDocsCommands) +
"generateReleaseTrainDocsCommand='" + this.generateReleaseTrainDocsCommand + '\'' +
", waitTimeInMinutes=" + this.waitTimeInMinutes + '}';
@Override
public String toString() {
return "Maven{" + "buildCommand='" + this.buildCommand + '\''
+ ", deployCommand='" + this.deployCommand + '\''
+ ", publishDocsCommands=" + Arrays.toString(this.publishDocsCommands)
+ "generateReleaseTrainDocsCommand='"
+ this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes="
+ this.waitTimeInMinutes + '}';
}
}
public static class Gradle implements Serializable {
/**
* A mapping that should be applied to {@code gradle.properties} in order
* to perform a substitution of properties. The mapping is from a property
* inside {@code gradle.properties} to the projects name. Example
* A mapping that should be applied to {@code gradle.properties} in order to
* perform a substitution of properties. The mapping is from a property inside
* {@code gradle.properties} to the projects name. Example.
*
* In {@code gradle.properties} you have {@code verifierVersion=1.0.0} . You
* want this property to get updated with the value of {@code spring-cloud-contract}
* version. Then it's enough to do the mapping like this for this Releaser's property:
* {@code verifierVersion=spring-cloud-contract}
* In {@code gradle.properties} you have {@code verifierVersion=1.0.0} . You want
* this property to get updated with the value of {@code spring-cloud-contract}
* version. Then it's enough to do the mapping like this for this Releaser's
* property: {@code verifierVersion=spring-cloud-contract}.
*/
private Map<String, String> gradlePropsSubstitution = new HashMap<String, String>() {
{
@@ -725,15 +843,14 @@ public class ReleaserProperties implements Serializable {
};
/**
* List of regular expressions of ignored gradle props.
* Defaults to test projects and samples.
* List of regular expressions of ignored gradle props. Defaults to test projects
* and samples.
*/
@SuppressWarnings("unchecked")
private List<String> ignoredGradleRegex = Arrays.asList(
"^.*spring-cloud-contract-maven-plugin/src/test/projects/.*$",
"^.*spring-cloud-contract-maven-plugin/target/.*$",
"^.*samples/standalone/[a-z]+/.*$"
);
"^.*samples/standalone/[a-z]+/.*$");
public Map<String, String> getGradlePropsSubstitution() {
return this.gradlePropsSubstitution;
@@ -752,21 +869,23 @@ public class ReleaserProperties implements Serializable {
this.ignoredGradleRegex = ignoredGradleRegex;
}
@Override public String toString() {
@Override
public String toString() {
return "Gradle{" + "gradlePropsSubstitution=" + this.gradlePropsSubstitution
+ ", ignoredGradleRegex=" + this.ignoredGradleRegex + '}';
}
}
public static class Sagan implements Serializable {
/**
* If set to {@code false} will not update Sagan
* If set to {@code false} will not update Sagan.
*/
private boolean updateSagan = true;
/**
* URL to the Sagan API
* URL to the Sagan API.
*/
private String baseUrl = "https://spring.io";
@@ -786,14 +905,17 @@ public class ReleaserProperties implements Serializable {
this.updateSagan = updateSagan;
}
@Override public String toString() {
@Override
public String toString() {
return "Sagan{" + "baseUrl='" + this.baseUrl + '\'' + '}';
}
}
public static class Template implements Serializable {
/**
* Folder in which blog, email etc. templates are stored
* Folder in which blog, email etc. templates are stored.
*/
private String templateFolder = "cloud";
@@ -807,101 +929,9 @@ public class ReleaserProperties implements Serializable {
@Override
public String toString() {
return "Template{" +
"templateFolder='" + this.templateFolder + '\'' +
'}';
return "Template{" + "templateFolder='" + this.templateFolder + '\'' + '}';
}
}
public String getWorkingDir() {
return StringUtils.hasText(this.workingDir) ?
this.workingDir : System.getProperty("user.dir");
}
public void setWorkingDir(String workingDir) {
this.workingDir = workingDir;
}
public Git getGit() {
return this.git;
}
public void setGit(Git git) {
this.git = git;
}
public Pom getPom() {
return this.pom;
}
public void setPom(Pom pom) {
this.pom = pom;
}
public Maven getMaven() {
return this.maven;
}
public void setMaven(Maven maven) {
this.maven = maven;
}
public Gradle getGradle() {
return this.gradle;
}
public void setGradle(Gradle gradle) {
this.gradle = gradle;
}
public Map<String, String> getFixedVersions() {
return this.fixedVersions;
}
public void setFixedVersions(Map<String, String> fixedVersions) {
this.fixedVersions = fixedVersions;
}
public MetaRelease getMetaRelease() {
return this.metaRelease;
}
public void setMetaRelease(MetaRelease metaRelease) {
this.metaRelease = metaRelease;
}
public Sagan getSagan() {
return this.sagan;
}
public void setSagan(Sagan sagan) {
this.sagan = sagan;
}
public Template getTemplate() {
return this.template;
}
public void setTemplate(Template template) {
this.template = template;
}
public boolean isPostReleaseTasksOnly() {
return this.postReleaseTasksOnly;
}
public void setPostReleaseTasksOnly(boolean postReleaseTasksOnly) {
this.postReleaseTasksOnly = postReleaseTasksOnly;
}
@Override public String toString() {
return "ReleaserProperties{" + "workingDir='" + this.workingDir + '\'' + ", git=" + this.git
+ ", pom=" + this.pom + ", maven=" + this.maven + ", gradle=" + this.gradle + ", sagan="
+ this.sagan + ", fixedVersions=" + this.fixedVersions + ", metaRelease="
+ this.metaRelease + ", template=" + this.template + '}';
}
public ReleaserProperties copy() {
return (ReleaserProperties) SerializationUtils.clone(this);
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
/**
@@ -6,4 +38,5 @@ package org.springframework.cloud.release.internal;
public interface ReleaserPropertiesAware {
void setReleaserProperties(ReleaserProperties properties);
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -15,18 +47,22 @@ import org.springframework.cloud.release.internal.template.TemplateGenerator;
public class DocumentationUpdater implements ReleaserPropertiesAware {
private final ProjectDocumentationUpdater projectDocumentationUpdater;
private final ReleaseTrainContentsUpdater releaseTrainContentsUpdater;
private ReleaserProperties properties;
public DocumentationUpdater(ProjectGitHandler gitHandler, ReleaserProperties properties,
TemplateGenerator templateGenerator) {
public DocumentationUpdater(ProjectGitHandler gitHandler,
ReleaserProperties properties, TemplateGenerator templateGenerator) {
this.properties = properties;
this.projectDocumentationUpdater = new ProjectDocumentationUpdater(this.properties, gitHandler);
this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(this.properties, gitHandler,
templateGenerator);
this.projectDocumentationUpdater = new ProjectDocumentationUpdater(
this.properties, gitHandler);
this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(
this.properties, gitHandler, templateGenerator);
}
DocumentationUpdater(ReleaserProperties properties, ProjectDocumentationUpdater updater,
DocumentationUpdater(ReleaserProperties properties,
ProjectDocumentationUpdater updater,
ReleaseTrainContentsUpdater contentsUpdater) {
this.properties = properties;
this.projectDocumentationUpdater = updater;
@@ -34,34 +70,34 @@ public class DocumentationUpdater implements ReleaserPropertiesAware {
}
/**
* Updates the documentation repository if current release train version is greater or equal
* than the one stored in the repo.
*
* @param currentProject
* @param springCloudReleaseBranch
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used
* Updates the documentation repository if current release train version is greater or
* equal than the one stored in the repo.
* @param currentProject the project we're parsing
* @param bomReleaseBranch branch of the BOM
* @return {@link File cloned temporary directory} - {@code null} if wrong version is
* used
*/
public File updateDocsRepo(ProjectVersion currentProject, String springCloudReleaseBranch) {
return this.projectDocumentationUpdater
.updateDocsRepo(currentProject, springCloudReleaseBranch);
public File updateDocsRepo(ProjectVersion currentProject, String bomReleaseBranch) {
return this.projectDocumentationUpdater.updateDocsRepo(currentProject,
bomReleaseBranch);
}
/**
* Updates the project page if current release train version is greater or equal
* than the one stored in the repo.
*
* @param projects
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used or the switch is turned off
* Updates the project page if current release train version is greater or equal than
* the one stored in the repo.
* @param projects list of projects to update versions for
* @return {@link File cloned temporary directory} - {@code null} if wrong version is
* used or the switch is turned off
*/
public File updateProjectRepo(Projects projects) {
return this.releaseTrainContentsUpdater.updateProjectRepo(projects);
}
/**
* Updates the release train wiki page
*
* @param projects
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used or the switch is turned off
* Updates the release train wiki page.
* @param projects list of projects to update versions for
* @return {@link File cloned temporary directory} - {@code null} if wrong version is
* used or the switch is turned off
*/
public File updateReleaseTrainWiki(Projects projects) {
return this.releaseTrainContentsUpdater.updateReleaseTrainWiki(projects);
@@ -73,4 +109,5 @@ public class DocumentationUpdater implements ReleaserPropertiesAware {
this.projectDocumentationUpdater.setReleaserProperties(properties);
this.releaseTrainContentsUpdater.setReleaserProperties(properties);
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -18,9 +50,12 @@ import org.springframework.cloud.release.internal.pom.ProjectVersion;
class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
private static final String SC_STATIC_URL = "http://cloud.spring.io/spring-cloud-static/";
private static final Logger log = LoggerFactory.getLogger(ProjectDocumentationUpdater.class);
private static final Logger log = LoggerFactory
.getLogger(ProjectDocumentationUpdater.class);
private final ProjectGitHandler gitHandler;
private ReleaserProperties properties;
ProjectDocumentationUpdater(ReleaserProperties properties,
@@ -30,21 +65,24 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
}
/**
* Updates the documentation repository if current release train version is greater or equal
* than the one stored in the repo.
*
* @param currentProject
* @param springCloudReleaseBranch
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used
* Updates the documentation repository if current release train version is greater or
* equal than the one stored in the repo.
* @param currentProject project to update the docs repo for
* @param bomBranch the bom project branch
* @return {@link File cloned temporary directory} - {@code null} if wrong version is
* used
*/
File updateDocsRepo(ProjectVersion currentProject, String springCloudReleaseBranch) {
File updateDocsRepo(ProjectVersion currentProject, String bomBranch) {
if (!this.properties.getGit().isUpdateDocumentationRepo()) {
log.info("Will not update documentation repository, since the switch to do so "
+ "is off. Set [releaser.git.update-documentation-repo] to [true] to change that");
log.info(
"Will not update documentation repository, since the switch to do so "
+ "is off. Set [releaser.git.update-documentation-repo] to [true] to change that");
return null;
}
if (!currentProject.isReleaseOrServiceRelease()) {
log.info("Will not update documentation repository for non release or service release [{}]", currentProject.version);
log.info(
"Will not update documentation repository for non release or service release [{}]",
currentProject.version);
return null;
}
File documentationProject = this.gitHandler.cloneDocumentationProject();
@@ -52,28 +90,38 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
String pathToIndexHtml = "current/index.html";
File indexHtml = new File(documentationProject, pathToIndexHtml);
if (!indexHtml.exists()) {
throw new IllegalStateException("index.html is not present at [" + pathToIndexHtml + "]");
throw new IllegalStateException(
"index.html is not present at [" + pathToIndexHtml + "]");
}
return updateTheDocsRepo(springCloudReleaseBranch, documentationProject, indexHtml);
return updateTheDocsRepo(bomBranch, documentationProject, indexHtml);
}
private File updateTheDocsRepo(String springCloudReleaseBranch, File documentationProject, File indexHtml) {
private File updateTheDocsRepo(String springCloudReleaseBranch,
File documentationProject, File indexHtml) {
try {
String indexHtmlText = readIndexHtmlContents(indexHtml);
int index = indexHtmlText.indexOf(SC_STATIC_URL);
if (index == -1) {
throw new IllegalStateException("The URL to the documentation repo not found in the index.html file");
throw new IllegalStateException(
"The URL to the documentation repo not found in the index.html file");
}
int beginIndex = index + SC_STATIC_URL.length();
String storedReleaseTrainLine = indexHtmlText.substring(beginIndex);
String storedReleaseTrain = storedReleaseTrainLine.substring(0, storedReleaseTrainLine.indexOf("/"));
String firstLetterOfReleaseTrain = String.valueOf(storedReleaseTrain.charAt(0));
String currentReleaseTrainVersion = branchToReleaseVersion(springCloudReleaseBranch);
String firstLetterOfCurrentReleaseTrain = String.valueOf(currentReleaseTrainVersion.charAt(0));
boolean newerOrEqualReleaseTrain = (!storedReleaseTrain.equals(currentReleaseTrainVersion)) && firstLetterOfCurrentReleaseTrain
.compareToIgnoreCase(firstLetterOfReleaseTrain) >= 0;
String storedReleaseTrain = storedReleaseTrainLine.substring(0,
storedReleaseTrainLine.indexOf("/"));
String firstLetterOfReleaseTrain = String
.valueOf(storedReleaseTrain.charAt(0));
String currentReleaseTrainVersion = branchToReleaseVersion(
springCloudReleaseBranch);
String firstLetterOfCurrentReleaseTrain = String
.valueOf(currentReleaseTrainVersion.charAt(0));
boolean newerOrEqualReleaseTrain = (!storedReleaseTrain
.equals(currentReleaseTrainVersion))
&& firstLetterOfCurrentReleaseTrain
.compareToIgnoreCase(firstLetterOfReleaseTrain) >= 0;
if (!newerOrEqualReleaseTrain) {
log.info("Current release train [{}] is not newer than the stored one [{}]",
log.info(
"Current release train [{}] is not newer than the stored one [{}]",
currentReleaseTrainVersion, storedReleaseTrain);
return documentationProject;
}
@@ -95,11 +143,14 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
private File pushCommitedChanges(String currentReleaseTrainVersion,
File documentationProject, File indexHtml, String indexHtmlText,
String storedReleaseTrain) throws IOException {
String replacedIndexHtml = indexHtmlText.replace(storedReleaseTrain, currentReleaseTrainVersion);
String replacedIndexHtml = indexHtmlText.replace(storedReleaseTrain,
currentReleaseTrainVersion);
Files.write(indexHtml.toPath(), replacedIndexHtml.getBytes());
log.info("Stored the release train [{}] in [{}]",
currentReleaseTrainVersion, indexHtml.getAbsolutePath());
this.gitHandler.commit(documentationProject, "Updating the link to the current version to [" + currentReleaseTrainVersion + "]");
log.info("Stored the release train [{}] in [{}]", currentReleaseTrainVersion,
indexHtml.getAbsolutePath());
this.gitHandler.commit(documentationProject,
"Updating the link to the current version to ["
+ currentReleaseTrainVersion + "]");
this.gitHandler.pushCurrentBranch(documentationProject);
log.info("Committed and pushed changes to the documentation project");
return documentationProject;
@@ -113,4 +164,5 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}

View File

@@ -1,10 +1,44 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.util.List;
import java.util.Objects;
public class ReleaseTrainContents {
final Title title;
final List<Row> rows;
ReleaseTrainContents(Title title, List<Row> rows) {
@@ -14,11 +48,15 @@ public class ReleaseTrainContents {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ReleaseTrainContents contents = (ReleaseTrainContents) o;
return Objects.equals(this.title, contents.title) &&
Objects.equals(this.rows, contents.rows);
return Objects.equals(this.title, contents.title)
&& Objects.equals(this.rows, contents.rows);
}
@Override
@@ -33,5 +71,5 @@ public class ReleaseTrainContents {
public List<Row> getRows() {
return this.rows;
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -31,13 +63,18 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory
.getLogger(ReleaseTrainContentsUpdater.class);
private ReleaserProperties properties;
private final ReleaseTrainContentsGitHandler handler;
private final ReleaseTrainContentsParser parser;
private final ReleaseTrainContentsGenerator generator;
private final TemplateGenerator templateGenerator;
ReleaseTrainContentsUpdater(ReleaserProperties properties, ProjectGitHandler handler, TemplateGenerator templateGenerator) {
private ReleaserProperties properties;
ReleaseTrainContentsUpdater(ReleaserProperties properties, ProjectGitHandler handler,
TemplateGenerator templateGenerator) {
this.properties = properties;
this.handler = new ReleaseTrainContentsGitHandler(handler);
this.templateGenerator = templateGenerator;
@@ -46,22 +83,24 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
}
/**
* Updates the project page if current release train version is greater or equal
* than the one stored in the repo.
*
* @param projects
* @return {@link File cloned temporary directory} - {@code null} if wrong version is used or the switch is turned off
* Updates the project page if current release train version is greater or equal than
* the one stored in the repo.
* @param projects projects to update project repo for
* @return {@link File cloned temporary directory} - {@code null} if wrong version is
* used or the switch is turned off
*/
File updateProjectRepo(Projects projects) {
if (!this.properties.getGit().isUpdateSpringProject()) {
log.info("Will not update the Spring Project cause the switch is turned off. Set [releaser.git.update-spring-project=true].");
log.info("Will not update the Spring Project cause "
+ "the switch is turned off. Set [releaser.git.update-spring-project=true].");
return null;
}
File releaseTrainProject = this.handler.cloneSpringDocProject();
File index = new File(releaseTrainProject, "index.html");
ReleaseTrainContents contents = this.parser.parseProjectPage(index);
if (contents == null) {
log.warn("There are no markers for the index.html page - I don't really know what to do, so I'll back away");
log.warn(
"There are no markers for the index.html page - I don't really know what to do, so I'll back away");
return null;
}
String newContents = this.generator.releaseTrainContents(contents, projects);
@@ -72,8 +111,8 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
return pushNewContents(projects, releaseTrainProject, index, newContents);
}
private File pushNewContents(Projects projects, File releaseTrainProject,
File index, String newContents) {
private File pushNewContents(Projects projects, File releaseTrainProject, File index,
String newContents) {
try {
log.debug("Storing new contents to the page");
Files.write(index.toPath(), newContents.getBytes());
@@ -88,28 +127,35 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
}
/**
* Clones the test project, updates it and runs tests
*
* Clones the test project, updates it and runs tests.
* @param projects - set of project with versions to assert against
*/
File updateReleaseTrainWiki(Projects projects) {
if (!this.properties.getGit().isUpdateReleaseTrainWiki() ||
!this.properties.getMetaRelease().isEnabled()) {
log.info("Will not clone and update the release train wiki, since the switch to do so "
+ "is off or it's not a meta-release. Set [releaser.git.update-release-train-wiki] to [true] to change that");
if (!this.properties.getGit().isUpdateReleaseTrainWiki()
|| !this.properties.getMetaRelease().isEnabled()) {
log.info(
"Will not clone and update the release train wiki, since the switch to do so "
+ "is off or it's not a meta-release. Set [releaser.git.update-release-train-wiki] to [true] to change that");
return null;
}
File releaseTrainWiki = this.handler.cloneReleaseTrainWiki();
ProjectVersion releaseTrain = projects.releaseTrain(this.properties);
String releaseTrainName = releaseTrain.major();
String wikiPagePrefix = this.properties.getGit().getReleaseTrainWikiPagePrefix();
String releaseTrainDocFileName = releaseTrainDocFileName(releaseTrainName, wikiPagePrefix);
log.info("Reading the file [{}] for the current release train", releaseTrainDocFileName);
File releaseTrainDocFile = releaseTrainDocFile(releaseTrainWiki, releaseTrainDocFileName);
String releaseVersionFromCurrentFile = this.parser.latestReleaseTrainFromWiki(releaseTrainDocFile);
log.info("Latest release train version in the file is [{}]", releaseVersionFromCurrentFile);
if (!isThisReleaseTrainVersionNewer(releaseTrain, releaseVersionFromCurrentFile)) {
log.info("Current release train version [{}] is not "
String releaseTrainDocFileName = releaseTrainDocFileName(releaseTrainName,
wikiPagePrefix);
log.info("Reading the file [{}] for the current release train",
releaseTrainDocFileName);
File releaseTrainDocFile = releaseTrainDocFile(releaseTrainWiki,
releaseTrainDocFileName);
String releaseVersionFromCurrentFile = this.parser
.latestReleaseTrainFromWiki(releaseTrainDocFile);
log.info("Latest release train version in the file is [{}]",
releaseVersionFromCurrentFile);
if (!isThisReleaseTrainVersionNewer(releaseTrain,
releaseVersionFromCurrentFile)) {
log.info(
"Current release train version [{}] is not "
+ "newer than the version taken from the wiki [{}]",
releaseTrain.version, releaseVersionFromCurrentFile);
return releaseTrainWiki;
@@ -118,7 +164,9 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
releaseTrainName, releaseTrainDocFile, releaseVersionFromCurrentFile);
}
private File generateNewWikiEntry(Projects projects, File releaseTrainWiki, ProjectVersion releaseTrain, String releaseTrainName, File releaseTrainDocFile, String releaseVersionFromCurrentFile) {
private File generateNewWikiEntry(Projects projects, File releaseTrainWiki,
ProjectVersion releaseTrain, String releaseTrainName,
File releaseTrainDocFile, String releaseVersionFromCurrentFile) {
File releaseNotes = this.templateGenerator.releaseNotes(projects);
try {
List<String> lines = Files.readAllLines(releaseTrainDocFile.toPath());
@@ -128,44 +176,54 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
break;
}
}
return insertNewWikiContentBeforeTheLatestRelease(releaseTrainWiki, releaseTrain,
releaseTrainName, releaseTrainDocFile, releaseNotes, lines, lineIndex);
return insertNewWikiContentBeforeTheLatestRelease(releaseTrainWiki,
releaseTrain, releaseTrainName, releaseTrainDocFile, releaseNotes,
lines, lineIndex);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
private File insertNewWikiContentBeforeTheLatestRelease(File releaseTrainWiki, ProjectVersion releaseTrain, String releaseTrainName, File releaseTrainDocFile, File releaseNotes, List<String> lines, int lineIndex) throws IOException {
private File insertNewWikiContentBeforeTheLatestRelease(File releaseTrainWiki,
ProjectVersion releaseTrain, String releaseTrainName,
File releaseTrainDocFile, File releaseNotes, List<String> lines,
int lineIndex) throws IOException {
String newContent = new StringJoiner("\n")
.add(String.join("\n", lines.subList(0, lineIndex)))
.add("\n").add(new String(Files.readAllBytes(releaseNotes.toPath())))
.add(String.join("\n", lines.subList(0, lineIndex))).add("\n")
.add(new String(Files.readAllBytes(releaseNotes.toPath())))
.add(String.join("\n", lines.subList(lineIndex, lines.size())))
.toString();
Files.write(releaseTrainDocFile.toPath(), newContent.getBytes());
log.info("Successfully stored new wiki contents for release train [{}]", releaseTrainName);
log.info("Successfully stored new wiki contents for release train [{}]",
releaseTrainName);
this.handler.commitAndPushChanges(releaseTrainWiki, releaseTrain);
return releaseTrainWiki;
}
private String releaseTrainDocFileName(String releaseTrainName, String wikiPagePrefix) {
return new StringJoiner("-")
.add(wikiPagePrefix).add(releaseTrainName).add("Release-Notes.md").toString();
private String releaseTrainDocFileName(String releaseTrainName,
String wikiPagePrefix) {
return new StringJoiner("-").add(wikiPagePrefix).add(releaseTrainName)
.add("Release-Notes.md").toString();
}
private boolean isThisReleaseTrainVersionNewer(ProjectVersion releaseTrain, String releaseVersionFromCurrentFile) {
private boolean isThisReleaseTrainVersionNewer(ProjectVersion releaseTrain,
String releaseVersionFromCurrentFile) {
if (StringUtils.hasText(releaseVersionFromCurrentFile)) {
return releaseTrain.compareToReleaseTrainName(releaseVersionFromCurrentFile) > 0;
return releaseTrain
.compareToReleaseTrainName(releaseVersionFromCurrentFile) > 0;
}
return true;
}
private File releaseTrainDocFile(File releaseTrainWiki, String releaseTrainDocFileName) {
private File releaseTrainDocFile(File releaseTrainWiki,
String releaseTrainDocFileName) {
File releaseTrainDocFile = new File(releaseTrainWiki, releaseTrainDocFileName);
if (!releaseTrainDocFile.exists()) {
try {
if (!releaseTrainDocFile.createNewFile()) {
throw new IllegalStateException("Failed to create releae train doc file");
throw new IllegalStateException(
"Failed to create releae train doc file");
}
}
catch (IOException e) {
@@ -180,6 +238,7 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
this.properties = properties;
this.generator.setReleaserProperties(properties);
}
}
/**
@@ -189,29 +248,36 @@ class ReleaseTrainContentsGenerator implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory
.getLogger(ReleaseTrainContentsGenerator.class);
private static final String SPRING_PROJECT_TEMPLATE = "spring-project";
private ReleaserProperties properties;
private final File projectOutput;
private ReleaserProperties properties;
ReleaseTrainContentsGenerator(ReleaserProperties properties) {
this.properties = properties;
this.projectOutput = new File("target/index.html");
}
String releaseTrainContents(ReleaseTrainContents currentContents, Projects projects) {
String trainProject = this.properties.getMetaRelease().getReleaseTrainProjectName();
String trainProject = this.properties.getMetaRelease()
.getReleaseTrainProjectName();
ProjectVersion currentReleaseTrainProject = currentReleaseTrainProject(projects);
ProjectVersion lastGa = new ProjectVersion(trainProject, currentContents.title.lastGaTrainName);
ProjectVersion currentGa = new ProjectVersion(trainProject, currentContents.title.currentGaTrainName);
ReleaseTrainContents newReleaseTrainContents = updateReleaseTrainContentsIfNecessary(currentContents, projects,
currentReleaseTrainProject, lastGa, currentGa);
ProjectVersion lastGa = new ProjectVersion(trainProject,
currentContents.title.lastGaTrainName);
ProjectVersion currentGa = new ProjectVersion(trainProject,
currentContents.title.currentGaTrainName);
ReleaseTrainContents newReleaseTrainContents = updateReleaseTrainContentsIfNecessary(
currentContents, projects, currentReleaseTrainProject, lastGa, currentGa);
if (!currentContents.equals(newReleaseTrainContents)) {
Template template = HandlebarsHelper.template(this.properties.getTemplate()
.getTemplateFolder(), SPRING_PROJECT_TEMPLATE);
Template template = HandlebarsHelper.template(
this.properties.getTemplate().getTemplateFolder(),
SPRING_PROJECT_TEMPLATE);
return generate(this.projectOutput, template, newReleaseTrainContents);
}
log.warn("Current release train [{}] is neither last [{}] or current [{}] or the projects haven't changed. Will not update the contents",
log.warn("Current release train [{}] is neither last [{}] "
+ "or current [{}] or the projects haven't changed. Will not update the contents",
currentReleaseTrainProject.version, lastGa, currentGa);
return "";
}
@@ -220,14 +286,16 @@ class ReleaseTrainContentsGenerator implements ReleaserPropertiesAware {
return projects.releaseTrain(this.properties);
}
private String generate(File contentOutput, Template template, ReleaseTrainContents releaseTrainContents) {
private String generate(File contentOutput, Template template,
ReleaseTrainContents releaseTrainContents) {
try {
Map<String, Object> map = ImmutableMap.<String, Object>builder()
.put("lastGaTrainName", releaseTrainContents.title.lastGaTrainName)
.put("currentGaTrainName", releaseTrainContents.title.currentGaTrainName)
.put("currentSnapshotTrainName", releaseTrainContents.title.currentSnapshotTrainName)
.put("projects", releaseTrainContents.rows)
.build();
.put("currentGaTrainName",
releaseTrainContents.title.currentGaTrainName)
.put("currentSnapshotTrainName",
releaseTrainContents.title.currentSnapshotTrainName)
.put("projects", releaseTrainContents.rows).build();
String contents = template.apply(map);
Files.write(contentOutput.toPath(), contents.getBytes());
return contents;
@@ -237,61 +305,77 @@ class ReleaseTrainContentsGenerator implements ReleaserPropertiesAware {
}
}
private ReleaseTrainContents updateReleaseTrainContentsIfNecessary(ReleaseTrainContents currentContents, Projects projects,
ProjectVersion currentReleaseTrainProject, ProjectVersion lastGa, ProjectVersion currentGa) {
private ReleaseTrainContents updateReleaseTrainContentsIfNecessary(
ReleaseTrainContents currentContents, Projects projects,
ProjectVersion currentReleaseTrainProject, ProjectVersion lastGa,
ProjectVersion currentGa) {
ReleaseTrainContents newReleaseTrainContents = currentContents;
// current GA is greater than the last GA
if (greaterMinorOfLastGaReleaseTrain(currentReleaseTrainProject, lastGa)) {
Title title = new Title(currentReleaseTrainProject.version, currentContents.title.currentGaTrainName,
Title title = new Title(currentReleaseTrainProject.version,
currentContents.title.currentGaTrainName,
currentContents.title.currentSnapshotTrainName);
return updatedReleaseTrainContents(currentContents, projects, title, true);
} else if (currentReleaseTrainProject.isSameReleaseTrainName(currentGa.version)) {
Title title = new Title(currentContents.title.lastGaTrainName, currentReleaseTrainProject.isReleaseOrServiceRelease() ?
currentReleaseTrainProject.version : currentContents.title.currentGaTrainName, currentReleaseTrainProject.isSnapshot() ?
currentReleaseTrainProject.version : currentContents.title.currentSnapshotTrainName);
}
else if (currentReleaseTrainProject.isSameReleaseTrainName(currentGa.version)) {
Title title = new Title(currentContents.title.lastGaTrainName,
currentReleaseTrainProject.isReleaseOrServiceRelease()
? currentReleaseTrainProject.version
: currentContents.title.currentGaTrainName,
currentReleaseTrainProject.isSnapshot()
? currentReleaseTrainProject.version
: currentContents.title.currentSnapshotTrainName);
return updatedReleaseTrainContents(currentContents, projects, title, false);
}
return newReleaseTrainContents;
}
private boolean greaterMinorOfLastGaReleaseTrain(ProjectVersion currentReleaseTrainProject, ProjectVersion lastGa) {
return currentReleaseTrainProject.isSameReleaseTrainName(lastGa.version) &&
currentReleaseTrainProject.isReleaseOrServiceRelease() &&
currentReleaseTrainProject.compareToReleaseTrainName(lastGa.version) > 0;
private boolean greaterMinorOfLastGaReleaseTrain(
ProjectVersion currentReleaseTrainProject, ProjectVersion lastGa) {
return currentReleaseTrainProject.isSameReleaseTrainName(lastGa.version)
&& currentReleaseTrainProject.isReleaseOrServiceRelease()
&& currentReleaseTrainProject
.compareToReleaseTrainName(lastGa.version) > 0;
}
private ReleaseTrainContents updatedReleaseTrainContents(ReleaseTrainContents currentContents, Projects projects,
Title title, boolean lastGa) {
private ReleaseTrainContents updatedReleaseTrainContents(
ReleaseTrainContents currentContents, Projects projects, Title title,
boolean lastGa) {
List<Row> rows = Row.fromProjects(projects, lastGa);
return new ReleaseTrainContents(
title, currentContents.rows.stream().map(current -> {
Row projectRow = rows.stream().filter(row ->
current.componentName.equals(row.componentName)).findFirst().orElse(current);
if (projectRow == current) {
return projectRow;
}
return from(current, projectRow);
}).collect(Collectors.toCollection(LinkedList::new)));
return new ReleaseTrainContents(title,
currentContents.rows.stream().map(current -> {
Row projectRow = rows.stream().filter(
row -> current.componentName.equals(row.componentName))
.findFirst().orElse(current);
if (projectRow == current) {
return projectRow;
}
return from(current, projectRow);
}).collect(Collectors.toCollection(LinkedList::new)));
}
private Row from(Row current, Row project) {
return new Row(current.componentName, StringUtils.hasText(project.lastGaVersion) ?
project.lastGaVersion : current.lastGaVersion,
StringUtils.hasText(project.currentGaVersion) ?
project.currentGaVersion : current.currentGaVersion,
StringUtils.hasText(project.currentSnapshotVersion) ?
project.currentSnapshotVersion : current.currentSnapshotVersion);
return new Row(current.componentName,
StringUtils.hasText(project.lastGaVersion) ? project.lastGaVersion
: current.lastGaVersion,
StringUtils.hasText(project.currentGaVersion) ? project.currentGaVersion
: current.currentGaVersion,
StringUtils.hasText(project.currentSnapshotVersion)
? project.currentSnapshotVersion
: current.currentSnapshotVersion);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
class ReleaseTrainContentsGitHandler {
private static final Logger log = LoggerFactory.getLogger(ReleaseTrainContentsGitHandler.class);
private static final Logger log = LoggerFactory
.getLogger(ReleaseTrainContentsGitHandler.class);
private static final String PROJECT_PAGE_UPDATED_COMMIT_MSG = "Updating project page to release train [%s]";
@@ -311,7 +395,8 @@ class ReleaseTrainContentsGitHandler {
void commitAndPushChanges(File repo, ProjectVersion releaseTrain) {
log.debug("Committing and pushing changes");
this.handler.commit(repo, String.format(PROJECT_PAGE_UPDATED_COMMIT_MSG, releaseTrain.version));
this.handler.commit(repo,
String.format(PROJECT_PAGE_UPDATED_COMMIT_MSG, releaseTrain.version));
this.handler.pushCurrentBranch(repo);
}
@@ -327,7 +412,8 @@ class ReleaseTrainContentsParser {
String contents = new String(Files.readAllBytes(rawHtml.toPath()));
String[] split = contents.split("<!-- (BEGIN|END) COMPONENTS -->");
if (split.length != 3) {
log.warn("The page is missing the components table markers. Please add [<!-- BEGIN COMPONENTS -->] and [<!-- END COMPONENTS -->] to the file.");
log.warn("The page is missing the components table markers. "
+ "Please add [<!-- BEGIN COMPONENTS -->] and [<!-- END COMPONENTS -->] to the file.");
return null;
}
String table = split[1];
@@ -349,14 +435,13 @@ class ReleaseTrainContentsParser {
String latestReleaseTrainFromWiki(File rawMd) {
try {
return Files.readAllLines(rawMd.toPath()).stream()
.filter(s -> s.trim().startsWith("#"))
.map(s -> s.substring(1).trim())
.filter(s -> new ProjectVersion("foo", s).isValid())
.findFirst()
.filter(s -> s.trim().startsWith("#")).map(s -> s.substring(1).trim())
.filter(s -> new ProjectVersion("foo", s).isValid()).findFirst()
.orElse("");
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.util.LinkedList;
@@ -12,9 +44,13 @@ import org.springframework.cloud.release.internal.pom.Projects;
* @author Marcin Grzejszczak
*/
public class Row {
final String componentName;
final String lastGaVersion;
final String currentGaVersion;
final String currentSnapshotVersion;
Row(String[] row) {
@@ -25,7 +61,8 @@ public class Row {
this.currentSnapshotVersion = row[initialIndex + 3].trim();
}
Row(String componentName, String lastGaVersion, String currentGaVersion, String currentSnapshotVersion) {
Row(String componentName, String lastGaVersion, String currentGaVersion,
String currentSnapshotVersion) {
this.componentName = componentName.trim();
this.lastGaVersion = lastGaVersion.trim();
this.currentGaVersion = currentGaVersion.trim();
@@ -33,34 +70,36 @@ public class Row {
}
static List<Row> fromProjects(Projects projects, boolean lastGa) {
return projects
.stream()
return projects.stream()
.map(v -> new Row(v.projectName, lastGa ? versionOrEmptyForGa(v) : "",
!lastGa ? versionOrEmptyForGa(v) : "", v.isSnapshot() ? v.version : ""))
!lastGa ? versionOrEmptyForGa(v) : "",
v.isSnapshot() ? v.version : ""))
.collect(Collectors.toCollection(LinkedList::new));
}
private static String versionOrEmptyForGa(ProjectVersion v) {
return v.isReleaseOrServiceRelease() ?
v.version : "";
return v.isReleaseOrServiceRelease() ? v.version : "";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Row row = (Row) o;
return Objects.equals(this.componentName, row.componentName) &&
Objects.equals(this.lastGaVersion, row.lastGaVersion) &&
Objects.equals(this.currentGaVersion, row.currentGaVersion) &&
Objects.equals(this.currentSnapshotVersion, row.currentSnapshotVersion);
return Objects.equals(this.componentName, row.componentName)
&& Objects.equals(this.lastGaVersion, row.lastGaVersion)
&& Objects.equals(this.currentGaVersion, row.currentGaVersion) && Objects
.equals(this.currentSnapshotVersion, row.currentSnapshotVersion);
}
@Override
public int hashCode() {
return Objects
.hash(this.componentName, this.lastGaVersion,
this.currentGaVersion, this.currentSnapshotVersion);
return Objects.hash(this.componentName, this.lastGaVersion, this.currentGaVersion,
this.currentSnapshotVersion);
}
public String getComponentName() {
@@ -78,4 +117,5 @@ public class Row {
public String getCurrentSnapshotVersion() {
return this.currentSnapshotVersion;
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.util.Objects;
@@ -8,7 +40,9 @@ import java.util.Objects;
public class Title {
final String lastGaTrainName;
final String currentGaTrainName;
final String currentSnapshotTrainName;
Title(String[] row) {
@@ -18,7 +52,8 @@ public class Title {
this.currentSnapshotTrainName = row[initialIndex + 2].trim();
}
Title(String lastGaTrainName, String currentGaTrainName, String currentSnapshotTrainName) {
Title(String lastGaTrainName, String currentGaTrainName,
String currentSnapshotTrainName) {
this.lastGaTrainName = lastGaTrainName.trim();
this.currentGaTrainName = currentGaTrainName.trim();
this.currentSnapshotTrainName = currentSnapshotTrainName.trim();
@@ -26,19 +61,23 @@ public class Title {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Title title = (Title) o;
return Objects.equals(this.lastGaTrainName, title.lastGaTrainName) &&
Objects.equals(this.currentGaTrainName, title.currentGaTrainName) &&
Objects
.equals(this.currentSnapshotTrainName, title.currentSnapshotTrainName);
return Objects.equals(this.lastGaTrainName, title.lastGaTrainName)
&& Objects.equals(this.currentGaTrainName, title.currentGaTrainName)
&& Objects.equals(this.currentSnapshotTrainName,
title.currentSnapshotTrainName);
}
@Override
public int hashCode() {
return Objects
.hash(this.lastGaTrainName, this.currentGaTrainName, this.currentSnapshotTrainName);
return Objects.hash(this.lastGaTrainName, this.currentGaTrainName,
this.currentSnapshotTrainName);
}
public String getLastGaTrainName() {
@@ -52,4 +91,5 @@ public class Title {
public String getCurrentSnapshotTrainName() {
return this.currentSnapshotTrainName;
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.File;
@@ -58,8 +75,8 @@ import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
/**
* Abstraction over a Git repo. Can cloned repo from a given location
* and check its branch.
* Abstraction over a Git repo. Can cloned repo from a given location and check its
* branch.
*
* @author Marcin Grzejszczak
*/
@@ -89,7 +106,7 @@ class GitRepo {
}
/**
* Clones the project
* Clones the project.
* @param projectUri - URI of the project
* @return file where the project was cloned
*/
@@ -111,7 +128,7 @@ class GitRepo {
}
/**
* Checks out a branch for a project
* Checks out a branch for a project.
* @param branch - branch to check out
*/
void checkout(String branch) {
@@ -126,31 +143,35 @@ class GitRepo {
}
/**
* Performs a commit
* Performs a commit.
* @param message - commit message
*/
void commit(String message) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
git.add().addFilepattern(".").call();
git.commit().setAllowEmpty(false).setMessage(message).call();
printLog(git);
} catch (EmtpyCommitException e) {
}
catch (EmtpyCommitException e) {
log.info("There were no changes detected. Will not commit an empty commit");
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
boolean hasBranch(String branch) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
List<Ref> refs = git.branchList().setListMode(ListBranchCommand.ListMode.ALL)
.call();
boolean present = refs.stream().anyMatch(ref -> branch.equals(nameOfBranch(ref.getName())));
boolean present = refs.stream()
.anyMatch(ref -> branch.equals(nameOfBranch(ref.getName())));
if (log.isDebugEnabled()) {
log.debug("Branch [{}] is present [{}]", branch, present);
}
return present;
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
@@ -165,84 +186,92 @@ class GitRepo {
log.info("Printing [{}] last commits for branch [{}]", maxCount, currentBranch);
Iterable<RevCommit> commits = git.log().setMaxCount(maxCount).call();
for (RevCommit commit : commits) {
log.info("Name [{}], msg [{}]", commit.getId().name(), commit.getShortMessage());
log.info("Name [{}], msg [{}]", commit.getId().name(),
commit.getShortMessage());
}
}
/**
* Creates a tag with a given name
* @param tagName
* Creates a tag with a given name.
* @param tagName name of the tag to set
*/
void tag(String tagName) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
git.tag().setName(tagName).call();
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
* Pushes the commits to {@code origin} remote branch
* Pushes the commits to {@code origin} remote branch.
* @param branch - remote branch to which the code should be pushed
*/
void pushBranch(String branch) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
String localBranch = git.getRepository().getFullBranch();
RefSpec refSpec = new RefSpec(localBranch + ":" + branch);
this.gitFactory.push(git).setPushTags().setRefSpecs(refSpec).call();
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
* Pushes the commits od current branch
* Pushes the commits od current branch.
*/
void pushCurrentBranch() {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
this.gitFactory.push(git).call();
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
* Pushes the commits to {@code origin} remote tag
* Pushes the commits to {@code origin} remote tag.
* @param tagName - remote tag to which the code should be pushed
*/
void pushTag(String tagName) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
String localBranch = git.getRepository().getFullBranch();
RefSpec refSpec = new RefSpec(localBranch + ":" + "refs/tags/" + tagName);
this.gitFactory.push(git).setPushTags().setRefSpecs(refSpec).call();
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
void revert(String message) {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
RevCommit commit = git.log().setMaxCount(1).call().iterator().next();
String shortMessage = commit.getShortMessage();
String id = commit.getId().getName();
if (!shortMessage.contains("Update SNAPSHOT to ")) {
throw new IllegalStateException("Won't revert the commit with id [" + id + "] "
+ "and message [" + shortMessage + "]. Only commit that updated "
+ "snapshot to another version can be reverted");
throw new IllegalStateException(
"Won't revert the commit with id [" + id + "] " + "and message ["
+ shortMessage + "]. Only commit that updated "
+ "snapshot to another version can be reverted");
}
log.debug("The commit to be reverted is [{}]", commit);
git.revert().include(commit).call();
git.commit().setAmend(true).setMessage(message).call();
printLog(git);
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
String currentBranch() {
try(Git git = this.gitFactory.open(file(this.basedir))) {
try (Git git = this.gitFactory.open(file(this.basedir))) {
return git.getRepository().getBranch();
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
@@ -254,8 +283,8 @@ class GitRepo {
private Git cloneToBasedir(URIish projectUrl, File destinationFolder)
throws GitAPIException {
CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
.setURI(projectUrl.toString() + ".git").setDirectory(
humanishDestination(projectUrl, destinationFolder));
.setURI(projectUrl.toString() + ".git")
.setDirectory(humanishDestination(projectUrl, destinationFolder));
try {
return command.call();
}
@@ -269,8 +298,7 @@ class GitRepo {
return new File(destinationFolder, projectUrl.getHumanishName());
}
private Ref checkoutBranch(File projectDir, String branch)
throws GitAPIException {
private Ref checkoutBranch(File projectDir, String branch) throws GitAPIException {
Git git = this.gitFactory.open(projectDir);
CheckoutCommand command = git.checkout().setName(branch);
try {
@@ -282,7 +310,8 @@ class GitRepo {
catch (GitAPIException e) {
deleteBaseDirIfExists();
throw e;
} finally {
}
finally {
git.close();
}
}
@@ -305,8 +334,8 @@ class GitRepo {
return containsBranch(git, label, null);
}
private boolean containsBranch(Git git, String label, ListBranchCommand.ListMode listMode)
throws GitAPIException {
private boolean containsBranch(Git git, String label,
ListBranchCommand.ListMode listMode) throws GitAPIException {
ListBranchCommand command = git.branchList();
if (listMode != null) {
command.setListMode(listMode);
@@ -336,31 +365,37 @@ class GitRepo {
* {@link org.eclipse.jgit.api.CloneCommand} allowing for easier unit testing.
*/
static class JGitFactory {
private static final Logger log = LoggerFactory.getLogger(JGitFactory.class);
private final JschConfigSessionFactory factory = new JschConfigSessionFactory() {
@Override protected void configure(OpenSshConfig.Host host, Session session) {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
Connector connector = null;
try {
if(SSHAgentConnector.isConnectorAvailable()){
if (SSHAgentConnector.isConnectorAvailable()) {
USocketFactory usf = new JNAUSocketFactory();
connector = new SSHAgentConnector(usf);
}
log.info("Successfully connected to an agent");
} catch (AgentProxyException e) {
log.error("Exception occurred while trying to connect to agent. Will create"
+ "the default JSch connection", e);
}
catch (AgentProxyException e) {
log.error(
"Exception occurred while trying to connect to agent. Will create"
+ "the default JSch connection",
e);
return super.createDefaultJSch(fs);
}
final JSch jsch = super.createDefaultJSch(fs);
if (connector != null) {
JSch.setConfig("PreferredAuthentications", "publickey,password");
IdentityRepository identityRepository = new RemoteIdentityRepository(connector);
IdentityRepository identityRepository = new RemoteIdentityRepository(
connector);
jsch.setIdentityRepository(identityRepository);
}
return jsch;
@@ -369,27 +404,6 @@ class GitRepo {
private final CredentialsProvider provider;
JGitFactory(ReleaserProperties releaserProperties) {
if (StringUtils.hasText(releaserProperties.getGit().getUsername())) {
log.info("Passed username and password - will set a custom credentials provider");
this.provider = credentialsProvider(releaserProperties);
} else {
log.info("No custom credentials provider will be set");
this.provider = null;
}
}
CredentialsProvider credentialsProvider(ReleaserProperties properties) {
return new UsernamePasswordCredentialsProvider(
properties.getGit().getUsername(),
properties.getGit().getPassword());
}
// for tests
JGitFactory() {
this.provider = null;
}
private final TransportConfigCallback callback = transport -> {
if (transport instanceof SshTransport) {
SshTransport sshTransport = (SshTransport) transport;
@@ -397,15 +411,35 @@ class GitRepo {
}
};
JGitFactory(ReleaserProperties releaserProperties) {
if (StringUtils.hasText(releaserProperties.getGit().getUsername())) {
log.info(
"Passed username and password - will set a custom credentials provider");
this.provider = credentialsProvider(releaserProperties);
}
else {
log.info("No custom credentials provider will be set");
this.provider = null;
}
}
// for tests
JGitFactory() {
this.provider = null;
}
CredentialsProvider credentialsProvider(ReleaserProperties properties) {
return new UsernamePasswordCredentialsProvider(
properties.getGit().getUsername(), properties.getGit().getPassword());
}
CloneCommand getCloneCommandByCloneRepository() {
return Git.cloneRepository()
.setCredentialsProvider(this.provider)
return Git.cloneRepository().setCredentialsProvider(this.provider)
.setTransportConfigCallback(this.callback);
}
PushCommand push(Git git) {
return git.push()
.setCredentialsProvider(this.provider)
return git.push().setCredentialsProvider(this.provider)
.setTransportConfigCallback(this.callback);
}
@@ -417,5 +451,7 @@ class GitRepo {
throw new IllegalStateException(e);
}
}
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.IOException;
@@ -12,6 +44,7 @@ import com.jcabi.github.RtGithub;
import com.jcabi.http.wire.RetryWire;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.Projects;
@@ -24,14 +57,16 @@ import org.springframework.util.StringUtils;
class GithubIssues {
private static final Logger log = LoggerFactory.getLogger(GithubIssues.class);
private static final String GITHUB_ISSUE_TITLE = "Spring Cloud Release took place";
private final Github github;
private final ReleaserProperties properties;
GithubIssues(ReleaserProperties properties) {
this.github = new RtGithub(new RtGithub(
properties.getGit().getOauthToken()).entry().through(RetryWire.class));
this.github = new RtGithub(new RtGithub(properties.getGit().getOauthToken())
.entry().through(RetryWire.class));
this.properties = properties;
}
@@ -51,12 +86,15 @@ class GithubIssues {
// do this only for RELEASE & SR
String releaseVersion = parsedVersion();
if (!(version.isRelease() || version.isServiceRelease())) {
log.info("Guide issue creation will occur only for Release or Service Release versions. Your version is [{}]", releaseVersion);
log.info(
"Guide issue creation will occur only for Release or Service Release versions. Your version is [{}]",
releaseVersion);
return;
}
Repo springGuides = this.github.repos()
.get(new Coordinates.Simple("spring-guides", "getting-started-guides"));
String issueTitle = StringUtils.capitalize(releaseVersion) + " " + GITHUB_ISSUE_TITLE;
String issueTitle = StringUtils.capitalize(releaseVersion) + " "
+ GITHUB_ISSUE_TITLE;
// check if the issue is not already there
boolean issueAlreadyFiled = issueAlreadyFiled(springGuides, issueTitle);
if (issueAlreadyFiled) {
@@ -66,7 +104,9 @@ class GithubIssues {
try {
int number = springGuides.issues().create(issueTitle, issueText(projects))
.number();
log.info("Successfully created an issue with title [{}] in Spring Guides under: https://github.com/spring-guides/getting-started-guides/issues/" + number, issueTitle);
log.info("Successfully created an issue with "
+ "title [{}] in Spring Guides under: https://github.com/spring-guides/getting-started-guides/issues/"
+ number, issueTitle);
}
catch (IOException e) {
log.error("Exception occurred while trying to create the issue in guides", e);
@@ -82,15 +122,11 @@ class GithubIssues {
}
private String issueText(Projects projects) {
StringBuilder builder = new StringBuilder()
.append("Spring Cloud [")
.append(parsedVersion())
.append("] Released with the following projects:")
StringBuilder builder = new StringBuilder().append("Spring Cloud [")
.append(parsedVersion()).append("] Released with the following projects:")
.append("\n\n");
projects.forEach(project -> builder
.append(project.projectName).append(" : ")
.append("`").append(project.version).append("`")
.append("\n"));
projects.forEach(project -> builder.append(project.projectName).append(" : ")
.append("`").append(project.version).append("`").append("\n"));
return builder.toString();
}
@@ -116,4 +152,5 @@ class GithubIssues {
}
return false;
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.IOException;
@@ -25,16 +57,18 @@ import org.springframework.util.StringUtils;
*/
class GithubMilestones {
private static final Logger log = LoggerFactory.getLogger(GithubMilestones.class);
private final Github github;
private final ReleaserProperties properties;
static final Map<ProjectVersion, String> MILESTONE_URL_CACHE = new ConcurrentHashMap<>();
static final Map<ProjectVersion, Milestone.Smart> MILESTONE_CACHE = new ConcurrentHashMap<>();
private static final Logger log = LoggerFactory.getLogger(GithubMilestones.class);
private final Github github;
private final ReleaserProperties properties;
GithubMilestones(ReleaserProperties properties) {
this.github = new RtGithub(new RtGithub(
properties.getGit().getOauthToken()).entry().through(RetryWire.class));
this.github = new RtGithub(new RtGithub(properties.getGit().getOauthToken())
.entry().through(RetryWire.class));
this.properties = properties;
}
@@ -66,32 +100,35 @@ class GithubMilestones {
catch (IOException e) {
log.error("Exception occurred while trying to retrieve the milestone", e);
}
} else {
}
else {
log.warn("No matching milestone was found");
}
}
Milestone.Smart matchingMilestone(String tagVersion,
Iterable<Milestone> milestones) {
Milestone.Smart matchingMilestone(String tagVersion, Iterable<Milestone> milestones) {
log.debug("Successfully received list of milestones [{}]", milestones);
log.info("Will try to match against tag version [{}]", tagVersion);
try {
int counter = 0;
for (Milestone milestone : milestones) {
if (counter++ >= this.properties.getGit().getNumberOfCheckedMilestones()) {
log.warn("No matching milestones were found within the provided threshold [{}] of checked milestones",
if (counter++ >= this.properties.getGit()
.getNumberOfCheckedMilestones()) {
log.warn(
"No matching milestones were found within the provided threshold [{}] of checked milestones",
this.properties.getGit().getNumberOfCheckedMilestones());
return null;
}
Milestone.Smart smartMilestone = new Milestone.Smart(milestone);
String title = milestoneTitle(smartMilestone);
if (tagVersion.equals(title) || numericVersion(tagVersion)
.equals(title)) {
if (tagVersion.equals(title)
|| numericVersion(tagVersion).equals(title)) {
log.info("Found a matching milestone [{}]", smartMilestone.number());
return smartMilestone;
}
}
} catch (AssertionError | IOException e) {
}
catch (AssertionError | IOException e) {
log.error("Exception occurred while trying to retrieve the milestone", e);
return null;
}
@@ -107,7 +144,8 @@ class GithubMilestones {
Assert.hasText(this.properties.getGit().getOauthToken(),
"You have to pass Github OAuth token for milestone closing to be operational");
String tagVersion = version.version;
Milestone.Smart foundMilestone = matchingMilestone(tagVersion, closedMilestones(version));
Milestone.Smart foundMilestone = matchingMilestone(tagVersion,
closedMilestones(version));
String foundUrl = "";
if (foundMilestone != null) {
try {
@@ -115,7 +153,7 @@ class GithubMilestones {
log.info("Found a matching milestone with issues URL [{}]", url);
foundUrl = url.toString()
.replace("https://api.github.com/repos", "https://github.com")
.replace("milestones", "milestone")+ "?closed=1";
.replace("milestones", "milestone") + "?closed=1";
}
catch (IOException e) {
throw new IllegalStateException(e);
@@ -129,8 +167,8 @@ class GithubMilestones {
}
private String numericVersion(String version) {
return version.contains("RELEASE") ?
version.substring(0, version.lastIndexOf(".")) : "";
return version.contains("RELEASE")
? version.substring(0, version.lastIndexOf(".")) : "";
}
String milestoneTitle(Milestone.Smart milestone) throws IOException {
@@ -145,9 +183,10 @@ class GithubMilestones {
Map<String, String> map) {
try {
return this.github.repos()
.get(new Coordinates.Simple(org(), version.projectName))
.milestones().iterate(map);
} catch (AssertionError e) {
.get(new Coordinates.Simple(org(), version.projectName)).milestones()
.iterate(map);
}
catch (AssertionError e) {
log.error("Exception occurred while trying to fetch milestones", e);
return new ArrayList<>();
}
@@ -180,4 +219,5 @@ class GithubMilestones {
params.put("direction", "desc");
return params;
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.File;
@@ -15,7 +47,7 @@ import org.springframework.cloud.release.internal.pom.Projects;
import org.springframework.util.StringUtils;
/**
* Contains business logic around Git & Github operations
* Contains business logic around Git & Github operations.
*
* @author Marcin Grzejszczak
*/
@@ -24,11 +56,17 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory.getLogger(ProjectGitHandler.class);
private static final String MSG = "Bumping versions";
private static final String PRE_RELEASE_MSG = "Update SNAPSHOT to %s";
private static final String POST_RELEASE_MSG = "Going back to snapshots";
private static final String POST_RELEASE_BUMP_MSG = "Bumping versions to %s after release";
private final GithubMilestones githubMilestones;
private final GithubIssues githubIssues;
private ReleaserProperties properties;
public ProjectGitHandler(ReleaserProperties properties) {
@@ -40,11 +78,14 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
public void commitAndTagIfApplicable(File project, ProjectVersion version) {
GitRepo gitRepo = gitRepo(project);
if (version.isSnapshot()) {
log.info("Snapshot version [{}] found. Will only commit the changed poms", version);
log.info("Snapshot version [{}] found. Will only commit the changed poms",
version);
gitRepo.commit(MSG);
}
else {
log.info("NON-snapshot version [{}] found. Will commit the changed poms, tag the version and push the tag", version);
log.info(
"NON-snapshot version [{}] found. Will commit the changed poms, tag the version and push the tag",
version);
gitRepo.commit(String.format(PRE_RELEASE_MSG, version.version));
String tagName = "v" + version.version;
gitRepo.tag(tagName);
@@ -54,9 +95,10 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
public void commitAfterBumpingVersions(File project, ProjectVersion version) {
if (version.isSnapshot()) {
log.info("Snapshot version [{}] found. Will only commit the changed poms", version);
commit(project, String
.format(POST_RELEASE_BUMP_MSG, version.bumpedVersion()));
log.info("Snapshot version [{}] found. Will only commit the changed poms",
version);
commit(project,
String.format(POST_RELEASE_BUMP_MSG, version.bumpedVersion()));
}
else {
log.info("Non snapshot version [{}] found. Won't do anything", version);
@@ -87,18 +129,17 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
}
public File cloneDocumentationProject() {
return cloneAndCheckOut(this.properties.getGit()
.getDocumentationUrl(), this.properties.getGit()
.getDocumentationBranch());
return cloneAndCheckOut(this.properties.getGit().getDocumentationUrl(),
this.properties.getGit().getDocumentationBranch());
}
public File cloneSpringDocProject() {
return cloneAndCheckOut(this.properties.getGit()
.getSpringProjectUrl(), this.properties.getGit()
.getSpringProjectBranch());
return cloneAndCheckOut(this.properties.getGit().getSpringProjectUrl(),
this.properties.getGit().getSpringProjectBranch());
}
private File cloneAndCheckOut(String springProjectUrl, String springProjectUrlBranch) {
private File cloneAndCheckOut(String springProjectUrl,
String springProjectUrlBranch) {
File clonedProject = cloneProject(springProjectUrl);
checkout(clonedProject, springProjectUrlBranch);
return clonedProject;
@@ -111,8 +152,8 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
*/
public File cloneProjectFromOrg(String projectName) {
String orgUrl = this.properties.getMetaRelease().getGitOrgUrl();
String fullUrl = orgUrl.endsWith("/") ? (orgUrl + projectName) : (orgUrl + "/" +
projectName + suffixNonHttpRepo(orgUrl));
String fullUrl = orgUrl.endsWith("/") ? (orgUrl + projectName)
: (orgUrl + "/" + projectName + suffixNonHttpRepo(orgUrl));
if (log.isDebugEnabled()) {
log.debug("Full url of the project is [{}]", fullUrl);
}
@@ -122,20 +163,20 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
}
String version = this.properties.getFixedVersions().get(projectName);
if (StringUtils.isEmpty(version)) {
throw new IllegalStateException("You haven't provided a version for project [" + projectName + "]");
throw new IllegalStateException(
"You haven't provided a version for project [" + projectName + "]");
}
return findAndCheckOutBranchForVersion(clonedProject, new String[] { version });
}
/**
* From the version analyzes the branch and checks it out. E.g.
* - for spring-cloud-releases `Finchley.RELEASE version will resolve either Finchley
* branch or will fallback to master if theres no Finchley branch
* - for spring-cloud-sleuths `2.1.0.RELEASE version will resolve 2.1.x branch
*
* From the version analyzes the branch and checks it out. E.g. - for
* spring-cloud-releases `Finchley.RELEASE version will resolve either Finchley
* branch or will fallback to master if theres no Finchley branch - for
* spring-cloud-sleuths `2.1.0.RELEASE version will resolve 2.1.x branch
* @param url - of project to clone
* @param versions - list of versions to check against, if none matches, will fallback to master
* @param versions - list of versions to check against, if none matches, will fallback
* to master
* @return location of the cloned project
*/
public File cloneAndGuessBranch(String url, String... versions) {
@@ -150,14 +191,13 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
if (log.isDebugEnabled()) {
log.debug("Checking versions {} for project [{}]", versions, clonedProject);
}
String branchToCheckout = Arrays.stream(versions)
.map(this::branchFromVersion)
String branchToCheckout = Arrays.stream(versions).map(this::branchFromVersion)
.map(version -> gitRepo(clonedProject).hasBranch(version) ? version : "")
.filter(StringUtils::hasText)
.findFirst()
.orElse("master");
.filter(StringUtils::hasText).findFirst().orElse("master");
if ("master".equals(branchToCheckout)) {
log.info("None of the versions {} matches a branch. Assuming that should work with master branch", (Object) versions);
log.info(
"None of the versions {} matches a branch. Assuming that should work with master branch",
(Object) versions);
return clonedProject;
}
log.info("Branch [{}] exists. Will check it out", branchToCheckout);
@@ -171,9 +211,10 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
File cloneProject(String url) {
try {
File destinationDir = this.properties.getGit().getCloneDestinationDir() != null ?
new File(this.properties.getGit().getCloneDestinationDir()) :
Files.createTempDirectory("releaser").toFile();
File destinationDir = this.properties.getGit()
.getCloneDestinationDir() != null
? new File(this.properties.getGit().getCloneDestinationDir())
: Files.createTempDirectory("releaser").toFile();
return gitRepo(destinationDir).cloneProject(new URIish(url));
}
catch (Exception e) {
@@ -203,7 +244,8 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
// [Camden] -> [Camden.x]
return splitVersion[0];
}
throw new IllegalStateException("Wrong version [" + version + "]. Can't extract semver pieces of it");
throw new IllegalStateException(
"Wrong version [" + version + "]. Can't extract semver pieces of it");
}
@@ -244,4 +286,5 @@ public class ProjectGitHandler implements ReleaserPropertiesAware {
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.gradle;
import java.io.File;
@@ -18,6 +50,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
@@ -37,10 +70,10 @@ public class GradleUpdater implements ReleaserPropertiesAware {
}
/**
* For the given root folder (typically the working directory) performs the whole
* flow of updating {@code gradle.properties} with values from BOM project.
* Remember to pass the mapping from a property name inside {@code gradle.properties} to
* the project name via {@link ReleaserProperties.Gradle#getGradlePropsSubstitution}
* For the given root folder (typically the working directory) performs the whole flow
* of updating {@code gradle.properties} with values from BOM project. Remember to
* pass the mapping from a property name inside {@code gradle.properties} to the
* project name via {@link ReleaserProperties.Gradle#getGradlePropsSubstitution}
* @param projectRoot - root folder with project to update
* @param projects - versions of projects used to update poms
* @param versionFromBom - version for the project from Spring Cloud Release
@@ -54,35 +87,42 @@ public class GradleUpdater implements ReleaserPropertiesAware {
private void processAllGradleProps(File projectRoot, Projects projects,
ProjectVersion versionFromScRelease, boolean assertVersions) {
try {
Files.walkFileTree(projectRoot.toPath(),
new GradlePropertiesWalker(this.properties, projects, versionFromScRelease, assertVersions));
Files.walkFileTree(projectRoot.toPath(), new GradlePropertiesWalker(
this.properties, projects, versionFromScRelease, assertVersions));
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override public void setReleaserProperties(ReleaserProperties properties) {
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
private class GradlePropertiesWalker extends SimpleFileVisitor<Path> {
private final class GradlePropertiesWalker extends SimpleFileVisitor<Path> {
private static final String GRADLE_PROPERTIES = "gradle.properties";
private final ReleaserProperties properties;
private final Projects projects;
private final boolean skipVersionAssert;
private final boolean assertVersions;
private final List<Pattern> unacceptableVersionPatterns;
private GradlePropertiesWalker(ReleaserProperties properties, Projects projects,
ProjectVersion versionFromScRelease, boolean assertVersions) {
this.properties = properties;
this.projects = projects;
List<Pattern> unacceptableVersionPatterns = versionFromScRelease.unacceptableVersionPatterns();
List<Pattern> unacceptableVersionPatterns = versionFromScRelease
.unacceptableVersionPatterns();
this.unacceptableVersionPatterns = unacceptableVersionPatterns;
this.skipVersionAssert = !assertVersions || unacceptableVersionPatterns.isEmpty();
this.skipVersionAssert = !assertVersions
|| unacceptableVersionPatterns.isEmpty();
this.assertVersions = assertVersions;
}
@@ -91,12 +131,16 @@ public class GradleUpdater implements ReleaserPropertiesAware {
File file = path.toFile();
if (GRADLE_PROPERTIES.equals(file.getName())) {
if (pathIgnored(file)) {
log.debug("Ignoring file [{}] since it's on a list of patterns to ignore", file);
log.debug(
"Ignoring file [{}] since it's on a list of patterns to ignore",
file);
return FileVisitResult.CONTINUE;
}
log.info("Will process the file [{}] and update its gradle properties", file);
log.info("Will process the file [{}] and update its gradle properties",
file);
final String fileContents = asString(path);
final AtomicReference<String> changedString = new AtomicReference<>(fileContents);
final AtomicReference<String> changedString = new AtomicReference<>(
fileContents);
Properties props = loadProps(file);
final Map<String, String> substitution = this.properties.getGradle()
.getGradlePropsSubstitution();
@@ -104,12 +148,14 @@ public class GradleUpdater implements ReleaserPropertiesAware {
if (substitution.containsKey(key)) {
String projectName = substitution.get(key);
if (!this.projects.containsProject(projectName)) {
log.warn("Should update project with name [{}] but it wasn't found in the list of projects [{}]", projectName, this.projects
.asList());
log.warn(
"Should update project with name [{}] but it wasn't found in the list of projects [{}]",
projectName, this.projects.asList());
return;
}
ProjectVersion value = this.projects.forName(projectName);
log.info("Replacing [{}->{}] with [{}->{}]", key, value1, key, value);
log.info("Replacing [{}->{}] with [{}->{}]", key, value1, key,
value);
changedString.set(changedString.get().replace(key + "=" + value1,
key + "=" + value));
}
@@ -122,9 +168,10 @@ public class GradleUpdater implements ReleaserPropertiesAware {
private void assertNoSnapshotsArePresent(Path path) {
if (this.assertVersions && !this.skipVersionAssert) {
log.debug("Update should check if no wrong versions remained in the gradle prop. List of wrong patterns: {}",
this.unacceptableVersionPatterns.stream().map(Pattern::pattern).collect(Collectors
.toList()));
log.debug(
"Update should check if no wrong versions remained in the gradle prop. List of wrong patterns: {}",
this.unacceptableVersionPatterns.stream().map(Pattern::pattern)
.collect(Collectors.toList()));
Scanner scanner = new Scanner(asString(path));
int lineNumber = 0;
while (scanner.hasNextLine()) {
@@ -134,7 +181,10 @@ public class GradleUpdater implements ReleaserPropertiesAware {
.filter(pattern -> pattern.matcher(line).matches())
.findFirst().orElse(null);
if (matchingPattern != null) {
throw new IllegalStateException("The file [" + path + "] matches the [ " + matchingPattern.pattern() + "] pattern in line number [" + lineNumber + "]\n\n" + line);
throw new IllegalStateException("The file [" + path
+ "] matches the [ " + matchingPattern.pattern()
+ "] pattern in line number [" + lineNumber + "]\n\n"
+ line);
}
}
log.info("No invalid versions remained in the gradle properties");
@@ -154,8 +204,8 @@ public class GradleUpdater implements ReleaserPropertiesAware {
private boolean pathIgnored(File file) {
String path = file.getPath();
return this.assertVersions &&
this.properties.getGradle().getIgnoredGradleRegex().stream().anyMatch(path::matches);
return this.assertVersions && this.properties.getGradle()
.getIgnoredGradleRegex().stream().anyMatch(path::matches);
}
private String asString(Path path) {
@@ -175,5 +225,7 @@ public class GradleUpdater implements ReleaserPropertiesAware {
throw new IllegalStateException(e);
}
}
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -31,8 +48,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID;
/**
* Parses the poms for a given project and populates versions from a release train
* Parses the poms for a given project and populates versions from a release train.
*
* @author Marcin Grzejszczak
*/
@@ -41,12 +60,16 @@ class BomParser {
private static final Logger log = LoggerFactory.getLogger(BomParser.class);
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;
private final String pomWithBootStarterParent;
private final String thisTrainBom;
private final PomReader pomReader = new PomReader();
private final Pattern versionPattern;
private final ReleaserProperties properties;
BomParser(ReleaserProperties properties, File thisProjectRoot) {
this.thisProjectRoot = thisProjectRoot;
@@ -59,7 +82,8 @@ class BomParser {
Versions allVersions() {
Versions boot = bootVersion();
Versions cloud = versionsFromBom();
return new Versions(boot.bootVersion, cloud.scBuildVersion, allProjects(boot, cloud));
return new Versions(boot.bootVersion, cloud.scBuildVersion,
allProjects(boot, cloud));
}
private Set<Project> allProjects(Versions boot, Versions cloud) {
@@ -76,8 +100,10 @@ class BomParser {
}
String bootArtifactId = model.getParent().getArtifactId();
log.debug("Boot artifact id is equal to [{}]", bootArtifactId);
if (!SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID.equals(bootArtifactId)) {
throw new IllegalStateException("The pom doesn't have a [" + SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID
if (!SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID
.equals(bootArtifactId)) {
throw new IllegalStateException("The pom doesn't have a ["
+ SpringCloudConstants.BOOT_STARTER_PARENT_ARTIFACT_ID
+ "] artifact id");
}
String bootVersion = model.getParent().getVersion();
@@ -96,27 +122,29 @@ class BomParser {
return this.pomReader.readPom(pomFile);
}
// the BOM contains all versions of projects and its parent MUST be Spring Cloud Dependencies Parent
// the BOM contains all versions of projects and its parent MUST be Spring Cloud
// Dependencies Parent
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)) {
throw new IllegalStateException("The pom doesn't have a [" + SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID
+ "] artifact id");
log.debug("[{}] artifact id is equal to [{}]",
CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID, buildArtifact);
if (!CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID.equals(buildArtifact)) {
throw new IllegalStateException("The pom doesn't have a ["
+ CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID + "] artifact id");
}
String buildVersion = model.getParent().getVersion();
log.debug("Spring Cloud Build version is equal to [{}]", buildVersion);
Set<Project> projects = model.getProperties().entrySet()
.stream()
.filter(propertyMatchesSCPattern())
.map(toProject())
Set<Project> projects = model.getProperties().entrySet().stream()
.filter(propertyMatchesSCPattern()).map(toProject())
.collect(Collectors.toSet());
String releaseTrainProjectVersion = model.getVersion();
projects.add(new Project(this.properties.getMetaRelease().getReleaseTrainProjectName(), releaseTrainProjectVersion));
projects.add(
new Project(this.properties.getMetaRelease().getReleaseTrainProjectName(),
releaseTrainProjectVersion));
return new Versions(buildVersion, projects);
}
@@ -133,5 +161,5 @@ class BomParser {
return new Project(name, entry.getValue().toString());
};
}
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -31,18 +48,18 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
class PomReader {
/**
* Returns a parsed POM
* Returns a parsed POM.
*/
Model readPom(File file) {
File pom = file;
if (file.isDirectory()) {
pom = new File(file,"pom.xml");
pom = new File(file, "pom.xml");
}
if (!pom.exists()) {
return null;
}
String fileText = "";
try(Reader reader = new FileReader(pom)) {
try (Reader reader = new FileReader(pom)) {
if (file.isFile()) {
fileText = new String(Files.readAllBytes(file.toPath()));
}
@@ -51,9 +68,12 @@ class PomReader {
}
catch (XmlPullParserException | IOException e) {
if (file.isFile() && fileText.length() == 0) {
throw new IllegalStateException("File [" + pom.getAbsolutePath() + "] is empty", e);
throw new IllegalStateException(
"File [" + pom.getAbsolutePath() + "] is empty", e);
}
throw new IllegalStateException("Failed to read file: " + pom.getAbsolutePath(), e);
throw new IllegalStateException(
"Failed to read file: " + pom.getAbsolutePath(), e);
}
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.BufferedWriter;
@@ -21,6 +38,7 @@ import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
@@ -37,6 +55,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.stax2.XMLInputFactory2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import static org.springframework.util.StringUtils.hasText;
@@ -50,12 +69,12 @@ class PomUpdater {
private static final Logger log = LoggerFactory.getLogger(PomUpdater.class);
private final PomReader pomReader = new PomReader();
private final PomWriter pomWriter = new PomWriter();
/**
* Basing on the contents of the root pom and the versions will decide whether
* the project should be updated or not.
*
* Basing on the contents of the root pom and the versions will decide whether the
* project should be updated or not.
* @param rootFolder - root folder of the project
* @param versions - list of dependencies to be updated
* @return {@code true} if the project is on the list of projects to be updated
@@ -70,18 +89,20 @@ class PomUpdater {
log.info("Failed to read the model");
return false;
}
String artifactId = artifactId(model);
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());
log.info(
"Skipping project [{}] since it's not on the list of projects to update",
model.getArtifactId());
return false;
}
log.info("Project [{}] will have its dependencies updated", model.getArtifactId());
log.info("Project [{}] will have its dependencies updated",
model.getArtifactId());
return true;
}
boolean hasSkipDeployment(Model model) {
String property = model.getProperties()
.getProperty("maven.deploy.skip");
String property = model.getProperties().getProperty("maven.deploy.skip");
boolean hasSkipDeploymentProperty = Boolean.parseBoolean(property);
if (hasSkipDeploymentProperty) {
return true;
@@ -89,28 +110,20 @@ class PomUpdater {
if (model.getBuild() == null) {
return false;
}
boolean plugins = model.getBuild()
.getPlugins()
.stream()
.filter(plugin -> "maven-deploy-plugin".equalsIgnoreCase(plugin.getArtifactId()))
.map(this::skipFromConfiguration)
.findFirst()
.orElse(false);
boolean plugins = model.getBuild().getPlugins().stream()
.filter(plugin -> "maven-deploy-plugin"
.equalsIgnoreCase(plugin.getArtifactId()))
.map(this::skipFromConfiguration).findFirst().orElse(false);
if (plugins) {
return true;
}
if (model.getBuild()
.getPluginManagement() == null) {
if (model.getBuild().getPluginManagement() == null) {
return false;
}
return model.getBuild()
.getPluginManagement()
.getPlugins()
.stream()
.filter(plugin -> "maven-deploy-plugin".equalsIgnoreCase(plugin.getArtifactId()))
.map(this::skipFromConfiguration)
.findFirst()
.orElse(false);
return model.getBuild().getPluginManagement().getPlugins().stream()
.filter(plugin -> "maven-deploy-plugin"
.equalsIgnoreCase(plugin.getArtifactId()))
.map(this::skipFromConfiguration).findFirst().orElse(false);
}
private Boolean skipFromConfiguration(Plugin plugin) {
@@ -134,16 +147,16 @@ class PomUpdater {
if (!parent) {
return model.getArtifactId();
}
return model.getArtifactId().substring(0, model.getArtifactId().indexOf("-parent"));
return model.getArtifactId().substring(0,
model.getArtifactId().indexOf("-parent"));
}
ModelWrapper readModel(File pom) {
return new ModelWrapper(this.pomReader.readPom(pom));
}
/**q
* Updates the root / child module model
*
/**
* Updates the root / child module model.
* @param rootPom - root project model
* @param pom - file with the pom
* @param versions - versions to update
@@ -158,9 +171,8 @@ class PomUpdater {
}
/**
* Overwrites the pom.xml with data from {@link ModelWrapper} only if there were
* any changes in the model.
*
* Overwrites the pom.xml with data from {@link ModelWrapper} only if there were any
* changes in the model.
* @return - the pom file
*/
File overwritePomIfDirty(ModelWrapper updatedPomModel, Versions versions, File pom) {
@@ -172,8 +184,8 @@ class PomUpdater {
return pom;
}
private List<VersionChange> updateParentIfPossible(ModelWrapper wrapper, Versions versions,
Model model, List<VersionChange> sourceChanges) {
private List<VersionChange> updateParentIfPossible(ModelWrapper wrapper,
Versions versions, Model model, List<VersionChange> sourceChanges) {
String rootProjectName = wrapper.projectName();
List<VersionChange> changes = new ArrayList<>(sourceChanges);
if (model.getParent() == null || isEmpty(model.getParent().getVersion())) {
@@ -182,39 +194,48 @@ class PomUpdater {
}
String parentGroupId = model.getParent().getGroupId();
String parentArtifactId = model.getParent().getArtifactId();
log.debug("Searching for a version of parent [{}:{}]", parentGroupId, parentArtifactId);
log.debug("Searching for a version of parent [{}:{}]", parentGroupId,
parentArtifactId);
String oldVersion = model.getParent().getVersion();
String version = versions.versionForProject(parentArtifactId);
log.debug("Found version is [{}]", version);
if (isEmpty(version)) {
if (hasText(model.getParent().getRelativePath())) {
version = versions.versionForProject(rootProjectName);
} else {
log.warn("There is no info on the [{}:{}] version", parentGroupId, parentArtifactId);
}
else {
log.warn("There is no info on the [{}:{}] version", parentGroupId,
parentArtifactId);
return changes;
}
}
if (oldVersion.equals(version)) {
log.debug("Won't update the version of parent [{}:{}] since you're already using the proper one", parentGroupId, parentArtifactId);
log.debug(
"Won't update the version of parent [{}:{}] since you're already using the proper one",
parentGroupId, parentArtifactId);
return changes;
}
log.info("Setting version of parent [{}] to [{}] for module [{}]", parentArtifactId,
version, model.getArtifactId());
log.info("Setting version of parent [{}] to [{}] for module [{}]",
parentArtifactId, version, model.getArtifactId());
if (hasText(version)) {
changes.add(new VersionChange(parentGroupId, parentArtifactId, oldVersion, version));
changes.add(new VersionChange(parentGroupId, parentArtifactId, oldVersion,
version));
}
return changes;
}
private List<VersionChange> updateVersionIfPossible(ModelWrapper wrapper, Versions versions,
Model model, List<VersionChange> sourceChanges) {
private List<VersionChange> updateVersionIfPossible(ModelWrapper wrapper,
Versions versions, Model model, List<VersionChange> sourceChanges) {
String rootProjectName = wrapper.projectName();
String rootProjectGroupId = wrapper.groupId();
List<VersionChange> changes = new ArrayList<>(sourceChanges);
String groupId = groupId(model);
String artifactId = model.getArtifactId();
if (model.getGroupId() != null && !model.getGroupId().equals(rootProjectGroupId)) {
log.info("Will not update project [{}] since its group id [{}] is not equal the parent group id [{}]", model.getArtifactId(), model.getGroupId(), rootProjectGroupId);
if (model.getGroupId() != null
&& !model.getGroupId().equals(rootProjectGroupId)) {
log.info(
"Will not update project [{}] since its group id [{}] is not equal the parent group id [{}]",
model.getArtifactId(), model.getGroupId(), rootProjectGroupId);
return changes;
}
log.debug("Searching for a version [{}:{}]", groupId, artifactId);
@@ -222,11 +243,15 @@ class PomUpdater {
String version = versions.versionForProject(rootProjectName);
log.debug("Found version is [{}]", version);
if (isEmpty(version) || isEmpty(model.getVersion())) {
log.debug("There was no version set for project [{}], skipping version setting for module [{}]", rootProjectName, model.getArtifactId());
log.debug(
"There was no version set for project [{}], skipping version setting for module [{}]",
rootProjectName, model.getArtifactId());
return changes;
}
if (oldVersion.equals(version)) {
log.debug("Won't update the version of module [{}]:[{}] since you're already using the proper one", groupId, artifactId);
log.debug(
"Won't update the version of module [{}]:[{}] since you're already using the proper one",
groupId, artifactId);
return changes;
}
log.info("Setting [{}] version to [{}]", artifactId, version);
@@ -243,11 +268,15 @@ class PomUpdater {
}
return "";
}
}
class ModelWrapper {
final Model model;
final Versions versions;
final List<VersionChange> sourceChanges = new ArrayList<>();
ModelWrapper(Model model, List<VersionChange> sourceChanges, Versions versions) {
@@ -269,13 +298,14 @@ class ModelWrapper {
if (this.model.getGroupId() != null) {
return this.model.getGroupId();
}
return this.model.getParent() != null ?
this.model.getParent().getGroupId() : "";
return this.model.getParent() != null ? this.model.getParent().getGroupId() : "";
}
boolean isDirty() {
return !this.sourceChanges.isEmpty() || this.versions.shouldSetProperty(this.model.getProperties());
return !this.sourceChanges.isEmpty()
|| this.versions.shouldSetProperty(this.model.getProperties());
}
}
class PomWriter {
@@ -291,9 +321,11 @@ class PomWriter {
LoggerToMavenLog loggerToMavenLog = new LoggerToMavenLog(PomWriter.log);
versionChangerFactory.setLog(loggerToMavenLog);
versionChangerFactory.setModel(wrapper.model);
log.info("Applying version / parent / plugin / project changes to the pom [{}]", pom);
VersionChanger changer = versionChangerFactory.newVersionChanger( true,
true, true, true);
log.info(
"Applying version / parent / plugin / project changes to the pom [{}]",
pom);
VersionChanger changer = versionChangerFactory.newVersionChanger(true, true,
true, true);
for (VersionChange versionChange : wrapper.sourceChanges) {
changer.apply(versionChange);
}
@@ -304,14 +336,15 @@ class PomWriter {
bw.write(input.toString());
}
log.debug("Flushed changes to the pom file [{}]", pom);
} catch (Exception e) {
}
catch (Exception e) {
log.error("Exception occurred while trying to apply changes to the POM", e);
}
}
/**
* Creates a {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader} from a StringBuilder.
*
* Creates a {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader}
* from a StringBuilder.
* @param input The XML to read and modify.
* @return The {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader}.
*/
@@ -327,48 +360,52 @@ class PomWriter {
}
return newPom;
}
}
class PropertyVersionChanger extends AbstractVersionChanger {
private final Versions versions;
private final PropertyStorer propertyStorer;
PropertyVersionChanger(ModelWrapper wrapper, Versions versions, ModifiedPomXMLEventReader pom, Log log) {
PropertyVersionChanger(ModelWrapper wrapper, Versions versions,
ModifiedPomXMLEventReader pom, Log log) {
super(wrapper.model, pom, log);
this.versions = versions;
this.propertyStorer = new PropertyStorer(log, pom);
}
PropertyVersionChanger(ModelWrapper wrapper, Versions versions, ModifiedPomXMLEventReader pom, Log log, PropertyStorer propertyStorer) {
PropertyVersionChanger(ModelWrapper wrapper, Versions versions,
ModifiedPomXMLEventReader pom, Log log, PropertyStorer propertyStorer) {
super(wrapper.model, pom, log);
this.versions = versions;
this.propertyStorer = propertyStorer;
}
@Override public void apply(final VersionChange versionChange) {
this.versions.projects
.stream()
.filter(project -> {
Properties properties = getModel().getProperties();
String projectVersionKey = propertyName(project);
if (!properties.containsKey(projectVersionKey)) {
return false;
}
String version = properties.getProperty(projectVersionKey);
return !version.equals(project.version);
})
.forEach(this.propertyStorer::setPropertyVersionIfApplicable);
@Override
public void apply(final VersionChange versionChange) {
this.versions.projects.stream().filter(project -> {
Properties properties = getModel().getProperties();
String projectVersionKey = propertyName(project);
if (!properties.containsKey(projectVersionKey)) {
return false;
}
String version = properties.getProperty(projectVersionKey);
return !version.equals(project.version);
}).forEach(this.propertyStorer::setPropertyVersionIfApplicable);
}
private String propertyName(Project project) {
return project.name + ".version";
}
}
class PropertyStorer {
private final Log log;
private final ModifiedPomXMLEventReader pom;
PropertyStorer(Log log, ModifiedPomXMLEventReader pom) {
@@ -379,7 +416,8 @@ class PropertyStorer {
void setPropertyVersionIfApplicable(Project project) {
String propertyName = propertyName(project);
if (setPropertyVersion(propertyName, project.version)) {
this.log.info("Updating property [" + propertyName + "] to version [" + project.version + "]");
this.log.info("Updating property [" + propertyName + "] to version ["
+ project.version + "]");
}
}
@@ -390,7 +428,8 @@ class PropertyStorer {
private boolean setPropertyVersion(String propertyName, String version) {
try {
if (StringUtils.isEmpty(version)) {
this.log.warn("Version for [" + propertyName + "] is empty. Will not set it");
this.log.warn(
"Version for [" + propertyName + "] is empty. Will not set it");
return false;
}
return PomHelper.setPropertyVersion(this.pom, null, propertyName, version);
@@ -400,6 +439,7 @@ class PropertyStorer {
return false;
}
}
}
class LoggerToMavenLog implements Log {
@@ -410,67 +450,84 @@ class LoggerToMavenLog implements Log {
this.logger = logger;
}
@Override public boolean isDebugEnabled() {
@Override
public boolean isDebugEnabled() {
return this.logger.isDebugEnabled();
}
@Override public void debug(CharSequence content) {
@Override
public void debug(CharSequence content) {
this.logger.debug(content.toString());
}
@Override public void debug(CharSequence content, Throwable error) {
@Override
public void debug(CharSequence content, Throwable error) {
this.logger.debug(content.toString(), error);
}
@Override public void debug(Throwable error) {
@Override
public void debug(Throwable error) {
this.debug("Exception occurred", error);
}
@Override public boolean isInfoEnabled() {
@Override
public boolean isInfoEnabled() {
return this.logger.isInfoEnabled();
}
@Override public void info(CharSequence content) {
@Override
public void info(CharSequence content) {
this.logger.info(content.toString());
}
@Override public void info(CharSequence content, Throwable error) {
@Override
public void info(CharSequence content, Throwable error) {
this.logger.info(content.toString(), error);
}
@Override public void info(Throwable error) {
@Override
public void info(Throwable error) {
this.info("Exception occurred", error);
}
@Override public boolean isWarnEnabled() {
@Override
public boolean isWarnEnabled() {
return this.logger.isWarnEnabled();
}
@Override public void warn(CharSequence content) {
@Override
public void warn(CharSequence content) {
this.logger.warn(content.toString());
}
@Override public void warn(CharSequence content, Throwable error) {
@Override
public void warn(CharSequence content, Throwable error) {
this.logger.warn(content.toString(), error);
}
@Override public void warn(Throwable error) {
@Override
public void warn(Throwable error) {
this.warn("Exception occurred", error);
}
@Override public boolean isErrorEnabled() {
@Override
public boolean isErrorEnabled() {
return this.logger.isErrorEnabled();
}
@Override public void error(CharSequence content) {
@Override
public void error(CharSequence content) {
this.logger.error(content.toString());
}
@Override public void error(CharSequence content, Throwable error) {
@Override
public void error(CharSequence content, Throwable error) {
this.logger.error(content.toString(), error);
}
@Override public void error(Throwable error) {
@Override
public void error(Throwable error) {
this.error("Exception occurred", error);
}
}
}

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -31,6 +48,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
@@ -43,15 +61,16 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
private static final List<String> IGNORED_SNAPSHOT_LINE_PATTERNS = Arrays.asList(
"^.*replace=.*$",
// issue [#80]
"^[\\s]*<!--.*-->.*$"
);
"^[\\s]*<!--.*-->.*$");
private static final Logger log = LoggerFactory.getLogger(ProjectPomUpdater.class);
private ReleaserProperties properties;
private final ProjectGitHandler gitRepo;
private final PomUpdater pomUpdater = new PomUpdater();
private ReleaserProperties properties;
public ProjectPomUpdater(ReleaserProperties properties) {
this.properties = properties;
this.gitRepo = new ProjectGitHandler(properties);
@@ -63,15 +82,17 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
}
/**
* For the given root folder (typically the working directory) retrieves list of versions
* for a given release version.
* For the given root folder (typically the working directory) retrieves list of
* versions for a given release version.
* @return projects retrieved from the release train bom
*/
public Projects retrieveVersionsFromReleaseTrainBom() {
File clonedScRelease = this.gitRepo.cloneReleaseTrainProject();
this.gitRepo.checkout(clonedScRelease, this.properties.getPom().getBranch());
BomParser sCReleasePomParser = new BomParser(this.properties, clonedScRelease);
Versions versions = sCReleasePomParser.allVersions();
log.info("Will update the following versions manually [{}]", this.properties.getFixedVersions());
log.info("Will update the following versions manually [{}]",
this.properties.getFixedVersions());
this.properties.getFixedVersions().forEach(versions::setVersion);
log.info("Retrieved the following versions\n{}", versions);
return versions.toProjectVersions();
@@ -82,8 +103,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
*/
public Projects fixedVersions() {
Set<ProjectVersion> projectVersions = this.properties.getFixedVersions()
.entrySet()
.stream()
.entrySet().stream()
.map(entry -> new ProjectVersion(entry.getKey(), entry.getValue()))
.collect(Collectors.toSet());
if (log.isDebugEnabled()) {
@@ -93,13 +113,13 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
}
/**
* For the given root folder (typically the working directory) performs the whole
* flow of updating {@code pom.xml} with values from release train
* (e.g. Spring Cloud Release project.)
* For the given root folder (typically the working directory) performs the whole flow
* of updating {@code pom.xml} with values from release train (e.g. Spring Cloud
* Release project.)
* @param projectRoot - root folder with project to update
* @param projects - versions of projects used to update poms
* @param versionFromReleaseTrain - version for the built project taken
* from release train (e.g. Spring Cloud Release project)
* @param versionFromReleaseTrain - version for the built project taken from release
* train (e.g. Spring Cloud Release project)
* @param assertVersions - should version assertion take place
*/
public void updateProjectFromReleaseTrain(File projectRoot, Projects projects,
@@ -133,20 +153,27 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
}
}
@Override public void setReleaserProperties(ReleaserProperties properties) {
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
private class PomWalker extends SimpleFileVisitor<Path> {
private final class PomWalker extends SimpleFileVisitor<Path> {
private static final String POM_XML = "pom.xml";
private final ModelWrapper rootPom;
private final Versions versions;
private final PomUpdater pomUpdater;
private final ReleaserProperties properties;
private final boolean skipVersionAssert;
private final boolean assertVersions;
private final List<Pattern> unacceptableVersionPatterns;
private PomWalker(ModelWrapper rootPom, Projects projects, PomUpdater pomUpdater,
@@ -156,9 +183,11 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
this.versions = new Versions(projects, properties);
this.pomUpdater = pomUpdater;
this.properties = properties;
List<Pattern> unacceptableVersionPatterns = versionFromScRelease.unacceptableVersionPatterns();
List<Pattern> unacceptableVersionPatterns = versionFromScRelease
.unacceptableVersionPatterns();
this.unacceptableVersionPatterns = unacceptableVersionPatterns;
this.skipVersionAssert = !assertVersions || unacceptableVersionPatterns.isEmpty();
this.skipVersionAssert = !assertVersions
|| unacceptableVersionPatterns.isEmpty();
this.assertVersions = assertVersions;
}
@@ -167,25 +196,34 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
File file = path.toFile();
if (POM_XML.equals(file.getName())) {
if (pathIgnored(file)) {
log.debug("Ignoring file [{}] since it's on a list of patterns to ignore", file);
log.debug(
"Ignoring file [{}] since it's on a list of patterns to ignore",
file);
return FileVisitResult.CONTINUE;
}
ModelWrapper model = this.pomUpdater.updateModel(this.rootPom, file, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(this.rootPom, file,
this.versions);
this.pomUpdater.overwritePomIfDirty(model, this.versions, file);
if (this.assertVersions && !this.skipVersionAssert && !this.pomUpdater.hasSkipDeployment(model.model)) {
log.debug("Update is a non-snapshot one. Checking if no snapshot versions remained in the pom");
if (this.assertVersions && !this.skipVersionAssert
&& !this.pomUpdater.hasSkipDeployment(model.model)) {
log.debug(
"Update is a non-snapshot one. Checking if no snapshot versions remained in the pom");
Scanner scanner = new Scanner(asString(path));
int lineNumber = 0;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lineNumber++;
Pattern matchingPattern = this.unacceptableVersionPatterns.stream()
.filter(pattern ->
IGNORED_SNAPSHOT_LINE_PATTERNS.stream().noneMatch(line::matches) &&
pattern.matcher(line).matches())
Pattern matchingPattern = this.unacceptableVersionPatterns
.stream()
.filter(pattern -> IGNORED_SNAPSHOT_LINE_PATTERNS.stream()
.noneMatch(line::matches)
&& pattern.matcher(line).matches())
.findFirst().orElse(null);
if (matchingPattern != null) {
throw new IllegalStateException("The file [" + path + "] matches the [ " + matchingPattern.pattern() + "] pattern in line number [" + lineNumber + "]\n\n" + line);
throw new IllegalStateException("The file [" + path
+ "] matches the [ " + matchingPattern.pattern()
+ "] pattern in line number [" + lineNumber + "]\n\n"
+ line);
}
}
log.info("No invalid versions remained in the pom");
@@ -196,8 +234,8 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
private boolean pathIgnored(File file) {
String path = file.getPath();
return this.assertVersions &&
this.properties.getPom().getIgnoredPomRegex().stream().anyMatch(path::matches);
return this.assertVersions && this.properties.getPom().getIgnoredPomRegex()
.stream().anyMatch(path::matches);
}
private String asString(Path path) {
@@ -208,7 +246,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
throw new IllegalStateException(e);
}
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -12,18 +44,30 @@ import org.apache.maven.model.Model;
import org.springframework.util.StringUtils;
/**
* Object representing a root project's version.
* Knows how to provide a minor bumped version;
* Object representing a root project's version. Knows how to provide a minor bumped
* version;
*
* @author Marcin Grzejszczak
*/
public class ProjectVersion {
private static final Pattern SNAPSHOT_PATTERN = Pattern.compile("^.*\\.(BUILD-)?SNAPSHOT.*$");
private static final Pattern SNAPSHOT_PATTERN = Pattern
.compile("^.*\\.(BUILD-)?SNAPSHOT.*$");
private static final String MILESTONE_REGEX = ".*\\.M[0-9]+";
private static final String RC_REGEX = "^.*\\.RC.*$";
/**
* Name of the project.
*/
public final String projectName;
/**
* Version of the project.
*/
public final String version;
private final Model model;
public ProjectVersion(String projectName, String version) {
@@ -38,7 +82,8 @@ public class ProjectVersion {
this.projectName = projectVersion.projectName;
this.version = projectVersion.version;
this.model = null;
} else {
}
else {
PomReader pomReader = new PomReader();
Model model = pomReader.readPom(project);
this.projectName = nameWithoutParent(model.getArtifactId());
@@ -71,27 +116,28 @@ public class ProjectVersion {
return this.version;
}
Integer incrementedPatch = Integer.valueOf(splitVersion[2]) + 1;
return String.format("%s.%s.%s.%s", splitVersion[0], splitVersion[1], incrementedPatch, splitVersion[3]);
return String.format("%s.%s.%s.%s", splitVersion[0], splitVersion[1],
incrementedPatch, splitVersion[3]);
}
private String[] assertVersion() {
if (this.version == null) {
throw new IllegalStateException("Version can't be null!");
}
// 1.0.0.BUILD-SNAPSHOT
String[] splitVersion = this.version.split("\\.");
if (splitVersion.length < 4 && isNumeric(splitVersion[0]) ||
splitVersion.length == 1 && !isNumeric(splitVersion[0])) {
throw new IllegalStateException("Version is invalid. Should be of format [1.2.3.A]");
if (splitVersion.length < 4 && isNumeric(splitVersion[0])
|| splitVersion.length == 1 && !isNumeric(splitVersion[0])) {
throw new IllegalStateException(
"Version is invalid. Should be of format [1.2.3.A]");
}
return splitVersion;
}
/**
* For GA and SR will bump the snapshots
* in the rest of cases will return snapshot of the current version
* @return
* For GA and SR will bump the snapshots in the rest of cases will return snapshot of
* the current version.
* @return the post release snapshot version
*/
public String postReleaseSnapshotVersion() {
String[] strings = assertVersion();
@@ -118,7 +164,8 @@ public class ProjectVersion {
if (StringUtils.hasText(this.model.getGroupId())) {
return this.model.getGroupId();
}
if (this.model.getParent() != null && StringUtils.hasText(this.model.getParent().getGroupId())) {
if (this.model.getParent() != null
&& StringUtils.hasText(this.model.getParent().getGroupId())) {
return this.model.getParent().getGroupId();
}
return "";
@@ -128,7 +175,8 @@ public class ProjectVersion {
try {
assertVersion();
return true;
} catch (IllegalStateException e) {
}
catch (IllegalStateException e) {
return false;
}
}
@@ -167,8 +215,8 @@ public class ProjectVersion {
}
String[] splitThis = this.version.split("\\.");
String[] splitThat = version.split("\\.");
return splitThis.length == splitThat.length &&
splitThis[0].equals(splitThat[0]) && splitThis[1].equals(splitThat[1]);
return splitThis.length == splitThat.length && splitThis[0].equals(splitThat[0])
&& splitThis[1].equals(splitThat[1]);
}
public boolean isSameReleaseTrainName(String version) {
@@ -199,35 +247,44 @@ public class ProjectVersion {
return new VersionNumber(thisValue).compareTo(new VersionNumber(thatValue));
}
@Override public String toString() {
@Override
public String toString() {
return this.version;
}
@Override public boolean equals(Object o) {
if (this == o)
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProjectVersion that = (ProjectVersion) o;
return Objects.equals(this.projectName, that.projectName);
}
@Override public int hashCode() {
@Override
public int hashCode() {
return Objects.hash(this.projectName);
}
public List<Pattern> unacceptableVersionPatterns() {
if (isSnapshot()) {
return Collections.emptyList();
} else if (isMilestone() || isRc()) {
}
else if (isMilestone() || isRc()) {
return Collections.singletonList(SNAPSHOT_PATTERN);
}
// treat like GA
return Arrays.asList(SNAPSHOT_PATTERN, Pattern.compile(MILESTONE_REGEX), Pattern.compile(RC_REGEX));
return Arrays.asList(SNAPSHOT_PATTERN, Pattern.compile(MILESTONE_REGEX),
Pattern.compile(RC_REGEX));
}
}
class VersionNumber implements Comparable<VersionNumber> {
private final String version;
VersionNumber(String version) {
@@ -256,4 +313,5 @@ class VersionNumber implements Comparable<VersionNumber> {
Integer thatNumber = Integer.valueOf(thatVersion);
return thisNumber.compareTo(thatNumber);
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -11,7 +43,7 @@ import java.util.stream.Collectors;
import org.springframework.cloud.release.internal.ReleaserProperties;
/**
* Abstraction over collection of projects
* Abstraction over collection of projects.
*
* @author Marcin Grzejszczak
*/
@@ -23,21 +55,38 @@ public class Projects extends HashSet<ProjectVersion> {
@SuppressWarnings("unchecked")
public Projects(ProjectVersion... versions) {
addAll(new HashSet<>(Arrays.stream(versions).filter(Objects::nonNull).collect(Collectors.toList())));
addAll(new HashSet<>(Arrays.stream(versions).filter(Objects::nonNull)
.collect(Collectors.toList())));
}
public static Projects forRollback(Projects projects, ProjectVersion originalVersion) {
public static Projects forRollback(Projects projects,
ProjectVersion originalVersion) {
Projects newProjects = new Projects();
newProjects.add(new ProjectVersion(originalVersion.projectName, originalVersion.bumpedVersion()));
newProjects.addAll(projects.forNameStartingWith(SpringCloudConstants.SPRING_BOOT));
newProjects.add(new ProjectVersion(originalVersion.projectName,
originalVersion.bumpedVersion()));
newProjects
.addAll(projects.forNameStartingWith(SpringCloudConstants.SPRING_BOOT));
return newProjects;
}
private static IllegalStateException exception(Projects projects,
String projectName) {
return new IllegalStateException("Project with name [" + projectName
+ "] is not present in the list of projects [" + projects.asList()
+ "] . " + additionalErrorMessage(projectName));
}
private static String additionalErrorMessage(String projectName) {
return "Either put it in the Spring Cloud Release project or set it via the [--releaser.fixed-versions["
+ projectName + "]=1.0.0.RELEASE] property";
}
public ProjectVersion releaseTrain(ReleaserProperties properties) {
return this.forName(properties.getMetaRelease().getReleaseTrainProjectName());
}
@Override public boolean add(ProjectVersion projectVersion) {
@Override
public boolean add(ProjectVersion projectVersion) {
if (projectVersion == null) {
return false;
}
@@ -45,17 +94,15 @@ public class Projects extends HashSet<ProjectVersion> {
}
public Projects filter(List<String> projectsToSkip) {
return this.stream()
.filter(v -> !projectsToSkip.contains(v.projectName))
return this.stream().filter(v -> !projectsToSkip.contains(v.projectName))
.collect(Collectors.toCollection(Projects::new));
}
public Projects postReleaseSnapshotVersion(List<String> projectsToSkip) {
Projects projects = this.stream()
.filter(v -> projectsToSkip(projectsToSkip, v))
Projects projects = this.stream().filter(v -> projectsToSkip(projectsToSkip, v))
.collect(Collectors.toCollection(Projects::new));
Projects bumped = this.stream()
.map(v -> new ProjectVersion(v.projectName, v.postReleaseSnapshotVersion()))
Projects bumped = this.stream().map(
v -> new ProjectVersion(v.projectName, v.postReleaseSnapshotVersion()))
.collect(Collectors.toCollection(Projects::new));
Projects merged = new Projects(projects);
merged.addAll(bumped);
@@ -73,35 +120,26 @@ public class Projects extends HashSet<ProjectVersion> {
public ProjectVersion forFile(File projectRoot) {
final ProjectVersion thisProject = new ProjectVersion(projectRoot);
return this.stream().filter(projectVersion -> projectVersion.projectName.equals(thisProject.projectName))
.findFirst()
.orElseThrow(() -> exception(this, thisProject.projectName));
}
private static IllegalStateException exception(Projects projects, String projectName) {
return new IllegalStateException(
"Project with name [" + projectName + "] is not present in the list of projects [" + projects.asList() + "] . "
+ additionalErrorMessage(projectName));
}
private static String additionalErrorMessage(String projectName) {
return "Either put it in the Spring Cloud Release project or set it via the [--releaser.fixed-versions["
+ projectName + "]=1.0.0.RELEASE] property";
return this.stream()
.filter(projectVersion -> projectVersion.projectName
.equals(thisProject.projectName))
.findFirst().orElseThrow(() -> exception(this, thisProject.projectName));
}
public ProjectVersion forName(String projectName) {
return this.stream().filter(projectVersion -> projectVersion.projectName.equals(projectName))
.findFirst()
.orElseThrow(() -> exception(this, projectName));
return this.stream()
.filter(projectVersion -> projectVersion.projectName.equals(projectName))
.findFirst().orElseThrow(() -> exception(this, projectName));
}
public boolean containsProject(String projectName) {
return this.stream()
.anyMatch(projectVersion -> projectVersion.projectName.equals(projectName));
return this.stream().anyMatch(
projectVersion -> projectVersion.projectName.equals(projectName));
}
public List<ProjectVersion> forNameStartingWith(String projectName) {
return this.stream().filter(projectVersion -> projectVersion.projectName.startsWith(projectName))
return this.stream().filter(
projectVersion -> projectVersion.projectName.startsWith(projectName))
.collect(Collectors.toList());
}
@@ -110,6 +148,8 @@ public class Projects extends HashSet<ProjectVersion> {
}
public String asList() {
return this.stream().map(version -> version.projectName + ":" + version.version).collect(Collectors.joining(","));
return this.stream().map(version -> version.projectName + ":" + version.version)
.collect(Collectors.joining(","));
}
}

View File

@@ -1,17 +1,33 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
@@ -20,9 +36,11 @@ package org.springframework.cloud.release.internal.pom;
* @author Marcin Grzejszczak
*/
final class SpringCloudConstants {
static final String SPRING_BOOT = "spring-boot";
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_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";

View File

@@ -1,18 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -31,18 +48,22 @@ import static org.springframework.cloud.release.internal.pom.SpringCloudConstant
import static org.springframework.cloud.release.internal.pom.SpringCloudConstants.CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID;
/**
* Represents versions taken out from Spring Cloud Release pom
* Represents versions taken out from Spring Cloud Release pom.
*
* @author Marcin Grzejszczak
*/
class Versions {
private static final String SPRING_BOOT_PROJECT_NAME = "spring-boot";
static final Versions EMPTY_VERSION = new Versions("");
private static final String SPRING_BOOT_PROJECT_NAME = "spring-boot";
String bootVersion;
String scBuildVersion;
Set<Project> projects = new HashSet<>();
ReleaserProperties properties;
Versions(String bootVersion) {
@@ -65,7 +86,8 @@ class Versions {
this(new ReleaserProperties(), bootVersion, scBuildVersion, projects);
}
Versions(ReleaserProperties properties, String bootVersion, String scBuildVersion, Set<Project> projects) {
Versions(ReleaserProperties properties, String bootVersion, String scBuildVersion,
Set<Project> projects) {
this.properties = properties;
this.bootVersion = bootVersion;
this.scBuildVersion = scBuildVersion;
@@ -79,11 +101,16 @@ class 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))
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))
.findFirst().orElse(new ProjectVersion(BUILD_ARTIFACT_ID, "")).version;
versions.forEach(projectVersion -> setVersion(projectVersion.projectName, projectVersion.version));
versions.forEach(projectVersion -> setVersion(projectVersion.projectName,
projectVersion.version));
}
private String bomProjectName() {
@@ -100,11 +127,8 @@ class Versions {
}
String versionForProject(String projectName) {
return this.projects.stream()
.filter(project -> nameMatches(projectName, project))
.findFirst()
.orElse(Project.EMPTY_PROJECT)
.version;
return this.projects.stream().filter(project -> nameMatches(projectName, project))
.findFirst().orElse(Project.EMPTY_PROJECT).version;
}
boolean shouldBeUpdated(String projectName) {
@@ -133,20 +157,23 @@ class Versions {
}
boolean parent = matchesNameWithSuffix(projectName, "-parent", project);
boolean bomArtifactId = comparisonOfBomArtifactAndParent(projectName, project);
return !bomArtifactId &&
(parent || matchesNameWithSuffix(projectName, "-dependencies", project));
return !bomArtifactId && (parent
|| matchesNameWithSuffix(projectName, "-dependencies", project));
}
private boolean comparisonOfBomArtifactAndParent(String projectName, Project project) {
return artifactOrParent(projectName, project.name) || artifactOrParent(project.name, projectName);
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());
return projectName.equals(dependenciesArtifactId())
&& otherProjectName.equals(dependenciesParentArtifactId());
}
private boolean matchesNameWithSuffix(String projectName, String suffix, Project project) {
private boolean matchesNameWithSuffix(String projectName, String suffix,
Project project) {
boolean containsSuffix = projectName.endsWith(suffix);
if (!containsSuffix) {
return false;
@@ -157,29 +184,30 @@ class Versions {
Versions setVersion(String projectName, String version) {
switch (projectName) {
case SPRING_BOOT_PROJECT_NAME:
case BOOT_STARTER_PARENT_ARTIFACT_ID:
case BOOT_DEPENDENCIES_ARTIFACT_ID:
updateBootVersions(version);
break;
case BUILD_ARTIFACT_ID:
case CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID:
updateBuildVersions(version);
break;
default:
if (bomVersionProjectNames().contains(projectName)) {
updateBomVersions(version);
} else {
remove(projectName);
add(projectName, version);
}
case SPRING_BOOT_PROJECT_NAME:
case BOOT_STARTER_PARENT_ARTIFACT_ID:
case BOOT_DEPENDENCIES_ARTIFACT_ID:
updateBootVersions(version);
break;
case BUILD_ARTIFACT_ID:
case CLOUD_DEPENDENCIES_PARENT_ARTIFACT_ID:
updateBuildVersions(version);
break;
default:
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());
List<String> names = new ArrayList<>(
this.properties.getMetaRelease().getReleaseTrainDependencyNames());
names.add(this.properties.getMetaRelease().getReleaseTrainProjectName());
return names;
}
@@ -217,11 +245,14 @@ class Versions {
this.projects.removeIf(project -> expectedProjectName.equals(project.name));
}
@Override public String toString() {
return "Spring Boot Version=[" + this.bootVersion + ']' + "\nSpring Cloud Build Version=["
+ this.scBuildVersion + ']' + "\nProjects=\n\t" + this.projects.stream().map(Object::toString).collect(
Collectors.joining("\n\t"));
@Override
public String toString() {
return "Spring Boot Version=[" + this.bootVersion + ']'
+ "\nSpring Cloud Build Version=[" + this.scBuildVersion + ']'
+ "\nProjects=\n\t" + this.projects.stream().map(Object::toString)
.collect(Collectors.joining("\n\t"));
}
}
/**
@@ -232,6 +263,7 @@ class Project {
static Project EMPTY_PROJECT = new Project("", "");
final String name;
final String version;
Project(String name, String version) {
@@ -239,26 +271,32 @@ class Project {
this.version = version;
}
@Override public boolean equals(Object o) {
if (this == o)
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Project project = (Project) o;
if (this.name != null ? !this.name.equals(project.name) : project.name != null)
if (this.name != null ? !this.name.equals(project.name) : project.name != null) {
return false;
return this.version != null ?
this.version.equals(project.version) :
project.version == null;
}
return this.version != null ? this.version.equals(project.version)
: project.version == null;
}
@Override public int hashCode() {
@Override
public int hashCode() {
int result = this.name != null ? this.name.hashCode() : 0;
result = 31 * result + (this.version != null ? this.version.hashCode() : 0);
return result;
}
@Override public String toString() {
@Override
public String toString() {
return "name=[" + this.name + "], version=[" + this.version + ']';
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.post;
import java.io.Closeable;
@@ -35,14 +67,18 @@ public class PostReleaseActions implements Closeable {
private static final ExecutorService SERVICE = Executors.newCachedThreadPool();
private final ProjectGitHandler projectGitHandler;
private final ProjectPomUpdater projectPomUpdater;
private final GradleUpdater gradleUpdater;
private final ProjectBuilder projectBuilder;
private final ReleaserProperties properties;
public PostReleaseActions(ProjectGitHandler projectGitHandler,
ProjectPomUpdater projectPomUpdater, GradleUpdater gradleUpdater, ProjectBuilder projectBuilder,
ReleaserProperties properties) {
ProjectPomUpdater projectPomUpdater, GradleUpdater gradleUpdater,
ProjectBuilder projectBuilder, ReleaserProperties properties) {
this.projectGitHandler = projectGitHandler;
this.projectPomUpdater = projectPomUpdater;
this.gradleUpdater = gradleUpdater;
@@ -51,123 +87,128 @@ public class PostReleaseActions implements Closeable {
}
/**
* Clones the test project, updates it and runs tests
*
* Clones the test project, updates it and runs tests.
* @param projects - set of project with versions to assert against
*/
public void runUpdatedTests(Projects projects) {
if (!this.properties.getGit().isRunUpdatedSamples() ||
!this.properties.getMetaRelease().isEnabled()) {
if (!this.properties.getGit().isRunUpdatedSamples()
|| !this.properties.getMetaRelease().isEnabled()) {
log.info("Will not update and run test samples, since the switch to do so "
+ "is off. Set [releaser.git.run-updated-samples] to [true] to change that");
return;
}
File file = this.projectGitHandler.cloneTestSamplesProject();
ProjectVersion projectVersion = newProjectVersion(file);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion,
releaseTrainVersion);
updateWithVersions(file, newProjects);
this.projectBuilder.build(projectVersion, file.getAbsolutePath());
}
/**
* Clones all samples for the given project. For each of them, checks out the proper
* branch, updates all the poms with the new, bumped versions of release train projects,
* commits the changes and pushes them.
*
* branch, updates all the poms with the new, bumped versions of release train
* projects, commits the changes and pushes them.
* @param projects - set of project with versions to assert against
*/
public void updateAllTestSamples(Projects projects) {
if (!this.properties.getGit().isUpdateAllTestSamples() ||
!this.properties.getMetaRelease().isEnabled()) {
if (!this.properties.getGit().isUpdateAllTestSamples()
|| !this.properties.getMetaRelease().isEnabled()) {
log.info("Will not update all test samples, since the switch to do so "
+ "is off. Set [releaser.git.update-all-test-samples] to [true] to change that");
return;
}
List<ProjectUrlAndException> projectUrlAndExceptions = this.properties.getGit()
.getAllTestSampleUrls()
.entrySet()
.stream()
.map(e -> updateAllProjects(projects, e))
.map(this::getResult)
.flatMap(Collection::stream)
.collect(Collectors.toList());
.getAllTestSampleUrls().entrySet().stream()
.map(e -> updateAllProjects(projects, e)).map(this::getResult)
.flatMap(Collection::stream).collect(Collectors.toList());
log.info("Updated all samples!");
String exceptionMessages = projectUrlAndExceptions.stream()
.filter(ProjectUrlAndException::hasException)
.map(e -> "Project [" + e.key + "] for url [" + e.url + "] "
+ "has exception [\n\n" + Arrays
.stream(NestedExceptionUtils.getMostSpecificCause(e.ex)
.getStackTrace())
.map(StackTraceElement::toString)
.collect(Collectors.joining("\n")) + "]")
+ "has exception [\n\n"
+ Arrays.stream(NestedExceptionUtils.getMostSpecificCause(e.ex)
.getStackTrace()).map(StackTraceElement::toString)
.collect(Collectors.joining("\n"))
+ "]")
.collect(Collectors.joining("\n"));
if (StringUtils.hasText(exceptionMessages)) {
throw new IllegalStateException("Exceptions were found while updating samples\n" + exceptionMessages);
} else {
throw new IllegalStateException(
"Exceptions were found while updating samples\n" + exceptionMessages);
}
else {
log.info("No exceptions were found while updating the samples");
}
}
private Future<List<ProjectUrlAndException>> updateAllProjects(Projects projects, Map.Entry<String, List<String>> e) {
private Future<List<ProjectUrlAndException>> updateAllProjects(Projects projects,
Map.Entry<String, List<String>> e) {
return SERVICE.submit(() -> {
String key = e.getKey();
List<String> value = e.getValue();
log.info("Running version update for project [{}] and samples {}", key, value);
log.info("Running version update for project [{}] and samples {}", key,
value);
ProjectVersion projectVersionForReleaseTrain = projects.forName(key);
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")));
return value.stream()
.map(url -> run(key, url, () ->
commitUpdatedProject(projects, key, projectVersionForReleaseTrain, postRelease, url)))
.map(this::getResult)
.collect(Collectors.toList());
.map(url -> run(key, url,
() -> commitUpdatedProject(projects, key,
projectVersionForReleaseTrain, postRelease, url)))
.map(this::getResult).collect(Collectors.toList());
});
}
Projects getPostReleaseProjects(Projects projects) {
return projects
.postReleaseSnapshotVersion(this.properties.getMetaRelease().getProjectsToSkip());
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;
private void commitUpdatedProject(Projects projects, String key,
ProjectVersion projectVersionForReleaseTrain, Projects postRelease,
String url) {
String releaseTrainVersion = projects.forName(
this.properties.getMetaRelease().getReleaseTrainProjectName()).version;
String projectVersion = projects.forName(key).version;
log.info("Running version update for project [{}], url [{}], "
+ "release train version [{}] and project version [{}]", key, url,
releaseTrainVersion, projectVersion);
File file = this.projectGitHandler
.cloneAndGuessBranch(url, releaseTrainVersion, projectVersion);
log.info(
"Running version update for project [{}], url [{}], "
+ "release train version [{}] and project version [{}]",
key, url, releaseTrainVersion, projectVersion);
File file = this.projectGitHandler.cloneAndGuessBranch(url, releaseTrainVersion,
projectVersion);
Projects newPostRelease = new Projects(postRelease);
ProjectVersion newProjectVersion = newProjectVersion(file);
newPostRelease.add(newProjectVersion);
updateWithVersions(file, newPostRelease);
this.projectGitHandler
.commit(file, "Updated versions after [" + releaseTrainVersion + "] "
+ "release train and [" + projectVersionForReleaseTrain.version + "] ["
+ key + "] project release");
this.projectGitHandler.commit(file,
"Updated versions after [" + releaseTrainVersion + "] "
+ "release train and [" + projectVersionForReleaseTrain.version
+ "] [" + key + "] project release");
this.projectGitHandler.pushCurrentBranch(file);
}
private ProjectVersion newProjectVersion(File file) {
try {
return new ProjectVersion(file);
} catch (Exception ex) {
}
catch (Exception ex) {
ProjectVersion projectVersion = ProjectVersion.notMavenProject(file);
String name = projectVersion.projectName;
String version = projectVersion.version;
log.warn("Exception occurred while trying to read the pom file. Will assume that the project name is [" + name + "] and version [" + version + "]", ex);
log.warn(
"Exception occurred while trying to read the pom file. Will assume that the project name is ["
+ name + "] and version [" + version + "]",
ex);
return projectVersion;
}
}
private void updateWithVersions(File file, Projects newPostRelease) {
this.projectPomUpdater
.updateProjectFromReleaseTrain(file, newPostRelease,
newProjectVersion(file), false);
this.projectPomUpdater.updateProjectFromReleaseTrain(file, newPostRelease,
newProjectVersion(file), false);
this.gradleUpdater.updateProjectFromBom(file, newPostRelease,
newProjectVersion(file), false);
}
@@ -188,7 +229,8 @@ public class PostReleaseActions implements Closeable {
return new ProjectUrlAndException(projectAndFuture.key, projectAndFuture.url, e);
}
private List<ProjectUrlAndException> getResult(Future<List<ProjectUrlAndException>> future) {
private List<ProjectUrlAndException> getResult(
Future<List<ProjectUrlAndException>> future) {
try {
return future.get(10, TimeUnit.MINUTES);
}
@@ -198,29 +240,32 @@ public class PostReleaseActions implements Closeable {
}
/**
* Clones the release train documentation project
*
* Clones the release train documentation project.
* @param projects - set of project with versions to assert against
*/
public void generateReleaseTrainDocumentation(Projects projects) {
if (!this.properties.getGit().isUpdateReleaseTrainDocs() ||
!this.properties.getMetaRelease().isEnabled()) {
log.info("Will not update the release train documentation, since the switch to do so "
+ "is off. Set [releaser.git.update-release-train-docs] to [true] to change that");
if (!this.properties.getGit().isUpdateReleaseTrainDocs()
|| !this.properties.getMetaRelease().isEnabled()) {
log.info(
"Will not update the release train documentation, since the switch to do so "
+ "is off. Set [releaser.git.update-release-train-docs] to [true] to change that");
return;
}
File file = this.projectGitHandler.cloneReleaseTrainDocumentationProject();
ProjectVersion projectVersion = newProjectVersion(file);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion,
releaseTrainVersion);
updateWithVersions(file, newProjects);
this.projectBuilder.generateReleaseTrainDocs(releaseTrainVersion, file.getAbsolutePath());
this.projectBuilder.generateReleaseTrainDocs(releaseTrainVersion,
file.getAbsolutePath());
}
private Projects addVersionForTestsProject(Projects projects, ProjectVersion projectVersion,
String releaseTrainVersion) {
private Projects addVersionForTestsProject(Projects projects,
ProjectVersion projectVersion, String releaseTrainVersion) {
Projects newProjects = new Projects(projects);
newProjects.add(new ProjectVersion(projectVersion.projectName, releaseTrainVersion));
newProjects
.add(new ProjectVersion(projectVersion.projectName, releaseTrainVersion));
return newProjects;
}
@@ -228,12 +273,15 @@ public class PostReleaseActions implements Closeable {
public void close() {
SERVICE.shutdown();
}
}
class ProjectAndFuture {
final String key;
final String url;
final Future future;
ProjectAndFuture(String key, String url, Future future) {
@@ -241,11 +289,15 @@ class ProjectAndFuture {
this.url = url;
this.future = future;
}
}
class ProjectUrlAndException {
final String key;
final String url;
final Exception ex;
ProjectUrlAndException(String key, String url, Exception ex) {
@@ -257,4 +309,5 @@ class ProjectUrlAndException {
boolean hasException() {
return this.ex != null;
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.project;
import java.io.File;
@@ -17,8 +49,9 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.util.StringUtils;
@@ -28,6 +61,7 @@ import org.springframework.util.StringUtils;
public class ProjectBuilder implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory.getLogger(ProjectBuilder.class);
private static final String VERSION_MUSTACHE = "{{version}}";
private ReleaserProperties properties;
@@ -42,34 +76,38 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
public void build(ProjectVersion versionFromReleaseTrain, String projectRoot) {
try {
String[] commands = commandWithSystemProps(this.properties.getMaven().getBuildCommand(),
versionFromReleaseTrain).split(" ");
String[] commands = commandWithSystemProps(
this.properties.getMaven().getBuildCommand(), versionFromReleaseTrain)
.split(" ");
runCommand(projectRoot, commands);
assertNoHtmlFilesInDocsContainUnresolvedTags(projectRoot);
log.info("No HTML files from docs contain unresolved tags");
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
public void generateReleaseTrainDocs(String version, String projectRoot) {
try {
String updatedCommand =
this.properties.getMaven().getGenerateReleaseTrainDocsCommand().replace(VERSION_MUSTACHE, version);
String updatedCommand = this.properties.getMaven()
.getGenerateReleaseTrainDocsCommand()
.replace(VERSION_MUSTACHE, version);
runCommand(projectRoot, updatedCommand.split(" "));
assertNoHtmlFilesInDocsContainUnresolvedTags(this.properties.getWorkingDir());
log.info("No HTML files from docs contain unresolved tags");
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
private String commandWithSystemProps(String command,
ProjectVersion version) {
private String commandWithSystemProps(String command, ProjectVersion version) {
if (command.contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) {
return appendProfile(command, version);
}
return appendProfile(command, version) + " " + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER;
return appendProfile(command, version) + " "
+ ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER;
}
private String appendProfile(String command, ProjectVersion version) {
@@ -77,10 +115,12 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
if (version.isMilestone() || version.isRc()) {
log.info("Adding the milestone profile to the Maven build");
return trimmedCommand + " -Pmilestone";
} else if (version.isRelease() || version.isServiceRelease()) {
}
else if (version.isRelease() || version.isServiceRelease()) {
log.info("Adding the central profile to the Maven build");
return trimmedCommand + " -Pcentral";
} else {
}
else {
log.info("The build is a snapshot one - will not add any profiles");
}
return trimmedCommand;
@@ -101,11 +141,12 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
public void deploy(ProjectVersion version) {
try {
String[] commands = commandWithSystemProps(this.properties.getMaven().getDeployCommand(),
version).split(" ");
String[] commands = commandWithSystemProps(
this.properties.getMaven().getDeployCommand(), version).split(" ");
runCommand(commands);
log.info("The project has successfully been deployed");
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
@@ -132,29 +173,31 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
runCommand(commands);
}
log.info("The docs got published successfully");
} catch (Exception e) {
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
* We need to insert the system properties as a list of -Dkey=value entries
* instead of just pasting the String that contains these values
* We need to insert the system properties as a list of -Dkey=value entries instead of
* just pasting the String that contains these values.
*/
private String[] substituteSystemProps(String... commands) {
boolean containsSystemProps = this.properties.getMaven().getSystemProperties().contains("-D");
String[] splitSystemProps = StringUtils.delimitedListToStringArray(this.properties.getMaven()
.getSystemProperties(), "-D");
boolean containsSystemProps = this.properties.getMaven().getSystemProperties()
.contains("-D");
String[] splitSystemProps = StringUtils.delimitedListToStringArray(
this.properties.getMaven().getSystemProperties(), "-D");
// first element might be empty even though the second one contains values
if (splitSystemProps.length > 1) {
splitSystemProps = StringUtils.isEmpty(splitSystemProps[0]) ?
Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length) :
splitSystemProps;
splitSystemProps = StringUtils.isEmpty(splitSystemProps[0])
? Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length)
: splitSystemProps;
}
String[] systemPropsWithPrefix = containsSystemProps ? Arrays.stream(splitSystemProps)
.map(s -> "-D" + s.trim())
.collect(Collectors.toList())
.toArray(new String[splitSystemProps.length]) : splitSystemProps;
String[] systemPropsWithPrefix = containsSystemProps ? Arrays
.stream(splitSystemProps).map(s -> "-D" + s.trim())
.collect(Collectors.toList()).toArray(new String[splitSystemProps.length])
: splitSystemProps;
final AtomicInteger index = new AtomicInteger(-1);
for (int i = 0; i < commands.length; i++) {
if (commands[i].contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) {
@@ -168,8 +211,10 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
commandsList.remove(index.get());
if (index.get() >= commandsList.size()) {
commandsList.addAll(systemPropsList);
} else {
// we need to reverse to set the objects in the same order as passed in the prop
}
else {
// we need to reverse to set the objects in the same order as passed in
// the prop
List<String> reversedSystemProps = new ArrayList<>(systemPropsList);
Collections.reverse(reversedSystemProps);
reversedSystemProps.forEach(s -> commandsList.add(index.get(), s));
@@ -178,12 +223,15 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
return commandsList.toArray(new String[commandsList.size()]);
}
@Override public void setReleaserProperties(ReleaserProperties properties) {
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
class ProcessExecutor implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory.getLogger(ProcessExecutor.class);
private String workingDir;
@@ -195,18 +243,22 @@ class ProcessExecutor implements ReleaserPropertiesAware {
void runCommand(String[] commands, long waitTimeInMinutes) {
try {
String workingDir = this.workingDir;
log.debug("Will run the command from [{}] via {} and wait for result for [{}] minutes",
log.debug(
"Will run the command from [{}] via {} and wait for result for [{}] minutes",
workingDir, commands, waitTimeInMinutes);
ProcessBuilder builder = builder(commands, workingDir);
Process process = startProcess(builder);
boolean finished = process.waitFor(waitTimeInMinutes, TimeUnit.MINUTES);
if (!finished) {
log.error("The command hasn't managed to finish in [{}] minutes", waitTimeInMinutes);
log.error("The command hasn't managed to finish in [{}] minutes",
waitTimeInMinutes);
process.destroyForcibly();
throw new IllegalStateException("Process waiting time of [" + waitTimeInMinutes + "] minutes exceeded");
throw new IllegalStateException("Process waiting time of ["
+ waitTimeInMinutes + "] minutes exceeded");
}
if (process.exitValue() != 0) {
throw new IllegalStateException("The process has exited with exit code [" + process.exitValue() + "]");
throw new IllegalStateException("The process has exited with exit code ["
+ process.exitValue() + "]");
}
}
catch (InterruptedException | IOException e) {
@@ -219,24 +271,27 @@ class ProcessExecutor implements ReleaserPropertiesAware {
}
ProcessBuilder builder(String[] commands, String workingDir) {
return new ProcessBuilder(commands)
.directory(new File(workingDir))
.inheritIO();
return new ProcessBuilder(commands).directory(new File(workingDir)).inheritIO();
}
@Override public void setReleaserProperties(ReleaserProperties properties) {
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.workingDir = properties.getWorkingDir();
}
}
class HtmlFileWalker extends SimpleFileVisitor<Path> {
private static final String HTML_EXTENSION = ".html";
@Override public FileVisitResult visitFile(Path path, BasicFileAttributes attr) {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attr) {
File file = path.toFile();
if (file.getName().endsWith(HTML_EXTENSION) && asString(file).contains("Unresolved")) {
throw new IllegalStateException("File [" + file + "] contains a tag that wasn't resolved properly");
if (file.getName().endsWith(HTML_EXTENSION)
&& asString(file).contains("Unresolved")) {
throw new IllegalStateException(
"File [" + file + "] contains a tag that wasn't resolved properly");
}
return FileVisitResult.CONTINUE;
}
@@ -249,4 +304,5 @@ class HtmlFileWalker extends SimpleFileVisitor<Path> {
throw new IllegalStateException(e);
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.util.ArrayList;
@@ -8,23 +40,41 @@ import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Project {
public String id = "";
public String name = "";
public String repoUrl = "";
public String siteUrl = "";
public String category = "";
public String stackOverflowTags;
public List<Release> projectReleases = new ArrayList<>();
public List<String> stackOverflowTagList = new ArrayList<>();
public Boolean aggregator;
@Override public String toString() {
return "Project{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' + ", repoUrl='"
+ this.repoUrl + '\'' + ", siteUrl='" + this.siteUrl + '\'' + ", category='"
+ this.category + '\'' + ", stackOverflowTags='" + this.stackOverflowTags + '\''
+ ", projectReleases=" + this.projectReleases + ", stackOverflowTagList="
+ this.stackOverflowTagList + ", aggregator=" + this.aggregator + '}';
public String rawBootConfig;
public String rawOverview;
@Override
public String toString() {
return "Project{" + "id='" + this.id + '\'' + ", name='" + this.name + '\''
+ ", repoUrl='" + this.repoUrl + '\'' + ", siteUrl='" + this.siteUrl
+ '\'' + ", category='" + this.category + '\'' + ", stackOverflowTags='"
+ this.stackOverflowTags + '\'' + ", projectReleases="
+ this.projectReleases + ", stackOverflowTagList="
+ this.stackOverflowTagList + ", aggregator=" + this.aggregator
+ ", rawBootConfig='" + this.rawBootConfig + '\'' + ", rawOverview='"
+ this.rawOverview + '\'' + '}';
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -5,28 +37,43 @@ import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Release {
public String releaseStatus = "";
public String refDocUrl = "";
public String apiDocUrl = "";
public String groupId = "";
public String artifactId = "";
public Repository repository;
public String version = "";
public boolean current;
public boolean generalAvailability;
public boolean preRelease;
public String versionDisplayName = "";
public boolean snapshot;
@Override public String toString() {
return "Release{" + "releaseStatus='" + this.releaseStatus + '\'' + ", refDocUrl='"
+ this.refDocUrl + '\'' + ", apiDocUrl='" + this.apiDocUrl + '\'' + ", groupId='"
+ this.groupId + '\'' + ", artifactId='" + this.artifactId + '\'' + ", repository="
+ this.repository + ", version='" + this.version + '\'' + ", current=" + this.current
+ ", generalAvailability=" + this.generalAvailability + ", preRelease="
+ this.preRelease + ", versionDisplayName='" + this.versionDisplayName + '\''
+ ", snapshot=" + this.snapshot + '}';
@Override
public String toString() {
return "Release{" + "releaseStatus='" + this.releaseStatus + '\''
+ ", refDocUrl='" + this.refDocUrl + '\'' + ", apiDocUrl='"
+ this.apiDocUrl + '\'' + ", groupId='" + this.groupId + '\''
+ ", artifactId='" + this.artifactId + '\'' + ", repository="
+ this.repository + ", version='" + this.version + '\'' + ", current="
+ this.current + ", generalAvailability=" + this.generalAvailability
+ ", preRelease=" + this.preRelease + ", versionDisplayName='"
+ this.versionDisplayName + '\'' + ", snapshot=" + this.snapshot + '}';
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -5,21 +37,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReleaseUpdate {
public String groupId = "";
public String artifactId = "";
public String version = "";
public String releaseStatus = "";
public String refDocUrl = "";
public String apiDocUrl = "";
public Boolean current;
public Repository repository;
@Override public String toString() {
@Override
public String toString() {
return "ReleaseUpdate{" + "groupId='" + this.groupId + '\'' + ", artifactId='"
+ this.artifactId + '\'' + ", version='" + this.version + '\'' + ", releaseStatus='"
+ this.releaseStatus + '\'' + ", refDocUrl='" + this.refDocUrl + '\''
+ ", apiDocUrl='" + this.apiDocUrl + '\'' + ", repository=" + this.repository + '}';
+ this.artifactId + '\'' + ", version='" + this.version + '\''
+ ", releaseStatus='" + this.releaseStatus + '\'' + ", refDocUrl='"
+ this.refDocUrl + '\'' + ", apiDocUrl='" + this.apiDocUrl + '\''
+ ", repository=" + this.repository + '}';
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -5,15 +37,22 @@ import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @author Marcin Grzejszczak
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Repository {
public String id;
public String name;
public String url;
public Boolean snapshotsEnabled;
@Override public String toString() {
return "Repository{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' + ", url='"
+ this.url + '\'' + ", snapshotsEnabled=" + this.snapshotsEnabled + '}';
@Override
public String toString() {
return "Repository{" + "id='" + this.id + '\'' + ", name='" + this.name + '\''
+ ", url='" + this.url + '\'' + ", snapshotsEnabled="
+ this.snapshotsEnabled + '}';
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.net.URI;
@@ -5,6 +37,7 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -19,9 +52,11 @@ import org.springframework.web.client.RestTemplate;
*/
class RestTemplateSaganClient implements SaganClient {
private static final Logger log = LoggerFactory.getLogger(RestTemplateSaganClient.class);
private static final Logger log = LoggerFactory
.getLogger(RestTemplateSaganClient.class);
private final RestTemplate restTemplate;
private final String baseUrl;
RestTemplateSaganClient(RestTemplate restTemplate, ReleaserProperties properties) {
@@ -29,17 +64,28 @@ class RestTemplateSaganClient implements SaganClient {
this.baseUrl = properties.getSagan().getBaseUrl();
}
@Override public Project getProject(String projectName) {
return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}", Project.class, projectName);
@Override
public Project getProject(String projectName) {
return this.restTemplate.getForObject(
this.baseUrl + "/project_metadata/{projectName}", Project.class,
projectName);
}
@Override public Release getRelease(String projectName, String releaseVersion) {
return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}", Release.class, projectName, releaseVersion);
@Override
public Release getRelease(String projectName, String releaseVersion) {
return this.restTemplate.getForObject(
this.baseUrl
+ "/project_metadata/{projectName}/releases/{releaseVersion}",
Release.class, projectName, releaseVersion);
}
@Override public Release deleteRelease(String projectName, String releaseVersion) {
ResponseEntity<Release> entity = this.restTemplate.exchange(this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}",
HttpMethod.DELETE, new HttpEntity<>(""), Release.class, projectName, releaseVersion);
@Override
public Release deleteRelease(String projectName, String releaseVersion) {
ResponseEntity<Release> entity = this.restTemplate.exchange(
this.baseUrl
+ "/project_metadata/{projectName}/releases/{releaseVersion}",
HttpMethod.DELETE, new HttpEntity<>(""), Release.class, projectName,
releaseVersion);
Release release = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, release);
return release;
@@ -48,13 +94,28 @@ class RestTemplateSaganClient implements SaganClient {
@Override
public Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdates) {
RequestEntity<List<ReleaseUpdate>> request = RequestEntity
.put(URI.create(this.baseUrl +"/project_metadata/" + projectName + "/releases"))
.put(URI.create(
this.baseUrl + "/project_metadata/" + projectName + "/releases"))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.body(releaseUpdates);
ResponseEntity<Project> entity = this.restTemplate
.exchange(request, Project.class);
ResponseEntity<Project> entity = this.restTemplate.exchange(request,
Project.class);
Project project = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, project);
return project;
}
@Override
public void patchProject(Project project) {
RequestEntity<Project> request = RequestEntity
.patch(URI
.create(this.baseUrl + "/project_metadata/" + project.name + "/"))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.body(project);
ResponseEntity<Project> entity = this.restTemplate.exchange(request,
Project.class);
Project updatedProject = entity.getBody();
log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, updatedProject);
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.util.List;
@@ -6,6 +38,7 @@ import java.util.List;
* @author Marcin Grzejszczak
*/
public interface SaganClient {
Project getProject(String projectName);
Release getRelease(String projectName, String releaseVersion);
@@ -13,4 +46,7 @@ public interface SaganClient {
Release deleteRelease(String projectName, String releaseVersion);
Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdate);
void patchProject(Project project);
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.util.stream.Collectors;
@@ -17,6 +49,7 @@ public class SaganUpdater {
private static final Logger log = LoggerFactory.getLogger(SaganUpdater.class);
private final SaganClient saganClient;
private final ReleaserProperties releaserProperties;
public SaganUpdater(SaganClient saganClient, ReleaserProperties releaserProperties) {
@@ -24,7 +57,8 @@ public class SaganUpdater {
this.releaserProperties = releaserProperties;
}
public void updateSagan(String branch, ProjectVersion originalVersion, ProjectVersion version) {
public void updateSagan(String branch, ProjectVersion originalVersion,
ProjectVersion version) {
if (!this.releaserProperties.getSagan().isUpdateSagan()) {
log.info("Will not update sagan, since the switch to do so "
+ "is off. Set [releaser.sagan.update-sagan] to [true] to change that");
@@ -33,13 +67,16 @@ public class SaganUpdater {
ReleaseUpdate update = releaseUpdate(branch, originalVersion, version);
updateSaganForNonSnapshot(branch, originalVersion, version);
log.info("Updating Sagan with \n\n{}", update);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
this.saganClient.updateRelease(version.projectName,
Collections.singletonList(update));
}
private void updateSaganForNonSnapshot(String branch, ProjectVersion originalVersion,
ProjectVersion version) {
if (!version.isSnapshot()) {
log.info("Version is non snapshot [{}]. Will remove all older versions and mark this as current", version);
log.info(
"Version is non snapshot [{}]. Will remove all older versions and mark this as current",
version);
Project project = this.saganClient.getProject(version.projectName);
if (project != null) {
removeAllSameMinorVersions(version, project);
@@ -48,10 +85,11 @@ public class SaganUpdater {
removeVersionFromSagan(version, snapshot);
if (version.isRelease() || version.isServiceRelease()) {
String bumpedSnapshot = toSnapshot(version.bumpedVersion());
ReleaseUpdate snapshotUpdate =
releaseUpdate(branch, originalVersion, new ProjectVersion(version.projectName, bumpedSnapshot));
ReleaseUpdate snapshotUpdate = releaseUpdate(branch, originalVersion,
new ProjectVersion(version.projectName, bumpedSnapshot));
log.info("Updating Sagan with bumped snapshot \n\n[{}]", snapshotUpdate);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(snapshotUpdate));
this.saganClient.updateRelease(version.projectName,
Collections.singletonList(snapshotUpdate));
}
}
}
@@ -67,8 +105,10 @@ public class SaganUpdater {
log.info("Removing [{}/{}] from Sagan", version.projectName, snapshot);
try {
this.saganClient.deleteRelease(version.projectName, snapshot);
} catch (Exception e) {
log.error("Failed to remove [" + version.projectName + "/" + snapshot + "] from Sagan", e);
}
catch (Exception e) {
log.error("Failed to remove [" + version.projectName + "/" + snapshot
+ "] from Sagan", e);
}
}
@@ -88,7 +128,8 @@ public class SaganUpdater {
private String toSnapshot(String version) {
if (version.contains("RELEASE")) {
return version.replace("RELEASE", "BUILD-SNAPSHOT");
} else if (version.matches(".*SR[0-9]+")) {
}
else if (version.matches(".*SR[0-9]+")) {
return version.substring(0, version.lastIndexOf(".")) + ".BUILD-SNAPSHOT";
}
return version;
@@ -97,9 +138,11 @@ public class SaganUpdater {
private String version(ProjectVersion version) {
if (version.isSnapshot()) {
return "SNAPSHOT";
} else if (version.isMilestone() || version.isRc()) {
}
else if (version.isMilestone() || version.isRc()) {
return "PRERELEASE";
} else if (version.isRelease() || version.isServiceRelease()) {
}
else if (version.isRelease() || version.isServiceRelease()) {
return "GENERAL_AVAILABILITY";
}
return "";
@@ -108,13 +151,16 @@ public class SaganUpdater {
private String referenceUrl(String branch, ProjectVersion version) {
if (!version.isSnapshot()) {
// static/sleuth/{version}/
return "http://cloud.spring.io/spring-cloud-static/" + version.projectName + "/{version}/";
return "http://cloud.spring.io/spring-cloud-static/" + version.projectName
+ "/{version}/";
}
if (branch.toLowerCase().contains("master")) {
// sleuth/
return "http://cloud.spring.io/" + version.projectName + "/" + version.projectName + ".html";
return "http://cloud.spring.io/" + version.projectName + "/"
+ version.projectName + ".html";
}
// sleuth/1.1.x/
return "http://cloud.spring.io/" + version.projectName + "/" + branch + "/";
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.tech;
import java.io.IOException;
@@ -12,10 +44,14 @@ import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
*/
public final class HandlebarsHelper {
private HandlebarsHelper() {
throw new IllegalStateException("Can't instantiate a utility class");
}
public static Template template(String templateSubFolder, String templateName) {
try {
Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader("/templates/" +
templateSubFolder));
Handlebars handlebars = new Handlebars(
new ClassPathTemplateLoader("/templates/" + templateSubFolder));
handlebars.registerHelper("replace", StringHelpers.replace);
handlebars.registerHelper("capitalizeFirst", StringHelpers.capitalizeFirst);
return handlebars.compile(templateName);
@@ -24,4 +60,5 @@ public final class HandlebarsHelper {
throw new IllegalStateException(e);
}
}
}

View File

@@ -5,7 +5,23 @@
* 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
* 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.
*/
/*
* Copyright 2013-2019 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,
@@ -20,12 +36,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Exception to be thrown if one wants to continue with the build
* and throw this exception at the end of the release
* Exception to be thrown if one wants to continue with the build and throw this exception
* at the end of the release.
*
* @author Marcin Grzejszczak
*/
public class MakeBuildUnstableException extends RuntimeException {
private static final Logger log = LoggerFactory.getLogger(MakeBuildUnstableException.class);
private static final Logger log = LoggerFactory
.getLogger(MakeBuildUnstableException.class);
public MakeBuildUnstableException(Throwable cause) {
super(cause);
@@ -41,4 +60,5 @@ public class MakeBuildUnstableException extends RuntimeException {
super(message, cause);
log.error("\n\n[BUILD UNSTABLE] WARNING! " + message, cause);
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
@@ -19,16 +51,23 @@ import org.springframework.cloud.release.internal.pom.Projects;
*/
class BlogTemplateGenerator {
private static final Logger log = LoggerFactory.getLogger(BlogTemplateGenerator.class);
private static final Logger log = LoggerFactory
.getLogger(BlogTemplateGenerator.class);
private static final Pattern RC_PATTERN = Pattern.compile("(.*)(RC)([0-9]+)");
private static final Pattern MILESTONE_PATTERN = Pattern.compile("(.*)(M)([0-9]+)");
private static final Pattern SR_PATTERN = Pattern.compile("(.*)(SR)([0-9]+)");
private final Template template;
private final String releaseVersion;
private final File blogOutput;
private final Projects projects;
private final NotesGenerator notesGenerator;
BlogTemplateGenerator(Template template, String releaseVersion, File blogOutput,
@@ -42,31 +81,33 @@ class BlogTemplateGenerator {
File blog() {
try {
// availability - General Availability (RELEASE) / Service Release 1 (SR1) / Milestone 1 (M1)
// availability - General Availability (RELEASE) / Service Release 1 (SR1) /
// Milestone 1 (M1)
// releaseName - Dalston
// releaseLink
// - [Maven Central](http://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-dependencies/Dalston.RELEASE/)
// - [Maven Central](http://repo1.maven.org/maven2/org/
// springframework/cloud/spring-cloud-dependencies/Dalston.RELEASE/)
// - [Spring Milestone](https://repo.spring.io/milestone/) repository
// releaseVersion '- Dalston.RELEASE
boolean release = this.releaseVersion.contains("RELEASE");
boolean nonRelease = !(release || SR_PATTERN.matcher(this.releaseVersion).matches());
boolean nonRelease = !(release
|| SR_PATTERN.matcher(this.releaseVersion).matches());
String availability = availability(release);
String releaseName = parsedReleaseName(this.releaseVersion);
String releaseLink = link(nonRelease);
Map<String, Object> map = ImmutableMap.<String, Object>builder()
.put("availability", availability)
.put("releaseName", releaseName)
.put("availability", availability).put("releaseName", releaseName)
.put("releaseLink", releaseLink)
.put("releaseVersion", this.releaseVersion)
.put("projects", this.notesGenerator.fromProjects(this.projects))
.put("nonRelease", nonRelease)
.build();
.put("nonRelease", nonRelease).build();
String blog = this.template.apply(map);
Files.write(this.blogOutput.toPath(), blog.getBytes());
return this.blogOutput;
}
catch (Exception e) {
throw new IllegalStateException("Exception occurred while trying to create a blog entry", e);
throw new IllegalStateException(
"Exception occurred while trying to create a blog entry", e);
}
}
@@ -80,15 +121,20 @@ class BlogTemplateGenerator {
Matcher milestone = MILESTONE_PATTERN.matcher(this.releaseVersion);
if (release) {
return "General Availability (RELEASE)";
} else if (sr.matches()) {
}
else if (sr.matches()) {
return availabilityText(sr, "Service Release", "SR");
} else if (rc.matches()) {
}
else if (rc.matches()) {
return availabilityText(rc, "Release Candidate", "RC");
} else if (milestone.matches()) {
}
else if (milestone.matches()) {
return milestone(milestone);
}
if (log.isWarnEnabled()) {
log.warn("Unrecognized release [{}] . Hopefully, you know what you're doing. Will treat it as milestone", this.releaseVersion);
log.warn("Unrecognized release [{}] . "
+ "Hopefully, you know what you're doing. Will treat it as milestone",
this.releaseVersion);
}
return milestone(milestone);
}
@@ -106,6 +152,9 @@ class BlogTemplateGenerator {
if (nonRelease) {
return "[Spring Milestone](https://repo.spring.io/milestone/) repository";
}
return "[Maven Central](http://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-dependencies/" + this.releaseVersion + "/)";
return "[Maven Central](http://repo1.maven.org/maven2/"
+ "org/springframework/cloud/spring-cloud-dependencies/"
+ this.releaseVersion + "/)";
}
}

View File

@@ -1,22 +1,56 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
import java.nio.file.Files;
import com.github.jknack.handlebars.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.jknack.handlebars.Template;
/**
* @author Marcin Grzejszczak
*/
class EmailTemplateGenerator {
private static final Logger log = LoggerFactory.getLogger(EmailTemplateGenerator.class);
private static final Logger log = LoggerFactory
.getLogger(EmailTemplateGenerator.class);
private final Template template;
private final String releaseVersion;
private final File emailOutput;
EmailTemplateGenerator(Template template, String releaseVersion, File emailOutput) {
@@ -32,7 +66,9 @@ class EmailTemplateGenerator {
return this.emailOutput;
}
catch (Exception e) {
throw new IllegalStateException("Exception occurred while trying to generate an email template", e);
throw new IllegalStateException(
"Exception occurred while trying to generate an email template", e);
}
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.util.Arrays;
@@ -20,22 +52,26 @@ class NotesGenerator {
}
Set<Notes> fromProjects(Projects projects) {
return projects.stream().filter(projectVersion ->
!projectVersion.projectName.toLowerCase().contains("boot")
).map(projectVersion -> {
String name = projectVersion.projectName;
String version = projectVersion.version;
String closedMilestoneUrl = this.handler.milestoneUrl(projectVersion);
String convertedName = Arrays.stream(name.split("-"))
.map(StringUtils::capitalize).collect(Collectors.joining(" "));
return new Notes(convertedName, version, closedMilestoneUrl);
}).collect(Collectors.toSet());
return projects.stream().filter(projectVersion -> !projectVersion.projectName
.toLowerCase().contains("boot")).map(projectVersion -> {
String name = projectVersion.projectName;
String version = projectVersion.version;
String closedMilestoneUrl = this.handler.milestoneUrl(projectVersion);
String convertedName = Arrays.stream(name.split("-"))
.map(StringUtils::capitalize)
.collect(Collectors.joining(" "));
return new Notes(convertedName, version, closedMilestoneUrl);
}).collect(Collectors.toSet());
}
}
class Notes {
private final String name;
private final String version;
private final String closedMilestoneUrl;
Notes(String name, String version, String closedMilestoneUrl) {
@@ -57,22 +93,27 @@ class Notes {
return this.closedMilestoneUrl;
}
@Override public boolean equals(Object o) {
if (this == o)
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Notes notes = (Notes) o;
if (this.name != null ? !this.name.equals(notes.name) : notes.name != null)
if (this.name != null ? !this.name.equals(notes.name) : notes.name != null) {
return false;
return this.version != null ?
this.version.equals(notes.version) :
notes.version == null;
}
return this.version != null ? this.version.equals(notes.version)
: notes.version == null;
}
@Override public int hashCode() {
@Override
public int hashCode() {
int result = this.name != null ? this.name.hashCode() : 0;
result = 31 * result + (this.version != null ? this.version.hashCode() : 0);
return result;
}
}

View File

@@ -1,3 +1,35 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
@@ -20,12 +52,17 @@ import org.springframework.cloud.release.internal.pom.Projects;
*/
class ReleaseNotesTemplateGenerator {
private static final Logger log = LoggerFactory.getLogger(ReleaseNotesTemplateGenerator.class);
private static final Logger log = LoggerFactory
.getLogger(ReleaseNotesTemplateGenerator.class);
private final Template template;
private final String releaseVersion;
private final File blogOutput;
private final Projects projects;
private final NotesGenerator notesGenerator;
ReleaseNotesTemplateGenerator(Template template, String releaseVersion,
@@ -49,7 +86,9 @@ class ReleaseNotesTemplateGenerator {
return this.blogOutput;
}
catch (IOException e) {
throw new IllegalStateException("Exception occurred while trying to generate release notes", e);
throw new IllegalStateException(
"Exception occurred while trying to generate release notes", e);
}
}
}

View File

@@ -1,32 +1,73 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
import java.io.IOException;
import com.github.jknack.handlebars.Template;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.Projects;
import org.springframework.cloud.release.internal.tech.HandlebarsHelper;
import com.github.jknack.handlebars.Template;
/**
* @author Marcin Grzejszczak
*/
public class TemplateGenerator implements ReleaserPropertiesAware {
private static final String EMAIL_TEMPLATE = "email";
private static final String BLOG_TEMPLATE = "blog";
private static final String TWITTER_TEMPLATE = "tweet";
private static final String RELEASE_NOTES_TEMPLATE = "notes";
private final File emailOutput;
private final File blogOutput;
private final File tweetOutput;
private final File releaseNotesOutput;
private ReleaserProperties props;
private final ProjectGitHandler handler;
private ReleaserProperties props;
public TemplateGenerator(ReleaserProperties props, ProjectGitHandler handler) {
this.props = props;
this.handler = handler;
@@ -63,7 +104,8 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
throw new IllegalStateException("Couldn't create a file [" + file + "]");
}
return file;
} catch (IOException e) {
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
@@ -72,7 +114,8 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
File blogOutput = file(this.blogOutput);
String releaseVersion = parsedVersion(projects);
Template template = template(BLOG_TEMPLATE);
return new BlogTemplateGenerator(template, releaseVersion, blogOutput, projects, this.handler).blog();
return new BlogTemplateGenerator(template, releaseVersion, blogOutput, projects,
this.handler).blog();
}
public File tweet(Projects projects) {
@@ -86,8 +129,8 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
File output = file(this.releaseNotesOutput);
String releaseVersion = parsedVersion(projects);
Template template = template(RELEASE_NOTES_TEMPLATE);
return new ReleaseNotesTemplateGenerator(template, releaseVersion,
output, projects, this.handler).releaseNotes();
return new ReleaseNotesTemplateGenerator(template, releaseVersion, output,
projects, this.handler).releaseNotes();
}
private String parsedVersion(Projects projects) {
@@ -102,10 +145,13 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
}
private Template template(String template) {
return HandlebarsHelper.template(this.props.getTemplate().getTemplateFolder(), template);
return HandlebarsHelper.template(this.props.getTemplate().getTemplateFolder(),
template);
}
@Override public void setReleaserProperties(ReleaserProperties properties) {
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.props = properties;
}
}

View File

@@ -1,21 +1,56 @@
/*
* Copyright 2013-2019 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
import java.nio.file.Files;
import com.github.jknack.handlebars.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.jknack.handlebars.Template;
/**
* @author Marcin Grzejszczak
*/
class TwitterTemplateGenerator {
private static final Logger log = LoggerFactory.getLogger(TwitterTemplateGenerator.class);
private static final Logger log = LoggerFactory
.getLogger(TwitterTemplateGenerator.class);
private final Template template;
private final String releaseVersion;
private final File output;
TwitterTemplateGenerator(Template template, String releaseVersion, File output) {
@@ -31,7 +66,9 @@ class TwitterTemplateGenerator {
return this.output;
}
catch (Exception e) {
throw new IllegalStateException("Exception occurred while trying to generate a twitter template", e);
throw new IllegalStateException(
"Exception occurred while trying to generate a twitter template", e);
}
}
}

View File

@@ -9,4 +9,4 @@ On behalf of the team and the community, I'm excited to announce Spring Cloud {{
link to blog post
link to twitter
Cheers,
Cheers,

View File

@@ -3,4 +3,4 @@
{{ date }}
{{#each projects}} - {{name}} `{{version}}` {{#if closedMilestoneUrl}}([issues]({{{ closedMilestoneUrl }}})){{/if}}
{{/each}}
{{/each}}

View File

@@ -356,4 +356,4 @@ Spring dependency management plugin.
{% endcapture %}
{% include project_page.html %}
</html>
</html>

View File

@@ -1 +1 @@
The {{ this }} version of @springcloud has been released!
The {{ this }} version of @springcloud has been released!

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
import java.io.File;
@@ -11,6 +27,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.Projects;
@@ -25,8 +42,11 @@ import static org.assertj.core.api.BDDAssertions.then;
*/
public class PomUpdateAcceptanceTests {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
TestPomReader testPomReader = new TestPomReader();
@Rule public TemporaryFolder tmp = new TemporaryFolder();
File temporaryFolder;
@Before
@@ -44,21 +64,25 @@ public class PomUpdateAcceptanceTests {
Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom();
File project = new File(this.temporaryFolder, "/spring-cloud-sleuth");
projectPomUpdater
.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true);
projectPomUpdater.updateProjectFromReleaseTrain(project, projects,
projects.forFile(project), true);
then(this.temporaryFolder).exists();
Model rootPom = this.testPomReader.readPom(tmpFile("/spring-cloud-sleuth/pom.xml"));
Model depsPom = this.testPomReader.readPom(tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-dependencies/pom.xml"));
Model corePom = this.testPomReader.readPom(tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-core/pom.xml"));
Model zipkinStreamPom = this.testPomReader.readPom(tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-zipkin-stream/pom.xml"));
Model rootPom = this.testPomReader
.readPom(tmpFile("/spring-cloud-sleuth/pom.xml"));
Model depsPom = this.testPomReader.readPom(
tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-dependencies/pom.xml"));
Model corePom = this.testPomReader.readPom(
tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-core/pom.xml"));
Model zipkinStreamPom = this.testPomReader.readPom(tmpFile(
"/spring-cloud-sleuth/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-zipkin-stream/pom.xml"));
then(rootPom.getVersion()).isEqualTo("1.2.0.BUILD-SNAPSHOT");
then(rootPom.getProperties())
.containsEntry("spring-cloud-build.version","1.3.1.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-commons.version","1.2.0.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-stream.version","Chelsea.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-netflix.version","1.3.0.BUILD-SNAPSHOT")
.containsEntry("checkstyle.version","100.0.0.RELEASE");
.containsEntry("spring-cloud-build.version", "1.3.1.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-commons.version", "1.2.0.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-stream.version", "Chelsea.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-netflix.version", "1.3.0.BUILD-SNAPSHOT")
.containsEntry("checkstyle.version", "100.0.0.RELEASE");
then(depsPom.getVersion()).isEqualTo("1.2.0.BUILD-SNAPSHOT");
then(depsPom.getParent().getVersion()).isEqualTo("1.3.1.BUILD-SNAPSHOT");
then(corePom.getParent().getVersion()).isEqualTo("1.2.0.BUILD-SNAPSHOT");
@@ -66,50 +90,58 @@ public class PomUpdateAcceptanceTests {
}
@Test
public void should_not_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version() throws Exception {
public void should_not_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version()
throws Exception {
ReleaserProperties releaserProperties = branchReleaserProperties();
ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties);
Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom();
projects.add(new ProjectVersion("spring-cloud-sleuth-samples", "0.0.5.RELEASE"));
File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-unmatched-property/spring-cloud-sleuth-samples");
File project = new File(this.temporaryFolder,
"/spring-cloud-sleuth-with-unmatched-property/spring-cloud-sleuth-samples");
addBuildSnapshotToChildPom(project);
projectPomUpdater
.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true);
projectPomUpdater.updateProjectFromReleaseTrain(project, projects,
projects.forFile(project), true);
}
private void addBuildSnapshotToChildPom(File project) throws IOException {
File childPom = new File(project, "pom.xml");
String text = new String(Files.readAllBytes(childPom.toPath()));
Files.write(childPom.toPath(), text.replaceAll("1.19.2", "1.19.2.BUILD-SNAPSHOT").getBytes());
Files.write(childPom.toPath(),
text.replaceAll("1.19.2", "1.19.2.BUILD-SNAPSHOT").getBytes());
}
@Test
public void should_not_fail_update_when_after_updating_a_release_version_there_still_is_a_snapshot_version_in_a_non_deployable_module() throws Exception {
public void should_not_fail_update_when_after_updating_a_release_version_there_still_is_a_snapshot_version_in_a_non_deployable_module()
throws Exception {
ReleaserProperties releaserProperties = branchReleaserProperties();
ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties);
Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom();
File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-unmatched-property");
File project = new File(this.temporaryFolder,
"/spring-cloud-sleuth-with-unmatched-property");
BDDAssertions.thenThrownBy(() ->
projectPomUpdater
.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true)
).hasMessageContaining("<spring-cloud-unmatched.version>0.6.0.BUILD-SNAPSHOT</spring-cloud-unmatched.version>");
BDDAssertions
.thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(
project, projects, projects.forFile(project), true))
.hasMessageContaining(
"<spring-cloud-unmatched.version>0.6.0.BUILD-SNAPSHOT</spring-cloud-unmatched.version>");
}
@Test
public void should_update_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version_for_boot_snapshot_version() throws Exception {
public void should_update_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version_for_boot_snapshot_version()
throws Exception {
ReleaserProperties releaserProperties = branchReleaserProperties();
ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties);
Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom();
projects.removeIf(projectVersion -> projectVersion.projectName.contains("spring-cloud-build"));
projects.removeIf(projectVersion -> projectVersion.projectName
.contains("spring-cloud-build"));
projects.add(new ProjectVersion("spring-cloud-build", "1.4.2.BUILD-SNAPSHOT"));
File project = new File(this.temporaryFolder, "/spring-cloud-sleuth");
BDDAssertions.thenThrownBy(() ->
projectPomUpdater
.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true)
).hasMessageContaining("<version>1.4.2.BUILD-SNAPSHOT</version>");
BDDAssertions
.thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(
project, projects, projects.forFile(project), true))
.hasMessageContaining("<version>1.4.2.BUILD-SNAPSHOT</version>");
}
@Test
@@ -130,7 +162,8 @@ public class PomUpdateAcceptanceTests {
private ReleaserProperties releaserProperties() throws URISyntaxException {
ReleaserProperties releaserProperties = new ReleaserProperties();
releaserProperties.getGit().setReleaseTrainBomUrl(file("/projects/spring-cloud-release/").toURI().toString());
releaserProperties.getGit().setReleaseTrainBomUrl(
file("/projects/spring-cloud-release/").toURI().toString());
return releaserProperties;
}
@@ -149,10 +182,14 @@ public class PomUpdateAcceptanceTests {
}
private File pom(String relativePath) throws URISyntaxException {
return new File(new File(PomUpdateAcceptanceTests.class.getResource(relativePath).toURI()), "pom.xml");
return new File(
new File(
PomUpdateAcceptanceTests.class.getResource(relativePath).toURI()),
"pom.xml");
}
private String asString(File file) throws IOException {
return new String(Files.readAllBytes(file.toPath()));
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
import java.util.Arrays;
@@ -13,6 +29,7 @@ import static org.assertj.core.api.BDDAssertions.then;
* @author Marcin Grzejszczak
*/
public class ReleaserPropertiesTests {
@Test
public void should_return_provided_working_dir_when_it_was_set() {
String workingDir = "foo";
@@ -52,22 +69,17 @@ public class ReleaserPropertiesTests {
copy.getPom().setIgnoredPomRegex(Arrays.asList("bar8", "bar9"));
copy.getSagan().setBaseUrl("bar10");
BDDAssertions.then(properties.getWorkingDir())
.isEqualTo("foo");
BDDAssertions.then(properties.getFixedVersions())
.isEqualTo(map());
BDDAssertions.then(properties.getMaven().getBuildCommand())
.isEqualTo("foo2");
BDDAssertions.then(properties.getWorkingDir()).isEqualTo("foo");
BDDAssertions.then(properties.getFixedVersions()).isEqualTo(map());
BDDAssertions.then(properties.getMaven().getBuildCommand()).isEqualTo("foo2");
BDDAssertions.then(properties.getGradle().getIgnoredGradleRegex())
.isEqualTo(Arrays.asList("foo3", "foo4"));
BDDAssertions.then(properties.getMetaRelease().getProjectsToSkip())
.isEqualTo(Arrays.asList("foo5", "foo6"));
BDDAssertions.then(properties.getGit().getPassword())
.isEqualTo("foo7");
BDDAssertions.then(properties.getGit().getPassword()).isEqualTo("foo7");
BDDAssertions.then(properties.getPom().getIgnoredPomRegex())
.isEqualTo(Arrays.asList("foo8", "foo9"));
BDDAssertions.then(properties.getSagan().getBaseUrl())
.isEqualTo("foo10");
BDDAssertions.then(properties.getSagan().getBaseUrl()).isEqualTo("foo10");
}
private Map<String, String> map() {
@@ -81,4 +93,5 @@ public class ReleaserPropertiesTests {
map.put("bar", "foo");
return map;
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal;
import java.io.File;
@@ -13,6 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.BDDMockito;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.cloud.release.internal.docs.DocumentationUpdater;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
@@ -25,8 +42,8 @@ import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.sagan.SaganUpdater;
import org.springframework.cloud.release.internal.template.TemplateGenerator;
import static org.mockito.BDDMockito.then;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
/**
@@ -35,15 +52,33 @@ import static org.mockito.Mockito.never;
@RunWith(MockitoJUnitRunner.class)
public class ReleaserTests {
@Mock ProjectPomUpdater projectPomUpdater;
@Mock ProjectBuilder projectBuilder;
@Mock ProjectGitHandler projectGitHandler;
@Mock TemplateGenerator templateGenerator;
@Mock GradleUpdater gradleUpdater;
@Mock SaganUpdater saganUpdater;
@Mock DocumentationUpdater documentationUpdater;
@Mock PostReleaseActions postReleaseActions;
@Rule public OutputCapture outputCapture = new OutputCapture();
@Rule
public OutputCapture outputCapture = new OutputCapture();
@Mock
ProjectPomUpdater projectPomUpdater;
@Mock
ProjectBuilder projectBuilder;
@Mock
ProjectGitHandler projectGitHandler;
@Mock
TemplateGenerator templateGenerator;
@Mock
GradleUpdater gradleUpdater;
@Mock
SaganUpdater saganUpdater;
@Mock
DocumentationUpdater documentationUpdater;
@Mock
PostReleaseActions postReleaseActions;
File pom;
@Before
@@ -56,7 +91,8 @@ public class ReleaserTests {
return new Releaser(this.projectPomUpdater, this.projectBuilder,
this.projectGitHandler, this.templateGenerator, this.gradleUpdater,
this.saganUpdater, this.documentationUpdater, this.postReleaseActions) {
@Override ProjectVersion originalVersion(File project) {
@Override
ProjectVersion originalVersion(File project) {
return originalVersionSupplier.get();
}
};
@@ -72,50 +108,58 @@ public class ReleaserTests {
public void should_not_bump_versions_for_original_release_project() {
releaser(() -> new ProjectVersion("original", "1.0.0.RELEASE"))
.rollbackReleaseVersion(this.pom,
new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")),
new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")),
new ProjectVersion("changed", "1.0.0.RELEASE"));
BDDAssertions.then(this.outputCapture.toString()).contains("Successfully reverted the commit and came back to snapshot versions");
then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class));
BDDAssertions.then(this.outputCapture.toString()).contains(
"Successfully reverted the commit and came back to snapshot versions");
then(this.projectGitHandler).should(never())
.commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class));
}
@Test
public void should_not_bump_versions_for_original_snapshot_project_and_current_snapshot() {
releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"))
.rollbackReleaseVersion(this.pom,
new Projects(new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")),
new Projects(
new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")),
new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT"));
BDDAssertions.then(this.outputCapture.toString()).contains("Won't rollback a snapshot version");
then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class));
BDDAssertions.then(this.outputCapture.toString())
.contains("Won't rollback a snapshot version");
then(this.projectGitHandler).should(never())
.commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class));
}
@Test
public void should_bump_versions_for_original_snapshot_project() {
ProjectVersion scReleaseVersion = new ProjectVersion("changed", "1.0.0.RELEASE");
releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"))
.rollbackReleaseVersion(this.pom,
new Projects(new ProjectVersion("changed", "1.0.0.RELEASE"),
new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE"),
new ProjectVersion("spring-boot-starter", "3.0.0.RELEASE")),
.rollbackReleaseVersion(this.pom, new Projects(
new ProjectVersion("changed", "1.0.0.RELEASE"),
new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE"),
new ProjectVersion("spring-boot-starter", "3.0.0.RELEASE")),
scReleaseVersion);
BDDAssertions.then(this.outputCapture.toString())
.contains("Project was successfully updated")
.contains("Successfully reverted the commit and bumped snapshot versions");
.contains("Project was successfully updated").contains(
"Successfully reverted the commit and bumped snapshot versions");
}
@Test
public void should_not_generate_email_for_snapshot_version() {
releaser().createEmail(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"), projects());
releaser().createEmail(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"),
projects());
then(this.templateGenerator).should(never()).email(any(Projects.class));
}
@Test
public void should_generate_email_for_release_version() {
BDDMockito.given(this.templateGenerator.email(projects())).willReturn(new File("."));
releaser().createEmail(new ProjectVersion("original", "1.0.0.RELEASE"), projects());
BDDMockito.given(this.templateGenerator.email(projects()))
.willReturn(new File("."));
releaser().createEmail(new ProjectVersion("original", "1.0.0.RELEASE"),
projects());
then(this.templateGenerator).should().email(any(Projects.class));
}
@@ -124,21 +168,24 @@ public class ReleaserTests {
public void should_not_close_milestone_for_snapshots() {
releaser().closeMilestone(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"));
then(this.projectGitHandler).should(never()).closeMilestone(any(ProjectVersion.class));
then(this.projectGitHandler).should(never())
.closeMilestone(any(ProjectVersion.class));
}
@Test
public void should_not_rollback_for_snapshots() {
releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"))
.rollbackReleaseVersion(null,
new Projects(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")),
new Projects(
new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")),
new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"));
then(this.projectGitHandler).should(never()).revertChangesIfApplicable(any(File.class), any(ProjectVersion.class));
then(this.projectGitHandler).should(never())
.revertChangesIfApplicable(any(File.class), any(ProjectVersion.class));
}
Projects projects() {
return new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"));
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -11,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.BDDMockito;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
@@ -24,21 +41,28 @@ import static org.assertj.core.api.BDDAssertions.then;
*/
public class ProjectDocumentationUpdaterTests {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
File project;
File tmpFolder;
ProjectGitHandler handler;
File clonedDocProject;
ReleaserProperties properties = new ReleaserProperties();
@Before
public void setup() throws IOException, URISyntaxException {
this.tmpFolder = this.tmp.newFolder();
this.project = new File(
ProjectDocumentationUpdaterTests.class.getResource("/projects/spring-cloud-static").toURI());
this.project = new File(ProjectDocumentationUpdaterTests.class
.getResource("/projects/spring-cloud-static").toURI());
TestUtils.prepareLocalRepo();
FileSystemUtils.copyRecursively(file("/projects"), this.tmpFolder);
this.properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
this.properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
this.handler = new ProjectGitHandler(this.properties);
this.clonedDocProject = this.handler.cloneDocumentationProject();
}
@@ -46,42 +70,50 @@ public class ProjectDocumentationUpdaterTests {
@Test
public void should_throw_exception_if_index_html_not_found()
throws URISyntaxException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"1.3.4.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationBranch("master");
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-release/").toURI().toString());
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-release/").toURI().toString());
BDDAssertions.thenThrownBy(() ->
new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.SR33"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("index.html is not present");
BDDAssertions
.thenThrownBy(() -> new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.SR33"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("index.html is not present");
}
@Test
public void should_throw_exception_if_index_found_but_doc_repo_url_missing()
throws URISyntaxException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"1.3.4.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
BDDAssertions.thenThrownBy(() ->
new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties)) {
@Override String readIndexHtmlContents(File indexHtml) {
return "";
}
}.updateDocsRepo(releaseTrainVersion, "vAngel.SR33"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("The URL to the documentation repo not found");
BDDAssertions.thenThrownBy(() -> new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)) {
@Override
String readIndexHtmlContents(File indexHtml) {
return "";
}
}.updateDocsRepo(releaseTrainVersion, "vAngel.SR33"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("The URL to the documentation repo not found");
}
@Test
public void should_not_update_current_version_in_the_docs_if_current_release_is_not_ga_or_sr() {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.BUILD-SNAPSHOT");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"2.0.0.BUILD-SNAPSHOT");
ReleaserProperties properties = new ReleaserProperties();
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.M7");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"vAngel.M7");
then(updatedDocs).isNull();
}
@@ -89,22 +121,26 @@ public class ProjectDocumentationUpdaterTests {
@Test
public void should_not_update_current_version_in_the_docs_if_current_release_starts_with_v_and_then_lower_letter_than_the_stored_release()
throws URISyntaxException, IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"1.3.4.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(file("/projects/spring-cloud-static/").toURI().toString());
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vAngel.SR33");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"vAngel.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
new File(updatedDocs, "current/index.html").toPath()));
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.doesNotContain("http://cloud.spring.io/spring-cloud-static/Angel.SR33/");
}
@Test
public void should_not_commit_if_the_same_version_is_already_there() {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"1.3.4.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
ProjectGitHandler handler = BDDMockito.spy(new ProjectGitHandler(properties));
@@ -119,15 +155,17 @@ public class ProjectDocumentationUpdaterTests {
@Test
public void should_not_update_current_version_in_the_docs_if_current_release_starts_with_lower_letter_than_the_stored_release()
throws IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"1.3.4.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Angel.SR33");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"Angel.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
new File(updatedDocs, "current/index.html").toPath()));
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.doesNotContain("http://cloud.spring.io/spring-cloud-static/Angel.SR33/");
}
@@ -135,15 +173,17 @@ public class ProjectDocumentationUpdaterTests {
@Test
public void should_update_current_version_in_the_docs_if_current_release_starts_with_v_and_then_higher_letter_than_the_stored_release()
throws IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"2.0.0.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "vFinchley.SR33");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"vFinchley.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
new File(updatedDocs, "current/index.html").toPath()));
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.contains("http://cloud.spring.io/spring-cloud-static/Finchley.SR33/");
}
@@ -151,33 +191,39 @@ public class ProjectDocumentationUpdaterTests {
@Test
public void should_update_current_version_in_the_docs_if_current_release_starts_with_higher_letter_than_the_stored_release()
throws IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"2.0.0.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Finchley.SR33");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"Finchley.SR33");
String indexHtmlContent = new String(Files.readAllBytes(
new File(updatedDocs, "current/index.html").toPath()));
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.contains("http://cloud.spring.io/spring-cloud-static/Finchley.SR33/");
}
@Test
public void should_not_update_current_version_in_the_docs_if_switch_is_off() {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33");
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth",
"2.0.0.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
properties.getGit().setUpdateDocumentationRepo(false);
File updatedDocs = new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties))
.updateDocsRepo(releaseTrainVersion, "Finchley.SR33");
File updatedDocs = new ProjectDocumentationUpdater(properties,
new ProjectGitHandler(properties)).updateDocsRepo(releaseTrainVersion,
"Finchley.SR33");
then(updatedDocs).isNull();
}
private File file(String relativePath) throws URISyntaxException {
return new File(ProjectDocumentationUpdaterTests.class.getResource(relativePath).toURI());
return new File(
ProjectDocumentationUpdaterTests.class.getResource(relativePath).toURI());
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.util.Arrays;
@@ -17,85 +33,113 @@ public class ReleaseTrainContentsGeneratorTests {
@Test
public void should_return_empty_contents_if_there_versions_are_lower_than_current_ones() {
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(new ReleaserProperties());
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(
new ReleaserProperties());
String contents = generator
.releaseTrainContents(contents(), olderReleaseTrain());
String contents = generator.releaseTrainContents(contents(), olderReleaseTrain());
BDDAssertions.then(contents).isEmpty();
}
@Test
public void should_return_empty_contents_if_there_are_no_changes_in_the_versions() {
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(new ReleaserProperties());
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(
new ReleaserProperties());
String contents = generator
.releaseTrainContents(contents(), sameProjectsForCurrentGa());
String contents = generator.releaseTrainContents(contents(),
sameProjectsForCurrentGa());
BDDAssertions.then(contents).isEmpty();
}
@Test
public void should_return_contents_with_updated_current_release_train() {
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(new ReleaserProperties());
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(
new ReleaserProperties());
String contents = generator
.releaseTrainContents(contents(), newerProjectsForNewGa());
String contents = generator.releaseTrainContents(contents(),
newerProjectsForNewGa());
BDDAssertions.then(contents).contains("|Edgware.SR5|Finchley.SR2|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(" |spring-cloud-cli|1.4.1.RELEASE|3.0.0.RELEASE|2.0.1.BUILD-SNAPSHOT|");
BDDAssertions.then(contents)
.contains("|Edgware.SR5|Finchley.SR2|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(
" |spring-cloud-cli|1.4.1.RELEASE|3.0.0.RELEASE|2.0.1.BUILD-SNAPSHOT|");
}
@Test
public void should_return_contents_with_updated_previous_release_train() {
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(new ReleaserProperties());
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(
new ReleaserProperties());
String contents = generator
.releaseTrainContents(contents(), newerProjectsForOldGa());
String contents = generator.releaseTrainContents(contents(),
newerProjectsForOldGa());
BDDAssertions.then(contents).contains("|Edgware.SR6|Finchley.SR1|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(" |spring-cloud-cli|3.0.0.RELEASE|2.0.0.RELEASE|2.0.1.BUILD-SNAPSHOT|");
BDDAssertions.then(contents)
.contains("|Edgware.SR6|Finchley.SR1|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(
" |spring-cloud-cli|3.0.0.RELEASE|2.0.0.RELEASE|2.0.1.BUILD-SNAPSHOT|");
}
@Test
public void should_return_contents_with_updated_current_snapshot_train() {
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(new ReleaserProperties());
ReleaseTrainContentsGenerator generator = new ReleaseTrainContentsGenerator(
new ReleaserProperties());
String contents = generator
.releaseTrainContents(contents(), newerProjectsForCurrentSnapshot());
String contents = generator.releaseTrainContents(contents(),
newerProjectsForCurrentSnapshot());
BDDAssertions.then(contents).contains("|Edgware.SR5|Finchley.SR1|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(" |spring-cloud-cli|1.4.1.RELEASE|2.0.0.RELEASE|3.0.0.BUILD-SNAPSHOT|");
BDDAssertions.then(contents)
.contains("|Edgware.SR5|Finchley.SR1|Finchley.BUILD-SNAPSHOT|");
BDDAssertions.then(contents).contains(
" |spring-cloud-cli|1.4.1.RELEASE|2.0.0.RELEASE|3.0.0.BUILD-SNAPSHOT|");
}
ReleaseTrainContents contents() {
Title title = new Title("Edgware.SR5", "Finchley.SR1", "Finchley.BUILD-SNAPSHOT");
List<Row> rows = Arrays.asList(
new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1", "Elmhurst.BUILD-SNAPSHOT"),
new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE", "2.0.4.BUILD-SNAPSHOT"),
new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE", "1.0.1.BUILD-SNAPSHOT"));
new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1",
"Elmhurst.BUILD-SNAPSHOT"),
new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE",
"2.0.4.BUILD-SNAPSHOT"),
new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE",
"1.0.1.BUILD-SNAPSHOT"));
return new ReleaseTrainContents(title, rows);
}
Projects olderReleaseTrain() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -118,8 +162,7 @@ public class ReleaseTrainContentsGeneratorTests {
}
Projects sameProjectsForCurrentGa() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -142,8 +185,7 @@ public class ReleaseTrainContentsGeneratorTests {
}
Projects newerProjectsForNewGa() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "3.0.1.RELEASE"),
@@ -166,8 +208,7 @@ public class ReleaseTrainContentsGeneratorTests {
}
Projects newerProjectsForOldGa() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "3.0.1.RELEASE"),
@@ -212,4 +253,5 @@ public class ReleaseTrainContentsGeneratorTests {
new ProjectVersion("spring-cloud-openfeign", "3.0.1.BUILD-SNAPSHOT"),
new ProjectVersion("spring-cloud-function", "1.0.0.BUILD-SNAPSHOT"));
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -11,10 +27,10 @@ import org.junit.Test;
*/
public class ReleaseTrainContentsParserTests {
File finchley = new File(
ReleaseTrainContentsParserTests.class
.getResource("/projects/spring-cloud-wiki/Spring-Cloud-Finchley-Release-Notes.md")
.toURI());
File finchley = new File(ReleaseTrainContentsParserTests.class
.getResource(
"/projects/spring-cloud-wiki/Spring-Cloud-Finchley-Release-Notes.md")
.toURI());
public ReleaseTrainContentsParserTests() throws URISyntaxException {
}
@@ -26,4 +42,5 @@ public class ReleaseTrainContentsParserTests {
BDDAssertions.then(releaseTrain).isEqualTo("Finchley.SR2");
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -26,19 +42,28 @@ import org.springframework.util.FileSystemUtils;
*/
public class ReleaseTrainContentsUpdaterTests {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
ReleaserProperties properties = new ReleaserProperties();
ProjectGitHandler projectGitHandler = new ProjectGitHandler(this.properties) {
@Override
public String milestoneUrl(ProjectVersion releaseVersion) {
return "http://foo.com";
}
};
TemplateGenerator templateGenerator = new TemplateGenerator(this.properties, this.projectGitHandler);
TemplateGenerator templateGenerator = new TemplateGenerator(this.properties,
this.projectGitHandler);
ReleaseTrainContentsUpdater updater = new ReleaseTrainContentsUpdater(this.properties,
this.projectGitHandler, this.templateGenerator);
File springCloudRepo;
File wikiRepo;
@Rule public TemporaryFolder tmp = new TemporaryFolder();
File temporaryFolder;
@Before
@@ -51,7 +76,8 @@ public class ReleaseTrainContentsUpdaterTests {
}
private File file(String relativePath) throws URISyntaxException {
return new File(ReleaseTrainContentsUpdaterTests.class.getResource(relativePath).toURI());
return new File(
ReleaseTrainContentsUpdaterTests.class.getResource(relativePath).toURI());
}
@Test
@@ -64,24 +90,32 @@ public class ReleaseTrainContentsUpdaterTests {
}
@Test
public void should_not_update_the_contents_of_spring_project_repo_when_release_train_smaller() throws GitAPIException {
this.properties.getGit().setSpringProjectUrl(this.springCloudRepo.getAbsolutePath() + "/");
public void should_not_update_the_contents_of_spring_project_repo_when_release_train_smaller()
throws GitAPIException {
this.properties.getGit()
.setSpringProjectUrl(this.springCloudRepo.getAbsolutePath() + "/");
File file = this.updater.updateProjectRepo(oldReleaseTrain());
BDDAssertions.then(file).isNotNull();
BDDAssertions.then(GitTestUtils.openGitProject(file).log().call().iterator().next().getShortMessage())
BDDAssertions
.then(GitTestUtils.openGitProject(file).log().call().iterator().next()
.getShortMessage())
.doesNotContain("Updating project page to release train");
}
@Test
public void should_update_the_contents_of_spring_project_repo_when_release_train_greater() throws GitAPIException {
this.properties.getGit().setSpringProjectUrl(this.springCloudRepo.getAbsolutePath() + "/");
public void should_update_the_contents_of_spring_project_repo_when_release_train_greater()
throws GitAPIException {
this.properties.getGit()
.setSpringProjectUrl(this.springCloudRepo.getAbsolutePath() + "/");
File file = this.updater.updateProjectRepo(newReleaseTrain());
BDDAssertions.then(file).isNotNull();
BDDAssertions.then(GitTestUtils.openGitProject(file).log().call().iterator().next().getShortMessage())
BDDAssertions
.then(GitTestUtils.openGitProject(file).log().call().iterator().next()
.getShortMessage())
.contains("Updating project page to release train [Edgware.SR7]");
}
@@ -105,47 +139,59 @@ public class ReleaseTrainContentsUpdaterTests {
}
@Test
public void should_not_update_the_contents_of_wiki_repo_when_release_train_smaller() throws GitAPIException, IOException {
public void should_not_update_the_contents_of_wiki_repo_when_release_train_smaller()
throws GitAPIException, IOException {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
this.properties.getGit()
.setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
File file = this.updater.updateReleaseTrainWiki(oldReleaseTrain());
BDDAssertions.then(file).isNotNull();
BDDAssertions.then(edgwareWikiEntryContent(file))
.doesNotContain("# Edgware.SR7")
.doesNotContain("Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions.then(GitTestUtils.openGitProject(file).log().call().iterator().next().getShortMessage())
BDDAssertions.then(edgwareWikiEntryContent(file)).doesNotContain("# Edgware.SR7")
.doesNotContain(
"Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions
.then(GitTestUtils.openGitProject(file).log().call().iterator().next()
.getShortMessage())
.doesNotContain("Updating project page to release train");
}
@Test
public void should_update_the_contents_of_wiki_when_release_train_greater() throws GitAPIException, IOException {
public void should_update_the_contents_of_wiki_when_release_train_greater()
throws GitAPIException, IOException {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
this.properties.getGit()
.setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
File file = this.updater.updateReleaseTrainWiki(newReleaseTrain());
BDDAssertions.then(file).isNotNull();
BDDAssertions.then(edgwareWikiEntryContent(file))
.contains("# Edgware.SR7")
.contains("Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions.then(GitTestUtils.openGitProject(file).log().call().iterator().next().getShortMessage())
BDDAssertions.then(edgwareWikiEntryContent(file)).contains("# Edgware.SR7")
.contains(
"Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions
.then(GitTestUtils.openGitProject(file).log().call().iterator().next()
.getShortMessage())
.contains("Updating project page to release train [Edgware.SR7]");
}
@Test
public void should_generate_the_contents_of_wiki_when_release_train_missing() throws GitAPIException, IOException {
public void should_generate_the_contents_of_wiki_when_release_train_missing()
throws GitAPIException, IOException {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
this.properties.getGit()
.setReleaseTrainWikiUrl(this.wikiRepo.getAbsolutePath() + "/");
File file = this.updater.updateReleaseTrainWiki(freshNewReleaseTrain());
BDDAssertions.then(file).isNotNull();
BDDAssertions.then(greenwichWikiEntryContent(file))
.contains("# Greenwich.RELEASE")
.contains("Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions.then(GitTestUtils.openGitProject(file).log().call().iterator().next().getShortMessage())
.contains("# Greenwich.RELEASE").contains(
"Spring Cloud Consul `2.0.1.RELEASE` ([issues](http://foo.com))");
BDDAssertions
.then(GitTestUtils.openGitProject(file).log().call().iterator().next()
.getShortMessage())
.contains("Updating project page to release train [Greenwich.RELEASE]");
}
@@ -162,8 +208,7 @@ public class ReleaseTrainContentsUpdaterTests {
}
Projects oldReleaseTrain() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -187,8 +232,7 @@ public class ReleaseTrainContentsUpdaterTests {
}
Projects newReleaseTrain() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -212,8 +256,7 @@ public class ReleaseTrainContentsUpdaterTests {
}
Projects freshNewReleaseTrain() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "3.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -235,4 +278,5 @@ public class ReleaseTrainContentsUpdaterTests {
new ProjectVersion("spring-cloud-openfeign", "2.0.1.RELEASE"),
new ProjectVersion("spring-cloud-function", "1.0.0.RELEASE"));
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.util.List;
@@ -17,8 +33,7 @@ public class RowTests {
public void should_convert_projects_to_rows_for_last_ga() {
Projects projects = new Projects(
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
new ProjectVersion("sc-release", "2.0.1.RELEASE")
);
new ProjectVersion("sc-release", "2.0.1.RELEASE"));
List<Row> rows = Row.fromProjects(projects, true);
@@ -38,8 +53,7 @@ public class RowTests {
public void should_convert_projects_to_rows_for_current_ga() {
Projects projects = new Projects(
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
new ProjectVersion("sc-release", "2.0.1.RELEASE")
);
new ProjectVersion("sc-release", "2.0.1.RELEASE"));
List<Row> rows = Row.fromProjects(projects, false);
@@ -54,4 +68,5 @@ public class RowTests {
BDDAssertions.then(foo.currentGaVersion).isEmpty();
BDDAssertions.then(foo.currentSnapshotVersion).isEqualTo("1.0.0.BUILD-SNAPSHOT");
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.docs;
import java.io.File;
@@ -16,12 +32,12 @@ public class SpringCloudGhPagesParserTests {
@Rule
public OutputCapture capture = new OutputCapture();
File rawHtml = new File(SpringCloudGhPagesParserTests.class.getResource(
"/raw/spring-cloud-gh-pages-index.html"
).toURI());
File wrongHtml = new File(SpringCloudGhPagesParserTests.class.getResource(
"/raw/some-file.html"
).toURI());
File rawHtml = new File(SpringCloudGhPagesParserTests.class
.getResource("/raw/spring-cloud-gh-pages-index.html").toURI());
File wrongHtml = new File(SpringCloudGhPagesParserTests.class
.getResource("/raw/some-file.html").toURI());
public SpringCloudGhPagesParserTests() throws URISyntaxException {
}
@@ -33,28 +49,46 @@ public class SpringCloudGhPagesParserTests {
BDDAssertions.then(contents).isNotNull();
BDDAssertions.then(contents.title).isEqualTo(
new Title("Edgware.SR5", "Finchley.SR1", "Finchley.BUILD-SNAPSHOT")
);
new Title("Edgware.SR5", "Finchley.SR1", "Finchley.BUILD-SNAPSHOT"));
BDDAssertions.then(contents.rows).contains(
new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1", "Elmhurst.BUILD-SNAPSHOT"),
new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE", "2.0.4.BUILD-SNAPSHOT"),
new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE", "1.0.1.BUILD-SNAPSHOT"));
new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1",
"Elmhurst.BUILD-SNAPSHOT"),
new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE",
"2.0.4.BUILD-SNAPSHOT"),
new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE",
"2.0.1.BUILD-SNAPSHOT"),
new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE",
"2.0.2.BUILD-SNAPSHOT"),
new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE",
"1.0.1.BUILD-SNAPSHOT"));
}
@Test
@@ -66,4 +100,5 @@ public class SpringCloudGhPagesParserTests {
BDDAssertions.then(this.capture.toString())
.contains("The page is missing the components table markers");
}
}
}

View File

@@ -1,10 +1,20 @@
package org.springframework.cloud.release.internal.git;
/*
* Copyright 2013-2019 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.
*/
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
import static org.springframework.cloud.release.internal.git.GitTestUtils.clonedProject;
import static org.springframework.cloud.release.internal.git.GitTestUtils.setOriginOnProjectToTmp;
package org.springframework.cloud.release.internal.git;
import java.io.File;
import java.io.FileOutputStream;
@@ -25,22 +35,34 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.cloud.release.internal.pom.TestUtils;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
import static org.springframework.cloud.release.internal.git.GitTestUtils.clonedProject;
import static org.springframework.cloud.release.internal.git.GitTestUtils.setOriginOnProjectToTmp;
/**
* @author Marcin Grzejszczak
*/
public class GitRepoTests {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
File springCloudReleaseProject;
File tmpFolder;
GitRepo gitRepo;
@Before
public void setup() throws IOException, URISyntaxException {
this.tmpFolder = this.tmp.newFolder();
this.springCloudReleaseProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
this.springCloudReleaseProject = new File(
GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
TestUtils.prepareLocalRepo();
this.gitRepo = new GitRepo(this.tmpFolder);
}
@@ -55,43 +77,44 @@ public class GitRepoTests {
@Test
public void should_throw_exception_when_there_is_no_repo() {
thenThrownBy(() -> this.gitRepo
.cloneProject(new URIish(GitRepoTests.class.getResource("/projects/").toURI().toURL())))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Exception occurred while cloning repo");
thenThrownBy(() -> this.gitRepo.cloneProject(
new URIish(GitRepoTests.class.getResource("/projects/").toURI().toURL())))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Exception occurred while cloning repo");
}
@Test
public void should_throw_an_exception_when_failed_to_initialize_the_repo() {
thenThrownBy(() -> new GitRepo(this.tmpFolder,
new ExceptionThrowingJGitFactory()).cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Exception occurred while cloning repo")
.hasCauseInstanceOf(CustomException.class);
thenThrownBy(() -> new GitRepo(this.tmpFolder, new ExceptionThrowingJGitFactory())
.cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Exception occurred while cloning repo")
.hasCauseInstanceOf(CustomException.class);
}
@Test
public void should_check_out_a_branch_on_cloned_repo() throws IOException {
URIish uri = new URIish(this.springCloudReleaseProject.toURI().toURL());
File project = this.gitRepo
.cloneProject(uri);
File project = this.gitRepo.cloneProject(uri);
new GitRepo(project).checkout("vCamden.SR3");
File pom = new File(new File(this.tmpFolder, uri.getHumanishName()), "pom.xml");
then(pom).exists();
then(Files.lines(pom.toPath()).anyMatch(s -> s.contains("<version>Camden.SR3</version>"))).isTrue();
then(Files.lines(pom.toPath())
.anyMatch(s -> s.contains("<version>Camden.SR3</version>"))).isTrue();
}
@Test
public void should_check_out_a_branch_on_cloned_repo2() throws IOException {
URIish uri = new URIish(this.springCloudReleaseProject.toURI().toURL());
File project = this.gitRepo
.cloneProject(uri);
File project = this.gitRepo.cloneProject(uri);
new GitRepo(project).checkout("Camden.x");
File pom = new File(new File(this.tmpFolder, uri.getHumanishName()), "pom.xml");
then(pom).exists();
then(Files.lines(pom.toPath()).anyMatch(s -> s.contains("<version>Camden.BUILD-SNAPSHOT</version>"))).isTrue();
then(Files.lines(pom.toPath())
.anyMatch(s -> s.contains("<version>Camden.BUILD-SNAPSHOT</version>")))
.isTrue();
}
@Test
@@ -111,13 +134,15 @@ public class GitRepoTests {
}
@Test
public void should_throw_an_exception_when_checking_out_nonexisting_branch() throws IOException {
public void should_throw_an_exception_when_checking_out_nonexisting_branch()
throws IOException {
File project = new GitRepo(this.tmpFolder)
.cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL()));
try {
new GitRepo(project).checkout("nonExistingBranch");
fail("should throw an exception");
} catch (IllegalStateException e) {
}
catch (IllegalStateException e) {
then(e).hasMessageContaining("Ref nonExistingBranch can not be resolved");
}
}
@@ -130,7 +155,7 @@ public class GitRepoTests {
new GitRepo(project).commit("some message");
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
RevCommit revCommit = git.log().call().iterator().next();
then(revCommit.getShortMessage()).isEqualTo("some message");
}
@@ -145,7 +170,7 @@ public class GitRepoTests {
new GitRepo(project).commit("empty commit");
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
RevCommit revCommit = git.log().call().iterator().next();
then(revCommit.getShortMessage()).isNotEqualTo("empty commit");
}
@@ -160,7 +185,7 @@ public class GitRepoTests {
new GitRepo(project).tag("v1.0.0");
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
tagIsPresent(git, "v1.0.0");
}
}
@@ -168,7 +193,8 @@ public class GitRepoTests {
private void tagIsPresent(Git git, String tag) throws GitAPIException {
List<Ref> refs = git.tagList().call();
System.out.println("All tags" + refs);
then(refs.stream().anyMatch(ref -> ref.getName().startsWith("refs/tags/" + tag))).isTrue();
then(refs.stream().anyMatch(ref -> ref.getName().startsWith("refs/tags/" + tag)))
.isTrue();
}
@Test
@@ -182,7 +208,7 @@ public class GitRepoTests {
new GitRepo(project).pushBranch("master");
try(Git git = openGitProject(origin)) {
try (Git git = openGitProject(origin)) {
RevCommit revCommit = git.log().call().iterator().next();
then(revCommit.getShortMessage()).isEqualTo("some message");
}
@@ -199,7 +225,7 @@ public class GitRepoTests {
new GitRepo(project).pushCurrentBranch();
try(Git git = openGitProject(origin)) {
try (Git git = openGitProject(origin)) {
RevCommit revCommit = git.log().call().iterator().next();
then(revCommit.getShortMessage()).isEqualTo("some message");
}
@@ -230,7 +256,7 @@ public class GitRepoTests {
new GitRepo(project).pushTag("v5.6.7.RELEASE");
try(Git git = openGitProject(origin)) {
try (Git git = openGitProject(origin)) {
tagIsPresent(git, "v5.6.7");
git.checkout().setName("v5.6.7.RELEASE").call();
RevCommit revCommit = git.log().call().iterator().next();
@@ -238,7 +264,6 @@ public class GitRepoTests {
}
}
private Git openGitProject(File project) {
return new GitRepo.JGitFactory().open(project);
}
@@ -249,7 +274,7 @@ public class GitRepoTests {
try (PrintStream out = new PrintStream(new FileOutputStream(newFile))) {
out.print("foo");
}
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
git.add().addFilepattern("newFile").call();
}
}
@@ -264,32 +289,37 @@ public class GitRepoTests {
new GitRepo(project).revert("Reverting the commit");
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
RevCommit revCommit = git.log().call().iterator().next();
then(revCommit.getShortMessage()).isEqualTo("Reverting the commit");
}
}
@Test
public void should_not_revert_changes_when_commit_message_is_not_related_to_updating_snapshots() throws Exception {
public void should_not_revert_changes_when_commit_message_is_not_related_to_updating_snapshots()
throws Exception {
File project = new GitRepo(this.tmpFolder)
.cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL()));
BDDAssertions.thenThrownBy(
() -> new GitRepo(project).revert("some message"))
.hasMessageContaining("Won't revert the commit with id");
BDDAssertions.thenThrownBy(() -> new GitRepo(project).revert("some message"))
.hasMessageContaining("Won't revert the commit with id");
}
}
class ExceptionThrowingJGitFactory extends GitRepo.JGitFactory {
@Override CloneCommand getCloneCommandByCloneRepository() {
@Override
CloneCommand getCloneCommandByCloneRepository() {
throw new CustomException("foo");
}
}
class CustomException extends RuntimeException {
public CustomException(String message) {
CustomException(String message) {
super(message);
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.File;
@@ -17,7 +33,7 @@ public class GitTestUtils {
public static void setOriginOnProjectToTmp(File origin, File project)
throws GitAPIException, MalformedURLException {
try(Git git = openGitProject(project)) {
try (Git git = openGitProject(project)) {
RemoteRemoveCommand remove = git.remoteRemove();
remove.setName("origin");
remove.call();
@@ -33,8 +49,10 @@ public class GitTestUtils {
return new GitRepo.JGitFactory().open(project);
}
public static File clonedProject(File baseDir, File projectToClone) throws IOException {
public static File clonedProject(File baseDir, File projectToClone)
throws IOException {
GitRepo projectRepo = new GitRepo(baseDir);
return projectRepo.cloneProject(new URIish(projectToClone.toURI().toURL()));
}
}

View File

@@ -1,8 +1,24 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import javax.json.Json;
import com.jcabi.github.Coordinates;
@@ -29,13 +45,18 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
*/
public class GithubIssuesTests {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Rule
public OutputCapture capture = new OutputCapture();
MkGithub github;
Repo repo;
@Rule public TemporaryFolder folder = new TemporaryFolder();
@Rule public OutputCapture capture = new OutputCapture();
@Before
public void setup() throws IOException {
public void setup() throws IOException {
this.github = new MkGithub("spring-guides");
this.repo = createGettingStartedGuides(this.github);
}
@@ -45,9 +66,8 @@ public class GithubIssuesTests {
Github github = BDDMockito.mock(Github.class);
GithubIssues issues = new GithubIssues(github, withToken());
issues.fileIssue(new Projects(
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")
), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT"));
issues.fileIssue(new Projects(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")),
new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT"));
BDDMockito.then(github).shouldHaveZeroInteractions();
}
@@ -59,11 +79,11 @@ public class GithubIssuesTests {
properties.getGit().setUpdateSpringGuides(false);
GithubIssues issues = new GithubIssues(github, properties);
issues.fileIssue(new Projects(
new ProjectVersion("foo", "1.0.0.RELEASE"),
new ProjectVersion("bar", "2.0.0.RELEASE"),
new ProjectVersion("baz", "3.0.0.RELEASE")
), new ProjectVersion("sc-release", "Edgware.RELEASE"));
issues.fileIssue(
new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"),
new ProjectVersion("bar", "2.0.0.RELEASE"),
new ProjectVersion("baz", "3.0.0.RELEASE")),
new ProjectVersion("sc-release", "Edgware.RELEASE"));
BDDMockito.then(github).shouldHaveZeroInteractions();
}
@@ -72,23 +92,23 @@ public class GithubIssuesTests {
public void should_file_an_issue_for_release_version() throws IOException {
GithubIssues issues = new GithubIssues(this.github, withToken());
issues.fileIssue(new Projects(
new ProjectVersion("foo", "1.0.0.RELEASE"),
new ProjectVersion("bar", "2.0.0.RELEASE"),
new ProjectVersion("baz", "3.0.0.RELEASE")
), new ProjectVersion("sc-release", "Edgware.RELEASE"));
issues.fileIssue(
new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"),
new ProjectVersion("bar", "2.0.0.RELEASE"),
new ProjectVersion("baz", "3.0.0.RELEASE")),
new ProjectVersion("sc-release", "Edgware.RELEASE"));
then(this.capture.toString()).doesNotContain("Guide issue creation will occur only");
then(this.capture.toString())
.doesNotContain("Guide issue creation will occur only");
Issue issue = this.github.repos()
.get(new Coordinates.Simple("spring-guides", "getting-started-guides"))
.issues().get(1);
then(issue.exists()).isTrue();
Issue.Smart smartIssue = new Issue.Smart(issue);
then(smartIssue.title()).isEqualTo("Edgware.RELEASE Spring Cloud Release took place");
then(smartIssue.body())
.contains("Spring Cloud [Edgware.RELEASE]")
.contains("foo : `1.0.0.RELEASE`")
.contains("bar : `2.0.0.RELEASE`")
then(smartIssue.title())
.isEqualTo("Edgware.RELEASE Spring Cloud Release took place");
then(smartIssue.body()).contains("Spring Cloud [Edgware.RELEASE]")
.contains("foo : `1.0.0.RELEASE`").contains("bar : `2.0.0.RELEASE`")
.contains("baz : `3.0.0.RELEASE`");
}
@@ -97,18 +117,14 @@ public class GithubIssuesTests {
GithubIssues issues = new GithubIssues(new ReleaserProperties());
thenThrownBy(() -> issues.fileIssue(new Projects(Collections.emptySet()),
nonGaSleuthProject()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("You have to pass Github OAuth token for milestone closing to be operational");
nonGaSleuthProject())).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"You have to pass Github OAuth token for milestone closing to be operational");
}
private Repo createGettingStartedGuides(MkGithub github) throws IOException {
return github.repos().create(
Json.createObjectBuilder().add(
"name",
"getting-started-guides"
).build()
);
Json.createObjectBuilder().add("name", "getting-started-guides").build());
}
private ProjectVersion nonGaSleuthProject() {
@@ -121,4 +137,5 @@ public class GithubIssuesTests {
properties.getPom().setBranch("vEdgware.RELEASE");
return properties;
}
}
}

View File

@@ -1,7 +1,22 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import javax.json.Json;
@@ -26,13 +41,18 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
*/
public class GithubMilestonesTests {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Rule
public OutputCapture capture = new OutputCapture();
MkGithub github;
Repo repo;
@Rule public TemporaryFolder folder = new TemporaryFolder();
@Rule public OutputCapture capture = new OutputCapture();
@Before
public void setup() throws IOException {
public void setup() throws IOException {
this.github = new MkGithub();
this.repo = createSleuthRepo(this.github);
}
@@ -40,11 +60,13 @@ public class GithubMilestonesTests {
@Test
public void should_close_milestone_if_there_is_one() throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.2.0.BUILD-SNAPSHOT";
}
};
@@ -56,13 +78,16 @@ public class GithubMilestonesTests {
}
@Test
public void should_close_milestone_when_the_milestone_contains_numeric_version_only_and_version_is_ga() throws IOException {
public void should_close_milestone_when_the_milestone_contains_numeric_version_only_and_version_is_ga()
throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.2.0";
}
};
@@ -78,13 +103,16 @@ public class GithubMilestonesTests {
}
@Test
public void should_not_close_milestone_when_the_milestone_contains_numeric_version_only() throws IOException {
public void should_not_close_milestone_when_the_milestone_contains_numeric_version_only()
throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.2.0";
}
};
@@ -98,49 +126,57 @@ public class GithubMilestonesTests {
@Test
public void should_fetch_url_of_a_closed_matching_milestone() throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.2.0.RELEASE";
}
@Override URL foundMilestoneUrl(Milestone.Smart milestone)
throws IOException {
return new URL("https://api.github.com/repos/spring-cloud/spring-cloud-sleuth/milestones/33");
@Override
URL foundMilestoneUrl(Milestone.Smart milestone) throws IOException {
return new URL(
"https://api.github.com/repos/spring-cloud/spring-cloud-sleuth/milestones/33");
}
};
this.repo.milestones().create("0.2.0.RELEASE");
String url = milestones.milestoneUrl(gaSleuthProject());
then(url).isEqualTo("https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
then(url).isEqualTo(
"https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
}
@Test
public void should_fetch_url_of_a_closed_matching_milestone_from_cache() {
GithubMilestones milestones = new GithubMilestones(this.github, withToken());
GithubMilestones.MILESTONE_URL_CACHE.put(gaSleuthProject(), "https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
GithubMilestones.MILESTONE_URL_CACHE.put(gaSleuthProject(),
"https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
String url = milestones.milestoneUrl(gaSleuthProject());
then(url).isEqualTo("https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
then(url).isEqualTo(
"https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1");
}
@Test
public void should_return_null_if_no_matching_milestone_was_found() {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.9.0.RELEASE";
}
@Override URL foundMilestoneUrl(Milestone.Smart milestone)
throws IOException {
@Override
URL foundMilestoneUrl(Milestone.Smart milestone) throws IOException {
return new URL("http://foo.com/bar");
}
};
@@ -151,13 +187,16 @@ public class GithubMilestonesTests {
}
@Test
public void should_return_null_if_no_matching_milestone_was_found_within_threshold() throws IOException {
public void should_return_null_if_no_matching_milestone_was_found_within_threshold()
throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withThreshold()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.2.0";
}
};
@@ -165,7 +204,8 @@ public class GithubMilestonesTests {
milestones.closeMilestone(gaSleuthProject());
then(this.capture.toString()).contains("No matching milestones were found within the provided threshold [0]");
then(this.capture.toString()).contains(
"No matching milestones were found within the provided threshold [0]");
}
private ProjectVersion nonGaSleuthProject() {
@@ -173,13 +213,16 @@ public class GithubMilestonesTests {
}
@Test
public void should_throw_exception_when_there_is_no_matching_milestone() throws IOException {
public void should_throw_exception_when_there_is_no_matching_milestone()
throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone) {
@Override
String milestoneTitle(Milestone.Smart milestone) {
return "0.1.0.BUILD-SNAPSHOT";
}
};
@@ -190,14 +233,16 @@ public class GithubMilestonesTests {
}
@Test
public void should_print_that_no_milestones_were_found_when_io_problems_occurred() throws IOException {
public void should_print_that_no_milestones_were_found_when_io_problems_occurred()
throws IOException {
GithubMilestones milestones = new GithubMilestones(this.github, withToken()) {
@Override String org() {
@Override
String org() {
return GithubMilestonesTests.this.repo.coordinates().user();
}
@Override String milestoneTitle(Milestone.Smart milestone)
throws IOException {
@Override
String milestoneTitle(Milestone.Smart milestone) throws IOException {
throw new IOException("foo");
}
};
@@ -210,11 +255,7 @@ public class GithubMilestonesTests {
private Repo createSleuthRepo(MkGithub github) throws IOException {
return github.repos().create(
Json.createObjectBuilder().add(
"name",
"spring-cloud-sleuth"
).build()
);
Json.createObjectBuilder().add("name", "spring-cloud-sleuth").build());
}
@Test
@@ -237,4 +278,5 @@ public class GithubMilestonesTests {
properties.getGit().setNumberOfCheckedMilestones(0);
return properties;
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.git;
import java.io.File;
@@ -23,22 +39,29 @@ import static org.mockito.Mockito.never;
@RunWith(MockitoJUnitRunner.class)
public class ProjectGitHandlerTests {
@Mock GitRepo gitRepo;
@Mock
GitRepo gitRepo;
ReleaserProperties properties = new ReleaserProperties();
ProjectGitHandler updater = new ProjectGitHandler(this.properties) {
@Override GitRepo gitRepo(File workingDir) {
@Override
GitRepo gitRepo(File workingDir) {
return ProjectGitHandlerTests.this.gitRepo;
}
@Override File cloneProject(String url) {
@Override
File cloneProject(String url) {
return new File(".");
}
};
File file = new File("");
@Test
public void should_only_commit_without_pushing_changes_when_version_is_snapshot() {
this.updater.commitAndTagIfApplicable(this.file, projectVersion("1.0.0.BUILD-SNAPSHOT"));
this.updater.commitAndTagIfApplicable(this.file,
projectVersion("1.0.0.BUILD-SNAPSHOT"));
then(this.gitRepo).should().commit(eq("Bumping versions"));
then(this.gitRepo).should(never()).tag(anyString());
@@ -55,15 +78,18 @@ public class ProjectGitHandlerTests {
@Test
public void should_commit_when_snapshot_version_is_present_with_post_release_msg() {
this.updater.commitAfterBumpingVersions(this.file, projectVersion("1.0.0.BUILD-SNAPSHOT"));
this.updater.commitAfterBumpingVersions(this.file,
projectVersion("1.0.0.BUILD-SNAPSHOT"));
then(this.gitRepo).should().commit(eq("Bumping versions to 1.0.1.BUILD-SNAPSHOT after release"));
then(this.gitRepo).should()
.commit(eq("Bumping versions to 1.0.1.BUILD-SNAPSHOT after release"));
then(this.gitRepo).should(never()).tag(anyString());
}
@Test
public void should_not_commit_when_non_snapshot_version_is_present() {
this.updater.commitAfterBumpingVersions(this.file, projectVersion("1.0.0.RELEASE"));
this.updater.commitAfterBumpingVersions(this.file,
projectVersion("1.0.0.RELEASE"));
then(this.gitRepo).should(never()).commit(eq("Bumping versions after release"));
then(this.gitRepo).should(never()).tag(anyString());
@@ -71,14 +97,16 @@ public class ProjectGitHandlerTests {
@Test
public void should_not_revert_changes_for_snapshots() {
this.updater.revertChangesIfApplicable(this.file, projectVersion("1.0.0.BUILD-SNAPSHOT"));
this.updater.revertChangesIfApplicable(this.file,
projectVersion("1.0.0.BUILD-SNAPSHOT"));
then(this.gitRepo).should(never()).revert(anyString());
}
@Test
public void should_revert_changes_when_version_is_not_snapshot() {
this.updater.revertChangesIfApplicable(this.file, projectVersion("1.0.0.RELEASE"));
this.updater.revertChangesIfApplicable(this.file,
projectVersion("1.0.0.RELEASE"));
then(this.gitRepo).should().revert(eq("Going back to snapshots"));
}
@@ -92,10 +120,11 @@ public class ProjectGitHandlerTests {
@Test
public void should_throw_exception_when_no_fixed_version_passed_for_the_project() {
BDDAssertions.thenThrownBy(() -> this.updater
.cloneProjectFromOrg("spring-cloud-sleuth"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("You haven't provided a version");
BDDAssertions
.thenThrownBy(
() -> this.updater.cloneProjectFromOrg("spring-cloud-sleuth"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("You haven't provided a version");
}
@Test
@@ -136,7 +165,8 @@ public class ProjectGitHandlerTests {
given(this.gitRepo.hasBranch(anyString())).willReturn(true);
given(this.gitRepo.hasBranch("2.3.x")).willReturn(false);
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.3.4.RELEASE");
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(),
"2.3.4.RELEASE");
then(this.gitRepo).should(never()).checkout("2.3.x");
}
@@ -146,7 +176,8 @@ public class ProjectGitHandlerTests {
given(this.gitRepo.hasBranch(anyString())).willReturn(false);
given(this.gitRepo.hasBranch("2.3.x")).willReturn(true);
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.3.4.RELEASE");
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(),
"2.3.4.RELEASE");
then(this.gitRepo).should().checkout("2.3.x");
}
@@ -156,7 +187,7 @@ public class ProjectGitHandlerTests {
given(this.gitRepo.hasBranch(anyString())).willReturn(false);
given(this.gitRepo.hasBranch("Finchley")).willReturn(true);
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "Finchley.SR6");
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "Finchley.SR6");
then(this.gitRepo).should().checkout("Finchley");
}
@@ -166,7 +197,8 @@ public class ProjectGitHandlerTests {
given(this.gitRepo.hasBranch(anyString())).willReturn(false);
given(this.gitRepo.hasBranch("Finchley")).willReturn(true);
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.0.0.RELEASE", "Finchley.SR6");
this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.0.0.RELEASE",
"Finchley.SR6");
then(this.gitRepo).should(never()).checkout("2.0.0");
then(this.gitRepo).should().checkout("Finchley");
@@ -175,4 +207,5 @@ public class ProjectGitHandlerTests {
private ProjectVersion projectVersion(String version) {
return new ProjectVersion("foo", version);
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.gradle;
import java.io.File;
@@ -24,7 +40,10 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
* @author Marcin Grzejszczak
*/
public class GradleUpdaterTests {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
File temporaryFolder;
@Before
@@ -37,21 +56,21 @@ public class GradleUpdaterTests {
public void should_substitute_values_in_gradle_properties() throws IOException {
File projectRoot = tmpFile("gradleproject");
ReleaserProperties properties = new ReleaserProperties();
Map<String, String> props = new HashMap<String, String>() {{
put("foo", "spring-cloud-contract");
put("bar", "spring-cloud-sleuth");
}};
Map<String, String> props = new HashMap<String, String>() {
{
put("foo", "spring-cloud-contract");
put("bar", "spring-cloud-sleuth");
}
};
properties.getGradle().setGradlePropsSubstitution(props);
Projects projects = new Projects(
new ProjectVersion("spring-cloud-contract", "1.0.0"),
new ProjectVersion("spring-cloud-sleuth", "2.0.0")
);
new ProjectVersion("spring-cloud-sleuth", "2.0.0"));
new GradleUpdater(properties).updateProjectFromBom(projectRoot,
projects, new ProjectVersion("spring-cloud-contract", "1.0.0"), true);
new GradleUpdater(properties).updateProjectFromBom(projectRoot, projects,
new ProjectVersion("spring-cloud-contract", "1.0.0"), true);
then(asString(tmpFile("gradleproject/gradle.properties")))
.contains("foo=1.0.0");
then(asString(tmpFile("gradleproject/gradle.properties"))).contains("foo=1.0.0");
then(asString(tmpFile("gradleproject/child/gradle.properties")))
.contains("bar=2.0.0");
}
@@ -60,19 +79,21 @@ public class GradleUpdaterTests {
public void should_throw_exception_if_snapshots_remain() {
File projectRoot = tmpFile("gradleproject");
ReleaserProperties properties = new ReleaserProperties();
Map<String, String> props = new HashMap<String, String>() {{
put("foo", "spring-cloud-contract");
put("bar", "spring-cloud-sleuth");
}};
Map<String, String> props = new HashMap<String, String>() {
{
put("foo", "spring-cloud-contract");
put("bar", "spring-cloud-sleuth");
}
};
properties.getGradle().setGradlePropsSubstitution(props);
Projects projects = new Projects(
new ProjectVersion("spring-cloud-contract", "1.0.0.BUILD-SNAPSHOT"),
new ProjectVersion("spring-cloud-sleuth", "2.0.0")
);
new ProjectVersion("spring-cloud-sleuth", "2.0.0"));
thenThrownBy(() -> new GradleUpdater(properties).updateProjectFromBom(projectRoot,
projects, new ProjectVersion("spring-cloud-contract", "1.0.0.RELEASE"), true))
.hasMessageContaining("matches the [ ^.*\\.(BUILD-)?SNAPSHOT.*$] pattern in line number [1]");
projects, new ProjectVersion("spring-cloud-contract", "1.0.0.RELEASE"),
true)).hasMessageContaining(
"matches the [ ^.*\\.(BUILD-)?SNAPSHOT.*$] pattern in line number [1]");
}
private File file(String relativePath) throws URISyntaxException {
@@ -86,4 +107,5 @@ public class GradleUpdaterTests {
private String asString(File file) throws IOException {
return new String(Files.readAllBytes(file.toPath()));
}
}
}

View File

@@ -1,7 +1,22 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import org.junit.Before;
@@ -19,19 +34,20 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
public class BomParserTests {
File springCloudReleaseProject;
ReleaserProperties properties = new ReleaserProperties();
@Before
public void setup() throws URISyntaxException {
this.springCloudReleaseProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
this.springCloudReleaseProject = new File(
GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
}
@Test
public void should_throw_exception_when_boot_pom_is_missing() {
BomParser parser = new BomParser(this.properties, new File("."));
thenThrownBy(parser::bootVersion)
.isInstanceOf(IllegalStateException.class)
thenThrownBy(parser::bootVersion).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Pom is not present");
}
@@ -41,8 +57,7 @@ public class BomParserTests {
this.properties.getPom().setThisTrainBom(null);
BomParser parser = new BomParser(this.properties, this.springCloudReleaseProject);
thenThrownBy(parser::bootVersion)
.isInstanceOf(IllegalStateException.class)
thenThrownBy(parser::bootVersion).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Pom is not present");
}
@@ -52,16 +67,17 @@ public class BomParserTests {
this.properties.getPom().setThisTrainBom(null);
BomParser parser = new BomParser(this.properties, this.springCloudReleaseProject);
thenThrownBy(parser::bootVersion)
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("The pom doesn't have a [spring-boot-starter-parent] artifact id");
thenThrownBy(parser::bootVersion).isInstanceOf(IllegalStateException.class)
.hasMessageContaining(
"The pom doesn't have a [spring-boot-starter-parent] artifact id");
}
@Test
public void should_populate_sc_release_version() {
BomParser parser = new BomParser(this.properties, this.springCloudReleaseProject);
String scReleaseVersion = parser.allVersions().versionForProject("spring-cloud-release");
String scReleaseVersion = parser.allVersions()
.versionForProject("spring-cloud-release");
then(scReleaseVersion).isEqualTo("Dalston.BUILD-SNAPSHOT");
}
@@ -79,8 +95,7 @@ public class BomParserTests {
public void should_throw_exception_when_cloud_pom_is_missing() {
BomParser parser = new BomParser(this.properties, new File("."));
thenThrownBy(parser::versionsFromBom)
.isInstanceOf(IllegalStateException.class)
thenThrownBy(parser::versionsFromBom).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Pom is not present");
}
@@ -90,8 +105,7 @@ public class BomParserTests {
this.properties.getPom().setThisTrainBom(null);
BomParser parser = new BomParser(this.properties, this.springCloudReleaseProject);
thenThrownBy(parser::versionsFromBom)
.isInstanceOf(IllegalStateException.class)
thenThrownBy(parser::versionsFromBom).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Pom is not present");
}
@@ -101,9 +115,9 @@ public class BomParserTests {
this.properties.getPom().setThisTrainBom("pom.xml");
BomParser parser = new BomParser(this.properties, this.springCloudReleaseProject);
thenThrownBy(parser::versionsFromBom)
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("The pom doesn't have a [spring-cloud-dependencies-parent] artifact id");
thenThrownBy(parser::versionsFromBom).isInstanceOf(IllegalStateException.class)
.hasMessageContaining(
"The pom doesn't have a [spring-cloud-dependencies-parent] artifact id");
}
@Test
@@ -147,4 +161,5 @@ public class BomParserTests {
Project project(String name, String value) {
return new Project(name, value);
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import org.junit.Test;
@@ -15,104 +31,124 @@ import static org.mockito.BDDMockito.then;
@RunWith(MockitoJUnitRunner.class)
public class LoggerToMavenLogTests {
@Mock Logger logger;
@InjectMocks LoggerToMavenLog loggerToMavenLog;
@Mock
Logger logger;
@InjectMocks
LoggerToMavenLog loggerToMavenLog;
RuntimeException exception = new RuntimeException();
@Test public void isDebugEnabled() {
@Test
public void isDebugEnabled() {
this.loggerToMavenLog.isDebugEnabled();
then(this.logger).should().isDebugEnabled();
}
@Test public void debug() {
@Test
public void debug() {
this.loggerToMavenLog.debug("foo");
then(this.logger).should().debug("foo");
}
@Test public void debug1() {
@Test
public void debug1() {
this.loggerToMavenLog.debug("foo", this.exception);
then(this.logger).should().debug("foo", this.exception);
}
@Test public void debug2() {
@Test
public void debug2() {
this.loggerToMavenLog.debug(this.exception);
then(this.logger).should().debug("Exception occurred", this.exception);
}
@Test public void isInfoEnabled() {
@Test
public void isInfoEnabled() {
this.loggerToMavenLog.isInfoEnabled();
then(this.logger).should().isInfoEnabled();
}
@Test public void info() {
@Test
public void info() {
this.loggerToMavenLog.info("foo");
then(this.logger).should().info("foo");
}
@Test public void info1() {
@Test
public void info1() {
this.loggerToMavenLog.info("foo", this.exception);
then(this.logger).should().info("foo", this.exception);
}
@Test public void info2() {
@Test
public void info2() {
this.loggerToMavenLog.info(this.exception);
then(this.logger).should().info("Exception occurred", this.exception);
}
@Test public void isWarnEnabled() {
@Test
public void isWarnEnabled() {
this.loggerToMavenLog.isWarnEnabled();
then(this.logger).should().isWarnEnabled();
}
@Test public void warn() {
@Test
public void warn() {
this.loggerToMavenLog.warn("foo");
then(this.logger).should().warn("foo");
}
@Test public void warn1() {
@Test
public void warn1() {
this.loggerToMavenLog.warn("foo", this.exception);
then(this.logger).should().warn("foo", this.exception);
}
@Test public void warn2() {
@Test
public void warn2() {
this.loggerToMavenLog.warn(this.exception);
then(this.logger).should().warn("Exception occurred", this.exception);
}
@Test public void isErrorEnabled() {
@Test
public void isErrorEnabled() {
this.loggerToMavenLog.isErrorEnabled();
then(this.logger).should().isErrorEnabled();
}
@Test public void error() {
@Test
public void error() {
this.loggerToMavenLog.error("foo");
then(this.logger).should().error("foo");
}
@Test public void error1() {
@Test
public void error1() {
this.loggerToMavenLog.error("foo", this.exception);
then(this.logger).should().error("foo", this.exception);
}
@Test public void error2() {
@Test
public void error2() {
this.loggerToMavenLog.error(this.exception);
then(this.logger).should().error("Exception occurred", this.exception);
}
}
}

View File

@@ -1,17 +1,33 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
@@ -25,6 +41,7 @@ import org.apache.maven.model.Model;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.release.internal.git.GitRepoTests;
import static org.assertj.core.api.BDDAssertions.then;
@@ -36,17 +53,23 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
public class PomReaderTests {
PomReader pomReader = new PomReader();
File springCloudReleaseProjectPom;
File springCloudReleaseProject;
File empty;
File licenseFile;
@Before
public void setup() throws URISyntaxException {
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release")
.toURI();
this.springCloudReleaseProject = new File(scRelease);
this.springCloudReleaseProjectPom = new File(scRelease.getPath(), "pom.xml");
this.empty = new File(GitRepoTests.class.getResource("/projects/project/empty.xml").toURI());
this.empty = new File(
GitRepoTests.class.getResource("/projects/project/empty.xml").toURI());
this.licenseFile = new File(scRelease.getPath(), "LICENSE.txt");
}
@@ -81,8 +104,8 @@ public class PomReaderTests {
@Test
public void should_throw_exception_when_file_is_empty() {
thenThrownBy(() -> this.pomReader.readPom(this.empty))
.hasMessageStartingWith("File [")
.hasMessageContaining("] is empty")
.hasMessageStartingWith("File [").hasMessageContaining("] is empty")
.hasCauseInstanceOf(EOFException.class);
}
}
}

View File

@@ -1,17 +1,33 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
@@ -29,6 +45,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.cloud.release.internal.git.GitRepoTests;
import org.springframework.util.FileSystemUtils;
@@ -38,11 +55,18 @@ import org.springframework.util.FileSystemUtils;
*/
public class PomUpdaterTests {
@Rule
public OutputCapture capture = new OutputCapture();
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
Versions versions = new Versions("0.0.1", "0.0.2", projects());
PomUpdater pomUpdater = new PomUpdater();
PomReader pomReader = new PomReader();
@Rule public OutputCapture capture = new OutputCapture();
@Rule public TemporaryFolder tmp = new TemporaryFolder();
File temporaryFolder;
@Before
@@ -52,41 +76,51 @@ public class PomUpdaterTests {
}
@Test
public void should_not_update_pom_when_project_is_not_on_the_versions_list() throws Exception {
public void should_not_update_pom_when_project_is_not_on_the_versions_list()
throws Exception {
File springCloudReleasePom = file("/projects/spring-cloud-release");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse();
BDDAssertions.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 {
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");
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versions)).isFalse();
BDDAssertions
.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");
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");
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versions)).isTrue();
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versions))
.isTrue();
}
@Test
public void should_update_pom_when_project_is_not_on_the_versions_list() throws Exception {
public void should_update_pom_when_project_is_not_on_the_versions_list()
throws Exception {
File springCloudSleuthPom = file("/projects/spring-cloud-sleuth");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue();
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom,
this.versions)).isTrue();
}
@Test
public void should_not_update_pom_when_project_is_on_the_versions_list_but_there_is_no_pom() throws Exception {
public void should_not_update_pom_when_project_is_on_the_versions_list_but_there_is_no_pom()
throws Exception {
File springCloudSleuthPom = file("/projects/spring-cloud-sleuth/empty-folder");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isFalse();
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom,
this.versions)).isFalse();
}
@Test
@@ -94,86 +128,110 @@ public class PomUpdaterTests {
File originalPom = pom("/projects/project");
File pomInTemp = tmpFile("/project/pom.xml");
ModelWrapper rootPom = model("foo");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isEqualTo(asString(originalPom));
}
@Test
public void should_update_the_pom_if_only_artifact_id_is_matched_in_the_root_pom() throws Exception {
public void should_update_the_pom_if_only_artifact_id_is_matched_in_the_root_pom()
throws Exception {
File originalPom = pom("/projects/project", "pom_matching_artifact.xml");
File pomInTemp = tmpFile("/project/pom_matching_artifact.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_update_the_pom_if_parent_is_matched_via_sc_build() throws Exception {
public void should_update_the_pom_if_parent_is_matched_via_sc_build()
throws Exception {
File originalPom = pom("/projects/project", "pom_matching_parent_v2.xml");
File pomInTemp = tmpFile("/project/pom_matching_parent_v2.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(originalPom)).isNotEqualTo(asString(storedPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.2");
}
@Test
public void should_update_the_pom_if_parent_is_matched_via_sc_dependencies_parent() throws Exception {
public void should_update_the_pom_if_parent_is_matched_via_sc_dependencies_parent()
throws Exception {
File originalPom = pom("/projects/project", "pom_matching_parent.xml");
File pomInTemp = tmpFile("/project/pom_matching_parent.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.2");
}
@Test
public void should_not_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception {
public void should_not_update_child_pom_when_project_is_not_on_the_versions_list()
throws Exception {
File springCloudReleasePom = file("/projects/spring-cloud-release");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse();
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom,
this.versions)).isFalse();
}
@Test
public void should_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception {
public void should_update_child_pom_when_project_is_not_on_the_versions_list()
throws Exception {
File springCloudSleuthPom = file("/projects/spring-cloud-sleuth");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue();
BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom,
this.versions)).isTrue();
}
@Test
public void should_update_the_child_pom_if_parent_is_matched_via_sc_build() throws Exception {
File originalPom = pom("/projects/project/children", "pom_matching_parent_v2.xml");
public void should_update_the_child_pom_if_parent_is_matched_via_sc_build()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_matching_parent_v2.xml");
File pomInTemp = tmpFile("/project/children/pom_matching_parent_v2.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT")
@@ -181,122 +239,165 @@ public class PomUpdaterTests {
}
@Test
public void should_update_the_parent_from_properties_even_if_group_ids_dont_match() throws Exception {
File originalPom = pom("/projects/project/children", "pom_different_group_boot_parent.xml");
public void should_update_the_parent_from_properties_even_if_group_ids_dont_match()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_different_group_boot_parent.xml");
File pomInTemp = tmpFile("/project/children/pom_different_group_boot_parent.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_only_update_the_properties_section_when_group_ids_dont_match_and_there_is_no_skip_deployment() throws Exception {
public void should_only_update_the_properties_section_when_group_ids_dont_match_and_there_is_no_skip_deployment()
throws Exception {
File originalPom = pom("/projects/project/children", "pom_different_group.xml");
File pomInTemp = tmpFile("/project/children/pom_different_group.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("1.5.8.RELEASE");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_deployment_property() throws Exception {
File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_prop.xml");
File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_prop.xml");
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_deployment_property()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_different_group_skip_deployment_prop.xml");
File pomInTemp = tmpFile(
"/project/children/pom_different_group_skip_deployment_prop.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.1");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin() throws Exception {
File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_plugin.xml");
File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_plugin.xml");
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_different_group_skip_deployment_plugin.xml");
File pomInTemp = tmpFile(
"/project/children/pom_different_group_skip_deployment_plugin.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.1");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin_management() throws Exception {
File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_plugin_mngmnt.xml");
File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_plugin_mngmnt.xml");
public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin_management()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_different_group_skip_deployment_plugin_mngmnt.xml");
File pomInTemp = tmpFile(
"/project/children/pom_different_group_skip_deployment_plugin_mngmnt.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("1.2.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.1");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT");
}
@Test
public void should_update_boot_parent_even_if_the_project_group_doesnt_match() throws Exception {
File originalPom = pom("/projects/project/children", "pom_case_from_contract.xml");
public void should_update_boot_parent_even_if_the_project_group_doesnt_match()
throws Exception {
File originalPom = pom("/projects/project/children",
"pom_case_from_contract.xml");
File pomInTemp = tmpFile("/project/children/pom_case_from_contract.xml");
ModelWrapper rootPom = model("spring-cloud-contract", "org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper rootPom = model("spring-cloud-contract",
"org.springframework.cloud");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.1");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.1");
}
@Test
public void should_update_the_child_pom_if_parent_is_matched_via_sc_dependencies_parent() throws Exception {
public void should_update_the_child_pom_if_parent_is_matched_via_sc_dependencies_parent()
throws Exception {
File originalPom = pom("/projects/project/children", "pom_matching_parent.xml");
File pomInTemp = tmpFile("/project/children/pom_matching_parent.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
// the rest is the same
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT")
@@ -305,29 +406,38 @@ public class PomUpdaterTests {
@Test
public void should_update_the_child_pom_if_properties_are_matched() throws Exception {
File originalPom = pom("/projects/project/children", "pom_matching_properties.xml");
File originalPom = pom("/projects/project/children",
"pom_matching_properties.xml");
File pomInTemp = tmpFile("/project/children/pom_matching_properties.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.3.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getProperties())
.containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT")
.containsEntry("spring-cloud-vault.version", "0.0.4.BUILD-SNAPSHOT");
}
@Test
public void should_override_a_pom_when_there_was_a_change_in_the_model() throws Exception {
File beforeProcessing = pom("/projects/project/children", "pom_matching_properties.xml");
public void should_override_a_pom_when_there_was_a_change_in_the_model()
throws Exception {
File beforeProcessing = pom("/projects/project/children",
"pom_matching_properties.xml");
File afterProcessing = tmpFile("/project/children/pom_matching_properties.xml");
ModelWrapper model = this.pomUpdater.updateModel(model("spring-cloud-sleuth"), afterProcessing, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(model("spring-cloud-sleuth"),
afterProcessing, this.versions);
File processedPom = this.pomUpdater.overwritePomIfDirty(model, Versions.EMPTY_VERSION, afterProcessing);
File processedPom = this.pomUpdater.overwritePomIfDirty(model,
Versions.EMPTY_VERSION, afterProcessing);
String processedPomText = asString(processedPom);
String beforeProcessingText = asString(beforeProcessing);
@@ -335,39 +445,51 @@ public class PomUpdaterTests {
}
@Test
public void should_not_override_a_pom_when_there_was_no_change_in_the_model() throws Exception {
public void should_not_override_a_pom_when_there_was_no_change_in_the_model()
throws Exception {
File beforeProcessing = pom("/projects/project/");
File afterProcessing = tmpFile("/project/pom.xml");
ModelWrapper model = this.pomUpdater.updateModel(model("foo"), afterProcessing, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(model("foo"), afterProcessing,
this.versions);
File processedPom = this.pomUpdater.overwritePomIfDirty(model, Versions.EMPTY_VERSION, afterProcessing);
File processedPom = this.pomUpdater.overwritePomIfDirty(model,
Versions.EMPTY_VERSION, afterProcessing);
BDDAssertions.then(asString(processedPom)).isEqualTo(asString(beforeProcessing));
}
@Test
public void should_update_the_model_when_root_project_has_parent_suffix() throws Exception {
public void should_update_the_model_when_root_project_has_parent_suffix()
throws Exception {
File originalPom = pom("/projects/spring-cloud-contract");
File pomInTemp = tmpFile("/spring-cloud-contract/pom.xml");
ModelWrapper rootPom = model("spring-cloud-contract-parent");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom));
Model overriddenPomModel = this.pomReader.readPom(storedPom);
BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2");
BDDAssertions.then(overriddenPomModel.getVersion())
.isEqualTo("0.0.2.BUILD-SNAPSHOT");
BDDAssertions.then(overriddenPomModel.getParent().getVersion())
.isEqualTo("0.0.2");
}
@Test
public void should_not_update_the_model_when_project_uses_same_version_for_artifact() throws Exception {
File originalPom = pom("/projects/project/", "pom_matching_artifact_same_version.xml");
public void should_not_update_the_model_when_project_uses_same_version_for_artifact()
throws Exception {
File originalPom = pom("/projects/project/",
"pom_matching_artifact_same_version.xml");
File pomInTemp = tmpFile("/project/pom_matching_artifact_same_version.xml");
ModelWrapper rootPom = model("spring-cloud-sleuth");
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versions);
ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp,
this.versions);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions, pomInTemp);
File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versions,
pomInTemp);
BDDAssertions.then(asString(storedPom)).isEqualTo(asString(originalPom));
}
@@ -406,11 +528,12 @@ public class PomUpdaterTests {
}
private File pom(String relativePath, String pomName) throws URISyntaxException {
return new File(new File(GitRepoTests.class.getResource(relativePath).toURI()), pomName);
return new File(new File(GitRepoTests.class.getResource(relativePath).toURI()),
pomName);
}
private String asString(File file) throws IOException {
return new String(Files.readAllBytes(file.toPath()));
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -16,39 +32,45 @@ import org.springframework.cloud.release.internal.git.ProjectGitHandler;
*/
public class ProjectPomUpdaterTests {
@Test public void should_convert_fixed_versions_to_updated_fixed_versions() {
@Test
public void should_convert_fixed_versions_to_updated_fixed_versions() {
ReleaserProperties properties = new ReleaserProperties();
properties.getFixedVersions().put("spring-cloud-task", "2.0.0.RELEASE");
properties.getFixedVersions().put("spring-cloud-openfeign", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-openfeign",
"2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-consul", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-zookeeper", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-zookeeper",
"2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-stream", "Elmhurst.RELEASE");
properties.getFixedVersions().put("spring-cloud-config", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-cloudfoundry", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-cloudfoundry",
"2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-netflix", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-vault", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-security", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-security",
"2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-commons", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-sleuth", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-aws", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-contract", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-release", "Finchley.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-contract",
"2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-release",
"Finchley.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-build", "2.0.3.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-bus", "2.0.1.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-function", "1.0.0.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-starter-build", "Finchley.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-function",
"1.0.0.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-cloud-starter-build",
"Finchley.BUILD-SNAPSHOT");
properties.getFixedVersions().put("spring-boot", "2.0.3.RELEASE");
properties.getFixedVersions().put("spring-cloud-gateway", "2.0.1.BUILD-SNAPSHOT");
ProjectPomUpdater updater = new ProjectPomUpdater(properties);
Map<String, String> fixedVersions = updater.fixedVersions()
.stream()
.collect(Collectors.toMap(
projectVersion -> projectVersion.projectName,
Map<String, String> fixedVersions = updater.fixedVersions().stream()
.collect(Collectors.toMap(projectVersion -> projectVersion.projectName,
projectVersion -> projectVersion.version));
BDDAssertions.then(fixedVersions)
.containsEntry("spring-boot", "2.0.3.RELEASE")
BDDAssertions.then(fixedVersions).containsEntry("spring-boot", "2.0.3.RELEASE")
.containsEntry("spring-boot-dependencies", "2.0.3.RELEASE")
.containsEntry("spring-boot-starter", "2.0.3.RELEASE")
.containsEntry("spring-cloud-build", "2.0.3.BUILD-SNAPSHOT")
@@ -57,14 +79,16 @@ public class ProjectPomUpdaterTests {
.containsEntry("spring-cloud", "Finchley.BUILD-SNAPSHOT");
}
@Test public void should_skip_any_steps_if_there_is_no_pom_xml() {
@Test
public void should_skip_any_steps_if_there_is_no_pom_xml() {
ReleaserProperties properties = new ReleaserProperties();
ProjectGitHandler handler = BDDMockito.mock(ProjectGitHandler.class);
ProjectPomUpdater updater = new ProjectPomUpdater(properties, handler);
updater.updateProjectFromReleaseTrain(
new File("target"), new Projects(), new ProjectVersion("foo", "1.0.0.RELEASE"), false);
updater.updateProjectFromReleaseTrain(new File("target"), new Projects(),
new ProjectVersion("foo", "1.0.0.RELEASE"), false);
BDDMockito.then(handler).shouldHaveZeroInteractions();
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -20,12 +36,15 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
public class ProjectVersionTests {
File springCloudReleaseProject;
File springCloudContract;
@Before
public void setup() throws URISyntaxException {
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
URI scContract = GitRepoTests.class.getResource("/projects/spring-cloud-contract").toURI();
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release")
.toURI();
URI scContract = GitRepoTests.class.getResource("/projects/spring-cloud-contract")
.toURI();
this.springCloudReleaseProject = new File(scRelease.getPath(), "pom.xml");
this.springCloudContract = new File(scContract.getPath(), "pom.xml");
}
@@ -48,7 +67,8 @@ public class ProjectVersionTests {
@Test
public void should_build_version_from_file() {
ProjectVersion projectVersion = new ProjectVersion(this.springCloudReleaseProject);
ProjectVersion projectVersion = new ProjectVersion(
this.springCloudReleaseProject);
then(projectVersion.version).isEqualTo("Dalston.BUILD-SNAPSHOT");
then(projectVersion.projectName).isEqualTo("spring-cloud-starter-build");
@@ -137,36 +157,44 @@ public class ProjectVersionTests {
@Test
public void should_not_bump_version_by_patch_version_when_non_ga_or_sr() {
then(projectVersion("1.0.1.BUILD-SNAPSHOT").postReleaseSnapshotVersion()).isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.M1").postReleaseSnapshotVersion()).isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.RC1").postReleaseSnapshotVersion()).isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("Finchley.SR1").postReleaseSnapshotVersion()).isEqualTo("Finchley.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.BUILD-SNAPSHOT").postReleaseSnapshotVersion())
.isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.M1").postReleaseSnapshotVersion())
.isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.RC1").postReleaseSnapshotVersion())
.isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(projectVersion("Finchley.SR1").postReleaseSnapshotVersion())
.isEqualTo("Finchley.BUILD-SNAPSHOT");
}
@Test
public void should_bump_version_by_patch_version_when_bumping_snapshots_for_ga() {
then(projectVersion("1.0.1.RELEASE").postReleaseSnapshotVersion()).isEqualTo("1.0.2.BUILD-SNAPSHOT");
then(projectVersion("1.0.1.RELEASE").postReleaseSnapshotVersion())
.isEqualTo("1.0.2.BUILD-SNAPSHOT");
}
@Test
public void should_return_the_previous_version_for_release_train_version_when_bumping_snapshots() {
String version = "Edgware.BUILD-SNAPSHOT";
then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("Edgware.BUILD-SNAPSHOT");
then(projectVersion(version).postReleaseSnapshotVersion())
.isEqualTo("Edgware.BUILD-SNAPSHOT");
}
@Test
public void should_bump_version_by_patch_version_when_bumping_releases() {
String version = "1.0.1.RELEASE";
then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("1.0.2.BUILD-SNAPSHOT");
then(projectVersion(version).postReleaseSnapshotVersion())
.isEqualTo("1.0.2.BUILD-SNAPSHOT");
}
@Test
public void should_return_the_previous_version_for_release_train_version_when_bumping_releases() {
String version = "Edgware.RELEASE";
then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("Edgware.BUILD-SNAPSHOT");
then(projectVersion(version).postReleaseSnapshotVersion())
.isEqualTo("Edgware.BUILD-SNAPSHOT");
}
@Test
@@ -240,7 +268,8 @@ public class ProjectVersionTests {
@Test
public void should_return_False_when_checking_ga_version_against_non_ga() {
then(projectVersion("1.0.1.BUILD-SNAPSHOT").isReleaseOrServiceRelease()).isFalse();
then(projectVersion("1.0.1.BUILD-SNAPSHOT").isReleaseOrServiceRelease())
.isFalse();
then(projectVersion("1.0.1.M4").isReleaseOrServiceRelease()).isFalse();
then(projectVersion("1.0.1.RC4").isReleaseOrServiceRelease()).isFalse();
}
@@ -296,7 +325,8 @@ public class ProjectVersionTests {
String thisVersion = "Finchley.SR1";
String thatVersion = "Finchley.SR10";
then(projectVersion(thatVersion).compareToReleaseTrainName(thisVersion)).isPositive();
then(projectVersion(thatVersion).compareToReleaseTrainName(thisVersion))
.isPositive();
}
@Test
@@ -312,12 +342,14 @@ public class ProjectVersionTests {
String thisVersion = "Finchley.SR2";
String thatVersion = "Finchley.SR1";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isPositive();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isPositive();
thisVersion = "Greenwich.SR1";
thatVersion = "Finchley.SR2";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isPositive();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isPositive();
}
@Test
@@ -333,12 +365,14 @@ public class ProjectVersionTests {
String thisVersion = "Finchley.SR1";
String thatVersion = "Finchley.SR2";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isNegative();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isNegative();
thisVersion = "Finchley.SR2";
thatVersion = "Greenwich.SR1";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isNegative();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isNegative();
}
@Test
@@ -346,7 +380,8 @@ public class ProjectVersionTests {
String thisVersion = "";
String thatVersion = "Finchley.SR2";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isNegative();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isNegative();
thisVersion = "";
thatVersion = "";
@@ -359,42 +394,51 @@ public class ProjectVersionTests {
String thisVersion = "Finchley.SR1";
String thatVersion = "";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isPositive();
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion))
.isPositive();
}
@Test
public void should_return_no_unacceptable_patterns_for_a_snapshot_version() {
then(projectVersion("1.0.0.BUILD-SNAPSHOT").unacceptableVersionPatterns()).isEmpty();
then(projectVersion("1.0.0.BUILD-SNAPSHOT").unacceptableVersionPatterns())
.isEmpty();
then(projectVersion("1.0.0.SNAPSHOT").unacceptableVersionPatterns()).isEmpty();
}
@Test
public void should_return_snapshot_unacceptable_patterns_for_a_milestone_or_rc_version() {
List<Pattern> milestonePatterns = projectVersion("1.0.0.M1").unacceptableVersionPatterns();
List<Pattern> milestonePatterns = projectVersion("1.0.0.M1")
.unacceptableVersionPatterns();
then(milestonePatterns).isNotEmpty();
then(milestonePatterns.get(0).pattern()).contains("SNAPSHOT");
List<Pattern> rcPatterns = projectVersion("1.0.0.RC1").unacceptableVersionPatterns();
List<Pattern> rcPatterns = projectVersion("1.0.0.RC1")
.unacceptableVersionPatterns();
then(rcPatterns).isNotEmpty();
then(rcPatterns.get(0).pattern()).contains("SNAPSHOT");
}
@Test
public void should_return_snapshot_milestone_rc_unacceptable_patterns_for_a_ga_or_sr_version() {
List<Pattern> gaPatterns = projectVersion("1.0.0.RELEASE").unacceptableVersionPatterns();
List<Pattern> gaPatterns = projectVersion("1.0.0.RELEASE")
.unacceptableVersionPatterns();
thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(gaPatterns);
gaPatterns = projectVersion("1.0.0").unacceptableVersionPatterns();
thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(gaPatterns);
List<Pattern> srPatterns = projectVersion("1.0.0.SR1").unacceptableVersionPatterns();
List<Pattern> srPatterns = projectVersion("1.0.0.SR1")
.unacceptableVersionPatterns();
thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(srPatterns);
List<Pattern> unknownTypeOfVersion = projectVersion("1.0.0.SOMETHING").unacceptableVersionPatterns();
thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(unknownTypeOfVersion);
List<Pattern> unknownTypeOfVersion = projectVersion("1.0.0.SOMETHING")
.unacceptableVersionPatterns();
thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(
unknownTypeOfVersion);
}
private void thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(List<Pattern> unknownTypeOfVersion) {
private void thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(
List<Pattern> unknownTypeOfVersion) {
then(unknownTypeOfVersion).isNotEmpty();
then(unknownTypeOfVersion.get(0).pattern()).contains("SNAPSHOT");
then(unknownTypeOfVersion.get(1).pattern()).contains("M[0-9]");
@@ -404,4 +448,5 @@ public class ProjectVersionTests {
private ProjectVersion projectVersion(String version) {
return new ProjectVersion("foo", version);
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -53,7 +69,8 @@ public class ProjectsTests {
projectVersions.add(new ProjectVersion("spring-boot-starter-build", "1.0.0"));
Projects projects = new Projects(projectVersions);
then(projects.forNameStartingWith("spring-boot").get(0).version).isEqualTo("1.0.0");
then(projects.forNameStartingWith("spring-boot").get(0).version)
.isEqualTo("1.0.0");
}
@Test
@@ -65,7 +82,8 @@ public class ProjectsTests {
projectVersions.add(boot);
ProjectVersion bootDeps = new ProjectVersion("spring-boot-dependencies", "2.0.0");
projectVersions.add(bootDeps);
ProjectVersion original = new ProjectVersion("spring-cloud-starter-foo", "3.0.0.BUILD-SNAPSHOT");
ProjectVersion original = new ProjectVersion("spring-cloud-starter-foo",
"3.0.0.BUILD-SNAPSHOT");
projectVersions.add(original);
Projects projects = new Projects(projectVersions);
@@ -73,7 +91,8 @@ public class ProjectsTests {
then(forRollback.forName("spring-boot-starter").version).isEqualTo("2.0.0");
then(forRollback.forName("spring-boot-dependencies").version).isEqualTo("2.0.0");
then(forRollback.forName("spring-cloud-starter-foo").version).isEqualTo("3.0.1.BUILD-SNAPSHOT");
then(forRollback.forName("spring-cloud-starter-foo").version)
.isEqualTo("3.0.1.BUILD-SNAPSHOT");
}
@Test
@@ -122,7 +141,8 @@ public class ProjectsTests {
@Test
public void should_return_projects_with_bumped_versions() {
Set<ProjectVersion> projectVersions = new HashSet<>();
projectVersions.add(new ProjectVersion("spring-boot-dependencies", "2.0.0.RELEASE"));
projectVersions
.add(new ProjectVersion("spring-boot-dependencies", "2.0.0.RELEASE"));
projectVersions.add(new ProjectVersion("spring-boot-starter", "2.0.0.RELEASE"));
projectVersions.add(new ProjectVersion("foo", "1.0.0.RELEASE"));
projectVersions.add(new ProjectVersion("bar", "1.0.1.M1"));
@@ -132,9 +152,11 @@ public class ProjectsTests {
projectVersions.add(new ProjectVersion("foo4", "Finchley.SR4"));
Projects projects = new Projects(projectVersions);
Projects bumped = projects.postReleaseSnapshotVersion(Collections.singletonList("spring-boot"));
Projects bumped = projects
.postReleaseSnapshotVersion(Collections.singletonList("spring-boot"));
then(bumped.forName("spring-boot-dependencies").version).isEqualTo("2.0.0.RELEASE");
then(bumped.forName("spring-boot-dependencies").version)
.isEqualTo("2.0.0.RELEASE");
then(bumped.forName("spring-boot-starter").version).isEqualTo("2.0.0.RELEASE");
then(bumped.forName("foo").version).isEqualTo("1.0.1.BUILD-SNAPSHOT");
then(bumped.forName("bar").version).isEqualTo("1.0.1.BUILD-SNAPSHOT");
@@ -151,8 +173,8 @@ public class ProjectsTests {
Projects projects = new Projects(projectVersions);
thenThrownBy(() -> projects.forFile(this.springCloudReleasePom))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Project with name [spring-cloud-starter-build] is not present");
.isInstanceOf(IllegalStateException.class).hasMessageContaining(
"Project with name [spring-cloud-starter-build] is not present");
}
@Test
@@ -162,8 +184,8 @@ public class ProjectsTests {
Projects projects = new Projects(projectVersions);
thenThrownBy(() -> projects.forName("spring-cloud-starter-build"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Project with name [spring-cloud-starter-build] is not present");
.isInstanceOf(IllegalStateException.class).hasMessageContaining(
"Project with name [spring-cloud-starter-build] is not present");
}
@Test
@@ -208,4 +230,4 @@ public class ProjectsTests {
}
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import org.apache.maven.plugin.logging.Log;
@@ -17,19 +33,25 @@ import static org.mockito.BDDMockito.then;
@RunWith(MockitoJUnitRunner.class)
public class PropertyStorerTests {
@Mock Log log;
@Mock ModifiedPomXMLEventReader pom;
@InjectMocks PropertyStorer propertyStorer;
@Mock
Log log;
@Test public void should_not_set_a_version_when_its_empty() {
@Mock
ModifiedPomXMLEventReader pom;
@InjectMocks
PropertyStorer propertyStorer;
@Test
public void should_not_set_a_version_when_its_empty() {
this.propertyStorer.setPropertyVersionIfApplicable(new Project("foo", ""));
then(this.log).should().warn(containsWarnMsgAboutEmptyVersion());
}
private String containsWarnMsgAboutEmptyVersion() {
return BDDMockito.argThat(
argument -> argument.contains("is empty. Will not set it"));
return BDDMockito
.argThat(argument -> argument.contains("is empty. Will not set it"));
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.util.HashSet;
@@ -11,8 +27,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.BDDMockito.then;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
/**
@@ -21,33 +37,42 @@ import static org.mockito.Mockito.never;
@RunWith(MockitoJUnitRunner.class)
public class PropertyVersionChangerTests {
@Mock PropertyStorer propertyStorer;
@Mock
PropertyStorer propertyStorer;
@Test
public void should_set_version_when_project_matches_property_name() throws Exception {
PropertyVersionChanger changer = new PropertyVersionChanger(model(), versions(), null, null, this.propertyStorer);
PropertyVersionChanger changer = new PropertyVersionChanger(model(), versions(),
null, null, this.propertyStorer);
changer.apply(null);
then(this.propertyStorer).should().setPropertyVersionIfApplicable(project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT"));
then(this.propertyStorer).should().setPropertyVersionIfApplicable(
project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT"));
}
@Test
public void should_not_set_version_when_project_doesnt_match_property_name() throws Exception {
PropertyVersionChanger changer = new PropertyVersionChanger(nonMatchingModel(), versions(), null, null, this.propertyStorer);
public void should_not_set_version_when_project_doesnt_match_property_name()
throws Exception {
PropertyVersionChanger changer = new PropertyVersionChanger(nonMatchingModel(),
versions(), null, null, this.propertyStorer);
changer.apply(null);
then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class));
then(this.propertyStorer).should(never())
.setPropertyVersionIfApplicable(any(Project.class));
}
@Test
public void should_not_set_version_when_project_matches_property_name_and_versions_are_the_same() throws Exception {
PropertyVersionChanger changer = new PropertyVersionChanger(modelWithSameValues(), versions(), null, null, this.propertyStorer);
public void should_not_set_version_when_project_matches_property_name_and_versions_are_the_same()
throws Exception {
PropertyVersionChanger changer = new PropertyVersionChanger(modelWithSameValues(),
versions(), null, null, this.propertyStorer);
changer.apply(null);
then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class));
then(this.propertyStorer).should(never())
.setPropertyVersionIfApplicable(any(Project.class));
}
Versions versions() {
@@ -56,10 +81,9 @@ public class PropertyVersionChangerTests {
@SuppressWarnings("unchecked")
private Set<Project> allProjects() {
return new HashSet<>(Arrays.asList(new Project[] {
project("spring-cloud-aws", "1.2.0.BUILD-SNAPSHOT"),
project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT")
}));
return new HashSet<>(Arrays.asList(
new Project[] { project("spring-cloud-aws", "1.2.0.BUILD-SNAPSHOT"),
project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT") }));
}
Project project(String name, String value) {
@@ -101,4 +125,5 @@ public class PropertyVersionChangerTests {
properties.setProperty("spring-cloud-non-matching.version", "1.0.0.RELEASE");
return properties;
}
}
}

View File

@@ -1,9 +1,24 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
import org.apache.maven.model.Model;
import org.springframework.cloud.release.internal.pom.PomReader;
/**
* @author Marcin Grzejszczak
@@ -15,4 +30,5 @@ public class TestPomReader {
public Model readPom(File pom) {
return this.pomReader.readPom(pom);
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.io.File;
@@ -16,7 +32,8 @@ public class TestUtils {
prepareLocalRepo("target/test-classes/projects/", "spring-cloud-static");
}
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException {
private static void prepareLocalRepo(String buildDir, String repoPath)
throws IOException {
File dotGit = new File(buildDir + repoPath + "/.git");
File git = new File(buildDir + repoPath + "/git");
if (git.exists()) {
@@ -27,4 +44,4 @@ public class TestUtils {
git.renameTo(dotGit);
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
import java.util.ArrayList;
@@ -29,16 +45,17 @@ class ListOfChanges {
ListOfChanges(ModelWrapper model) {
this.changes = new ArrayList<>(model.sourceChanges);
}
}
class VersionChangeAssert extends
AbstractAssert<VersionChangeAssert, ListOfChanges> {
class VersionChangeAssert extends AbstractAssert<VersionChangeAssert, ListOfChanges> {
public VersionChangeAssert(ListOfChanges actual) {
VersionChangeAssert(ListOfChanges actual) {
super(actual, VersionChangeAssert.class);
}
VersionChangeAssert newParentVersionIsEqualTo(String groupId, String artifactId, String newVersion) {
VersionChangeAssert newParentVersionIsEqualTo(String groupId, String artifactId,
String newVersion) {
boolean matches = false;
for (VersionChange change : this.actual.changes) {
if (newVersion.equals(change.getNewVersion())
@@ -54,5 +71,5 @@ class VersionChangeAssert extends
failWithMessage("There is no change with that parent coordinates");
return this;
}
}
}

View File

@@ -1,17 +1,33 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 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
* 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
* 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.
* 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.
*/
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.pom;
@@ -36,12 +52,10 @@ public class VersionsTests {
@Test
public void should_add_boot_to_versions_when_version_is_created() {
then(new Versions("1.2.3.RELEASE").projects)
.contains(
new Project("spring-boot", "1.2.3.RELEASE"),
new Project("spring-boot-starter-parent", "1.2.3.RELEASE"),
new Project("spring-boot-dependencies", "1.2.3.RELEASE")
);
then(new Versions("1.2.3.RELEASE").projects).contains(
new Project("spring-boot", "1.2.3.RELEASE"),
new Project("spring-boot-starter-parent", "1.2.3.RELEASE"),
new Project("spring-boot-dependencies", "1.2.3.RELEASE"));
}
@Test
@@ -113,14 +127,19 @@ public class VersionsTests {
versions = mixedVersions().setVersion("spring-cloud-build", "3.0.0");
then(versions.versionForProject("spring-cloud-dependencies-parent")).isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.RELEASE");
then(versions.versionForProject("spring-cloud-dependencies-parent"))
.isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.RELEASE");
versions = mixedVersions().setVersion("spring-cloud-dependencies-parent", "3.0.0");
versions = mixedVersions().setVersion("spring-cloud-dependencies-parent",
"3.0.0");
then(versions.versionForProject("spring-cloud-build")).isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-dependencies-parent")).isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.RELEASE");
then(versions.versionForProject("spring-cloud-dependencies-parent"))
.isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.RELEASE");
}
@Test
@@ -142,48 +161,68 @@ public class VersionsTests {
versions = mixedVersions().setVersion("spring-cloud-release", "Greenwich.SR8");
then(versions.versionForProject("spring-cloud")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-release")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-starter")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-release"))
.isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-starter"))
.isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.SR8");
versions = mixedVersions().setVersion("spring-cloud-dependencies", "Greenwich.SR8");
versions = mixedVersions().setVersion("spring-cloud-dependencies",
"Greenwich.SR8");
then(versions.versionForProject("spring-cloud")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-release")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-starter")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-release"))
.isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-starter"))
.isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.SR8");
}
@Test
public void should_update_projects_for_custom_bom_only() {
Versions versions = mixedVersions(customBom()).setVersion("spring-cloud", "3.0.0");
Versions versions = mixedVersions(customBom()).setVersion("spring-cloud",
"3.0.0");
then(versions.versionForProject("spring-cloud")).isEqualTo("3.0.0");
then(versions.versionForProject("spring-cloud-stream-starters")).isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud-stream-starters"))
.isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud-starter")).isEmpty();
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.RELEASE");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.RELEASE");
versions = mixedVersions(customBom()).setVersion("spring-cloud-stream-starters", "Fishtown.SR4");
versions = mixedVersions(customBom()).setVersion("spring-cloud-stream-starters",
"Fishtown.SR4");
then(versions.versionForProject("spring-cloud")).isEmpty();
then(versions.versionForProject("spring-cloud-stream-starters")).isEqualTo("Fishtown.SR4");
then(versions.versionForProject("spring-cloud-stream-starters"))
.isEqualTo("Fishtown.SR4");
then(versions.versionForProject("spring-cloud-starter")).isEmpty();
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.RELEASE");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.RELEASE");
versions = mixedVersions(customBom()).setVersion("spring-cloud-release", "Greenwich.SR8");
versions = mixedVersions(customBom()).setVersion("spring-cloud-release",
"Greenwich.SR8");
then(versions.versionForProject("spring-cloud-release")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-stream-starters")).isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud-release"))
.isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-stream-starters"))
.isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud")).isEmpty();
then(versions.versionForProject("spring-cloud-starter")).isEmpty();
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.RELEASE");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.RELEASE");
versions = mixedVersions(customBom()).setVersion("spring-cloud-dependencies", "Greenwich.SR8");
versions = mixedVersions(customBom()).setVersion("spring-cloud-dependencies",
"Greenwich.SR8");
then(versions.versionForProject("spring-cloud")).isEmpty();
then(versions.versionForProject("spring-cloud-stream-starters")).isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud-stream-starters"))
.isEqualTo("Fishtown.RELEASE");
then(versions.versionForProject("spring-cloud-starter")).isEmpty();
then(versions.versionForProject("spring-cloud-dependencies")).isEqualTo("Greenwich.SR8");
then(versions.versionForProject("spring-cloud-dependencies"))
.isEqualTo("Greenwich.SR8");
}
@Test
@@ -203,8 +242,10 @@ public class VersionsTests {
private ReleaserProperties customBom() {
ReleaserProperties properties = new ReleaserProperties();
properties.getMetaRelease().setReleaseTrainDependencyNames(Collections.emptyList());
properties.getMetaRelease().setReleaseTrainProjectName("spring-cloud-stream-starters");
properties.getMetaRelease()
.setReleaseTrainDependencyNames(Collections.emptyList());
properties.getMetaRelease()
.setReleaseTrainProjectName("spring-cloud-stream-starters");
properties.getPom().setThisTrainBom("spring-cloud-stream-dependencies");
return properties;
}
@@ -236,4 +277,5 @@ public class VersionsTests {
properties.setProperty("missing.version", "1.0.0");
return properties;
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.post;
import java.io.File;
@@ -39,12 +55,19 @@ public class PostReleaseActionsTests {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
File temporaryFolder;
TestPomReader testPomReader = new TestPomReader();
GradleUpdater gradleUpdater = BDDMockito.mock(GradleUpdater.class);
ReleaserProperties properties = new ReleaserProperties();
File cloned;
LinkedMultiValueMap<String, File> clonedTestProjects = new LinkedMultiValueMap<>();
ProjectGitHandler projectGitHandler = new ProjectGitHandler(this.properties) {
@Override
public File cloneTestSamplesProject() {
@@ -65,7 +88,9 @@ public class PostReleaseActionsTests {
return file;
}
};
ProjectPomUpdater updater = new ProjectPomUpdater(this.properties);
ProjectBuilder builder = new ProjectBuilder(this.properties);
@Before
@@ -102,7 +127,8 @@ public class PostReleaseActionsTests {
@Test
public void should_update_project_and_run_tests_and_update_test_is_called() {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().setTestSamplesProjectUrl(tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
this.properties.getGit().setTestSamplesProjectUrl(
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
this.properties.getMaven().setBuildCommand("touch build.log");
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties);
@@ -118,8 +144,9 @@ public class PostReleaseActionsTests {
}
private void thenGradleUpdaterWasCalled() {
BDDMockito.then(this.gradleUpdater).should().updateProjectFromBom(BDDMockito.any(File.class),
BDDMockito.any(Projects.class), BDDMockito.any(ProjectVersion.class), BDDMockito.eq(false));
BDDMockito.then(this.gradleUpdater).should().updateProjectFromBom(
BDDMockito.any(File.class), BDDMockito.any(Projects.class),
BDDMockito.any(ProjectVersion.class), BDDMockito.eq(false));
}
@Test
@@ -147,8 +174,10 @@ public class PostReleaseActionsTests {
@Test
public void should_update_project_and_run_tests_and_release_train_docs_generation_is_called() {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().setReleaseTrainDocsUrl(tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
this.properties.getMaven().setGenerateReleaseTrainDocsCommand("touch generate.log");
this.properties.getGit().setReleaseTrainDocsUrl(
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
this.properties.getMaven()
.setGenerateReleaseTrainDocsCommand("touch generate.log");
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties);
@@ -175,7 +204,7 @@ public class PostReleaseActionsTests {
}
@Test
public void should_do_nothing_when_the_switch_for_test_samples_update_check_is_off_and_test_samples_update_is_called() {
public void should_do_nothing_when_the_switch_for_test_samples_update_check_is_off_and_update_is_called() {
this.properties.getGit().setUpdateReleaseTrainDocs(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties);
@@ -187,12 +216,13 @@ public class PostReleaseActionsTests {
}
@Test
public void should_update_test_sample_projects_when_test_samples_update_is_called() throws Exception {
public void should_update_test_sample_projects_when_test_samples_update_is_called()
throws Exception {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().getAllTestSampleUrls().clear();
this.properties.getGit().getAllTestSampleUrls().put("spring-cloud-sleuth",
Collections.singletonList(tmpFile("spring-cloud-core-tests/")
.getAbsolutePath() + "/"));
Collections.singletonList(
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"));
AtomicReference<Projects> postReleaseProjects = new AtomicReference<>();
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties) {
@@ -205,31 +235,36 @@ public class PostReleaseActionsTests {
actions.updateAllTestSamples(currentGa());
Map.Entry<String, List<File>> entry = this.clonedTestProjects.entrySet()
.stream()
.filter(s -> s.getKey().contains("spring-cloud-core-tests"))
.findFirst().orElseThrow(() -> new IllegalStateException("Not found"));
Map.Entry<String, List<File>> entry = this.clonedTestProjects.entrySet().stream()
.filter(s -> s.getKey().contains("spring-cloud-core-tests")).findFirst()
.orElseThrow(() -> new IllegalStateException("Not found"));
File clonedFile = entry.getValue().get(0);
Model pomWithCloud = this.testPomReader.readPom(new File(clonedFile, "zuul-proxy-eureka/pom.xml"));
Model pomWithCloud = this.testPomReader
.readPom(new File(clonedFile, "zuul-proxy-eureka/pom.xml"));
Git git = GitTestUtils.openGitProject(clonedFile);
BDDAssertions.then(pomWithCloud.getProperties().getProperty("spring-cloud.version")).isEqualTo("Finchley.BUILD-SNAPSHOT");
BDDAssertions.then(pomWithCloud.getParent().getVersion()).isEqualTo("2.0.4.RELEASE");
BDDAssertions
.then(pomWithCloud.getProperties().getProperty("spring-cloud.version"))
.isEqualTo("Finchley.BUILD-SNAPSHOT");
BDDAssertions.then(pomWithCloud.getParent().getVersion())
.isEqualTo("2.0.4.RELEASE");
Iterator<RevCommit> iterator = git.log().call().iterator();
RevCommit commit = iterator.next();
BDDAssertions.then(commit.getShortMessage())
.isEqualTo("Updated versions after [Finchley.SR1] release train and [2.0.1.RELEASE] [spring-cloud-sleuth] project release");
BDDAssertions.then(commit.getShortMessage()).isEqualTo(
"Updated versions after [Finchley.SR1] release train and [2.0.1.RELEASE] [spring-cloud-sleuth] project release");
thenGradleUpdaterWasCalled();
BDDAssertions.then(postReleaseProjects.get()
.forName("spring-boot-dependencies").version).isEqualTo("2.0.4.RELEASE");
BDDAssertions.then(
postReleaseProjects.get().forName("spring-boot-dependencies").version)
.isEqualTo("2.0.4.RELEASE");
}
@Test
public void should_assume_that_project_version_is_snapshot_when_no_pom_is_present() throws Exception {
public void should_assume_that_project_version_is_snapshot_when_no_pom_is_present()
throws Exception {
this.properties.getMetaRelease().setEnabled(true);
this.properties.getGit().getAllTestSampleUrls().clear();
this.properties.getGit().getAllTestSampleUrls().put("spring-cloud-sleuth",
Collections.singletonList(tmpFile("spring-cloud-static/")
.getAbsolutePath() + "/"));
Collections.singletonList(
tmpFile("spring-cloud-static/").getAbsolutePath() + "/"));
AtomicReference<Projects> postReleaseProjects = new AtomicReference<>();
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties) {
@@ -242,10 +277,9 @@ public class PostReleaseActionsTests {
actions.updateAllTestSamples(currentGa());
Map.Entry<String, List<File>> entry = this.clonedTestProjects.entrySet()
.stream()
.filter(s -> s.getKey().contains("spring-cloud-static"))
.findFirst().orElseThrow(() -> new IllegalStateException("Not found"));
Map.Entry<String, List<File>> entry = this.clonedTestProjects.entrySet().stream()
.filter(s -> s.getKey().contains("spring-cloud-static")).findFirst()
.orElseThrow(() -> new IllegalStateException("Not found"));
}
private String sleuthParentPomVersion() {
@@ -254,8 +288,7 @@ public class PostReleaseActionsTests {
}
Projects currentGa() {
return new Projects(
new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
return new Projects(new ProjectVersion("spring-cloud-aws", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-bus", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-cli", "2.0.0.RELEASE"),
new ProjectVersion("spring-cloud-commons", "2.0.1.RELEASE"),
@@ -286,4 +319,5 @@ public class PostReleaseActionsTests {
private File file(String relativePath) throws URISyntaxException {
return new File(PomUpdateAcceptanceTests.class.getResource(relativePath).toURI());
}
}
}

View File

@@ -1,7 +1,20 @@
package org.springframework.cloud.release.internal.project;
/*
* Copyright 2013-2019 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.
*/
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
package org.springframework.cloud.release.internal.project;
import java.io.File;
import java.io.IOException;
@@ -15,6 +28,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.cloud.release.internal.PomUpdateAcceptanceTests;
import org.springframework.cloud.release.internal.ReleaserProperties;
@@ -22,14 +36,21 @@ import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.TestUtils;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
/**
* @author Marcin Grzejszczak
*/
public class ProjectBuilderTests {
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@Rule
public OutputCapture outputCapture = new OutputCapture();
File temporaryFolder;
@Rule public OutputCapture outputCapture = new OutputCapture();
@Before
public void checkOs() throws Exception {
@@ -49,7 +70,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_command_when_after_running_there_is_no_html_file_with_unresolved_tag() throws Exception {
public void should_successfully_execute_a_command_when_after_running_there_is_no_html_file_with_unresolved_tag()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("ls -al");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -62,20 +84,23 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_command_when_path_is_provided_explicitly() throws Exception {
public void should_successfully_execute_a_command_when_path_is_provided_explicitly()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("ls -al");
properties.setWorkingDir(new File("/foo/bar").getAbsolutePath());
ProjectBuilder builder = projectBuilder(properties);
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"), tmpFile("/builder/resolved").getPath());
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
tmpFile("/builder/resolved").getPath());
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("resolved.log");
}
@Test
public void should_successfully_execute_a_build_command_for_milestone_version() throws Exception {
public void should_successfully_execute_a_build_command_for_milestone_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -88,7 +113,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_build_command_for_rc_version() throws Exception {
public void should_successfully_execute_a_build_command_for_rc_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -101,7 +127,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_build_command_for_release_version() throws Exception {
public void should_successfully_execute_a_build_command_for_release_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -114,7 +141,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_build_command_for_sr_version() throws Exception {
public void should_successfully_execute_a_build_command_for_sr_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -127,7 +155,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present() throws Exception {
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo {{systemProps}}");
properties.getMaven().setSystemProperties("-Dhello=world -Dfoo=bar");
@@ -141,7 +170,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_and_there_are_no_sys_props() throws Exception {
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_and_there_are_no_sys_props()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo {{systemProps}}");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -149,12 +179,12 @@ public class ProjectBuilderTests {
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo");
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@Test
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_without_system_props() throws Exception {
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_without_system_props()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo {{systemProps}}");
properties.getMaven().setSystemProperties("hello=world foo=bar");
@@ -168,7 +198,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_inside_command() throws Exception {
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present_inside_command()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo {{systemProps}} bar");
properties.getMaven().setSystemProperties("-Dhello=world -Dfoo=bar");
@@ -182,7 +213,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_pass_system_props_when_build_gets_executed_without_explicit_system_props() throws Exception {
public void should_successfully_pass_system_props_when_build_gets_executed_without_explicit_system_props()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo bar");
properties.getMaven().setSystemProperties("-Dhello=world -Dfoo=bar");
@@ -202,8 +234,10 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = projectBuilder(properties);
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("contains a tag that wasn't resolved properly");
thenThrownBy(
() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining(
"contains a tag that wasn't resolved properly");
}
@Test
@@ -214,8 +248,10 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = projectBuilder(properties);
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("Process waiting time of [0] minutes exceeded");
thenThrownBy(
() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining(
"Process waiting time of [0] minutes exceeded");
}
@Test
@@ -232,7 +268,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_deploy_command_for_milestone_version() throws Exception {
public void should_successfully_execute_a_deploy_command_for_milestone_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -245,7 +282,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_deploy_command_for_rc_version() throws Exception {
public void should_successfully_execute_a_deploy_command_for_rc_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -258,7 +296,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_deploy_command_for_release_version() throws Exception {
public void should_successfully_execute_a_deploy_command_for_release_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -271,7 +310,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_deploy_command_for_sr_version() throws Exception {
public void should_successfully_execute_a_deploy_command_for_sr_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
@@ -284,7 +324,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() throws Exception {
public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo \"{{systemProps}}\"");
properties.getMaven().setSystemProperties("-Dhello=hello-world");
@@ -298,7 +339,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_pass_system_props_when_deploy_gets_executed_without_explicit_system_props() throws Exception {
public void should_successfully_pass_system_props_when_deploy_gets_executed_without_explicit_system_props()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo ");
properties.getMaven().setSystemProperties("-Dhello=hello-world");
@@ -319,8 +361,10 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = projectBuilder(properties);
thenThrownBy(() -> builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("Process waiting time of [0] minutes exceeded");
thenThrownBy(
() -> builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining(
"Process waiting time of [0] minutes exceeded");
}
@Test
@@ -344,9 +388,11 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder() throws Exception {
public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setPublishDocsCommands(new String[] { "echo {{systemProps}} 1", "echo {{systemProps}} 2" });
properties.getMaven().setPublishDocsCommands(
new String[] { "echo {{systemProps}} 1", "echo {{systemProps}} 2" });
properties.getMaven().setSystemProperties("-Dhello=world -Dfoo=bar");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
@@ -365,9 +411,11 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_a_publish_docs_command_and_substitute_the_version() throws Exception {
public void should_successfully_execute_a_publish_docs_command_and_substitute_the_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setPublishDocsCommands(new String[] { "echo '{{version}}'" });
properties.getMaven()
.setPublishDocsCommands(new String[] { "echo '{{version}}'" });
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectBuilder builder = new ProjectBuilder(properties) {
@@ -384,7 +432,8 @@ public class ProjectBuilderTests {
}
@Test
public void should_successfully_execute_an_update_docs_command_and_substitute_the_version() throws Exception {
public void should_successfully_execute_an_update_docs_command_and_substitute_the_version()
throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setGenerateReleaseTrainDocsCommand("echo '{{version}}'");
File resolved = tmpFile("/builder/resolved");
@@ -406,12 +455,14 @@ public class ProjectBuilderTests {
@Test
public void should_throw_exception_when_publish_docs_command_took_too_long_to_execute() {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setPublishDocsCommands(new String[] { "sleep 1", "sleep 1" });
properties.getMaven()
.setPublishDocsCommands(new String[] { "sleep 1", "sleep 1" });
properties.getMaven().setWaitTimeInMinutes(0);
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = projectBuilder(properties);
thenThrownBy(() -> builder.publishDocs("")).hasMessageContaining("Process waiting time of [0] minutes exceeded");
thenThrownBy(() -> builder.publishDocs(""))
.hasMessageContaining("Process waiting time of [0] minutes exceeded");
}
@Test
@@ -423,40 +474,49 @@ public class ProjectBuilderTests {
@Override
ProcessExecutor executor(String workingDir) {
return new ProcessExecutor(properties.getWorkingDir()) {
@Override Process startProcess(ProcessBuilder builder) {
@Override
Process startProcess(ProcessBuilder builder) {
return processWithInvalidExitCode();
}
};
}
};
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("The process has exited with exit code [1]");
thenThrownBy(
() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining(
"The process has exited with exit code [1]");
}
private Process processWithInvalidExitCode() {
return new Process() {
@Override public OutputStream getOutputStream() {
@Override
public OutputStream getOutputStream() {
return null;
}
@Override public InputStream getInputStream() {
@Override
public InputStream getInputStream() {
return null;
}
@Override public InputStream getErrorStream() {
@Override
public InputStream getErrorStream() {
return null;
}
@Override public int waitFor() {
@Override
public int waitFor() {
return 0;
}
@Override public int exitValue() {
@Override
public int exitValue() {
return 1;
}
@Override public void destroy() {
@Override
public void destroy() {
}
};
@@ -466,21 +526,6 @@ public class ProjectBuilderTests {
return new TestProcessExecutor(workingDir);
}
class TestProcessExecutor extends ProcessExecutor {
int counter = 0;
TestProcessExecutor(String workingDir) {
super(workingDir);
}
@Override ProcessBuilder builder(String[] commands, String workingDir) {
this.counter++;
return super.builder(commands, workingDir)
.redirectOutput(tmpFile("/builder/resolved/resolved.log"));
}
}
private File tmpFile(String relativePath) {
return new File(this.temporaryFolder, relativePath);
}
@@ -493,4 +538,21 @@ public class ProjectBuilderTests {
return new String(Files.readAllBytes(file.toPath()));
}
}
class TestProcessExecutor extends ProcessExecutor {
int counter = 0;
TestProcessExecutor(String workingDir) {
super(workingDir);
}
@Override
ProcessBuilder builder(String[] commands, String workingDir) {
this.counter++;
return super.builder(commands, workingDir)
.redirectOutput(tmpFile("/builder/resolved/resolved.log"));
}
}
}

View File

@@ -1,14 +1,29 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.BDDAssertions.then;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -19,6 +34,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Marcin Grzejszczak
*/
@@ -27,7 +44,9 @@ import org.springframework.web.client.RestTemplate;
@AutoConfigureStubRunner(ids = "sagan:sagan-site")
public class RestTemplateSaganClientTests {
@Value("${stubrunner.runningstubs.sagan-site.port}") Integer saganPort;
@Value("${stubrunner.runningstubs.sagan-site.port}")
Integer saganPort;
SaganClient client;
@Before
@@ -45,7 +64,8 @@ public class RestTemplateSaganClientTests {
then(project.id).isEqualTo("spring-framework");
then(project.name).isEqualTo("Spring Framework");
then(project.repoUrl).isEqualTo("http://github.com/spring-projects/spring-framework");
then(project.repoUrl)
.isEqualTo("http://github.com/spring-projects/spring-framework");
then(project.siteUrl).isEqualTo("http://projects.spring.io/spring-framework");
then(project.category).isEqualTo("active");
then(project.stackOverflowTags).isNotBlank();
@@ -54,8 +74,10 @@ public class RestTemplateSaganClientTests {
then(project.projectReleases).isNotEmpty();
Release release = project.projectReleases.get(0);
then(release.releaseStatus).isEqualTo("PRERELEASE");
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/");
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/javadoc-api/");
then(release.refDocUrl).isEqualTo(
"http://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/");
then(release.apiDocUrl)
.isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/javadoc-api/");
then(release.groupId).isEqualTo("org.springframework");
then(release.artifactId).isEqualTo("spring-context");
then(release.repository.id).isEqualTo("spring-milestones");
@@ -75,8 +97,10 @@ public class RestTemplateSaganClientTests {
Release release = this.client.getRelease("spring-framework", "5.0.0.RC4");
then(release.releaseStatus).isEqualTo("PRERELEASE");
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/spring-framework-reference/");
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/javadoc-api/");
then(release.refDocUrl).isEqualTo(
"http://docs.spring.io/spring/docs/{version}/spring-framework-reference/");
then(release.apiDocUrl)
.isEqualTo("http://docs.spring.io/spring/docs/{version}/javadoc-api/");
then(release.groupId).isEqualTo("org.springframework");
then(release.artifactId).isEqualTo("spring-context");
then(release.repository.id).isEqualTo("spring-milestones");
@@ -156,7 +180,8 @@ public class RestTemplateSaganClientTests {
sithRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/";
sithRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
List<ReleaseUpdate> updates = Arrays.asList(firstRelease, secondRelease, thirdRelease, fourthRelease ,fithRelease, sithRelease);
List<ReleaseUpdate> updates = Arrays.asList(firstRelease, secondRelease,
thirdRelease, fourthRelease, fithRelease, sithRelease);
Project project = this.client.updateRelease("spring-framework", updates);
@@ -190,8 +215,7 @@ public class RestTemplateSaganClientTests {
private RestTemplate restTemplate(ReleaserProperties properties) {
return new RestTemplateBuilder()
.basicAuthorization(properties.getGit().getOauthToken(), "")
.build();
.basicAuthorization(properties.getGit().getOauthToken(), "").build();
}
@Configuration
@@ -199,4 +223,5 @@ public class RestTemplateSaganClientTests {
static class Config {
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.sagan;
import java.util.Arrays;
@@ -12,8 +28,8 @@ import org.mockito.Mockito;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import static org.mockito.BDDMockito.then;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
/**
@@ -22,19 +38,17 @@ import static org.mockito.Mockito.never;
public class SaganUpdaterTest {
SaganClient saganClient = Mockito.mock(SaganClient.class);
ReleaserProperties properties = new ReleaserProperties();
SaganUpdater saganUpdater = new SaganUpdater(this.saganClient, this.properties);
@Before
public void setup() {
Project project = new Project();
project.projectReleases.addAll(Arrays.asList(
release("1.0.0.RC1"),
release("1.1.0.BUILD-SNAPSHOT"),
release("2.0.0.M4"))
);
BDDMockito.given(this.saganClient.getProject(anyString()))
.willReturn(project);
project.projectReleases.addAll(Arrays.asList(release("1.0.0.RC1"),
release("1.1.0.BUILD-SNAPSHOT"), release("2.0.0.M4")));
BDDMockito.given(this.saganClient.getProject(anyString())).willReturn(project);
}
private Release release(String version) {
@@ -44,7 +58,8 @@ public class SaganUpdaterTest {
return release;
}
@Test public void should_not_update_sagan_when_switch_is_off() {
@Test
public void should_not_update_sagan_when_switch_is_off() {
this.properties.getSagan().setUpdateSagan(false);
this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));
@@ -52,27 +67,33 @@ public class SaganUpdaterTest {
then(this.saganClient).shouldHaveZeroInteractions();
}
@Test public void should_update_sagan_for_milestone() {
@Test
public void should_update_sagan_for_milestone() {
this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.M1",
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
"http://cloud.spring.io/spring-cloud-static/foo/{version}/",
"PRERELEASE")));
}
@Test public void should_update_sagan_for_rc() {
this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1"));
@Test
public void should_update_sagan_for_rc() {
this.saganUpdater.updateSagan("master", version("1.0.0.RC1"),
version("1.0.0.RC1"));
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.RC1",
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE")));
"http://cloud.spring.io/spring-cloud-static/foo/{version}/",
"PRERELEASE")));
}
private ProjectVersion version(String version) {
return new ProjectVersion("foo", version);
}
@Test public void should_update_sagan_from_master() {
@Test
public void should_update_sagan_from_master() {
ProjectVersion projectVersion = version("1.0.0.BUILD-SNAPSHOT");
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
@@ -82,7 +103,8 @@ public class SaganUpdaterTest {
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
@Test public void should_update_sagan_from_release_version() {
@Test
public void should_update_sagan_from_release_version() {
ProjectVersion projectVersion = version("1.0.0.RELEASE");
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
@@ -91,14 +113,16 @@ public class SaganUpdaterTest {
then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE",
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "GENERAL_AVAILABILITY")));
"http://cloud.spring.io/spring-cloud-static/foo/{version}/",
"GENERAL_AVAILABILITY")));
then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT");
then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.1.BUILD-SNAPSHOT",
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
@Test public void should_update_sagan_from_non_master() {
@Test
public void should_update_sagan_from_non_master() {
ProjectVersion projectVersion = version("1.1.0.BUILD-SNAPSHOT");
this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion);
@@ -111,15 +135,13 @@ public class SaganUpdaterTest {
private ArgumentMatcher<List<ReleaseUpdate>> withReleaseUpdate(final String version,
final String refDocUrl, final String releaseStatus) {
return argument -> {
return argument -> {
ReleaseUpdate item = argument.get(0);
return "foo".equals(item.artifactId) &&
releaseStatus.equals(item.releaseStatus) &&
version.equals(item.version) &&
refDocUrl.equals(item.apiDocUrl) &&
refDocUrl.equals(item.refDocUrl) &&
item.current;
};
return "foo".equals(item.artifactId)
&& releaseStatus.equals(item.releaseStatus)
&& version.equals(item.version) && refDocUrl.equals(item.apiDocUrl)
&& refDocUrl.equals(item.refDocUrl) && item.current;
};
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 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.
*/
package org.springframework.cloud.release.internal.template;
import java.io.File;
@@ -6,6 +22,7 @@ import java.nio.file.Files;
import java.util.HashSet;
import org.junit.Test;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
@@ -19,6 +36,7 @@ import static org.assertj.core.api.BDDAssertions.then;
public class TemplateGeneratorTests {
ReleaserProperties props = new ReleaserProperties();
ProjectGitHandler handler = new ProjectGitHandler(this.props) {
@Override
public String milestoneUrl(ProjectVersion releaseVersion) {
@@ -30,7 +48,8 @@ public class TemplateGeneratorTests {
public void should_generate_email_from_template_for_tag_with_v_prefix() {
this.props.getPom().setBranch("vDalston.RELEASE");
File generatedMail = new TemplateGenerator(this.props, this.handler).email(new Projects());
File generatedMail = new TemplateGenerator(this.props, this.handler)
.email(new Projects());
then(generatedMail).hasContent(expectedEmail());
}
@@ -39,8 +58,9 @@ public class TemplateGeneratorTests {
public void should_generate_email_from_template_when_output_folder_is_missing() {
this.props.getPom().setBranch("vDalston.RELEASE");
File generatedMail = new TemplateGenerator(this.props, new File("target/foo/bar/baz/template.txt"),
this.handler).email(new Projects());
File generatedMail = new TemplateGenerator(this.props,
new File("target/foo/bar/baz/template.txt"), this.handler)
.email(new Projects());
then(generatedMail).hasContent(expectedEmail());
}
@@ -49,7 +69,8 @@ public class TemplateGeneratorTests {
public void should_generate_email_from_template_for_tag_without_v_prefix() {
this.props.getPom().setBranch("Dalston.RELEASE");
File generatedMail = new TemplateGenerator(this.props, this.handler).email(new Projects());
File generatedMail = new TemplateGenerator(this.props, this.handler)
.email(new Projects());
then(generatedMail).hasContent(expectedEmail());
}
@@ -58,7 +79,8 @@ public class TemplateGeneratorTests {
public void should_generate_tweet_from_template_for_tag_with_v_prefix() {
this.props.getPom().setBranch("vDalston.RELEASE");
File generatedTweet = new TemplateGenerator(this.props, this.handler).tweet(new Projects());
File generatedTweet = new TemplateGenerator(this.props, this.handler)
.tweet(new Projects());
then(generatedTweet).hasContent(expectedTweet());
}
@@ -67,7 +89,8 @@ public class TemplateGeneratorTests {
public void should_generate_tweet_from_template_for_tag_without_v_prefix() {
this.props.getPom().setBranch("Dalston.RELEASE");
File generatedTweet = new TemplateGenerator(this.props, this.handler).tweet(new Projects());
File generatedTweet = new TemplateGenerator(this.props, this.handler)
.tweet(new Projects());
then(generatedTweet).hasContent(expectedTweet());
}
@@ -76,209 +99,227 @@ public class TemplateGeneratorTests {
public void should_generate_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("vDalston.RELEASE");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("General Availability (RELEASE) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Maven Central]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.RELEASE</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'");
.contains(
"| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.RELEASE</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'");
}
@Test
public void should_generate_blog_from_template_for_tag_without_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("Dalston.RELEASE");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("General Availability (RELEASE) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Maven Central]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth\t| 1.0.0.RELEASE\t| ([issues](http://foo.bar.com))")
.contains("<version>Dalston.RELEASE</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'");
.contains(
"| Spring Cloud Sleuth\t| 1.0.0.RELEASE\t| ([issues](http://foo.bar.com))")
.contains("<version>Dalston.RELEASE</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'");
}
@Test
public void should_generate_sr_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("vDalston.SR1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Maven Central]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.SR1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'");
.contains(
"| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.SR1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'");
}
@Test
public void should_generate_sr_blog_from_template_for_tag_without_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("Dalston.SR1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RELEASE"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RELEASE"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Maven Central]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.SR1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'");
.contains(
"| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](http://foo.bar.com))")
.contains("<version>Dalston.SR1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'");
}
@Test
public void should_generate_milestone_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("vDalston.M1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.M1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.M1"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.M1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.M1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Milestone 1 (M1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth\t| 1.0.0.M1\t| ([issues](http://foo.bar.com))")
.contains(
"| Spring Cloud Sleuth\t| 1.0.0.M1\t| ([issues](http://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'http://repo.spring.io/milestone'")
.contains("<version>Dalston.M1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'");
.contains("<version>Dalston.M1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'");
}
@Test
public void should_generate_milestone_blog_from_template_for_tag_without_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("Dalston.M1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.M1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.M1"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.M1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.M1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Milestone 1 (M1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth\t| 1.0.0.M1\t| ([issues](http://foo.bar.com))")
.contains(
"| Spring Cloud Sleuth\t| 1.0.0.M1\t| ([issues](http://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'http://repo.spring.io/milestone'")
.contains("<version>Dalston.M1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'");
.contains("<version>Dalston.M1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'");
}
@Test
public void should_generate_rc_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("vDalston.RC1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth\t| 1.0.0.RC1\t| ([issues](http://foo.bar.com))")
.contains(
"| Spring Cloud Sleuth\t| 1.0.0.RC1\t| ([issues](http://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'http://repo.spring.io/milestone'")
.contains("<version>Dalston.RC1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'");
.contains("<version>Dalston.RC1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'");
}
@Test
public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release()
throws IOException {
this.props.getPom().setBranch("Dalston.RC1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
}
});
File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects);
File generatedBlog = new TemplateGenerator(this.props, this.handler)
.blog(projects);
then(content(generatedBlog))
.contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]")
.contains("The release can be found in [Spring Milestone]")
.contains("### Spring Cloud Sleuth")
.contains("| Spring Cloud Sleuth\t| 1.0.0.RC1\t| ([issues](http://foo.bar.com))")
.contains(
"| Spring Cloud Sleuth\t| 1.0.0.RC1\t| ([issues](http://foo.bar.com))")
.contains("<id>spring-milestones</id>")
.contains("url 'http://repo.spring.io/milestone'")
.contains("<version>Dalston.RC1</version>")
.contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'");
.contains("<version>Dalston.RC1</version>").contains(
"mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'");
}
@Test
public void should_generate_release_notes_template_when_url_exists()
throws IOException {
ProjectGitHandler handler = new ProjectGitHandler(this.props) {
@Override public String milestoneUrl(ProjectVersion releaseVersion) {
@Override
public String milestoneUrl(ProjectVersion releaseVersion) {
return "http://foo.bar.com?closed=1";
}
};
this.props.getPom().setBranch("Dalston.RC1");
Projects projects = new Projects(
new HashSet<ProjectVersion>() {{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
add(new ProjectVersion("spring-boot-dependencies", "1.0.1.RC1"));
}}
);
Projects projects = new Projects(new HashSet<ProjectVersion>() {
{
add(new ProjectVersion("spring-cloud-sleuth", "1.0.0.RC1"));
add(new ProjectVersion("spring-cloud-consul", "1.0.1.RC1"));
add(new ProjectVersion("spring-boot-dependencies", "1.0.1.RC1"));
}
});
File generatedOutput = new TemplateGenerator(this.props, handler).releaseNotes(projects);
File generatedOutput = new TemplateGenerator(this.props, handler)
.releaseNotes(projects);
then(content(generatedOutput))
.contains("# Dalston.RC1")
.contains("Spring Cloud Sleuth `1.0.0.RC1` ([issues](http://foo.bar.com?closed=1))")
.contains("Spring Cloud Consul `1.0.1.RC1` ([issues](http://foo.bar.com?closed=1))")
then(content(generatedOutput)).contains("# Dalston.RC1").contains(
"Spring Cloud Sleuth `1.0.0.RC1` ([issues](http://foo.bar.com?closed=1))")
.contains(
"Spring Cloud Consul `1.0.1.RC1` ([issues](http://foo.bar.com?closed=1))")
.doesNotContain("Boot");
}
@@ -287,18 +328,14 @@ public class TemplateGeneratorTests {
}
private String expectedEmail() {
return "Title:\n"
+ "Spring Cloud Dalston.RELEASE available\n\n"
+ "Content:\n"
return "Title:\n" + "Spring Cloud Dalston.RELEASE available\n\n" + "Content:\n"
+ "All,\n" + "\n"
+ "On behalf of the team and the community, I'm excited to announce Spring Cloud Dalston RELEASE Train release.\n"
+ "\n"
+ "link to blog post\n"
+ "link to twitter\n\n"
+ "Cheers,\n";
+ "\n" + "link to blog post\n" + "link to twitter\n\n" + "Cheers,\n";
}
private String expectedTweet() {
return "The Dalston.RELEASE version of @springcloud has been released!";
}
}

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -17,7 +17,7 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -105,7 +105,8 @@
<nameSuffixForTests>Test</nameSuffixForTests>
<ruleClassForTests>org.junit.rules.ErrorCollector</ruleClassForTests>
<staticImports>
<staticImport>com.blogspot.toomuchcoding.frauddetection.matchers.CustomMatchers.*</staticImport>
<staticImport>com.blogspot.toomuchcoding.frauddetection.matchers.CustomMatchers.*
</staticImport>
</staticImports>
<imports>
<import>com.blogspot.toomuchcoding.frauddetection.matchers.CustomMatchers</import>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -31,7 +31,7 @@
<groupId>org.foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -28,7 +28,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -31,7 +31,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -31,7 +31,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
@@ -31,7 +31,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

Some files were not shown because too many files have changed in this diff Show More