diff --git a/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/introduction.adoc b/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/introduction.adoc new file mode 100644 index 00000000..1b450204 --- /dev/null +++ b/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/introduction.adoc @@ -0,0 +1 @@ +For testing... \ No newline at end of file diff --git a/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/toc.yml b/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/toc.yml new file mode 100644 index 00000000..29a65739 --- /dev/null +++ b/src/functionalTest/gradle-projects/test-micronaut-module/src/main/docs/guide/toc.yml @@ -0,0 +1,2 @@ +introduction: + title: Introduction \ No newline at end of file diff --git a/src/functionalTest/groovy/io/micronaut/build/ReleasesDropdownFunctionalTest.groovy b/src/functionalTest/groovy/io/micronaut/build/ReleasesDropdownFunctionalTest.groovy new file mode 100644 index 00000000..91b92268 --- /dev/null +++ b/src/functionalTest/groovy/io/micronaut/build/ReleasesDropdownFunctionalTest.groovy @@ -0,0 +1,34 @@ +package io.micronaut.build + +import java.nio.file.Files + +class ReleasesDropdownFunctionalTest extends AbstractFunctionalTest { + + void "version dropdown is populated from github"() { + given: + withSample("test-micronaut-module") + + and: 'we override the github slug to use micronaut-crac' + testDirectory.resolve("gradle.properties").toFile() << "githubSlug=micronaut-projects/micronaut-crac" + + and: 'we copy the grails-doc-files.jar to the prepareDocsResources directory' + def path = Files.createDirectories(testDirectory.resolve("build/tmp/prepareDocsResources")) + def stream = ReleasesDropdownFunctionalTest.getResourceAsStream("/grails-doc-files.jar") + def target = path.resolve("grails-doc-files.jar") + Files.copy(stream, target) + + when: 'we build the docs' + run 'docs' + + and: 'we find all the version options in the dropdown' + def html = testDirectory.resolve("build/docs/guide/index.html").text + def versions = html.findAll(" + version + } + + then: 'there are more than 2, and 2 of them are latest and snapshot' + versions.contains('latest') + versions.contains('snapshot') + versions.size() > 2 + } +} diff --git a/src/functionalTest/resources/grails-doc-files.jar b/src/functionalTest/resources/grails-doc-files.jar new file mode 100644 index 00000000..49b2c54e Binary files /dev/null and b/src/functionalTest/resources/grails-doc-files.jar differ diff --git a/src/main/groovy/io/micronaut/build/MicronautDocsPlugin.groovy b/src/main/groovy/io/micronaut/build/MicronautDocsPlugin.groovy index 2a12ed44..b964d473 100644 --- a/src/main/groovy/io/micronaut/build/MicronautDocsPlugin.groovy +++ b/src/main/groovy/io/micronaut/build/MicronautDocsPlugin.groovy @@ -195,10 +195,10 @@ abstract class MicronautDocsPlugin implements Plugin { outputIndex = layout.buildDir.file("working/05-dropdown/index.html") versionsJson = githubApi.zip(slug) { api, ghSlug -> try { - byte[] jsonArr = api.fetchTagsFromGitHub(ghslug) + byte[] jsonArr = api.fetchTagsFromGitHub(ghSlug) return new String(jsonArr, "UTF-8") } catch (Exception e) { - task.logger.error("Exception fetching github tags for $ghSlug") + task.logger.error("Exception fetching github tags for $ghSlug", e) return "[]" } } diff --git a/src/main/java/io/micronaut/build/utils/GithubApiUtils.java b/src/main/java/io/micronaut/build/utils/GithubApiUtils.java index d1bec514..e9fa5521 100644 --- a/src/main/java/io/micronaut/build/utils/GithubApiUtils.java +++ b/src/main/java/io/micronaut/build/utils/GithubApiUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 original authors + * Copyright 2017-2023 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ static byte[] fetchTagsFromGitHub(Logger logger, String slug) { private static byte[] fetchFromGithub(Logger logger, String slug, String what) { String url = System.getProperty(GITHUB_API_BASE_URL_SYSTEM_PROPERTY, GITHUB_BASE_API_URL) + "/repos/" + normalizeSlug(slug) + "/" + what; + logger.lifecycle("Fetching " + what + " from " + url); try { return fetchFromGithub(logger, connectionForGithubUrl(logger, url)); } catch (IOException ex) {