Added -Pguides when the given project version is the newest GA version

fixes gh-145
This commit is contained in:
Marcin Grzejszczak
2019-04-30 16:19:05 +04:00
parent f0918918f2
commit b1ae873800
14 changed files with 2987 additions and 27 deletions

View File

@@ -338,6 +338,8 @@ be set there. Just provide a mapping for the `gradle-props-substition` looking l
Example: `"--releaser.pom.ignored-pom-regex=".{asterisk}\\.git/.{asterisk}$,.\{asterisk}spring-cloud-contract-maven-plugin/src/test/projects/.{asterisk}$,.{asterisk}spring-cloud-contract-maven-plugin/target/.{asterisk}$,.{asterisk}samples/standalone/[a-z]+/.{asterisk}$"`.
- `releaser.working-dir` - By default Releaser assumes running the program from the current working directory.
- `releaser.template.template-folder` - Tells which subfolder with templates to pick for blog, email etc. generation. Defaults to `cloud`.
- `releaser.versions.all-versions-file-url` - Url to a file containing all the versions. Defaults to YAML from start.spring.io.
- `releaser.versions.bom-name` - Name in the YAML from initilizr for BOM mappings. Defaults to `spring-cloud`.
TIP: You can pass the options either via system properties or via application arguments.
Example for system properties: `java -Dreleaser.pom.branch=Camden.SR6 -jar target/spring-cloud-release-tools-spring-1.0.0.M1.jar`

View File

@@ -324,6 +324,8 @@ be set there. Just provide a mapping for the `gradle-props-substition` looking l
Example: `"--releaser.pom.ignored-pom-regex=".{asterisk}\\.git/.{asterisk}$,.\{asterisk}spring-cloud-contract-maven-plugin/src/test/projects/.{asterisk}$,.{asterisk}spring-cloud-contract-maven-plugin/target/.{asterisk}$,.{asterisk}samples/standalone/[a-z]+/.{asterisk}$"`.
- `releaser.working-dir` - By default Releaser assumes running the program from the current working directory.
- `releaser.template.template-folder` - Tells which subfolder with templates to pick for blog, email etc. generation. Defaults to `cloud`.
- `releaser.versions.all-versions-file-url` - Url to a file containing all the versions. Defaults to YAML from start.spring.io.
- `releaser.versions.bom-name` - Name in the YAML from initilizr for BOM mappings. Defaults to `spring-cloud`.
TIP: You can pass the options either via system properties or via application arguments.
Example for system properties: `java -Dreleaser.pom.branch=Camden.SR6 -jar target/spring-cloud-release-tools-spring-1.0.0.M1.jar`

View File

@@ -96,6 +96,11 @@
<artifactId>handlebars</artifactId>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-metadata</artifactId>
<version>0.8.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -61,6 +61,8 @@ public class ReleaserProperties implements Serializable {
private Template template = new Template();
private Versions versions = new Versions();
/**
* Project name to its version - overrides all versions retrieved from a repository
* like Spring Cloud Release.
@@ -150,13 +152,21 @@ public class ReleaserProperties implements Serializable {
this.postReleaseTasksOnly = postReleaseTasksOnly;
}
public Versions getVersions() {
return this.versions;
}
public void setVersions(Versions versions) {
this.versions = versions;
}
@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 + '}';
+ this.template + ", versions=" + this.versions + '}';
}
public ReleaserProperties copy() {
@@ -959,4 +969,41 @@ public class ReleaserProperties implements Serializable {
}
public static class Versions implements Serializable {
/**
* Url to a file containing all the versions. Defaults to YAML from
* start.spring.io.
*/
private String allVersionsFileUrl = "https://raw.githubusercontent.com/spring-io/start.spring.io/master/start-site/src/main/resources/application.yml";
/**
* Name in the YAML from initilizr for BOM mappings.
*/
private String bomName = "spring-cloud";
public String getAllVersionsFileUrl() {
return this.allVersionsFileUrl;
}
public void setAllVersionsFileUrl(String allVersionsFileUrl) {
this.allVersionsFileUrl = allVersionsFileUrl;
}
public String getBomName() {
return bomName;
}
public void setBomName(String bomName) {
this.bomName = bomName;
}
@Override
public String toString() {
return "Versions{" + "allVersionsFileUrl='" + this.allVersionsFileUrl + '\''
+ ", bomName='" + this.bomName + '\'' + '}';
}
}
}

View File

@@ -25,8 +25,10 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -49,6 +51,10 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory.getLogger(ProjectPomUpdater.class);
private static final boolean UPDATE_FIXED_VERSIONS = true;
private static final Map<String, Versions> CACHE = new ConcurrentHashMap<>();
private final ProjectGitHandler gitRepo;
private final PomUpdater pomUpdater = new PomUpdater();
@@ -71,13 +77,32 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware {
* @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());
this.properties.getFixedVersions().forEach(versions::setVersion);
return retrieveVersionsFromReleaseTrainBom(this.properties.getPom().getBranch(),
UPDATE_FIXED_VERSIONS);
}
/**
* For the given root folder (typically the working directory) retrieves list of
* versions for a given release version.
* @param branch branch for which to pick the versions
* @param updateFixedVersions whether should update the retrieved versions with fixed
* ones
* @return projects retrieved from the release train bom
*/
public Projects retrieveVersionsFromReleaseTrainBom(String branch,
boolean updateFixedVersions) {
Versions versions = CACHE.computeIfAbsent(branch, s -> {
File clonedScRelease = this.gitRepo.cloneReleaseTrainProject();
this.gitRepo.checkout(clonedScRelease, branch);
BomParser sCReleasePomParser = new BomParser(this.properties,
clonedScRelease);
return sCReleasePomParser.allVersions();
});
if (updateFixedVersions) {
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();
}

View File

@@ -37,6 +37,7 @@ 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;
import org.springframework.cloud.release.internal.versions.VersionsFetcher;
import org.springframework.util.StringUtils;
/**
@@ -50,8 +51,12 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
private ReleaserProperties properties;
public ProjectBuilder(ReleaserProperties properties) {
private final VersionsFetcher versionsFetcher;
public ProjectBuilder(ReleaserProperties properties,
VersionsFetcher versionsFetcher) {
this.properties = properties;
this.versionsFetcher = versionsFetcher;
}
public void build(ProjectVersion versionFromReleaseTrain) {
@@ -102,7 +107,7 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
}
else if (version.isRelease() || version.isServiceRelease()) {
log.info("Adding the central profile to the Maven build");
return trimmedCommand + " -Pcentral";
return trimmedCommand + " -Pcentral" + profilesForLatestVersion(version);
}
else {
log.info("The build is a snapshot one - will not add any profiles");
@@ -110,6 +115,16 @@ public class ProjectBuilder implements ReleaserPropertiesAware {
return trimmedCommand;
}
private String profilesForLatestVersion(ProjectVersion projectVersion) {
boolean latestGa = this.versionsFetcher.isLatestGa(projectVersion);
if (latestGa) {
log.info("Version [" + projectVersion.version
+ "] is the latest GA! Will append additional profiles");
return " -Pguides";
}
return "";
}
private void assertNoHtmlFilesInDocsContainUnresolvedTags(String workingDir) {
try {
File docs = new File(workingDir, "docs");

View File

@@ -0,0 +1,187 @@
/*
* 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
*
* https://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.versions;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import io.spring.initializr.metadata.BillOfMaterials;
import io.spring.initializr.metadata.InitializrProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.Projects;
import org.springframework.core.io.InputStreamResource;
import org.springframework.util.StringUtils;
/**
* Knows how to fetch the data related to versions. E.g. the latest release train, is this
* project's version the latest one etc.
*
* @author Marcin Grzejszczak
*/
public class VersionsFetcher implements ReleaserPropertiesAware {
private static final Logger log = LoggerFactory.getLogger(VersionsFetcher.class);
private ReleaserProperties properties;
private final ProjectPomUpdater projectPomUpdater;
private final ToPropertiesConverter toPropertiesConverter;
public VersionsFetcher(ReleaserProperties properties,
ProjectPomUpdater projectPomUpdater) {
this.properties = properties;
this.projectPomUpdater = projectPomUpdater;
this.toPropertiesConverter = new ToPropertiesConverter(new RawGithubRetriever());
}
/**
* Checks if the given project version is the latest GA available.
* @param version version to check
* @return {@code true} if this version is the latest GA
*/
public boolean isLatestGa(ProjectVersion version) {
if (!version.isReleaseOrServiceRelease()) {
if (log.isDebugEnabled()) {
log.debug("Version [" + version.toString()
+ "] is non GA, will not fetch any versions.");
}
return false;
}
String latestVersionsUrl = this.properties.getVersions().getAllVersionsFileUrl();
InitializrProperties initializrProperties = this.toPropertiesConverter
.toProperties(latestVersionsUrl);
if (initializrProperties == null) {
return false;
}
ProjectVersion bomVersion = latestBomVersion();
if (bomVersion == null) {
log.info("No BOM mapping with name [{}] found",
this.properties.getVersions().getBomName());
return false;
}
Projects projectVersions = this.projectPomUpdater
.retrieveVersionsFromReleaseTrainBom("v" + bomVersion.toString(), false);
boolean containsProject = projectVersions.containsProject(version.projectName);
if (containsProject) {
return bomVersion.compareTo(projectVersions.forName(version.projectName)) > 0;
}
log.info("The project [" + version.projectName
+ "] is not present in the BOM with projects [" + projectVersions.stream()
.map(v -> v.projectName).collect(Collectors.joining(", "))
+ "]");
return false;
}
private ProjectVersion latestBomVersion() {
String latestVersionsUrl = this.properties.getVersions().getAllVersionsFileUrl();
InitializrProperties initializrProperties = this.toPropertiesConverter
.toProperties(latestVersionsUrl);
if (initializrProperties == null) {
return null;
}
ProjectVersion springCloudVersion = initializrProperties.getEnv().getBoms()
.getOrDefault(
this.properties.getVersions().getBomName(), new BillOfMaterials())
.getMappings().stream()
.map(mapping -> new ProjectVersion(
this.properties.getVersions().getBomName(), mapping.getVersion()))
.filter(ProjectVersion::isReleaseOrServiceRelease)
.max(ProjectVersion::compareTo).orElse(new ProjectVersion(
this.properties.getVersions().getBomName(), ""));
log.info("Latest BOM version is [{}]", springCloudVersion.version);
return springCloudVersion;
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
class RawGithubRetriever {
private static final Logger LOG = LoggerFactory.getLogger(RawGithubRetriever.class);
String raw(String stringUrl) {
try {
URL url = new URL(stringUrl);
URLConnection con = url.openConnection();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
con.getInputStream(), StandardCharsets.UTF_8))) {
return reader.lines().collect(Collectors.joining("\n"));
}
}
catch (IOException e) {
LOG.warn("Exception occurred while trying to fetch the URL [" + stringUrl
+ "] contents");
return null;
}
}
}
class ToPropertiesConverter {
private static final Map<String, InitializrProperties> CACHE = new ConcurrentHashMap<>();
private final RawGithubRetriever rawGithubRetriever;
ToPropertiesConverter(RawGithubRetriever rawGithubRetriever) {
this.rawGithubRetriever = rawGithubRetriever;
}
InitializrProperties toProperties(String url) {
return CACHE.computeIfAbsent(url, s -> {
String retrievedFile = this.rawGithubRetriever.raw(s);
if (StringUtils.isEmpty(retrievedFile)) {
return null;
}
YamlPropertiesFactoryBean yamlProcessor = new YamlPropertiesFactoryBean();
yamlProcessor.setResources(new InputStreamResource(new ByteArrayInputStream(
retrievedFile.getBytes(StandardCharsets.UTF_8))));
Properties properties = yamlProcessor.getObject();
return new Binder(
new MapConfigurationPropertySource(properties.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey().toString(),
e -> e.getValue().toString()))))
.bind("initializr",
InitializrProperties.class)
.get();
});
}
}

View File

@@ -45,6 +45,7 @@ import org.springframework.cloud.release.internal.pom.Projects;
import org.springframework.cloud.release.internal.pom.TestPomReader;
import org.springframework.cloud.release.internal.pom.TestUtils;
import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.versions.VersionsFetcher;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -91,7 +92,9 @@ public class PostReleaseActionsTests {
ProjectPomUpdater updater = new ProjectPomUpdater(this.properties);
ProjectBuilder builder = new ProjectBuilder(this.properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater);
ProjectBuilder builder = new ProjectBuilder(this.properties, versionsFetcher);
@Before
public void setup() throws Exception {

View File

@@ -32,8 +32,10 @@ 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;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.TestUtils;
import org.springframework.cloud.release.internal.versions.VersionsFetcher;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.BDDAssertions.then;
@@ -61,7 +63,7 @@ public class ProjectBuilderTests {
}
ProjectBuilder projectBuilder(ReleaserProperties properties) {
return new ProjectBuilder(properties) {
return new ProjectBuilder(properties, versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return testExecutor(workingDir);
@@ -123,7 +125,7 @@ public class ProjectBuilderTests {
builder.build(new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
.contains("foo -Pmilestone").doesNotContain("-Pguides");
}
@Test
@@ -137,7 +139,7 @@ public class ProjectBuilderTests {
builder.build(new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
.contains("foo -Pcentral -Pguides");
}
@Test
@@ -278,7 +280,7 @@ public class ProjectBuilderTests {
builder.deploy(new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
.contains("foo -Pmilestone").doesNotContain("-Pguides");
}
@Test
@@ -292,7 +294,7 @@ public class ProjectBuilderTests {
builder.deploy(new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
.contains("foo -Pmilestone").doesNotContain("-Pguides");
}
@Test
@@ -306,7 +308,7 @@ public class ProjectBuilderTests {
builder.deploy(new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
.contains("foo -Pcentral -Pguides");
}
@Test
@@ -320,7 +322,7 @@ public class ProjectBuilderTests {
builder.deploy(new ProjectVersion("foo", "1.0.0.SR1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
.contains("foo -Pcentral -Pguides");
}
@Test
@@ -373,7 +375,8 @@ public class ProjectBuilderTests {
properties.getMaven().setPublishDocsCommands(new String[] { "ls -al", "ls -al" });
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectBuilder builder = new ProjectBuilder(properties) {
ProjectBuilder builder = new ProjectBuilder(properties,
versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return executor;
@@ -387,6 +390,16 @@ public class ProjectBuilderTests {
then(executor.counter).isEqualTo(2);
}
private VersionsFetcher versionsFetcher(ReleaserProperties properties) {
ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties);
return new VersionsFetcher(properties, pomUpdater) {
@Override
public boolean isLatestGa(ProjectVersion version) {
return true;
}
};
}
@Test
public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder()
throws Exception {
@@ -396,7 +409,8 @@ public class ProjectBuilderTests {
properties.getMaven().setSystemProperties("-Dhello=world -Dfoo=bar");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectBuilder builder = new ProjectBuilder(properties) {
ProjectBuilder builder = new ProjectBuilder(properties,
versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return executor;
@@ -418,7 +432,8 @@ public class ProjectBuilderTests {
.setPublishDocsCommands(new String[] { "echo '{{version}}'" });
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectBuilder builder = new ProjectBuilder(properties) {
ProjectBuilder builder = new ProjectBuilder(properties,
versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return executor;
@@ -439,7 +454,8 @@ public class ProjectBuilderTests {
File resolved = tmpFile("/builder/resolved");
properties.setWorkingDir(resolved.getPath());
TestProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectBuilder builder = new ProjectBuilder(properties) {
ProjectBuilder builder = new ProjectBuilder(properties,
versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return executor;
@@ -470,7 +486,8 @@ public class ProjectBuilderTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("exit 1");
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties) {
ProjectBuilder builder = new ProjectBuilder(properties,
versionsFetcher(properties)) {
@Override
ProcessExecutor executor(String workingDir) {
return new ProcessExecutor(properties.getWorkingDir()) {

View File

@@ -0,0 +1,106 @@
/*
* 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
*
* https://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.versions;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import org.assertj.core.api.BDDAssertions;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
class VersionsFetcherTests {
@Test
void should_return_true_when_current_version_is_the_latest_ga()
throws URISyntaxException {
ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract",
"2.5.0.RELEASE");
URI initilizrUri = VersionsFetcherTests.class.getResource("/raw/initializr.yml")
.toURI();
ReleaserProperties properties = new ReleaserProperties();
properties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
properties.getGit().setReleaseTrainBomUrl(
file("/projects/spring-cloud-release/").toURI().toString());
ProjectPomUpdater updater = new ProjectPomUpdater(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater);
boolean latestGa = versionsFetcher.isLatestGa(projectVersion);
BDDAssertions.then(latestGa).isTrue();
}
@Test
void should_return_false_when_current_version_is_not_the_latest_ga()
throws URISyntaxException {
ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract",
"1.0.0.RELEASE");
URI initilizrUri = VersionsFetcherTests.class.getResource("/raw/initializr.yml")
.toURI();
ReleaserProperties properties = new ReleaserProperties();
properties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
properties.getGit().setReleaseTrainBomUrl(
file("/projects/spring-cloud-release/").toURI().toString());
ProjectPomUpdater updater = new ProjectPomUpdater(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater);
boolean latestGa = versionsFetcher.isLatestGa(projectVersion);
BDDAssertions.then(latestGa).isTrue();
}
@Test
void should_return_false_when_current_version_is_not_present_in_the_bom()
throws URISyntaxException {
ProjectVersion projectVersion = new ProjectVersion("spring-cloud-non-existant",
"1.0.0.RELEASE");
URI initilizrUri = VersionsFetcherTests.class.getResource("/raw/initializr.yml")
.toURI();
ReleaserProperties properties = new ReleaserProperties();
properties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
properties.getGit().setReleaseTrainBomUrl(
file("/projects/spring-cloud-release/").toURI().toString());
ProjectPomUpdater updater = new ProjectPomUpdater(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater);
boolean latestGa = versionsFetcher.isLatestGa(projectVersion);
BDDAssertions.then(latestGa).isFalse();
}
@Test
void should_return_false_when_current_version_is_not_ga() {
ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract",
"1.0.0.BUILD-SNAPSHOT");
ReleaserProperties properties = new ReleaserProperties();
ProjectPomUpdater updater = new ProjectPomUpdater(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater);
boolean latestGa = versionsFetcher.isLatestGa(projectVersion);
BDDAssertions.then(latestGa).isFalse();
}
private File file(String relativePath) throws URISyntaxException {
return new File(VersionsFetcherTests.class.getResource(relativePath).toURI());
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,7 @@ import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.sagan.SaganClient;
import org.springframework.cloud.release.internal.sagan.SaganUpdater;
import org.springframework.cloud.release.internal.template.TemplateGenerator;
import org.springframework.cloud.release.internal.versions.VersionsFetcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
@@ -55,8 +56,8 @@ class ReleaserConfiguration {
}
@Bean
ProjectBuilder projectBuilder() {
return new ProjectBuilder(this.properties);
ProjectBuilder projectBuilder(VersionsFetcher versionsFetcher) {
return new ProjectBuilder(this.properties, versionsFetcher);
}
@Bean
@@ -64,6 +65,11 @@ class ReleaserConfiguration {
return new ProjectPomUpdater(this.properties);
}
@Bean
VersionsFetcher versionsFetcher(ProjectPomUpdater updater) {
return new VersionsFetcher(this.properties, updater);
}
@Bean
ProjectGitHandler projectGitHandler() {
return new ProjectGitHandler(this.properties);

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.release.internal.spring;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -64,6 +65,7 @@ import org.springframework.cloud.release.internal.sagan.Release;
import org.springframework.cloud.release.internal.sagan.SaganClient;
import org.springframework.cloud.release.internal.sagan.SaganUpdater;
import org.springframework.cloud.release.internal.template.TemplateGenerator;
import org.springframework.cloud.release.internal.versions.VersionsFetcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.FileSystemUtils;
@@ -694,7 +696,8 @@ public class AcceptanceTests {
private Releaser defaultReleaser(String expectedVersion, String projectName,
ReleaserProperties properties) {
ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties);
ProjectBuilder projectBuilder = new ProjectBuilder(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, pomUpdater);
ProjectBuilder projectBuilder = new ProjectBuilder(properties, versionsFetcher);
TestProjectGitHandler handler = new TestProjectGitHandler(properties,
expectedVersion, projectName);
TemplateGenerator templateGenerator = new TemplateGenerator(properties, handler);
@@ -724,7 +727,8 @@ public class AcceptanceTests {
private Releaser defaultMetaReleaser(ReleaserProperties properties) {
ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties);
ProjectBuilder projectBuilder = new ProjectBuilder(properties);
VersionsFetcher versionsFetcher = new VersionsFetcher(properties, pomUpdater);
ProjectBuilder projectBuilder = new ProjectBuilder(properties, versionsFetcher);
NonAssertingTestProjectGitHandler handler = new NonAssertingTestProjectGitHandler(
properties);
TemplateGenerator templateGenerator = Mockito
@@ -781,6 +785,9 @@ public class AcceptanceTests {
.setSpringProjectUrl(tmpFile("spring-cloud").getAbsolutePath() + "/");
releaserProperties.getGit().setReleaseTrainWikiUrl(
tmpFile("spring-cloud-wiki").getAbsolutePath() + "/");
URI initilizrUri = AcceptanceTests.class.getResource("/raw/initializr.yml")
.toURI();
releaserProperties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
this.releaserProperties = releaserProperties;
return releaserProperties;
}
@@ -810,6 +817,9 @@ public class AcceptanceTests {
releaserProperties.getGit().setReleaseTrainWikiUrl(
tmpFile("spring-cloud-wiki").getAbsolutePath() + "/");
releaserProperties.setFixedVersions(versions);
URI initilizrUri = AcceptanceTests.class.getResource("/raw/initializr.yml")
.toURI();
releaserProperties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
this.releaserProperties = releaserProperties;
return releaserProperties;
}
@@ -821,6 +831,9 @@ public class AcceptanceTests {
file("/projects/spring-cloud-release-with-snapshot/").toURI().toString());
releaserProperties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
URI initilizrUri = AcceptanceTests.class.getResource("/raw/initializr.yml")
.toURI();
releaserProperties.getVersions().setAllVersionsFileUrl(initilizrUri.toString());
this.releaserProperties = releaserProperties;
return releaserProperties;
}

File diff suppressed because it is too large Load Diff