Reformat:
This commit is contained in:
@@ -53,12 +53,9 @@ class ArtifactFetcher {
|
||||
File outputZip = new File(downloadedZipsFolder, projectName + ".zip");
|
||||
for (String url : urls) {
|
||||
try {
|
||||
info(projectName + ": Fetching sources from [" + url
|
||||
+ "]. Please wait...");
|
||||
FileUtils.copyURLToFile(new URL(url), outputZip, CONNECT_TIMEOUT,
|
||||
READ_TIMEOUT);
|
||||
info(projectName + ": Successfully fetched a zip from [" + url + "] to ["
|
||||
+ outputZip + "]");
|
||||
info(projectName + ": Fetching sources from [" + url + "]. Please wait...");
|
||||
FileUtils.copyURLToFile(new URL(url), outputZip, CONNECT_TIMEOUT, READ_TIMEOUT);
|
||||
info(projectName + ": Successfully fetched a zip from [" + url + "] to [" + outputZip + "]");
|
||||
break;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -66,9 +63,8 @@ class ArtifactFetcher {
|
||||
}
|
||||
}
|
||||
if (!outputZip.exists()) {
|
||||
error(projectName
|
||||
+ ": Exception occurred while trying to download an artifact with name ["
|
||||
+ projectName + "] and version [" + version + "]");
|
||||
error(projectName + ": Exception occurred while trying to download an artifact with name [" + projectName
|
||||
+ "] and version [" + version + "]");
|
||||
return null;
|
||||
}
|
||||
return unpackDocs(projectName, outputZip);
|
||||
@@ -105,8 +101,7 @@ class ArtifactFetcher {
|
||||
if (releaseType == ReleaseType.SNAPSHOT) {
|
||||
// 2.0.0-SNAPSHOT or 2.0.0-BUILD-SNAPSHOT -> 2.0.x
|
||||
String[] splitVersion = version.split("\\.");
|
||||
sourcesUrls
|
||||
.add(sourcesUrl + splitVersion[0] + "." + splitVersion[1] + ".x.zip");
|
||||
sourcesUrls.add(sourcesUrl + splitVersion[0] + "." + splitVersion[1] + ".x.zip");
|
||||
// fallback
|
||||
sourcesUrls.add(sourcesUrl + "master.zip");
|
||||
}
|
||||
|
||||
@@ -28,31 +28,25 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
class ConfigurationPropertiesAggregator {
|
||||
|
||||
private static final List<String> wordsToIgnore = Arrays.asList("|===",
|
||||
"|Name | Default | Description");
|
||||
private static final List<String> wordsToIgnore = Arrays.asList("|===", "|Name | Default | Description");
|
||||
|
||||
List<ConfigurationProperty> mergedConfigurationProperties(Path unpackedDocs) {
|
||||
try {
|
||||
return Files.walk(unpackedDocs)
|
||||
.filter(path -> path.endsWith("_configprops.adoc")).flatMap(path -> {
|
||||
try {
|
||||
return Files.readAllLines(path).stream()
|
||||
.filter(s -> !StringUtils.isEmpty(s)
|
||||
&& !wordsToIgnore.contains(s))
|
||||
.map(s -> {
|
||||
// |foo|bar|baz -> foo|bar|baz -> split ->
|
||||
// foo,bar,baz
|
||||
String[] strings = s.substring(1).split("\\|");
|
||||
return new ConfigurationProperty(
|
||||
strings[0].trim(), strings[1].trim(),
|
||||
strings[2].trim());
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}).sorted(Comparator.comparing(o -> o.name))
|
||||
.collect(Collectors.toList());
|
||||
return Files.walk(unpackedDocs).filter(path -> path.endsWith("_configprops.adoc")).flatMap(path -> {
|
||||
try {
|
||||
return Files.readAllLines(path).stream()
|
||||
.filter(s -> !StringUtils.isEmpty(s) && !wordsToIgnore.contains(s)).map(s -> {
|
||||
// |foo|bar|baz -> foo|bar|baz -> split ->
|
||||
// foo,bar,baz
|
||||
String[] strings = s.substring(1).split("\\|");
|
||||
return new ConfigurationProperty(strings[0].trim(), strings[1].trim(),
|
||||
strings[2].trim());
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}).sorted(Comparator.comparing(o -> o.name)).collect(Collectors.toList());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -41,8 +41,7 @@ class ConfigurationProperty {
|
||||
return false;
|
||||
}
|
||||
ConfigurationProperty that = (ConfigurationProperty) o;
|
||||
return Objects.equals(name, that.name)
|
||||
&& Objects.equals(description, that.description)
|
||||
return Objects.equals(name, that.name) && Objects.equals(description, that.description)
|
||||
&& Objects.equals(defaultValue, that.defaultValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,25 +42,21 @@ public class GenerateReleaseTrainDocs {
|
||||
String repoUrl = args[2];
|
||||
File unzippedDocs = new File(args[3]);
|
||||
File generatedTrainDocs = new File(args[4]);
|
||||
new GenerateReleaseTrainDocs().generate(bomPath, starterParentPath, repoUrl,
|
||||
unzippedDocs, generatedTrainDocs);
|
||||
new GenerateReleaseTrainDocs().generate(bomPath, starterParentPath, repoUrl, unzippedDocs, generatedTrainDocs);
|
||||
}
|
||||
|
||||
GenerateReleaseTrainDocs() {
|
||||
this.service = Executors.newFixedThreadPool(4);
|
||||
}
|
||||
|
||||
void generate(File bomPath, File starterParentPath, String repoUrl, File unzippedDocs,
|
||||
File generatedTrainDocs) {
|
||||
void generate(File bomPath, File starterParentPath, String repoUrl, File unzippedDocs, File generatedTrainDocs) {
|
||||
List<Project> projects = mavenPropertiesToDocsProjects(bomPath);
|
||||
info("Found the following projects [" + projects + "]");
|
||||
List<File> outputFolders = downloadSources(unzippedDocs, projects, repoUrl);
|
||||
projects.add(springBootVersion(starterParentPath));
|
||||
projects.sort(Comparator.comparing(o -> o.name));
|
||||
List<ConfigurationProperty> configurationProperties = mergeConfigurationProperties(
|
||||
unzippedDocs);
|
||||
File file = renderAsciidocTemplates(generatedTrainDocs, projects,
|
||||
configurationProperties);
|
||||
List<ConfigurationProperty> configurationProperties = mergeConfigurationProperties(unzippedDocs);
|
||||
File file = renderAsciidocTemplates(generatedTrainDocs, projects, configurationProperties);
|
||||
info("Rendered docs templates to [" + file + "]");
|
||||
new ResourcesCopier().copy(outputFolders, file);
|
||||
}
|
||||
@@ -68,10 +64,8 @@ public class GenerateReleaseTrainDocs {
|
||||
List<Project> mavenPropertiesToDocsProjects(File file) {
|
||||
Model model = PomReader.readPom(file);
|
||||
Properties properties = model.getProperties();
|
||||
return properties.entrySet().stream()
|
||||
.filter(e -> e.getKey().toString().endsWith(".version"))
|
||||
.map(e -> new Project(e.getKey().toString().replace(".version", ""),
|
||||
e.getValue().toString()))
|
||||
return properties.entrySet().stream().filter(e -> e.getKey().toString().endsWith(".version"))
|
||||
.map(e -> new Project(e.getKey().toString().replace(".version", ""), e.getValue().toString()))
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
}
|
||||
|
||||
@@ -80,8 +74,7 @@ public class GenerateReleaseTrainDocs {
|
||||
return new Project("spring-boot", model.getParent().getVersion());
|
||||
}
|
||||
|
||||
List<File> downloadSources(File outputFolder, List<Project> projects,
|
||||
String repoUrl) {
|
||||
List<File> downloadSources(File outputFolder, List<Project> projects, String repoUrl) {
|
||||
ArtifactFetcher fetcher = new ArtifactFetcher(outputFolder, repoUrl);
|
||||
try {
|
||||
List<Future<File>> futures = new LinkedList<>();
|
||||
|
||||
@@ -34,8 +34,7 @@ final class HandlebarsHelper {
|
||||
|
||||
public static Template template(String templateName) {
|
||||
try {
|
||||
Handlebars handlebars = new Handlebars(
|
||||
new ClassPathTemplateLoader("/templates/spring-cloud/"));
|
||||
Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader("/templates/spring-cloud/"));
|
||||
handlebars.registerHelper("replace", StringHelpers.replace);
|
||||
handlebars.registerHelper("capitalizeFirst", StringHelpers.capitalizeFirst);
|
||||
return handlebars.compile(templateName);
|
||||
|
||||
@@ -44,8 +44,7 @@ final class PomReader {
|
||||
*/
|
||||
public static Model readPom(File pom) {
|
||||
if (!pom.exists()) {
|
||||
throw new IllegalStateException(
|
||||
"File [" + pom.getAbsolutePath() + "] not found");
|
||||
throw new IllegalStateException("File [" + pom.getAbsolutePath() + "] not found");
|
||||
}
|
||||
String fileText = "";
|
||||
try (Reader reader = new FileReader(pom)) {
|
||||
@@ -57,11 +56,9 @@ final class PomReader {
|
||||
}
|
||||
catch (XmlPullParserException | IOException e) {
|
||||
if (pom.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ class Project {
|
||||
return false;
|
||||
}
|
||||
Project project = (Project) o;
|
||||
return Objects.equals(name, project.name)
|
||||
&& Objects.equals(version, project.version);
|
||||
return Objects.equals(name, project.name) && Objects.equals(version, project.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,8 +56,7 @@ class Project {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Project{" + "name='" + this.name + '\'' + ", version='" + this.version
|
||||
+ '\'' + '}';
|
||||
return "Project{" + "name='" + this.name + '\'' + ", version='" + this.version + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,12 +44,10 @@ class TemplateGenerator {
|
||||
this.outputFolder.mkdirs();
|
||||
}
|
||||
|
||||
File generate(List<Project> projects,
|
||||
List<ConfigurationProperty> configurationProperties) {
|
||||
File generate(List<Project> projects, List<ConfigurationProperty> configurationProperties) {
|
||||
PathMatchingResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
|
||||
try {
|
||||
Resource[] resources = resourceLoader
|
||||
.getResources("templates/spring-cloud/*.hbs");
|
||||
Resource[] resources = resourceLoader.getResources("templates/spring-cloud/*.hbs");
|
||||
List<TemplateProject> templateProjects = templateProjects(projects);
|
||||
for (Resource resource : resources) {
|
||||
File templateFile = resource.getFile();
|
||||
@@ -71,18 +69,14 @@ class TemplateGenerator {
|
||||
}
|
||||
|
||||
private List<TemplateProject> templateProjects(List<Project> projects) {
|
||||
return projects.stream()
|
||||
.filter(project -> project.name.startsWith("spring-cloud-"))
|
||||
.map(project -> {
|
||||
if (project.name.contains("spring-cloud-task")) {
|
||||
return new TemplateProject(project.name, project.version,
|
||||
"{basedir}/" + project.name
|
||||
+ "/spring-cloud-task-docs/src/main/asciidoc/index.adoc[leveloffset=+1]");
|
||||
}
|
||||
return new TemplateProject(project.name, project.version,
|
||||
"{basedir}/" + project.name + "/docs/src/main/asciidoc/"
|
||||
+ project.name + ".adoc[leveloffset=+1]");
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
return projects.stream().filter(project -> project.name.startsWith("spring-cloud-")).map(project -> {
|
||||
if (project.name.contains("spring-cloud-task")) {
|
||||
return new TemplateProject(project.name, project.version, "{basedir}/" + project.name
|
||||
+ "/spring-cloud-task-docs/src/main/asciidoc/index.adoc[leveloffset=+1]");
|
||||
}
|
||||
return new TemplateProject(project.name, project.version,
|
||||
"{basedir}/" + project.name + "/docs/src/main/asciidoc/" + project.name + ".adoc[leveloffset=+1]");
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
}
|
||||
|
||||
private String renameTemplate(File templateFile) {
|
||||
|
||||
@@ -63,8 +63,7 @@ final class ZipCategory {
|
||||
List<File> unzippedFiles = new ArrayList<>();
|
||||
try (InputStream fileInputStream = Files.newInputStream(self.toPath())) {
|
||||
try (ZipInputStream zipInput = new ZipInputStream(fileInputStream)) {
|
||||
for (ZipEntry entry = zipInput
|
||||
.getNextEntry(); entry != null; entry = zipInput.getNextEntry()) {
|
||||
for (ZipEntry entry = zipInput.getNextEntry(); entry != null; entry = zipInput.getNextEntry()) {
|
||||
if (!entry.isDirectory()) {
|
||||
final File file = new File(destination, entry.getName());
|
||||
if (file.getParentFile() != null) {
|
||||
|
||||
@@ -32,34 +32,26 @@ public class GenerateReleaseTrainDocsTests {
|
||||
|
||||
@Test
|
||||
void should_return_a_list_of_docs_modules_to_download() throws URISyntaxException {
|
||||
File testPom = new File(
|
||||
GenerateReleaseTrainDocsTests.class.getResource("/test/pom.xml").toURI());
|
||||
File testPom = new File(GenerateReleaseTrainDocsTests.class.getResource("/test/pom.xml").toURI());
|
||||
|
||||
List<Project> projects = new GenerateReleaseTrainDocs()
|
||||
.mavenPropertiesToDocsProjects(testPom);
|
||||
List<Project> projects = new GenerateReleaseTrainDocs().mavenPropertiesToDocsProjects(testPom);
|
||||
|
||||
BDDAssertions.then(projects).extracting("name").containsOnly("spring-cloud-bus",
|
||||
"spring-cloud-build", "spring-cloud-cloudfoundry", "spring-cloud-commons",
|
||||
"spring-cloud-circuitbreaker", "spring-cloud-config",
|
||||
"spring-cloud-consul", "spring-cloud-contract", "spring-cloud-function",
|
||||
"spring-cloud-gateway", "spring-cloud-kubernetes", "spring-cloud-netflix",
|
||||
"spring-cloud-openfeign", "spring-cloud-security", "spring-cloud-sleuth",
|
||||
"spring-cloud-stream", "spring-cloud-task", "spring-cloud-vault",
|
||||
"spring-cloud-zookeeper", "spring-cloud-cli");
|
||||
BDDAssertions.then(projects)
|
||||
.contains(new Project("spring-cloud-bus", "1.2.3-SNAPSHOT"));
|
||||
BDDAssertions.then(projects).extracting("name").containsOnly("spring-cloud-bus", "spring-cloud-build",
|
||||
"spring-cloud-cloudfoundry", "spring-cloud-commons", "spring-cloud-circuitbreaker",
|
||||
"spring-cloud-config", "spring-cloud-consul", "spring-cloud-contract", "spring-cloud-function",
|
||||
"spring-cloud-gateway", "spring-cloud-kubernetes", "spring-cloud-netflix", "spring-cloud-openfeign",
|
||||
"spring-cloud-security", "spring-cloud-sleuth", "spring-cloud-stream", "spring-cloud-task",
|
||||
"spring-cloud-vault", "spring-cloud-zookeeper", "spring-cloud-cli");
|
||||
BDDAssertions.then(projects).contains(new Project("spring-cloud-bus", "1.2.3-SNAPSHOT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_unpack_starters_docs() throws URISyntaxException {
|
||||
File testPom = new File(GenerateReleaseTrainDocsTests.class
|
||||
.getResource("/test/sleuth-only.xml").toURI());
|
||||
File testPom = new File(GenerateReleaseTrainDocsTests.class.getResource("/test/sleuth-only.xml").toURI());
|
||||
File unzippedDocs = new File("target/test-unpacked-docs/");
|
||||
List<Project> projects = new GenerateReleaseTrainDocs()
|
||||
.mavenPropertiesToDocsProjects(testPom);
|
||||
List<Project> projects = new GenerateReleaseTrainDocs().mavenPropertiesToDocsProjects(testPom);
|
||||
|
||||
new GenerateReleaseTrainDocs().downloadSources(unzippedDocs, projects,
|
||||
"https://github.com/spring-cloud/");
|
||||
new GenerateReleaseTrainDocs().downloadSources(unzippedDocs, projects, "https://github.com/spring-cloud/");
|
||||
|
||||
BDDAssertions.then(unzippedDocs).isNotEmptyDirectory();
|
||||
}
|
||||
@@ -69,43 +61,35 @@ public class GenerateReleaseTrainDocsTests {
|
||||
File file = new File("target/test-train-docs");
|
||||
FileSystemUtils.deleteRecursively(file);
|
||||
List<Project> projects = Arrays.asList(new Project("spring-cloud-foo", "1.0.0"),
|
||||
new Project("spring-cloud-bar", "2.0.0"),
|
||||
new Project("spring-boot", "3.0.0"),
|
||||
new Project("spring-cloud-bar", "2.0.0"), new Project("spring-boot", "3.0.0"),
|
||||
new Project("spring-cloud", "4.0.0"));
|
||||
List<ConfigurationProperty> configurationProperties = Arrays.asList(
|
||||
new ConfigurationProperty("first", "firstDefault", "firstDescription"),
|
||||
new ConfigurationProperty("second", "secondDefault",
|
||||
"secondDescription"));
|
||||
new ConfigurationProperty("second", "secondDefault", "secondDescription"));
|
||||
|
||||
File outputFolder = new TemplateGenerator(file).generate(projects,
|
||||
configurationProperties);
|
||||
File outputFolder = new TemplateGenerator(file).generate(projects, configurationProperties);
|
||||
|
||||
BDDAssertions.then(outputFolder).isNotEmptyDirectory();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_generate_adocs_from_spring_cloud_sleuth_docs()
|
||||
throws URISyntaxException, IOException {
|
||||
void should_generate_adocs_from_spring_cloud_sleuth_docs() throws URISyntaxException, IOException {
|
||||
File generatedAdocs = new File("target/test-train-sleuth-docs");
|
||||
FileSystemUtils.deleteRecursively(generatedAdocs);
|
||||
File testPom = new File(GenerateReleaseTrainDocsTests.class
|
||||
.getResource("/test/sleuth-only.xml").toURI());
|
||||
File starterPom = new File(GenerateReleaseTrainDocsTests.class
|
||||
.getResource("/test/starter-pom.xml").toURI());
|
||||
File testPom = new File(GenerateReleaseTrainDocsTests.class.getResource("/test/sleuth-only.xml").toURI());
|
||||
File starterPom = new File(GenerateReleaseTrainDocsTests.class.getResource("/test/starter-pom.xml").toURI());
|
||||
File unzippedDocs = new File("target/test-unpacked-sleuth-docs/");
|
||||
|
||||
GenerateReleaseTrainDocs.main(testPom.getAbsolutePath(),
|
||||
starterPom.getAbsolutePath(), "https://github.com/spring-cloud/",
|
||||
unzippedDocs.getAbsolutePath(), generatedAdocs.getAbsolutePath());
|
||||
GenerateReleaseTrainDocs.main(testPom.getAbsolutePath(), starterPom.getAbsolutePath(),
|
||||
"https://github.com/spring-cloud/", unzippedDocs.getAbsolutePath(), generatedAdocs.getAbsolutePath());
|
||||
|
||||
BDDAssertions.then(generatedAdocs).isNotEmptyDirectory();
|
||||
BDDAssertions.then(configProps(generatedAdocs)).contains(
|
||||
"|spring.sleuth.async.configurer.enabled | true | Enable default AsyncConfigurer.");
|
||||
BDDAssertions.then(configProps(generatedAdocs))
|
||||
.contains("|spring.sleuth.async.configurer.enabled | true | Enable default AsyncConfigurer.");
|
||||
}
|
||||
|
||||
private String configProps(File file) throws IOException {
|
||||
return new String(
|
||||
Files.readAllBytes(new File(file, "configprops.adoc").toPath()));
|
||||
return new String(Files.readAllBytes(new File(file, "configprops.adoc").toPath()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class TestThatGeneratesTheFinalReleaseTrainDocumentationTests {
|
||||
String unzippedDocs = System.getProperty("unzippedDocs");
|
||||
String generatedTrainDocs = System.getProperty("generatedTrainDocs");
|
||||
|
||||
GenerateReleaseTrainDocs.main(bomPath, starterParentPath, repoUrl, unzippedDocs,
|
||||
generatedTrainDocs);
|
||||
GenerateReleaseTrainDocs.main(bomPath, starterParentPath, repoUrl, unzippedDocs, generatedTrainDocs);
|
||||
|
||||
BDDAssertions.then(new File(generatedTrainDocs)).isNotEmptyDirectory();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user