Introduces symlinks for current documentation

fixes gh-172
This commit is contained in:
Marcin Grzejszczak
2019-11-22 16:14:26 +01:00
parent e2d3cf0e2a
commit 5b23bdb399
7 changed files with 201 additions and 316 deletions

View File

@@ -18,18 +18,18 @@ package org.springframework.cloud.release.cloud.docs;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.docs.CustomProjectDocumentationUpdater;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.cloud.release.internal.project.ProjectVersion;
import org.springframework.cloud.release.internal.project.Projects;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
/**
@@ -38,21 +38,17 @@ import org.springframework.util.StringUtils;
class SpringCloudCustomProjectDocumentationUpdater
implements CustomProjectDocumentationUpdater {
private static final String HTTP_SC_STATIC_URL = "http://cloud.spring.io/spring-cloud-static/";
private static final String HTTPS_SC_STATIC_URL = "https://cloud.spring.io/spring-cloud-static/";
public static final String NO_PROJECT_NAME = "";
private byte[] indexHtmlTemplate;
private static final Logger log = LoggerFactory
.getLogger(SpringCloudCustomProjectDocumentationUpdater.class);
private final ProjectGitHandler gitHandler;
SpringCloudCustomProjectDocumentationUpdater(ProjectGitHandler gitHandler) {
private final ReleaserProperties releaserProperties;
SpringCloudCustomProjectDocumentationUpdater(ProjectGitHandler gitHandler,
ReleaserProperties releaserProperties) {
this.gitHandler = gitHandler;
this.releaserProperties = releaserProperties;
}
@Override
@@ -74,25 +70,30 @@ class SpringCloudCustomProjectDocumentationUpdater
public File updateDocsRepo(File clonedDocumentationProject,
ProjectVersion currentProject, Projects projects, String bomBranch) {
log.debug("Cloning the doc project to [{}]", clonedDocumentationProject);
String pathToIndexHtml = "current/index.html";
File indexHtml = indexHtmlWithRedirection(clonedDocumentationProject, "",
bomBranch, pathToIndexHtml);
File docsRepo = updateTheDocsRepo(NO_PROJECT_NAME, bomBranch,
clonedDocumentationProject, indexHtml);
ProjectVersion releaseTrainProject = new ProjectVersion(
this.releaserProperties.getMetaRelease().getReleaseTrainProjectName(),
branchToReleaseVersion(bomBranch));
File currentReleaseFolder = new File(clonedDocumentationProject, currentFolder(
releaseTrainProject.projectName, releaseTrainProject.version));
// remove the old way
removeAFolderWithRedirection(currentReleaseFolder);
File docsRepo = updateTheDocsRepo(releaseTrainProject, clonedDocumentationProject,
currentReleaseFolder);
log.info(
"Updating all current links to documentation for release train projects");
projects.forEach(projectVersion -> {
File index = indexHtmlWithRedirection(clonedDocumentationProject,
projectVersion.projectName, projectVersion.version, pathToIndexHtml);
File currentProjectReleaseFolder = new File(clonedDocumentationProject,
currentFolder(projectVersion.projectName, projectVersion.version));
removeAFolderWithRedirection(currentProjectReleaseFolder);
try {
updateTheDocsRepo(projectVersion.projectName, projectVersion.version,
clonedDocumentationProject, index);
log.info("Processed [{}] for project with name [{}]", index,
projectVersion.projectName);
updateTheDocsRepo(projectVersion, clonedDocumentationProject,
currentProjectReleaseFolder);
log.info("Processed [{}] for project with name [{}]",
currentProjectReleaseFolder, projectVersion.projectName);
}
catch (Exception ex) {
log.warn(
"Exception occurred while trying o update the index html of a project ["
"Exception occurred while trying o update the symlink of a project ["
+ projectVersion.projectName + "]",
ex);
}
@@ -100,55 +101,53 @@ class SpringCloudCustomProjectDocumentationUpdater
return pushChanges(docsRepo);
}
private File indexHtmlWithRedirection(File clonedDocumentationProject,
String projectName, String version, String pathToIndexHtml) {
File indexHtml = indexHtml(clonedDocumentationProject,
combinedPathToIndexHtml(projectName, version, pathToIndexHtml));
if (!indexHtml.exists()) {
return generateIndexHtml(projectName, version, pathToIndexHtml, indexHtml);
}
return indexHtml;
}
private File generateIndexHtml(String projectName, String projectVersion,
String pathToIndexHtml, File indexHtml) {
try {
log.info("No file [{}] found, will create one", indexHtml);
indexHtml.getParentFile().mkdirs();
indexHtml.createNewFile();
String newIndex = new String(indexHtmlTemplate()).replaceAll("\\{\\{URL}}",
"https://cloud.spring.io/spring-cloud-static/"
+ concreteVersionIndexHtml(projectName,
branchToReleaseVersion(projectVersion),
"index.html"));
Files.write(indexHtml.toPath(), newIndex.getBytes());
return indexHtml;
}
catch (IOException ex) {
throw new IllegalStateException(ex);
private void removeAFolderWithRedirection(File currentReleaseFolder) {
if (!isSymbolinkLink(currentReleaseFolder)) {
FileSystemUtils.deleteRecursively(currentReleaseFolder);
}
}
private String combinedPathToIndexHtml(String projectName, String projectVersion,
String pathToIndexHtml) {
private boolean isSymbolinkLink(File currentFolder) {
return Files.isSymbolicLink(currentFolder.toPath());
}
private String currentFolder(String projectName, String projectVersion) {
boolean releaseTrain = new ProjectVersion(projectName, projectVersion)
.isReleaseTrain();
// release train -> static/current/index.html
// project -> static/spring-cloud-sleuth/current/index.html
String prefix = releaseTrain ? ""
: (StringUtils.hasText(projectName) ? projectName : "") + "/";
return prefix + pathToIndexHtml;
// release train -> static/current
// project -> static/spring-cloud-sleuth/current
return releaseTrain ? "current"
: (StringUtils.hasText(projectName) ? projectName : "") + "/current";
}
private String concreteVersionIndexHtml(String projectName, String projectVersion,
String pathToIndexHtml) {
boolean releaseTrain = new ProjectVersion(projectName, projectVersion)
.isReleaseTrain();
// release train -> static/current/index.html
// project -> static/spring-cloud-sleuth/current/index.html
String prefix = releaseTrain ? projectVersion
: (projectName + "/" + projectVersion);
return prefix + "/" + pathToIndexHtml;
String linkToVersion(File file) {
if (Files.isSymbolicLink(file.toPath())) {
try {
Path path = Files.readSymbolicLink(file.toPath());
// current -> Hoxton.SR2
// spring-cloud-sleuth/current -> spring-cloud-sleuth/1.2.3.RELEASE
return folderName(path.toString());
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
return "";
}
private String folderName(String path) {
int last = path.lastIndexOf(File.separator);
return last > 0 ? path.substring(last + 1) : path;
}
private String concreteVersionFolder(ProjectVersion projectVersion) {
String projectName = projectVersion.projectName;
boolean releaseTrain = projectVersion.isReleaseTrain();
// release train -> static/Hoxton.SR2/
// project -> static/spring-cloud-sleuth/1.2.3.RELEASE/
String prefix = releaseTrain ? projectVersion.version
: (projectName + "/" + projectVersion.version);
return prefix + "/";
}
private File pushChanges(File docsRepo) {
@@ -157,93 +156,60 @@ class SpringCloudCustomProjectDocumentationUpdater
return docsRepo;
}
File indexHtml(File clonedDocumentationProject, String pathToIndexHtml) {
return new File(clonedDocumentationProject, pathToIndexHtml);
}
private File updateTheDocsRepo(String projectName, String version,
File documentationProject, File indexHtml) {
private File updateTheDocsRepo(ProjectVersion projectVersion,
File documentationProject, File currentVersionFolder) {
try {
String indexHtmlText = readIndexHtmlContents(indexHtml);
String httpSubstring = HTTP_SC_STATIC_URL
+ (StringUtils.hasText(projectName) ? (projectName + "/") : "");
String httpsSubstring = HTTPS_SC_STATIC_URL
+ (StringUtils.hasText(projectName) ? (projectName + "/") : "");
int httpIndex = indexHtmlText.indexOf(httpSubstring);
int httpsIndex = indexHtmlText.indexOf(httpsSubstring);
if (httpIndex == -1 && httpsIndex == -1) {
throw new IllegalStateException(
"The URL to the documentation repo not found in the index.html file");
}
int beginIndex = beginIndex(httpIndex, httpSubstring, httpsIndex,
httpsSubstring);
String storedVersionLine = indexHtmlText.substring(beginIndex);
String storedVersion = storedVersionLine.substring(0,
storedVersionLine.indexOf("/"));
String currentVersion = branchToReleaseVersion(version);
boolean newerVersion = isMoreMature(storedVersion, currentVersion);
String storedVersion = linkToVersion(currentVersionFolder);
String currentVersion = projectVersion.version;
boolean newerVersion = StringUtils.isEmpty(storedVersion)
|| isMoreMature(storedVersion, currentVersion);
if (!newerVersion) {
log.info("Current version [{}] is not newer than the stored one [{}]",
currentVersion, storedVersion);
return documentationProject;
}
return commitChanges(currentVersion, documentationProject, indexHtml,
indexHtmlText, storedVersion);
boolean deleted = Files.deleteIfExists(currentVersionFolder.toPath())
|| FileSystemUtils.deleteRecursively(currentVersionFolder.toPath());
if (deleted) {
log.info("Deleted current version folder link at [{}]",
currentVersionFolder);
}
boolean creatingParentDirs = currentVersionFolder.getParentFile().mkdirs();
if (!creatingParentDirs) {
log.warn("Failed to create parent directory of [{}]",
currentVersionFolder);
}
File newTarget = new File(documentationProject,
concreteVersionFolder(projectVersion));
Files.createSymbolicLink(currentVersionFolder.toPath(), newTarget.toPath());
log.info("Updated the link [{}] to point to [{}]",
currentVersionFolder.toPath(),
Files.readSymbolicLink(currentVersionFolder.toPath()));
return commitChanges(currentVersion, documentationProject);
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
boolean isMoreMature(String storedVersion, String currentVersion) {
private boolean isMoreMature(String storedVersion, String currentVersion) {
return new ProjectVersion("project", currentVersion)
.isMoreMature(new ProjectVersion("project", storedVersion));
}
private int beginIndex(int httpIndex, String httpSubstring, int httpsIndex,
String httpsSubstring) {
if (httpIndex != -1) {
return httpIndex + httpSubstring.length();
private String branchToReleaseVersion(String branch) {
if (branch.startsWith("v")) {
return branch.substring(1);
}
return httpsIndex + httpsSubstring.length();
return branch;
}
private String branchToReleaseVersion(String springCloudReleaseBranch) {
if (springCloudReleaseBranch.startsWith("v")) {
return springCloudReleaseBranch.substring(1);
}
return springCloudReleaseBranch;
}
private File commitChanges(String currentVersion, File documentationProject,
File indexHtml, String indexHtmlText, String storedReleaseTrain)
private File commitChanges(String currentVersion, File documentationProject)
throws IOException {
String replacedIndexHtml = indexHtmlText.replace(storedReleaseTrain,
currentVersion);
Files.write(indexHtml.toPath(), replacedIndexHtml.getBytes());
log.info("Stored the version URL [{}] in [{}]", currentVersion,
indexHtml.getAbsolutePath());
log.info("Updated the symbolic links");
this.gitHandler.commit(documentationProject,
"Updating the link to the current version to [" + currentVersion + "]");
return documentationProject;
}
String readIndexHtmlContents(File indexHtml) throws IOException {
return new String(Files.readAllBytes(indexHtml.toPath()));
}
private byte[] indexHtmlTemplate() {
if (this.indexHtmlTemplate == null) {
try {
URI uri = CustomProjectDocumentationUpdater.class
.getResource("/cloud/index.html").toURI();
this.indexHtmlTemplate = IOUtils.toByteArray(uri);
}
catch (URISyntaxException | IOException ex) {
throw new IllegalStateException(ex);
}
}
return this.indexHtmlTemplate;
}
}

View File

@@ -1,29 +0,0 @@
<!--
~ 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.
-->
<!DOCTYPE HTML>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1; url={{URL}}">
<script>
window.location.href = "{{URL}}"
</script>
<title>Page Redirection</title>
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow the <a href='{{URL}}'>link to latest release</a>

View File

@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import javax.validation.constraints.NotNull;
@@ -80,60 +81,10 @@ public class SpringCloudCustomProjectDocumentationUpdaterTests {
SpringCloudGithubIssuesAccessor.springCloud(this.properties)));
}
@Test
public void should_generate_a_new_index_html_when_original_one_is_not_found()
throws URISyntaxException, IOException {
ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-release",
"Hoxton.SR10");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationBranch("master");
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-release/").toURI().toString());
File updatedDocs = projectDocumentationUpdaterWithNoIndexHtml(properties)
.updateDocsRepo(projects(), releaseTrainVersion, "vHoxton.SR10");
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.contains("cloud.spring.io/spring-cloud-static/Hoxton.SR10/");
String sleuthIndexHtmlContent = new String(Files.readAllBytes(
new File(updatedDocs, "spring-cloud-sleuth/current/index.html")
.toPath()));
then(sleuthIndexHtmlContent).contains(
"cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/1.0.0.RELEASE/");
}
@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");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
SpringCloudCustomProjectDocumentationUpdater customUpdater = new SpringCloudCustomProjectDocumentationUpdater(
new ProjectGitHandler(properties)) {
@Override
String readIndexHtmlContents(File indexHtml) {
return "";
}
};
BDDAssertions
.thenThrownBy(() -> new DocumentationUpdater(this.handler, properties,
templateGenerator(properties),
Collections.singletonList(customUpdater)).updateDocsRepo(
projects(), 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-release",
"Angel.M7");
ReleaserProperties properties = new ReleaserProperties();
File updatedDocs = projectDocumentationUpdater(properties)
@@ -146,30 +97,10 @@ public class SpringCloudCustomProjectDocumentationUpdaterTests {
private DocumentationUpdater projectDocumentationUpdater(
ReleaserProperties properties) {
return new DocumentationUpdater(this.handler, properties,
templateGenerator(properties), Collections.singletonList(
new SpringCloudCustomProjectDocumentationUpdater(this.handler) {
@Override
boolean isMoreMature(String first, String second) {
return true;
}
}));
}
@NotNull
private DocumentationUpdater projectDocumentationUpdaterWithNoIndexHtml(
ReleaserProperties properties) {
return new DocumentationUpdater(this.handler, properties,
templateGenerator(properties), Collections.singletonList(
new SpringCloudCustomProjectDocumentationUpdater(this.handler) {
@Override
File indexHtml(File clonedDocumentationProject,
String pathToIndexHtml) {
File file = super.indexHtml(clonedDocumentationProject,
pathToIndexHtml);
file.delete();
return file;
}
}));
templateGenerator(properties),
Collections.singletonList(
new SpringCloudCustomProjectDocumentationUpdater(this.handler,
properties)));
}
@NotNull
@@ -177,40 +108,56 @@ public class SpringCloudCustomProjectDocumentationUpdaterTests {
return new TemplateGenerator(properties, this.gitHubHandler);
}
@NotNull
private ProjectGitHandler projectGitHandler(ReleaserProperties properties) {
return new ProjectGitHandler(properties);
}
@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-release",
"Finchley.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
File updatedDocs = new SpringCloudCustomProjectDocumentationUpdater(
new ProjectGitHandler(properties)).updateDocsRepo(this.clonedDocProject,
releaseTrainVersion, projects(), "vAngel.SR33");
new ProjectGitHandler(properties), properties).updateDocsRepo(
this.clonedDocProject, releaseTrainVersion, projects(),
"vFinchley.SR33");
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent).doesNotContain(
"https://cloud.spring.io/spring-cloud-static/Angel.SR33/");
BDDAssertions.then(new File(updatedDocs, "current/index.html").toPath())
.doesNotExist();
Path current = new File(updatedDocs, "current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.endsWith("Finchley.SR33");
releaseTrainVersion = new ProjectVersion("spring-cloud-release", "Angel.SR33");
properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(
file("/projects/spring-cloud-static/").toURI().toString());
updatedDocs = new SpringCloudCustomProjectDocumentationUpdater(
new ProjectGitHandler(properties), properties).updateDocsRepo(
this.clonedDocProject, releaseTrainVersion, projects(),
"vAngel.SR33");
BDDAssertions.then(new File(updatedDocs, "current/index.html").toPath())
.doesNotExist();
current = new File(updatedDocs, "current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.doesNotEndWith("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-release",
"Dalston.SR3");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
ProjectGitHandler handler = BDDMockito.spy(new ProjectGitHandler(properties));
new SpringCloudCustomProjectDocumentationUpdater(handler).updateDocsRepo(
this.clonedDocProject, releaseTrainVersion, projects(), "vDalston.SR3");
new SpringCloudCustomProjectDocumentationUpdater(handler, properties)
.updateDocsRepo(this.clonedDocProject, releaseTrainVersion, projects(),
"vDalston.SR3");
BDDMockito.then(handler).should(BDDMockito.never())
.commit(BDDMockito.any(File.class), BDDMockito.anyString());
@@ -219,59 +166,75 @@ public class SpringCloudCustomProjectDocumentationUpdaterTests {
@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-release",
"Angel.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = new SpringCloudCustomProjectDocumentationUpdater(
new ProjectGitHandler(properties)).updateDocsRepo(this.clonedDocProject,
releaseTrainVersion, projects(), "Angel.SR33");
new ProjectGitHandler(properties), properties).updateDocsRepo(
this.clonedDocProject, releaseTrainVersion, projects(),
"Angel.SR33");
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent).doesNotContain(
"https://cloud.spring.io/spring-cloud-static/Angel.SR33/");
BDDAssertions.then(new File(updatedDocs, "current/index.html").toPath())
.doesNotExist();
Path current = new File(updatedDocs, "current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.doesNotEndWith("Angel.SR33");
}
@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-release",
"Finchley.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = projectDocumentationUpdater(properties)
.updateDocsRepo(projects(), releaseTrainVersion, "vFinchley.SR33");
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.contains("cloud.spring.io/spring-cloud-static/Finchley.SR33/");
BDDAssertions.then(new File(updatedDocs, "current/index.html").toPath())
.doesNotExist();
Path current = new File(updatedDocs, "current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.endsWith("spring-cloud-static/Finchley.SR33");
}
@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-release",
"Finchley.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
File updatedDocs = projectDocumentationUpdater(properties)
.updateDocsRepo(projects(), releaseTrainVersion, "Finchley.SR33");
File updatedDocs = projectDocumentationUpdater(properties).updateDocsRepo(
new Projects(new ProjectVersion("spring-cloud-sleuth", "2.0.0.RELEASE")),
releaseTrainVersion, "vFinchley.SR33");
String indexHtmlContent = new String(
Files.readAllBytes(new File(updatedDocs, "current/index.html").toPath()));
then(indexHtmlContent)
.contains("cloud.spring.io/spring-cloud-static/Finchley.SR33/");
BDDAssertions.then(new File(updatedDocs, "current/index.html").toPath())
.doesNotExist();
Path current = new File(updatedDocs, "current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.endsWith("spring-cloud-static/Finchley.SR33");
BDDAssertions.then(
new File(updatedDocs, "spring-cloud-sleuth/current/index.html").toPath())
.doesNotExist();
current = new File(updatedDocs, "spring-cloud-sleuth/current/").toPath();
BDDAssertions.then(current).isSymbolicLink();
BDDAssertions.then(Files.readSymbolicLink(current).toString())
.endsWith("spring-cloud-static/spring-cloud-sleuth/2.0.0.RELEASE");
}
@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-release",
"Finchley.SR33");
ReleaserProperties properties = new ReleaserProperties();
properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString());
properties.getGit().setUpdateDocumentationRepo(false);

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.release.cloud.docs;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -25,8 +26,9 @@ class SpringCloudDocsConfiguration {
@Bean
SpringCloudCustomProjectDocumentationUpdater springCloudCustomProjectDocumentationUpdater(
ProjectGitHandler handler) {
return new SpringCloudCustomProjectDocumentationUpdater(handler);
ProjectGitHandler handler, ReleaserProperties releaserProperties) {
return new SpringCloudCustomProjectDocumentationUpdater(handler,
releaserProperties);
}
}

View File

@@ -16,49 +16,23 @@
package org.springframework.cloud.release.cloud.docs;
import java.io.File;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.docs.CustomProjectDocumentationUpdater;
import org.springframework.cloud.release.internal.git.ProjectGitHandler;
public class SpringCloudDocsAccessor {
public static CustomProjectDocumentationUpdater updater(ProjectGitHandler handler) {
return new SpringCloudCustomProjectDocumentationUpdater(handler);
public static CustomProjectDocumentationUpdater updater(ProjectGitHandler handler,
ReleaserProperties releaserProperties) {
return new SpringCloudCustomProjectDocumentationUpdater(handler,
releaserProperties);
}
public static CustomProjectDocumentationUpdater testUpdater(ProjectGitHandler handler,
String version) {
return new TestCustomProjectDocumentationUpdater(handler, version);
}
}
class TestCustomProjectDocumentationUpdater
extends SpringCloudCustomProjectDocumentationUpdater {
private final String version;
TestCustomProjectDocumentationUpdater(ProjectGitHandler gitHandler, String version) {
super(gitHandler);
this.version = version;
}
@Override
String readIndexHtmlContents(File indexHtml) {
return response();
}
private String response() {
return "<!DOCTYPE HTML>\n" + "\n" + "<meta charset=\"UTF-8\">\n"
+ "<meta http-equiv=\"refresh\" content=\"1; url=https://cloud.spring.io/spring-cloud-static/"
+ this.version + "/\">\n" + "\n" + "<script>\n"
+ " window.location.href = \"https://cloud.spring.io/spring-cloud-static/"
+ this.version + "/\"\n" + "</script>\n" + "\n"
+ "<title>Page Redirection</title>\n" + "\n"
+ "<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->\n"
+ "If you are not redirected automatically, follow the <a href='https://cloud.spring.io/spring-cloud-static/"
+ this.version + "/'>link to latest release</a>\n";
ReleaserProperties releaserProperties = new ReleaserProperties();
return new SpringCloudCustomProjectDocumentationUpdater(handler,
releaserProperties);
}
}

View File

@@ -242,8 +242,13 @@ public class AcceptanceTests {
"2.1.2.BUILD-SNAPSHOT");
then(this.gitHandler.issueCreatedInSpringGuides).isTrue();
then(this.gitHandler.issueCreatedInStartSpringIo).isTrue();
then(text(new File(this.documentationFolder, "current/index.html")))
.doesNotContain("Angel.SR3").contains("Greenwich.SR2");
then(Files.readSymbolicLink(
new File(this.documentationFolder, "spring-cloud-consul/current")
.toPath())
.toString()).endsWith("5.3.5.RELEASE");
then(Files
.readSymbolicLink(new File(this.documentationFolder, "current").toPath())
.toString()).endsWith("Xitmars.SR4");
thenRunUpdatedTestsWereCalled();
}
@@ -515,8 +520,12 @@ public class AcceptanceTests {
"2.1.6.BUILD-SNAPSHOT");
then(this.gitHandler.issueCreatedInSpringGuides).isTrue();
then(this.gitHandler.issueCreatedInStartSpringIo).isTrue();
then(text(new File(this.documentationFolder, "current/index.html")))
.doesNotContain("Angel.SR3").contains("Greenwich.SR2");
then(Files.readSymbolicLink(
new File(this.documentationFolder, "spring-cloud-build/current").toPath())
.toString()).endsWith("5.3.11.RELEASE");
then(Files
.readSymbolicLink(new File(this.documentationFolder, "current").toPath())
.toString()).endsWith("Xitmars.SR4");
}
@Test