diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityProjectGenerationConfiguration.java index 1481b543b00..a676b465bd1 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityProjectGenerationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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. @@ -18,6 +18,7 @@ import io.spring.initializr.generator.buildsystem.Build; import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion; +import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.project.ProjectGenerationConfiguration; @@ -52,6 +53,13 @@ ObservabilityHelpDocumentCustomizer observabilityHelpDocumentCustomizer(ProjectD return new ObservabilityHelpDocumentCustomizer(description, build); } + @Bean + @ConditionalOnRequestedDependency("wavefront") + @ConditionalOnPlatformVersion("[3.2.0, 3.3.0-M1)") + WavefrontHelpDocumentCustomizer wavefrontHelpDocumentCustomizer(Build build) { + return new WavefrontHelpDocumentCustomizer("https://docs.wavefront.com/wavefront_springboot3.html", build); + } + } @Configuration(proxyBeanMethods = false) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizer.java new file mode 100644 index 00000000000..94d7533466d --- /dev/null +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizer.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2024 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 io.spring.start.site.extension.dependency.observability; + +import io.spring.initializr.generator.buildsystem.Build; +import io.spring.initializr.generator.spring.documentation.HelpDocument; +import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; + +/** + * A {@link HelpDocumentCustomizer} that provides additional references when Wavefront is + * selected. + * + * @author Stephane Nicoll + * @author Brian Clozel + */ +class WavefrontHelpDocumentCustomizer implements HelpDocumentCustomizer { + + private final Build build; + + private final String referenceLink; + + WavefrontHelpDocumentCustomizer(String referenceLink, Build build) { + this.referenceLink = referenceLink; + this.build = build; + } + + @Override + public void customize(HelpDocument document) { + document.gettingStarted().addReferenceDocLink(this.referenceLink, "Wavefront for Spring Boot documentation"); + + StringBuilder sb = new StringBuilder(); + sb.append(String.format("## Observability with Wavefront%n%n")); + sb.append(String + .format("If you don't have a Wavefront account, the starter will create a freemium account for you.%n")); + sb.append(String.format("The URL to access the Wavefront Service dashboard is logged on startup.%n")); + + if (this.build.dependencies().has("web") || this.build.dependencies().has("webflux")) { + sb.append( + String.format("%nYou can also access your dashboard using the `/actuator/wavefront` endpoint.%n")); + } + + if (!this.build.dependencies().has("distributed-tracing")) { + sb.append(String.format( + "%nFinally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry.%n")); + } + document.addSection((writer) -> writer.print(sb)); + } + +} diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizerTests.java new file mode 100644 index 00000000000..e2721825666 --- /dev/null +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizerTests.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2024 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 io.spring.start.site.extension.dependency.observability; + +import io.spring.initializr.generator.test.io.TextAssert; +import io.spring.initializr.generator.test.project.ProjectStructure; +import io.spring.initializr.web.project.ProjectRequest; +import io.spring.start.site.extension.AbstractExtensionTests; +import org.assertj.core.api.ListAssert; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link WavefrontHelpDocumentCustomizer}. + * + * @author Stephane Nicoll + * @author Brian Clozel + */ +class WavefrontHelpDocumentCustomizerTests extends AbstractExtensionTests { + + @Test + void wavefrontAddGeneralSection() { + assertHelpDocument("3.2.0", "wavefront").contains("## Observability with Wavefront", "", + "If you don't have a Wavefront account, the starter will create a freemium account for you.", + "The URL to access the Wavefront Service dashboard is logged on startup."); + } + + @Test + void wavefrontWithoutWebApplicationDoesNotAddActuatorSection() { + assertHelpDocument("3.2.0", "wavefront") + .doesNotContain("You can also access your dashboard using the `/actuator/wavefront` endpoint."); + } + + @Test + void wavefrontWithWebApplicationAddActuatorSection() { + assertHelpDocument("3.2.0", "wavefront", "web") + .contains("You can also access your dashboard using the `/actuator/wavefront` endpoint."); + } + + @Test + void wavefrontWithoutDistributedTracingAddTracingNote() { + assertHelpDocument("3.2.0", "wavefront") + .contains("Finally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry."); + } + + @Test + void wavefrontWithDistributedTracingDoesNotAddTracingNote() { + assertHelpDocument("3.2.0", "wavefront", "distributed-tracing").doesNotContain( + "Finally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry."); + } + + @Test + void springBoot3xWavefrontReference() { + assertHelpDocument("3.2.0", "wavefront").contains( + "* [Wavefront for Spring Boot documentation](https://docs.wavefront.com/wavefront_springboot3.html)"); + } + + private ListAssert assertHelpDocument(String version, String... dependencies) { + ProjectRequest request = createProjectRequest(dependencies); + request.setBootVersion(version); + ProjectStructure project = generateProject(request); + return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines(); + } + +}