Skip to content

Commit

Permalink
Polish "Add help section and Maven plugin when azure-support is selec…
Browse files Browse the repository at this point in the history
…ted"

See gh-1676
  • Loading branch information
mhalbritter committed Dec 19, 2024
1 parent a587d36 commit 32ba6e1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* A {@link BuildCustomizer} that adds a maven plugin when azure-support is selected.
* A {@link BuildCustomizer} that adds a Maven plugin when azure-support is selected.
*
* @author Muyao Feng
*/
class SpringAzureMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {

private static final String PLUGIN_VERSION = "0.1.0";

private final ProjectDescription projectDescription;

SpringAzureMavenBuildCustomizer(ProjectDescription projectDescription) {
Expand All @@ -36,7 +38,7 @@ class SpringAzureMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {
@Override
public void customize(MavenBuild build) {
build.plugins().add("com.microsoft.azure", "azure-container-apps-maven-plugin", (plugin) -> {
plugin.version("0.1.0");
plugin.version(PLUGIN_VERSION);
plugin.configuration((configuration) -> {
configuration.add("subscriptionId", "your-subscription-id");
configuration.add("resourceGroup", "your-resource-group");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,20 @@ private static Consumer<HelpDocument> addDeploySection() {
helpDocument.addSection((writer) -> {
writer.println("### Deploy to Azure");
writer.println();
writer.println("This project can be deployed to Azure with maven support.");
writer.println("This project can be deployed to Azure with Maven.");
writer.println();
writer.println(
"In your `pom.xml`, replace the following placeholder variables with your specific Azure details:");
"To get started, replace the following placeholder in your `pom.xml` with your specific Azure details:");
writer.println();
writer.println("- `subscriptionId`");
writer.println("- `resourceGroup`");
writer.println("- `appEnvironmentName`");
writer.println("- `region`");
writer.println();
writer.println("Deploy with:");
writer.println("Now you can deploy your application:");
writer.println("""
```bash
mvn azure-container-apps:deploy
./mvnw azure-container-apps:deploy
```
""");
writer.println(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,6 +17,8 @@
package io.spring.start.site.extension.dependency.springazure;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
Expand Down Expand Up @@ -54,6 +56,7 @@ ImplicitDependencyHelpDocumentCustomizer azureDependencyHelpDocumentCustomizer(B

@Bean
@ConditionalOnRequestedDependency("azure-support")
@ConditionalOnBuildSystem(MavenBuildSystem.ID)
SpringAzureMavenBuildCustomizer azureDependencyMavenBuildCustomizer(ProjectDescription projectDescription) {
return new SpringAzureMavenBuildCustomizer(projectDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@
* Tests for {@link SpringAzureMavenBuildCustomizer}.
*
* @author Muyao Feng
* @author Moritz Halbritter
*/
class SpringAzureMavenBuildCustomizerTests extends AbstractExtensionTests {

@Test
void shouldDoNothingIfAzureSupportIsntSelected() {
ProjectRequest request = createProjectRequest("web");
assertThat(mavenPom(request)).doesNotContain("azure-container-apps-maven-plugin");
}

@Test
void azureContainerAppsMavenPluginAddedWhenAzureSupportPresent() {
ProjectRequest request = createProjectRequest("azure-support");
assertThat(mavenPom(request)).hasText("/project/build/plugins/plugin[1]/groupId", "com.microsoft.azure");
assertThat(mavenPom(request)).hasText("/project/build/plugins/plugin[1]/artifactId",
"azure-container-apps-maven-plugin");
assertThat(mavenPom(request)).hasText("/project/build/plugins/plugin[1]/groupId", "com.microsoft.azure")
.hasText("/project/build/plugins/plugin[1]/artifactId", "azure-container-apps-maven-plugin");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void azureJdbcWithPostgresql() {
@Test
void DeploytoAzureSectionAddedWhenAzureSupportPresent() {
ProjectStructure project = generateProject("azure-support");
assertThatHelpDocumentOf(project).contains("Deploy to Azure");
assertThatHelpDocumentOf(project).contains("### Deploy to Azure");
}

private static Stream<Arguments> azureDependencies() {
Expand Down

0 comments on commit 32ba6e1

Please sign in to comment.